Compare commits
No commits in common. "c60efbc5a51631aa417d0e51a24af0dc72801f80" and "86b860f9a393424108f2150fb6923c987c321232" have entirely different histories.
c60efbc5a5
...
86b860f9a3
7 changed files with 15 additions and 136 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -16,4 +16,5 @@ doc
|
||||||
# Project specific files and folders
|
# Project specific files and folders
|
||||||
*.mapfg
|
*.mapfg
|
||||||
*.mapgr
|
*.mapgr
|
||||||
|
*.path
|
||||||
*.tgz
|
*.tgz
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -12,8 +12,6 @@ import org.insa.graphs.model.Path;
|
||||||
|
|
||||||
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
private float pathCost;
|
|
||||||
|
|
||||||
public DijkstraAlgorithm(ShortestPathData data) {
|
public DijkstraAlgorithm(ShortestPathData data) {
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +32,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
// List of sommets, but with type Label
|
// List of sommets, but with type Label
|
||||||
ArrayList<Label> labels = new ArrayList<Label>(nbNodes);
|
ArrayList<Label> labels = new ArrayList<Label>(nbNodes);
|
||||||
|
|
||||||
// Heap of sommets
|
// Heap of sommets
|
||||||
BinaryHeap<Label> tas = new BinaryHeap<Label>();
|
BinaryHeap<Label> tas = new BinaryHeap<Label>();
|
||||||
|
|
||||||
|
|
@ -74,7 +71,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
// we know its origin and destination
|
// we know its origin and destination
|
||||||
for (Arc arc : x.getNode().getSuccessors()) {
|
for (Arc arc : x.getNode().getSuccessors()) {
|
||||||
if (successor.getNode().equals(arc.getDestination())) {
|
if (successor.getNode().equals(arc.getDestination())) {
|
||||||
arc_cost = (float) data.getCost(arc);
|
arc_cost = arc.getLength();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final float possible_path_cost = x.getCost() + arc_cost;
|
final float possible_path_cost = x.getCost() + arc_cost;
|
||||||
|
|
@ -100,7 +97,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (labels.get(data.getDestination().getId()).getParentNode() == null) {
|
if (labels.get(data.getDestination().getId()).getParentNode() == null) {
|
||||||
this.pathCost = 0;
|
|
||||||
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
|
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -132,18 +128,15 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
notifyDestinationReached(data.getDestination());
|
notifyDestinationReached(data.getDestination());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Reverse the path...
|
// Reverse the path...
|
||||||
Collections.reverse(arcs_path);
|
Collections.reverse(arcs_path);
|
||||||
|
|
||||||
// Create the final solution.
|
// Create the final solution.
|
||||||
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(graph, arcs_path));
|
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(graph, arcs_path));
|
||||||
|
|
||||||
this.pathCost = labels.get(data.getDestination().getId()).getCost();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return solution;
|
return solution;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getCostPath() {
|
|
||||||
return this.pathCost;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,22 +71,20 @@ public class DijkstraAlgorithmTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
/* Stratégie:
|
/* Stratégie:
|
||||||
* Chemins courts testés par comparaison avec Bellman.
|
* Chemins courts testés par comparaison avec Bellman.
|
||||||
* Chemin longs testés par comparaison avec chemins déjà construits. Bellman trop long.
|
* Chemin longs testés par comparaison avec chemins déjà construits. Bellman trop long.
|
||||||
*/
|
*/
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
@Test
|
|
||||||
/*
|
/*
|
||||||
* Map: carre.mapgr
|
* Map: carre.mapgr
|
||||||
* Chemin: 19 --> 4
|
* Chemin: 19 --> 4
|
||||||
* Tous chemins permis
|
* Tous chemins permis
|
||||||
* Mode: LENGTH
|
|
||||||
* PATH UTILISE : ../Paths/custom_paths/short_path_carre.path
|
* PATH UTILISE : ../Paths/custom_paths/short_path_carre.path
|
||||||
*/
|
*/
|
||||||
public void chemin_court_CARRE_length() {
|
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);
|
||||||
Node origin = myGraph.get(19);
|
Node origin = myGraph.get(19);
|
||||||
|
|
@ -112,7 +110,7 @@ public class DijkstraAlgorithmTest {
|
||||||
* Tous chemins permis
|
* Tous chemins permis
|
||||||
* PATH UTILISE : ../Paths/custom_paths/long_path_carre.path
|
* PATH UTILISE : ../Paths/custom_paths/long_path_carre.path
|
||||||
*/
|
*/
|
||||||
public void chemin_long_CARRE_length() {
|
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);
|
||||||
|
|
@ -132,7 +130,6 @@ public class DijkstraAlgorithmTest {
|
||||||
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 nul sur carte carrée.
|
* Chemin nul sur carte carrée.
|
||||||
|
|
@ -210,10 +207,9 @@ public class DijkstraAlgorithmTest {
|
||||||
* être obligé de trouver une autre solution.
|
* être obligé de trouver une autre solution.
|
||||||
* Origine: 16644
|
* Origine: 16644
|
||||||
* Destination: 39229
|
* Destination: 39229
|
||||||
* Mode: LENGTH
|
|
||||||
* PATH UTILISE : ../Paths/custom_paths/long_path_tls.path
|
* PATH UTILISE : ../Paths/custom_paths/long_path_tls.path
|
||||||
*/
|
*/
|
||||||
public void chemin_long_TLS_length() {
|
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);
|
||||||
Node origin = myGraph.get(16644);
|
Node origin = myGraph.get(16644);
|
||||||
|
|
@ -229,39 +225,7 @@ public class DijkstraAlgorithmTest {
|
||||||
assert(dijk_path.getPath().isValid());
|
assert(dijk_path.getPath().isValid());
|
||||||
assert(dijk_path.isFeasible());
|
assert(dijk_path.isFeasible());
|
||||||
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength()) < 1.0));
|
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength()) < 1.0));
|
||||||
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < 10.0);
|
assert(Math.abs(dijk_path.getPath().getLength() - bell_path.getPath().getLength()) < (bell_path.getPath().getLength() ));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
/*
|
|
||||||
* Chemin long sur la carte de Toulouse.
|
|
||||||
* Même si Bellman est de plus long à faire long à faire, ce test prend moins
|
|
||||||
* de 3s, on estime que ce n'est pas trop et on va utiliser Bellman.
|
|
||||||
* Par contre, dans le test sur la région midi_pyrenees qui arrive après, on va
|
|
||||||
* être obligé de trouver une autre solution.
|
|
||||||
* Origine: 16644
|
|
||||||
* Destination: 39229
|
|
||||||
* Mode: TIME
|
|
||||||
* PATH UTILISE : ../Paths/custom_paths/long_path_tls.path
|
|
||||||
*/
|
|
||||||
public void chemin_long_TLS_time() {
|
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(2);
|
|
||||||
Graph myGraph = graph.get(2);
|
|
||||||
Node origin = myGraph.get(16644);
|
|
||||||
Node destination = myGraph.get(39229);
|
|
||||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
|
||||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
|
||||||
|
|
||||||
BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data);
|
|
||||||
ShortestPathSolution bell_path = bellman.doRun();
|
|
||||||
|
|
||||||
assert(dijk_path.getPath().isValid());
|
|
||||||
assert(dijk_path.isFeasible());
|
|
||||||
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getMinimumTravelTime()) < 1.0));
|
|
||||||
assert(Math.abs(dijk_path.getPath().getMinimumTravelTime() - bell_path.getPath().getMinimumTravelTime()) < 10.0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -307,50 +271,6 @@ public class DijkstraAlgorithmTest {
|
||||||
assert(dijk_path_car.isFeasible());
|
assert(dijk_path_car.isFeasible());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
/*
|
|
||||||
* On veut vérifier le bon fonctionnement des modes TIME et LENGTH.
|
|
||||||
* Pour cela, on va obtenir deux chemins avec l'algo de Dijkstra et vérifier
|
|
||||||
* que:
|
|
||||||
* -le chemin TIME est plus rapide en durée que le chemin LENGTH
|
|
||||||
* -le chemin LENGTH est plus court en distance que le chemin LENGTH.
|
|
||||||
* On prend un grand chemin pour être sur d'avoir une différence :
|
|
||||||
* Origine: 16644
|
|
||||||
* Destination: 39229
|
|
||||||
* Mode: TIME/LENGTH
|
|
||||||
* PATH UTILISE : ../Paths/custom_paths/long_path_tls.path
|
|
||||||
*/
|
|
||||||
public void chemin_time_length_comparison() {
|
|
||||||
Graph myGraph = graph.get(2);
|
|
||||||
Node origin = myGraph.get(19135);
|
|
||||||
Node destination = myGraph.get(1980);
|
|
||||||
|
|
||||||
// Filter: forCarsL
|
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(1);
|
|
||||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra_L = new DijkstraAlgorithm(data);
|
|
||||||
ShortestPathSolution dijk_path_L = dijkstra_L.doRun();
|
|
||||||
|
|
||||||
// Filter: forCarsT
|
|
||||||
ArcInspector new_Inspector = ArcInspectorFactory.getAllFilters().get(2);
|
|
||||||
data = new ShortestPathData(myGraph, origin, destination, new_Inspector);
|
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra_T = new DijkstraAlgorithm(data);
|
|
||||||
ShortestPathSolution dijk_path_T = dijkstra_T.doRun();
|
|
||||||
|
|
||||||
assert(dijk_path_L.getPath().isValid());
|
|
||||||
assert(dijk_path_L.isFeasible());
|
|
||||||
assert(dijk_path_T.getPath().isValid());
|
|
||||||
assert(dijk_path_T.isFeasible());
|
|
||||||
|
|
||||||
assert((Math.abs(dijkstra_L.getCostPath() - dijk_path_L.getPath().getLength()) < 1.0));
|
|
||||||
assert((Math.abs(dijkstra_T.getCostPath() - dijk_path_T.getPath().getMinimumTravelTime()) < 1.0));
|
|
||||||
|
|
||||||
assert(dijk_path_L.getPath().getLength() < dijk_path_T.getPath().getLength());
|
|
||||||
assert(dijk_path_L.getPath().getMinimumTravelTime() > dijk_path_T.getPath().getMinimumTravelTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
@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.
|
||||||
|
|
@ -360,10 +280,9 @@ public class DijkstraAlgorithmTest {
|
||||||
* -etc.
|
* -etc.
|
||||||
* Origin: 279654
|
* Origin: 279654
|
||||||
* Destination: 481936
|
* Destination: 481936
|
||||||
* Mode: LENGTH
|
|
||||||
* PATH UTILISE : ../Paths/custom_paths/long_chemin_midi_pyrenees.path
|
* PATH UTILISE : ../Paths/custom_paths/long_chemin_midi_pyrenees.path
|
||||||
*/
|
*/
|
||||||
public void chemin_long_Midi_pyrenees_length() {
|
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);
|
||||||
Node origin = myGraph.get(279654);
|
Node origin = myGraph.get(279654);
|
||||||
|
|
@ -373,10 +292,9 @@ 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.getPath().isValid());
|
assert(dijk_path.getPath().isValid());
|
||||||
assert(dijk_path.isFeasible());
|
assert(dijk_path.isFeasible());
|
||||||
// On a des erreurs d'arrondi assez grande avec la distance, mais elles sont mineures
|
|
||||||
// relativement aux distance de 300000 ici.
|
|
||||||
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getLength())) < 1000.0);
|
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.
|
// 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.
|
// Avec notre long chemin: entre 250 et 260 kilomètres.
|
||||||
|
|
@ -384,37 +302,4 @@ public class DijkstraAlgorithmTest {
|
||||||
// On peut aussi supposer que le nombre d'arcs empruntés est très grand.
|
// On peut aussi supposer que le nombre d'arcs empruntés est très grand.
|
||||||
assert(dijk_path.getPath().getArcs().size() > 1000);
|
assert(dijk_path.getPath().getArcs().size() > 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
/*
|
|
||||||
* Cette fois-ci, Bellman est trop long à utiliser même une seule fois.
|
|
||||||
* 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
|
|
||||||
* Mode: LENGTH
|
|
||||||
* PATH UTILISE : ../Paths/custom_paths/long_chemin_midi_pyrenees.path
|
|
||||||
*/
|
|
||||||
public void chemin_long_Midi_pyrenees_time() {
|
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(2);
|
|
||||||
Graph myGraph = graph.get(3);
|
|
||||||
Node origin = myGraph.get(279654);
|
|
||||||
Node destination = myGraph.get(481936);
|
|
||||||
ShortestPathData data = new ShortestPathData(myGraph, origin, destination, arcInspector);
|
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
|
||||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
|
||||||
|
|
||||||
assert(dijk_path.getPath().isValid());
|
|
||||||
assert(dijk_path.isFeasible());
|
|
||||||
// On a des erreurs d'arrondi assez grandes avec la distance
|
|
||||||
assert((Math.abs(dijkstra.getCostPath() - dijk_path.getPath().getMinimumTravelTime())) < 100.0);
|
|
||||||
// Selon le chemin sélectionné on peut avoir une estimation de la durée qu'on est censée avoir.
|
|
||||||
// Avec notre long chemin: entre 12000 et 13000 secondes.
|
|
||||||
assert(dijkstra.getCostPath() > 12000 && dijkstra.getCostPath() < 13000);
|
|
||||||
// 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