Traffic Assignment: Urban Transportation Systems Planning
Traffic Assignment: Urban Transportation Systems Planning
a 3 5 7 f
4 1
c e
6
• So many ways, 5 links can be selected to ensure
connectivity of all the 6 nodes
• But, for the minimum spanning tree (shown by
yellow lines), the total cost is minimum
Indian Institute of Technology, Kharagpur
Step 1
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Step 2
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Step 3
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Step 4
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Step 5
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Prim’s Algorithm
• Start at any vertex in a graph (vertex A, for
example), and find the least cost vertex (vertex B,
for example) connected to the start vertex.
• Now, from either 'A' or 'B', find the next least costly
vertex connection, without creating a cycle (vertex
C, for example).
• Now, from either 'A', 'B', or 'C', find the next least
costly vertex connection, without creating a cycle,
and so on
• Eventually, all the vertices will be connected,
without any cycles, and an MST will be the result
Indian Institute of Technology, Kharagpur
Example
Step 1 4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Step 2
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Step 3
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Step 4
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Step 5
4
b d
1 2
a 3 5 7 f
4 1
c e
6
Indian Institute of Technology, Kharagpur
Shortest path
• Finding a path between two vertices (or nodes)
such that the sum of the weights of its constituent
edges is minimized
• Formally, given a weighted graph (that is, a set V
of vertices, a set E of edges, and a real-valued
weight function f : E → R), and one element v of V,
find a path P from v to a v' of V so that
– Σf(p), p ϵ P, is minimal among all paths
connecting v to v'
Indian Institute of Technology, Kharagpur
Dijkstra's algorithm
• It solves the single-pair, single-source, and
single-destination shortest path problems
Indian Institute of Technology, Kharagpur
Algorithm
• Let's call the node we are starting as initial node
and from which Y be the distance to an other node
• Assign some initial distance values and try to
improve them step-by-step and assign to every
node a distance value; Steps are
Set it to zero for initial node and to infinity for
all other nodes and mark all nodes as unvisited
Set initial node as current
For current node, consider all its unvisited
neighbours and calculate their distance
Indian Institute of Technology, Kharagpur
• For example, if current node (A) has distance of 6, and
an edge connecting it with another node (B) is 2, the
distance to B through A will be 6+2=8
• If this distance is less than the previously recorded
distance (infinity in the beginning, zero for the initial
node), overwrite the distance
• When we are done considering all neighbours of the
current node, mark it as visited
• A visited node will not be checked ever again; its
distance recorded now is final and minimal
• Set the unvisited node with the smallest distance (from
the initial node) as the next "current node" and
continue from step 3
Indian Institute of Technology, Kharagpur
Example
9 5
6 6
2 11
3 4
14
9
10 15
1
7 2
14 9 5 6
6 22
2 (7+10)=17>9
11
3 4
14
9
10 15
0
1 7
7 2
Indian Institute of Technology, Kharagpur
• Now node 3 become the current node from which
the distance of node 4 is (9+11)= 20<22 and node
6 is (9+2)= 11<14
• The distance of node 6 from node 1 is more than
the distance from node 3, so
(9+2)=11<14
9 5 6
6
(9+11)=20<22
2 9
11
3 4
14
9
10 15
0
1 7
7 2
Indian Institute of Technology, Kharagpur
• Now node 6 become the current node from which
the distance of node 5 is (11+9)= 20
• And distance from node 5 to node 4 is (20+6)= 26 >
20, so
(11+9)=20
11
9 5 6
6
20
2 9
11
3 4
14
9
10 15
0
1 7
7 2