Minor fixes and tests
This commit is contained in:
parent
db095f9ea9
commit
460456581e
4 changed files with 12 additions and 5 deletions
|
@ -56,7 +56,10 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
|
||||
Node destination = data.getDestination();
|
||||
Node currentNode = null;
|
||||
|
||||
// Debug / Tests
|
||||
double previousCost = 0;
|
||||
int iterationCounter = 0;
|
||||
|
||||
while (!heap.isEmpty() && (currentNode == null || !currentNode.equals(destination))) {
|
||||
// Get the node with the minimum cost
|
||||
|
@ -65,11 +68,12 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
currentNode = currentLabel.getNode();
|
||||
|
||||
/*
|
||||
// Debug
|
||||
// Debug / Tests
|
||||
assert(((BinaryHeap<Label>) heap).isValid());
|
||||
assert(currentLabel.getTotalCost() >= previousCost);
|
||||
previousCost = currentLabel.getCost();
|
||||
*/
|
||||
iterationCounter++;
|
||||
|
||||
for (Arc arc : currentNode.getSuccessors()) {
|
||||
Node dest = arc.getDestination();
|
||||
|
@ -111,6 +115,8 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
currentLabel = labels.get(arc.getOrigin().getId());
|
||||
}
|
||||
|
||||
System.out.printf("Nombre de sommets explorés : %d\n", iterationCounter);
|
||||
|
||||
Collections.reverse(path);
|
||||
|
||||
return new ShortestPathSolution(data, AbstractSolution.Status.OPTIMAL, new Path(data.getGraph(), path));
|
||||
|
|
|
@ -4,7 +4,7 @@ package org.insa.graphs.algorithm.shortestpath;
|
|||
public class AStarAlgorithmTest extends ShortestPathTest {
|
||||
@Override
|
||||
protected ShortestPathSolution runShortestPathAlgo(ShortestPathData data) {
|
||||
return new AStarAlgorithm(data).doRun();
|
||||
return new AStarAlgorithm(data).run();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,6 @@ package org.insa.graphs.algorithm.shortestpath;
|
|||
public class DijkstraAlgorithmTest extends ShortestPathTest {
|
||||
@Override
|
||||
protected ShortestPathSolution runShortestPathAlgo(ShortestPathData data) {
|
||||
return new DijkstraAlgorithm(data).doRun();
|
||||
return new DijkstraAlgorithm(data).run();
|
||||
}
|
||||
}
|
|
@ -62,7 +62,7 @@ public abstract class ShortestPathTest {
|
|||
for (ArcInspector arcInspector : arcInspectors) {
|
||||
ShortestPathData data = createData(maps[i], arcInspector, origIndexes[i], destIndexes[i]);
|
||||
ShortestPathSolution sol = runShortestPathAlgo(data);
|
||||
ShortestPathSolution oracle = new BellmanFordAlgorithm(data).doRun();
|
||||
ShortestPathSolution oracle = new BellmanFordAlgorithm(data).run();
|
||||
assertTrue(sol.isFeasible());
|
||||
Path path = sol.getPath();
|
||||
assertTrue(path.isValid());
|
||||
|
@ -71,7 +71,8 @@ public abstract class ShortestPathTest {
|
|||
assertEquals(path, Path.createShortestPathFromNodes(data.getGraph(), path.getNodes()));
|
||||
if (i == 1)
|
||||
assertEquals(path, Path.createFastestPathFromNodes(data.getGraph(), path.getNodes()));
|
||||
// Check result against Bellman Ford algorithm (except for the square map or there may be several paths with the same cost)
|
||||
// Check result against Bellman Ford algorithm (except for the square map
|
||||
// where there may be several paths with the same cost)
|
||||
if (i != 0)
|
||||
assertEquals(sol.getPath(), oracle.getPath());
|
||||
System.out.println();
|
||||
|
|
Loading…
Reference in a new issue