[ library(graph_algorithms) | The ECLiPSe Libraries | Reference Manual | Alphabetic Index ]

single_pair_all_shortest_paths(+Graph, +DistanceArg, +SourceNode, +SinkNode, -Paths)

Computes all shortest paths from a source to a sink node
Graph
a graph structure
DistanceArg
which argument of EdgeData to use as distance: integer
SourceNode
source node number
SinkNode
sink node number
Paths
a (possibly empty) list of Length-EdgeList structures

Description

Computes all shortest paths from SourceNode to SinkNode. If there are no paths at all, an empty list is returned. Otherwise, all minimal paths are returned in a list.

DistanceArg refers to the graph's EdgeData information that was specified when the graph was constructed. If EdgeData is a simple number, then DistanceArg should be 0 and EdgeData will be taken as the length of the edge. If EdgeData is a compound data structure, DistanceArg should be a number between 1 and the arity of that structure and determines which argument of the EdgeData structure will be interpreted as the edge's length. Important: the distance information in EdgeData must be a non-negative number, and the numeric type (integer, float, etc) must be the same in all edges.

If DistanceArg is given as -1, then any EdgeData is ignored and the length of every edge is assumed to be equal to 1.

The shortest paths are returned as a list of Length-EdgeList structures where Length is the length of the shortest path and EdgeList is such a path in reverse order, i.e. starting with the edge reaching SinkNode and ending with the edge starting from SourceNode.

Examples

    ?- sample_graph(G), single_pair_all_shortest_paths(G, 0, 1, 3, P).
    P = [2 - [e(2, 3, 1), e(1, 2, 1)]]
    

See Also

all_shortest_paths / 4, single_pair_shortest_path / 5