Compare commits
No commits in common. "3f7a1543fd82b7a80d520f026d91954d8bf340ac" and "a5b553e712fb0f7d1be49d0535512d558ee90a60" have entirely different histories.
3f7a1543fd
...
a5b553e712
1 changed files with 133 additions and 154 deletions
|
|
@ -40,9 +40,7 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
static ArrayList<String> Maps = new ArrayList<String>(Arrays.asList("../Maps/carre.mapgr",
|
||||
"../Maps/insa.mapgr",
|
||||
"../Maps/toulouse.mapgr",
|
||||
"../Maps/midi-pyrenees.mapgr",
|
||||
"../Maps/belgium.mapgr"
|
||||
));
|
||||
"../Maps/midi-pyrenees.mapgr"));
|
||||
|
||||
@BeforeClass
|
||||
/*
|
||||
|
|
@ -121,7 +119,7 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Realizes n tests with the given graph informations.
|
||||
* The n tests all use random origin and destination nodes id.
|
||||
* The outputs of the tests are compared with the algorithm Bellman.
|
||||
|
|
@ -150,90 +148,6 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
assert(path.getPath() == null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Cette fois-ci, Bellman est trop long à utiliser un grand nombre de fois.
|
||||
* On va donc utiliser quelques techniques pour se rassurer:
|
||||
* -Le cout en distance est au moins la distance à vol d'oiseau entre les noeuds.
|
||||
* -les sous-chemins d'un PCC sont des PCC. Sachant cela, on doit être sur
|
||||
* qu'en appliquant un second Dijkstra sur 2 noeuds aléatoires dans le path
|
||||
* renvoyé par le premier Dijkstra (hors origine et destination), on
|
||||
* obtient :
|
||||
* -un plus court chemin qui est le même que le sous chemin relevé (sous PCC).
|
||||
* -un plus court chemin de coût inférieur au chemin (premier dijkstra) dont il a été extrait.
|
||||
* On teste 'nbrePCC' PCC et 'nbreSousPCC' sous PCC.
|
||||
*/
|
||||
public void TestsCheminsTropLongs(Graph graph, Node origin, Node destination, ArcInspector arcFilter, int nbrePCC, int nbreSousPCC) {
|
||||
int longueur_path = 0;
|
||||
Node noeudSelectionneOrigine = graph.get(0);
|
||||
Node noeudSelectionneDestination = graph.get(0);
|
||||
int size_graph = graph.size();
|
||||
|
||||
for (int i = 0 ; i < nbrePCC ; i++) {
|
||||
origin = graph.get(Math.abs(rand.nextInt()) % size_graph);
|
||||
destination = graph.get(Math.abs(rand.nextInt()) % size_graph);
|
||||
|
||||
ShortestPathData data = new ShortestPathData(graph, origin, destination, arcFilter);
|
||||
|
||||
final ShortestPathAlgorithm algo = initAlgo(data);
|
||||
final ShortestPathSolution path = algo.doRun();
|
||||
|
||||
if (path.getPath() != null) {
|
||||
assert(path.getPath().isValid());
|
||||
assert(path.isFeasible());
|
||||
double distanceFromOriginToDestination = 0;
|
||||
if (data.getMode() == Mode.LENGTH) {
|
||||
assert((Math.abs(algo.getCostPath() - path.getPath().getLength())) < 1);
|
||||
distanceFromOriginToDestination = Point.distance(origin.getPoint(), destination.getPoint());
|
||||
}
|
||||
else {
|
||||
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime())) < 1);
|
||||
distanceFromOriginToDestination = Point.distance(origin.getPoint(), destination.getPoint()) / (1000 * graph.getGraphInformation().getMaximumSpeed());
|
||||
}
|
||||
|
||||
|
||||
// Distance trouvée supérieure ou égale (improbable voire impossible) au chemin à vol d'oiseau.
|
||||
assert(distanceFromOriginToDestination <= algo.getCostPath());
|
||||
|
||||
for (int j = 0; j < nbreSousPCC ; j++) {
|
||||
longueur_path = path.getPath().size();
|
||||
int milieu_path = longueur_path / 2;
|
||||
|
||||
int indiceOrigine = Math.abs(rand.nextInt()) % milieu_path;
|
||||
int indiceDestination = milieu_path + Math.abs(rand.nextInt()) % milieu_path - 1;
|
||||
|
||||
noeudSelectionneOrigine = path.getPath().getArcs().get(indiceOrigine).getOrigin();
|
||||
|
||||
noeudSelectionneDestination = path.getPath().getArcs().get(indiceDestination).getOrigin();
|
||||
|
||||
ShortestPathData dataSousPCC = new ShortestPathData(graph, noeudSelectionneOrigine, noeudSelectionneDestination, arcFilter);
|
||||
|
||||
final ShortestPathAlgorithm algoSousPCC = initAlgo(dataSousPCC);
|
||||
final ShortestPathSolution pathSousPCC = algoSousPCC.doRun();
|
||||
|
||||
if (path.getPath() != null) {
|
||||
// Note: comme les chemins des arcs sont récupérés au même en droit entre pathSousPCC et path,
|
||||
// on peut comparer directement les objets soit leurs adresses. Sinon, il aurait fallu comparer
|
||||
// l'id des noeuds origines et destination du chemin.
|
||||
for (int k = 0 ; k < pathSousPCC.getPath().size()-1; k++) {
|
||||
assert(pathSousPCC.getPath().getArcs().get(k) == path.getPath().getArcs().get(indiceOrigine + k));
|
||||
}
|
||||
assert(pathSousPCC.getPath().isValid());
|
||||
assert(pathSousPCC.isFeasible());
|
||||
if (data.getMode() == Mode.LENGTH) {
|
||||
assert((Math.abs(algoSousPCC.getCostPath() - pathSousPCC.getPath().getLength())) < 1.0);
|
||||
}
|
||||
else {
|
||||
assert((Math.abs(algoSousPCC.getCostPath() - pathSousPCC.getPath().getMinimumTravelTime())) < 1.0);
|
||||
}
|
||||
|
||||
// sous PCC de coût inférieur au PCC
|
||||
assert(algoSousPCC.getCostPath() <= algo.getCostPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
/*
|
||||
|
|
@ -338,7 +252,7 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
nTestsWithBellman(myGraph, origin, destination, arcInspector, size_graph, 2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
/*
|
||||
* Permet de tester les chemins moyennement longs en distance (0 - 30 km).
|
||||
* On teste 100 chemins sur la carte de Toulouse (environ 1 min d'exécution)
|
||||
|
|
@ -360,7 +274,7 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
nTestsWithBellman(myGraph, origin, destination, arcInspector, size_graph, 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
/*
|
||||
* Permet de tester les chemins moyennement longs en temps (0 - 2h).
|
||||
* On teste 100 chemins sur la carte de Toulouse (environ 1 min d'exécution)
|
||||
|
|
@ -368,7 +282,7 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
* graphe, ce test prend moins d'une minute donc on va quand même utiliser Bellman.
|
||||
* Par contre, dans le test sur la région midi_pyrenees / France qui arrive après,
|
||||
* on va être obligé de trouver une autre solution (principale difficulté).
|
||||
* Mode: TIME
|
||||
* Mode: LENGTH
|
||||
* Carte utilisée : ../Maps/toulouse.mapgr
|
||||
*/
|
||||
public void cheminsToulouseTIME() {
|
||||
|
|
@ -384,7 +298,7 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
|
||||
@Test
|
||||
/*
|
||||
* On veut vérifier le bon fonctionnement des modes TIME et LENGTH.
|
||||
* On veut vérifier le bon fonctionnement des modes TIME et LENGTH.
|
||||
* On va faire 100 tests pour vérifier le bon fonctionnement sur la carte
|
||||
* de Toulouse
|
||||
* Pour cela, on va obtenir deux chemins avec l'algo de algo et vérifier
|
||||
|
|
@ -439,14 +353,15 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
|
||||
@Test
|
||||
/*
|
||||
* Le principe du test est celui utilisé dans la méthode TestsCheminsTropLongues:
|
||||
* -On fait plusieurs PCC et pour chacun on extrait plusieurs chemins des PCC
|
||||
* et on s'assure que c'est un PCC en refaisant notre algo de l'origine à la
|
||||
* destination du chemin extrait. Les chemins extraits et sousPCC obtenus doivent
|
||||
* être les mêmes.
|
||||
* Entres autres, on vérifie aussi que les PCC sont de distance supérieures
|
||||
* aux distances à vol d'oiseau et que les sousPCC sont de longueur
|
||||
* inférieures aux PCC.
|
||||
* Cette fois-ci, Bellman est trop long à utiliser un grand nombre de fois.
|
||||
* On va donc utiliser quelques techniques pour se rassurer:
|
||||
* -Le cout en distance est au moins la distance à vol d'oiseau entre les noeuds.
|
||||
* -les sous-chemins d'un PCC sont des PCC. Sachant cela, on doit être sur
|
||||
* qu'en appliquant un second Dijkstra sur 2 noeuds aléatoires dans le path
|
||||
* renvoyé par le premier Dijkstra (hors origine et destination), on
|
||||
* obtient :
|
||||
* -un plus court chemin qui est le même que le sous chemin relevé (sous PCC).
|
||||
* -un plus court chemin de coût inférieur au chemin dont il a été extrait.
|
||||
* On teste 10 PCC et pour chaque PCC 25 sous PCC
|
||||
* Mode: LENGTH
|
||||
* Carte utilisée : ../Maps/midi_pyrenees.mapgr
|
||||
|
|
@ -456,20 +371,76 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||
Node origin = myGraph.get(0);
|
||||
Node destination = myGraph.get(0);
|
||||
int size_graph = myGraph.size();
|
||||
int longueur_path = 0;
|
||||
Node noeudSelectionneOrigine = myGraph.get(0);
|
||||
Node noeudSelectionneDestination = myGraph.get(0);
|
||||
|
||||
for (int i = 0 ; i < 10 ; i++) {
|
||||
origin = myGraph.get(Math.abs(rand.nextInt()) % size_graph);
|
||||
destination = myGraph.get(Math.abs(rand.nextInt()) % size_graph);
|
||||
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
TestsCheminsTropLongs(myGraph, origin, destination, arcInspector, 10, 25);
|
||||
final ShortestPathAlgorithm algo = initAlgo(data);
|
||||
final ShortestPathSolution path = algo.doRun();
|
||||
|
||||
if (path.getPath() != null) {
|
||||
assert(path.getPath().isValid());
|
||||
assert(path.isFeasible());
|
||||
assert((Math.abs(algo.getCostPath() - path.getPath().getLength())) < 1.0);
|
||||
|
||||
double distanceFromOriginToDestination = Point.distance(origin.getPoint(), destination.getPoint());
|
||||
|
||||
// Distance trouvée supérieure ou égale (improbable voire impossible) au chemin à vol d'oiseau.
|
||||
assert(distanceFromOriginToDestination <= algo.getCostPath());
|
||||
|
||||
for (int j = 0; j < 25 ; j++) {
|
||||
longueur_path = path.getPath().size();
|
||||
int milieu_path = longueur_path / 2;
|
||||
|
||||
int indiceOrigine = Math.abs(rand.nextInt()) % milieu_path;
|
||||
int indiceDestination = milieu_path + Math.abs(rand.nextInt()) % milieu_path - 1;
|
||||
|
||||
noeudSelectionneOrigine = path.getPath().getArcs().get(indiceOrigine).getOrigin();
|
||||
|
||||
noeudSelectionneDestination = path.getPath().getArcs().get(indiceDestination).getOrigin();
|
||||
|
||||
ShortestPathData dataSousPCC = new ShortestPathData(myGraph, noeudSelectionneOrigine, noeudSelectionneDestination, arcInspector);
|
||||
|
||||
final ShortestPathAlgorithm algoSousPCC = initAlgo(dataSousPCC);
|
||||
final ShortestPathSolution pathSousPCC = algoSousPCC.doRun();
|
||||
|
||||
if (path.getPath() != null) {
|
||||
// Note: comme les chemins des arcs sont récupérés au même en droit entre pathSousPCC et path,
|
||||
// on peut comparer directement les objets soit leurs adresses. Sinon, il aurait fallu comparer
|
||||
// l'id des noeuds origines et destination du chemin.
|
||||
for (int k = 0 ; k < pathSousPCC.getPath().size()-1; k++) {
|
||||
assert(pathSousPCC.getPath().getArcs().get(k) == path.getPath().getArcs().get(indiceOrigine + k));
|
||||
}
|
||||
assert(pathSousPCC.getPath().isValid());
|
||||
assert(pathSousPCC.isFeasible());
|
||||
assert((Math.abs(algoSousPCC.getCostPath() - pathSousPCC.getPath().getLength())) < 1.0);
|
||||
|
||||
// sous PCC de coût inférieur au PCC
|
||||
assert(algoSousPCC.getCostPath() <= algo.getCostPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
/*
|
||||
* Le principe du test est celui utilisé dans la méthode TestsCheminsTropLongues:
|
||||
* -On fait plusieurs PCC et pour chacun on extrait plusieurs chemins des PCC
|
||||
* et on s'assure que c'est un PCC en refaisant notre algo de l'origine à la
|
||||
* destination du chemin extrait. Les chemins extraits et sousPCC obtenus doivent
|
||||
* être les mêmes.
|
||||
* Entres autres, on vérifie aussi que les PCC sont de distance supérieures
|
||||
* aux distances à vol d'oiseau et que les sousPCC sont de longueur
|
||||
* inférieures aux PCC.
|
||||
* Cette fois-ci, Bellman est trop long à utiliser un grand nombre de fois.
|
||||
* On va donc utiliser quelques techniques pour se rassurer:
|
||||
* -Le temps mis est plus grand que le temps à vitesse maximale permise.
|
||||
* -les sous-chemins d'un PCC sont des PCC. Sachant cela, on doit être sur
|
||||
* qu'en appliquant un second Dijkstra sur 2 noeuds aléatoires dans le path
|
||||
* renvoyé par le premier Dijkstra (hors origine et destination), on
|
||||
* obtient :
|
||||
* -un plus court chemin qui est le même que le sous chemin relevé.
|
||||
* -un plus court chemin de coût inférieur au chemin dont il a été extrait.
|
||||
* On teste 10 PCC et pour chaque PCC 25 sous PCC
|
||||
* Mode: TIME
|
||||
* Carte utilisée : ../Maps/midi_pyrenees.mapgr
|
||||
|
|
@ -479,54 +450,62 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(2);
|
||||
Node origin = myGraph.get(0);
|
||||
Node destination = myGraph.get(0);
|
||||
|
||||
TestsCheminsTropLongs(myGraph, origin, destination, arcInspector, 10, 25);
|
||||
}
|
||||
int size_graph = myGraph.size();
|
||||
int longueur_path = 0;
|
||||
Node noeudSelectionneOrigine;
|
||||
Node noeudSelectionneDestination;
|
||||
|
||||
@Test
|
||||
/*
|
||||
* Le principe du test est celui utilisé dans la méthode TestsCheminsTropLongues:
|
||||
* -On fait plusieurs PCC et pour chacun on extrait plusieurs chemins des PCC
|
||||
* et on s'assure que c'est un PCC en refaisant notre algo de l'origine à la
|
||||
* destination du chemin extrait. Les chemins extraits et sousPCC obtenus doivent
|
||||
* être les mêmes.
|
||||
* Entres autres, on vérifie aussi que les PCC sont de distance supérieures
|
||||
* aux distances à vol d'oiseau et que les sousPCC sont de longueur
|
||||
* inférieures aux PCC.
|
||||
* On teste 10 PCC et pour chaque PCC 25 sous PCC
|
||||
* Mode: TIME
|
||||
* Carte utilisée : ../Maps/belgium.mapgr
|
||||
*/
|
||||
public void cheminBelgiqueLENGTH() {
|
||||
Graph myGraph = graph.get(4);
|
||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||
Node origin = myGraph.get(0);
|
||||
Node destination = myGraph.get(0);
|
||||
for (int i = 0 ; i < 10 ; i++) {
|
||||
origin = myGraph.get(Math.abs(rand.nextInt()) % size_graph);
|
||||
destination = myGraph.get(Math.abs(rand.nextInt()) % size_graph);
|
||||
|
||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
||||
|
||||
TestsCheminsTropLongs(myGraph, origin, destination, arcInspector, 10, 25);
|
||||
}
|
||||
final ShortestPathAlgorithm algo = initAlgo(data);
|
||||
final ShortestPathSolution path = algo.doRun();
|
||||
|
||||
@Test
|
||||
/*
|
||||
* Le principe du test est celui utilisé dans la méthode TestsCheminsTropLongues:
|
||||
* -On fait plusieurs PCC et pour chacun on extrait plusieurs chemins des PCC
|
||||
* et on s'assure que c'est un PCC en refaisant notre algo de l'origine à la
|
||||
* destination du chemin extrait. Les chemins extraits et sousPCC obtenus doivent
|
||||
* être les mêmes.
|
||||
* Entres autres, on vérifie aussi que les PCC sont de distance supérieures
|
||||
* aux distances à vol d'oiseau et que les sousPCC sont de longueur
|
||||
* inférieures aux PCC.
|
||||
* On teste 10 PCC et pour chaque PCC 25 sous PCC
|
||||
* Mode: TIME
|
||||
* Carte utilisée : ../Maps/belgium.mapgr
|
||||
*/
|
||||
public void cheminBelgiqueTIME() {
|
||||
Graph myGraph = graph.get(4);
|
||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(2);
|
||||
Node origin = myGraph.get(0);
|
||||
Node destination = myGraph.get(0);
|
||||
|
||||
TestsCheminsTropLongs(myGraph, origin, destination, arcInspector, 10, 25);
|
||||
if (path.getPath() != null) {
|
||||
assert(path.getPath().isValid());
|
||||
assert(path.isFeasible());
|
||||
assert((Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime())) < 10.0);
|
||||
|
||||
double tempsFromOriginToDestination = Point.distance(origin.getPoint(), destination.getPoint()) / (1000 * data.getGraph().getGraphInformation().getMaximumSpeed());
|
||||
|
||||
// Temps supérieur ou égal (improbable voire impossible) au chemin à vol d'oiseau à la vitesse maximale.
|
||||
assert(tempsFromOriginToDestination <= algo.getCostPath());
|
||||
|
||||
for (int j = 0; j < 25 ; j++) {
|
||||
longueur_path = path.getPath().size();
|
||||
int milieu_path = longueur_path / 2;
|
||||
|
||||
int indiceOrigine = Math.abs(rand.nextInt()) % milieu_path;
|
||||
int indiceDestination = milieu_path + Math.abs(rand.nextInt()) % milieu_path - 1;
|
||||
|
||||
noeudSelectionneOrigine = path.getPath().getArcs().get(indiceOrigine).getOrigin();
|
||||
noeudSelectionneDestination = path.getPath().getArcs().get(indiceDestination).getOrigin();
|
||||
|
||||
ShortestPathData dataSousPCC = new ShortestPathData(myGraph, noeudSelectionneOrigine, noeudSelectionneDestination, arcInspector);
|
||||
|
||||
final ShortestPathAlgorithm algoSousPCC = initAlgo(dataSousPCC);
|
||||
final ShortestPathSolution pathSousPCC = algoSousPCC.doRun();
|
||||
|
||||
if (path.getPath() != null) {
|
||||
// Note: comme les chemins des arcs sont récupérés au même en droit entre pathSousPCC et path,
|
||||
// on peut comparer directement les objets soit leurs adresses. Sinon, il aurait fallu comparer
|
||||
// l'id des noeuds origines et destination du chemin.
|
||||
for (int k = 0 ; k < pathSousPCC.getPath().size()-1; k++) {
|
||||
assert(pathSousPCC.getPath().getArcs().get(k) == path.getPath().getArcs().get(indiceOrigine + k));
|
||||
}
|
||||
assert(pathSousPCC.getPath().isValid());
|
||||
assert(pathSousPCC.isFeasible());
|
||||
assert((Math.abs(algoSousPCC.getCostPath() - pathSousPCC.getPath().getMinimumTravelTime())) < 1.0);
|
||||
|
||||
// sous PCC de coût inférieur au PCC
|
||||
assert(algoSousPCC.getCostPath() <= algo.getCostPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue