0% found this document useful (0 votes)
15 views6 pages

Mayu Chapter 3 - Jupyter Notebook

The document solves 6 linear programming problems (LLPs) using the PuLP library in Python. For each LLP, it formulates the objective function and constraints as a pulp model, solves the model, and displays the optimal objective value and variable values. The 6 problems cover maximization and minimization of linear functions subject to various inequality constraints. Problems 3, 4, and 6 are found to be infeasible or unbounded.

Uploaded by

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

Mayu Chapter 3 - Jupyter Notebook

The document solves 6 linear programming problems (LLPs) using the PuLP library in Python. For each LLP, it formulates the objective function and constraints as a pulp model, solves the model, and displays the optimal objective value and variable values. The 6 problems cover maximization and minimization of linear functions subject to various inequality constraints. Problems 3, 4, and 6 are found to be infeasible or unbounded.

Uploaded by

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

3/2/24, 4:51 PM Mayu chapter 3 - Jupyter Notebook

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

Chapter 3

3.1) Solve the following LLP:

Max Z = 150x+75y
subject to,
4x+6y <= 24
5x+3y <= 15
x>=0, y>=0

In [1]: 1 from pulp import *


2 model = LpProblem(name="small-problem", sense=LpMaximize)
3 x = LpVariable(name="x", lowBound=0)
4 y = LpVariable(name="y", lowBound=0)
5 model += (4 * x + 6 * y <= 24)
6 model += (5 * x + 3 * y <= 15)
7 model += 150 * x + 75 * y
8 model

Out[1]: small-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

In [2]: 1 model.solve()

Out[2]: 1

In [4]: 1 model.objective.value()

Out[4]: 450.0

localhost:8888/notebooks/Mayu chapter 3.ipynb 1/6


3/2/24, 4:51 PM Mayu chapter 3 - Jupyter Notebook

In [5]: 1 x.value()

Out[5]: 3.0

In [7]: 1 y.value()

Out[7]: 0.0

3.2) Solve the following LLP:

Max Z = 3.5x+2y
subject to,
x+y >= 5
x >= 4
y <= 2
x>=0, y>=0

In [8]: 1 from pulp import *


2 model = LpProblem(sense= LpMinimize)
3 x = LpVariable(name="x", lowBound=0)
4 y = LpVariable(name="y", lowBound=0)
5 model += (x+y >= 5)
6 model += (x >= 4)
7 model += (y <= 2)
8 model += (3.5*x)+(2*y)
9 model

Out[8]: NoName:
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

In [9]: 1 model.solve()

Out[9]: 1

In [10]: 1 model.objective.value()

Out[10]: 16.0

In [11]: 1 x.value()

Out[11]: 4.0

localhost:8888/notebooks/Mayu chapter 3.ipynb 2/6


3/2/24, 4:51 PM Mayu chapter 3 - Jupyter Notebook

In [12]: 1 y.value()

Out[12]: 1.0

3.3) Solve the following LLP:

Max Z = 3x + 5y + 4z
subject to,
2x+3y <= 8
2y+5z <= 10
3x+2y+4z <= 15
x>=0, y>=0, z>=0

In [3]: 1 from pulp import *


2 model=LpProblem(sense= LpMaximize)
3 x=LpVariable(name="x", lowBound=0)
4 y=LpVariable(name="y", lowBound=0)
5 z=LpVariable(name="z", lowBound=0)
6 model += (2*x+3*y <= 8)
7 model += (2*y+5*z <= 10)
8 model += (3*x+2*y+4*z <= 15)
9 model += (3*x + 5*y + 4*z)
10 model

Out[3]: NoName:
MAXIMIZE
3*x + 5*y + 4*z + 0
SUBJECT TO
_C1: 2 x + 3 y <= 8

_C2: 2 y + 5 z <= 10

_C3: 3 x + 2 y + 4 z <= 15

VARIABLES
x Continuous
y Continuous
z Continuous

In [4]: 1 model.solve()

Out[4]: 1

In [5]: 1 model.objective.value()

Out[5]: 18.658536500000004

In [6]: 1 x.value()

Out[6]: 2.1707317

In [7]: 1 y.value()

Out[7]: 1.2195122

localhost:8888/notebooks/Mayu chapter 3.ipynb 3/6


3/2/24, 4:51 PM Mayu chapter 3 - Jupyter Notebook

In [8]: 1 z.value()

Out[8]: 1.5121951

3.4) Solve the following LLP:

Min Z = x + 2*y + z
subject to,
x + 1/2y + 1/2z <= 1
3/2x+2y+z >= 8
x>=0, y>=0, z >=0

In [9]: 1 from pulp import *


2 model=LpProblem(sense= LpMinimize)
3 x=LpVariable(name="x", lowBound=0)
4 y=LpVariable(name="y", lowBound=0)
5 z=LpVariable(name="z", lowBound=0)
6 model += ((x)+(0.5*y)+(0.5*z) <= 1)
7 model += ((1.5*x)+(2*y)+(z) >= 8)
8 model += x+2*y+z
9 model

Out[9]: NoName:
MINIMIZE
1*x + 2*y + 1*z + 0
SUBJECT TO
_C1: x + 0.5 y + 0.5 z <= 1

_C2: 1.5 x + 2 y + z >= 8

VARIABLES
x Continuous
y Continuous
z Continuous

In [10]: 1 model.solve()

Out[10]: -1

1 solve() returns the integer status of the solution, which is -1,


2 i.e. solution is infeasible or unbounded.

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

localhost:8888/notebooks/Mayu chapter 3.ipynb 4/6


3/2/24, 4:51 PM Mayu chapter 3 - Jupyter Notebook

In [ ]: 1 ​

3.5) Solve the following LLP:

Min Z = x + y
subject to,
x >= 6
y >= 6
x+y <= 11
x>=0, y>=0

In [13]: 1 from pulp import *


2 model=LpProblem(sense= LpMinimize)
3 x=LpVariable(name="x", lowBound=0)
4 y=LpVariable(name="y", lowBound=0)
5 model += (x >= 6)
6 model += (y >= 6)
7 model += (x+y <= 11)
8 model += x+y
9 model

Out[13]: NoName:
MINIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: x >= 6

_C2: y >= 6

_C3: x + y <= 11

VARIABLES
x Continuous
y Continuous

In [14]: 1 model.solve()

Out[14]: -1

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

In [ ]: 1 ​

localhost:8888/notebooks/Mayu chapter 3.ipynb 5/6


3/2/24, 4:51 PM Mayu chapter 3 - Jupyter Notebook

In [ ]: 1 ​

3.6) Solve the following LLP:

Max Z = x + y
subject to,
x-1 >= 1
x+y >= 2

In [16]: 1 from pulp import *


2 model=LpProblem(sense= LpMaximize)
3 x=LpVariable(name="x", lowBound=0)
4 y=LpVariable(name="y", lowBound=0)
5 model += (x-y >= 1)
6 model += (x+y >= 2)
7 model += x+y
8 model

Out[16]: NoName:
MAXIMIZE
1*x + 1*y + 0
SUBJECT TO
_C1: x - y >= 1

_C2: x + y >= 2

VARIABLES
x Continuous
y Continuous

In [17]: 1 model.solve()

Out[17]: -2

In [ ]: 1 ​

localhost:8888/notebooks/Mayu chapter 3.ipynb 6/6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy