Skip to content

Commit 13ed4fe

Browse files
author
Peter
committed
no pre-calculation of weight, for graphhopper#111 and more compact edges if two weights per edges
1 parent 3e49f88 commit 13ed4fe

22 files changed

+603
-368
lines changed

core/src/main/java/com/graphhopper/routing/Path.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected Path setFromNode( int from )
102102
*/
103103
private int getFromNode()
104104
{
105-
if (!EdgeIterator.Edge.isValid(fromNode))
105+
if (fromNode < 0)
106106
throw new IllegalStateException("Call extract() before retrieving fromNode");
107107

108108
return fromNode;
@@ -196,20 +196,12 @@ public String getDebugInfo()
196196
protected void processEdge( int edgeId, int endNode )
197197
{
198198
EdgeIteratorState iter = graph.getEdgeProps(edgeId, endNode);
199-
double dist = calcDistance(iter);
199+
double dist = iter.getDistance();
200200
distance += dist;
201201
millis += calcMillis(dist, iter.getFlags());
202202
addEdge(edgeId);
203203
}
204204

205-
/**
206-
* This method returns the distance in meter for the specified edge.
207-
*/
208-
protected double calcDistance( EdgeIteratorState iter )
209-
{
210-
return iter.getDistance();
211-
}
212-
213205
/**
214206
* Calculates the time in millis for the specified distance in meter and speed (in km/h) via
215207
* flags.
@@ -486,7 +478,7 @@ private void updatePointsAndInstruction( EdgeIteratorState edge, PointList pl )
486478
double lon = pl.getLongitude(i);
487479
points.add(lat, lon);
488480
}
489-
double dist = calcDistance(edge);
481+
double dist = edge.getDistance();
490482
prevInstruction.setDistance(dist + prevInstruction.getDistance());
491483
prevInstruction.setMillis(calcMillis(dist, flags) + prevInstruction.getMillis());
492484
}

core/src/main/java/com/graphhopper/routing/QueryGraph.java

Lines changed: 204 additions & 111 deletions
Large diffs are not rendered by default.

core/src/main/java/com/graphhopper/routing/ch/Path4CH.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
import com.graphhopper.routing.PathBidirRef;
2121
import com.graphhopper.routing.util.FlagEncoder;
22-
import com.graphhopper.routing.util.Weighting;
2322
import com.graphhopper.storage.Graph;
24-
import com.graphhopper.util.EdgeIteratorState;
2523
import com.graphhopper.util.EdgeSkipIterState;
2624

2725
/**
@@ -32,12 +30,9 @@
3230
*/
3331
public class Path4CH extends PathBidirRef
3432
{
35-
private final Weighting calc;
36-
37-
public Path4CH( Graph g, FlagEncoder encoder, Weighting calc )
33+
public Path4CH( Graph g, FlagEncoder encoder )
3834
{
3935
super(g, encoder);
40-
this.calc = calc;
4136
}
4237

4338
@Override
@@ -48,17 +43,11 @@ protected void processEdge( int tmpEdge, int endNode )
4843
expandEdge((EdgeSkipIterState) graph.getEdgeProps(tmpEdge, endNode), false);
4944
}
5045

51-
@Override
52-
public double calcDistance( EdgeIteratorState mainIter )
53-
{
54-
return calc.revertWeight(mainIter, mainIter.getDistance());
55-
}
56-
5746
private void expandEdge( EdgeSkipIterState mainEdgeState, boolean revert )
5847
{
5948
if (!mainEdgeState.isShortcut())
6049
{
61-
double dist = calcDistance(mainEdgeState);
50+
double dist = mainEdgeState.getDistance();
6251
distance += dist;
6352
long flags = mainEdgeState.getFlags();
6453
millis += calcMillis(dist, flags);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to Peter Karich under one or more contributor license
3+
* agreements. See the NOTICE file distributed with this work for
4+
* additional information regarding copyright ownership.
5+
*
6+
* Peter Karich licenses this file to you under the Apache License,
7+
* Version 2.0 (the "License"); you may not use this file except
8+
* in compliance with the License. You may obtain a copy of the
9+
* License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package com.graphhopper.routing.ch;
20+
21+
import com.graphhopper.routing.util.Weighting;
22+
import com.graphhopper.util.EdgeIteratorState;
23+
import com.graphhopper.util.EdgeSkipIterState;
24+
25+
/**
26+
* Used in CH preparation and therefor assumed that all edges are of type EdgeSkipIterState
27+
* <p>
28+
* @author Peter Karich
29+
*/
30+
public class PreparationWeighting implements Weighting
31+
{
32+
private final Weighting userWeighting;
33+
34+
public PreparationWeighting( Weighting userWeighting )
35+
{
36+
this.userWeighting = userWeighting;
37+
}
38+
39+
@Override
40+
public double getMinWeight( double distance )
41+
{
42+
return userWeighting.getMinWeight(distance);
43+
}
44+
45+
@Override
46+
public double calcWeight( EdgeIteratorState edge )
47+
{
48+
if (edge instanceof EdgeSkipIterState)
49+
{
50+
EdgeSkipIterState tmp = (EdgeSkipIterState) edge;
51+
if (tmp.isShortcut())
52+
return tmp.getWeight();
53+
}
54+
return userWeighting.calcWeight(edge);
55+
}
56+
57+
@Override
58+
public String toString()
59+
{
60+
return "PREPARE+" + userWeighting.toString();
61+
}
62+
63+
Weighting getUserWeighting()
64+
{
65+
return userWeighting;
66+
}
67+
}

0 commit comments

Comments
 (0)