public ShortestPathTree getShortestPathTree(State initialState) {
Vertex target = null;
if (options.rctx != null) {
target = initialState.getOptions().rctx.target;
}
ShortestPathTree spt = new BasicShortestPathTree(options);
BinHeap<State> queue = new BinHeap<State>(1000);
spt.add(initialState);
queue.insert(initialState, initialState.getWeight());
while (!queue.empty()) { // Until the priority queue is empty:
State u = queue.extract_min();
Vertex u_vertex = u.getVertex();
if (traverseVisitor != null) {
traverseVisitor.visitVertex(u);
}
if (!spt.getStates(u_vertex).contains(u)) {
continue;
}
if (verbose) {
System.out.println("min," + u.getWeight());
System.out.println(u_vertex);
}
if (searchTerminationStrategy != null &&
searchTerminationStrategy.shouldSearchTerminate(initialState.getVertex(), null, u, spt, options)) {
break;
}
for (Edge edge : options.arriveBy ? u_vertex.getIncoming() : u_vertex.getOutgoing()) {
if (skipEdgeStrategy != null &&
skipEdgeStrategy.shouldSkipEdge(initialState.getVertex(), null, u, edge, spt, options)) {
continue;
}
// Iterate over traversal results. When an edge leads nowhere (as indicated by
// returning NULL), the iteration is over.
for (State v = edge.traverse(u); v != null; v = v.getNextResult()) {
if (skipTraverseResultStrategy != null &&
skipTraverseResultStrategy.shouldSkipTraversalResult(initialState.getVertex(), null, u, v, spt, options)) {
continue;
}
if (traverseVisitor != null) {
traverseVisitor.visitEdge(edge, v);
}
if (verbose) {
System.out.printf(" w = %f + %f = %f %s", u.getWeight(), v.getWeightDelta(), v.getWeight(), v.getVertex());
}
if (v.exceedsWeightLimit(options.maxWeight)) continue;
if (spt.add(v)) {
double estimate = heuristic.computeForwardWeight(v, target);
queue.insert(v, v.getWeight() + estimate);
if (traverseVisitor != null) traverseVisitor.visitEnqueue(v);
}
}
}
spt.postVisit(u);
}
return spt;
}