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.BufferedInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
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.MyArcInspector;
|
import org.insa.graphs.algorithm.MyArcInspector;
|
||||||
import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
|
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.ProblemeOuvert;
|
||||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
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.Graph;
|
||||||
import org.insa.graphs.model.Node;
|
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.io.BinaryGraphReader;
|
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||||
import org.insa.graphs.model.io.GraphReader;
|
import org.insa.graphs.model.io.GraphReader;
|
||||||
|
|
||||||
public class TestDijkstra {
|
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
|
// 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, boolean Astar, boolean restreint) throws Exception {
|
public static void testScenario(String map, int depart, int arrivee, Mode mode, boolean petitGraphe, int type, boolean restreint) 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
|
||||||
|
|
@ -44,10 +67,16 @@ public class TestDijkstra {
|
||||||
ArcInspector arcInspector = new MyArcInspector(mode, maxSpeed,restreint);
|
ArcInspector arcInspector = new MyArcInspector(mode, maxSpeed,restreint);
|
||||||
ShortestPathData data = new ShortestPathData(graph, origin, destination, arcInspector);
|
ShortestPathData data = new ShortestPathData(graph, origin, destination, arcInspector);
|
||||||
DijkstraAlgorithm dijkstra;
|
DijkstraAlgorithm dijkstra;
|
||||||
if (Astar) {
|
switch (type) {
|
||||||
|
case 1:
|
||||||
dijkstra = new AStarAlgorithm(data);
|
dijkstra = new AStarAlgorithm(data);
|
||||||
} else {
|
break;
|
||||||
|
case 2:
|
||||||
|
dijkstra = new ProblemeOuvert(data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
dijkstra = new DijkstraAlgorithm(data);
|
dijkstra = new DijkstraAlgorithm(data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,13 +112,14 @@ public class TestDijkstra {
|
||||||
coutPath = pathFromNodes.getLength();
|
coutPath = pathFromNodes.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Astar){
|
if (type == 1) {
|
||||||
System.out.println("Coût DijkstraAstar: " + coutAlgo);
|
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);
|
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 Algo vs Path: " + coutAlgo + " vs " + coutPath + " => OK");
|
System.out.println("Coût Algo vs Path: " + coutAlgo + " vs " + coutPath + " => OK");
|
||||||
|
|
@ -143,22 +173,22 @@ public class TestDijkstra {
|
||||||
|
|
||||||
//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,false,false);
|
testScenario("insa.mapgr", 369, 838, Mode.LENGTH, true,0,false);
|
||||||
|
|
||||||
System.out.println("== Test en temps ==");
|
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
|
// 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",564429,602395 , Mode.LENGTH, false,false,false);
|
// testScenario("bretagne.mapgr",564429,602395 , Mode.LENGTH, false,false,false);
|
||||||
|
|
||||||
// System.out.println("== Test bug dijkstra temps ==");
|
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.
|
// 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) ==");
|
||||||
System.out.println("== Trajet impossible (piste cyclable) ==");
|
// testScenario("insa.mapgr",90,922 , Mode.LENGTH, false,false,true); //marche pas
|
||||||
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
|
|
||||||
|
|
||||||
|
//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