0% found this document useful (0 votes)
109 views17 pages

Optimization Using Python: Dr. R K Jena

Optimization involves choosing alternatives to achieve objectives given constraints. Python can be used to solve optimization problems using packages like PuLP and SciPy. Linear programming formulations in Python involve defining variables, constraints, and objectives to maximize or minimize. Examples demonstrated include maximizing profits from wood products given labor and demand constraints, and maximizing production given machine time constraints. Python allows formulating and solving optimization problems commonly seen in applications like scheduling, supply chain management, and production planning.

Uploaded by

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

Optimization Using Python: Dr. R K Jena

Optimization involves choosing alternatives to achieve objectives given constraints. Python can be used to solve optimization problems using packages like PuLP and SciPy. Linear programming formulations in Python involve defining variables, constraints, and objectives to maximize or minimize. Examples demonstrated include maximizing profits from wood products given labor and demand constraints, and maximizing production given machine time constraints. Python allows formulating and solving optimization problems commonly seen in applications like scheduling, supply chain management, and production planning.

Uploaded by

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

Optimization Using Python

Dr. R K Jena
IMT, Nagpur
What is Optimization?

• Optimization is a problem of decision making


in which we need to choose between various
alternatives under certain conditions.
• Optimization models are mathematical
models that include functions that represent
goals or objectives for the system being
modelled with given condition.
2
General form of a mathematical model

• min or max f(x1,...,xn) (Objective function)


• subject to, g(x1,...,xn) ≥0 (functional constraints)
x1,...,xn ∈S (set constraints)
• x1,...,xn are called decision variables
• In another words, the goal is to find x1,...,xn such that:
 They satisfy the constraints.
 If no such value exist for x1,...,xn, the problem is infeasible.
 They achieve min or max objective function value (may be
unbounded)
3
Types of Deterministic Optimization
Models

4
Applications of optimization
• Scheduling of Buses/trains (Transport)
• Transportation network design
• Supply chain optimization
• Optimum circuit design of PCB
• Design optimization of various mechanical components
• Process optimization in chemical industry
• Designing of the sharing network in internet
• Search engine optimization
• Shop floor layout planning
• Production planning and scheduling
• Hospital management systems etc. 5
Python interface for optimization

• Pyomo→used for LP models.


• PuLP→used for LP models.
•Pyscipopt →used for LP models
•Scipy →used for Assignment models

6
Solving a Linear Programming problem with Python
(Pulp)
• Linear Programming is a type of optimisation where
an objective function should be
maximized/minimized with given constraints.

7
Solving using Pulp
• from pulp import *
• # declare your variables
• x1=LpVariable("x1",0)
• x2=LpVariable("x2",0)
• x3=LpVariable("x3",0)
• # defines the problem
prob = LpProblem("problem", LpMaximize)
• # defines the constraints
• prob += x1+2*x2+3*x3 <=10
• prob += x2+2*x3<=5

8
Solving using Pulp
• # defines the objective function to maximize
prob+=1000*x1+2000*x2+3000*x3
# solve the problem
• status = prob.solve()
• LpStatus[status]
• # print the results x1, x2, x3
value(x1)
value(x2)
Value(x3)
• # Print the value of the objective
print("Objective = %f" % value(prob.objective)) 9
Solving a Linear Programming problem with Python
(Pulp)
• Example:
Let us say that you want to maximize profits by selling wood soldiers
(denoted x1) and wood trains (denoted x2) given that the margin is 3$
for one soldier and 2$ for one train, you want to maximize the profit.
In addition, you have the following constraints per week:
• a soldier requires 2 hours of finishing labour. a train requires 1
hour of finishing labour. You have only 100 hours of finishing
labour avaiable weekly
• a soldier requires 1 hour of carprentry labour. Same for a train.
You have only 80 hours of carpentry labour available weekly
• Demand for soldiers not more than 40 per week
• Demand of trains not more than 1000 per week 10
Problem Formulation
• Maximize : 3x1+2x2
• Subject to:
• 2*x1 + x2 <= 100
• x1 + x2 <= 80
• x1 <=40
• X2<=1000
• x1>=0 and x2>=0
11
Solving using Pulp
• from pulp import *
• # declare your variables
x1 = LpVariable("x1", 0, 40) # 0<= x1 <= 40
x2 = LpVariable("x2", 0, 1000) # 0<= x2 <= 1000
• # defines the problem
prob = LpProblem("problem", LpMaximize)
• # defines the constraints
prob += 2*x1+x2 <= 100
prob += x1+x2 <= 80
12
Solving using Pulp
• # defines the objective function to maximize
prob += 3*x1+2*x2
• # solve the problem
• status = prob.solve()
• LpStatus[status]
• # print the results x1 = 20, x2 = 60
value(x1)
value(x2)
• # Print the value of the objective
print("Objective = %f" % value(prob.objective))
13
Solving using Pulp
A company makes two products (X and Y) using two machines (A and B).
Each unit of X that is produced requires 50 minutes processing time on
machine A and 30 minutes processing time on machine B. Each unit of Y
that is produced requires 24 minutes processing time on machine A and
33 minutes processing time on machine B.
At the start of the current week there are 30 units of X and 90 units of Y
in stock. Available processing time on machine A is forecast to be 40
hours and on machine B is forecast to be 35 hours.
The demand for X in the current week is forecast to be 75 units and for Y
is forecast to be 95 units. Company policy is to maximise the combined
sum of the units of X and the units of Y in stock at the end of the week.
Formulate the problem of deciding how much of each product to make
in the current week as a linear program. 14
Solving using Pulp
Maximise (x+30-75) + (y+90-95) = x+y-50
Subjected to:
•50x + 24y <= 2400 # machine A time
•30x + 33y <= 2100 # machine B time
•x >= 45
•y >= 5
•Answer:
•x=45 and y=6.25; Value of the objective function is
1.25
15
16
Thanks

17

You might also like