Djikstra v1 finalisé

This commit is contained in:
Marie Brunetto 2023-04-05 18:16:57 +02:00
parent 6943f73f81
commit 29339a9e86

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;
@ -21,6 +20,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
int tailleGraphe = data.getGraph().size();
int index = 0;
ArrayList<Label> labelSommets = new ArrayList<Label>();
Label currentLabel;
@ -45,6 +45,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
double currentCost;
double newCost;
Label newLabel;
notifyOriginProcessed(currentNode);
//Boucle principale ----------------------------------------------------
@ -57,26 +58,34 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
index = currentNode.getId();
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);
}
}
}
}
}
@ -101,6 +110,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 ));
}