Сравнить коммиты
Нет общих коммитов. «f62e31215655364b742e039c291e182f42aba022» и «e4f9a18f22a2b737c96391348e7aef5bfe3e9bd6» имеют совершенно разные истории.
f62e312156
...
e4f9a18f22
1 изменённых файлов: 61 добавлений и 41 удалений
|
|
@ -48,11 +48,12 @@ public class DijkstraAlgorithmTest {
|
|||
public static void init() {
|
||||
try {
|
||||
// Create the map
|
||||
for (String mapName : Maps) {
|
||||
for (int j = 0 ; j < Maps.size() ; j++) {
|
||||
final String mapName = Maps.get(j);
|
||||
// Create a graph reader
|
||||
final GraphReader reader = new BinaryGraphReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
||||
// Read the graph.
|
||||
// Read the graph. X
|
||||
graph.add(reader.read());
|
||||
// free resources
|
||||
reader.close();
|
||||
|
|
@ -74,37 +75,6 @@ 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
|
||||
|
|
@ -114,12 +84,22 @@ public class DijkstraAlgorithmTest {
|
|||
* PATH UTILISE : ../Paths/custom_paths/short_path_carre.path
|
||||
*/
|
||||
public void chemin_court_CARRE_length() {
|
||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0); // all arcs
|
||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||
Graph myGraph = graph.get(0);
|
||||
Node origin = myGraph.get(19);
|
||||
Node destination = myGraph.get(4);
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
assertBellmanHasSameResult(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);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -135,7 +115,18 @@ public class DijkstraAlgorithmTest {
|
|||
Node origin = myGraph.get(15);
|
||||
Node destination = myGraph.get(9);
|
||||
|
||||
assertBellmanHasSameResult(myGraph, origin, destination, arcInspector);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -150,8 +141,13 @@ 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);
|
||||
|
||||
assertNoPathFound(myGraph, origin, destination, arcInspector);
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||
|
||||
assert(!dijk_path.isFeasible());
|
||||
assert(dijk_path.getPath() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -167,8 +163,12 @@ 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);
|
||||
|
||||
assertNoPathFound(myGraph, origin, destination, arcInspector);
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||
assert(!dijk_path.isFeasible());
|
||||
assert(dijk_path.getPath() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -184,8 +184,18 @@ 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);
|
||||
|
||||
assertBellmanHasSameResult(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);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -205,8 +215,18 @@ 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);
|
||||
|
||||
assertBellmanHasSameResult(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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Загрузка…
Сослаться в новой задаче