Compare commits
No commits in common. "d7c938cc76f3aa0f90f2cb48878219e8a6b23aa8" and "205605920baab5b3f221320356590992751f244f" have entirely different histories.
d7c938cc76
...
205605920b
3 changed files with 3 additions and 79 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -17,5 +17,3 @@ doc
|
||||||
*.mapfg
|
*.mapfg
|
||||||
*.mapgr
|
*.mapgr
|
||||||
*.tgz
|
*.tgz
|
||||||
*.path
|
|
||||||
*.json
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,5 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
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 class AStarAlgorithmTest extends ShortestPathAlgorithmTest {
|
||||||
|
|
||||||
public AStarAlgorithmTest() {
|
public AStarAlgorithmTest() {
|
||||||
|
|
@ -18,70 +11,4 @@ public class AStarAlgorithmTest extends ShortestPathAlgorithmTest {
|
||||||
return new AStarAlgorithm(data);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ public abstract class ShortestPathAlgorithmTest {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Verifies that path is valid and matches the one found by the Bellman algo
|
* Verifies that path is valid and mathes the one found by the Bellman algo
|
||||||
*/
|
*/
|
||||||
private void assertBellmanHasSameResult(Graph graph, Node origin, Node destination, ArcInspector arcFilter) {
|
private void assertBellmanHasSameResult(Graph graph, Node origin, Node destination, ArcInspector arcFilter) {
|
||||||
final ShortestPathData data = new ShortestPathData(graph, origin, destination, arcFilter);
|
final ShortestPathData data = new ShortestPathData(graph, origin, destination, arcFilter);
|
||||||
|
|
@ -240,7 +240,7 @@ public abstract class ShortestPathAlgorithmTest {
|
||||||
assert(path.getPath().isValid());
|
assert(path.getPath().isValid());
|
||||||
assert(path.isFeasible());
|
assert(path.isFeasible());
|
||||||
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime()) < 1.0));
|
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime()) < 1.0));
|
||||||
assert(Math.abs(path.getPath().getMinimumTravelTime() - bell_path.getPath().getMinimumTravelTime()) < 1.0 );
|
assert(Math.abs(path.getPath().getMinimumTravelTime() - bell_path.getPath().getMinimumTravelTime()) < 10.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -356,7 +356,6 @@ public abstract class ShortestPathAlgorithmTest {
|
||||||
assert(path.isFeasible());
|
assert(path.isFeasible());
|
||||||
// On a des erreurs d'arrondi assez grande avec la distance, mais elles sont mineures
|
// On a des erreurs d'arrondi assez grande avec la distance, mais elles sont mineures
|
||||||
// relativement aux distance de 300000 ici.
|
// 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);
|
assert((Math.abs(algo.getCostPath() - path.getPath().getLength())) < 1000.0);
|
||||||
// Probable explication :
|
// Probable explication :
|
||||||
// - `algo.getCostPath()` : somme de double
|
// - `algo.getCostPath()` : somme de double
|
||||||
|
|
@ -393,7 +392,7 @@ public abstract class ShortestPathAlgorithmTest {
|
||||||
assert(path.getPath().isValid());
|
assert(path.getPath().isValid());
|
||||||
assert(path.isFeasible());
|
assert(path.isFeasible());
|
||||||
// On a des erreurs d'arrondi assez grandes avec la distance
|
// On a des erreurs d'arrondi assez grandes avec la distance
|
||||||
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime())) < 1000.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.
|
// 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.
|
// Avec notre long chemin: entre 12000 et 13000 secondes.
|
||||||
assert(algo.getCostPath() > 12000 && algo.getCostPath() < 13000);
|
assert(algo.getCostPath() > 12000 && algo.getCostPath() < 13000);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue