diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraProblemeOuvert.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ProblemeOuvert.java similarity index 100% rename from be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraProblemeOuvert.java rename to be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ProblemeOuvert.java diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/TestDijkstra.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/TestDijkstra.java index 1bbff53..c0172b9 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/TestDijkstra.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/TestDijkstra.java @@ -11,8 +11,8 @@ import javax.swing.SwingUtilities; import org.insa.graphs.algorithm.AbstractInputData.Mode; import org.insa.graphs.algorithm.ArcInspector; -import org.insa.graphs.algorithm.ArcInspectorFactory; import org.insa.graphs.algorithm.MyArcInspector; +import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm; import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm; import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm; import org.insa.graphs.algorithm.shortestpath.ShortestPathData; @@ -24,9 +24,7 @@ import org.insa.graphs.model.Node; import org.insa.graphs.model.Path; import org.insa.graphs.model.Arc; 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 { @@ -48,7 +46,7 @@ public class TestDijkstra { } // fonction pour tester un scénario - public static void testScenario(String map, int depart, int arrivee, Mode mode, boolean petitGraphe) throws Exception { + public static void testScenario(String map, int depart, int arrivee, Mode mode, boolean petitGraphe, boolean Astar) throws Exception { final Graph graph; final Path path; int maxSpeed = 130; // La vitesse maximale en km/h @@ -68,14 +66,21 @@ public class TestDijkstra { ArcInspector arcInspector = new MyArcInspector(mode, maxSpeed); ShortestPathData data = new ShortestPathData(graph, origin, destination, arcInspector); - DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data); + DijkstraAlgorithm dijkstra; + if (Astar) { + dijkstra = new AStarAlgorithm(data); + } else { + dijkstra = new DijkstraAlgorithm(data); + } + + ShortestPathSolution solution = dijkstra.run(); if (solution.getStatus() == ShortestPathSolution.Status.OPTIMAL) { path = solution.getPath(); // Vérif validité du chemin boolean valid = path.isValid(); - System.out.println("Chemin Dijkstra valide ? " + valid); + System.out.println("Chemin Algo valide ? " + valid); // Récupérer la liste des noeuds du chemin trouvé java.util.List nodeList = new java.util.ArrayList<>(); @@ -101,14 +106,18 @@ public class TestDijkstra { coutPath = pathFromNodes.getLength(); } - - System.out.println("Coût Dijkstra: " + coutAlgo); + if (Astar){ + System.out.println("Coût DijkstraAstar: " + coutAlgo); + }else{ + System.out.println("Coût Dijkstra: " + coutAlgo); + } + boolean coutOk = Math.abs(coutAlgo - coutPath) < 1e-6; // pour comparer des réels if(coutOk){ - System.out.println("Coût Dijkstra vs Path: " + coutAlgo + " vs " + coutPath + " => OK"); + System.out.println("Coût Algo vs Path: " + coutAlgo + " vs " + coutPath + " => OK"); } else { - System.out.println("Coût Dijkstra vs Path: " + coutAlgo + " vs " + coutPath + " => (différence attendue)"); + System.out.println("Coût Algo vs Path: " + coutAlgo + " vs " + coutPath + " => (différence attendue)"); } // Pour petits graphes, comparaison Bellman-Ford @@ -116,7 +125,7 @@ public class TestDijkstra { BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data); ShortestPathSolution solBellman = bellman.run(); boolean memeStatut = solution.getStatus() == solBellman.getStatus(); - System.out.println("Statut Dijkstra == Bellman-Ford ? " + memeStatut); + System.out.println("Statut Algo == Bellman-Ford ? " + memeStatut); if (solBellman.getPath() != null) { double coutBellman; @@ -128,9 +137,9 @@ public class TestDijkstra { boolean memeCout = Math.abs(coutAlgo - coutBellman) < 1e-6; //méthode pour comparer des floats. if(memeCout){ - System.out.println("Coût Dijkstra == Bellman-Ford ? OK"); + System.out.println("Coût Algo == Bellman-Ford ? OK"); } else { - System.out.println("Coût Dijkstra == Bellman-Ford ? (différence entre Bellman et Dijkstra.)"); + System.out.println("Coût Algo == Bellman-Ford ? (différence présente entre Bellman et Algo.)"); } } } @@ -149,20 +158,20 @@ public class TestDijkstra { public static void main(String[] args) throws Exception { //cartes non routières System.out.println("== Chemin de longueur nulle =="); - testScenario("carre.mapgr", 9, 9, Mode.LENGTH, true); + testScenario("carre.mapgr", 9, 9, Mode.LENGTH, true,false); System.out.println("== Sommet hors du graphe =="); - testScenario("carre.mapgr", 0, 9999, Mode.LENGTH, true); + testScenario("carre.mapgr", 0, 9999, Mode.LENGTH, true,false); //cartes routières System.out.println("== Test en distance =="); - testScenario("insa.mapgr", 369, 838, Mode.LENGTH, true); + testScenario("insa.mapgr", 369, 838, Mode.LENGTH, true,false); System.out.println("== Test en temps =="); - testScenario("insa.mapgr", 369, 838, Mode.TIME, true); + testScenario("insa.mapgr", 369, 838, Mode.TIME, true,false); // autres scénarios - //System.out.println("== Trajet long (et pénible avec les enfants) =="); - // testScenario("bretagne.mapgr",48233,135047 , Mode.TIME, false); + System.out.println("== Trajet long (et pénible avec les enfants) =="); + testScenario("bretagne.mapgr",48233,135047 , Mode.TIME, false,false); } }