CPS 206 Fall 1999, Problem 11. Work alone.
Fibers: Final Project
You are to complete one or more of the following suggested projects, all related to the Fiber system of program execution. Each project should include determining the "useful instruction efficiency" of the Fiber program built, should assume that all input is read before timing begins, and all output is printed after timing ends (from an array or list left in memory). Each project should include a comparison of the Fiber program's results with those obtained from a sequential implementation of the same algorithm, to demonstrate correctness. Report the efficiency obtained on at least two test cases of your choosing:
Assume the data base contains the representation of a directed graph, as follows:
Each node i in the graph is accompanied by the facts: arcs(i, dl), where dl is a list of [ node, length] sublists. If [j, x] appears in dl, the graph has an arc of length dl from node i to node j. The problem is to find a path of least total distance (sum of its arc lengths) from node 0 to node N: path(N,L, D) is true when L is such a path (a list of nodes), and D is the total distance of path L.
A method that works well is due to Dijkstra: Label those nodes whose minimum distance from 0 is known with that distance. A new node not yet labeled can be labeled if that node is one whose direct distance from any labeled node is smallest. The currently-labeled nodes are maintained in a set H using facts that are added to the data base: inH(i) indicates that i is in H. Each node has a distance: d(i, distance) and these facts are updated during the computation. The graph's node set consists of all nodes numbered 0..N. A computation stage occurs as a new node is added to H. First, the arcs leaving that node are followed, and the tentative distance for arcs at each arc tip are adjusted. Then, the set of nodes not in H are searched for a node with smallest distance among these nodes. One node at minimum distance is selected and added to H, beginning the next stage. Once all nodes reachable from 0 have been added to H, the computation ends (it can end sooner, when N enters H). The list returned can be discovered from the d() facts in the data base, or it can be computed backwards from N, by a trail t(j, prev) of facts entered when node "prev" minimizes j's distance. During the computation, it may be helpful to maintain also the set of nodes that are reachable, and are not yet in H.
Modify the problem specification to allow the graph to be read from input in the form of triples of integers: From To Length.
There are at least 3 alternative approaches to the implementation of the algorithm. You should implement one of them: