Skip to content

Commit e3e027e

Browse files
committed
fix incorrect time unit for GenericWeighting.calcMillis, fixes graphhopper#898
1 parent 78d19a8 commit e3e027e

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

core/src/main/java/com/graphhopper/routing/util/DataFlagEncoder.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public DataFlagEncoder() {
129129
"delivery",
130130
"agricultural",
131131
"no"
132-
);
132+
);
133133

134134

135135
counter = 0;
@@ -210,9 +210,9 @@ int getHighwayValue(ReaderWay way) {
210210
int getAccessValue(ReaderWay way) {
211211
int accessValue = 0;
212212
Integer tmpAccessValue = 0;
213-
for (String restriction: restrictions) {
213+
for (String restriction : restrictions) {
214214
tmpAccessValue = accessMap.get(way.getTag(restriction, "yes"));
215-
if(tmpAccessValue != null && tmpAccessValue > accessValue){
215+
if (tmpAccessValue != null && tmpAccessValue > accessValue) {
216216
accessValue = tmpAccessValue;
217217
}
218218
}
@@ -221,9 +221,9 @@ int getAccessValue(ReaderWay way) {
221221
}
222222

223223
//TODO It is bad that it's a bit static right now. If anyone changes the accessMap this method won't work anymore...
224-
public AccessValue getEdgeAccessValue(long flags){
224+
public AccessValue getEdgeAccessValue(long flags) {
225225
int accessValue = (int) accessEncoder.getValue(flags);
226-
switch (accessValue){
226+
switch (accessValue) {
227227
case 0:
228228
return AccessValue.ACCESSIBLE;
229229
case 5:
@@ -355,6 +355,9 @@ public String getHighwayAsString(EdgeIteratorState edge) {
355355
}
356356

357357
public double[] getHighwaySpeedMap(Map<String, Double> map) {
358+
if (map == null)
359+
throw new IllegalArgumentException("Map cannot be null when calling getHighwaySpeedMap");
360+
358361
double[] res = new double[highwayMap.size()];
359362
for (Entry<String, Double> e : map.entrySet()) {
360363
Integer integ = highwayMap.get(e.getKey());
@@ -575,7 +578,7 @@ public ConfigMap readStringMap(PMap weightingMap) {
575578
return cMap;
576579
}
577580

578-
public enum AccessValue{
581+
public enum AccessValue {
579582

580583
ACCESSIBLE,
581584
EVENTUALLY_ACCESSIBLE,

core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
*/
3939
public class GenericWeighting extends AbstractWeighting {
4040
/**
41-
* Converting to seconds is not necessary but makes adding other penalties easier (e.g. turn
42-
* costs or traffic light costs etc)
41+
* Convert to milliseconds for correct calcMillis.
4342
*/
44-
protected final static double SPEED_CONV = 3.6;
43+
private final static double SPEED_CONV = 3600;
4544
private final double headingPenalty;
4645
private final long headingPenaltyMillis;
4746
private final double maxSpeed;

core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
* @author Peter Karich
4242
*/
4343
public class GenericWeightingTest {
44-
private final EncodingManager em = new EncodingManager("generic");
45-
private final DataFlagEncoder encoder = (DataFlagEncoder) em.getEncoder("generic");
44+
private final DataFlagEncoder encoder = new DataFlagEncoder();
45+
private final EncodingManager em = new EncodingManager(encoder);
4646
private Graph graph;
4747

48-
private final double edgeWeight = 566;
48+
private final double edgeWeight = 566111;
4949

5050
@Before
51-
public void setup() {
51+
public void setUp() {
5252
ReaderWay way = new ReaderWay(27l);
5353
way.setTag("highway", "primary");
5454
way.setTag("maxspeed", "10");
@@ -98,4 +98,12 @@ public void testBlockedByShape() {
9898
instance.setGraph(graph);
9999
assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
100100
}
101+
102+
@Test
103+
public void testCalcTime() {
104+
ConfigMap cMap = encoder.readStringMap(new PMap());
105+
GenericWeighting weighting = new GenericWeighting(encoder, cMap);
106+
EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
107+
assertEquals(edgeWeight, weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE), .1);
108+
}
101109
}

0 commit comments

Comments
 (0)