Skip to content

Commit 43017a7

Browse files
author
Peter
committed
minor astar tuning
1 parent 75c890f commit 43017a7

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

core/src/main/java/de/jetsli/graph/reader/RoutingAlgorithmIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public RoutingAlgorithmIntegrationTests(Graph graph) {
4545
public void start() {
4646
Collector testCollector = new Collector();
4747

48-
//
48+
//
4949
List<OneRun> list = new ArrayList<OneRun>();
5050
list.add(new OneRun(43.727687, 7.418737, 43.730729, 7.421288, 1.532, 88));
5151
list.add(new OneRun(43.727687, 7.418737, 43.74958, 7.436566, 3.448, 136));

core/src/main/java/de/jetsli/graph/routing/AStar.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public AStar(Graph g) {
4747
double tmpLon = graph.getLongitude(from);
4848
double distToGoal = approxDist.calcDistKm(lat, lon, tmpLat, tmpLon);
4949
double fDistComplete = 0 + distToGoal;
50-
AStarEdge fromEntry = new AStarEdge(from, 0, fDistComplete);
50+
AStarEdge fromEntry = new AStarEdge(from, fDistComplete, 0);
5151
AStarEdge curr = fromEntry;
5252
while (true) {
5353
int currVertex = curr.node;
@@ -62,7 +62,7 @@ public AStar(Graph g) {
6262
// which satisfies the h(x) requirement instead of this expensive real calculation
6363
// 2. use less expensive calc distance
6464
// (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;
6666
AStarEdge de = map.get(neighborNode);
6767
if (de == null) {
6868
// dup code
@@ -72,7 +72,7 @@ public AStar(Graph g) {
7272
fDistComplete = gDist + distToGoal;
7373
// --
7474

75-
de = new AStarEdge(neighborNode, gDist, fDistComplete);
75+
de = new AStarEdge(neighborNode, fDistComplete, gDist);
7676
de.prevEntry = curr;
7777
map.put(neighborNode, de);
7878
openSet.add(de);
@@ -121,11 +121,12 @@ private static class AStarEdge extends Edge {
121121

122122
// the variable 'distance' is used to let heap select smallest *full* distance.
123123
// but to compare distance we need it only from start:
124-
double distToCompare;
124+
float distToCompare;
125125

126-
public AStarEdge(int loc, double distToCompare, double distForHeap) {
126+
public AStarEdge(int loc, double distForHeap, float distToCompare) {
127127
super(loc, distForHeap);
128-
this.distToCompare = distToCompare;
128+
// round makes distance smaller => heuristic should underestimate the distance!
129+
this.distToCompare = (float) distToCompare;
129130
}
130131
}
131132

0 commit comments

Comments
 (0)