0% found this document useful (0 votes)
22 views5 pages

Python PRACTICAL 12

The document contains 6 examples of linear programming problems modeled and solved using the PuLP library in Python. Each problem defines variables and constraints to optimize an objective function. The output shows the problem formulation, solution, and values of the variables.

Uploaded by

Black Adam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

Python PRACTICAL 12

The document contains 6 examples of linear programming problems modeled and solved using the PuLP library in Python. Each problem defines variables and constraints to optimize an objective function. The output shows the problem formulation, solution, and values of the variables.

Uploaded by

Black Adam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PRACTICAL: 12

NAME: Ashwin Pinto


ROLL NO: 12
-------------------------------------------------------------------------------------------------------------------------
#1
from pulp import *
model=LpProblem(sense=LpMinimize)
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
model+=(x>=6)
model+=(y>=6)
model+=(x+y<=11)
model+=x+y
model
NoName:
MINIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: x >= 6
_C2: y >= 6
_C3: x + y <= 11
VARIABLES
x Continuous
y Continuous
>>model.solve()
-1
>>model.objective.value()
12.0
>>x.value()
6.0
>>y.value()
6.0

#2
from pulp import *
model=LpProblem(sense=LpMaximize)
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
z=LpVariable(name="z",lowBound=0)
model+=(x+2*y+z<=430)
model+=(3*x+2*z<=460)
model+=(x+4*y<=120)
model+=3*x+2*y
model
NoName:
MAXIMIZE
3*x + 2*y + 0
SUBJECT TO
_C1: x + 2 y + z <= 430
_C2: 3 x + 2 z <= 460
_C3: x + 4 y <= 120
VARIABLES
x Continuous
y Continuous
z Continuous
>>model.solve()
1
>>model.objective.value()
360.0
>>x.value()
120.0
>>y.value()
0.0
>>z.value()
0.0

#3
from pulp import *
model=LpProblem(sense=LpMaximize)
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
z=LpVariable(name="z",lowBound=0)
model+=(2*x+3*y<=8)
model+=(2*x+5*z<=10)
model+=(3*x+2*y+4*z<=15)
model+=3*x+5*y+4*z
model
NoName:
MAXIMIZE
3*x + 5*y + 4*z + 0
SUBJECT TO
_C1: 2 x + 3 y <= 8
_C2: 2 x + 5 z <= 10
_C3: 3 x + 2 y + 4 z <= 15
VARIABLES
x Continuous
y Continuous
z Continuous
>>model.solve()
1
>>model.objective.value()
21.333333500000002
>>x.value()
0.0
>>y.value()
2.6666667
>>z.value()
2.0
#4
from pulp import *
model=LpProblem(sense=LpMaximize)
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
z=LpVariable(name="z",lowBound=0)
w=LpVariable(name="w",lowBound=0)
model+=(4*x+6*y-5*z-4*w>=-20)
model+=(-8*x-3*y+3*z+2*w<=20)
model+=(x+y<=11)
model+=4*x+y+3*z+5*w
model
NoName:
MAXIMIZE
5*w + 4*x + 1*y + 3*z + 0
SUBJECT TO
_C1: - 4 w + 4 x + 6 y - 5 z >= -20
_C2: 2 w - 8 x - 3 y + 3 z <= 20
_C3: x + y <= 11
VARIABLES
w Continuous
x Continuous
y Continuous
z Continuous
>>model.solve()
1
>>model.objective.value()
124.0
>>x.value()
11.0
>>y.value()
0.0
z.value()
0.0
>>w.value()
16.0

#5
from pulp import *
model=LpProblem(sense=LpMaximize)
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
z=LpVariable(name="z",lowBound=0)
w=LpVariable(name="w",lowBound=0)
model+=(4*x+6*y-5*z-4*w>=20)
model+=(-8*x-3*y+3*z+2*w<=20)
model+=(x+y<=11)
model+=(3*x-2*y+4*z+w<=10)
model+=4*x+y+3*z+5*w
model
NoName:
MAXIMIZE
5*w + 4*x + 1*y + 3*z + 0
SUBJECT TO
_C1: - 4 w + 4 x + 6 y - 5 z >= 20
_C2: 2 w - 8 x - 3 y + 3 z <= 20
_C3: x + y <= 11
_C4: w + 3 x - 2 y + 4 z <= 10
VARIABLES
w Continuous
x Continuous
y Continuous
z Continuous
>>model.solve()
1
>>model.objective.value()
70.7777778
>>x.value()
4.5555556
>>y.value()
6.4444444
>>z.value()
0.0
>>w.value()
9.2222222

#6
from pulp import *
model=LpProblem(sense=LpMaximize)
x=LpVariable(name="x",lowBound=0)
y=LpVariable(name="y",lowBound=0)
z=LpVariable(name="z",lowBound=0)
model+=(x+2*y+2*z<=1)
model+=(3*x+2*y+z>=8)
model+=x+2*y+z
model
NoName:
MAXIMIZE
1*x + 2*y + 1*z + 0
SUBJECT TO
_C1: x + 2 y + 2 z <= 1
_C2: 3 x + 2 y + z >= 8
VARIABLES
x Continuous
y Continuous
z Continuous
>>model.solve()
-1
>>model.objective.value()
2.6666667
>>x.value()
2.6666667
>>y.value()
0.0
>>z.value()
0.0

You might also like