0% found this document useful (0 votes)
8 views

Python Practical 11

This document contains the solutions to 10 questions involving linear programming problems. For each question, the linear program is defined and solved using the pulp library in Python. The optimal solutions and objective values are printed for each problem.

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)
8 views

Python Practical 11

This document contains the solutions to 10 questions involving linear programming problems. For each question, the linear program is defined and solved using the pulp library in Python. The optimal solutions and objective values are printed for each problem.

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/ 10

PRACTICAL 11

NAME: Ashwin Pinto


ROLL NO: 12
Class : Sy Bsc(cs)

Q1)
ANS:
print("Q1")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMaximize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += 150*x+75*y
Lp_prob +=4*x+6*y<=24
Lp_prob+= 5*x+3*y<=15
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Maximize=",p.value(Lp_prob.objective))
OUTPUT: Q1
Problem:
MAXIMIZE
150*x + 75*y + 0
SUBJECT TO
_C1: 4 x + 6 y <= 24

_C2: 5 x + 3 y <= 15

VARI
ABLES
x Continuous
y Continuous
Optimal
x= 3.0
y= 0.0
Maximize= 450.0

Q2)
ANS:
print("Q2")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMaximize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += 5*x+3*y
Lp_prob +=x+y<=7
Lp_prob+= 2*x+5*y<=1
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Maximize=",p.value(Lp_prob.objective))
OUTPUT:
Q2
Problem:
MAXIMIZE
5*x + 3*y + 0
SUBJECT TO
_C1: x + y <= 7

_C2: 2 x + 5 y <= 1

VARIABLES
x Continuous
y Continuous

Optimal
x= 0.5
y= 0.0
Maximize= 2.5

Q3)
ANS:
print("Q3")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMinimize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += 3.5*x+2*y
Lp_prob +=x+y>=5
Lp_prob +=x>=4
Lp_prob+= y<=2
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Minimize=",p.value(Lp_prob.objective))
OUTPUT: Q3
Problem:
MINIMIZE
3.5*x + 2*y + 0.0
SUBJECT TO
_C1: x + y >= 5

_C2: x >= 4

_C3: y <= 2

VARIABLES
x Continuous
y Continuous

Optimal
x= 4.0
y= 1.0
Minimize= 16.0

Q4)
ANS:
print("Q4")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMaximize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += 150*x+75*y
Lp_prob +=4*x+6*y<=24
Lp_prob+= 5*x+3*y<=15
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Maximize=",p.value(Lp_prob.objective))
OUTPUT:
Q4
Problem:
MAXIMIZE
150*x + 75*y + 0
SUBJECT TO
_C1: 4 x + 6 y <= 24

_C2: 5 x + 3 y <= 15

VARIABLES
x Continuous
y Continuous

Optimal
x= 3.0
y= 0.0
Maximize= 450.0

Q5)
ANS:
print("Q5")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMaximize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += 5*x+3*y
Lp_prob +=x+y<=7
Lp_prob+= 2*x+5*y<=1
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Maximize=",p.value(Lp_prob.objective))
OUTPUT: Q5
Problem:
MAXIMIZE
5*x + 3*y + 0
SUBJECT TO
_C1: x + y <= 7

_C2: 2 x + 5 y <= 1

VARIABLES
x Continuous
y Continuous

Optimal
x= 0.5
y= 0.0
Maximize= 2.5

Q6)
ANS:
print("Q6")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMaximize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += x+y
Lp_prob +=2*x-2*y>=1
Lp_prob+= x+y>=2
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Maximize=",p.value(Lp_prob.objective))
OUTPUT:
Q6
Problem:
MAXIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: 2 x - 2 y >= 1

_C2: x + y >= 2

VARIABLES
x Continuous
y Continuous

Unbounded
x= 0.0
y= 0.0
Maximize= 0.0
Q7)
ANS:
print("Q7")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMinimize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += 3.5*x+2*y
Lp_prob +=x+y>=5
Lp_prob +=x>=4
Lp_prob+= y<=2
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Minimize=",p.value(Lp_prob.objective))
OUTPUT:
Q7
Problem:
MINIMIZE
3.5*x + 2*y + 0.0
SUBJECT TO
_C1: x + y >= 5

_C2: x >= 4

_C3: y <= 2

VARIABLES
x Continuous
y Continuous

Optimal
x= 4.0
y= 1.0
Minimize= 16.0

Q8)
ANS:
print("Q8")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMinimize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += 3.5*x+2*y
Lp_prob +=x+y>=5
Lp_prob +=x>=4
Lp_prob+= y<=2
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Minimize=",p.value(Lp_prob.objective))
OUPUT:
Q8
Problem:
MINIMIZE
3.5*x + 2*y + 0.0
SUBJECT TO
_C1: x + y >= 5

_C2: x >= 4

_C3: y <= 2

VARIABLES
x Continuous
y Continuous

Optimal
x= 4.0
y= 1.0
Minimize= 16.0

Q9)
ANS:
print("Q9")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMaximize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += 150*x+75*y
Lp_prob +=4*x+6*y<=24
Lp_prob+= 5*x+3*y<=15
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Maximize=",p.value(Lp_prob.objective))
OUTPUT: Q9
Problem:
MAXIMIZE
150*x + 75*y + 0
SUBJECT TO
_C1: 4 x + 6 y <= 24

_C2: 5 x + 3 y <= 15

VARIABLES
x Continuous
y Continuous

Optimal
x= 3.0
y= 0.0
Maximize= 450.0

Q10)
ANS:
print("Q10")
import pulp as p
Lp_prob=p.LpProblem('Problem',p.LpMaximize)
x=p.LpVariable("x", lowBound=0)
y=p.LpVariable("y", lowBound=0)
Lp_prob += x+y
Lp_prob +=x-y>=1
Lp_prob+= x+y>=2
print(Lp_prob)
status=Lp_prob.solve()
print(p.LpStatus[status])
print("x=",p.value(x))
print("y=",p.value(y))
print("Maximize=",p.value(Lp_prob.objective))
OUTPUT:
Q10
Problem:
MAXIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: x - y >= 1

_C2: x + y >= 2

VARIABLES
x Continuous
y Continuous

Unbounded
x= 0.0
y= 0.0
Maximize= 0.0

You might also like