commentaires

This commit is contained in:
Bensouda Idriss 2023-05-19 12:43:46 +02:00
parent 728f069973
commit 9b1b344d29
4 changed files with 17 additions and 3 deletions

View file

@ -13,6 +13,7 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
@Override
public Label CreationLabel(Node x, Double cout, Arc parent){
ShortestPathData data = getInputData();
//On utilise Point.distance qui permet d'obtenir la distance à vol d'oiseau d'un point x vers un point destination
return new LabelStar(x,cout,parent,Point.distance(data.getGraph().get(x.getId()).getPoint(), data.getDestination().getPoint()));
}

View file

@ -31,7 +31,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
ArrayList<Arc> Arcs = new ArrayList<Arc>();
/* Initialise nos label */
for (Node x: data.getGraph().getNodes())
{
@ -47,6 +46,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
Tas.insert(List_Label.get(data.getOrigin().getId()));
Label x;
//Tant que le tas n'est pas vide et que notre destination n'est pas marquée (noir)
while (!List_Label.get(data.getDestination().getId()).isMarque() && !Tas.isEmpty()){
x = Tas.findMin();
x.setMarque(true);
@ -57,13 +57,16 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
if (!data.isAllowed(suivant)) {
continue;
}
// On récupère le label correspondant au sommet destination de notre arc suivant
Label l=List_Label.get(suivant.getDestination().getId());
if(!l.isMarque()){
Boolean changé = false;
//On vérifie si le coût sera amélioré avec notre label destination
if (x.getRealCost()+data.getCost(suivant) < l.getRealCost()){
changé = true;
}
//Si oui, si le label à déjà été atteint, on le sort du tas, met à jour ses attributs et le réinsère
if(changé){
if (l.getRealCost() != Double.MAX_VALUE){
@ -72,6 +75,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
Tas.insert(l);
l.setParent(suivant);
}
//Sinon, on met juste à jour ses attributs et l'insère dans le tas
else{
l.setCost(x.getRealCost()+data.getCost(suivant));
Tas.insert(l);
@ -84,18 +88,27 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
}
//On récupère le chemin (liste d'arcs) de la destination vers la source
Label dest =List_Label.get(data.getDestination().getId());
while (dest.getParent() != null){
Arcs.add(dest.getParent());
dest = List_Label.get(dest.getParent().getOrigin().getId());
}
//On inverse la liste d'arcs
Collections.reverse(Arcs);
//On construit la solution
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(data.getGraph(), Arcs));
ArrayList<Node> solutionNodes = new ArrayList<Node>();
//On récupère la liste de nodes du Path solution
for (Arc a : Arcs){
solutionNodes.add(a.getOrigin());
}
solutionNodes.add(data.getDestination());
//Vérifications de la validité de la solution
ShortestVerif(solution, solutionNodes, data);
fastestVerif(solution, solutionNodes, data);
volDoiseauVerif(data, solution);
@ -113,7 +126,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
// Permet de vérifier si le temps de parcours de la solution est bien le plus rapide
public void fastestVerif(ShortestPathSolution solution,ArrayList<Node> solutionNodes,ShortestPathData data){
Path p= Path.createFastestPathFromNodes(data.getGraph(), solutionNodes);
System.out.println("fastest path : " + p.getMinimumTravelTime());