06 Network Models-2
06 Network Models-2
Network Models
1. Introduction to Networks
2. Shortest Path Problem
3. Minimum Spanning Tree Problem
4. Max Flow Problem
5. Minimum Cost Flow Problem
1
Chapter 8. Network Models
1. Introduction to Networks
2. Shortest Path Problem
3. Minimum Spanning Tree Problem
4. Max Flow Problem
5. Minimum Cost Flow Problem
2
Basic Definition
3
Example
1 3
Network G = (N, A) 2 4
Also Seen
Graph G = (V,E)
Vertex set V = {1,2,3,4}
Edge set:
A={1-2,1-3,3-2,3-4,2-4} 4
Basic Definition
2 4
5
Chapter 8. Network Models
1. Introduction to Networks
2. Shortest Path Problem
3. Minimum Spanning Tree Problem
4. Max Flow Problem
5. Minimum Cost Flow Problem
6
The Shortest Path Problem
2 4 4
2 2
1 1 2 3 6
4 2
3 3 5
What is the shortest path from a source node (often
denoted as s) to a sink node, (often denoted as t)?
What is the shortest path from node 1 to node 6?
Assumptions for this lecture:
1. There is a path from the source to all other nodes.
2. All arc lengths are non-negative
7
Shortest Path Problem
8
Car replacement example:
We have just purchased a new car (or machine)
for $12,000 at time 0. The cost of maintaining
the car during a year depends on the age of the
car at the beginning of the year, as given in the
table below.
Age of Car Annual Age of Car Trade-in Price
(Years) Maintenance cost (Years)
0 $2,000 1 $7,000
1 $4,000 2 $6,000
2 $5,000 3 $2,000
3 $9,000 4 $1,000
4 $12,000 5 $0
9
Car replacement example:
Formulate as a shortest path problem.
Our network will have six nodes.
Node i is the beginning of year i
For i<j, an arc (i,j) corresponds to purchasing
a new car at the beginning of year i and
keeping it until the beginning of year j.
The length of arc (i,j) (call it cij) is the total
net cost incurred from year i to j.
10
Car replacement example:
cij = maintenance cost incurred during years i,i+1,…,j-1
+ cost of purchasing a car at the beginning of year i
- trade-in value received at the beginning of year j.
11
Network for minimizing car costs
From the figure below
we can see that both path 1-3-5-6 and
1-2-4-6 will give us the shortest path
with a value of 31.
44
31 31
21 21
12 12
1 7 2 7 3 7 4 7 5 7 6
12 12
21
12
Dijkstra’s Algorithm for the Shortest
Path Problem
2 4 4
2 2
1 1 2 3 6
4 2
3 3 5
Procedure Update(i)
for each (i,j) A(i) do
if d(j) > d(i) + cij then d(j) : = d(i) + cij and
pred(j) : = i;
Path P 62 10 78 72
1 i j
15
Scan the arcs out
An Example of i, and update
d( ), pred( ), and
d(2) =
\ 2 d(4) =
\ 6 LIST
pred(2) = 1 pred(4) = 2
4
22 44
2 2
d(1) = 0 11 1 2 3
66 d(6) =
\ 6
pred(1) = 0 4 2
pred(6) = 5
3
3 5
d(3) =
\ 4\ 3 d(5) =
\ 4
pred(3) = 1\ 2 pred(5) = 2
The
End Find
Find the
the node
Initialize the ii on
node on
LIST
LIST with
withand
distances
\ 2,\ 3,
LIST = {1, \ 6}
\ 4,\ 5, \ minimum
minimum
LIST.
distance.
distance.
The Output from Dijkstra’s To findnode
the has
Each
Algorithm shortest path
one incoming
from node j, trace
arc (except for
back from the
2 6 the
nodesource)
to the
2 4 4
2
source.
0 2
1 1 6 6
2
3 5
4
3
Dijkstra provides a shortest path from node 1 to
all other nodes. It provides a shortest path tree.
Note that this tree is an out-tree.
17
Comments on Dijkstra’s Algorithm
Dijkstra’s algorithm makes nodes
permanent in increasing order of distance
from the origin node.
Dijkstra’s algorithm is efficient in its
current form. The running time grows as
n2, where n is the number of nodes
It can be made much more efficient
In practice it runs in time linear in the
number of arcs (or almost so).
18
Chapter 8. Network Models
1. Introduction to Networks
2. Shortest Path Problem
3. Minimum Spanning Tree Problem
4. Max Flow Problem
5. Minimum Cost Flow Problem
19
More Definitions
2 4 2 4 2 4
5 5 5
20
Minimum Spanning Tree Problems
Arc (i,j) in a network has a length c(i,j)
Want to determine the spanning network :
the set of arcs in a network that connect all
nodes
Clearly, such a group of arcs contain no loop.
Minimum spanning tree : the sum of the
length of the arcs is to be minimized.
For a network with n nodes, a spanning tree
is a group of (n-1) arcs that connects all
nodes of the network and contains no loops.
21
Minimum Spanning Tree Algorithm
Select any node arbitrarily, and then
connect it to the nearest distinct node
Find the closest arc connecting the
connected node set and the unconnected
node set.
Repeat until all nodes are connected.
Ties are broken arbitrarily.
22
Example: University campus has five
buildings. The distances between buildings
are given in the figure below. What is the
minimum length of cable required to
interconnect the buildings?
1 1
2
2
2
6
5 4
2 3
4
4
5 3
23
Exercise:
The distance (in miles) between the Indiana
cities of G, F, E, T, and S are shown in the table.
It is necessary to build a state road that connect
all the cities. Assume that for political reason no
road can be built between G – F and S – E. What
is the minimum length of road required?
G F E T S
G - 132 217 164 58
F 132 - 290 201 79
E 217 290 - 113 303
T 164 201 113 - 196
S 58 79 303 196 -
24
Chapter 8. Network Models
1. Introduction to Networks
2. Shortest Path Problem
3. Minimum Spanning Tree Problem
4. Max Flow Problem
5. Minimum Cost Flow Problem
25
Mathematical Formulation for maximum
flow problem
Sunco Oil wants to ship the maximum possible
amount of oil (per hour) via pipeline from node so to
node si as shown in the figure below.
Arc Capacity
Added Arc
(so,1) 2
3 (so,2) 3
so 1 2 si (1,2) 3
2 3 2
(1,3) 4
4 3 1 (3,si) 1
(2,si) 2
26
LP for maximum flow problem
Let X0 be the flow through the artificial arc
the conservation of flow implies that X0 = total amount
of oil entering the sink.
Sunco’s goal is to maximize X0.
Max x0
s.t . x so,1 2, x so, 2 3, x12 3,
x 2, si 2, x13 4, x 3, si 1,
x0 x so,1 x so, 2 x so,1 x12 x13
x so, 2 x12 x 2, si x13 x 3, si
x 2, si x 3, si x0
x ij 0, (i,j) 27
Chapter 8. Network Models
1. Introduction to Networks
2. Shortest Path Problem
3. Minimum Spanning Tree Problem
4. Max Flow Problem
5. Minimum Cost Flow Problem
28
Minimum Cost Flow Problem
Special Cases
– Shortest Path Problem
– Transportation problem
– Assignment Problem
– Max Flow Problem
Minimum Cost Flow Problem
– Generalized Network Optimization
29
The Minimum Cost Flow Problem
Network G = (N, A) A network with costs,
capacities, supplies, demands
Node set N = {1, 2, 3, 4} 3
Arc set A = {(1,2), (1,3), (2,3), 2 $3, 4
$3, 6
(2,4), (3,4)}
Capacities uij on arc (i,j) 4 1 $8, 5 $7, 2 4
$2, 7 -2
•e.g., u12 = 6
3
Cost cij on arc (i,j) -5
•e.g., c12 = $3
Supply/demand bi for node i.
• e.g. b1 = 4 (supply)
• b3 = -5 (demand)
31
3
The LP 2 $3, 4
$3, 6
Formulation
4 1 $8, 5 $7, 2 4 -2
z x12 x13 x23 x24 x34 $2, 7
1 -3 -8 -7 -3 -2 = 0 3
-5
0 1 1 0 0 0 = 4
Supply/Demand
0 -1 0 1 1 0 = 3 constraints
0 0 -1 -1 0 1 = -5
0 0 0 0 -1 -1 = -2
Minimize cx
( i , j )A
ij ij
n n
s.t. x x
j 1
ij
k 1
ki bi for all i
Min z 2 X AB 9 X AD 4 X AC 3 X BC X CE 3 X DE 2 X ED
s .t . X AB X AD X AC 50
X AB X BC 40
X AC X BC X CE 0
X AD X ED X DE 30
X CE X DE X ED 60
0 X AB 10, 0 X CE 80, X ij 0, i , j
35
Network Simplex Method
UB Technique
Leaving variable : the first blocking variable
- The basic var. reaching LB = 0, or UB = Uij
If NB Xij reaches Uij ,
then replace it with Yij = Uij – Xij = 0
For Flow (i j) : bi bi - Uij
bj bj + Uij
37
Network Simplex Method
[50] A [40] A
2 -2
UAB=10 UAB=10
[40] B [50] B
39
Network Simplex Method
Entering Basic Variable
Among NB, the one which makes z improve with the
highest rate is chosen.
Example : NB XAC Assume XAC =
Undirected cycle :
9 (40) AC-CE-ED-DA
[40] A D [-30]
CE : 50 +
4
[0]
3 (10)
DE : 10 -
C
1 (50) AD : 40 -
3 (50) UCE=80 Incremental Effect on
[50] B E [-60]
z=4+1-3-9
=-7
Min : Good Candidate
40
Network Simplex Method
NB YAB =
[40] A 9 (40)
D [-30] Undirected cycle :
-2 (B,A,D,E,C,B)
[0]
C 3 (10) Incremental Effect on z
UAB=10 1 (50) = 9 + 3 - - 3 - 2
3 (50) UCE=80 =6
[50] B E [-60]
Min : Bad Candidate
[40] A 9 (40)
D [-30]
NB XED =
[0]2 Undirected cycle :
C (E,D,E)
1 (50) 3 (10)
Incremental Effect on z
3 (50) UCE=80
[50] B E [-60] = 3 + 2 = 5
Min : Bad Candidate
41
Network Simplex Method
Leaving Variable
NB XAC enters.
9 (40 - ) AC :
[40] A D [-30]
4() CE : 50 80
C
[0]
3 (10 - ) DE : 10 0
1 (50 + )
UCE=80
AD : 40 0
3 (50)
[50] B E [-60]
0 10
42
Network Simplex Method
[40] A 9 (30 )
D [-30]
NB (BA) = - 1
4(10)
-2 [0] 2 3 NB (DE) = 7
UAB=10 C
1 (60) NB (ED) = - 2
3 (50) UCE=80 XED enters.
[50] B E [-60]
44
Network Simplex Method
[50] A 9 (10 ) NB (AB) = 1
D [-30]
4(40) NB (DE) = 5
2 [-80]
2 (20) NB (EC) = 2
UAB=10 C
-1 3 Optimal
3 (40) UCE=80
[40] B E [20]
46