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