feat(dijkstra): support double precision instead of float
This commit is contained in:
parent
6af2ae2ead
commit
f4db47ee4e
4 changed files with 17 additions and 17 deletions
|
@ -63,7 +63,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
notifyNodeMarked(x.getNode());
|
||||
// System.out.println(x.getCost()); // Pour vérifier une croissance des noeuds marqués
|
||||
// We create a list of node successors of x, instead of a list of Arcs.
|
||||
float arc_cost = 0;
|
||||
double arc_cost = 0;
|
||||
for (Arc successorArc : x.getNode().getSuccessors()) {
|
||||
Label successor = labels.get(successorArc.getDestination().getId());
|
||||
|
||||
|
@ -76,11 +76,11 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
// data.getcost(arc) returns a cost considering the mode chosen:
|
||||
// TIME or LENGTH
|
||||
// Similar to using getLength / getMinimumTravelTime
|
||||
arc_cost = (float) data.getCost(arc);
|
||||
arc_cost = data.getCost(arc);
|
||||
}
|
||||
}
|
||||
|
||||
final float possible_path_cost = x.getCost() + arc_cost;
|
||||
final double possible_path_cost = x.getCost() + arc_cost;
|
||||
if (successor.getCost() > possible_path_cost) {
|
||||
// Mise à jour du label
|
||||
successor.setPathCost(possible_path_cost);
|
||||
|
|
|
@ -7,7 +7,7 @@ public class Label implements Comparable<Label> {
|
|||
Node node;
|
||||
boolean marked;
|
||||
boolean reached;
|
||||
float pathCost;
|
||||
double pathCost;
|
||||
Node parentNode;
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class Label implements Comparable<Label> {
|
|||
this.node = node;
|
||||
this.marked = false;
|
||||
this.marked = false;
|
||||
this.pathCost = Float.MAX_VALUE;
|
||||
this.pathCost = Double.MAX_VALUE;
|
||||
this.parentNode = null;
|
||||
}
|
||||
|
||||
|
@ -24,24 +24,24 @@ public class Label implements Comparable<Label> {
|
|||
public void mark() { this.marked = true; }
|
||||
public boolean isReached() { return this.reached; }
|
||||
public void markReached() { this.reached = true; }
|
||||
public float getPathCost() { return this.pathCost; }
|
||||
public void setPathCost(float newCost) { this.pathCost = newCost; }
|
||||
public double getPathCost() { return this.pathCost; }
|
||||
public void setPathCost(double newCost) { this.pathCost = newCost; }
|
||||
public Node getParentNode() { return this.parentNode; }
|
||||
public void setParentNode(Node parentNode) { this.parentNode = parentNode; }
|
||||
|
||||
public float getCost() {
|
||||
public double getCost() {
|
||||
// function will be modified later
|
||||
|
||||
return pathCost;
|
||||
}
|
||||
|
||||
public float getTotalCost() {
|
||||
public double getTotalCost() {
|
||||
// will be overriden for A*
|
||||
return pathCost;
|
||||
}
|
||||
|
||||
public int compareTo(Label other) {
|
||||
final float difference = this.getTotalCost() - other.getTotalCost();
|
||||
final double difference = this.getTotalCost() - other.getTotalCost();
|
||||
return (int) Math.signum(difference);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
|||
import org.insa.graphs.model.RoadInformation;
|
||||
|
||||
public class LabelStar extends Label {
|
||||
private float distanceToDestination;
|
||||
private double distanceToDestination;
|
||||
private int MaximumSpeed;
|
||||
|
||||
public LabelStar(Node node, int MaximumSpeed, Node destination) {
|
||||
|
@ -14,15 +14,15 @@ public class LabelStar extends Label {
|
|||
this.MaximumSpeed = MaximumSpeed;
|
||||
// precision was never an answer
|
||||
if (this.MaximumSpeed < 0) {
|
||||
distanceToDestination = (float) Point.distance(node.getPoint(), destination.getPoint());
|
||||
distanceToDestination = (double) Point.distance(node.getPoint(), destination.getPoint());
|
||||
}
|
||||
else {
|
||||
distanceToDestination = (float) Point.distance(node.getPoint(), destination.getPoint()) / (1000 * MaximumSpeed);
|
||||
distanceToDestination = (double) Point.distance(node.getPoint(), destination.getPoint()) / (1000 * MaximumSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTotalCost() {
|
||||
public double getTotalCost() {
|
||||
return this.getCost() + distanceToDestination;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class LabelStar extends Label {
|
|||
* "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();
|
||||
final double difference = this.getTotalCost() - other.getTotalCost();
|
||||
int retour = (int) Math.signum(difference);
|
||||
if (Math.abs(difference) < 0.01) {
|
||||
// En cas d'égalité:
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.insa.graphs.model.Node;
|
|||
|
||||
public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPathObserver> {
|
||||
|
||||
protected float pathCost;
|
||||
protected double pathCost;
|
||||
|
||||
protected ShortestPathAlgorithm(ShortestPathData data) {
|
||||
super(data);
|
||||
|
@ -69,7 +69,7 @@ public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPa
|
|||
}
|
||||
}
|
||||
|
||||
public float getCostPath() {
|
||||
public double getCostPath() {
|
||||
return this.pathCost;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue