workimg on a star
This commit is contained in:
parent
df25330f67
commit
6f81f4d860
3 changed files with 126 additions and 2 deletions
|
@ -1,9 +1,61 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
/*
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.insa.graphs.algorithm.AbstractSolution;
|
||||||
|
import org.insa.graphs.algorithm.ArcInspector;
|
||||||
|
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||||
|
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
||||||
|
import org.insa.graphs.algorithm.utils.ElementNotFoundException;
|
||||||
|
import org.insa.graphs.model.Arc;
|
||||||
|
import org.insa.graphs.model.Graph;
|
||||||
|
import org.insa.graphs.model.Node;
|
||||||
|
import org.insa.graphs.model.Path;
|
||||||
|
|
||||||
|
*/
|
||||||
public class AStarAlgorithm extends DijkstraAlgorithm {
|
public class AStarAlgorithm extends DijkstraAlgorithm {
|
||||||
|
|
||||||
public AStarAlgorithm(ShortestPathData data) {
|
public AStarAlgorithm(ShortestPathData data) {
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
@Override
|
||||||
|
protected ShortestPathSolution doRun() {
|
||||||
|
|
||||||
|
// retrieve data from the input problem (getInputData() is inherited from the
|
||||||
|
// parent class ShortestPathAlgorithm)
|
||||||
|
final ShortestPathData data = getInputData();
|
||||||
|
// on crée un inspector qui nous permettra de savoir si on peut ou pas utiliser un arc
|
||||||
|
ArcInspector inspector = data.getArcInspector();
|
||||||
|
// on change l'inspector au mode qui nous intéresse soit ici voiture ( qui est a la deuxieme case du tableau)
|
||||||
|
//inspector = ArcInspectorFactory.getAllFilters().get(1);
|
||||||
|
final Graph graph = data.getGraph();
|
||||||
|
final int nbNodes = graph.size();
|
||||||
|
final Node destination = data.getDestination();
|
||||||
|
final Node origin = data.getOrigin();
|
||||||
|
|
||||||
|
// affichage de l'inspector utilisé
|
||||||
|
System.out.println("Inspector utilisé est : " + inspector.toString());
|
||||||
|
|
||||||
|
// Labels A* pour chaque nœud
|
||||||
|
LabelStar[] labels = new LabelStar[nbNodes];
|
||||||
|
// Tas binaire pour l'extraction du label de coût f minimal
|
||||||
|
BinaryHeap<Label> heap = new BinaryHeap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//return solution;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
|
@ -61,10 +61,27 @@ public class Label implements Comparable<Label>{
|
||||||
public Arc getarcpere_fils() {
|
public Arc getarcpere_fils() {
|
||||||
return this.arcpere_fils;
|
return this.arcpere_fils;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//juste un nv nom pour getcost car c demande en A star
|
||||||
|
public double getTotalCost() {
|
||||||
|
return getCost();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// on override la méthode de comparaison
|
// on override la méthode de comparaison
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Label other){
|
public int compareTo(Label other){
|
||||||
return Double.compare(this.getCost(),other.getCost());
|
return Double.compare(this.getCost(),other.getCost());
|
||||||
}
|
} */
|
||||||
|
|
||||||
|
//car on va utiliser priority avce les plus petit distances car on a une binary heap
|
||||||
// ces labels sont associé à chaque noeud : les noeuds du graphes sont numérotés de 0 à N-1
|
// ces labels sont associé à chaque noeud : les noeuds du graphes sont numérotés de 0 à N-1
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Label other) {
|
||||||
|
// Compare via getTotalCost plutôt que directement getCost
|
||||||
|
return Double.compare(this.getTotalCost(), other.getTotalCost());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
|
||||||
|
import org.insa.graphs.model.Arc;
|
||||||
|
import org.insa.graphs.model.Node;
|
||||||
|
|
||||||
|
public class LabelStar extends Label{
|
||||||
|
private double cout_estimee;
|
||||||
|
|
||||||
|
public LabelStar(Node sommetCourant, double cout_estimee) {
|
||||||
|
super(sommetCourant);
|
||||||
|
this.cout_estimee = cout_estimee;
|
||||||
|
}
|
||||||
|
//Constructeur de copie pour cloner un LabelStar existant.
|
||||||
|
/*
|
||||||
|
public LabelStar(LabelStar other) {
|
||||||
|
super(other.getsommetcourant ());
|
||||||
|
// Recopie de tous les champs de Label
|
||||||
|
this.setmarque(other.getmarque());
|
||||||
|
this.setcoutrealise(other.getCost());
|
||||||
|
this.setarcperefils(other.getarcpere_fils());
|
||||||
|
// Recopie de l'heuristique
|
||||||
|
this.cout_estimee = other.cout_estimee;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//Setter
|
||||||
|
public void setCoutEstimee(double cout_estimee) {
|
||||||
|
this.cout_estimee = cout_estimee;
|
||||||
|
}
|
||||||
|
//Getter pour l'estimatio
|
||||||
|
public double getCoutEstimee() {
|
||||||
|
return this.cout_estimee;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coût total total cost = cout_realise + cout_estimee
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getTotalCost() {
|
||||||
|
// g(n) = getCostRealise(), h(n) = cout_estimee
|
||||||
|
return this.getCost() + this.cout_estimee;
|
||||||
|
}
|
||||||
|
|
||||||
|
////car on va utiliser priority avce les plus petit distances car on a une binary heap
|
||||||
|
///
|
||||||
|
/* plus besoin car compareTo héritée de Label
|
||||||
|
@Override
|
||||||
|
public int compareTo(Label other) {
|
||||||
|
double fThis = this.getCost();
|
||||||
|
double fOther = other.getCost();
|
||||||
|
return Double.compare(fThis, fOther);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue