Easy Mod Probs-Sol
Easy Mod Probs-Sol
One practical problem encountered during the DNA mapping process is that of compactly storing ex-
tremely long DNA sequences of the same length which do not differ greatly. We consider here a simplified
version of the problem with sequences
Pnof 2 symbols only (0 and 1). The Hamming distance between two
sequences a, b Fn2 is defined as i=1 |ai bi |, i.e. the number of bits which should be flipped to
transform a into b. For example, on the following set of 6 sequences below, the distance matrix is as
follows:
1. 011100011101
1 2 3 4 5 6
2. 101101011001
1 0 4 4 5 4 3
3. 110100111001 2 - 0 4 3 4 5
3 - - 0 5 2 5
4. 101001111101 4 - - - 0 3 6
5 - - - - 0 5
5. 100100111101
6 - - - - - 0
6. 010101011100
As long as the Hamming distances are not too large, a compact storage scheme can be envisaged where
we only store one complete sequence and all the differences which allow the reconstruction of the other
sequences. Explain how this problem can be formulated to find a spanning tree of minimum cost in a
graph. Solve the problem for the instance given above. [E. Amaldi, Politecnico di Milano]
Given a communication network the probability that a secret message is intercepted along a link con-
necting node i to j is pij . Explain how you can model the problem of broadcasting the secret message
to every node minimizing the interception probability as a minimum spanning tree problem on a graph.
[E. Amaldi, Politecnico di Milano]
19
Exercises Operations Research L. Liberti
A firm is planning the production of 3 products A1 ,A2 ,A3 . In a month production can be active for 22
days. In the following tables are given: maximum demands (units=100kg), price ($/100Kg), production
costs (per 100Kg of product), and production quotas (maximum amount of 100kg units of product that
would be produced in a day if all production lines were dedicated to the product).
Product A1 A2 A3
Maximum demand 5300 4500 5400
Selling price $124 $109 $115
Production cost $73.30 $52.90 $65.40
Production quota 500 450 550
1. Formulate an AMPL model to determine the production plan to maximize the total income.
2. Change the mathematical program and the AMPL model to cater for a fixed activation cost on the
production line, as follows:
Product A1 A2 A3
Activation cost $170000 $150000 $100000
3. Change the mathematical program and the AMPL model to cater for both the fixed activation cost
and for a minimum production batch:
Product A1 A2 A3
Minimum batch 20 20 16
A firm is planning the production of 3 products A1 , A2 , A3 over a time horizon of 4 months (january to
april). Demand for the products over the months is as follows:
Prices, production costs, production quotas, activation costs and minimum batches (see Ex. 4.3 for
definitions of these quantities) are:
Product A1 A2 A3
Unit 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
Production planning 20
Exercises Operations Research L. Liberti
There are 23 productive days in january, 20 in february, 23 in march and 22 in april. The activation
status of a production line can be changed every month. Minimum batches are monthly.
Moreover, storage space can be rented at monthly rates of $3.50 for A1 , $4.00 for A2 and $3.00 for
A3 . Each product takes the same amount of storage space. The total available volume is 800 units.
Write a mathematical program to maximize the income, and solve it with AMPL. [E. Amaldi, Po-
litecnico di Milano]
4.5 Transportation
An Italian transportation firm should carry some empty containers from its 6 stores (in Verona, Perugia,
Rome, Pescara, Taranto and Lamezia) to the main national ports (Genoa, Venice, Ancona, Naples, Bari).
The container stocks at the stores are the following:
Empty containers
Verona 10
Perugia 12
Rome 20
Pescara 24
Taranto 18
Lamezia 40
Container demand
Genoa 20
Venice 15
Ancona 25
Naples 33
Bari 21
Transportation is carried out by a fleet of lorries. The transportation cost for each container is propor-
tional to the distance travelled by the lorry, and amounts to 30 euro / km. Every lorry can carry at most
2 containers. Distances are as follows:
Write a mathematical program to find the minimal cost transportation policy and solve it with AMPL.
[E. Amaldi, Politecnico di Milano]
A project consists of the following 7 activities, whose length in days is given in brackets: A (4), B (3),
C (5), D (2), E (10), F (10), G (1). The following precedences are also given: A G, D; E, G F ;
D, F C; F B. Each day of work costs 1000 euros; furthermore a special machinery must be rented
from the beginning of activity A to the end of activity B at a daily cost of 5000 euros. Formulate this as
an LP problem and suggest an algorithm for solving it. [F. Malucelli, Politecnico di Milano]
A museum director must decide how many guards should be employed to control a new wing. Budget cuts
have forced him to station guards at each door, guarding two rooms at once. Formulate a mathematical
program to minimize the number of guards. Solve the problem on the map below using AMPL.
J
I
E
F
H G
D
A
B C
M H
S L
R Q N
J G
K
T P O
I
W D
X U C E
A
Y Z B F
4.8 Inheritance
Inheritance 22
Exercises Operations Research L. Liberti
Two very precious Jack Russell race dogs: 3000$ each (the will asserts that they may not be
separated)
which must be shared between the two sons. What is the partition that minimizes the difference between
the values of the two parts? Formulate a mathematical program and solve it with AMPL. [P. Belotti,
Carnegie Mellon]
4.9 Carelland
The independent state of Carelland mainly exports four goods: steel, engines, electronic components
and plastics. The Chancellor of the Exchequer (a.k.a. the minister of economy) of Carelland wants
to maximize exports and minimize imports. The unit prices on the world markets for steel, engines,
electronics and plastics, expressed in the local currency (the Klunz) are, respectively: 500, 1500, 300,
1200. Producing 1 steel unit requires 0.02 engine units, 0.01 plastics units, 250 Klunz in other imported
goods and 6 man-months of work. Producing 1 engine unit requires 0.8 steel units, 0.15 electronics units,
0.11 plastics units, 300 Klunz in imported goods and 1 man-year. One electronics unit requires: 0.01 steel
units, 0.01 engine units, 0.05 plastics units, 50 Klunz in imported goods and 6 man-months. One plastics
unit requires: 0.03 engine units, 0.2 steel units, 0.05 electronics units, 300 Klunz in imported goods and
2 man-years. Engine production is limited to 650000 units, plastics production to 60000 units. The
total available workforce is 830000 each year. Steel, engines, electronics and plastics cannot be imported.
Write a mathematical program that maximizes the gross internal product and solve the problem with
AMPL. [G. Carello, Politecnico di Milano]
10 tasks must be run on 3 CPUs at 1.33, 2 and 2.66 GHz (each processor can run only one task at a
time). The number of elementary operations of the tasks (expressed in billions of instructions (BI)) is as
follows:
process 1 2 3 4 5 6 7
BI 1.1 2.1 3 1 0.7 5 3
Schedule tasks to processors so that the completion time of the last task is minimized. Solve the problem
with AMPL.
CPU Scheduling 23
Exercises Operations Research L. Liberti
A fabric dyeing plant has 3 dyeing baths. Each batch of fabric must be dyed in each bath in the order:
first, second, third bath. The plant must colour five batches of fabric of different sizes. Dyeing batch i in
bath j takes a time sij expressed in hours in the matrix below:
3 1 1
2 1.5 1
3 1.2 1.3 .
2 2 2
2.1 2 3
Schedule the dyeing operations in the baths so that the ending time of the last batch is minimized.
4.12 Parking
On Dantzig Street cars can be parked on both sides of the street. Mr. Edmonds, who lives at number 1,
is organizing a party for around 30 people, who will arrive in 15 cars. The length of the i-th car is i ,
expressed in meters as follows:
i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
i 4 4.5 5 4.1 2.4 5.2 3.7 3.5 3.2 4.5 2.3 3.3 3.8 4.6 3
In order to avoid bothering the neighbours, Mr. Edmonds would like to arrange the parking on both sides
of the street so that the length of the street occupied by his friends cars should be minimum. Give a
mathematical programming formulation and solve the problem with AMPL.
How does the program change if on exactly one of the street sides the cars should not occupy more
than 15m?
Parking 24
Chapter 11
Consider a complete undirected graph G = (V, E) where each vertex is a sequence and the weight of an
edge {i, j} E is given by the Hamming distance between sequence i and sequence j. To each edge
{i, j} E we also associate the sequence of bit flips necessary to transform sequence i into sequence j.
A minimum cost spanning tree in G provides the most economical way to recover all possible sequences
starting from only one of these sequences.
The instance in the exercise yields a minimum spanning tree having cost 15.
5
1
4
4
3 3 5
2 4 5
4 5 6
4 2
6
5
3
The communication network is represented by a directed graph G = (V, A). Each arc (i, j) is weighted
by its probability 1 pij that the the message is not intercepted along the arc. In order to broadcast
the message to all nodes we want to find a subset of arcs which is connected, reaches all nodes, and has
no cycle (otherwise the interception probability might increase). In other words, a spanning tree. The
spanning tree T should maximize the chances that the message arrives at each node without interception,
71
Solutions Operations Research L. Liberti
i.e.: Y
max { (1 pij ) | T spanning tree}. (11.1)
all T {i,j}T
Since the Prim (and Kruskal) algorithms for finding optimum spanning trees deal with the case when the
cost of the tree is the sum of the costs of the edges, we cannot use those algorithms to solve the problem.
However, we can reformulate Q the problem by requiring the spanning tree T which maximizes the
modified objective function log {i,j}T (1 pij ). This will change the value of the objective function
associated to the solution but not the solution itself, since the log function is monotonic increasing.
Y
log max { (1 pij ) | T spanning tree} =
all T {i,j}T
Y
= max {log (1 pij ) | T spanning tree} =
all T {i,j}T
X
= max { log(1 pij ) | T spanning tree}.
all T {i,j}T
The latter is a proper minimum spanning tree problem on the graph G where each arc (i, j) A is
weighted by log(1 pij ), and can be solved using either Prims algorithm.
11.3.1 Formulation
Indicex: Let i be an index on the set {1, 2, 3}.
Parameters:
P : number of production days in a month;
di : maximum market demand for product i;
vi : selling price for product i;
ci : production cost for product i;
qi : maximum production quota for product i;
ai : activation cost for the plant producing i;
li : minimum batch of product i.
Variables:
xi : quantity of product i to produce (xi 0);
yi : activation status of product i (1 if active, 0 otherwise).
Objective function: X
max ((vi ci )xi ai yi )
i
Constraints:
1. (demand): for each i, xi di ;
P xi
2. (production): i qi P ;
# mixedproduction.mod
set PRODUCTS;
subject to production:
sum {i in PRODUCTS} (x[i] / quota[i]) <= days;
# mixedproduction.dat
set PRODUCTS := A1 A2 A3 ;
# mixedproduction.run
model mixedproduction.mod;
data mixedproduction.dat;
option solver cplexstudent;
solve;
display x;
display y;
ampl: display y;
y [*] :=
A1 0
A2 1
A3 1
;
11.4.1 Formulation
Indices:
i: an index on the set = {A1 , A2 , A3 };
j: an index on the set = {1, 2, 3, 4}.
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;
li : minimum batch for production i;
mi : storage cost for product i;
C: storage capacity in number of units.
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: (1=active, 0=inactive).
All variables are constrained to be non-negative. yij are binary variables.
Objective function:
3
X 4
X 4
X 4
X 4
X
max vi wij ci xij mi zij ai yij .
i=1 j=1 j=1 j=1 j=1
Constraints:
1. (requirement): for each i, j: wij dij ;
P3 xij
2. (production): per each j: i=1 qi Pj ;
# productionplan.mod
set PRODUCTS;
param Months;
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]) ;
# productionplan.dat
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 ;
# productionplan.run
model productionplan.mod;
data productionplan.dat;
option solver cplexstudent;
solve;
option display_round 4;
display revenue;
display x;
display y;
quit;
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 ;
11.5.1 Formulation
Indices:
i: index on the set {1, . . . , M } (stores);
j: index on the set {1, . . . , P } (ports);
Parameters:
mi : availability (in number of containers) at i-th store;
rj : demand at j-th port;
dij : distance between store i and port j;
C: unit transportation cost (per km).
Variables:
xij : number of containers sent from store i to port j;
yij : number of lorries travelling from store i to port j;
All variables are constrained to be non-negative.
Objective function:
M X
X P
min Cdij yij
i=1 j=1
Constraints:
PP
1. (store availability) for each i M : j=1 xij mi ;
PM
2. (port demand) for each j P : i=1 xij rj ;
3. (lorry capacity) for each i M , j P , 2yij xij .
Transportation: Solution 77
Solutions Operations Research L. Liberti
# transportation.mod
set STORES;
set PORTS;
minimize cost:
sum {i in STORES, j in PORTS} costkm * distance[i,j] * y[i,j];
# transportation.dat
param availability :=
Verona 10
Perugia 12
Rome 20
Pescara 24
Taranto 18
Lamezia 40 ;
param demand :=
Genoa 20
Venice 15
Ancona 25
Naples 33
Bari 21 ;
param distance :
Genoa Venice Ancona Naples Bari :=
Verona 290 115 355 715 810
Perugia 380 340 165 380 610
Rome 505 530 285 220 450
Pescara 655 450 155 240 315
Taranto 1010 840 550 305 95
Lamezia 1072 1097 747 372 333 ;
Transportation: Solution 78
Solutions Operations Research L. Liberti
# transportation.run
model transportation.mod;
data transportation.dat;
option solver cplexstudent;
solve;
option display_round 4;
display cost;
display x;
display y;
x [*,*]
: Ancona Bari Genova Napoli Venezia :=
Lamezia 0.0000 4.0000 0.0000 26.0000 0.0000
Perugia 1.0000 0.0000 6.0000 0.0000 5.0000
Pescara 24.0000 0.0000 0.0000 0.0000 0.0000
Roma 0.0000 0.0000 14.0000 6.0000 0.0000
Taranto 0.0000 17.0000 0.0000 1.0000 0.0000
Verona 0.0000 0.0000 0.0000 0.0000 10.0000
;
y [*,*]
: Ancona Bari Genova Napoli Venezia :=
Lamezia 0.0000 2.0000 0.0000 13.0000 0.0000
Perugia 1.0000 0.0000 3.0000 0.0000 3.0000
Pescara 12.0000 0.0000 0.0000 0.0000 0.0000
Roma 0.0000 0.0000 7.0000 3.0000 0.0000
Taranto 0.0000 9.0000 0.0000 1.0000 0.0000
Verona 0.0000 0.0000 0.0000 0.0000 5.0000
;
The precedence graph G = (V, A) (which associates to each arc an activity) is as follows.
E F
3 4 6 B
10 10
0 0 3 7
C
A D
1 2 5 5
4 1
To each vertex i V we associate a variable ti (the starting time of the activities represented by arcs in
+ (i). The mathematical programming formulation of the problem is:
min t7 t1 + 5000(t4 t2 )
ti + dij tj (i, j) A,
The problem can be formalized by representing each museum room by a vertex v V of an undirected
graph G = (V, E). There is an edge between two vertices if there is a door leading from one room to
the other; this way, edges represent the possibility of there being a guard on a door. We want to choose
the smallest subset F E of edges covering all vertices, i.e. such that for all v V there is w V with
{v, w} F .
J
I
E
I J E
F
H G
D
H G F D
A
B C
B A C
To each {i, j} E we associated a binary variable xij is assigned the value 1 if there is a guard on the
door represented by edge {i, j} and 0 otherwise.
11.7.1 Formulation
Parameters. G = (V, A): graph description of the museum topology.
Objective function X
min xij
{i,j}E
P
Constraints. (Vertex cover): xij 1 i V .
jV :{i,j}E
# museum.mod
# museum.dat
param n := 10;
set E :=
1 2
1 3
1 6
1 7
2 8
3 4
4 5
7 9
8 9
9 10 ;
# museum.run
model museum.mod;
data museum.dat;
option solver cplexstudent;
solve;
display cost;
display x;
x :=
1 2 0
1 3 1
1 6 1
1 7 1
2 8 1
3 4 0
4 5 1
7 9 0
8 9 0
9 10 1
;
The problem may be formalized as follows: given a set A of n elements each with an evaluation function
v : A R, we want to find a partition of A in A1 , A2 such that
X X
|v(A1 ) v(A2 )| = | v(a) v(a)|
aA1 aA2
It can be modelled using mathematical programming by introducing binary variables xa , ya for each
a A, such that xa = 1 and ya = 0 if object a is assigned to brother x, and xa = 0 and ya = 1 if a is
assigned to y. We naturally need the constraint
a A (xa + ya = 1).
which ensures that the inheritance is split between the two brothers as fairly as possible. Because of the
absolute value, this formulation is nonlinear.
P
Let V = aA v(a) be the total value of the inheritance. The Subset-Sum can also be described as
follows:
maximize the inheritance assigned to one of the brothers with the constraint that it should not
exceed V /2;
minimize the inheritance assigned to one of the brothers with the constraint that it should not be
less than V /2.
P
min va xa
aA
V
P P
s.t. va xa 2 va
aA aA
a A xa {0, 1}
# subsetsum.mod
param n;
param v {1..n};
param V := sum {i in 1..n} v [i];
var x {1..n} binary;
minimize cost: sum {i in 1..n} v[i] * x[i];
subject to limit: sum {i in 1..n} v [i]* x[i] >= 0.5 * V;
Inheritance: Solution 82
Solutions Operations Research L. Liberti
# subsetsum.dat
param n := 13;
param: v :=
1 25000
2 5000
3 20000
4 40000
5 12000
6 12000
7 12000
8 3000
9 6000
10 10000
11 15000
12 10000
13 13000;
# subsetsum.run
model subsetsum.mod;
data subsetsum.dat;
option solver cplexstudent;
solve;
display cost;
display x;
x [*] :=
1 1
2 0
3 1
4 0
5 0
6 0
7 0
8 1
9 1
10 0
11 1
12 1
13 1
;
Miximize the profits (exported quantities - produced quantities) subject to the constraints on production,
amount of work and balance between produced and exported products.
Carelland: Solution 83
Solutions Operations Research L. Liberti
11.9.1 Formulation
Parameters:
P : set of products;
Variabili:
Model:
X X
max pi y i mi xi
iP iP
X
hi xi H
iP
xi Mi i P
ya + 0.8xm + 0.01xe + 0.2xp = xa
ym + 0.02xa + 0.01xe + 0.03xp = xm
ye + 0.15xm + 0.05xp = xe
yp + 0.01xa + 0.11xm + 0.05xe = xp
xi , yi 0 i P
# carelland.mod
set PRODUCTS;
Carelland: Solution 84
Solutions Operations Research L. Liberti
maximize klunz:
sum {i in PRODUCTS} (p[i]*y[i] - m[i]*x[i]);
subject to work:
sum {i in PRODUCTS} h[i]*x[i]<=HMan;
# carelland.dat
# carelland.run
model carelland.mod;
data carelland.dat;
option solver cplexstudent;
solve;
display profit;
display x;
display y;
x [*] :=
electronics 74375
engines 475833
plastics 60000
steel 393958
;
Carelland: Solution 85
Solutions Operations Research L. Liberti
y [*] :=
electronics 0
engines 465410
plastics 0
steel 547.917
;
Parameters:
Variables:
Objective function:
min W
Constraints:
P bi
(lengths) i P (Li = sk zik );
kC
(times) i P (ti + Li W )
P
(assignment) i P ( zik = 1);
kC
P
(cpudef) i P (yi = kzik )
kC
# cpuscheduling.mod
minimize makespan: W;
subject to hnonoverlapping{i in P, j in P : i != j} :
x[j] - x[i] - L[i] - (sigma[i,j] - 1) * Wmax >= 0;
subject to vnonoverlapping{i in P, j in P : i != j} :
y[j] - y[i] - 1 - (epsilon[i,j] - 1) * p >= 0;
subject to atleastone{i in P, j in P : i != j} :
sigma[i,j] + sigma[j,i] + epsilon[i,j] + epsilon[j,i] >= 1;
subject to hatmostone{i in P, j in P : i != j} :
sigma[i,j] + sigma[j,i] <= 1;
subject to vatmostone{i in P, j in P : i != j} :
epsilon[i,j] + epsilon[j,i] <= 1;
# cpuscheduling.dat
param p := 7;
param c := 3;
param : b :=
1 1.1
2 2.1
3 3.0
4 1.0
5 0.7
6 5.0
7 3.0 ;
param : s :=
1 1.33
2 2.00
3 2.66 ;
# cpuscheduling.run
model cpuscheduling.mod;
data cpuscheduling.dat;
option solver cplexstudent;
solve;
display makespan;
for{k in C} {
printf "CPU %d : ", k;
for{i in P : z[i,k] = 1} {
printf "[%d:%f] ", i, x[i];
}
printf "\n";
}
Constraints:
# dyeing.mod
param l >= 1;
param v >= 1;
set L := 1..l;
set V := 1..v;
set V0 := 1..v-1;
minimize makespan : T;
subject to nonoverlap{i in L, j in L, k in V : i != j} :
t[i,k] + s[i,k] <= t[j,k] + M * (1 - y[i,j,k]);
subject to disjunction{i in L, j in L, k in V : i != j} :
y[i,j,k] + y[j,i,k] = 1;
# dyeing.dat
param l := 5;
param v := 3;
param s : 1 2 3 :=
1 3.0 1.0 1.0
2 2.0 1.5 1.0
3 3.0 1.2 1.3
4 2.0 2.0 2.0
5 2.1 2.0 3.0 ;
# dyeing.run
model dyeing.mod;
data dyeing.dat;
option solver cplexstudent;
solve;
display makespan;
for {i in L} {
Parameters:
i : length of car i;
L: upper bound on the car line length;
: upper bound for the sum of car lengths.
Variables:
Objective function:
min max tj .
jM
Constraints:
P
(car line length definition) j M (tj = i xij );
iN
P
(assignment of cars to lines) i N ( xij = 1);
jM
Parking: Solution 90
Solutions Operations Research L. Liberti
# parking.mod
param n > 0;
param m > 0;
set N := 1..n;
set M := 1..m;
minimize minmaxobj: T;
subject to carlinedef {j in M} :
t[j] = sum{i in N} lambda[i] * x[i,j];
# parking.dat
param n := 15;
param m := 2;
param L := 15;
param : lambda :=
1 4.0
2 4.5
3 5.0
4 4.1
5 2.4
6 5.2
7 3.7
8 3.5
9 3.2
10 4.5
11 2.3
12 3.3
13 3.8
14 4.6
15 3.0 ;
Parking: Solution 91
Solutions Operations Research L. Liberti
# parking.run
model parking.mod;
data parking.dat;
option solver cplexstudent;
solve;
display minmaxobj;
for {j in M} {
printf "line %d (length = %f) : ", j, sum{i in N : x[i,j] = 1} lambda[i];
for {i in N : x[i,j] = 1} {
printf "%d ", i;
}
printf "\n";
}
Parking: Solution 92