0% found this document useful (0 votes)
60 views46 pages

06 Network Models-2

The document describes different network models including the shortest path problem, minimum spanning tree problem, maximum flow problem, and minimum cost flow problem. It then focuses on explaining the shortest path problem and Dijkstra's algorithm for solving it in graphs with non-negative edge weights. Dijkstra's algorithm works by maintaining distance labels from the source node and iteratively updating them and tracking predecessors until it has explored the entire graph.

Uploaded by

watri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views46 pages

06 Network Models-2

The document describes different network models including the shortest path problem, minimum spanning tree problem, maximum flow problem, and minimum cost flow problem. It then focuses on explaining the shortest path problem and Dijkstra's algorithm for solving it in graphs with non-negative edge weights. Dijkstra's algorithm works by maintaining distance labels from the source node and iteratively updating them and tracking predecessors until it has explored the entire graph.

Uploaded by

watri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

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

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

 A graph, or network, is defined by two sets of


symbols: nodes and arcs
 We define a set (call it V) of points, or vertices
 The vertices of a graph or network are also
called nodes.
 An arc consists of an ordered pair of vertices
and represents a possible direction of motion
that may occur between vertices.

3
Example
1 3

Network G = (N, A) 2 4

Node set N = {1, 2, 3, 4}


Arc Set {(1,2), (1,3), (3,2), (3,4), (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

 A sequence of arcs such that every arc has


exactly one vertex in common with previous
arc is called a chain.
Ex: (1,2)-(2,4)-(3,4)
 A path is a chain in which the terminal node
of each arc is identical to the initial node of
the next arc
Ex: (1,2)-(2,4)-(4,3) 1 3

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

 Where does it arise in practice?


– Common applications
• shortest paths in a vehicle
• shortest paths in internet routing
– Less obvious: close connection to dynamic
programming which we will see in later lectures

 How will we solve the shortest path problem?


– Dijkstra’s algorithm

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.

 c12= c23 = c34 = c45 = c56= 2+12-7=7


 c13= c24= c35= c46= 2+4+12-6=12
 c14= c25= c36= 2+4+5+12-2=21
 c15= c26= 2+4+5+9+12-1=31
 c16=2+4+5+9+12+12-0=44

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

Exercise: find the shortest path from node 1 to all


other nodes. Keep track of distances using labels, d(i)
and each node’s immediate predecessor, pred(i).
d(1)= 0, pred(1)=0;
d(2) = 2, pred(2)=1
Find the other distances, in order of increasing
13
distance from node 1.
A Key Step in Shortest Path Algorithms
 Let d( ) denote a vector of temporary distance labels.
 d(j) is the length of some path from the origin node 1 to
node j.

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

Up to this point, the best path from 1 to j has length 78


But P, (i,j) is a path from 1 to j of length 72.
14
Dijkstra’s Algorithm
Initialize distances.
begin
LIST = set of
d(s) : = 0 and pred(s) : = 0;
d(j) : =  for each j  N - {s};
temporary nodes
LIST : = {s};
while LIST  f do
begin
let d(i) : = min {d(j) : j  LIST}; Select the node i on
remove node i from LIST; LIST with minimum
update(i) distance label, and
if d(j) decreases, place j in LIST
then update(i)
end
end

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

1 3 A network is connected if every node


can be reached from every other
2 4
node by following a sequence of
arcs in which direction is ignored.
5

A spanning tree is a connected subset of a network


including all nodes, but containing no cycles.
1 3 1 3 1 3

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)

Send flow in each arc


Satisfy “supply/demand” constraints”
Satisfy flow bound constraints 30
Minimize cost
The Minimum Cost Flow Problem
A network with costs,
capacities, supplies, demands
3
Let xij be the flow 2 $3, 4
$3, 6
on arc (i,j).
4 1 $8, 5 $7, 2 4 -2
$2, 7
3
-5

Min z = the cost of sending flow

s.t. Flow out of i - Flow into i = bi for each i


0  xij  uij for all arcs (i,j) in A

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

0  x12  6, 0  x13  5, 0  x23  2, Lower and upper


bounds on variables
0  x24  4, 0  x34  7,

The constraint matrix is the node arc incidence matrix 32


The Minimum Cost Flow Problem
Let xij be the flow on arc (i,j).

Minimize the cost of sending flow


s.t. Flow out of i - Flow into i = bi
0  xij  uij

Minimize cx
( i , j )A
ij ij

n n

s.t.  x  x
j 1
ij
k 1
ki  bi for all i

0  xij  uij for all (i,j) 33


Network Simplex Method
[50] A 9
D [-30]
4
2 [0]
C 2 3
UAB=10 1
3 UCE=80
[40] B E [-60]

 The number of functional constraints =


the number of nodes
 Upper bounds constraints can be handled like the
non-negativity constraints
 One redundant constraint.
n nodes problem : (n –1) Basic Var’s.
34
Network Simplex Method
[50] A 9
D [-30]
4
2 [0]
C 2 3
UAB=10 1
3 UCE=80
[40] B E [-60]

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

(Ex.) XAB + XAC + XAD = 50


(10 – YAB) + XAC + XAD = 50 or
– YAB + XAC + XAD = 40 36
Network Simplex Method
 Yij becomes Basic Variable (Strictly Positive)
• Flow (j i) : Cancelling flow of Xij = Uij
• Capacity Uij : You can cancel at most Uij
• Cost (-Cij) : Cancelling means Save Cij

 Yij becomes Leaving Variable (Reaching UB Uij )


• Reversely Change Flow (j i) to Flow (i j)
• Yij = Uij becomes Xij = 0
• Yij = Uij – Xij

37
Network Simplex Method
[50] A [40] A

2 -2
UAB=10 UAB=10

[40] B [50] B

 XAB becomes Leaving Variable by reaching UB 10


 XAB = 10 becomes YAB = 0 (New NB)
 Flow (A B) becomes Flow (B A)
 Arc Capacity =10, Unit Cost = - 2.
 Assuming that the 10 units has flown to B from A,
and flow B to A implies cancelling the flow A to B
with cost saving by 2 units. 38
Network Simplex Method
 BFS Solution and Spanning Tree Solution
 n nodes and (n –1) basic var’s corresponding to arcs.
 (n – 1) Basic Arcs have no cycle, and forms the
spanning tree.
BFS = Spanning Tree Solution
x AD  40, x BC  50,
[40] A 9
D [-30]  x BC  xCE  0,
4  x AD  x DE  30,
-2 [0]
2 3
UAB=10 C
1  xCE  x DE  60.

3 UCE=80 x AD  40, x BC  50,


[50] B E [-60]
xCE  50, x DE  10.

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]

X ED      XCE is Leaving, obtained by UB


X AD : 30    0  Replace XCE with (80 – YCE)
X AC : 10      (C E) to (E C)
 bE= bE+80
X CE : 60    80
 bc= bc- 80
 0    20
43
Network Simplex Method
[40] A 9 (10 )
D [-30]
4(30)  NB (BA) = - 1
-2 [-80]
2 (20)  NB (DE) = 5
UAB=10 C
-1 3  NB (EC) = 2
3 (50) UCE=80  YAB enters.
[50] B E [20]

 YAB is Leaving, obtained by UB


Y AB    U BA  10  Remark: YAB is leaving as soon
X AC : 30    U AC   as it enters. It happens often in
Network Simplex.
X BC : 50    0  Replace YAB with (10 – XAB)
 0    10  (B A) to (A B)
 bB: 50 40, bA: 40 50

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]

 Transform to the 9 (10 )


[50] A D [-30]
original form.
4(40)
 Replace YC Ewith 2 [0]
2 (20)
(80 – XCE) UAB=10 C
1 (80) 3
 (E C) to (C E)
 bC: (- 80) 0, 3 (40) UCE=80
[40] B E [-60]
bE: 20 (- 60)
 Z = 490
45
thankyou

46

You might also like