Python's pulp linear programming introduction and examples

Source: Internet
Author: User

Pulp http://pythonhosted.org/PuLP/main/basic_python_coding.html Water Supply problem

1 Questions

The water supply company has three reservoirs for A,b,c to four residential quarters ,a and B water supply to all communities,and C only water supply to a ethyl C, Maximum water supply in the reservoir (thousand tonnes )

Reservoir

A

B

C

Maximum quantity of water supply (thousand tonnes)

50

60

50

the water use situation of the community is

Community

A

B

C

Ding

Basic water consumption (KT)

30

70

10

10

Additional water consumption (KT)

50

70

20

40

The reservoir water supply income is RMB /thousand tons , the expense cost is: other expenses 450/ thousand tons, the diversion management fee:

Cost of diversion from reservoir to community:

Yuan/thousand tons

A

B

C

Ding

A

160

130

220

170

B

140

130

190

150

C

190

200

230

asked How to allocate water supply to the reservoir, the company can make the most profit.

2 solving problems Ideas

to minimize the cost of diversion management, the profit is the highest .

Set : Reservoir i to the cell J Water Supply , the total Diversion management fee is Z

The target function is: z = 160.0*x11 + 130.0*x12 + 220.0*x13 + 170.0*x14 + 140.0*x21 + 130.0*x22 + 190.0*x23 + 150.0*x24 + 190.0*x31 + 200.0*x32 + 230.0*x33

to make Z the smallest value .

the constraints are:

1 #Coding=utf-82 #Coding=utf-83  fromPulpImport*4 5 6 defget_re ():7     Pass8 9 Ten defGetResult (C, con): One  A #Set Object -Prob = Lpproblem ('Mypro', Lpminimize) - #set the variable and set the variable minimum value the  -x11 = lpvariable ("X11", lowbound=0) -x12 = lpvariable ("X12", lowbound=0) -X13 = Lpvariable ("x13", lowbound=0) +x14 = Lpvariable ("x14", lowbound=0) -x21 = Lpvariable ("x21", lowbound=0) +x22 = Lpvariable ("x22", lowbound=0) Ax23 = Lpvariable ("x23", lowbound=0) atx24 = Lpvariable ("x24", lowbound=0) -X31 = Lpvariable ("x31", lowbound=0) -x32 = Lpvariable ("x32", lowbound=0) -x33 = Lpvariable ("x33", lowbound=0) -  -X =[X11, X12, X13, x14, x21, x22, x23, x24, x31 , x32, x33] in  -     #C = [the ",", ",", " ,", ",", "," to  +  -  the  *  $ Panax Notoginseng #objective Function -z =0 the      forIinchRange (len (X)): +z + = x[i]*C[i] A     #print (z) theProb + =Z +  - #load constraint variable $Prob + = x11+x12+x13+x14 = = Con[0]#constraint conditions 1 $Prob + = x21+x22+x23+x24 = = Con[1] -Prob + = X31+x32+x33 = = Con[2] -  theProb + = x11+x21+x31 <= con[3] -Prob + = x11+x21+x31 >= con[4]Wuyi  theProb + = x12 + x22 + x32 <= con[5] -Prob + = x12 + x22 + x32 >= con[6] Wu  -Prob + = x14 + x24 <= con[7] AboutProb + = x14 + x24 >= con[8] $  - #solving -  -Status =prob.solve () A  +     #print (Lpstatus[status]) the     Print(Value (prob.objective))#Calculation Results -  $  the #Show Results the For I in Prob.variables (): the Print (i.name + "=" + str (i.varvalue)) the      forIinchprob.variables (): -         in  the  the if __name__=='__main__': Aboutc = [160, 130, 220, 170, 140, 130, 190, 150, 190, 200, 230] thecon = [50, 60, 50, 80, 30, 140, 70, 50, 10] theGetResult (C, con)

Output Result:

Optimal24000.0x11=0.0x12=50.0x13=0.0x14=0.0x21 =0.0 x22=50.0x23=0.0x24=10.0x31=50.0x32=0.0x33=0.0

Python's pulp linear programming introduction and examples

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.