Professional Documents
Culture Documents
MANAGEMENT
Dr. LE THI DIEM CHAU
Dr. TRAN QUYNH LE
Dr. Nguyen Duc Duy
Dr. Tran Quoc Cong
Assoc.Prof. Do Ngoc Hien
Industrial Systems Engineering Department
Mechanical Engineering Faculty
Ho Chi Minh City University of Technology(HCMUT) – VNUHCM
2
Chapter 5
Methodology
(P3: Graph and Network
Optimization)
3
What is a graph?
• A data structure that consists of a set of nodes (vertices) and a set
of edges between the vertices.
4
Definitions
Vertex: A node in a graph.
Edge (arc): A pair of vertices representing a connection between
two nodes in a graph.
Formally
A graph G is defined as G = (V,E)
where
V(G) is a finite, nonempty set of vertices.
E(G) is a set of edges written as pairs of vertices.
5
Undirected graph
• A graph in which the edges have no direction.
V(Graph1) = {A,B,C,D}
E(Graph1) =
{(A,B),(A,D),(B,C),(B,D)}
6
Directed graph
• A graph in which each edge is directed from one vertex to another
(or the same) vertex
• The order of vertices in E is important for directed graphs.
7
Tree: A special case of directed graphs.
V(Graph2) = {A, B, C, D, E, F, G, H, I, J}
E(Graph2) = {(G,D), (G,J), (D,B), (D,F), (I,H), (I,J), (B,A), (B,C),
(F,E)}
8
Graph terminology
• Adjacent vertices: Two vertices in a graph that are connected by
an edge.
7 is adjacent from 5
5 7 or
5 is adjacent to 7
7 is adjacent from/to 5
5 7 or
5 is adjacent from/to 7
9
• Path: A sequence of vertices that connects two nodes in a graph.
1 2
3 4
10
• Complete graph: A graph in which every vertex is directly
connected to every other vertex.
11
Question 1)
What is the number of edges E in a complete undirected graph with V
vertices?
12
Question 2)
What is the number of edges E in a complete directed graph with V
vertices?
13
Question 3)
• Graph G has four vertices and edges of length 7, 8, 8, and 9.
14
Weighted graph
15
Distribution structures
Single-echelon/single-tier Multi-echelon/multi-tier
Doesnot involve any intermediary facilities Have several layers of intermediate
between the suppliers and the source(s) of demand facilities
Question
How many levels does the supply chain structure in the figure below have?
Question
How many levels does the supply chain structure in the figure below have?
SHORTEST PATH …
19
Weighted Graphs
• A graph for which each edge has an associated numerical value,
called the weight of the edge.
• Edge weights may represent, distances, costs, etc.
PVD
ORD
SFO
LGA
HNL
LAX
DFW
MIA
20
Shortest Path Problem
• Given a weighted graph and two vertices u and v, find
a path of minimum total weight between u and v.
PVD
ORD
SFO
LGA
HNL
LAX
DFW
MIA
21
Applications:
• Package routing.
• Flight reservations.
• Driving directions.
Telephone routes.
Which communication links to activate when a user makes a
phone call, e.g. from Hong Kong to New York, USA.
22
Shortest Path Properties
• Property 1: A subpath of a shortest path is itself a shortest path.
PVD
ORD
SFO
LGA
HNL
LAX
DFW
MIA
23
Example 1
Example 1
Example 1
Nút đã
khảo sát
Example 1
iteration:
Shortest path???
Dijkstra’s Algorithm
Born 11 May 1930 in Netherlands
Died 6 August 2002 (aged 72) in Netherlands
Citizenship Netherlands
Education Leiden University (B.S., M.S.)
University of Amsterdam (Ph.D.)
Awards Turing Award (1972); Harry H. Goode Memorial
Award (1974); SIGCSE Outstanding Contribution
(1989); ACM Fellow (1994); Dijkstra Prize (2002)
Scientific career
Fields •Computer science; Theoretical computer science
Institutions •Mathematisch Centrum; Eindhoven University of
Technology; Burroughs Corporation; University of
Texas at Austin
Thesis Communication with an Automatic Computer (1959)
Doctoral advisor Adriaan van Wijngaarden
Doctoral students •Nico Habermann & Jan van de Snepscheut Edsger Wybe Dijkstra
Dijkstra’s Algorithm
• Computes the distances of all the vertices from a given start vertex s
• Assumptions:
the graph is connected and the edge weights are nonnegative.
The Concept
• Grow a cloud of vertices, beginning with s and eventually covering all the
vertices.
• A label d(v) representing the distance of v from s in the subgraph
consisting of the cloud and its adjacent vertices.
• At each step:
• Add to the cloud the vertex u outside the cloud with the smallest
distance label, d(u).
• Update the labels of the vertices adjacent to u.
29
Edge Relaxation
•Consider an edge e = (u, z) such that
• u is the vertex most recently added to the cloud.
• z is not in the cloud.
•The relaxation of edge e updates distance d(z) as follows:
• d(z) = min {d(z), d(u) + weight(e)}
d(u) = 50
d(z) =
u e
s z
d(u) = 50
d(z) = 60
u e
s z
30
Example: Dijkstra’s Algorithm
0 0
8 A 4 8 A 4
2 2
8 7 2 1 4 8 7 2 1 3
B C D B C D
3 9 5 3 9 8
2 5 2 5
E F E F
0 0
8 A 4 8 A 4
2 2
8 7 2 1 3 7 7 2 1 3
B C D B C D
5 3 9 11 5 3 9 8
2 5 2 5
E F E F
31
Example: Dijkstra’s Algorithm
0 0
8 A 4 8 A 4
2 2
7 7 2 1 3 7 7 2 1 3
B C D B C D
5 3 9 8 3 9
5 8
2 5 2 5
E F E F
32
Example 1
[2, O]
[0, -]*
[5, O]
[4, O]
Example 1
[2, O]
[7, B]
[0, -]*
[5, O]
[4, A]
[4, O]
[5, B]
Example 1
[2, O]*
[7, B]
[9, A] [13, D]*
[8, B]* [14,E]
[8, E]*
[0, -]*
[5, O]
[4, A]*
[5, C]
[2, O]*
[8, B]* [13, D]*
[8, E]*
[0, -]*
[4, A]*
37
Why It Doesn’t Work for Negative-Weight Edges
• Dijkstra’s algorithm is based on the greedy method. It adds
vertices by increasing distance.
• E.g. C’s true distance is 1, but it is already in the cloud with d(C)=5.
0
8 A 4
6
7 7 5 1 4
B C D
5 0 -8 9
2 5
E F
38
Bellman-Ford Algorithm
• Works even with negative-weight edges, ….. , but not negative cycle!.
39
Bellman-Ford Algorithm
Algorithm Bellman Ford
for all v vertices
if v = s
D(v) = 0
else
D(v) =
for i 1 to n-1 do
for each (a, b) edges
{ relax edge (a, b) }
if D(a) + weight(a, b) < D(b)
D(b) = D(a) + weight(a, b)
40
Example: Bellman-Ford
Nodes are labeled with their d(v) values
8 0 4 8 0 4
-2 -2
7 1 8 7 -2 1 4
3 9 3 9
-2 5 -2 5
8 0 4 8 0 4
-2 -2
5 8 7 1 -1 7 1
-2 4 5 -2 -1
1 3 9 3 9
-2 6 9 5 -2 4 5
1 9
41
All-Pairs Shortest Paths
• Find the distance between every pair of vertices in a weighted
directed graph G.
42
MAXIMUM FLOW …
43
Maximum Flow Problem
• How can we maximize the flow in a network from a source (or set of
sources) to a destination (or set of destinations)?
44
The Problem
• A Network is a directed graph G.
•Each edge (u,v) has a maximum capacity c(u,v) or 0.
• A source node s in which flow leaves.
• A sink node t out which flow arrive.
• Want to find the maximum flow from s to t.
45
What is a Flow in a Network?
• For each edge (u,v), the flow f(u,v) is a real-valued function that must
satisfy 3 conditions:
46
Example: Flows
f(v2, v1) = 1, c(v2, v1) = 4.
f(v1, v2) = -1, c(v1, v2) = 10.
flow
capacity
47
Flow Value
• The value of a flow is given by| f | f ( s, v) f (v, t )
vV vV
|f|= f(s, v1) + f(s, v2) + f(s, v3) + f(s, v4) + f(s, t) = 11 + 8 + 0 + 0 + 0 = 19
|f|= f(s, t) + f(v1, t) + f(v2, t) + f(v3, t) + f(v4, t) = 0 + 0 + 0 + 15 + 4 = 19
48
Multiple Sources Network
• Several sources and several targets.
• Maximize the total flow from all sources to all targets.
• Reduce to max-flow by creating a supersource and a supersink.
49
Residual Networks
• The residual capacity of an edge (u,v) in a network with a flow
f(u,v) is given by:
50
Example: Residual Network
Flow Network:
Residual Network:
51
Augmenting Paths
• An augmenting path p is a path from s to t on the residual network.
• More flow can be sent from s to t through p.
• We call the maximum capacity by which we can increase the flow
on p the residual capacity of p.
52
Computing Max Flow
The Concept
1. Identify augmenting path
2. Increase flow along that path
3. Repeat
53
Example
Flow 1 Residual 1
Flow 2 Residual 2
No more augmenting paths max flow attained.
54
Cuts of Flow Networks
• A cut (S, T) of a flow network is a partition of V into S and T = V – S
such that s is in S and t is in T.
f(S,T) = 12 – 4 + 11 = 19
c(S,T)= 12 + 0 + 14 = 26
55
Example: Capacity of the cut
= maximum possible flow through the cut = 12 + 7 + 4 = 23
56
Net Flow of a Network
•The net flow across any cut is the same, and equal to the flow of the
network |f|.
57
Bounding the Network Flow
•The value of any flow f in a flow network G is bounded from above
by the capacity of any cut of G.
58
Max-Flow Min-Cut Theorem
• If f is a flow in a flow network G=(V,E), with source s and sink t
then the following conditions are equivalent:
1. f is a maximum flow in G.
59
The Basic Ford-Fulkerson Algorithm
60
Example: Ford-Fulkerson Algorithm
Original Network
Flow Network
Resulting Flow = 4
61
Example: Ford-Fulkerson Algorithm (cont.)
62
Example: Ford-Fulkerson Algorithm (cont.)
Resulting Flow = 23
No augmenting path
Max flow = 23
Residual Network
65