International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 A Comparative study on Algorithms for Shortest-Route Problem and Some Extensions Sohana Jahan, Md. Sazib Hasan Abstract-- The shortest-route problem determines shortest routes from one node to another. In this paper Dijkstra s Algorithm and Floyd s algorithm to determine shortest route between two nodes in the network are discussed. Some extensions in Floyd s algorithm have done. We have formulated a shortest route problem as a linear programming problem and solved it as a 0- integer programming problem. The dual of the formulated linear programming problem is also used to determine the shortest routes. Complementary Slackness Theorem is used to solve the primal problem from the solution of the dual problem and to determine the shortest distance as well as the shortest routes. Index Terms-- Complementary Slackness Theorem, Dual of an LPP, Dijkstra s algorithm, Floyd s algorithm, 0- Integer Programming Problem. I. Introduction Network optimization [], [] has always been at the heart of operational research. Shortest Route model is one of the network models whose applications cover a wide range of areas, such as telecommunications and transportation planning. The shortest-route problem [],[],[] determines shortest routes from one node to another. There are a number of algorithms that can be used to Sohana Jahan is with the the Department of Mathematics, University of Dhaka, Dhaka, Bangladesh ( e-mail:jahansohana@univdhaka.edu) Md. Sazib Hasan is with the Department of Mathematics, Brac University, Dhaka, Bangladesh. (e-mail : sazib@bracu.ac.bd) determine shortest distance and shortest route between two nodes in a network. In this paper we have discussed Dijkstra s algorithm [], [] and Floyd s algorithm []. We have made some extensions in Floyd s algorithm. We have given the linear programming formulation of a shortest route problem and solved it as a 0- integer programming problem []. We have also solved the problem by solving the dual of the formulated linear programming problem [] and determined the shortest routes. We have also used Complementary Slackness Theorem [] to solve the primal problem from the solution of the dual problem and determined the shortest distance as well as the shortest routes. II. Algorithms to find Shortest-Route There are a number of algorithms that can be used to determine shortest route between two nodes in a network. Among them Dijkstra s algorithm and Floyd s algorithm are more efficient. Dijkstra s algorithm [],[] determines the shortest route between the source node and every other node and Floyd s algorithm[] determines the shortest route between all pair of nodes in the network.. Dijkstra s algorithm: Let u i be the shortest distance from source node to node i, and define d ij ( 0)as the length of arc (i, j). Then the algorithm 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 defines the label for an immediately succeeding node j as [u i, i] = [u i + d ij, i], d ij 0. The label for the starting node is [0, -], indicating that the node has no predecessor. Node labels in Dijkstra s algorithm are of two types: temporary and permanent. A temporary label is modified if a shorter route to a node can be found. At the point when no better routes can be found, the status of the temporary label is changed to permanent. Step 0: Label the source node (node ) with the permanent label [0, - ]. Set i =, Step i: (a) Compute the temporary labels [u i + d ij,i] for each node j that can be reached from node i, provided j is not permanently labeled. If node j is already labeled with [u j, k] through another node k and if u i + d ij < u j, replace [u j, k] with [u i + d ij, i]. (b)if all the nodes have permanent labels, stop. Otherwise, select the label [u r, s] having the shortest distance (= u r ) among all the temporary labels. Set i = r and repeat step i. Now we consider the following network to implement the Dijkstra s algorithm Example: The network in Fig:. gives the routes and their lengths in miles between city (node ) and seven other cities (nodes,,,,,, ). We determine the shortest routes between city and each of the remaining seven cities. Fig.. According to Dijkstra s algorithm we start with iteration 0. Iteration 0: Assign the permanent label [0,-] to node. Iteration : Nodes and can be reached from node. Thus, the list of labeled nodes (temporary and permanent) becomes Node Label Status [0, -] Permanent [0+, ]=[,] Temporary [0+, ]=[,] Temporary Between the two temporary labels [, ] and [, ], node yields the smaller distance (u =). Thus, the status of node is changed to permanent. Iteration : Nodes and can be reached from node, and the list of labeled nodes becomes Node Label Status [0,-] Permanent [,] Permanent [,] or Temporary [+,]=[,] [+,]=[, ] Temporary [+, ] = [, ] Temporary 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 9 Among the temporary labels [, ], [, ], [, ], node yields the smaller distance (u =). Thus, the status of the temporary label [, ] at node is changed to permanent. Continuing in this way we have the final table in the last iteration: Iteration : Node Label Status [0,-] Permanent [,] Permanent [, ] Permanent [, ] Permanent [, ], [, ] Permanent [, ] or [, ] Permanent [0,] Permanent [, ] Permanent Therefore, the following sequence determines the shortest route from node to node () [, ] () [, ] () [, ] () [,] () Thus, the required rout is with a total length of miles. The route is shown in the following diagram in blue color. The alternative routes with shortest distance from node to node are and.. Floyd s Algorithm and some extension Floyd s algorithm determines the shortest route between any two nodes in the network, so this algorithm is more general than Dijkstra s algorithm. The algorithm represents an n-nodes network as a square matrix with n rows and n columns. Entry (i, j) of the matrix gives the distance d ij from node i to node j, which is finite is finite if i is linked directly to j, and infinite otherwise Given three nodes i, j, and k in Fig:. with the connecting distances shown on the three arcs, it is shorter to reach k from i passing through j if d ij + d jk < d ik In this case, it is optimal to replace the direct route from i k with the indirect route i j k. This triple operation exchange is applied systematically to the network using the following steps: 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 0 Step 0. Define the starting distance matrix D 0 and node sequence matrix S 0 as given below. The diagonal elements are marked with ( - ) to indicates that they are blocked. Set k =.. i. n D 0 j n - d d n d n d - d n d n...... d i d i d ij d in...... d n d n d nj - S 0 j n j n n....... i j n....... n j - General step k: Define row k and column k as pivot row and pivot column. Apply the triple operation to each element d ij in D k- for all i and j. that means if any entry of the pivot column is then the row corresponding this pivot element need not to consider for triple operation in this step. If the condition d ik + d kj < d ij, (i k, j k and i j) is satisfied, make the following changes: (a). Create D k by replacing d ij in D k- with d ik + d kj. (b). Create S k by replacing s ij in S k- with k. Set k=k+, and repeat step k up to n step. If d ik + d kj = d ij, (i k, j k and i j), d ij need not to replace by d ik + d kj but it meansn i k j is al alternative way of i j of length d ij. After n steps, we can determine the shortest route between nodes i and nodes j from the matrices D n and S n using the following rules:. From D n, d ij gives the shortest distance between nodes i and j.. From S n, determine the intermediate node k = s ij that yields the route i k j. If s ik = k and s kj = j, stop; all the intermediate nodes of the route have been found. Otherwise, repeat the procedure between nodes i and k, and between nodes k and j. Extensions. The triple operations should be done on the entries d ij of the rows and columns corresponding to finite entries of the pivot row and pivot column in D k- for all i and j. that means if any entry of the pivot column is then the row corresponding this pivot element need not to consider for triple operation in this step. For example, in the following table the rd row and rd column are pivot row and pivot column respectively. The entry d = in the pivot row. So the first column needs not to be considered for the triple operation. Same argument is applicable for the nd, th and th column as well as for the th, th, th, th and th rows. 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 D - - - - - - - S 0 In general if kth row and kth column are pivot row and pivot column respectively then if d kj = then we can leave the jth column for triple operation in this step. And if d ik = then ith row can be avoided.. For triple operation we should not consider those entries d ij of the rows (columns) corresponding to any element of the pivot column (row) which satisfies d ij d kj. Example: We will determine the shortest routes between every two nodes for the network, shown in Fig:., where the distance (in miles) is given on the arcs. All the arcs allow traffic in one direction. Iteration 0: The matrix D 0 and S 0 give the initial representation of the network. d ij = implies no traffic is allowed from node i to node j. D 0 - - - - - - - Iteration: Set k=. The pivot row and column are shown by the lightly shaded first row and first column in the D 0 matrix. Since all the entries in the pivot column is. None of the entries d ij can be improved by the triple operation. Thus, D and S are same as D 0 and S 0. D - - - - - - - S 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 Iteration : Set k=. In this iteration nd row and nd column are pivot row and pivot column respectively, as shown by the lightly shaded row and column in D. All the entries d i = except d. Also d = d = d =. So we can apply triple operation on the entries d, d and d only.among them d and d are the cells that can be improved by triple operation. The D and S are obtained from D and S in the following way: i) Replace d with d +d = += and set s =. ii) Replace d with d +d = += and set s =. These changes are shown in matrices D and S : D - - - - - - - Continuing in this way the final matrices in the last iteration where none of the entries d ij can be improved by the triple operation becomes: D - - - - - - - S S D - 0-9 - - - - - In D d + d = d implies d cannot be improved by triple operation. But at the same time it indicates is an alternative way of of length. Thus in the third iteration where k =, the matrices are: S 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 Now we can determine the shortest distance between any two cities from the matrix D. Also the shortest route can also be determined from S. For example, the shortest distance between the city and the city is d = mile. Now, to determine the shortest route between city and city, recall that a segment (i, j) represents a direct link only if s ij = j. Otherwise, i and j are linked through at least one other intermediate node. Since s =, the route is initially given as. Now, since s =, the segment (, ) is not a direct link and must be replaced with. s = so (,) is a direct link. Thus the route now becomes. Next, because s =, s = the route needs no further dissecting and the process ends. Similarly the shortest distance between the cities and is d = miles and the shortest route is. III. Linear Programming Formulation of the Shortest- Route Problem: Most of the network problem can be formulated as a Linear programming problem and can be solved by simplex type algorithm. In this section we discuss two Linear Programming (LP) formulations [],[], [] for the shortest-route problem. The formulations are general in the sense that they can be used to find the shortest route between any two nodes in the network. Consider the shortest-route network with n nodes and we desire to determine the shortest route between any two nodes s and t in the network. Formulation : This formulation assumes that an external one unit of flow enters the network at node s and leaves it at node t, where s and t are the two target nodes between which we seek to determine the shortest route. We define x ij = amount of flow in arc (i, j), for all feasible i and j, c ij = length of arc (i, j), for all feasible i and j. Because only one unit of flow can be in any arc at any one time, the variable x ij must assume binary values (0 or ) only. Thus, the objective function of the linear program becomes The constraint represents the conservation of flow at each node. For any node j, Total input flow = Total output flow. Formulation : This formulation is actually the dual problem of the LP in Formulation. Because the number of constraints in Formulation equals the number of nodes, the dual problem will have as many variables as the numbers of nodes in the network. Also, all the dual variables must be unrestricted because all the constraints in Formulation are equations. Let, y j = dual constraint associated with node j. 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 Given s and t are the start and terminal nodes of the network, the dual problem is defined as Maximize z = y t - y s Subject to y j y i c ij, for all feasible i and j All y i and y j unrestricted in sign. Example: Consider the problem of determining shortest route between the cities in the network as shown in Fig.. Here, s = and t =. The following diagram (Fig.) shows how the unit of flow enters at node and leaves at node Fig:. The associated LP is listed below: We set x ij = - for node i = for node j. Min z x x x x x x x x x x x x x x x x Node- - - = - Node- - - - = 0 Node- - - - = 0 Node- - - - = 0 Node- - - = 0 Node- - - = 0 Node- - = 0 Node- = Thus the Linear programming problem becomes. Minimize z = x + x + x + x + x + x + x + x +x +x + x +x +x +x + x + x Subject to x + x = x - x x x =0 x + x -x - x x = 0 x + x x - x x = 0 () x + x + x x x = 0 x + x + x - x x = 0 x + x + x x = 0 x + x = 0 x ij, for i,j =,,,,. The constraints represent flow conservation at each node. The problem is an 0 integer programming problem [9], [0]. We solved the above problem by TORA (a Windows based software).the optimal solution obtained by TORA is Z =, x =, x =, x =, x =. This solution gives the shortest route from node to node as and the associated distance is z = miles. 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 Dual of the formulated linear programming: We can solve the above problem using dual. Maximize z = y y Subject to y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y y (Route -) y, y,..., y unrestricted. Now solving the above dual problem using TORA we have y = -, y = -, y = -, y = -, y = -, y = -, y =, y = 0. The value of Z = gives the shortest distance from node to node. The solution satisfies in equation form the constraint of routes -, -, -, -, -, -, -, -, - and -. We can determine the shortest route from the constraints that are satisfied in equation form. For, we consider the sequence routes -, -, -, -, -. Thus the shortest route becomes: Similarly other routes from node to node with shortest length is,, and Note that, if we choose the route - we cannot move further from the node to any other node since each of the constraint of routes -, -, - is satisfied as an inequality in the optimal solution. We cannot choose the route - for the same reason. Also we can determine the route using Complementary Slackness Theorem [],[] by determining the values of the variables x ij of the primal problem. For, since the constraints of routes -, -, -, -, -and - are satisfied as inequality at the optimum values of y i in the dual problem, so by Complementary Slackness theorem the variables x = 0, x = 0, x = 0, x = 0, x =0, x = 0. And since the values of the slack variables of routes -, -, -, -, -, -, -, -,- and - are zero the values of the variables x, x, x, x, x, x, x, x, x, x are either 0 or. Substituting the values x = 0, x = 0, x = 0, x = 0, x =0 and x = 0 in the constraint set of the primal problem x + x = x - x x =0 x + x -x - x x = 0 x = 0 x + x x x = 0 () x + x x = 0 x = 0 x = 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 Thus we have a system of linear equations x + x = x - x x =0 x + x -x - x x = 0 () x + x x x = 0 x + x x = 0 By Gaussian elimination method the system in echelon form becomes: x + x = x + x + x = () x + x + x = x + x = We have equations in unknowns. So we three free variables, x, x and x. The possible choices of (x, x, x ) are (0,0,0), (0,0,), (0,,0), (0,,), (,0,0), (,0,), (,,0), (,,). Each of these possible choices may or may not be the solution points because the dependent variables have the restriction x ij = 0 or. For the first choice (0, 0, 0) substituting the values x = 0, x = 0 and x = 0 in the system () and solving we get x = 0, x =, x = 0 and x =. The variables with non zero value are x, x and x. Hence one route with shortest distance from node to node is ---. Again for the choice (0, 0, ), substituting x = 0, x = 0 and x = in the system () and solving we get x =, x =0, x = and x = 0. For this choice of the free variables we have x =, x =, x =, x =. Hence another route with shortest distance from node to node is. Note that if we choose x = 0, then from the last equation of system () we get x =.Now from the second last equation, since x = so x = 0 and x = 0.This implies if x =0 then the value of x must be 0. So the choices (0,, 0) and (,, 0) cannot give any shortest route. Again the choice (, 0, ) does not give a shortest route because it does not satisfy the system () of equations. Therefore the different routes with shortest distance from node to node for the choices of (x, x, x ) are as follows: (0,,) gives, (,0,0) gives, (,,) gives. Limitations: If the network is undirected then the set of decision variables will be very large. As a result simplex method will take more iteration than the other methods to get the optimum path. So Dijkstra s algorithm or Floyd s algorithm is preferable to get the shortest route between two nodes in an undirected network. IV.Conclusion We can determine shortest route from source node to any other node of the network applying Dijkstra s algorithm. Using Floyd s algorithm shortest route can be determined between any two nodes of the network. Formulating the shortest route problem as a linear programming problem we get a 0- integer linear programming problem (ILPP). Solving this we get the shortest distance from a source node to a sink node. Also solving the dual of the (ILPP) we get shortest distance as well as all possible shortest routes from the source node to the sink node. Complementary slackness theorem can also be used to find a solution of the primal problem (ILPP) from the solution of the dual problem to get the required results. 00- IJBAS-IJENS December 0 IJENS
International Journal of Basic & Applied Sciences IJBAS-IJENS Vol: No: 0 References: []. Dijkstra, E. W. "A note on two problems in connexion with graphs". Numerische Mathematik : 9, 99. []. Kenneth H. Rosen Discrete Mathematics and Its Applications, th Edition. Addison Wesley, 00, p -90-00 []. G. B. Dantzig., Linear programming and extensions. Princeton University Press, Princeton, NJ, 9. []. Hamdy A. Taha, Operation Research- An Introduction, Prentice Hall, 00, p -, 9-9 []. Kambo N.S., Mathematical Programming Techniques, East-West Press, 9, p -. []. Ralph P. Grimaldi Discrete and Combinatorial Mathematics- An Applied Introduction, Pearson Addison Wesley, 00, p 9-. []. Vanderbei Robert J. Linear Programming - Foundations and Extensions, Springer, 00, p -. [9]. Karlof John K. Integer Programming- Theory and Practice, Taylor and Fransis group, 00. [0]. Frederick S. Hiller, Gerald J. Lieberman, Introduction to Operations Research, McGraw Hill, 00, p -0.. []. Arsham H., Stability analysis for the shortest path problems, Journal of Congressus Numerantium, Vol., No., -0, 99. []. Arsham H., A Comprehensive Simplex-Like Algorithm for Network Optimization and Perturbation Analysis, Optimization, Vol., No., -, 99. []. Phillips N., Network Models in Optimization & Their Applications in Practice, Wiley, 99. []. Ahuja R. K., Magnanti T. L. and Orlin J. B. Network Flows: Theory, Algorithms, and Applications. Prentice Hall, Englewood Cliffs, NJ, 99. 00- IJBAS-IJENS December 0 IJENS