Compare commits

...

2 commits

Author SHA1 Message Date
24012e3afc feat(astar): compare total cost 2024-05-03 14:46:33 +02:00
a0c6437bd2 feat(astar): create class labelstar 2024-05-03 14:46:18 +02:00
2 changed files with 33 additions and 1 deletions

View file

@ -33,8 +33,21 @@ public class Label implements Comparable<Label> {
return pathCost;
}
public float getTotalCost() {
// will be overriden for A*
return pathCost;
}
public int compareTo(Label other) {
final float difference = this.getTotalCost() - other.getTotalCost();
final boolean equal = Math.abs(difference) < 1.0;
if (equal) {
return 0;
//TODO
}
// TODO ensure this works properly
return (int)(this.pathCost - other.pathCost);
// return (int)(this.pathCost - other.pathCost);
return this.pathCost - other.pathCost < 0 ? -1 : 1;
}
}

View file

@ -0,0 +1,19 @@
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;
}
}