refactor(test): use generic OSP algorithm

This commit is contained in:
Paul Alnet 2024-05-20 22:59:31 +02:00
parent f852e39994
commit 6af2ae2ead

View file

@ -100,11 +100,11 @@ public abstract class ShortestPathAlgorithmTest {
private void assertNoPathFound(Graph graph, Node origin, Node destination, ArcInspector arcFilter) {
ShortestPathData data = new ShortestPathData(graph, origin, destination, arcFilter);
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path = dijkstra.doRun();
final ShortestPathAlgorithm algo = initAlgo(data);
final ShortestPathSolution path = algo.doRun();
assert(!dijk_path.isFeasible());
assert(dijk_path.getPath() == null);
assert(!path.isFeasible());
assert(path.getPath() == null);
}
@Test
@ -231,16 +231,16 @@ public abstract class ShortestPathAlgorithmTest {
Node destination = myGraph.get(39229);
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path = dijkstra.doRun();
final ShortestPathAlgorithm algo = initAlgo(data);
final ShortestPathSolution path = algo.doRun();
BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data);
ShortestPathSolution bell_path = bellman.doRun();
assert(dijk_path.getPath().isValid());
assert(dijk_path.isFeasible());
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getMinimumTravelTime()) < 1.0));
assert(Math.abs(dijk_path.getPath().getMinimumTravelTime() - bell_path.getPath().getMinimumTravelTime()) < 10.0 );
assert(path.getPath().isValid());
assert(path.isFeasible());
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime()) < 1.0));
assert(Math.abs(path.getPath().getMinimumTravelTime() - bell_path.getPath().getMinimumTravelTime()) < 10.0 );
}
@Test
@ -264,8 +264,8 @@ public abstract class ShortestPathAlgorithmTest {
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
DijkstraAlgorithm dijkstra_bicycle = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path_bicycle = dijkstra_bicycle.doRun();
ShortestPathAlgorithm algo_bicycle = initAlgo(data);
ShortestPathSolution path_bicycle = algo_bicycle.doRun();
BellmanFordAlgorithm bellman_bicycle = new BellmanFordAlgorithm(data);
ShortestPathSolution bell_path_bicycle = bellman_bicycle.doRun();
@ -274,22 +274,22 @@ public abstract class ShortestPathAlgorithmTest {
ArcInspector new_Inspector = ArcInspectorFactory.getAllFilters().get(1);
data = new ShortestPathData(myGraph, origin, destination, new_Inspector);
DijkstraAlgorithm dijkstra_car = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path_car = dijkstra_car.doRun();
ShortestPathAlgorithm algo_car = initAlgo(data);
ShortestPathSolution path_car = algo_car.doRun();
assertEquals(dijk_path_bicycle.getPath(), null);
assert(!dijk_path_bicycle.isFeasible());
assertEquals(path_bicycle.getPath(), null);
assert(!path_bicycle.isFeasible());
assertEquals(bell_path_bicycle.getPath(), null);
assert(!bell_path_bicycle.isFeasible());
assert(dijk_path_car.getPath() != null);
assert(dijk_path_car.isFeasible());
assert(path_car.getPath() != null);
assert(path_car.isFeasible());
}
@Test
/*
* On veut vérifier le bon fonctionnement des modes TIME et LENGTH.
* Pour cela, on va obtenir deux chemins avec l'algo de Dijkstra et vérifier
* Pour cela, on va obtenir deux chemins avec l'algo de algo et vérifier
* que:
* -le chemin TIME est plus rapide en durée que le chemin LENGTH
* -le chemin LENGTH est plus court en distance que le chemin LENGTH.
@ -308,26 +308,26 @@ public abstract class ShortestPathAlgorithmTest {
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(1);
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
DijkstraAlgorithm dijkstra_L = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path_L = dijkstra_L.doRun();
ShortestPathAlgorithm algo_L = initAlgo(data);
ShortestPathSolution path_L = algo_L.doRun();
// Filter: forCarsT
ArcInspector new_Inspector = ArcInspectorFactory.getAllFilters().get(2);
data = new ShortestPathData(myGraph, origin, destination, new_Inspector);
DijkstraAlgorithm dijkstra_T = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path_T = dijkstra_T.doRun();
ShortestPathAlgorithm algo_T = initAlgo(data);
ShortestPathSolution path_T = algo_T.doRun();
assert(dijk_path_L.getPath().isValid());
assert(dijk_path_L.isFeasible());
assert(dijk_path_T.getPath().isValid());
assert(dijk_path_T.isFeasible());
assert(path_L.getPath().isValid());
assert(path_L.isFeasible());
assert(path_T.getPath().isValid());
assert(path_T.isFeasible());
assert((Math.abs(dijkstra_L.getCostPath() - dijk_path_L.getPath().getLength()) < 1.0));
assert((Math.abs(dijkstra_T.getCostPath() - dijk_path_T.getPath().getMinimumTravelTime()) < 1.0));
assert((Math.abs(algo_L.getCostPath() - path_L.getPath().getLength()) < 1.0));
assert((Math.abs(algo_T.getCostPath() - path_T.getPath().getMinimumTravelTime()) < 1.0));
assert(dijk_path_L.getPath().getLength() < dijk_path_T.getPath().getLength());
assert(dijk_path_L.getPath().getMinimumTravelTime() > dijk_path_T.getPath().getMinimumTravelTime());
assert(path_L.getPath().getLength() < path_T.getPath().getLength());
assert(path_L.getPath().getMinimumTravelTime() > path_T.getPath().getMinimumTravelTime());
}
@Test
@ -349,19 +349,19 @@ public abstract class ShortestPathAlgorithmTest {
Node destination = myGraph.get(481936);
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path = dijkstra.doRun();
final ShortestPathAlgorithm algo = initAlgo(data);
final ShortestPathSolution path = algo.doRun();
assert(dijk_path.getPath().isValid());
assert(dijk_path.isFeasible());
assert(path.getPath().isValid());
assert(path.isFeasible());
// On a des erreurs d'arrondi assez grande avec la distance, mais elles sont mineures
// relativement aux distance de 300000 ici.
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength())) < 1000.0);
assert((Math.abs(algo.getCostPath() - path.getPath().getLength())) < 1000.0);
// Selon le chemin sélectionné on peut avoir une estimation de la longueur qu'on est censée avoir.
// Avec notre long chemin: entre 250 et 260 kilomètres.
assert(dijkstra.getCostPath() > 250000 && dijkstra.getCostPath() < 260000);
assert(algo.getCostPath() > 250000 && algo.getCostPath() < 260000);
// On peut aussi supposer que le nombre d'arcs empruntés est très grand.
assert(dijk_path.getPath().getArcs().size() > 1000);
assert(path.getPath().getArcs().size() > 1000);
}
@Test
@ -383,17 +383,17 @@ public abstract class ShortestPathAlgorithmTest {
Node destination = myGraph.get(481936);
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path = dijkstra.doRun();
final ShortestPathAlgorithm algo = initAlgo(data);
final ShortestPathSolution path = algo.doRun();
assert(dijk_path.getPath().isValid());
assert(dijk_path.isFeasible());
assert(path.getPath().isValid());
assert(path.isFeasible());
// On a des erreurs d'arrondi assez grandes avec la distance
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getMinimumTravelTime())) < 100.0);
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime())) < 100.0);
// Selon le chemin sélectionné on peut avoir une estimation de la durée qu'on est censée avoir.
// Avec notre long chemin: entre 12000 et 13000 secondes.
assert(dijkstra.getCostPath() > 12000 && dijkstra.getCostPath() < 13000);
assert(algo.getCostPath() > 12000 && algo.getCostPath() < 13000);
// On peut aussi supposer que le nombre d'arcs empruntés est très grand.
assert(dijk_path.getPath().getArcs().size() > 1000);
assert(path.getPath().getArcs().size() > 1000);
}
}