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

Graph Theory Basics 2

The document describes algorithms for finding shortest paths in graphs: - It presents an iterative algorithm that starts with the origin node and finds the closest remaining node at each step, adding it to the set of permanent nodes and its path/distance. - An example application to finding shortest paths from an origin to all other nodes in a sample network is shown through multiple iterations. - The algorithm works by considering direct links from permanent to temporary nodes at each step to determine the minimum distance to each temporary node. The temporary node with minimum distance is then made permanent. - After n iterations, the shortest path from the origin to each of the n nodes in the network will have been determined.

Uploaded by

Alok Kumar
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)
46 views

Graph Theory Basics 2

The document describes algorithms for finding shortest paths in graphs: - It presents an iterative algorithm that starts with the origin node and finds the closest remaining node at each step, adding it to the set of permanent nodes and its path/distance. - An example application to finding shortest paths from an origin to all other nodes in a sample network is shown through multiple iterations. - The algorithm works by considering direct links from permanent to temporary nodes at each step to determine the minimum distance to each temporary node. The temporary node with minimum distance is then made permanent. - After n iterations, the shortest path from the origin to each of the n nodes in the network will have been determined.

Uploaded by

Alok Kumar
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/ 27

 GRAPH: A network of NODES (or VERTICES) and ARCS (or EDGES) joining

the nodes with each other


 DIGRAPH: A graph where the arcs have an ORIENTATION (or DIRECTION).
Graph a b
a b Digraph

c e c
d d

 A CHAIN between two nodes is a sequence of arcs where every arc has exactly
one node in common with the previous arc
b CHAIN: a-b-c-d; ARCS: a-b, c-b, c-d
a c d

 A PATH is a chain of directed arcs, where the terminal node of each arc is the
initial node of the succeeding arc:
d
b PATH: a-b-c-d; ARCS: a-b, b-c, c-d
a c

 2020, Jayant Rajgopal


b d
a c
CYCLE: a-b-c-d; ARCS: a-b, c-b, c-d, d-a

b d
CIRCUIT: a-b-c-d; ARCS: a-b, b-c, c-d, d-a a c

A graph is said to be CONNECTED if there is a continuous chain of edges


joining any two vertices.

A graph is STRONGLY CONNECTED if for all ordered pairs of vertices (i,j)


there is a path of arcs from i to j.

A graph is COMPLETE if every node is directly connected to every other node.


c
A TREE is a connected graph with no cycles.
b d
a
A SPANNING TREE is a tree that contains all the nodes of a graph.
b b
e e
a a
c c
Graph Spanning Tree
d d  2020, Jayant Rajgopal
GIVEN: A digraph G with a set of nodes 1,2,…,m, and
 a set of n directed arcs i-j emanating from node i and ending in node j,
 with each node i, a number bi that is the supply (if bi>0) or the demand (if bi<0); if
bi=0, then the node is called a transshipment node,
 with each arc i-j, a flow of xij and a unit transportation / movement cost of cij.

ASSUMPTION: i=1..mbi = 0
PROBLEM MCNF: Minimize all defined i-j (cijxij)

st  j xij - k xki = bi for i=1,2,…,m


Lijxij Uij for all i-j

The coefficient matrix for the constraints is called the NODE-ARC


INCIDENCE matrix.  2020, Jayant Rajgopal
A Prototypical Example
A new amusement park is being constructed by a large corporation. Cars are not allowed
into the park, but there is a system of narrow, winding pathways for automated people
movers and pedestrians. The road system is shown in the figure below, where O
represents the entrance to the park and A-F represent sites of various popular
amusements. The numbers above the arcs give the distances of the arcs.

A F
7
2 5
2

5 4
O B D
7
1 1
3

4 C E
4

The designers face three questions:


 2020, Jayant Rajgopal
1. Electrical lines must be laid under the pathways to establish communication between all
nodes in the network. Since this is an expensive process, the question to be answered is
how this can be accomplished with a minimum total distance ?
2. Location F is extremely popular with visitors, and it is planned that a small number of
people movers will run directly from the entrance O to site F. The question is which path
will provide the smallest total distance from O to F ?
3. During the peak season the number of people wanting to go from O to F is very large.
Thus during this time various routes may be followed from O to F (irrespective of
distance) so as to accommodate the increased demand through additional trips.
However, due to the terrain and the quality of the construction, there are limits on the
number of people mover trips that can run on any given path per day; these are different
for different paths. The question is how to route various trips to maximize the number of
trips that can be made per day without violating the limits on any individual path ?
 Question 1 may be answered by solving a minimum spanning tree problem.
 Question 2 may be answered by solving a shortest path problem.
 Question 1 may be answered by solving a maximum flow problem.

 2020, Jayant Rajgopal


