Commit c443c9ee authored by Antoine's avatar Antoine

Fixes #63

parent c382562f
...@@ -194,10 +194,10 @@ public class AStar implements Algorithm { ...@@ -194,10 +194,10 @@ public class AStar implements Algorithm {
protected Path result; protected Path result;
/** /**
* Set to true if the algorithm ran, but did not found any path from the * Set to false if the algorithm ran, but did not found any path from the
* source to the target. * source to the target, or if the algorithm did not run yet.
*/ */
protected boolean noPathFound; protected boolean pathFound = false;
/** /**
* New A* algorithm. * New A* algorithm.
...@@ -313,13 +313,14 @@ public class AStar implements Algorithm { ...@@ -313,13 +313,14 @@ public class AStar implements Algorithm {
* {@link #compute(String, String)}, if the {@link #getShortestPath()} * {@link #compute(String, String)}, if the {@link #getShortestPath()}
* returns null, or this method return true, there is no path from the given * returns null, or this method return true, there is no path from the given
* source node to the given target node. In other words, the graph has * source node to the given target node. In other words, the graph has
* several connected components. * several connected components. It also return true if the algorithm did
* not run.
* *
* @return True if there is no possible path from the source to the * @return True if there is no possible path from the source to the
* destination. * destination or if the algorithm did not run.
*/ */
public boolean noPathFound() { public boolean noPathFound() {
return noPathFound; return (! pathFound);
} }
/** /**
...@@ -385,7 +386,7 @@ public class AStar implements Algorithm { ...@@ -385,7 +386,7 @@ public class AStar implements Algorithm {
closed.clear(); closed.clear();
result = null; result = null;
noPathFound = false; pathFound = false;
} }
/** /**
...@@ -403,6 +404,8 @@ public class AStar implements Algorithm { ...@@ -403,6 +404,8 @@ public class AStar implements Algorithm {
new AStarNode(sourceNode, null, null, 0, costs.heuristic( new AStarNode(sourceNode, null, null, 0, costs.heuristic(
sourceNode, targetNode))); sourceNode, targetNode)));
pathFound = false;
while (!open.isEmpty()) { while (!open.isEmpty()) {
AStarNode current = getNextBetterNode(); AStarNode current = getNextBetterNode();
...@@ -411,6 +414,7 @@ public class AStar implements Algorithm { ...@@ -411,6 +414,7 @@ public class AStar implements Algorithm {
if (current.node == targetNode) { if (current.node == targetNode) {
// We found it ! // We found it !
assert current.edge != null; assert current.edge != null;
pathFound = true;
result = buildPath(current); result = buildPath(current);
return; return;
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment