This commit is contained in:
Favary Pierre 2021-05-04 16:37:52 +02:00
parent e847e06b8d
commit 71cee153fc
4 changed files with 76 additions and 2 deletions

View file

@ -0,0 +1,27 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.model.Arc;
import org.insa.graphs.model.Path;//trier tout ça
public class AStar extends DijkstraAlgorithm {
public void initLabel() {
int placeholder=0;
}
public AStar(ShortestPathData data) {
super(data);
}
public void proc1modifDijk() {
this.getInputData().getDestination();
}
//particularités de A*:
//-comment trouver la distance à vol d'oiseau entre deux nodes?--------node.getpoint().distanceTo()?
//-comment initialiser le labelstar.estim de chaque node avec cette méthode
//-comment avoir des LabelStar et non des Label
}

View file

@ -89,8 +89,14 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
Collections.reverse(bonsarcs);
//Path chemin= new Path(data.getGraph(),bonsarcs);//y'a t-il un retour si le chemin est infaisable? éviterait la condition précédente si oui
solution = new ShortestPathSolution(data,Status.OPTIMAL,new Path(data.getGraph(),bonsarcs));
//Path chemin= new Path(data.getGraph(),bonsarcs);//y'a t-il un retour si le chemin est infaisable?
//System.out.printf("valide: %b, longueur: %f\n",chemin.isValid(), chemin.getLength());
//System.out.printf("distance réelle origine-destination (test): %f", (float)this.getInputData().getOrigin().getPoint().distanceTo(this.getInputData().getDestination().getPoint()));
//comparer le coût avec celui de la méthode Path en utilisant equals ou compareTo, mais Dijkstra ne renvoie pas de coût de lui-même, ni ShortestPathSolution?
}
return solution;

View file

@ -34,13 +34,19 @@ public class Label implements Comparable<Label>{
}
//est-ce que cette fonction est utilisée?
public float getCost() {
return this.cout;
}
//fonction utilse pour LabelStar (permet d'hériter de compareTo)
public float getTotalCost() {
return this.cout;
}
//fonction de comparaison
public int compareTo(Label comp) {
float diff= this.cout-comp.cout;
float diff= this.getTotalCost()-comp.getTotalCost();
if (diff>0) {
return 1;
}else if (diff<0) {
@ -49,4 +55,5 @@ public class Label implements Comparable<Label>{
return 0;
}
}
}

View file

@ -0,0 +1,34 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.model.Arc;
import org.insa.graphs.model.Node;
public class LabelStar extends Label{
protected float estim;
public LabelStar(Node sommet, Arc padre, float prix, float estimation) {
super(sommet, padre, prix);
this.estim=estimation;
}
public LabelStar(Node sommet, Arc padre, float prix, float estimation, boolean mark) {
super(sommet, padre, prix, mark);
this.estim=estimation;
}
public float getEstimation() {
return this.estim;//même remarque que pour son pendant dans Label
}
public float getTotalCost() {
return this.cout+this.estim;
}
//...
public void setEstimation(Node destination) {
this.estim=(float)destination.getPoint().distanceTo(this.sommet_courant.getPoint());
}
//note: pourquoi l'icône de ce fichier de eclipse est-elle un peu différente?
}