diff --git a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/TestDijkstra.java b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/TestDijkstra.java index 8685ed2..3564781 100644 --- a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/TestDijkstra.java +++ b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/TestDijkstra.java @@ -6,6 +6,7 @@ import java.io.FileInputStream; import java.util.List; import org.insa.graphs.algorithm.ArcInspector; +import org.insa.graphs.algorithm.ArcInspectorFactory; import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm; import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm; import org.insa.graphs.algorithm.shortestpath.ShortestPathData; @@ -15,7 +16,9 @@ import org.insa.graphs.model.Graph; 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.BinaryPathReader; import org.insa.graphs.model.io.GraphReader; +import org.insa.graphs.model.io.PathReader; public class TestDijkstra { /* Définissez plusieurs scénarios. Chaque scénario est défini par : une carte (tester des cartes routières et non routières) @@ -45,37 +48,32 @@ Automated: No need for manual launching or visual inspection.*/ Graph graph = null; Path path = null; - // create a graph reader - /* try (final GraphReader reader = new BinaryGraphReader(new DataInputStream( - new BufferedInputStream(new FileInputStream(mapName))))) { - - // TODO: read the graph - graph = reader.read(); - reader.close(); - } - - // TODO: create a path reader - // Je suis là et c'est là que je dois faire les changements nécessaires - try (final PathReader pathReader = new BinaryPathReader(new DataInputStream( - new BufferedInputStream(new FileInputStream(pathName))))) { - - // TODO: read the path - path = pathReader.readPath(graph); - }*/ -// fonction pour recuperer les paths -// create a graph reader - void graphlecture (Graph graph,String mapName) throws Exception { - try (final GraphReader reader = new BinaryGraphReader(new DataInputStream( - new BufferedInputStream(new FileInputStream(mapName))))) { - - // TODO: read the graph - graph = reader.read(); - reader.close(); - }} + // fonction pour recuperer les paths + public static Path pathlecture(Graph graph,String pathName) { + try (final PathReader reader = new BinaryPathReader( + new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))))) { + return reader.readPath(graph); + } catch (Exception e) { + System.err.println("Erreur lors de la lecture du chemin : " + e.getMessage()); + e.printStackTrace(); + return null; + } +} +// fonction pour recuperer les graphs + public static Graph graphlecture(String mapName) { + try (final GraphReader reader = new BinaryGraphReader( + new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))))) { + return reader.read(); + } catch (Exception e) { + System.err.println("Erreur lors de la lecture du graphe : " + e.getMessage()); + e.printStackTrace(); + return null; + } +} -// Scénario 1 : trajet court petite map -final String mapName1= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; -final String pathName1 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path"; +// Scénario 1 : trajet court petite map pieton +final static String mapName1= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; +final static String pathName1 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path"; // Scénario 2 : trajet long petite map final String mapName2= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; Graph graphe2; @@ -83,8 +81,8 @@ Graph graphe2; // Scénario 3: trajet court grande map -final String mapName3= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/belgium.mapgr"; -final String pathName3 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_be_173101_302442.path"; +final static String mapName3= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/belgium.mapgr"; +final static String pathName3 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_be_173101_302442.path"; // Scénario 4: trajet long grande map final String mapName4= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/belgium.mapgr"; @@ -109,21 +107,24 @@ final String mapName8= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps /* Tests pour l'ensembles des scénarios*/ // Vérifier la validité du chemin : utilisation de .isvalid() -// fonction verifiant que deux chemins sont les memes -public static boolean bonchemin (Path chemintrouve,Path cheminrecherche){ +// fonction qui extrait le chemin valide + + +public static boolean boncheminDijkstra (ShortestPathData Data,Path chemindepart){ // on regarde d'abord si les chemins sont valides - if(!(chemintrouve.isValid()) || !(cheminrecherche.isValid()) ){ + Path chemintrouve = Path_Dijkstra(Data); + if(!(chemintrouve.isValid()) || !(chemindepart.isValid()) ){ System.out.println(" chemin(s) non valide"); return false; } // on verifie si les chemins ont le meme nombre de noeuds - if(chemintrouve.size() != cheminrecherche.size()){ + if(chemintrouve.size() != chemindepart.size()){ System.out.println(" chemins de taille différente"); return false; } // recuperation liste des arcs List arcstrouves = chemintrouve.getArcs(); - List arcsrecherches = cheminrecherche.getArcs(); + List arcsrecherches = chemindepart.getArcs(); // On verifie si les chemins utilisent les mêmes arcs for (int i=0; iepsilon){ - System.out.println("Dijkstra et BellmanFord on des coûts différents"); +else{ return true;} +} +// Recuperer origine d'un path +//public static Node getOrigin + // Vérifier que le coût en temps est similaire entre Dijkstra et Bellman-Ford +public static boolean memetemps (ShortestPathData Data){ + // Recuperation Path de Dijkstra + Path PathDijkstra =Path_Dijkstra(Data); + // Recuperation Path de BellmanFord + Path PathBellmanFord =Path_BellmanFord(Data); + // Verifier si un path existe avant de verifier sa validite pour eviter probs de pointeur + if (!ExistancePaths(PathDijkstra, PathBellmanFord)){ + return false; + } + // Verification de la validité des Path + if(!ValiditePaths(PathDijkstra, PathBellmanFord)){ return false; } + + // verification du cout en temps + double CostDijkstra = PathDijkstra.getMinimumTravelTime(); + double CostBellmanFord = PathBellmanFord.getMinimumTravelTime(); + if(CostDijkstra != CostBellmanFord){ + System.out.println("Dijkstra et BellmanFord ont des temps différents de parcours"); + return false; + } + System.out.println("Dijkstra et BellmanFord ont les même temps de parcours"); return true; } // Vérifier que le coût en distance est similaire entre Dijkstra et Bellman-Ford +public static boolean memedistance (ShortestPathData Data){ + // Recuperation Path de Dijkstra + Path PathDijkstra =Path_Dijkstra(Data); + // Recuperation Path de BellmanFord + Path PathBellmanFord =Path_BellmanFord(Data); + // Verifier si un path existe avant de verifier sa validite pour eviter probs de pointeur + if (!ExistancePaths(PathDijkstra, PathBellmanFord)){ + return false; + } + + // Verification de la validité des Path + if(!ValiditePaths(PathDijkstra, PathBellmanFord)){ + return false; + } + + // verification de la similarite en distance + double CostDijkstra = PathDijkstra.getLength(); + double CostBellmanFord = PathBellmanFord.getLength(); + if(CostDijkstra != CostBellmanFord){ + System.out.println("Dijkstra et BellmanFord ont des distances différentes de parcours"); + return false; + } + System.out.println("Dijkstra et BellmanFord ont les même distances de parcours"); + return true; +} + +public static boolean memepath (ShortestPathData Data){ + // Recuperation Path de Dijkstra + Path PathDijkstra =Path_Dijkstra(Data); + // Recuperation Path de BellmanFord + Path PathBellmanFord =Path_BellmanFord(Data); + + // Verifier si un path existe avant de verifier sa validite pour eviter probs de pointeur + if (!ExistancePaths(PathDijkstra, PathBellmanFord)){ + return false; + } + + // Verification de la validité des Path + if(!ValiditePaths(PathDijkstra, PathBellmanFord)){ + return false; + } + + // verification de la similarite des paths + // comparer l'ensemble des origines et destination des arcs et leurs couts + List ArcsDijkstra = PathDijkstra.getArcs(); + List ArcsBellmanFord = PathBellmanFord.getArcs(); + // Verifier si on a la meme taille d'arc + if(ArcsDijkstra.size() != ArcsBellmanFord.size()){ + return false; + } + // Verifier que les arcs ont même origine et même destination + for (int i=0;i filters = ArcInspectorFactory.getAllFilters(); + ArcInspector Nofilterbylength = filters.get(0); + ArcInspector OnlyCarByLength = filters.get(1); + ArcInspector OnlyCarByTime= filters.get(2); + ArcInspector OnlyPedestrianByTime = filters.get(3); + //final String mapName1= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; + //final String pathName1 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path"; + // Recuperation du graph et path de la situation + Graph graph = graphlecture(mapName1); + Path pathrecupere1 = pathlecture(graph, pathName1); + // Recuperation du path realise par Dijkstra + ShortestPathData Data1 = new ShortestPathData(graph,pathrecupere1.getOrigin(), pathrecupere1.getDestination(),Nofilterbylength); + // verification du bon chemin + if(boncheminDijkstra(Data1, pathrecupere1)){ + System.out.println("L'algorithme Dijkstra donne le bon path"); + } + else{System.out.println("L'algorithme Dijkstra ne donne pas le bon path");} + + // Comparaison avec Bellman Ford + // Comparaison de cout en distance + //if(memedistance(Data1)){ + + //} + + + + + } } \ No newline at end of file