Compare commits
3 commits
e4f9a18f22
...
f62e312156
Author | SHA1 | Date | |
---|---|---|---|
f62e312156 | |||
0ad795a8c4 | |||
5c248f26dc |
1 changed files with 41 additions and 61 deletions
|
@ -48,12 +48,11 @@ public class DijkstraAlgorithmTest {
|
|||
public static void init() {
|
||||
try {
|
||||
// Create the map
|
||||
for (int j = 0 ; j < Maps.size() ; j++) {
|
||||
final String mapName = Maps.get(j);
|
||||
for (String mapName : Maps) {
|
||||
// Create a graph reader
|
||||
final GraphReader reader = new BinaryGraphReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
||||
// Read the graph. X
|
||||
// Read the graph.
|
||||
graph.add(reader.read());
|
||||
// free resources
|
||||
reader.close();
|
||||
|
@ -75,6 +74,37 @@ public class DijkstraAlgorithmTest {
|
|||
* Chemin longs testés par comparaison avec chemins déjà construits. Bellman trop long.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
final ShortestPathData data = new ShortestPathData(graph, origin, destination, arcFilter);
|
||||
|
||||
final DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
final ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||
|
||||
final BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data);
|
||||
final ShortestPathSolution bell_path = bellman.doRun();
|
||||
|
||||
assert(dijk_path.getPath().isValid());
|
||||
assert(dijk_path.isFeasible());
|
||||
assert(Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength()) < 1.0);
|
||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verifies that no path is found
|
||||
*/
|
||||
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();
|
||||
|
||||
assert(!dijk_path.isFeasible());
|
||||
assert(dijk_path.getPath() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
/*
|
||||
* Map: carre.mapgr
|
||||
|
@ -84,22 +114,12 @@ public class DijkstraAlgorithmTest {
|
|||
* PATH UTILISE : ../Paths/custom_paths/short_path_carre.path
|
||||
*/
|
||||
public void chemin_court_CARRE_length() {
|
||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0); // all arcs
|
||||
Graph myGraph = graph.get(0);
|
||||
Node origin = myGraph.get(19);
|
||||
Node destination = myGraph.get(4);
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution dijk_path = dijkstra.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().getLength()) < 1.0);
|
||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
||||
assertBellmanHasSameResult(myGraph, origin, destination, arcInspector);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -115,18 +135,7 @@ public class DijkstraAlgorithmTest {
|
|||
Node origin = myGraph.get(15);
|
||||
Node destination = myGraph.get(9);
|
||||
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution dijk_path = dijkstra.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().getLength()) < 1.0);
|
||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
||||
assertBellmanHasSameResult(myGraph, origin, destination, arcInspector);
|
||||
}
|
||||
|
||||
|
||||
|
@ -141,13 +150,8 @@ public class DijkstraAlgorithmTest {
|
|||
Graph myGraph = graph.get(0);
|
||||
Node origin = myGraph.get(3);
|
||||
Node destination = myGraph.get(3);
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||
|
||||
assert(!dijk_path.isFeasible());
|
||||
assert(dijk_path.getPath() == null);
|
||||
assertNoPathFound(myGraph, origin, destination, arcInspector);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -163,12 +167,8 @@ public class DijkstraAlgorithmTest {
|
|||
Graph myGraph = graph.get(1);
|
||||
Node origin = myGraph.get(224);
|
||||
Node destination = myGraph.get(814);
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||
assert(!dijk_path.isFeasible());
|
||||
assert(dijk_path.getPath() == null);
|
||||
assertNoPathFound(myGraph, origin, destination, arcInspector);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -184,18 +184,8 @@ public class DijkstraAlgorithmTest {
|
|||
Graph myGraph = graph.get(2);
|
||||
Node origin = myGraph.get(8423);
|
||||
Node destination = myGraph.get(8435);
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution dijk_path = dijkstra.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().getLength()) < 1.0);
|
||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
||||
assertBellmanHasSameResult(myGraph, origin, destination, arcInspector);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -215,18 +205,8 @@ public class DijkstraAlgorithmTest {
|
|||
Graph myGraph = graph.get(2);
|
||||
Node origin = myGraph.get(16644);
|
||||
Node destination = myGraph.get(39229);
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution dijk_path = dijkstra.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().getLength()) < 1.0));
|
||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 10.0);
|
||||
assertBellmanHasSameResult(myGraph, origin, destination, arcInspector);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue