0% found this document useful (0 votes)
3 views

NetworkFlowExerciseCorrection

The document contains exercises on network flow problems, including the shortest path problem using Dijkstra's algorithm, integer programming formulations for shortest paths, and a max-flow problem using the augmenting path algorithm. It provides detailed solutions, including tables and ZIMPL models for implementation. Additionally, it discusses the trade-offs in inspection plans in a production line context, formulating it as a shortest path problem.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

NetworkFlowExerciseCorrection

The document contains exercises on network flow problems, including the shortest path problem using Dijkstra's algorithm, integer programming formulations for shortest paths, and a max-flow problem using the augmenting path algorithm. It provides detailed solutions, including tables and ZIMPL models for implementation. Additionally, it discusses the trade-offs in inspection plans in a production line context, formulating it as a shortest path problem.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Exercises on

Network Flow Problem


CORRECTION

Shortest path problem


Exercise 1. Solve the shortest path problem shown in Figure 1 using the Dijk-
stra’s algorithm. Count the number of distance updates.
3
2 4

2 6

s 1 5 6 1 7 4 6

8 2

0
3 5

Figure 1: Network for Exercise 1.

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

Node 1 Node 2 Node 3 Node 4 Node 5 Node 6


Iteration 0 0 ∞ ∞ ∞ ∞ ∞
Iteration 1 0 2 8 ∞ ∞ ∞
Iteration 2 0 2 7 5 ∞ ∞
Iteration 3 0 2 6 5 12 11
Iteration 4 0 2 6 5 6 11
Iteration 5 0 2 6 5 6 11
Iteration 6 0 2 6 5 6 11

Table 1: Label setting in all iterations of Dijkstra’s algorithm for Exercise 1.

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

xij ∈ {0, 1} ∀(i, j) ∈ A (5)

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

ZIMPL data file Arcs.dat corresponds to the network in Exercise 1.


1 # Start End Length
2 1 2 2
3 1 3 8
4 2 3 5
5 3 2 6
6 2 4 3
7 3 5 0
8 4 3 1
9 4 5 7
10 5 4 4
11 4 6 6
12 6 5 2

The formulation obtained in part (i) can be modeled by using ZIMPL as


follows.
ZIMPL model for solving shortest path problem in Exercise 1.
1 # A ZIMPL model to solve shortest path problem
2 # (find a shortest path from a source node
3 # to a target node in a directed network )
4

5 # Parameter defining input data files


6 param fileNodes := " Nodes .dat ";
4

7 param fileArcs := "Arcs.dat ";


8

9 # Import information of network nodes from data file


10 set Nodes := {read fileNodes as "<1s >" comment "#"};
11 param Balance [Nodes ] := read fileNodes as "<1s> 2n" comment "#
";
12

13 # Import information of network arcs from data file


14 set Arcs := {read fileArcs as "<1s, 2s >" comment "#"};
15 param Length [Arcs] := read fileArcs as "<1s, 2s> 3n" comment "
#";
16

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

26 # The selected arcs form a path from source node to target


node
27 subto Path:
28 f o r a l l <i> in Nodes do
29 sum <j> in Nodes with <i, j> in Arcs: x[i, j] -
sum <j> in Nodes with <j, i> in Arcs: x[j, i]
== Balance [i];

Exercise 3. A production line consists of an ordered sequence of n production


stages, and each stage has a manufacturing operation followed by a potential
inspection. The product enters stage 1 of the production line in batches of size
B ≥ 1. As the items within a batch move through the manufacturing stages,
the operations might introduce defects. The probability of producing a defect at
stage i is αi . We assume that all of the defects are non-repairable, so we must
scrap any defective item. The production line must end with an inspection station
so that we do not ship any defective units. Our problem is to find an optimal
inspection plan that specifies at which stages we should inspect the items so that
we minimize the total cost of production and inspection.
Using fewer inspection stations might decrease the inspection costs, but will
increase the production costs because we might perform unnecessary manufac-
turing operations on some units that are already defective. The optimal number
of inspection stations will achieve an appropriate trade-off between these two
conflicting cost considerations.
Suppose that the following cost data are available.
5

• pi : the manufacturing cost per unit in stage i.

• fij : the fixed cost of inspecting a batch after stage j, given that we last
inspected the batch after stage i.

Formulate this inspection problem as a shortest path problem.

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

A shortest path from node 0 to node n hence corresponds to an inspection plan


with minimum total incurred production and inspection costs.
6

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

Figure 2: Network for Exercise 4.

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.

Figure 3: Step 1 of augmenting path algorithm applied on the problem instance.

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.

Figure 4: Step 2 of augmenting path algorithm applied on the problem instance.


1
2 4 2 4
1 1
2 2 1
1 2 1 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.

Figure 5: Step 3 of augmenting path algorithm applied on the problem instance.

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

0 ≤ xij ≤ cij ∀(i, j) ∈ A (10)

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.

Exercise 6. This exercise shows an application of max-flow problem in scheduling


on uniform parallel machines. Consider the problem of scheduling a set J of jobs
on M uniform parallel machines. Each job j ∈ J has

• a processing time pj (denoting the number of days required to complete the


job),

• a release date rj (representing the beginning of the day when this job be-
comes available for processing), and

• a due date dj ≥ rj + pj (representing the beginning of the day by which the


job must be completed).

We assume that

• a machine can work on only one job at a time, and

• each job can be processed by at most one machine at a time.

However, we allow preemptions (i.e., we can interrupt a job and process it on


different machines on different days). The scheduling problem is to determine a
feasible schedule that completes all jobs before their due dates or to show that
no such schedule exists.
(i) Formulate the scheduling problem described in Table 2 with M = 3 ma-
chines as a maximum flow problem.

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

Table 2: Parameters for scheduling problem in Exercise 6.


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 introduce a source node s, a sink node t, a node corresponding to each


job j, and a node corresponding to each time interval Tk,l .

• 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.

• Finally, we connect each job node j to every interval node Tk,l if rj ≤ k


and dj ≥ l + 1 by an arc of capacity l − k + 1, representing the maximum
number of machines days we can allot to job j 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

Figure 6: Network for Exercise 6.

ZIMPL data file SchedulingNodes.dat corresponds to the network in Figure 6.


1 # Node Role
2 s 1
3 t -1
4 1 0
5 2 0
6 3 0
7 4 0
8 T12 0
9 T33 0
10 T44 0
11 T56 0
12 T78 0

ZIMPL data file SchedulingArcs.dat corresponds to the network in Figure 6.


1 # Start End Capacity
2 s 1 1.5
3 s 2 1.25
4 s 3 2.1
5 s 4 3.6
6 1 T33 1
7 1 T44 1
8 2 T12 2
11

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

The integer programming formulation introduced in the solution of Exercise


5 applied to the network instance in part (i) can be modeled by using ZIMPL as
follows.
ZIMPL model for solving the obtained max-flow problem.
1 # A ZIMPL model to solve maximum flow problem
2 # corresponding to a scheduling problem
3 # on uniform parallel machines
4

5 # Parameter defining input data files


6 param fileNodes := " SchedulingNodes .dat ";
7 param fileArcs := " SchedulingArcs .dat ";
8

9 # Import information of network nodes from data file


10 set Nodes := {read fileNodes as "<1s >" comment "#"};
11 param Balance [Nodes ] := read fileNodes as "<1s> 2n" comment "#
";
12

13 # Import information of network arcs from data file


14 set Arcs := {read fileArcs as "<1s, 2s >" comment "#"};
15 param Capacity [Arcs] := read fileArcs as "<1s, 2s> 3n" comment
"#";
16

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

28 # Flow conversation at every node except for the source node


and the sink node
12

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

33 # Flow at source node


34 subto FlowAtSource :
35 f o r a l l <s> in Nodes with Balance [s] == 1 do
36 sum <j> in Nodes with <s, j> in Arcs: x[s, j] -
sum <j> in Nodes with <j, s> in Arcs: x[j, s]
== v;
37

38 # Flow at sink node


39 subto FlowAtSink :
40 f o r a l l <t> in Nodes with Balance [t] == -1 do
41 sum <j> in Nodes with <t, j> in Arcs: x[t, j] -
sum <j> in Nodes with <j, t> in Arcs: x[j, t]
== -v;
42

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];

The result file obtained by using SCIP is as follows.


Result obtained by using SCIP.
1 solution status : optimal solution found
2 objective value: 8.45
3 v 8.45 (obj :1)
4 x$s$1 1.5 (obj :0)
5 x$1$T44 0.5 (obj :0)
6 x$1$T33 1 (obj :0)
7 x$s$2 1.25 (obj :0)
8 x$2$T12 1.25 (obj :0)
9 x$s$3 2.1 (obj :0)
10 x$3$T56 0.1 (obj :0)
11 x$3$T44 1 (obj :0)
12 x$3$T33 1 (obj :0)
13 x$s$4 3.6 (obj :0)
14 x$4$T78 2 (obj :0)
15 x$4$T56 1.6 (obj :0)
16 x$T12$t 1.25 (obj :0)
17 x$T33$t 2 (obj :0)
18 x$T44$t 1.5 (obj :0)
19 x$T56$t 1.7 (obj :0)
20 x$T78$t 2 (obj :0)
13

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 1 processes on machine 1 from day 3 to day 4.5.

• Job 2 processes on machine 1 from day 1 to day 2.25.

• Job 3 processes on machine 2 from day 3 to day 5.1.

• Job 4 processes on machine 3 from day 5 to day 6.6, and then from day 7
to day 9.

You might also like