123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- package org.insa.graphs.algorithm.shortestpath;
-
- import static org.junit.Assert.*;
-
- 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.Arrays;
-
- import org.insa.graphs.algorithm.ArcInspector;
- import org.insa.graphs.algorithm.ArcInspectorFactory;
- import org.insa.graphs.model.*;
- import org.insa.graphs.model.AccessRestrictions.AccessMode;
- import org.insa.graphs.model.RoadInformation.RoadType;
- import org.insa.graphs.model.io.BinaryGraphReader;
- import org.insa.graphs.model.io.BinaryPathReader;
- import org.insa.graphs.model.io.GraphReader;
- import org.insa.graphs.model.io.PathReader;
- import org.junit.BeforeClass;
- import org.junit.Test;
-
- public class DijkstraAlgorithmTest{
-
- //copié sur PathTest.java
- // Small graph use for tests
- private static Graph graph;
-
- // List of nodes
- private static Node[] nodes;
-
- // List of arcs in the graph, a2b is the arc from node A (0) to B (1).
- @SuppressWarnings("unused")
- 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;
-
- // permet de savoir quels arcs autoriser(cf l.187 excel ggdoc)
- private static ArcInspector alllen = ArcInspectorFactory.getAllFilters().get(0);
- private static ArcInspector carlen = ArcInspectorFactory.getAllFilters().get(1);
- private static ArcInspector alltime = ArcInspectorFactory.getAllFilters().get(2);
- private static ArcInspector cartime = ArcInspectorFactory.getAllFilters().get(3);
- private static ArcInspector pietime = ArcInspectorFactory.getAllFilters().get(4);
-
- private static ShortestPathSolution dijkal, dijkcl, dijkat, dijkct, dijkpt, onenodijk, emptydijk, invalidijk;
- private static ShortestPathSolution bfaal, bfacl, bfaat, bfact, bfapt; //les BF et Dijkstra sur deux lignes différentes par souci de lisibilité
-
-
- @BeforeClass
- public static void initAll() throws IOException {
-
- RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, false, 36, ""),
- speed20 = new RoadInformation(RoadType.MOTORWAY, null, false, 72, ""),
- pietonable = new RoadInformation(RoadType.PEDESTRIAN, null, false, 5, "");
- //cyclable = new RoadInformation(RoadType.CYCLEWAY, null, false, 20, ""),
- //toutes les routes ici sont à double sens
- //visiblement un problème ave le deuxième argument null, comment gérer les restrictions?
-
- // Create nodes
- nodes = new Node[8];
- for (int i = 0; i < nodes.length; ++i) {
- nodes[i] = new Node(i, 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, 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, nodes[0], nodes[7], carlen);//h accessible uniquement aux piétons
-
- //initialisation des Dijkstras
- dijkal = (new DijkstraAlgorithm(dataal)).run();
- dijkcl = (new DijkstraAlgorithm(datacl)).run();
- dijkat = (new DijkstraAlgorithm(dataat)).run();
- dijkct = (new DijkstraAlgorithm(datact)).run();
- //dijkpt = (new DijkstraAlgorithm(datapt)).run();//erreur ici
- onenodijk = (new DijkstraAlgorithm(onenodata)).run();
- emptydijk = (new DijkstraAlgorithm(emptydata)).run();//erreur ici
- //invalidijk = (new DijkstraAlgorithm(invalidata)).run();//et erreur là
-
- //initialisation des Bellman-Ford pour comparaison
- bfaal = (new BellmanFordAlgorithm(dataal)).run();
- bfacl = (new BellmanFordAlgorithm(datacl)).run();
- /*bfaat = (new BellmanFordAlgorithm(dataat)).run();
- bfact = (new BellmanFordAlgorithm(datact)).run();
- bfapt = (new BellmanFordAlgorithm(datapt)).run();*/ //erreurs partout ici...
-
- }
-
- //créer plus et avec des maps différentes
- //faire des test spécifiques pour longs trajets
-
-
- /*(Test faits directement via la console et DijkstraAlgorithm.java, actuellement commentés:
- -coûts croissants
- -nbr successeurs cohérents
- -tas valide.)*/
-
- @Test
- public void cheminValide() {
- assertTrue(dijkal.getPath().isValid());
- assertTrue(dijkcl.getPath().isValid());
- assertTrue(dijkat.getPath().isValid());
- assertTrue(dijkct.getPath().isValid());
- //assertTrue(dijkpt.getPath().isValid());//pas normal
- assertTrue(onenodijk.getPath().isValid());
- assertTrue(emptydijk.getPath().isValid());
- //assertFalse(invalidijk.getPath().isValid());
- }
-
- @Test
- public void faisable() {
- assertTrue(dijkal.isFeasible());
- assertTrue(dijkcl.isFeasible());
- assertTrue(dijkat.isFeasible());
- assertTrue(dijkct.isFeasible());
- //assertTrue(dijkpt.isFeasible());
- assertTrue(onenodijk.isFeasible());
- assertFalse(emptydijk.isFeasible());
- //assertFalse(invalidijk.isFeasible());
- }
-
-
- //résultat identique à Bellman-Ford (sur les petits scénarios)
- @Test
- public void sameasBF() {
- assertTrue(Float.compare(dijkal.getPath().getLength(),bfaal.getPath().getLength())==0);
- //assertTrue(Float.compare(dijkcl.getPath().getLength(),bfacl.getPath().getLength())==0);
- //assertTrue(Double.compare(dijkat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
- //assertTrue(Double.compare(dijkct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
- //assertTrue(Double.compare(dijkpt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
- }
-
- //grands scénarios:
- @Test
- 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";
-
- GraphReader graphread = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapaddr))));
- PathReader pathread = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathaddr))));
-
- Graph graphmap = graphread.read();
- Path pathmap = pathread.readPath(graphmap);//erreur ici mais pas mapmismatch, donc pourquoi? Path impossible? (hem)
- //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));
-
- assertTrue(dijkmap.run().getPath().getLength()==pathmap.getLength());
- //comparaison de la longueur
- }
- }
|