You are on page 1of 100

DIIIO06 –Lecture 2

LP Modeling
1. Review and basics
2. Some LP modeling techniques
3. More LP modeling techniques
4. More LP modeling examples
1. Review and basics
Linear optimization models

Linear programming (LP):

Linear objective function and constraints;


continuous variables.
Mixed-integer linear programming (MILP):
Linear objective function and constraints; continuous and/or
integer variables.
First main topic (This week and next one)

Modeling with linear objective, linear


constraints and
continuous/integer/binary variables.

Lets look some easy examples.


Ex.1: A simple example in finance

• 3 assets to choose from


• Prices: $45, $55, $37 (per unit)
• Expected rewards: $90, $80, $70 (per unit)
• Budget: $100

How many to buy from each of them?


A model (Continuous knapsack)
Ex.2: A simple example in finance revisited

• 3 assets to choose from


• Prices: $45, $55, $37 (per unit)
• Expected rewards: $90, $80, $70 (per unit)
• Budget: $100
• Cannot buy fractions of assets

How many to buy from each of them?


A model (Integer knapsack)
Ex.3: A simple example in finance rerevisited

• 3 assets to choose from


• Prices: $45, $55, $37 (per unit)
• Expected rewards: $90, $80, $70 (per unit)
• Budget: $100
• Either you buy one unit of the asset or you don’t buy that
asset
How many to buy from each of them?
A model (0-1knapsack, aka Binary knapsack)
Equivalent model (0-1knapsack, aka Binary knapsack)
Comments
Linear optimization models (LPs and MILPs) can be used to
solve a variety of problems.

Sometimes we must use integer variables. For instance in Ex.2


we cannot buy only a fraction of an asset. In Ex.3 we use 0-1
variables to model yes/no decisions.

MILPs models are more powerful in terms of modeling, but


they are also more difficult to solve (important trade-off!).
Modeling real problems by using linear models

We want to model problems arising from


real applications using linear optimization.

For now we do not care how to solve these


problems or about the LP form.

We will first learn how to model by using LPs.

Then we will learn how to model problems by


using MILPs.
LP modeling
examples
We start by looking at some LP
modeling examples
A simple problem
Farmer Jones must determine how many acres of corn and wheat to plant
this year. An acre of wheat yields 25 bushels of wheat and requires 10 hours
of labor per week. An acre of corn yields 10 bushels of corn and requires 4
hours of labor per week. All wheat can be sold at $4 a bushel, and all corn
can be sold at $3 a bushel. Seven acres of land and 40 hours per week of
labor are available. Government regulations require that at least 30 bushels
of corn be produced during the current year. Let x1 = number of acres of
corn planted, and x2 = number of acres of wheat planted. Using these
decision variables, formulate an LP whose solution will tell Farmer Jones
how to maximize the total revenue from wheat and corn.
A mixing/blending problem
Chandler Oil Company has 5,000 barrels of oil 1 and 10,000 barrels of oil
2. The company sells two products: gasoline and heating oil. Both
products are produced by combining oil 1 and oil 2. The quality levels of
oils 1 and 2 are 10 and 5 respectively. Gasoline must have an average
quality level of at least 8, and heating oil at least 6. Demand for each
product must be created by advertisement. Each dollar spent advertising
gasoline creates 5 barrels of demand and each dollar spent on heating oil
creates 10 barrels of demand. Gasoline is sold for $25 per barrel, heating
oil for $20. Formulate an LP to help Chandler Oil maximize prot. Assume
that no oil of either type can be purchased.
A tricky LP modeling problem

A hospital wants to schedule weekly nightshift


for its nurses. Let dj be the demand for nurses
on days j = 1,...,7. Every nurse works 5 days in a
row. The goal is to hire minimum number of
nurses.

( This problem should be modeled as an


MILP, but for now assume that you could
have fractional nurses…)
2. Some LP modeling
techniques
Summary

Basics of LP modeling:

Modeling constraints
a. Percentages/proportions.
b. Simple averages.
c. Weighted averages.
d. Variable weighted averages.
e. Absolute value
Notation

} will denote
variables.

} will denote
constants.
a. Percentages/proportions

Percentage
is percent of .

Proportion
b. Simple averages
are linear
expressions:
Examples of constraints using simple average
c. Weighted averages

We can also directly write linear constraints...


d. Variable weighted averages

Examples: blending, mixing constraints, etc.


d. Variable weighted averages

Weights are nonlinear expressions in terms of the


variables!
Example of constraint (nonlinear version)
Example of constraint (linear version)
e. Absolute value
The constraint

is nonlinear.
But in general, we can write
We obtain two equivalent linear constraints
3. More LP modeling techniques
Modeling different
objective functions
Some objective functions we can model linearly
• Linear

• Absolute value

• Maximum
We will learn how to model these
objective functions by modelling
them in the special case of the
Assignment Problem.

However, the same methods can


be applied to other problems as
well!
The assignment problem
Ex: the assignment problem
There are 3 workers available and 3 tasks that must be completed. The
costs of the workers performing each of the tasks is given by:

Task 1 Task 2 Task 3


Worker 1 10 20 30
Worker 2 20 22 10
Worker 3 25 30 15

How to assign the workers to the tasks so we


minimize the overall cost?
Assume that workers can only be assigned to one of the tasks.
An optimization model
The classic assignment problem: data
1
1 ..
.. .
n . Assignment n
j
workers i jobs
.. Cost = cij ..
. (cij not
necessarilly
.
n positive) n

Each worker must be assigned to exactly one job and vice versa
The classic assignment problem: variables
1
1 ..
.. .
n . xij j n
workers i jobs
.. (Binary ..
. variable) .
n n
Linear Objective Function: the model

