Adress case: En cas d'égalité, on considèrera en premier le sommet ayant le plus petit coût estimé à la destination.
This commit is contained in:
parent
c60efbc5a5
commit
436d69db1b
1 changed files with 24 additions and 1 deletions
|
@ -12,8 +12,31 @@ public class LabelStar extends Label {
|
||||||
distanceToDestination = (float) Point.distance(node.getPoint(), destination.getPoint());
|
distanceToDestination = (float) Point.distance(node.getPoint(), destination.getPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getTotalCost() {
|
public float getTotalCost() {
|
||||||
return this.getCost() + distanceToDestination;
|
return this.getCost() + distanceToDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
/*
|
||||||
|
* This override of the function CompareTo addresses the case:
|
||||||
|
* "En cas d'égalité, on considèrera en premier le sommet ayant le plus petit coût estimé à la destination."
|
||||||
|
*/
|
||||||
|
public int compareTo(Label other) {
|
||||||
|
final float difference = this.getTotalCost() - other.getTotalCost();
|
||||||
|
int retour = (int) Math.signum(difference);
|
||||||
|
if (Math.abs(difference) < 0.01) {
|
||||||
|
// En cas d'égalité:
|
||||||
|
// Récupérer le sommet avec le plus petit coût estimé à la destination
|
||||||
|
// <=> Récupérer le sommet avec le plus grand coût depuis l'origine
|
||||||
|
if ((this.getCost() - other.getCost() > 0.0)) {
|
||||||
|
retour = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
retour = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retour;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue