modified: be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java
This commit is contained in:
parent
46722fd591
commit
65d760558c
2 changed files with 17 additions and 23 deletions
|
@ -5,5 +5,11 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
||||||
public AStarAlgorithm(ShortestPathData data) {
|
public AStarAlgorithm(ShortestPathData data) {
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
/*Réécriture de la méthiode newLabel*/
|
||||||
|
/*Afin d'utiliser LabelSatr au lieu de Label dans l'algo*/
|
||||||
|
protected Label Label (Node node, ShortestpathData data) {
|
||||||
|
return new LabelSatr(node,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,12 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
notifyOriginProcessed(data.getOrigin());
|
notifyOriginProcessed(data.getOrigin());
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
// -----------------initialisation-------------------------------------------------
|
||||||
//////////////////////////////////////INITIALISATION/////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
BinaryHeap<Label> tas = new BinaryHeap<Label>();
|
BinaryHeap<Label> tas = new BinaryHeap<Label>();
|
||||||
|
|
||||||
ArrayList<Label> labels = new ArrayList<Label>();
|
ArrayList<Label> labels = new ArrayList<Label>();
|
||||||
|
|
||||||
//On initialise tous les labels à +infini, avec marque à false et pere à NULL
|
//On initialise tous les labels à +infini, avec marque à false et pere à NULL
|
||||||
for (int i = 0; i < nbNodes; i++) {
|
for (int i = 0; i < nbNodes; i++) {
|
||||||
labels.add(new Label(nodes.get(i)));
|
labels.add(new Label(nodes.get(i)));
|
||||||
|
@ -49,13 +50,8 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
labels.get(index_origine).setCost(0);
|
labels.get(index_origine).setCost(0);
|
||||||
//On insère le label actualisé dans le tas
|
//On insère le label actualisé dans le tas
|
||||||
tas.insert(labels.get(index_origine));
|
tas.insert(labels.get(index_origine));
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//////////////////////////////////////INITIALISATION/////////////////////////////////////////////
|
//--------------------Boucle d'iteration-------------------------------------------
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////ITERATIONS//////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//Définition d'une variable pour compter le nombre d'itérations pour le debogage
|
//Définition d'une variable pour compter le nombre d'itérations pour le debogage
|
||||||
int nbIterations = 0;
|
int nbIterations = 0;
|
||||||
|
@ -71,7 +67,8 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
//Vérification de la taille du tas
|
//Vérification de la taille du tas
|
||||||
System.out.println("Taille du tas : " + tas.size());
|
System.out.println("Taille du tas : " + tas.size());
|
||||||
|
|
||||||
//Debogage
|
//Sortie debogueur
|
||||||
|
|
||||||
//Incrémentation du nombre d'itérations
|
//Incrémentation du nombre d'itérations
|
||||||
nbIterations++;
|
nbIterations++;
|
||||||
//Verification du tas
|
//Verification du tas
|
||||||
|
@ -82,11 +79,10 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
System.out.println("Tas non valide");
|
System.out.println("Tas non valide");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//On récupère les arcs successeurs du label minimal
|
//On récupère les arcs successeurs du label minimal
|
||||||
List<Arc> arcs = label_min.getNode().getSuccessors();
|
List<Arc> arcs = label_min.getNode().getSuccessors();
|
||||||
|
|
||||||
//Debogage
|
//Sortie debogueur
|
||||||
System.out.println("Nb successeurs du label : " + arcs.size());
|
System.out.println("Nb successeurs du label : " + arcs.size());
|
||||||
|
|
||||||
for (int i = 0; i < arcs.size(); i++) {
|
for (int i = 0; i < arcs.size(); i++) {
|
||||||
|
@ -118,13 +114,8 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////ITERATIONS//////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
//-------------------On crée notre solution -------------------------------------
|
||||||
//////////////////////////////////CREATION DE LA SOLUTION////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
ShortestPathSolution solution = null;
|
ShortestPathSolution solution = null;
|
||||||
|
|
||||||
//La destination n'a pas de prédécesseur, le chemin est infaisable
|
//La destination n'a pas de prédécesseur, le chemin est infaisable
|
||||||
|
@ -169,11 +160,8 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//////////////////////////////////CREATION DE LA SOLUTION////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
return solution;
|
return solution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue