test dij sauf test coherence
This commit is contained in:
parent
d044186aa4
commit
4a1e281ec7
2 changed files with 97 additions and 10 deletions
|
@ -52,7 +52,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
try {
|
try {
|
||||||
tas.remove(tab.get(index));
|
tas.remove(tab.get(index));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("l'élement n'est pas dans le tas");
|
//System.out.println("l'élement n'est pas dans le tas");
|
||||||
notifyNodeReached(tab.get(index).getSommet());
|
notifyNodeReached(tab.get(index).getSommet());
|
||||||
if(tab.get(index).getSommet().equals(data.getDestination())){
|
if(tab.get(index).getSommet().equals(data.getDestination())){
|
||||||
// The destination has been found, notify the observers.
|
// The destination has been found, notify the observers.
|
||||||
|
|
|
@ -3,19 +3,21 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||||
|
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||||
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
|
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
|
||||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||||
import org.insa.graphs.model.Graph;
|
import org.insa.graphs.model.Graph;
|
||||||
import org.insa.graphs.model.Node;
|
import org.insa.graphs.model.Node;
|
||||||
import org.insa.graphs.model.Path;
|
|
||||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||||
import org.insa.graphs.model.io.GraphReader;
|
import org.insa.graphs.model.io.GraphReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DijkstraTest {
|
public class DijkstraTest {
|
||||||
|
@ -41,39 +43,113 @@ public class DijkstraTest {
|
||||||
private static ShortestPathSolution solDijkstra2;
|
private static ShortestPathSolution solDijkstra2;
|
||||||
private static ShortestPathSolution solBellman2;
|
private static ShortestPathSolution solBellman2;
|
||||||
|
|
||||||
|
private static String mapName3;
|
||||||
|
private static GraphReader reader3;
|
||||||
|
private static Graph graph3;
|
||||||
|
private static Node origin3;
|
||||||
|
private static Node destination3;
|
||||||
|
private static DijkstraAlgorithm dijkstra3;
|
||||||
|
private static ShortestPathSolution solDijkstra3;
|
||||||
|
|
||||||
|
private static Node origin4;
|
||||||
|
private static Node destination4;
|
||||||
|
private static DijkstraAlgorithm dijkstra4;
|
||||||
|
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{
|
||||||
|
|
||||||
mapName1 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
mapName1 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/carre.mapgr";
|
||||||
// Create a graph reader.
|
// Create a graph reader.
|
||||||
reader1 = new BinaryGraphReader(
|
reader1 = new BinaryGraphReader(
|
||||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName1))));
|
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName1))));
|
||||||
|
|
||||||
mapName2 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/toulouse.mapgr";
|
mapName2 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/carre.mapgr";
|
||||||
// Create a graph reader.
|
// Create a graph reader.
|
||||||
reader2 = new BinaryGraphReader(
|
reader2 = new BinaryGraphReader(
|
||||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName2))));
|
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName2))));
|
||||||
|
|
||||||
|
mapName3 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||||
|
reader3 = new BinaryGraphReader(
|
||||||
|
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName3))));
|
||||||
|
|
||||||
// Read the graph.
|
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
|
||||||
graph1 = reader1.read();
|
graph1 = reader1.read();
|
||||||
final int numNodes1 = graph1.size();
|
final int numNodes1 = graph1.size();
|
||||||
origin1 = graph1.get(random1.nextInt(numNodes1));
|
int i1 = random1.nextInt(numNodes1);
|
||||||
destination1 = graph1.get(random1.nextInt(numNodes1));
|
while(!graph1.get(i1).hasSuccessors()){
|
||||||
|
i1 = random1.nextInt(numNodes1);
|
||||||
|
}
|
||||||
|
origin1 = graph1.get(i1);
|
||||||
|
int i2 = random1.nextInt(numNodes1);
|
||||||
|
while(i2==i1){
|
||||||
|
i2 = random1.nextInt(numNodes1);
|
||||||
|
}
|
||||||
|
System.err.println(i1 + " " + 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();
|
||||||
solBellman1 = bellman1.run();
|
solBellman1 = bellman1.run();
|
||||||
|
|
||||||
|
|
||||||
graph2 = reader2.read();
|
graph2 = reader2.read();
|
||||||
final int numNodes2 = graph2.size();
|
final int numNodes2 = graph2.size();
|
||||||
origin2 = graph2.get(random1.nextInt(numNodes2));
|
int i3 = random1.nextInt(numNodes2);
|
||||||
destination2 = graph2.get(random1.nextInt(numNodes2));
|
while(!graph2.get(i3).hasSuccessors()){
|
||||||
|
i3 = random1.nextInt(numNodes2);
|
||||||
|
}
|
||||||
|
origin2 = graph2.get(i3);
|
||||||
|
int i4 = random1.nextInt(numNodes2);
|
||||||
|
while(i4==i3){
|
||||||
|
i4 = random1.nextInt(numNodes2);
|
||||||
|
}
|
||||||
|
System.out.println(i3 + " " + i4);
|
||||||
|
destination2 = graph2.get(i4);
|
||||||
dijkstra2 = new DijkstraAlgorithm(new ShortestPathData(graph2,origin2,destination2,ArcInspectorFactory.getAllFilters().get(2)));//only roads for cars and time
|
dijkstra2 = new DijkstraAlgorithm(new ShortestPathData(graph2,origin2,destination2,ArcInspectorFactory.getAllFilters().get(2)));//only roads for cars and time
|
||||||
bellman2 = new BellmanFordAlgorithm(new ShortestPathData(graph2,origin2,destination2,ArcInspectorFactory.getAllFilters().get(2)));
|
bellman2 = new BellmanFordAlgorithm(new ShortestPathData(graph2,origin2,destination2,ArcInspectorFactory.getAllFilters().get(2)));
|
||||||
solDijkstra2 = dijkstra2.run();
|
solDijkstra2 = dijkstra2.run();
|
||||||
solBellman2 = bellman2.run();
|
solBellman2 = bellman2.run();
|
||||||
|
|
||||||
|
|
||||||
|
graph3 = reader3.read();
|
||||||
|
origin3 = graph3.get(1223);
|
||||||
|
destination3 = graph3.get(1047); //valeurs sur map INSA qui donnent chemin inexistant
|
||||||
|
dijkstra3 = new DijkstraAlgorithm(new ShortestPathData(graph3,origin3,destination3,ArcInspectorFactory.getAllFilters().get(0)));//all roads allowed and length
|
||||||
|
solDijkstra3 = dijkstra3.run();
|
||||||
|
|
||||||
|
origin4 = graph1.get(1);
|
||||||
|
destination4 = graph1.get(1);
|
||||||
|
dijkstra4 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin4,destination4,ArcInspectorFactory.getAllFilters().get(0)));//all roads allowed and length
|
||||||
|
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
|
||||||
|
@ -82,9 +158,20 @@ public class DijkstraTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDijkstra2(){
|
public void testDijkstra2(){//test en temps avec BF que pour les voitures
|
||||||
assertEquals(solDijkstra2.getPath().getMinimumTravelTime(),solBellman2.getPath().getMinimumTravelTime(),0.00001);
|
assertEquals(solDijkstra2.getPath().getMinimumTravelTime(),solBellman2.getPath().getMinimumTravelTime(),0.00001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDijktra3(){//test dijkstra pour chemin inexistant
|
||||||
|
assertTrue(solDijkstra3.getStatus().equals(Status.INFEASIBLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDijkstra4(){//test dijkstra pour chemin longueur nulle
|
||||||
|
assertTrue(solDijkstra4.getPath().getLength()==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//pour le dernier test : test de coherence (dist pour minTravelTime > dist pour getLength)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue