1 network optimization chapter 3 shortest path problems
TRANSCRIPT
1
Network Optimization
Chapter 3Shortest Path Problems
2
In a weighted digraph, a path of minimum weight from vertex v to vertex w is called a shortest path (SP) from v to w, and its length is called the shortest distance (SD) from v to w.
For undirected graph, we can define SP and SD between two vertices.
The shortest path problem can be treated as a transshipment problem.
3.1 Shortest paths from a single
source
3
3.1 Shortest paths from a single source
(a) If we want to find SP and SD from v to w , then:
let v be the only source with a supply of 1 unit; let w be the only sink with a demand of 1 unit; let other vertices be intermediate vertices; let the cost of sending one unit of the
commodity from i to j be the weight of the arc (i , j);
we now use the network simplex method to solve this transshipment problem. A 0-1 solution x* will be obtained, and the arcs (i , j) with
=1 form a shortest path from v to w. x
*
ij
4
3.1 Shortest paths from a single source
(b) if we want to find shortest paths from a given vertex v to each of the other n-1 vertices in the digraph, then:
let v be the only source with a supply of n-1 units;
let every other vertex be a sink with a demand of 1 unit;
let the cost of sending one unit of commodity from i to j be the weight of the arc (i , j);
then the shortest path problem is transformed to a transshipment problem, and hence can be solved by the network simplex method.
5
3.1 Shortest paths from a single source
We study other two algorithms: Dijkstra’s algorithm to find a SP and
the SD from a specified vertex to every other vertex;
Floyd and Warshall algorithm for all-pairs shortest path problem.
6
Main idea about the Dijkstra’s method Suppose the 5 nearest vertices to
v1 are v1,v3,v5,v7 and v9. Then finding the sixth nearest
vertex is easy. Assume the sixth nearest vertex is
v6 and the shortest path is (v1,…v?, v6).
Then v? must be one the 5 nearest vertices. Can you see why?
7
Another important idea!!
Suppose 1356 is the SP from 1 to 6. Then, for sure, 135 is the SP from 1 to 5. Can you see why?
As a result, to save the SP from 1 to 6, I just need to write down 5 and the SP from 1 to 5.
8
3.1 Shortest paths from a single source
Dijkstra’s algorithm Let the network G = (V, E), V = {1, 2, …,
n}, and the weight of the arc (i , j) be a(i , j) . If there is no arc from i to j (i j), then a(i , j) is taken as a large positive number
M. We want to find the SD and SP from
vertex 1 to all other vertices.
0
9
3.1 Shortest paths from a single source
In the Dijkstra’s algorithm, each vertex i is assigned a label which is either permanent, or tentative.
The permanent label L(i) of i is the SD from 1 to i;
The tentative label L’(i) of i is an upper bound for the SD from 1 to i.
At each stage of the procedure, V is partitioned to two sets: P and T, where P is the set of vertices with permanent labels, and T = V \ P is the set of vertices with tentative labels.
10
3.1 Shortest paths from a single source
We also need to use an index V(i) to record the vertex immediately before i . This index may be updated after each iteration, and when we complete computation, it shows the vertex immediately before vertex i in the shortest path from vertex 1 to i.
Dijkstra’s algorithm Step 0 (initial step) Set L(1) = 0. Set L’(j) = a(1, j) and V(j)=1 for j = 2, 3,
…, n. Set P = {1}, T = {2, 3, …, n}.
11
3.1 Shortest paths from a single source
Step 1 (Designation of a permanent label)
Find k T such that Declare vertex k to be permanently labeled:
Set T = T - k, P = P + k, L(k) = L’(k). If T = Ø (i.e. P = V), stop; the
computation is completed.
(j)}{L' min (k)L'Tj
12
3.1 Shortest paths from a single source
Step 2 (Revision of tentative labels) Set L’(j) = min {L’(j), L(k) + a(k, j)} for
all j T, and if now L’(j) = L(k) + a(k, j),
then update V(j) as V(j)=k. Go to step 1.
13
Informal steps
L’(1)=0, V’(1)=1, P = {1}, T = {2,…} For all v in T, L(v)=M, V(v)=1, For any v is still in T and adjacent to v*,
Update L’(v), V’(v) Find v*, s.t.
L’(v*) L(v), v in T. L(v*) = L’(v*) and V(v*) = V’(v*) Move v* from T to P.
14
3.1 Shortest paths from a single source
In each step 1 → step 2 → step 1 iteration, a vertex is moved from T to P.
So, we need to have n-1 iterations to complete computation, and for all j=2,3,…n, the indexes V(2), …, V(n) gives us n-1 arcs which together with all n vertices form a subgraph H of G(V, E).
15
3.1 Shortest paths from a single source
If there exists a path from vertex 1 to any other vertex, then H must be connected. H is acyclic because if V(k)=i, arc (i, k) is in the shortest path from 1 to k, and i must enter P earlier than k does.
So, H is a spanning tree rooted at vertex 1. And H is a shortest distance tree which includes the shortest paths from vertex 1 to other vertices.
16
3.1 Shortest paths from a single source
Example 3.1 Obtain the SD from 1 to the remaining
vertices in the directed network shown below, using Dijkstra’s algorithm.
17
3.1 Shortest paths from a single source
Iteration 1Step 1. P = {1} L(1)=0
T = {2, 3, 4, 5, 6, 7}L’(2) = 4, L’(3) = 6, L’(4) = 8,L’(5) = L’(6) = L’(7) = M.V(2)=V(3)=V(4)=V(5)=V(6)=V(7)=1.Vertex 2 is assigned a permanent label.
18
3.1 Shortest paths from a single source
Step 2. P = {1,
2} L(2) = 4 Record ar
c (1,2)
T = {3, 4, 5, 6, 7}L’(3) = min {6, L(2) + a(2, 3)}=5L’(4) = min {8, L(2) + a(2, 4)}=8L’(5) = min {M, L(2) + a(2, 5)}=11L’(6) = min {M, L(2) + a(2, 6)}=ML’(7) = min {M, L(2) + a(2, 7)}=MV(3)=2, V(5)=2.
19
3.1 Shortest paths from a single source
Iteration 2Step 1. P={1,2} L(1) = 0 L(2) = 4
T = {3, 4, 5, 6, 7}Min{L’(i) | i in T}= L’(3) Vertex 3 is assigned a permanent label.
20
3.1 Shortest paths from a single source
Step 2 P = {1, 2,
3} L(3) = 5
T = {4, 5, 6, 7}L’(4) = min {8, L(3) + a(3, 4)}=7L’(5) = min {11, L(3) + a(3, 5)}=10L’(6) = min {M, L(3) + a(3, 6)}=9L’(7) = min {M, L(3) + a(3, 7)}=MV(4)=3, V(5)=3, V(6)=3.
21
3.1 Shortest paths from a single source
Iteration 3Step 1. P = {1, 2,
3} L(1) = 0 L(2) = 4 L(3) = 5
T = {4, 5, 6, 7}Min {L’(i) | i in T} = L’(4)Vertex 4 is assigned a permanent label.
22
3.1 Shortest paths from a single source
Step 2 P = {1, 2, 3,
4} L(4) = 7 T = {5, 6, 7}
L’(5) = min {10, L(4) + a(4, 5)}=10L’(6) = min {9, L(4) + a(4, 6)}=9L’(7) = min {M, L(4) + a(4, 7)}=M
23
3.1 Shortest paths from a single source
Iteration 4Step 1 P = {1, 2, 3,
4} L(1) = 0, L(2) = 4, L(3) = 5, L(4) = 7
T = {5, 6, 7}Min {L’(i) | i in T} =L’(6) Vertex 6 is assigned a permanent label.
24
3.1 Shortest paths from a single source
Step 2. P = {1, 2, 3, 4, 6} L(6) = 9
T = {5, 7}L’(5) = min {10, L(6) + a(6, 5)}=10L’(7) = min {M, L(6) + a(6, 7)}=17V(7)=6.
25
3.1 Shortest paths from a single source
Iteration 5Step 1 P = {1, 2, 3,
4, 6} L(1) = 0, L(2) = 4, L(3) = 5, L(4) = 7, L(6) = 9
T = {5,7}Min {L’(i) | i in T} = L’(5)Vertex 5 is assigned a permanent label.
26
3.1 Shortest paths from a single source
Step 2 P = {1, 2, 3, 4, 6, 5} L(5) = 10
T = {7}L’(7) = min {17, L(5) + a(5, 7)}=16V(7)=5
27
3.1 Shortest paths from a single source
Iteration 6Step 1. P = {1, 2, 3, 4, 6, 5} L(1) = 0, L(2) = 4, L(3) = 5, L(4) = 7, L(6) = 9, L(5) = 10.
T = {7}L’(7) = 16Vertex 7 gets a permanent label.
28
3.1 Shortest paths from a single source
Step 2. P = {1, 2, 3, 4, 6, 5,
7} L(7) = 16
T is empty
29
3.1 Shortest paths from a single source
Thus L(1) = 0, L(2) = 4, L(3) = 5, L(4) = 7, L(6) = 9, L(5) = 10 and L(7) = 16, giving the SD from 1 to each vertex.
The indexes V(2)=1, V(3)=2, V(4)=3, V(5)=3, V(6)=3, V(7)=5 show that arcs (1, 2), (2, 3), (3, 4), (3, 5), (3, 6) and (5, 7) constitute a shortest distance tree in the given network as shown below, giving the SP from vertex 1 to every other vertex.
30
3.1 Shortest paths from a single source
The shortest distance tree:
Question: is this a minimum weight spanning tree?
No, in MST, (6,5) replaces (3,6)
31
You answer should consist
Sequence of arcs. (according to the order the arcs are moved to P)
Tree (Draw it!!). Total weight.
32
3.1 Shortest paths from a single source
Theorem 3.1 Dijkstra’s algorithm finds the SD from vertex 1
to every other vertex i (i = 2, …, n). Proof. We prove the theorem by induction
on the cardinality of P. We will show that for each P generated in the algorithm,
(1) for every i P, L(i) is the SD from 1 to i. (2) for every j T, L’(j) is the length of an SP
from 1 to j under the restriction that every intermediate vertex is in P.
33
3.1 Shortest paths from a single source
First, when |P| = 1, i.e. P = {1}, T = {2, 3, …, n}, the two conclusions hold obviously. We now show that if conclusions (i)
and (ii) are true when |P| = k-1, then they also hold if |P| = k.
shore shore
34
3.1 Shortest paths from a single source
Without loss of generality, assume P = {1, 2, …, k-1}, T = {k, …, n}. By the assumption, (i) for i P, L(i) is the SD from 1 to i; (ii) for j T, L’(j) is the SD from 1 to j under the restriction that every intermediate vertex is in P.
35
3.1 Shortest paths from a single source
Also assume that in the current iteration, vertex k moves to P, i.e.
So, L(k) = L’(k), and
(△)
(*) (j)}{L' min (k)L'T j
, {k}TT {k}, PP
Tj j)},a(k, (k)L'(j),{L'min)j('L
36
3.1 Shortest paths from a single source
We need to show that (i) L(k) is the SD from 1 to k. If it is not true, let d be the SD from 1 to
k. So, d < L(k) = L’(k). As L’(k) is the SD from 1 to k provided that every intermediate vertex of the SP is in P, it means that along any SP from 1 to k, there must be at least one vertex in T. Let v be the first vertex in T along the SP from 1 to k.
37
3.1 Shortest paths from a single source
Let the SD from 1 to v be d’. Then d’ = L’(v) and d’ d < L’(k).
So, L’(v) < L’(k), which contradicts (*). Therefore, L(k) must be the SD from 1
to k.
(*) (j)}{L' min (k)L'T j
38
3.1 Shortest paths from a single source
(ii) We need to show that for each j = {k+1, …, n}, ’(j) is the SD from 1 to j under the restriction that all intermediate vertices are in .
Let be the SD from 1 to j when all intermediate vertices are in . The corresponding SP may have two possibilities:
TL
P
dP
39
3.1 Shortest paths from a single source
(a) The SP does not go through vertex k.
In this case, is the SD from 1 to j under the restriction that every intermediate vertex is in P = {1, …, k-1}. So, = L’(j).
d
d
40
(b) The SP includes vertex k.
In this case, k must be the last vertex before j in the SP. If not, the SP arrives at k, then reaches a q P, and at last comes to j.
It means the shortest path from 1 to q must pass through k, which is impossible because q enters P before k does, i.e. the SP from 1 to q need not to pass k.
Now since k is the last vertex in the SP before reaching j, the SD from 1 to j must be the SD from 1 to k plus a(k, j): L’(k) + a(k, j).
3.1 Shortest paths from a single source
41
3.1 Shortest paths from a single source
Combining the two cases (a) and (b), = min {L’(j), L’(k) +a(k, j)}. So, by the formula (△), ’(j) = , i.e.
’(j) is the SD from 1 to j under the restriction that every intermediate vertex of SP is in . So, the proof is completed.
dL d L
P
Tj j)},a(k, (k)L'(j),{L'min)j('L (△)
42
3.2 All shortest path algorithm
Let G = (V, A) be a directed network. V = {1, 2, …, n}.
Let auv be the weight of the arc (u, v). (in the method we allow some negative auv)
We want to calculate the SD from every vertex u to every other vertex v.
We will use The Floyd - Warshall Method
43
The main idea used Suppose v5 is the second vertex in
the shortest path from v1 to v9. That is, the shortest path from v1 to
v9 is (v1, v5, ???, v9). Besides, suppose (v5, v6, v7, v8, v9)
is the shortest path from v5 to v9. Then, we can assure the shortest
path from v1 to v9 is (v1, v5, v6, v7, v8, v9).
44
3.2 All shortest path algorithm
Let A = [auv] be the n n weight matrix;
P = [Puv] be the n n matrix with Puv = v, i.e.
The F&W method is an iterative method which needs to have n iterations. In the j-th iteration, we will have two n n matrices A(j) = [auv(j)] and P(j)=[Puv(j)] (j = 1, …, n). A(0)=A and P(0)=P.
n...21
.........
n...21
n...21
P
45
3.2 All shortest path algorithm
In A(j), auv (j) shall be the SD from u to v with intermediate vertices in the vertex set {1, 2, …, j}, and the corresponding element puv(j) in P(j) gives the vertex immediately after u in the path to attain the above SD auv(j).
46
3.2 All shortest path algorithm
The algorithm is as follows. Step 0 Let j = 1, A(0) = A and P(0) =
P. Step 1 for all (u,v), If auv (j-1) < auj (j-1)
+ ajv (j-1), then auv (j) = auv (j-1) and puv(j) = puv (j-1), otherwise
auv (j) = auj (j-1) + ajv (j-1) and
puv (j) = puj (j-1).
47
3.2 All shortest path algorithm
Step 2 If in matrix A(j), one diagonal element is negative, stop, the problem has a negative cycle, and some SD from a vertex to another vertex are unbounded.
If j = n, go to step 3; otherwise let j ← j+1 and return to Step 1.
48
3.2 All shortest path algorithm
Step 3 Each element auv(n) of the matrix A(n) gives the SD from vertex u to vertex v.
To find the SP from u to v, if puv (n) = j1, then the first arc of the SP is (u, j1). If j1 v, we continue by checking pj1v(n). If pj1v(n)=j2, then the second arc is (j1, j2). Repeat the procedure until we reach vertex v. Then the SP is u → j1 → j2 → …. → v.
49
3.2 All shortest path algorithm
We use an example to explain the algorithm.
Example 3.2 Obtain the SD matrix and the SP
matrix in the directed network as shown below.
50
3.2 All shortest path algorithm We begin with the following
matrices:
4321
4321
4321
4321
P(0) P and
0665
3010
703
340
A(0) A M
M
M
51
4121
4321
4321
4321
P(1) and
0265
3010
703
340
A(1)M
M
M
3.2 All shortest path algorithm Iteration 1, based on vertex 1 (j
= 1) at the end of the first iteration we
have the following matrices:
4321
4321
4321
4321
P(0) P and
0665
3010
703
340
A(0) A M
M
M
52
3.2 All shortest path algorithm
Matrix A(1) is obtained from A(0) by the following “triangle” operation:
Draw two lines on row k and column k respectively (here k=1, and when we calculate A(2), k=2, ……).
In A(0), for each element which is neither in row k, nor in column k, find its two projections on the two lines. For example for element , its two projections are and respectively.
Compare the sum of the two values at the projections with the value at the element. (e.g., compare with ). Then we use the rule in the F-W method to obtain A(1) and P(1).)0(43a
)0(43a)0(13a)0(41a
)0()0( 1341 aa
53
3.2 All shortest path algorithm
Iteration 2, based on vertex 2 (j=2)
It begins with A(1) and P(1). The triangle operations are carried out as in the previous operation (but now k=2) – at this stage the auv(2) = min{auv(1), au2(1) + a2v(1)}. At the end of this iteration we have the following matrices:
54
3.2 All shortest path algorithm
Iteration 2, based on vertex 2 (j=2)
4222
4322
4321
4321
P(2) and
0163
30107
703
3-40
A(2)M
M
4121
4321
4321
4321
P(1) and
0265
3010
703
340
A(1)M
M
M
55
3.2 All shortest path algorithm
Iteration 3, based at vertex 3 (j=3)
It begins with A(2) and P(2). Applying the triangle operation (let k=3), we obtain the following matrices:
4222
4322
3321
3321
P(3) and
0163
30107
4703
0340
A(3)
4222
4322
4321
4321
P(2) and
0163
30107
703
3-40
A(2)M
M
56
3.2 All shortest path algorithm Iteration 4, based on vertex 4
(j=4) It begins with A(3) and P(3).
Applying the triangle operation (let k=4) , we get the following matrices:
4222
4344
3321
3321
P(4) and
0163
3096
47-03-
03-40
A(4)
4222
4322
3321
3321
P(3) and
0163
30107
4703
0340
A(3)
57
3.2 All shortest path algorithm
At this stage we have the SD from every vertex to every other vertex in the network, which can be obtained readily from A(4).
The various shortest paths are obtained as follows:
From 1 to 2: p12(4)=2. So the SP is 1→2, i.e., the arc (1, 2).
From 1 to 3: p13(4) = 3. So the SP from 1 to 3 is the arc (1, 3). 1 2 3 3
1 2 3 3P(4)
4 4 3 4
2 2 2 4
58
3.2 All shortest path algorithm
From 1 to 4: p14(4) = 3. So take the arc (1, 3) and join it to the SP from 3 to 4. We have p34 (4) = 4. So the SP from 3 to 4 is the arc (3, 4). Thus the SP is 1→3→4.
From 2 to 1: the SP is the arc (2, 1). From 2 to 3: the SP is the arc (2, 3). From 2 to 4: the SP is 2→3→4. From 3 to 1: the SP is 3→4→2→1. From 3 to 2: the SP is 3→4→2. From 3 to 4: the SP is the arc (3, 4). From 4 to 1: the SP is 4→2→1. From 4 to 2: the SP is the arc (4, 2). From 4 to 3: the SP is 4→2→3.
1 2 3 3
1 2 3 3P(4)
4 4 3 4
2 2 2 4
59
3.2 All shortest path algorithm
Locating negative cycles Consider a network for which the
weight matrix is as follows:
0342
0
3102
10
A MMM
MM
60
3.2 All shortest path algorithm
At the end of the second iteration we have the following matrices:
0 1 1 2 3 4
2 0 1 3 1 2 3 4A(2) and P(2)
0 1 2 3 4
2 4 3 1 2 2 2 2
M M
M M M
61
3.2 All shortest path algorithm
In A(2), the diagonal element a44(2)= -1 <0, indicating the presence of a negative cycle in the network. The negative cycle can be located by using P(2) matrix, which is 4 → 2 → 4.
So, the F&W algorithm will stop calculation after obtaining A(2) and P(2).
62
3.2 All shortest path algorithm
Theorem 3.2 If the network contains no negative cycle, then in using the Floyd-Warshall algorithm, auv(n), the
(u, v)th element in A(n), is equal to the SD from u to v.
Proof Suppose the algorithm works until obtaining A(n) and P(n), and there is no negative cycle.
63
3.2 All shortest path algorithm
We use the induction method to show that for j =1, …, n, auv(j) is the SD from u to v with each intermediate vertex w j.
For j=1, as auv(1)= ,
obviously auv(1) is the SD from u to v if only vertex 1 can be a possible intermediate vertex.
otherwise aa
aaa if a
1u1
1vu1uvuv
v
64
3.2 All shortest path algorithm
Suppose auv(j-1) is the SD from u to v with each intermediate vertex w j-1. Let Quv(j) be the SP from u to v with every intermediate vertex w j.
It has two possibilities: (1) Quv(j) does not take j as an intermediate
vertex. Then Quv(j) = Quv(j-1)
and hence auv(j) = auv(j-1). (a)
65
3.2 All shortest path algorithm(2) Quv(j) has vertex j as an intermediate
vertex.
Then the part of Quv(j) from u to j must
be the SP from u to j with every intermediate vertex w j-1, i.e., it is Quj(j-1), and the part of Quv(j) from j to v must be Qjv(j-1). So,
auv(j) = auj(j-1) + ajv(j-1). (b)
66
3.2 All shortest path algorithm
Combining (a) and (b), we know that the SD from u to v with each intermediate vertex w j is
auv(j) = min{auv(j-1), auj(j-1) + ajv(j-1)}, which is just the formula in step 1. Therefore we proved that the
conclusion is true for j, and the induction proof is completed.
67
3.2 All shortest path algorithm
An exercise for F-W method. For the network shown on the next page, when we use F-W method to obtain all pairs of shortest distances, the final matrices A(6) and P(6) are:
023345
101423
430512
134034
563401
652620
)6(A
655355
654644
554222
666322
311321
644221
)6(P
68
3.2 All shortest path algorithm
Graph of the exercise
69
3.2 All shortest path algorithm
a. Using matrix P(6), show the shortest paths from vertex 3 to all other vertices and the shortest paths from vertex 4 to all other vertices.
b. Using matrix A(6) to verify your answer for question a.
70
3.3 Medians and centers
Location Problem In a network, we need to find a vertex
such that the distances to other vertices meet some optimality criterion.
Suppose G=(V,E), V = {1, 2, …n}. The following two criteria (Minsum Problems & Minmax Problems) are often used.
71
3.3 Medians and centers
1. Minsum Problems Find a vertex j such that the sum
of the distances from j to all other vertices is as small as possible.
Let d(j, k) be the shortest distance from j to k ( d( j, j )=0 ), then the Minsum problem is
n
1kn1,2,..., j
k)d(j,min
72
3.3 Medians and centers
This problem is also called l1 norm location problem as for the non-negative vector
dj = (d (j,1), d (j,2), …, d (j,n)), the l1 norm ||dj||1 = , (if all d(j,k) are non-negative) and the location problem is to find
n
1k
k)d(j,
1jn1,2,..., j
||d|| min
73
3.3 Medians and centers Once we obtain the n n shortest
distance matrix D = [d(i, k)] (for example by the F-W method), it is easy to solve the minsum location problem:
let then the best location is the vertex j such
that . The vertex j is also called a median
(vertex).
n
1ki k)d(i,s
in1,2,..., i
j smins
74
3.3 Medians and centers For example:
S1=21
S2=19
S3=15
S4=15
S5=11
S6=17
median
vertex
023345
101423
430512
134034
563401
652620
)6(A
75
3.3 Medians and centers
2. Minmax problems Find a vertex j such that the
distance from j to the farthest vertex is minimized, i.e. to solve the problem:
k)d(j,Max Minn1,...,kn1,.., j
The vertex j is also called a center (vertex).
76
3.3 Medians and centers
This is also called the norm location problem, because
= Max (d (j, 1), d (j, 2), …, d (j,
n))(if all d(j,k) are non-negative) and we want to find
L
||d|| j
||d|| Min j
n1,.., j
77
3.3 Medians and centers
The Minmax location problem can also be solved easily once we obtain the all pair SD matrix D=[d(i, k)].
For each row i, let Then the best location for the
minmax problem is vertex j such that
k)d(i, Max n1,.., k
ie
in1,.., i
e Min
je
78
3.3 Medians and centers For example:
e1=6
e2=6
e3=4
e4=5
e5=4
e6=5
center vertex
023345
101423
430512
134034
563401
652620
)6(A
centervertex
79
3.3 Medians and centers
It depends on different purposes to choose Minsum or Minmax criterion.
For example, a delivery company which transports goods to all vertices may use the Minsum criterion.
A fire station may use the Minmax criterion to decide its place.
80
Use NETSOLVE to calculate shortest paths Specify directed or undirected
graph by typing D or U to answer the question by NETSOLVE, depending on the particular problem.
No node data required. Need to enter edge (arc) data.
Enter the two node names and the weight of the edge (arc).
81
Use NETSOLVE to calculate shortest paths
NETSOLVE can calculate 4 types of shortest paths.
Type 1: from a given source vertex (say 2) to a given destination vertex (say 5).
Command: SPATH 2 5Type 2: from a given source vertex (say
1) to all other vertices.Command: SPATH 1 *
82
Use NETSOLVE to calculate shortest paths
Type 3: from all vertices to a given destination vertex (say 3).
Command: SPATH * 3Type 2: from any vertex to all other
vertices.Command: SPATH * *
83
Use NETSOLVE to calculate shortest paths
Example. For the network shown below, calculate all pairs of shortest paths
84
Use NETSOLVE to calculate shortest paths
Need to enter edge data:1 2 2 4 5 3 | Then type:1 4 2 5 4 1 | SPATH * *1 6 6 5 6 1 | You may see the 2 1 4 6 3 3 | result of SD & SP2 3 4 6 5 2 | from every
vertex 3 2 3 | i to any other 3 6 1 | vertex j4 2 1 |