Class R5R9Dijkstra
We report distances as total weights along the shortest path from the start node to the y node, where by default the weight of each edge is 1. We report unreachable nodes as at a distance of Integer.MAX_VALUE. Edges in the graph are dynamically calculated by the algorithm using two methods--looking for o-o edges only, suitable for the R5 rule, and looking for edges along potentially directed paths (i.e., semidirected paths), suitable for the R9 rule. The end node is used to stop the algorithm once that node has been visited, so that a shortest path has been found.
The algorithm is constrained to avoid certain paths. The start *-* end edge itself and start *-* z *-* end paths are avoided, to avoid length 1 or length 2 paths. Also, covered triples, z *-* r *-* w, z *-* w, are avoided to implement the constraint that only uncovered paths are considered. Coverings of end *-* start *-* z and start *-* end *-* w are also avoided, as specified for R5 and R9.
- Author:
- josephramsey 2024-8-6
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Represents a node in Dijkstra's algorithm.static class
Represents a graph for Dijkstra's algorithm.static enum
The rule that is being implemented, R5 or R9. -
Method Summary
Modifier and TypeMethodDescriptiondistances
(R5R9Dijkstra.Graph graph, Node x, Node y) Finds shortest distances from a x node to all other nodes in a graph, subject to the following constraints.static void
A simple test of the Dijkstra algorithm.
-
Method Details
-
distances
public static org.apache.commons.lang3.tuple.Pair<Map<Node,Integer>, distancesMap<Node, Node>> (R5R9Dijkstra.Graph graph, Node x, Node y) Finds shortest distances from a x node to all other nodes in a graph, subject to the following constraints. (1) Length 1 paths are not considered. (2) Length 2 paths are not considered. (3) Covered triples are not considered. (4) The y node is used to stop the algorithm once that node has been visited. (5) The graph is assumed to be undirected.Nodes that are not reached by the algorithm are reported as being at a distance of Integer.MAX_VALUE.
- Parameters:
graph
- The graph to search; should include only the relevant edge in the graph.x
- The starting node.y
- The ending node. The algorithm will stop when this node is reached.- Returns:
- A map of distances from the start node to each node in the graph, and a map of predecessors for each node.
-
main
A simple test of the Dijkstra algorithm. TODO This could be moved to a unit test.- Parameters:
args
- Command line arguments.
-