Tests Dijkstra
This commit is contained in:
parent
04f0e61c54
commit
86b860f9a3
1 changed files with 83 additions and 64 deletions
|
@ -10,14 +10,12 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
|
||||||
import org.insa.graphs.algorithm.ArcInspector;
|
import org.insa.graphs.algorithm.ArcInspector;
|
||||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||||
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.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;
|
import org.insa.graphs.model.io.PathReader;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -33,59 +31,34 @@ public class DijkstraAlgorithmTest {
|
||||||
public static ArrayList<Path> path = new ArrayList<Path>();
|
public static ArrayList<Path> path = new ArrayList<Path>();
|
||||||
|
|
||||||
@Parameter
|
@Parameter
|
||||||
// Liste de cartes
|
// Liste de cartes utilisées
|
||||||
static ArrayList<String> Maps = new ArrayList<String>(Arrays.asList("../Maps/carre.mapgr",
|
static ArrayList<String> Maps = new ArrayList<String>(Arrays.asList("../Maps/carre.mapgr",
|
||||||
"../Maps/insa.mapgr",
|
"../Maps/insa.mapgr",
|
||||||
"../Maps/toulouse.mapgr",
|
"../Maps/toulouse.mapgr",
|
||||||
"../Maps/midi-pyrenees.mapgr"));
|
"../Maps/midi-pyrenees.mapgr"));
|
||||||
|
|
||||||
//TODO: chemins map carree à creer
|
|
||||||
// chemins maps insa à remettre
|
|
||||||
// chemins map toulouse à créer
|
|
||||||
|
|
||||||
// test optimalité : long chemin: belgique espagne
|
|
||||||
|
|
||||||
static ArrayList<String> Paths_CARREE = new ArrayList<String>(Arrays.asList("../Paths/custom_paths/short_path_carre.path",
|
|
||||||
"../Paths/custom_paths/long_path_carre.path"));
|
|
||||||
static ArrayList<String> Paths_INSA = new ArrayList<String>(Arrays.asList( "../Paths/path_fr31insa_rangueil_r2.path",
|
|
||||||
"../Paths/custom_paths/long_path_insa.path"));
|
|
||||||
static ArrayList<String> Paths_TLS = new ArrayList<String>(Arrays.asList("../Paths/custom_paths/short_path_tls.path",
|
|
||||||
"../Paths/custom_paths/long_path_tls.path"));
|
|
||||||
static ArrayList<String> Paths_Midi_Pyrenees = new ArrayList<String>(Arrays.asList("../Paths/custom_paths/long_chemin_midi_pyrenees.path"));
|
|
||||||
|
|
||||||
// A list containing all the paths to be tested
|
|
||||||
static ArrayList[] Paths = {Paths_CARREE,Paths_INSA,Paths_TLS, Paths_Midi_Pyrenees};
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
// Init all the graphs and paths we need for the tests
|
/*
|
||||||
// We create for each map all the known paths (custom ones)
|
* Ajoute toute les cartes dans l'attribut graph.
|
||||||
|
* Ensuite, on testera des chemins dont qui sont disponibles dans custom_path.
|
||||||
|
* Ces chemins ont été tracés avec l'algo BellmanFord et sont donc considérés corrects.
|
||||||
|
* On ne crée pas les chemins dans un attribut, on va les "recréer" virtuellement à
|
||||||
|
* partir de leur origine/destination et en appliquant BellmanFord.
|
||||||
|
* Cela permet une meilleure adaptabilité du code.
|
||||||
|
*/
|
||||||
public static void init() {
|
public static void init() {
|
||||||
try {
|
try {
|
||||||
ArrayList<String> actual_path_list = new ArrayList<String>();
|
ArrayList<String> actual_path_list = new ArrayList<String>();
|
||||||
// Create the map
|
// Create the map
|
||||||
for (int j = 0 ; j < Maps.size() ; j++) {
|
for (int j = 0 ; j < Maps.size() ; j++) {
|
||||||
actual_path_list = Paths[j];
|
final String mapName = Maps.get(j);
|
||||||
final String mapName = Maps.get(j);
|
// Create a graph reader
|
||||||
// Create a graph reader
|
final GraphReader reader = new BinaryGraphReader(
|
||||||
final GraphReader reader = new BinaryGraphReader(
|
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
||||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
// Read the graph. X
|
||||||
// Read the graph. X
|
graph.add(reader.read());
|
||||||
graph.add(reader.read());
|
// free resources
|
||||||
// free resources
|
reader.close();
|
||||||
reader.close();
|
|
||||||
|
|
||||||
// Create the paths of the map
|
|
||||||
for (int i = 0 ; i < actual_path_list.size() ; i ++) {
|
|
||||||
final String pathName = actual_path_list.get(i);
|
|
||||||
// Create a PathReader.
|
|
||||||
final PathReader pathReader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
|
|
||||||
// System.out.println(pathName);
|
|
||||||
// System.out.println(mapName);
|
|
||||||
// Read the path.
|
|
||||||
path.add(pathReader.readPath(graph.get(j)));
|
|
||||||
// free resources
|
|
||||||
pathReader.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e) {
|
catch (FileNotFoundException e) {
|
||||||
|
@ -105,9 +78,12 @@ public class DijkstraAlgorithmTest {
|
||||||
*/
|
*/
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
// Map: carre.mapgr
|
/*
|
||||||
// Chemin: 19 --> 4
|
* Map: carre.mapgr
|
||||||
// Tous chemins permis
|
* Chemin: 19 --> 4
|
||||||
|
* Tous chemins permis
|
||||||
|
* PATH UTILISE : ../Paths/custom_paths/short_path_carre.path
|
||||||
|
*/
|
||||||
public void chemin_court_CARRE() {
|
public void chemin_court_CARRE() {
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||||
Graph myGraph = graph.get(0);
|
Graph myGraph = graph.get(0);
|
||||||
|
@ -122,6 +98,8 @@ public class DijkstraAlgorithmTest {
|
||||||
ShortestPathSolution bell_path = bellman.doRun();
|
ShortestPathSolution bell_path = bellman.doRun();
|
||||||
|
|
||||||
assert(dijk_path.getPath().isValid());
|
assert(dijk_path.getPath().isValid());
|
||||||
|
assert(dijk_path.isFeasible());
|
||||||
|
assert(Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength()) < 1.0);
|
||||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,12 +108,14 @@ public class DijkstraAlgorithmTest {
|
||||||
* Chemin long relativement à la carte carrée.
|
* Chemin long relativement à la carte carrée.
|
||||||
* Chemin: 15 --> 9
|
* Chemin: 15 --> 9
|
||||||
* Tous chemins permis
|
* Tous chemins permis
|
||||||
|
* PATH UTILISE : ../Paths/custom_paths/long_path_carre.path
|
||||||
*/
|
*/
|
||||||
public void chemin_long_CARRE() {
|
public void chemin_long_CARRE() {
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||||
Graph myGraph = graph.get(0);
|
Graph myGraph = graph.get(0);
|
||||||
Node origin = myGraph.get(15);
|
Node origin = myGraph.get(15);
|
||||||
Node destination = myGraph.get(9);
|
Node destination = myGraph.get(9);
|
||||||
|
|
||||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||||
|
@ -145,6 +125,8 @@ public class DijkstraAlgorithmTest {
|
||||||
ShortestPathSolution bell_path = bellman.doRun();
|
ShortestPathSolution bell_path = bellman.doRun();
|
||||||
|
|
||||||
assert(dijk_path.getPath().isValid());
|
assert(dijk_path.getPath().isValid());
|
||||||
|
assert(dijk_path.isFeasible());
|
||||||
|
assert(Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength()) < 1.0);
|
||||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +146,7 @@ public class DijkstraAlgorithmTest {
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||||
|
|
||||||
assertEquals(dijk_path.getStatus(), Status.INFEASIBLE);
|
assert(!dijk_path.isFeasible());
|
||||||
assert(dijk_path.getPath() == null);
|
assert(dijk_path.getPath() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,15 +167,17 @@ public class DijkstraAlgorithmTest {
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||||
|
assert(!dijk_path.isFeasible());
|
||||||
assertEquals(dijk_path.getStatus(), Status.INFEASIBLE);
|
|
||||||
assert(dijk_path.getPath() == null);
|
assert(dijk_path.getPath() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
/*
|
/*
|
||||||
* Chemin court sur la carte de Toulouse.
|
* Chemin court sur la carte de Toulouse.
|
||||||
|
* Origine : 8423
|
||||||
|
* Destination: 8435
|
||||||
* Tous chemins permis.
|
* Tous chemins permis.
|
||||||
|
* PATH UTILISE : ../Paths/custom_paths/short_path_tls.path
|
||||||
*/
|
*/
|
||||||
public void chemin_court_TLS() {
|
public void chemin_court_TLS() {
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||||
|
@ -209,30 +193,39 @@ public class DijkstraAlgorithmTest {
|
||||||
ShortestPathSolution bell_path = bellman.doRun();
|
ShortestPathSolution bell_path = bellman.doRun();
|
||||||
|
|
||||||
assert(dijk_path.getPath().isValid());
|
assert(dijk_path.getPath().isValid());
|
||||||
|
assert(dijk_path.isFeasible());
|
||||||
|
assert(Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength()) < 1.0);
|
||||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
/*
|
/*
|
||||||
* Chemin long sur la carte de Toulouse.
|
* Chemin long sur la carte de Toulouse.
|
||||||
* Comme Bellman est long à faire, on utilise un chemin déjà construit qu'on
|
* Même si Bellman est de plus long à faire long à faire, ce test prend moins
|
||||||
* importe via la fonction init. Ce chemin a été obtenu par Bellman mais une seule fois.
|
* de 3s, on estime que ce n'est pas trop et on va utiliser Bellman.
|
||||||
* Sinon, on peut trouver d'autres techniques pour se rassurer sur le chemin obtenue comme:
|
* Par contre, dans le test sur la région midi_pyrenees qui arrive après, on va
|
||||||
* -vérifier certains noeuds comme départ, destination, noeud pivot.
|
* être obligé de trouver une autre solution.
|
||||||
* -vérifier le cout avec une estimation gentille.
|
* Origine: 16644
|
||||||
* -etc.
|
* Destination: 39229
|
||||||
|
* PATH UTILISE : ../Paths/custom_paths/long_path_tls.path
|
||||||
*/
|
*/
|
||||||
public void chemin_long_TLS() {
|
public void chemin_long_TLS() {
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||||
Graph myGraph = graph.get(2);
|
Graph myGraph = graph.get(2);
|
||||||
Path myPath = path.get(1);
|
Node origin = myGraph.get(16644);
|
||||||
ShortestPathData data = new ShortestPathData(myGraph, myPath.getOrigin(), myPath.getDestination(), arcInspector);
|
Node destination = myGraph.get(39229);
|
||||||
|
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||||
|
|
||||||
|
BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data);
|
||||||
|
ShortestPathSolution bell_path = bellman.doRun();
|
||||||
|
|
||||||
assert(dijk_path.getPath().isValid());
|
assert(dijk_path.getPath().isValid());
|
||||||
assert(Math.abs(dijk_path.getPath().getLength() - myPath.getLength()) < 1.0);
|
assert(dijk_path.isFeasible());
|
||||||
|
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength()) < 1.0));
|
||||||
|
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < (bell_path.getPath().getLength() ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -242,6 +235,9 @@ public class DijkstraAlgorithmTest {
|
||||||
* Ce chemin est donc censé être utilisable en vélo mais pas en voiture.
|
* Ce chemin est donc censé être utilisable en vélo mais pas en voiture.
|
||||||
* Avec le filtre vélos, on obtient pas de chemin.
|
* Avec le filtre vélos, on obtient pas de chemin.
|
||||||
* Avec le filtre voitures on obtient un chemin.
|
* Avec le filtre voitures on obtient un chemin.
|
||||||
|
* Origine: 19135
|
||||||
|
* Destination: 1980
|
||||||
|
* PATH UTILISE : ../Paths/custom_paths/path_cyclist.path
|
||||||
*/
|
*/
|
||||||
public void chemin_velo_uniquement() {
|
public void chemin_velo_uniquement() {
|
||||||
// Filter: forBicyclesCustomT
|
// Filter: forBicyclesCustomT
|
||||||
|
@ -250,11 +246,15 @@ public class DijkstraAlgorithmTest {
|
||||||
Graph myGraph = graph.get(2);
|
Graph myGraph = graph.get(2);
|
||||||
Node origin = myGraph.get(19135);
|
Node origin = myGraph.get(19135);
|
||||||
Node destination = myGraph.get(1980);
|
Node destination = myGraph.get(1980);
|
||||||
|
|
||||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra_bicycle = new DijkstraAlgorithm(data);
|
DijkstraAlgorithm dijkstra_bicycle = new DijkstraAlgorithm(data);
|
||||||
ShortestPathSolution dijk_path_bicycle = dijkstra_bicycle.doRun();
|
ShortestPathSolution dijk_path_bicycle = dijkstra_bicycle.doRun();
|
||||||
|
|
||||||
|
BellmanFordAlgorithm bellman_bicycle = new BellmanFordAlgorithm(data);
|
||||||
|
ShortestPathSolution bell_path_bicycle = bellman_bicycle.doRun();
|
||||||
|
|
||||||
// Filter: forCarsL
|
// Filter: forCarsL
|
||||||
ArcInspector new_Inspector = ArcInspectorFactory.getAllFilters().get(1);
|
ArcInspector new_Inspector = ArcInspectorFactory.getAllFilters().get(1);
|
||||||
data = new ShortestPathData(myGraph, origin, destination, new_Inspector);
|
data = new ShortestPathData(myGraph, origin, destination, new_Inspector);
|
||||||
|
@ -263,24 +263,43 @@ public class DijkstraAlgorithmTest {
|
||||||
ShortestPathSolution dijk_path_car = dijkstra_car.doRun();
|
ShortestPathSolution dijk_path_car = dijkstra_car.doRun();
|
||||||
|
|
||||||
assertEquals(dijk_path_bicycle.getPath(), null);
|
assertEquals(dijk_path_bicycle.getPath(), null);
|
||||||
|
assert(!dijk_path_bicycle.isFeasible());
|
||||||
|
assertEquals(bell_path_bicycle.getPath(), null);
|
||||||
|
assert(!bell_path_bicycle.isFeasible());
|
||||||
|
|
||||||
assert(dijk_path_car.getPath() != null);
|
assert(dijk_path_car.getPath() != null);
|
||||||
|
assert(dijk_path_car.isFeasible());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
/*
|
/*
|
||||||
* Cette fois-ci, Bellman est trop long à utiliser même une seule fois.
|
* Cette fois-ci, Bellman est trop long à utiliser même une seule fois.
|
||||||
* On va donc utiliser quelques techniques pour se rassurer.
|
* On va donc utiliser quelques techniques pour se rassurer.
|
||||||
|
* -vérifier certains noeuds comme départ, destination, noeud pivot.
|
||||||
|
* -vérifier le cout avec une estimation gentille.
|
||||||
|
* -etc.
|
||||||
|
* Origin: 279654
|
||||||
|
* Destination: 481936
|
||||||
|
* PATH UTILISE : ../Paths/custom_paths/long_chemin_midi_pyrenees.path
|
||||||
*/
|
*/
|
||||||
public void chemin_long_Midi_pyrenees() {
|
public void chemin_long_Midi_pyrenees() {
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||||
Graph myGraph = graph.get(3);
|
Graph myGraph = graph.get(3);
|
||||||
Path myPath = path.get(0);
|
Node origin = myGraph.get(279654);
|
||||||
ShortestPathData data = new ShortestPathData(myGraph, myPath.getOrigin(), myPath.getDestination(), arcInspector);
|
Node destination = myGraph.get(481936);
|
||||||
|
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||||
|
|
||||||
|
|
||||||
assert(dijk_path.getPath().isValid());
|
assert(dijk_path.getPath().isValid());
|
||||||
assert(Math.abs(dijk_path.getPath().getLength() - myPath.getLength()) < 1.0);
|
assert(dijk_path.isFeasible());
|
||||||
|
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength())) < 1000.0);
|
||||||
|
// Selon le chemin sélectionné on peut avoir une estimation de la longueur qu'on est censée avoir.
|
||||||
|
// Avec notre long chemin: entre 250 et 260 kilomètres.
|
||||||
|
assert(dijkstra.getCostPath() > 250000 && dijkstra.getCostPath() < 260000);
|
||||||
|
// On peut aussi supposer que le nombre d'arcs empruntés est très grand.
|
||||||
|
assert(dijk_path.getPath().getArcs().size() > 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue