Ford-Bellman Shortest Path Algorithm with step-by-step execution Fernando Michel Tavera Student at National Autonomous University of Mexico (UNAM) Mexico e-mail: fernando_michel@ciencias.unam.mx Social service project director: Dr. Patricia Esperanza Balderas Ca\303\261as Full time professor at National Autonomous University of Mexico (UNAM) Mexico e-mail: balderas.patricia@gmail.com
<Text-field style="Heading 1" layout="Heading 1">Introduction</Text-field> The Ford-Bellman Shortest Path Algorithm is a well known solution to the Shortest Paths problem, which consists in finding the shortest path (in terms of arc weights) from an initial vertex r to each other vertex in a directed weighted graph In this work we utilize the definition of the Ford-Bellman algorithm given by Cook et. al. (see References) which is as follows: "Initialize y, p; set i = 0; While i < n and y is not a feasible potential Replace i by i + 1; For e\342\210\210E If e is incorrect Correct e." where: y is a set of y(v), the size of the shortest path found so far from r to v, for each vertex v; p is a set of the 'parent vertex' p(v)of each vertex v, that is to say the vertex prior to v in the shortest path from r to v found so far; Initialize means setting y(v) = \342\210\236 and p(v) = null for each for each vertex v except r, and y(r) = 0 (the value of p(r) is not important); An arc a=(u,v) with weight w is considered incorrect if y(u) + w \342\211\244 y(v), and correct otherwise; Correcting an arc a=(u,v) means changing the value of y(v) to y(u) + w such that a becomes correct, and setting p(v) = u in the process; And y is a feasible potential if all arcs are correct. This work is part of a social service project consisting in the implementation of several graph theory algorithms with step-by-step execution, intended to be used as a teaching aid in graph theory related courses. The usage examples presented were randomly generated.
<Text-field style="Heading 1" layout="Heading 1">Module usage</Text-field> The FordBellmanSP module contains only a single procedure definition for FordBellman(G, initial, stepByStep, draw), as follows: Calling FordBellman(...) will attempt to calculate the shortest paths in graph G from initial to every other vertex using the Ford-Bellman Algorithm. The parameters taken by procedure FordBellman(...) are explained below: G is an object of type Graph from Maple's GraphTheory library, it is the graph for which the shortest paths will be computed. G must be defined as directed, otherwise the procedure will terminate with an error. This parameter is not optional initial is a symbol representing the vertex of G from which the shortest paths will be calculated. If the given symbol is not in the vertex list of G, the procedure will terminate reporting an error, otherwise the vertex of G with a label matching the given symbol will be used as initial. This parameter is not optional. stepByStep is a true/false value. When it is set to true, the procedure will print a message reporting whenever an arc is corrected. When it is false, only the final result will be shown. This parameter is optional, and its default value is false. draw is a true/false value. When it is set to true, the resulting shortest paths graph will be displayed after computation finishes; if both stepByStep and draw are true then the graph G will be drawn at every step, highlighting the arcs currently in a shortest path in green and the replaced arcs in red. When draw is set to false, the graphs will not be displayed, and the procedure will print a list containing the shortest paths to each vertex, in the format: [[v1,[route to v1],distance to v1],[v2,[route to v2],distance to v2],...,[vn,[route to vn],distance to vn]] This parameter is optional, and its default value is true. The return value can be one of three possibilities as follows: If draw is true, the procedure returns a subgraph H of G containing only the arcs of G which are used in a shortest path. If draw is false, the procedure will return a list containing the shortest paths to each vertex, this is so the value reported by Maple contains more useful information. If initial is a symbol not present in the vertex list of G, or if G is not a directed graph, or if G contains a negative weight loop, or if there are vertices unreachable from initial, the procedure will return the string "ERROR".