@@ -47,7 +47,7 @@ public AStar(Graph g) {
47
47
double tmpLon = graph .getLongitude (from );
48
48
double distToGoal = approxDist .calcDistKm (lat , lon , tmpLat , tmpLon );
49
49
double fDistComplete = 0 + distToGoal ;
50
- AStarEdge fromEntry = new AStarEdge (from , 0 , fDistComplete );
50
+ AStarEdge fromEntry = new AStarEdge (from , fDistComplete , 0 );
51
51
AStarEdge curr = fromEntry ;
52
52
while (true ) {
53
53
int currVertex = curr .node ;
@@ -62,7 +62,7 @@ public AStar(Graph g) {
62
62
// which satisfies the h(x) requirement instead of this expensive real calculation
63
63
// 2. use less expensive calc distance
64
64
// (e.g. normed dist ... hmh but then entry.distance of edges needs to be normed too!)
65
- double gDist = iter .distance () + curr .distToCompare ;
65
+ float gDist = ( float ) iter .distance () + curr .distToCompare ;
66
66
AStarEdge de = map .get (neighborNode );
67
67
if (de == null ) {
68
68
// dup code
@@ -72,7 +72,7 @@ public AStar(Graph g) {
72
72
fDistComplete = gDist + distToGoal ;
73
73
// --
74
74
75
- de = new AStarEdge (neighborNode , gDist , fDistComplete );
75
+ de = new AStarEdge (neighborNode , fDistComplete , gDist );
76
76
de .prevEntry = curr ;
77
77
map .put (neighborNode , de );
78
78
openSet .add (de );
@@ -121,11 +121,12 @@ private static class AStarEdge extends Edge {
121
121
122
122
// the variable 'distance' is used to let heap select smallest *full* distance.
123
123
// but to compare distance we need it only from start:
124
- double distToCompare ;
124
+ float distToCompare ;
125
125
126
- public AStarEdge (int loc , double distToCompare , double distForHeap ) {
126
+ public AStarEdge (int loc , double distForHeap , float distToCompare ) {
127
127
super (loc , distForHeap );
128
- this .distToCompare = distToCompare ;
128
+ // round makes distance smaller => heuristic should underestimate the distance!
129
+ this .distToCompare = (float ) distToCompare ;
129
130
}
130
131
}
131
132
0 commit comments