1
0
Ответвление 0
BE_Graphes/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelStar.java

42 строки
1,2 КиБ
Java

package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.Point;
public class LabelStar extends Label {
private float distanceToDestination;
public LabelStar(Node node, Node destination) {
super(node);
// precision was never an answer
distanceToDestination = (float) Point.distance(node.getPoint(), destination.getPoint());
}
@Override
public float getTotalCost() {
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;
}
}