je rename un fichier
这个提交包含在:
父节点
d59974e56c
当前提交
773a14154f
共有 2 个文件被更改,包括 28 次插入 和 19 次删除
|
|
@ -11,8 +11,8 @@ import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
||||||
import org.insa.graphs.algorithm.ArcInspector;
|
import org.insa.graphs.algorithm.ArcInspector;
|
||||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
|
||||||
import org.insa.graphs.algorithm.MyArcInspector;
|
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.BellmanFordAlgorithm;
|
||||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
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.Path;
|
||||||
import org.insa.graphs.model.Arc;
|
import org.insa.graphs.model.Arc;
|
||||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
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.GraphReader;
|
||||||
import org.insa.graphs.model.io.PathReader;
|
|
||||||
|
|
||||||
public class TestDijkstra {
|
public class TestDijkstra {
|
||||||
|
|
||||||
|
|
@ -48,7 +46,7 @@ public class TestDijkstra {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fonction pour tester un scénario
|
// 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 Graph graph;
|
||||||
final Path path;
|
final Path path;
|
||||||
int maxSpeed = 130; // La vitesse maximale en km/h
|
int maxSpeed = 130; // La vitesse maximale en km/h
|
||||||
|
|
@ -68,14 +66,21 @@ public class TestDijkstra {
|
||||||
|
|
||||||
ArcInspector arcInspector = new MyArcInspector(mode, maxSpeed);
|
ArcInspector arcInspector = new MyArcInspector(mode, maxSpeed);
|
||||||
ShortestPathData data = new ShortestPathData(graph, origin, destination, arcInspector);
|
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();
|
ShortestPathSolution solution = dijkstra.run();
|
||||||
|
|
||||||
if (solution.getStatus() == ShortestPathSolution.Status.OPTIMAL) {
|
if (solution.getStatus() == ShortestPathSolution.Status.OPTIMAL) {
|
||||||
path = solution.getPath();
|
path = solution.getPath();
|
||||||
// Vérif validité du chemin
|
// Vérif validité du chemin
|
||||||
boolean valid = path.isValid();
|
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é
|
// Récupérer la liste des noeuds du chemin trouvé
|
||||||
java.util.List<Node> nodeList = new java.util.ArrayList<>();
|
java.util.List<Node> nodeList = new java.util.ArrayList<>();
|
||||||
|
|
@ -101,14 +106,18 @@ public class TestDijkstra {
|
||||||
coutPath = pathFromNodes.getLength();
|
coutPath = pathFromNodes.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Astar){
|
||||||
|
System.out.println("Coût DijkstraAstar: " + coutAlgo);
|
||||||
|
}else{
|
||||||
|
System.out.println("Coût Dijkstra: " + coutAlgo);
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Coût Dijkstra: " + coutAlgo);
|
|
||||||
|
|
||||||
boolean coutOk = Math.abs(coutAlgo - coutPath) < 1e-6; // pour comparer des réels
|
boolean coutOk = Math.abs(coutAlgo - coutPath) < 1e-6; // pour comparer des réels
|
||||||
if(coutOk){
|
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 {
|
} 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
|
// Pour petits graphes, comparaison Bellman-Ford
|
||||||
|
|
@ -116,7 +125,7 @@ public class TestDijkstra {
|
||||||
BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data);
|
BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data);
|
||||||
ShortestPathSolution solBellman = bellman.run();
|
ShortestPathSolution solBellman = bellman.run();
|
||||||
boolean memeStatut = solution.getStatus() == solBellman.getStatus();
|
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) {
|
if (solBellman.getPath() != null) {
|
||||||
|
|
||||||
double coutBellman;
|
double coutBellman;
|
||||||
|
|
@ -128,9 +137,9 @@ public class TestDijkstra {
|
||||||
|
|
||||||
boolean memeCout = Math.abs(coutAlgo - coutBellman) < 1e-6; //méthode pour comparer des floats.
|
boolean memeCout = Math.abs(coutAlgo - coutBellman) < 1e-6; //méthode pour comparer des floats.
|
||||||
if(memeCout){
|
if(memeCout){
|
||||||
System.out.println("Coût Dijkstra == Bellman-Ford ? OK");
|
System.out.println("Coût Algo == Bellman-Ford ? OK");
|
||||||
} else {
|
} 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 {
|
public static void main(String[] args) throws Exception {
|
||||||
//cartes non routières
|
//cartes non routières
|
||||||
System.out.println("== Chemin de longueur nulle ==");
|
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 ==");
|
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
|
//cartes routières
|
||||||
System.out.println("== Test en distance ==");
|
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 ==");
|
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
|
// autres scénarios
|
||||||
|
|
||||||
//System.out.println("== Trajet long (et pénible avec les enfants) ==");
|
System.out.println("== Trajet long (et pénible avec les enfants) ==");
|
||||||
// testScenario("bretagne.mapgr",48233,135047 , Mode.TIME, false);
|
testScenario("bretagne.mapgr",48233,135047 , Mode.TIME, false,false);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
正在加载…
在新工单中引用