This commit is contained in:
Georgia Koutsodima 2023-04-12 16:14:38 +02:00
parent c81a209b5a
commit 14240bbf30

View file

@ -1,8 +1,13 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.Arc;
import org.insa.graphs.algorithm.AbstractSolution.Status;
import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Path;
import java.util.ArrayList;
import java.util.Collections;
import org.insa.graphs.algorithm.utils.BinaryHeap;
@ -28,7 +33,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
Label label_origine = tab.get(data.getOrigin().getId());
label_origine.setCoutmin(0);
Label label_dest =tab.get(data.getDestination().getId())
Label label_dest =tab.get(data.getDestination().getId());
/*insertion de label origine dans le tas */
tas.insert(label_origine);
Label x;
@ -53,6 +58,29 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
}
}
// On n'a pas trouvé de solution, on est sorti de la boucle car le tas est vide
if (label_dest.getMarque()==false) {
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
}
else {
// The destination has been found, notify the observers.
notifyDestinationReached(data.getDestination());
// Create the path from the array of predecessors...
ArrayList<Arc> arcs = new ArrayList<>();
Arc arc = label_dest.getPere();
while (arc != null) {
arcs.add(arc);
arc = tab.get(arc.getOrigin().getId()).getPere();
}
// Reverse the path...
Collections.reverse(arcs);
// Create the final solution.
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(data.getGraph(), arcs));
}
return solution;