java.lang.Object
org.jgrapht.alg.shortestpath.AStarSpurEngine<V,E>
- Type Parameters:
V- graph vertex typeE- graph edge type
- All Implemented Interfaces:
SpurShortestPathEngine<V,E>
Spur shortest-path engine that delegates to JGraphT's
AStarShortestPath, using the
reverseDistancesToSink hint as an admissible heuristic. Bans are applied by wrapping the
input graph in a MaskSubgraph so we do not duplicate or modify the underlying A*
implementation.
Correctness: distances on the original graph are a valid lower bound for distances on any
subgraph obtained by removing vertices/edges (Dijkstra never gets shorter when the graph
shrinks). So h(v) = reverseDistancesToSink[v] is admissible for the spur subproblem on
the masked graph. If the heuristic map is null or missing for some vertex, the engine
falls back to 0.0 for that vertex (still admissible, equivalent to running A* with a
trivial heuristic, i.e. Dijkstra).
Edge weights must be non-negative.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongNumber of vertices the engine has expanded (popped from its open set) since the lastSpurShortestPathEngine.resetCounters()call.findPath(Graph<V, E> graph, V source, V sink, Set<V> bannedVertices, Set<E> bannedEdges, Map<V, Double> reverseDistancesToSink) Compute an exact shortest path fromsourcetosinkongraphignoring vertices inbannedVerticesand edges inbannedEdges.name()Symbolic name of the engine, used in benchmark reports.longNumber of shortest-path queries answered since the lastSpurShortestPathEngine.resetCounters()call.voidReset internal counters.
-
Constructor Details
-
AStarSpurEngine
public AStarSpurEngine()
-
-
Method Details
-
findPath
public GraphPath<V,E> findPath(Graph<V, E> graph, V source, V sink, Set<V> bannedVertices, Set<E> bannedEdges, Map<V, Double> reverseDistancesToSink) Description copied from interface:SpurShortestPathEngineCompute an exact shortest path fromsourcetosinkongraphignoring vertices inbannedVerticesand edges inbannedEdges.- Specified by:
findPathin interfaceSpurShortestPathEngine<V,E> - Parameters:
graph- original graph (engines should not mutate it)source- source vertex of the spur querysink- target vertex of the spur querybannedVertices- vertices to ignore (must not includesourceorsink)bannedEdges- edges to ignorereverseDistancesToSink- optional hint, lower-bound distances from each vertex tosinkcomputed on the original graph; may benullfor engines that do not need it- Returns:
- the shortest path or
nullif no path exists in the masked graph
-
expandedVertices
public long expandedVertices()Description copied from interface:SpurShortestPathEngineNumber of vertices the engine has expanded (popped from its open set) since the lastSpurShortestPathEngine.resetCounters()call. Best-effort metric used by benchmarks; engines that do not track expansion (e.g. those delegating to a back-end without a public expansion counter) may return0.- Specified by:
expandedVerticesin interfaceSpurShortestPathEngine<V,E> - Returns:
- number of vertices popped from the engine's open set since the last reset, or
0when not tracked
-
pathQueries
public long pathQueries()Description copied from interface:SpurShortestPathEngineNumber of shortest-path queries answered since the lastSpurShortestPathEngine.resetCounters()call.- Specified by:
pathQueriesin interfaceSpurShortestPathEngine<V,E> - Returns:
- number of shortest-path queries answered since the last reset
-
resetCounters
public void resetCounters()Description copied from interface:SpurShortestPathEngineReset internal counters. Called byBoundedPrunedYenKShortestPathbetween independent runs so that counters report per-run statistics.- Specified by:
resetCountersin interfaceSpurShortestPathEngine<V,E>
-
name
Description copied from interface:SpurShortestPathEngineSymbolic name of the engine, used in benchmark reports.- Specified by:
namein interfaceSpurShortestPathEngine<V,E> - Returns:
- a short human-readable identifier for this engine
-