Compare commits

...

3 commits

3 changed files with 79 additions and 3 deletions

2
.gitignore vendored
View file

@ -17,3 +17,5 @@ doc
*.mapfg
*.mapgr
*.tgz
*.path
*.json

View file

@ -1,5 +1,12 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.algorithm.ArcInspector;
import org.insa.graphs.algorithm.ArcInspectorFactory;
import org.insa.graphs.algorithm.AbstractInputData.Mode;
import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Node;
import org.junit.Test;
public class AStarAlgorithmTest extends ShortestPathAlgorithmTest {
public AStarAlgorithmTest() {
@ -11,4 +18,70 @@ public class AStarAlgorithmTest extends ShortestPathAlgorithmTest {
return new AStarAlgorithm(data);
}
/*
* Verifies that both paths are valid and Dijkstra path matches AStar path
* Applied either for LENGTH or TIME mode.
*/
private void assertDijkstraAStarHaveSameResult(Graph graph, Node origin, Node destination, ArcInspector arcFilter) {
final ShortestPathData data = new ShortestPathData(graph, origin, destination, arcFilter);
final ShortestPathAlgorithm Astar = initAlgo(data);
final ShortestPathSolution Astar_path = Astar.doRun();
final DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
final ShortestPathSolution dijkstra_path = dijkstra.doRun();
assert(Astar_path.getPath().isValid());
assert(Astar_path.isFeasible());
assert(dijkstra_path.getPath().isValid());
assert(dijkstra_path.isFeasible());
if (data.getMode() == Mode.LENGTH) {
assert(Math.abs(Astar.getCostPath() - Astar_path.getPath().getLength()) < 1.0);
assert(Math.abs(Astar_path.getPath().getLength() - dijkstra_path.getPath().getLength()) < 1.0);
}
else {
assert(Math.abs(Astar.getCostPath() - Astar_path.getPath().getMinimumTravelTime()) < 1.0);
assert(Math.abs(Astar_path.getPath().getMinimumTravelTime() - dijkstra_path.getPath().getMinimumTravelTime()) < 1.0);
}
}
@Test
/*
* Test supplémentaire pour Astar: on va vérifier que les résultats obtenus
* sont les mêmes que ceux obtenus avec Dijkstra.
* Origine: 16644
* Destination: 39229
* Mode: LENGTH
* PATH UTILISE : ../Paths/custom_paths/long_path_tls.path
*/
public void Dijkstra_Astar_LENGTH() {
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
Graph myGraph = graph.get(2);
Node origin = myGraph.get(16644);
Node destination = myGraph.get(39229);
assertDijkstraAStarHaveSameResult(myGraph, origin, destination, arcInspector);
}
@Test
/*
* Test supplémentaire pour Astar: on va vérifier que les résultats obtenus
* sont les mêmes que ceux obtenus avec Dijkstra.
* Origine: 16644
* Destination: 39229
* Mode: TIME
* PATH UTILISE : ../Paths/custom_paths/long_path_tls.path
*/
public void Dijkstra_Astar_TIME() {
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(2);
Graph myGraph = graph.get(2);
Node origin = myGraph.get(16644);
Node destination = myGraph.get(39229);
assertDijkstraAStarHaveSameResult(myGraph, origin, destination, arcInspector);
}
}

View file

@ -77,7 +77,7 @@ public abstract class ShortestPathAlgorithmTest {
*/
/*
* Verifies that path is valid and mathes the one found by the Bellman algo
* Verifies that path is valid and matches the one found by the Bellman algo
*/
private void assertBellmanHasSameResult(Graph graph, Node origin, Node destination, ArcInspector arcFilter) {
final ShortestPathData data = new ShortestPathData(graph, origin, destination, arcFilter);
@ -240,7 +240,7 @@ public abstract class ShortestPathAlgorithmTest {
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 );
assert(Math.abs(path.getPath().getMinimumTravelTime() - bell_path.getPath().getMinimumTravelTime()) < 1.0 );
}
@Test
@ -356,6 +356,7 @@ public abstract class ShortestPathAlgorithmTest {
assert(path.isFeasible());
// On a des erreurs d'arrondi assez grande avec la distance, mais elles sont mineures
// relativement aux distance de 300000 ici.
// Elles sont causées par le fait que les chemi
assert((Math.abs(algo.getCostPath() - path.getPath().getLength())) < 1000.0);
// Probable explication :
// - `algo.getCostPath()` : somme de double
@ -392,7 +393,7 @@ public abstract class ShortestPathAlgorithmTest {
assert(path.getPath().isValid());
assert(path.isFeasible());
// On a des erreurs d'arrondi assez grandes avec la distance
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime())) < 100.0);
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime())) < 1000.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(algo.getCostPath() > 12000 && algo.getCostPath() < 13000);