You are on page 1of 65

FREIGHT

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)

This document is reproduced with permission from Dr. Panitan


Kewcharoenwong - Sirindhorn International Institute of Technology,
Thammasat University, Thailand
GRAPH …

3
What is a graph?
• A data structure that consists of a set of nodes (vertices) and a set
of edges between the vertices.

• The set of edges describes relationships among 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.

Undirected graph: A graph in which the edges have no direction.


Directed graph (digraph): A graph in which each edge is directed
from one vertex to another (or the same) vertex.

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.

• The order of vertices in E is not important for undirected graphs.

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.

V(Graph2) = {1, 3, 5, 7, 9, 11}


E(Graph2) = {(1,3), (3,1), (5,7), (5,9), (9,11), (9,9),
(11,1)}

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.

• A path from 1 to 4 is <1, 2, 3, 4>.

• The length of a path is the number of edges in the path.

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.

• Explain why G is not a complete graph?

• What is the number of edges that must be added to G to make it


complete?

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.

• Example: in a flight route graph, the weight of an edge represents the


distance in miles between the airports.

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.

• Length of a path is the sum of the weights of its edges.

• Example: Shortest path between Providence and Honolulu.

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.

Road systems design


Problem: how to determine the number of lanes in each road?
Given: expected traffic between each pair of locations.
Method: Estimate total traffic on each road link assuming each
passenger will use shortest path.

22
Shortest Path Properties
• Property 1: A subpath of a shortest path is itself a shortest path.

• Property 2: There is a tree of shortest paths from a start vertex to all


the other vertices.

• Example: Tree of shortest paths from Providence.

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]

[4, O]* [7, B]*


[5, B] [8, C]
[9, D]
36

[2, O]*
[8, B]* [13, D]*
[8, E]*
[0, -]*
[4, A]*

[4, O]* [7, B]*


Dijkstra’s Algorithm

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.

• If a node with a negative incident edge were to be added late to


the cloud, it could mess up distances for vertices already in the
cloud.

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

• Must assume directed edges (for otherwise we would have negative-


weight cycles).

• Iteration i finds all shortest paths that use i edges.

•Can be extended to detect a negative-weight cycle if it exists.

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.

• Make n calls to Dijkstra’s algorithm (if no negative edges).

• Likewise, n calls to Bellman-Ford would.

• Can be improved by using dynamic programming or Floyd-


Warshall algorithm.

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)?

• The problem reportedly rose to prominence in relation to the rail


networks of the Country A, during the 1950's. The Country B wanted
to know how quickly the Country A could get supplies through its rail
network to its satellite states in Eastern Europe.

• In addition, the Country B wanted to know which rails it could


destroy most easily to cut off the satellite states from the rest of the
Country A. It turned out that these two problems were closely
related, and that solving the max flow problem also solves the min
cut problem of figuring out the cheapest way to cut off the Country
A from its satellites.

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:

1. Capacity constraint: total flow cannot exceed the capacity.

2. Skew symmetry: f(u,v) = -f(u,v)

3. Flow conservation: summation of flow into and out of a vertex


must be 0 (except for the source and sink).

46
Example: Flows
f(v2, v1) = 1, c(v2, v1) = 4.
f(v1, v2) = -1, c(v1, v2) = 10.

At v3  f(v3, s) + f(v3, v1) + f(v3, v2) + f(v3, v4) + f(v3, t) = 0


 0 + (-12) + 4 + (-7) + 15 = 0

flow
capacity

47
Flow Value
• The value of a flow is given by| f |  f ( s, v)  f (v, t )
vV vV

• The total flow leaving s = the total flow arriving t.

|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:

c f (u, v)  c(u, v)  f (u, v)

•The residual network of a graph G induced by a flow f is the graph


including only the edges with positive residual capacity.

G f (V , E f ) where E f  {(u, v) : c(u, v)  0}

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.

c f ( p)  min{c f (u, v) : (u, v) is on p}

Flow Network Residual Network

The residual capacity of this augmenting path is 4.

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.

• The Net Flow through a Cut (S,T) is


f (S,T )   f ( u, v )
uS ,vT

f(S,T) = 12 – 4 + 11 = 19

• The Capacity of a Cut (S,T) is


c( S , T )   c(u, v)
uS ,vT

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.

2. The residual network Gf contains no augmented paths.

3. |f| = c(S,T) for some cut (S,T) (a min-cut).

59
The Basic Ford-Fulkerson Algorithm

60
Example: Ford-Fulkerson Algorithm

Original Network

Flow Network
Resulting Flow = 4

61
Example: Ford-Fulkerson Algorithm (cont.)

Resulting Flow = 4 Residual


Network

Resulting Flow = 11 Residual


Network

62
Example: Ford-Fulkerson Algorithm (cont.)

Resulting Flow = 11 Residual


Network

Resulting Flow = 19 Residual


Network
63
Example: Ford-Fulkerson Algorithm (cont.)

Resulting Flow = 19 Residual


Network

Resulting Flow = 23 Residual


Network
64
Example: Ford-Fulkerson Algorithm (cont.)

Resulting Flow = 23

No augmenting path
Max flow = 23

Residual Network

65

You might also like