We already
know how to
model this
case
Linear Absolute value Objective Function: the model?

How to
model it?
A simpler example
Linear Absolute value Objective Function: the model
Linear Absolute value Objective Function: an application

How to
model it?
Exercise
Maximum of Linear Objective Functions: the model?

How to
model it?
A simpler example
Maximum of Linear Objective Functions: the model
A comment
This other model does
not model the
Maximum of (two) Linear
Objective Functions
It models a worse case cost
for every ij pair.
Summary

More LP modeling:

Modeling objective functions


a. Maximum and absolute value (minimization problem)
b. Minimum (maximization problem)
a. Maximum and absolute value
Example:
a. Maximum and absolute value
Example:

Nonlinear!!!

Can we model this as an LP?


Yes, we can model it as an LP

} These constraints
“represent” the
maximum.
Maximum in general (nonlinear)
Maximum in general (linear)
Example: Absolute value as objective function

Nonlinear!!!
But we can use

1.
2. The technique we used to linearize the
maximum of two linear functions.

Done!!!
b. Minimum in general (nonlinear)
Minimum in general (linear)
4. More LP modeling examples:
a.Production planning
b.Network flow models
a.Production planning

(http://cdn.wonderfulengineering.com/wp-
Example: Production planning + fixed cost
Data:
• T: number of periods • pt: unit production cost in t
• dt: demand in t • ft: setup cost in t
• s0: initial inventory

1 2 … t … T-1 T

To decide: production (xt) and inventory levels (st) at the


end of each period t=1,2,…,T.
Production planning
On each period t we will
have: amount
produced in t

inventory at the
t demand in t
beginning of t

inventory at the
end of t
Data:
Variables
On each period t we will have:
(Production
in t)
(Production cost)

(Inventory at the end of t-1)

t (Demand in t)

(Holding cost)

(Holding cost)

(Inventory at the end of t)


Objective function

(Production (Inventory
cost) cost)
Constraints
1. Nonnegativity:

2. Balance equation:

(Production in t) (Demand in t) (Inventory at


(Inventory at
the end of t)
the end of t-1)
The LP model
b. Network Flow problems
b.1.
Transportation
problems
Ex: Oil transportation
Cost per gallon, demand and availability (in gallons) are given by:

New York Chicago Atlanta Availability


Venezuela $100 $150 $90 90
Russia $190 $185 $170 60
Demand 50 40 60

Maximum amount that can be shipped from a country to


a city is 40 gallons.
In a picture: Demands
Costs
Supplies
NYC 50
90 $100
Venezuela
$150
$90
CHI 40
60 $190
Russia
$185
$170
ATL 60
Also, no more than 40 gallons per trip.
Variables:

(Notation: 1=Ven, 2=Rus and 1=NYC, 2=CHI, 3=ATL.)


LP Model

} Demand must be satisfied exactly.

} Resources must be completely


used .

} Bounds on variables
General transportation problem (data)
General transportation problem
(illustration)
1 d1
s1 1
.. ..
. .. .
cij . j dj
si i
.. uij ..
. .. .
sn n . m dm
General transportation problem (variables)
General transportation problem (LP model)

} Resources must be used


completely.

}
} Demand must be satisfied
exactly.
Bounds on
variables
Remark about feasibility
Feasibility requires:

(because of the equality constraints.)


What to do if that requirement is not satisfied?
(1)
1. If we have:

then:add dummy sink m+1 with

Demand
Costs
Upper bounds
Example
Application of the previous technique to
1 5
2 1 1, 15

3 2 2, 19

4 3, 17
3
Notation: uij, cij.
What to do if that requirement is not satisfied?
(2)
2. If we have:

then:add dummy source n+1 with

Source
Costs
Upper bounds
Special case: the assignment problem.
Example: FIFA World Cup 2014
1
1 ..
Soccer .. Assignment? .
matches . Stadiums
i j
.. ..
. .
Cost: cij
n n
The assignment problem (as transportation
problem).
The model:
(uij= 1, for all i,j)
1 1
1 1 ..
.. .. .
. cij .
1 i j 1
.. ..
. .. .
1 n .
n 1
General assignment problem (variables)

(In general, i and j could represent anything that needs


to be assigned.)
General assignment problem (LP model)

} j
i is assigned to exactly one

}
} j is assigned to exactly
one i
Bounds on
variables
The assignment problem is a nice LP
We would require
(Fractional
solution does not
make sense!)

But it can be shown


that: If we solve this LP by the Simplex method, we always

obtain integral solutions!!!


b.2 A more
complicated
example
Demand
70
Ex: Electricity distribution

House 1
40, 15
.
40, 5
Demand
Supply
100
Georgia
Power 40, 8
. N1
40, 8
40, 13
N2 40, 7 30

40, 26

Notation: capacity, cost.


.
40, 15

N3 40, 10
House 2
Network flow problem (variables)

Set of arcs:

A={(GP,N1),(GP,H1),(GP,N3),(N1,H1),
(N1,N2),(N1,N3),(H1,N2),(N2,H2),(N3,H2)}
Network flow problem (objective function)

(cij: the costs as given in the figure, ex: cGPH1=15)


Network flow problem (constraints)

1. Bounds on variables:
Network flow problem (constraints)

2. Flow conservation:

“OUTPUT - INPUT = 0”
Flow conservation at node GP

Flow conservation at node N1


Flow conservation at node N2

Flow conservation at node N3


Flow conservation at node H1

Flow conservation at node H2


If you want to learn how to
model: practice, practice,
practice, practice...

You might also like