NetworkFlowExerciseCorrection
NetworkFlowExerciseCorrection
2 6
s 1 5 6 1 7 4 6
8 2
0
3 5
Solution
Table 1 reports the label setting in all iterations of Dijkstra’s algorithm applied
to the problem instance. Each row of the table corresponds to an iteration, while
each column correspond to a node of the network. The entry at row i and column
j of the table is the label assigned to node j of the network in iteration i. Each
blue entry corresponds to a distance update, and each red entry corresponds to
a permanent label.
Following the result in Table 1, there are 8 distance updates (8 blue entries
in the table) during the execution of the algorithm.
Exercise 2. (i) Given a directed network G = (N, A) with arc length cij associ-
ated with each arc (i, j) ∈ A. Formulate the shortest path problem from a source
node s to a target node t in the network as an integer programming formulation.
(ii) Consider the network given in Exercise 1 with source node s = 1 and target
node t = 5. Implement the formulation obtained in part (i) for this problem
instance by using ZIMPL.
1
2
Solution
(i) Let xij be an indicator variable for whether arc (i, j) is part of the shortest
path from s to t. It means that
{
1 if arc (i, j) is in the shortest path from s to t,
xij =
0 otherwise.
We wish to select the set of arcs with minimal total length, subject to the con-
straint that this set forms a path from s to t. We come up with the following
formulation.
∑
min cij xij (1)
(i,j)∈A
∑ ∑
s.t. xij − xji = 0 ∀i ∈ N \{s, t} (2)
(i,j)∈A (j,i)∈A
∑ ∑
xsj − xjs = 1 (3)
(s,j)∈A (j,s)∈A
∑ ∑
xtj − xjt = −1 (4)
(t,j)∈A (j,t)∈A
The sum in (1) equals the total length of selected arcs, which need to be min-
imized. The constraint of forming a path imposes that, for all network nodes
except for s and t, the number of incoming and outgoing arcs that are part of
the path must be the same. This is represented by (2), due to the fact that the
first sum in (2) equals the number of outgoing arcs from a node i that are in the
path, while the second sum in (2) equals the number of incoming arcs to node i
that are in the path. Note that for the source node s there is only one outgoing
arc and no incoming arc that are part of the path, and for the target node t there
is only one incoming arc and no outgoing arc that are part of the path. This
is represented by (3) and (4), respectively. Indeed, since we are minimizing the
objective function (1) with non-negative coefficients cij , it is guaranteed by (3)
that its first sum (the number of outgoing arcs from the source s that are in the
3
path) must be 1, and the second sum (the number of incoming arcs to the source
s that are in the path) must be 0. The similar arguments applied to target node
t give rise of (4).
(ii) We need two input data files for the ZIMPL model of the shortest path
problem. The first data file contains the information about the network nodes.
Each line of this file consists of two information fields: the name of a node and
a number representing its role in the path. More precisely, the source node will
be assigned with number 1, the target node will be assigned with number -1,
while the other nodes are assigned with number 0 (this corresponds to the right
hand sides in (2) - (4)). The second data file contains the information about the
network arcs and their corresponding lengths. Each line of this file consists of
three information fields related to each arc: the node starts the arc, the node
ends the arc, and the arc length.
ZIMPL data file Nodes.dat corresponds to the network in Exercise 1.
1 # Node Role
2 1 1
3 2 0
4 3 0
5 4 0
6 5 -1
7 6 0
17 # Variables
18 # x[i, j] = 1 if arc (i, j) is in the shorstest path from
source node to target node , = 0 otherwise
19 var x[Arcs] binary;
20
21 ## Modeling objective
22 minimize PathLength : sum <i, j> in Arcs: Length [i, j] * x[i, j
];
23
24 ## Modeling constraints
25
• fij : the fixed cost of inspecting a batch after stage j, given that we last
inspected the batch after stage i.
Solution
We construct a directed network with n + 1 nodes numbered 0, 1, . . . , n. The
network contains an arc (i, j) for each pair of nodes i and j for which i < j. Each
path in the network from node 0 to node n defines an inspection plan (note that
the production line ends with an inspection station in order to scrap defective
items before shipping). For example, the path 0 − i − n implies that we inspect
the batches after the ith stage and the last stage.
Since the product enters production line from stage 1 in batches of size B > 1,
and the probability of producing a defect at stage i is αi , the number of non-
defective units at the end of stage i is
∏
i
B(i) = B (1 − αi ).
k=1
If we inspect the batch right after stage i and the next one is stage j, then the total
cost incurred after stage i until stage j (i.e., stages i + 1, i + 2, . . . , j) composes
of the following parts.
• The fixed cost fij of inspecting a batch after stage j given that we last
inspected the batch after stage i.
• Since after stage i we have B(i) non-defective units, and since the manu-
facturing cost per unit in stage k is pk , the manufacturing cost after stage
i until stage j is
∑j
B(i) pk .
k=i+1
We associate a cost cij to each arc (i, j) in the network, in which cij is the total
cost incurred after stage i until stage j. By the above discussion, we have
∑
j
cij = fij + B(i) pk .
k=i+1
Max-flow problem
Exercise 4. Solve the maximum flow problem shown in Figure 2 using augment-
ing path algorithm (the number besides each arc represents the arc capacity).
Specify the residual network before each augmentation.
1
2 4
2 2
1 1 2 1 6
s t
2 1
1
3 5
Solution
In the figures representing algorithm steps, the numbers in red show the flow
units transfering through the associated arcs in the network.
We start by sending no flow unit from s to t through the network. Figure
3(a) shows the zero flow in the network, and the corresponding residual network
coincides with the original network (Figure 3(b)).
1 1
2 4 2 4
0
2 2 2 2
0 0
1 1 0 2 0 1 6 1 1 2 1 6
0
s 0 t s t
0
2 1 2 1
1 1
3 5 3 5
0
(a) Zero flow. (b) Residual network at Step 1.
Let us choose the augmenting path 1−3−4−6 in the residual network at Step
1. The residual capacity of this augmenting path equals the minimum residual
capacity of the arcs in the path, and it is 2. Therefore, we augment 2 flow units
through this path (Figure 4(a)) and obtain the corresponding residual network
in Figure 4(b).
We now choose the augmenting path 1 − 2 − 4 − 5 − 6 in the residual network
at Step 2. This path has the residual capacity 1, so we can augment 1 flow units
7
1 1
2 4 2 4
0
2 2 2
0 2 2
1 1 0 2 0 1 6 1 1 1 6
2 2
s 2 t s 2 t
0
2 1 1
1 1
3 5 3 5
0
(a) Flow in Step 2. (b) Residual network at Step 2.
1 1 0 2 1 1 6 1 1 1 6
2 2
s 2 t s 2 t
1 1
2 1
1 1
3 5 3 5
0
(a) Flow in Step 3. (b) Residual network at Step 3.
through this path (Figure 5(a)) and obtain the corresponding residual network
in Figure 5(b).
After Step 3, no augmenting path is found in the residual network. Therefore,
an optimal solution to the maximum flow problem is given in Figure 5 (a), with
the flow value is 3.
Exercise 5. Given a directed network G = (N, A) with arc capacity cij associated
with each arc (i, j) ∈ A. Formulate the max-flow problem from a source node s
to a sink node t in the network as an integer programming formulation.
Solution
Let xij be the flow units transfering through arc (i, j) of the network. We
wish to send the maximum flow from the source node s to the sink node t subject
to the arc capacities and flow conversation at every other nodes. We come up
with the following formulation.
max v (6)
∑ ∑
s.t. xij − xji = 0 ∀i ∈ N \{s, t} (7)
(i,j)∈A (j,i)∈A
8
∑ ∑
xsj − xjs = v (8)
(s,j)∈A (j,s)∈A
∑ ∑
xtj − xjt = −v (9)
(t,j)∈A (j,t)∈A
The first sum in (7) equals the total flow coming out of node i ∈ N \{s, t},
while the second sum in (7) equals the total flow coming in this node. Therefore
constraints (7) ensure the flow conversation at every node except for the source
node and the sink node. By similar arguments, constraint (8) means that an
amount of v flow units are sent out from the source node s, which is also the
value need to be maximized. Constraint (9) guarantees that all flow units sent
out from the source node are received at the sink node. By constraints (10), the
flow transfering in each arc does not exceed the given arc capacity.
• a release date rj (representing the beginning of the day when this job be-
comes available for processing), and
We assume that
Job(j) 1 2 3 4
Processing time (pj ) 1.5 1.25 2.1 3.6
Release date (rj ) 3 1 3 5
Due date (dj ) 5 4 7 9
(ii) Solve the maximum flow problem obtained in part (i) by integer program-
ming approach with the use of ZIMPL and SCIP. From the obtained result, give
the schedule of all jobs.
Solution
(i) First, we rank all the release and due dates (rj and dj for all job j =
1, 2, 3, 4) in ascending order. In this way, we can easily see the scheduling mile-
stones from first day to the last day in the schedule. For our scheduling problem
instance, this order of release and due dates is 1, 3, 4, 5, 7, 9.
These dates give five mutually disjoint time intervals between consecutive
milestones: 1 → 3, 3 → 4, 4 → 5, 5 → 7, and 7 → 9. Let Tk,l denote the interval
that starts at the beginning of date k and ends at the beginning of date l + 1.
Then these five time intervals are respectively represented by T1,2 , T3,3 , T4,4 , T5,6 ,
and T7,8 . Note that within each interval Tk,l , the set of available jobs (i.e., those
released but not yet due) does not change: we can process all jobs j with rj ≤ k
and dj ≥ l + 1 in the interval.
To represent the scheduling problem, we construct a network G as follows.
• We connect the source node s to every job node j with an arc of capacity
pj , indicating that we need to assign pj days of machine time to job j.
• We connect each interval node Tk,l to the sink node t by an arc wtih capacity
(l − k + 1)M , representing the toal number of machine days available on
the days from k to l.
From the given scheduling data and following this construction, we obtain the
network in Figure 6.
The scheduling problem has a feasible schedule if and ∑ only if the maximum
flow value equals the total processing time of all jobs j∈J pj . Therefore, by
solving the max-flow problem on the obtained network, we obtain the schedule
result.
(ii) We need two input data files for the ZIMPL model of the maximum flow
problem. The first data file contains the information about the network nodes.
Each line of this file consists of two information fields: the name of a node and a
number representing its role in the path. More precisely, the source node will be
assigned with number 1, the target node will be assigned with number -1, while
the other nodes are assigned with number 0. The second data file contains the
information about the network arcs and their corresponding capacities. Each line
of this file consists of three information fields related to each arc: the node starts
the arc, the node ends the arc, and the arc capacity.
10
T1,2
1 1
6
1
T3,3
1.5 2
3
1.25 2 1
3
s T4,4 t
2.1 1 1
3 6
3.6 2
T5,6
2 6
4
2
T7,8
9 2 T33 1
10 3 T33 1
11 3 T44 1
12 3 T56 2
13 4 T56 2
14 4 T78 2
15 T12 t 6
16 T33 t 3
17 T44 t 3
18 T56 t 6
19 T78 t 6
17 # Variables
18 # x[i, j] = flow on arc (i, j)
19 var x[Arcs] >= 0;
20 # v = flow value
21 var v;
22
23 ## Modeling objective
24 maximize FlowValue : v;
25
26 ## Modeling constraints
27
29 subto FlowConversation :
30 f o r a l l <i> in Nodes with Balance [i] == 0 do
31 sum <j> in Nodes with <i, j> in Arcs: x[i, j] -
sum <j> in Nodes with <j, i> in Arcs: x[j, i]
== 0;
32
43 # Arc capacities
44 subto Capacity :
45 f o r a l l <i, j> in Arcs do
46 x[i, j] <= Capacity [i, j];
It can be seen from the obtained result that the maximum flow is 8.45, which
equals the total processing time of all jobs (= 1.5 + 1.25 + 2.1 + 3.6). Therefore
a feasible schedule exists.
From the detail value of each variable in the solution file, we obtain the
following schedule (here we accept fractions of days).
• Job 4 processes on machine 3 from day 5 to day 6.6, and then from day 7
to day 9.