forked from lebotlan/BE-Graphes
Test for A*
This commit is contained in:
parent
bf2c35eadd
commit
cb5f211cee
1 changed files with 25 additions and 6 deletions
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm;
|
||||
|
|
@ -84,18 +85,23 @@ public class ShortestPathTest {
|
|||
// System.out.println("" + insaBikiniCanal.getOrigin().getId() +" "+ insaBikiniCanal.getDestination().getId());
|
||||
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(insaBikiniCanalPathData);
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(insaBikiniCanalPathData);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(insaBikiniCanalPathData);
|
||||
|
||||
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
|
||||
assertEquals(Status.OPTIMAL, solutionBellmanFord.getStatus());
|
||||
assertEquals(Status.OPTIMAL, solutionDijkstra.getStatus());
|
||||
assertEquals(Status.OPTIMAL, solutionAStar.getStatus());
|
||||
|
||||
assertEquals(insaBikiniCanal.getLength(), solutionBellmanFord.getPath().getLength(),1.0);
|
||||
assertEquals(insaBikiniCanal.getLength(), solutionDijkstra.getPath().getLength(), 1.0);
|
||||
assertEquals(insaBikiniCanal.getLength(), solutionAStar.getPath().getLength(), 1.0);
|
||||
|
||||
assertEquals(insaBikiniCanal.getTravelTime(120), solutionBellmanFord.getPath().getTravelTime(120),1.0);
|
||||
assertEquals(insaBikiniCanal.getTravelTime(120), solutionDijkstra.getPath().getTravelTime(120), 1.0);
|
||||
assertEquals(insaBikiniCanal.getTravelTime(120), solutionAStar.getPath().getTravelTime(120), 1.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -103,41 +109,54 @@ public class ShortestPathTest {
|
|||
ShortestPathData cheminInexistant = new ShortestPathData(insa, insa.get(940), insa.get(702), onlyCarsByLengthArcInspector);
|
||||
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminInexistant);
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminInexistant);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(cheminInexistant);
|
||||
|
||||
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
|
||||
assertEquals(Status.INFEASIBLE, solutionBellmanFord.getStatus());
|
||||
assertEquals(Status.INFEASIBLE, solutionDijkstra.getStatus());
|
||||
assertEquals(Status.INFEASIBLE, solutionAStar.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheminLongueurNulle() {
|
||||
ShortestPathData cheminInexistant = new ShortestPathData(insa, insa.get(940), insa.get(940), noFilterByLengthArcInspector);
|
||||
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminInexistant);
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminInexistant);
|
||||
ShortestPathData cheminNul = new ShortestPathData(insa, insa.get(940), insa.get(940), noFilterByLengthArcInspector);
|
||||
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminNul);
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminNul);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(cheminNul);
|
||||
|
||||
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
|
||||
assertEquals(Status.INFEASIBLE, solutionBellmanFord.getStatus());
|
||||
assertEquals(Status.INFEASIBLE, solutionDijkstra.getStatus());
|
||||
assertEquals(Status.INFEASIBLE, solutionAStar.getStatus());
|
||||
|
||||
assertNull(solutionBellmanFord.getPath());
|
||||
assertNull(solutionDijkstra.getPath());
|
||||
assertNull(solutionAStar.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheminLong() { // En comparant les deux algos
|
||||
ShortestPathData cheminInexistant = new ShortestPathData(belgique, belgique.get(956754), belgique.get(842938), noFilterByLengthArcInspector);
|
||||
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminInexistant);
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminInexistant);
|
||||
ShortestPathData cheminLong = new ShortestPathData(belgique, belgique.get(956754), belgique.get(842938), noFilterByLengthArcInspector);
|
||||
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminLong);
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminLong);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(cheminLong);
|
||||
|
||||
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
|
||||
assertEquals(solutionBellmanFord.getStatus(), solutionDijkstra.getStatus());
|
||||
assertEquals(solutionBellmanFord.getPath().getLength(), solutionDijkstra.getPath().getLength(), 1.0);
|
||||
assertEquals(solutionBellmanFord.getPath().getTravelTime(120), solutionDijkstra.getPath().getTravelTime(120), 1.0);
|
||||
|
||||
assertEquals(solutionAStar.getStatus(), solutionDijkstra.getStatus());
|
||||
assertEquals(solutionAStar.getPath().getLength(), solutionDijkstra.getPath().getLength(), 1.0);
|
||||
assertEquals(solutionAStar.getPath().getTravelTime(120), solutionDijkstra.getPath().getTravelTime(120), 1.0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue