Mathematical Programming: Modelling and Applications September 2009 - - PowerPoint PPT Presentation
Mathematical Programming: Modelling and Applications September 2009 - - PowerPoint PPT Presentation
Mathematical Programming: Modelling and Applications September 2009 Sonia Cafieri LIX, cole Polytechnique cafieri@lix.polytechnique.fr Outline Some basic AMPL useful operations & commands A modelling problem Formulation of
2
Outline
Some basic AMPL useful operations & commands A modelling problem Formulation of the mathematical model The AMPL model Solution of the problem
3
AMPL basic set operations
These operations become useful or necessary in many problems
- Let A, B, and U be sets
- AMPL allows simple set operations:
Union:
U = A union B elements of A or B
Intersection:
U = A inter B elements of A and B
Difference:
U = A diff B elements of A and not of B
Union: Example
ampl: set MONTHS := {1,2,3,4}; ampl: set MONTHS0 := {0} union MONTHS; ampl: display MONTHS0; set MONTHS0 := 0 1 2 3 4;
4
AMPL commands
AMPL recognizes a lot of commands.
- Some commands you already know are, e.g.:
- model:
switch to model mode
- data:
switch to data mode
- exit:
exit AMPL
- display:
print model entities and expressions
- let:
change data values
- ……
- Other useful commands:
- fix:
freeze a variable at its current value
- unfix:
undo a fix command
- delete:
delete model entities
- purge:
delete model entities and their dependents
5
AMPL commands
Note that fix, unfix, delete, purge,.. are used for changing a model : it is possible in AMPL modifying models and data.
Fix: Example
fix varname
- This command instructs AMPL to treat the indicated variable as though fixed
at its current value (e.g. in solve command): we have a constant.
- If varname is the name of an indexed collection of variables, fix (and unfix)
affects all members of the collection.
- Fixing a variable we have a further constraint in the problem.
6
AMPL commands: fix
ampl: var y{1..4} >=1; ampl: let y[3] := 10; ampl: fix y[3]; ampl: display y[3]; y[3] = 10 ampl: minimize somma: sum{i in 1..4} y[i]; ampl: option solver cplex; ampl: solve; ILOG CPLEX 10.100, licensed to "ecolepolytechnique-palaiseau",
- ptions: e m b q use=8
CPLEX 10.1.0: optimal solution; objective 13 0 dual simplex iterations (0 in phase I) ampl: display y; y [*] := 1 1 2 1 3 10 4 1 ;
7
Production planning problem
A firm is planning the production of 3 products A1, A2, A3 over a time horizon of 4 months (January to April). We know:
- The demand for the products over the 4 months;
- Prices, production costs, production quotas, activation costs and
minimum batches for each product; Furthermore:
- There is a different number of productive days over the 4 months;
- The activation status of a production line can be changed every month.
- Minimum batches are monthly.
- Each product needs to be stored. There are different monthly rates for
renting the storage space for each product.
- Each product takes the same amount of storage space.
The total available volume is given.
8
Production planning problem: data
Demand for the products over the months:
Demand January February March April A1 5300 1200 7400 5300 A2 4500 5400 6500 7200 A3 4400 6700 12500 13200
Prices, production costs, production quotas, activation costs and minimum batches:
Product A1 A2 A3 Selling prices $124 $109 $115 Activation costs $150000 $150000 $100000 Production costs $73.30 $52.90 $65.40 Production quotas 500 450 550 Minimum batches 20 20 16
9
Production planning problem: data
Write a mathematical program to maximize the income, and solve it with AMPL. Number of productive days over the months:
January 23 February 20 March 23 April 22
Monthly rates for storage space:
A1 $3.50 A2 $4.00 A3 $3.00
Total available volume: 800 units.
10
Writing the mathematical model
Preliminary observations:
- There are some quantities (parameters) defined
for each product : selling price, production cost, production quota, activation cost, minimum batch, storage cost for each month: number of production days for each product and each month: maximum demand for each product in each month independently on product/month: storage capacity.
- Furthermore:
For each product, there is a different quantity produced, sold, stocked during each month and the activation status of each production line is also dependent on the months.
11
Writing the mathematical model
Sets and indices:
- 3 products use an index
- 4 months use an index
define parameters / variables indexed on
I i ∈ J j ∈ j i,
What decisions should we take?
quantity produced product , month quantity sold quantity stocked also take into account the activation status
i j
12
Mathematical model
- Parameters
Pj : number of production days in month j; dij : maximum demand for product i in month j; vi : selling price for product i; ci: production cost of product i; qi : maximum production quota of product i; ai : activation cost for production i; bi : minimum batch for production i; si : storage cost for product i; C: storage capacity in number of units.
13
Mathematical model
- Variables
xij : quantity of product i produced during month j; wij : quantity of product i sold during month j; zij : quantity of product i stocked during month j; yij : activation status for production i during month j; yij binary
⎩ ⎨ ⎧ =
- therwise
month during active is product if 1 j i yij
All variables are non negative
- Objective function
∑ ∑ ∑ ∑ ∑
∈ ∈ ∈ ∈ ∈
⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ − − −
I i J j J j J j J j ij i ij i ij i ij i
y a z s x c w v max
maximize the total income total income: 3 products – sum income obtained during each month
14
Mathematical model
- Constraints
- demand:
- production:
- balance:
- capacity:
- activation:
- minimum batch:
- december:
ij ij
d w J j I i ≤ ∈ ∈ ∀ ,
j I i i ij
P q x J j ≤ ∈ ∀
∑
∈ ij ij ij j i
w z x z J j I i + = + ∈ ∈ ∀
−1 ,
, C z J j
I i ij ≤
∈ ∀
∑
∈ ij i j ij
y q P x J j I i ≤ ∈ ∈ ∀ ,
ij i ij
y b x J j I i ≥ ∈ ∈ ∀ ,
0 =
∈ ∀
i
z I i
15
AMPL model – production planning
Starting from the mathematical formulation, try to code the AMPL model We have 2 indices for many variables/constraints:
i (products): A1, A2, A3 j (months): 1,2,3,4 It is useful to define 2 sets: set PRODUCTS; param Months; set MONTHS := 1..Months
We also have zi0 -- index 0
set MONTHS0 := MONTHS union {0}
16
AMPL model – production planning
Now we can define the parameters:
all parameters are non negative
param days{MONTHS} >= 0; param demand { PRODUCTS, MONTHS } >= 0; param price { PRODUCTS } >= 0; param cost { PRODUCTS } >= 0; param quota { PRODUCTS } >= 0; param activation { PRODUCTS } >= 0; param batch { PRODUCTS } >= 0; param storage { PRODUCTS } >= 0; param capacity >= 0;
Variables:
var x { PRODUCTS, MONTHS } >= 0; var w { PRODUCTS, MONTHS } >= 0; var z { PRODUCTS, MONTHS0 } >= 0; var y { PRODUCTS, MONTHS } >= 0, binary;
17
maximize revenue: sum {i in PRODUCTS} (price[i] * sum {j in MONTHS} w[i,j] - cost[i] * sum {j in MONTHS} x[i,j]
- storage[i] * sum {j in MONTHS} z[i,j]
- activation[i] * sum {j in MONTHS} y[i,j]) ;
Constraints:
subject to requirement {i in PRODUCTS, j in MONTHS}: w[i,j] <= demand[i,j]; subject to production {j in MONTHS}: sum {i in PRODUCTS} (x[i,j] / quota[i]) <= days[j]; subject to balance {i in PRODUCTS, j in MONTHS}: z[i,j-1] + x[i,j] = z[i,j] + w[i,j]; subject to capacitymag {j in MONTHS}: sum {i in PRODUCTS} z[i,j] <= capacity; subject to active {i in PRODUCTS, j in MONTHS}: x[i,j] <= days[j]*quota[i]*y[i,j]; subject to minbatch {i in PRODUCTS, j in MONTHS}: x[i,j] >= batch[i]*y[i,j];
AMPL model – production planning
Objective function:
18
AMPL dat – production planning
set PRODUCTS := A1 A2 A3 ; param Months := 4 ; param days := 1 23 2 20 3 23 4 22 ; param demand: 1 2 3 4 := A1 5300 1200 7400 5300 A2 4500 5400 6500 7200 A3 4400 6700 12500 13200 ; param : price cost quota activation batch storage := A1 124 73.30 500 150000 20 3.5 A2 109 52.90 450 150000 20 4 A3 115 65.40 550 100000 16 3 ; param capacity := 800 ; let {i in PRODUCTS} z[i,0] := 0; fix {i in PRODUCTS} z[i,0];
19
AMPL run – production planning
model productionplanning.mod; data productionplanning.dat;
- ption solver cplex;
solve;
- ption display_round 4;
display revenue; display x; display y;
20
Solution – production planning
ILOG AMPL 10.100, licensed to "ecolepolytechnique-palaiseau". AMPL Version 20060626 (Linux 2.6.9-5.ELsmp) ILOG CPLEX 10.100, licensed to "ecolepolytechnique-palaiseau", options: e m b q use=8 CPLEX 10.1.0: optimal integer solution; objective 1581550 33 MIP simplex iterations 0 branch-and-bound nodes revenue = 1581550.0000 x := A1 1 6100.0000 A1 2 0.0000 A1 3 0.0000 A1 4 0.0000 A2 1 0.0000 A2 2 3518.1818 A2 3 0.0000 A2 4 0.0000 A3 1 4400.0000 A3 2 6700.0000 A3 3 12650.0000 A3 4 12100.0000 ; y := A1 1 1.0000 A1 2 0.0000 A1 3 0.0000 A1 4 0.0000 A2 1 0.0000 A2 2 1.0000 A2 3 0.0000 A2 4 0.0000 A3 1 1.0000 A3 2 1.0000 A3 3 1.0000 A3 4 1.0000 ;