This commit is contained in:
Lea Norgeux 2023-04-12 16:21:32 +02:00
commit 734fa38388

View file

@ -1,7 +1,6 @@
package org.insa.graphs.algorithm.shortestpath; package org.insa.graphs.algorithm.shortestpath;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import org.insa.graphs.model.Node; import org.insa.graphs.model.Node;
import org.insa.graphs.model.Arc; import org.insa.graphs.model.Arc;
@ -22,6 +21,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
int tailleGraphe = data.getGraph().size(); int tailleGraphe = data.getGraph().size();
int index = 0; int index = 0;
ArrayList<Label> labelSommets = new ArrayList<Label>(); ArrayList<Label> labelSommets = new ArrayList<Label>();
Label currentLabel; Label currentLabel;
@ -46,6 +46,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
double currentCost; double currentCost;
double newCost; double newCost;
Label newLabel; Label newLabel;
notifyOriginProcessed(currentNode);
//Boucle principale ---------------------------------------------------- //Boucle principale ----------------------------------------------------
@ -58,26 +59,34 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
index = currentNode.getId(); index = currentNode.getId();
currentLabel.setMarqueTrue(); currentLabel.setMarqueTrue();
notifyNodeMarked(currentNode);
for(Arc arc : currentNode.getSuccessors()) for(Arc arc : currentNode.getSuccessors())
{ {
newLabel = labelSommets.get(arc.getDestination().getId()); if(data.isAllowed(arc))
if(!newLabel.getMarque())
{ {
currentCost = newLabel.getCost(); newLabel = labelSommets.get(arc.getDestination().getId());
newCost = arc.getLength() + currentLabel.getCost(); if(!newLabel.getMarque())
if(currentCost == -1.0)
{ {
newLabel.setNouveauChemin(arc, newCost); currentCost = newLabel.getCost();
leTas.insert(newLabel); newCost = data.getCost(arc) + currentLabel.getCost();
} if(currentCost == -1.0)
else if(newCost < currentCost) {
{ newLabel.setNouveauChemin(arc, newCost);
leTas.remove(newLabel); leTas.insert(newLabel);
newLabel.setNouveauChemin(arc, newCost); notifyNodeReached(newLabel.getSommetCourant());
leTas.insert(newLabel); }
else if(newCost < currentCost)
{
leTas.remove(newLabel);
newLabel.setNouveauChemin(arc, newCost);
leTas.insert(newLabel);
}
} }
} }
} }
} }
@ -102,6 +111,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
if(index != tailleGraphe) if(index != tailleGraphe)
{ {
Collections.reverse(arcListe); Collections.reverse(arcListe);
notifyDestinationReached(data.getDestination());
return new ShortestPathSolution(data, AbstractSolution.Status.FEASIBLE, new Path(data.getGraph(),arcListe )); return new ShortestPathSolution(data, AbstractSolution.Status.FEASIBLE, new Path(data.getGraph(),arcListe ));
} }