Let us represent the origin by O, and suppose that there are n additional nodes
in the network:
Objective at Iteration i: To find the ith closest node from O, along with the
corresponding path and distance.
Input at Iteration i: The closest, the 2nd closest,...,(i-1)th closest nodes to O,
along with their paths and distances. These are designated as permanent
nodes (P) while the remaining nodes are designated as temporary nodes (T).
Initially, P={O} and T={all other nodes}.
At Iteration i:
 Determine all nodes in T that are directly linked to at least one node in P;
call this subset of T as .
 For each j , compute Dj= Minimum {shortest distance from O to a
permanent node + distance of direct link from that permanent node to j }.
 Determine the j that has the minimum value for Dj. Remove j from T
and add it to P along with the shortest path and distance.

At the end of iteration n the shortest path to each node is available.


 2020, Jayant Rajgopal
Iteration 1
P={O}, DO=0;

A T={A,B,C,D,E,F}
2
0
5
= {A, B, C}
O B

DA=Min{DO+LOA}=2
4
DB=Min{DO+LOB}=5
C
DC=Min{DO+LOC}=4

Closest node = {A}, DA=2

 2020, Jayant Rajgopal


2 P={O,A}, DO=0, DA=2;
A
7
2 2
0
T={B,C,D,E,F}
O 5 B D
= {B, C, D}
4
DB =Min{DO+LOB,DA+LAB}
C =Min{0+5, 2+2}=4
DC =Min{DO+LOC}=0+4=4
DD =Min{DA+LAD}=2+7=9

(breaking the tie arbitrarily…) 2nd closest node = {C}, DC=4

 2020, Jayant Rajgopal


P={O,A,C}, DO=0, DA=2, DC=4;
2
A
7 T={B,D,E,F}
2 2
0
O 5 B D = {B, D, E}

1 DB =Min{DO+LOB, DA+LAB, DC+LCB}


4
=Min{0+5, 2+2, 4+1}=4
C E
DD =Min{DA+LAD}=2+7=9
4 4
DE =Min{DC+LCE}=4+4=8

3rd closest node = {B}, DB=4

 2020, Jayant Rajgopal


P={O,A,C,B}, DO=0, DA=2, DC=4, DB=4;
2
A
7
T={D,E,F}
2 2
0
 = {D, E}
O 4 B D
4
DD=Min{DA+LAD, DB+LBD}
4 3
=Min{2+7, 4+4}=8
C E DE =Min{DC+LCE, DB+LBE}
4 4
=Min{4+4, 4+3}=7

4th closest node = {E}, DE=7

 2020, Jayant Rajgopal


P={O,A,C,B,E}, DO=0, DA=2,
DC=4, DB=4, DE=7;
2
A
7 F
2 2 T={D,F}
0 D
O 4 B
4
D
 = {D, F}
1 7
4 3
DD=Min{DA+LAD, DB+LBD, DE+LED}
C E =Min{2+7, 4+4, 7+1}=8
4 7 DF =Min{DE+LEF}=7+7=14

5th closest node = {D}, DD=8

 2020, Jayant Rajgopal


P={O,A,C,B,E,D}, DO=0, DA=2,
2 DC=4, DB=4, DE=7, DD=8;
A
F
2
0
2 5 T={F}
8
O 4 B D
 = {F}
4

1 7
4 3

C E DF=Min{DD+LDF, DE+LEF}
4 7 =Min{8+5, 7+7}=13

6th closest node = {F}, DF=13

 2020, Jayant Rajgopal


 2020, Jayant Rajgopal
STEP 0: Start with some feasible flow (if one isn't obvious let flow in each arc be equal
to zero) from the source node to the sink node.
STEP 1:
If flow in arc (i-j) is less than capacity of arc (i-j) assign it to set I (set of arcs along
which amount of flow can be Increased).
If flow in arc (i-j) is greater than zero assign it to set R (set of arcs along which amount
of flow can be Reduced).
NOTE: An arc can belong to both I and R!
STEP 2: LABELING PROCEDURE
 Label the source node.
 If the flow along an arc (i-j) is from a labeled node to an unlabeled node and the
arc belongs to I, then label the unlabeled node, call the arc a forward arc and let
I(i-j) = Capacity(i-j) - Flow(i-j)
 If the flow along an arc is from an unlabeled node to a labeled node and the arc
belongs to R, then label the unlabeled node and call the arc a backward arc and
let R(i-j) = Flow(i-j)

 2020, Jayant Rajgopal


Continue the labeling procedure until (a) the sink has been labeled, or
(b) no more nodes can be labeled.
STEP 3: If the sink has not been labeled, STOP; this is the optimum
flow. If the sink has been labeled go to Step 4.
STEP 4: There is a chain C from source to sink.
 If C has only forward arcs, increase the flow in each arc by an
amount f = Min(i-j)CI(i-j)
 If C has forward and backward arcs, increase the flow in each
