Code: Select all
private boolean DFS(Vertex start) {
if (start.equals(end)) {
SO = SolverOutcome.SOLVED;
this.distance = distTo.get(end);
return true;
}
for (WeightedEdge e : input.neighbors(start)) {
Vertex to = e.to();
double distToV = distTo.get(start) + e.weight();
double h = input.estimatedDistanceToGoal(to, end);
if (!edgeTo.containsKey(to)) {
edgeTo.put(to, start);
/*
if the distance to the parent
plus the weight plus the estD is less than
the cost limit, put the distance
to the e.to() vertex, and make the DFS call
otherwise put it in the PQ
*/
if (distToV + h > costLimit) {
if (!PQ.contains(to)) {
PQ.add(to, distToV + h);
}
}
else {
distTo.put(to, distToV);
if (DFS(to)) {
return true;
}
}
}
}
return false;
}