diff --git a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithmTest.java b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithmTest.java index ab7a17c..f231a7b 100644 --- a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithmTest.java +++ b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithmTest.java @@ -7,15 +7,16 @@ import org.insa.graphs.*;//voir si on ne peut pas importer launch autrement import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; import org.insa.graphs.algorithm.ArcInspector; import org.insa.graphs.algorithm.ArcInspectorFactory; -import org.insa.graphs.algorithm.shortestpath.*; import org.insa.graphs.model.*; import org.insa.graphs.model.RoadInformation.RoadType; +import org.insa.graphs.model.io.BinaryGraphReader; +import org.insa.graphs.model.io.BinaryPathReader; import org.junit.BeforeClass; import org.junit.Test; @@ -30,7 +31,7 @@ public class DijkstraAlgorithmTest{ // List of arcs in the graph, a2b is the arc from node A (0) to B (1). @SuppressWarnings("unused") - private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d; + private static Arc ab, ac, ad, bf, bd, cd, cg, df, de, de2, dh, ef, eg, eh, fg, gh; private static ShortestPathData dataal, datacl, dataat, datact, datapt, onenodata, emptydata, invalidata; @@ -48,39 +49,47 @@ public class DijkstraAlgorithmTest{ @BeforeClass public static void initAll() throws IOException { - // 10 and 20 meters per seconds RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, true, 36, ""), - speed20 = new RoadInformation(RoadType.MOTORWAY, null, true, 72, ""); + speed20 = new RoadInformation(RoadType.MOTORWAY, null, true, 72, ""), + pietonable = new RoadInformation(RoadType.PEDESTRIAN, null, true, 5, ""); + //cyclable = new RoadInformation(RoadType.CYCLEWAY, null, true, 20, ""), // Create nodes - nodes = new Node[5]; + nodes = new Node[8]; for (int i = 0; i < nodes.length; ++i) { nodes[i] = new Node(i, null); } - // Add arcs... - a2b = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null); - a2c = Node.linkNodes(nodes[0], nodes[2], 15, speed10, null); - a2e = Node.linkNodes(nodes[0], nodes[4], 15, speed20, null); - b2c = Node.linkNodes(nodes[1], nodes[2], 10, speed10, null); - c2d_1 = Node.linkNodes(nodes[2], nodes[3], 20, speed10, null); - c2d_2 = Node.linkNodes(nodes[2], nodes[3], 10, speed10, null); - c2d_3 = Node.linkNodes(nodes[2], nodes[3], 15, speed20, null); - d2a = Node.linkNodes(nodes[3], nodes[0], 15, speed10, null); - d2e = Node.linkNodes(nodes[3], nodes[4], 22.8f, speed20, null); - e2d = Node.linkNodes(nodes[4], nodes[0], 10, speed10, null); - + // définition des arcs + ab = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null); + ac = Node.linkNodes(nodes[0], nodes[2], 50, speed20, null); + ad = Node.linkNodes(nodes[0], nodes[3], 15, speed10, null); + bd = Node.linkNodes(nodes[1], nodes[3], 15, speed20, null); + bf = Node.linkNodes(nodes[1], nodes[5], 20, speed10, null); + cd = Node.linkNodes(nodes[2], nodes[3], 10, speed20, null); + cg = Node.linkNodes(nodes[2], nodes[6], 15, speed10, null); + de = Node.linkNodes(nodes[3], nodes[4], 15, speed20, null); + de2= Node.linkNodes(nodes[3], nodes[4], 25, pietonable, null); + df = Node.linkNodes(nodes[3], nodes[5], 8, pietonable, null); + dh = Node.linkNodes(nodes[3], nodes[7], 12, pietonable, null); + ef = Node.linkNodes(nodes[4], nodes[5], 10, speed10, null); + eg = Node.linkNodes(nodes[4], nodes[6], 10, speed20, null); + eh = Node.linkNodes(nodes[4], nodes[7], 5, pietonable, null); + fg = Node.linkNodes(nodes[5], nodes[6], 10, pietonable, null); + gh = Node.linkNodes(nodes[6], nodes[7], 12, pietonable, null); + + graph = new Graph("ID", "", Arrays.asList(nodes), null); //initialisation des datas - dataal= new ShortestPathData(graph, null, null, alllen); - datacl= new ShortestPathData(graph, null, null, carlen); - dataat= new ShortestPathData(graph, null, null, alltime); - datact= new ShortestPathData(graph, null, null, cartime); - datapt= new ShortestPathData(graph, null, null, pietime); + dataal= new ShortestPathData(graph, nodes[0], nodes[4], alllen);//a->e + datacl= new ShortestPathData(graph, nodes[0], nodes[0], carlen);//b->g + dataat= new ShortestPathData(graph, nodes[0], nodes[0], alltime);//h->b + datact= new ShortestPathData(graph, nodes[0], nodes[0], cartime);//c->b + datapt= new ShortestPathData(graph, nodes[5], nodes[0], pietime);//f->e onenodata=new ShortestPathData(graph, nodes[2], nodes[2], pietime); emptydata=new ShortestPathData(graph, null, null, pietime); - invalidata=new ShortestPathData(graph, null, null, pietime); + invalidata=new ShortestPathData(graph, nodes[0], nodes[7], carlen);//h accessible uniquement aux piétons //initialisation des Dijkstras dijkal=new DijkstraAlgorithm(dataal); @@ -113,22 +122,52 @@ public class DijkstraAlgorithmTest{ @Test public void cheminValide() { assertTrue(dijkal.doRun().getPath().isValid()); + assertTrue(dijkcl.doRun().getPath().isValid()); + assertTrue(dijkat.doRun().getPath().isValid()); + assertTrue(dijkct.doRun().getPath().isValid()); + assertTrue(dijkpt.doRun().getPath().isValid()); + assertTrue(onenodijk.doRun().getPath().isValid()); + assertTrue(emptydijk.doRun().getPath().isValid());//pas sûr + assertFalse(invalidijk.doRun().getPath().isValid()); } @Test public void faisable() { - assertTrue(dijkal.doRun().isFeasible()); + assertTrue(dijkal.doRun().isFeasible()); + assertTrue(dijkcl.doRun().isFeasible()); + assertTrue(dijkat.doRun().isFeasible()); + assertTrue(dijkct.doRun().isFeasible()); + assertTrue(dijkpt.doRun().isFeasible()); + assertTrue(onenodijk.doRun().isFeasible()); + assertFalse(emptydijk.doRun().isFeasible());//pas sûr + assertFalse(invalidijk.doRun().isFeasible()); } //résultat identique à Bellman-Ford (sur les petits scénarios) @Test - public void sameasBF() { + public void sameasBF() {//peut-être faut-il donner directement par exemple à dijkal dijkal.doRun() pour éviter de la surexécution + //voir alors comment gérer les erreurs (pas encore gérées ici) assertTrue(Float.compare(dijkal.doRun().getPath().getLength(),bfaal.doRun().getPath().getLength())==0); + assertTrue(Float.compare(dijkcl.doRun().getPath().getLength(),bfacl.doRun().getPath().getLength())==0); + assertTrue(Double.compare(dijkat.doRun().getPath().getMinimumTravelTime(),bfaat.doRun().getPath().getMinimumTravelTime())==0); + assertTrue(Double.compare(dijkct.doRun().getPath().getMinimumTravelTime(),bfact.doRun().getPath().getMinimumTravelTime())==0); + assertTrue(Double.compare(dijkpt.doRun().getPath().getMinimumTravelTime(),bfapt.doRun().getPath().getMinimumTravelTime())==0); } - //tests applicables aussi pour des grands scénarios: - //... + //grands scénarios: + public void testmap() throws FileNotFoundException, IOException{//A FAIRE + + String mapaddr = "/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr"; + String pathaddr ="/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_aeroport_length.path"; + + Graph graphmap = (new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapaddr))))).read(); + Path pathmap = (new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathaddr))))).readPath(graphmap); + //quel inspector prendre? Le path est en longueur mais voitures seulement ou tout autorisé? + + DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), alllen)); - //graph = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream("a")))).read; + assertTrue(dijkmap.doRun().getPath().getLength()==pathmap.getLength()); + //comparaison de la longueur + } }