forward and decrease the flow in each backward arc by an amount
f = MIN {k1=Min(i-j)ICI(i-j), k2=Min(i-j) RC{R(i-j)}
Return to Step 1

 2020, Jayant Rajgopal


O-A A-B B-D D-F
5-3=2 1-0=1 4-0=4 9-3=6
A F
33
9
3 +15 1 3+1
9+1 1
0+1
7 5 0+1 4
O B D
6
2 55 1 6
1
41

C 14
E

 2020, Jayant Rajgopal


O-B B-D D-F
7-5=2 4-1=3 9-4=5
A F
33
9
45 1 4+2
10+2 1
1
7 5 +2 4 1 +2
O B D
6
2 55 1 6
1
41

C 14
E

 2020, Jayant Rajgopal


O-C C-E E-D D-F
4-1=3 4-1=3 1-0=1 9-6=3
A F
33
9
45 1 6+1
12+1 1
1
7 7 43
O B D
6
2 55 0+1 1 6
1
4 1 +1

C 1 +1 4
E

 2020, Jayant Rajgopal


O-C C-E B-E B-D D-F
4-2=2 4-2=2 5-0=5 4-3=1 9-7=2
A F
33
9
45 1 7 +1
13 +1 1
1
7 7 4 3 +1
O B D
6
2 55 -1 1 1 6
1
4 2 +1

C 2 +1 4
E

 2020, Jayant Rajgopal


can’t go further---OPTIMAL FLOW!
A F
33
9
45 1 8
14 1
1
7 7 44
O B D
6
2 54 1 1 6
1
43

C 34
E

 2020, Jayant Rajgopal


Cut Set: Suppose V1 is any subset of all the nodes that contains
the sink but not the source, and V2 is the set of remaining nodes.
Then the corresponding cut set is the set of all arcs (i-j) such that
iV2 and jV1.
The capacity of the cut is the sum of the capacities of all arcs in
the cut set.
E.g., A Si
V1={B, D, Si}
2 7 V2={So, A, C, E}
2 5
Cut Set={So-B,A-B,A-D,C-B,E-D,E-Si}
So 5 B 4 D
Capacity=5+2+7+1+1+7 =23
7
1 3 1
V1={C, D, E, Si}
4
V2={So, A, B}
C E
4 Cut Set={So-C,A-D,B-D,B-E}
Capacity=4+7+4+3=18
 2020, Jayant Rajgopal
Lemma 1: The total flow from source to sink in any feasible flow is no higher than
the capacity of any cut set.
In particular, the optimal flow (which is obviously also a feasible flow) can thus
never be higher than the capacity of any cut set.
So, if we find some feasible flow and some cut set for which the flow is equal to
the capacity of the cut set, then this must be the optimal flow!
Now, suppose we are doing our labeling and we get to a point where we’re unable
to label the sink. Let V1 here correspond to the nodes (including the sink…) that
are not labeled and V2 to the nodes that have been labeled, and let us denote the
corresponding cut set via C.
Lemma 2: If the sink cannot be labeled, then the capacity of the cut set C must be
equal to the current flow from source to sink.
So, if the sink cannot be labeled, the current flow must be optimal –we just use
Lemma 2 to verify that the sink cannot be labeled.

 2020, Jayant Rajgopal


V2 = {O, A, B, C, E}; V1 = {D,F}
Cut Set: {A-D, B-D, E-D, E-F}
Capacity of Cut Set = 3+4+1+6 =14
A F
33
9
45 1 8
14 1
1
7 7 44
O B D
6
2 54 1 1 6
1
43

C 34
E

 2020, Jayant Rajgopal


 Recall the MCNFP
 Assuming that i=1..m bi = 0

PROBLEM MCNF:
Minimize all defined i-j (cijxij)

st j xij - k xki = bi for i=1,2,…,m

Lij xij Uij for all i-j


 2020, Jayant Rajgopal
Minimize i j (cijxij)

st j xij = Si if i  pure supply nodes


-j xij = -Dj if i  pure demand nodes
j xij - k xki = 0 or Si or Di if i  transshipment node
(as the case may be…)
0xij for all i-j

 2020, Jayant Rajgopal


 Define the starting node as a source node with a supply of 1 unit and the
ending node (say m) as a sink node with a demand of 1 unit.
 All other nodes are transshipment nodes
 The cost associated with a node is its distance
Then we have
Minimize all defined i-j (cijxij)

st j x1j =1
j xij - k xki = 0 for i=2,…,m-1
- k xkm = -1
0xij for all i-j

 2020, Jayant Rajgopal


 Let the source node have a very large supply (M) and the sink node have a very large
demand equal to the same value M
 All other nodes are transshipment nodes
 The cost associated with all arcs are equal to zero, and the upper bound Uij for the flow
along arc i-j is set to the capacity of the arc (Cij)
 Finally, add a fictitious arc from the source to the sink node with Uso-si=M and a cost of 1
Then we have (assume that source node is node no. 1, and the sink node is node no. m)
Minimize xso-si

st j xso-j =M

j xij - k xki = 0 for i=2,…,m-1

- k xk-si = -M
0 xij Uij for all i-j

 2020, Jayant Rajgopal

You might also like