test dij finaux

This commit is contained in:
Raphael Rees 2023-05-13 15:41:24 +02:00
parent 9f3a23c707
commit 7c49a6d547
2 changed files with 28 additions and 48 deletions

View file

@ -28,8 +28,10 @@ public class DijkstraTest {
private static Node origin1; private static Node origin1;
private static Node destination1; private static Node destination1;
private static DijkstraAlgorithm dijkstra1; private static DijkstraAlgorithm dijkstra1;
private static DijkstraAlgorithm dijkstra5;
private static BellmanFordAlgorithm bellman1; private static BellmanFordAlgorithm bellman1;
private static ShortestPathSolution solDijkstra1; private static ShortestPathSolution solDijkstra1;
private static ShortestPathSolution solDijkstra5;
private static ShortestPathSolution solBellman1; private static ShortestPathSolution solBellman1;
private static Random random1 = new Random(); private static Random random1 = new Random();
@ -56,15 +58,6 @@ public class DijkstraTest {
private static DijkstraAlgorithm dijkstra4; private static DijkstraAlgorithm dijkstra4;
private static ShortestPathSolution solDijkstra4; private static ShortestPathSolution solDijkstra4;
private static String mapName5;
private static GraphReader reader5;
private static Graph graph5;
private static Node origin5;
private static Node destination5;
private static DijkstraAlgorithm dijkstra5;
private static ShortestPathSolution solDijkstra5;
@BeforeClass @BeforeClass
public static void initAll() throws IOException{ public static void initAll() throws IOException{
@ -81,10 +74,6 @@ public class DijkstraTest {
mapName3 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; mapName3 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
reader3 = new BinaryGraphReader( reader3 = new BinaryGraphReader(
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName3)))); new DataInputStream(new BufferedInputStream(new FileInputStream(mapName3))));
mapName5 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/france.mapgr";
reader5 = new BinaryGraphReader(
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName5))));
//Read the graph //Read the graph
graph1 = reader1.read(); graph1 = reader1.read();
@ -98,29 +87,31 @@ public class DijkstraTest {
while(i2==i1){ while(i2==i1){
i2 = random1.nextInt(numNodes1); i2 = random1.nextInt(numNodes1);
} }
System.err.println(i1 + " " + i2); //System.err.println(i1 + " " + i2);
destination1 = graph1.get(i2); destination1 = graph1.get(i2);
dijkstra1 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(0)));//all roads allowed and length dijkstra1 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(0)));//all roads allowed and length
bellman1 = new BellmanFordAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(0))); bellman1 = new BellmanFordAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(0)));
solDijkstra1 = dijkstra1.run(); solDijkstra1 = dijkstra1.run();
dijkstra5 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(1)));
solDijkstra5 = dijkstra5.run();
solBellman1 = bellman1.run(); solBellman1 = bellman1.run();
graph2 = reader2.read(); // graph2 = reader2.read();
final int numNodes2 = graph2.size(); // final int numNodes2 = graph2.size();
int i3 = random1.nextInt(numNodes2); // int i3 = random1.nextInt(numNodes2);
while(!graph2.get(i3).hasSuccessors()){ // while(!graph2.get(i3).hasSuccessors()){
i3 = random1.nextInt(numNodes2); // i3 = random1.nextInt(numNodes2);
} // }
origin2 = graph2.get(i3); // origin2 = graph2.get(i3);
int i4 = random1.nextInt(numNodes2); // int i4 = random1.nextInt(numNodes2);
while(i4==i3){ // while(i4==i3){
i4 = random1.nextInt(numNodes2); // i4 = random1.nextInt(numNodes2);
} //}
System.out.println(i3 + " " + i4); //System.out.println(i3 + " " + i4);
destination2 = graph2.get(i4); destination2 = graph1.get(i2);
dijkstra2 = new DijkstraAlgorithm(new ShortestPathData(graph2,origin2,destination2,ArcInspectorFactory.getAllFilters().get(2)));//only roads for cars and time dijkstra2 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(2)));//only roads for cars and time1
bellman2 = new BellmanFordAlgorithm(new ShortestPathData(graph2,origin2,destination2,ArcInspectorFactory.getAllFilters().get(2))); bellman2 = new BellmanFordAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(2)));
solDijkstra2 = dijkstra2.run(); solDijkstra2 = dijkstra2.run();
solBellman2 = bellman2.run(); solBellman2 = bellman2.run();
@ -135,21 +126,6 @@ public class DijkstraTest {
destination4 = graph1.get(1); destination4 = graph1.get(1);
dijkstra4 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin4,destination4,ArcInspectorFactory.getAllFilters().get(0)));//all roads allowed and length dijkstra4 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin4,destination4,ArcInspectorFactory.getAllFilters().get(0)));//all roads allowed and length
solDijkstra4 = dijkstra4.run(); solDijkstra4 = dijkstra4.run();
graph5 = reader5.read();
final int numNodes5 = graph5.size();
int i5 = random1.nextInt(numNodes5);
while(!graph5.get(i5).hasSuccessors()){
i5 = random1.nextInt(numNodes5);
}
origin5 = graph1.get(i5);
int i6 = random1.nextInt(numNodes5);
while(i6==i5){
i6 = random1.nextInt(numNodes5);
}
destination5 = graph5.get(i6);
dijkstra5 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(0)));//all roads allowed and length
solDijkstra5 = dijkstra5.run();
} }
@Test @Test
@ -170,8 +146,12 @@ public class DijkstraTest {
@Test @Test
public void testDijkstra4(){//test dijkstra pour chemin longueur nulle public void testDijkstra4(){//test dijkstra pour chemin longueur nulle
assertTrue(solDijkstra4.getPath().getLength()==0); assertTrue(solDijkstra4.getPath().getLength()==0);
} }
//pour le dernier test : test de coherence (dist pour minTravelTime > dist pour getLength)
@Test
public void testDijkstra5(){//test de cohérence
assertTrue(solDijkstra5.getPath().getLength() <= solDijkstra2.getPath().getLength());
assertTrue(solDijkstra5.getPath().getMinimumTravelTime() >= solDijkstra2.getPath().getMinimumTravelTime());
}
} }

View file

@ -30,7 +30,7 @@ public class Path {
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two * @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph. * consecutive nodes in the list are not connected in the graph.
* *
* @deprecated Need to be implemented. *
*/ */
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes) public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException { throws IllegalArgumentException {