Version fonctionnelle : Dijkstra (testé)

This commit is contained in:
Paul Faure 2020-04-24 18:23:08 +02:00
parent 56db8ab93e
commit 7c91d40de9
3 changed files with 62 additions and 1 deletions

View file

@ -48,10 +48,16 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
labels[currentID].marquer();
notifyNodeMarked(current.getSommetCourant());
System.out.println(labels[currentID].getCost());
// POUR LE TEST SUR LES COUTS CROISSANTS
// System.out.println(labels[currentID].getCost());
//nbNonMarque--;
// POUR LE TEST SUR LES SUCCESSEURS
//int compteur_successeurs = 0;
for (Arc succ: labels[currentID].getSommetCourant().getSuccessors()) {
// POUR LE TEST SUR LES SUCCESSEURS
//compteur_successeurs++;
if (!data.isAllowed(succ)) {
continue;
}
@ -68,6 +74,12 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
}
}
// POUR LE TEST SUR LES SUCCESSEURS
/*if (compteur_successeurs != labels[currentID].getSommetCourant().getNumberOfSuccessors()) {
System.out.println("ERREUR Nombre de successeurs visités : " + compteur_successeurs + "/" + labels[currentID].getSommetCourant().getNumberOfSuccessors());
}
System.out.println("Nombre de successeurs visités : " + compteur_successeurs + "/" + labels[currentID].getSommetCourant().getNumberOfSuccessors());
*/
}
catch (EmptyPriorityQueueException e) {
encore = false;
@ -78,6 +90,8 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
ShortestPathSolution solution = null;
//Pour le test SOMME(couts) = Cout(Label(Destination))
double SommeCouts = 0.0;
// Destination has no predecessor, the solution is infeasible...
if (labels[dest.getId()].getPere() == null) {
@ -91,8 +105,12 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// Create the path from the array of predecessors...
ArrayList<Arc> arcs = new ArrayList<>();
Arc arc = labels[dest.getId()].getPere();
while (arc != null) {
arcs.add(arc);
//Pour le test SOMME(couts) = Cout(Label(Destination))
SommeCouts += data.getCost(arc);
arc = labels[arc.getOrigin().getId()].getPere();
}
@ -103,6 +121,35 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(graph, arcs));
}
if (solution.getStatus() != Status.INFEASIBLE) {
// Test si le path est valide
if (!solution.getPath().isValid()) {
System.out.println("Erreur : PATH SOLUTION INVALID !");
}
// Test s'il correspond a Shortest et Fastest de la classe Path
// INUTILE, SUJET MAL COMPRIS
/*if (data.getMode() == Mode.LENGTH) {
if (solution.getPath().getLength() != Path.createShortestPathFromNodes(graph, solution.getPath().getNodes()).getLength()) {
System.out.println("Erreur : PATH SOLUTION NOT SHORTEST !");
} else {
System.out.println("PATH SOLUTION SHORTEST !");
}
} else {
if (solution.getPath().getMinimumTravelTime() != Path.createFastestPathFromNodes(graph, solution.getPath().getNodes()).getMinimumTravelTime()) {
System.out.println("Erreur : PATH SOLUTION NOT FASTEST !");
} else {
System.out.println("PATH SOLUTION FASTEST !");
}
}*/
if ((int)(SommeCouts * 1000) != (int)(labels[dest.getId()].getCost() * 1000)) {
System.out.println("Erreur : Cost label Dest (" + labels[dest.getId()].getCost() + ") != Somme(cost) (" + SommeCouts + ")");
}
}
return solution;
}

View file

@ -173,6 +173,10 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
return minItem;
}
public boolean IsValid() {
return true;
}
/**
* Creates a multi-lines string representing a sorted view of this binary heap.
*

View file

@ -225,6 +225,16 @@ public class Path {
return Collections.unmodifiableList(arcs);
}
public List<Node> getNodes() {
List<Node> Noeuds = new ArrayList<Node>();
for (Arc succ: arcs) {
Noeuds.add(succ.getOrigin());
}
Noeuds.add(this.getDestination());
return Noeuds;
}
/**
* Check if this path is empty (it does not contain any node).
*