fusion testdijkstra
This commit is contained in:
parent
aa1301c4e0
commit
48fd9be129
1 changed files with 51 additions and 21 deletions
|
|
@ -1,29 +1,52 @@
|
|||
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
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.ProblemeOuvert;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.gui.drawing.Drawing;
|
||||
import org.insa.graphs.gui.drawing.components.BasicDrawing;
|
||||
import org.insa.graphs.model.Graph;
|
||||
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.GraphReader;
|
||||
|
||||
public class TestDijkstra {
|
||||
|
||||
public static Drawing createDrawing() throws Exception {
|
||||
BasicDrawing basicDrawing = new BasicDrawing();
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JFrame frame = new JFrame("BE Graphes - Launch");
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
frame.setSize(new Dimension(800, 600));
|
||||
frame.setContentPane(basicDrawing);
|
||||
frame.validate();
|
||||
}
|
||||
});
|
||||
return basicDrawing;
|
||||
}
|
||||
|
||||
// fonction pour tester un scénario
|
||||
public static void testScenario(String map, int depart, int arrivee, Mode mode, boolean petitGraphe, boolean Astar, boolean restreint) throws Exception {
|
||||
// fonction pour tester un scénario: type: 0 dijkstra, 1 Astar, 2 ProblemeOuvert
|
||||
public static void testScenario(String map, int depart, int arrivee, Mode mode, boolean petitGraphe, int type, boolean restreint) throws Exception {
|
||||
final Graph graph;
|
||||
final Path path;
|
||||
int maxSpeed = 130; // La vitesse maximale en km/h
|
||||
|
|
@ -44,10 +67,16 @@ public class TestDijkstra {
|
|||
ArcInspector arcInspector = new MyArcInspector(mode, maxSpeed,restreint);
|
||||
ShortestPathData data = new ShortestPathData(graph, origin, destination, arcInspector);
|
||||
DijkstraAlgorithm dijkstra;
|
||||
if (Astar) {
|
||||
dijkstra = new AStarAlgorithm(data);
|
||||
} else {
|
||||
dijkstra = new DijkstraAlgorithm(data);
|
||||
switch (type) {
|
||||
case 1:
|
||||
dijkstra = new AStarAlgorithm(data);
|
||||
break;
|
||||
case 2:
|
||||
dijkstra = new ProblemeOuvert(data);
|
||||
break;
|
||||
default:
|
||||
dijkstra = new DijkstraAlgorithm(data);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -83,12 +112,13 @@ public class TestDijkstra {
|
|||
coutPath = pathFromNodes.getLength();
|
||||
}
|
||||
|
||||
if (Astar){
|
||||
if (type == 1) {
|
||||
System.out.println("Coût DijkstraAstar: " + coutAlgo);
|
||||
}else{
|
||||
} else if (type == 2) {
|
||||
System.out.println("Coût ProblemeOuvert: " + coutAlgo);
|
||||
} else {
|
||||
System.out.println("Coût Dijkstra: " + coutAlgo);
|
||||
}
|
||||
|
||||
|
||||
boolean coutOk = Math.abs(coutAlgo - coutPath) < 1e-6; // pour comparer des réels
|
||||
if(coutOk){
|
||||
|
|
@ -143,22 +173,22 @@ public class TestDijkstra {
|
|||
|
||||
//cartes routières
|
||||
System.out.println("== Test en distance ==");
|
||||
testScenario("insa.mapgr", 369, 838, Mode.LENGTH, true,false,false);
|
||||
testScenario("insa.mapgr", 369, 838, Mode.LENGTH, true,0,false);
|
||||
|
||||
System.out.println("== Test en temps ==");
|
||||
testScenario("insa.mapgr", 369, 838, Mode.TIME, true,false,false);
|
||||
testScenario("insa.mapgr", 369, 838, Mode.TIME, true,0,false);
|
||||
// autres scénarios
|
||||
|
||||
// System.out.println("== Trajet long (et pénible avec les enfants) ==");
|
||||
// testScenario("bretagne.mapgr",564429,602395 , Mode.LENGTH, false,false,false);
|
||||
|
||||
// System.out.println("== Test bug dijkstra temps ==");
|
||||
// testScenario("paris.mapgr", 27361, 36108, Mode.TIME, true,false,false); // ce test mettait en lumière un problème d'arrondi qui est mtn résolu.
|
||||
|
||||
System.out.println("== Trajet impossible (piste cyclable) ==");
|
||||
testScenario("insa.mapgr",90,922 , Mode.LENGTH, false,false,true);
|
||||
System.out.println("== Trajet impossible (piste cyclable) == sans restriction");
|
||||
testScenario("insa.mapgr",90,922 , Mode.LENGTH, false,false,false); //marche pas
|
||||
|
||||
System.out.println("== Test bug dijkstra temps ==");
|
||||
// testScenario("paris.mapgr", 27361, 36108, Mode.TIME, true,0,false); //ce chemin visualisait un bug d'arrondi de dijkstra qui est corrigé actuellement
|
||||
// System.out.println("== Trajet impossible (piste cyclable) ==");
|
||||
// testScenario("insa.mapgr",90,922 , Mode.LENGTH, false,false,true); //marche pas
|
||||
|
||||
//test probleme ouvert
|
||||
System.out.println("== Test Probleme Ouvert ==");
|
||||
testScenario("bretagne.mapgr",564429,602395 , Mode.LENGTH, false,2,false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue