Skip to content

Commit 18170ad

Browse files
authored
[RSPS-2011]: Fix Bug Speed to high (#46)
* Fix Bug Max Value * Fix bug and add tests
1 parent 63ea993 commit 18170ad

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

core/src/main/java/com/graphhopper/GraphHopperCustomSpeeds.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ protected void importPublicTransit() {
3939
long endTime = System.nanoTime();
4040
long elapsed = (endTime - startTime);
4141
long durationInMillis = TimeUnit.NANOSECONDS.toMillis(elapsed);
42+
43+
//Save Encoding Manager Into Properties to have Max Speed in place after setting the new speeds
44+
this.writeEncodingManagerToProperties();
45+
4246
logger.info("End Custom Speeds Provider : Graph processed in " + durationInMillis);
4347
}
4448

core/src/test/java/com/graphhopper/GraphHopperCustomSpeedsTest.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.graphhopper.config.CHProfile;
2121
import com.graphhopper.config.Profile;
2222
import com.graphhopper.routing.ev.RoadClass;
23+
import com.graphhopper.routing.ev.VehicleSpeed;
2324
import com.graphhopper.speeds.SpeedKmByHour;
2425
import com.graphhopper.speeds.WaySpeedsProvider;
2526
import com.graphhopper.util.*;
@@ -47,6 +48,8 @@ public class GraphHopperCustomSpeedsTest {
4748
private static final String GH_LOCATION = "target/graphhopper-test-gh";
4849
private static final String GH_LOCATION_CUSTOM_SPEEDS = "target/graphhopper-test-gh-custom_speeds";
4950

51+
private static final String GH_LOCATION_CUSTOM_SPEEDS_RELOAD = "target/graphhopper-test-gh-custom_speeds-reload";
52+
5053
@BeforeEach
5154
@AfterEach
5255
public void setup() {
@@ -266,5 +269,65 @@ public Optional<SpeedKmByHour> speedForRoadClass(RoadClass roadClass) {
266269

267270
}
268271

272+
@Test
273+
public void testEncodingManagerStorePropertiesAfterSetCustomSpeeds() {
274+
275+
// For bike, the max encoder speed is 30kmh
276+
class SpeedsTooHighSpeedProvider implements WaySpeedsProvider {
277+
278+
@Override
279+
public Optional<SpeedKmByHour> speedForWay(long osmWayId) {
280+
return Optional.of(new SpeedKmByHour(28));
281+
}
282+
283+
@Override
284+
public Optional<SpeedKmByHour> speedForRoadClass(RoadClass roadClass) {
285+
return Optional.of(new SpeedKmByHour(28));
286+
}
287+
}
288+
289+
final String bikeProfile = "bike_profile";
290+
291+
List<Profile> profiles = asList(
292+
new Profile(bikeProfile).setVehicle("bike")
293+
);
294+
295+
GraphHopper hopperCustomSpeeds = new GraphHopperCustomSpeeds(new SpeedsTooHighSpeedProvider()).
296+
setGraphHopperLocation(GH_LOCATION_CUSTOM_SPEEDS_RELOAD).
297+
setOSMFile(MONACO).
298+
setProfiles(profiles).
299+
setStoreOnFlush(true)
300+
.setEncodedValuesString("roundabout, road_class, road_class_link, road_environment, max_speed, road_access, ferry_speed, bike_network, get_off_bike, smoothness, osm_way_id");
301+
hopperCustomSpeeds.getCHPreparationHandler().setCHProfiles(
302+
new CHProfile(bikeProfile)
303+
);
304+
305+
hopperCustomSpeeds.importOrLoad();
306+
307+
double maxSpeed = hopperCustomSpeeds.getEncodingManager().getDecimalEncodedValue(VehicleSpeed.key("bike")).getMaxOrMaxStorableDecimal();
308+
309+
hopperCustomSpeeds.close();
310+
311+
GraphHopper loadHopperCustomSpeeds = new GraphHopper().
312+
setGraphHopperLocation(GH_LOCATION_CUSTOM_SPEEDS_RELOAD).
313+
setOSMFile(MONACO).
314+
setProfiles(profiles)
315+
.setEncodedValuesString("roundabout, road_class, road_class_link, road_environment, max_speed, road_access, ferry_speed, bike_network, get_off_bike, smoothness, osm_way_id");
316+
hopperCustomSpeeds.getCHPreparationHandler().setCHProfiles(
317+
new CHProfile(bikeProfile)
318+
);
319+
320+
loadHopperCustomSpeeds.importOrLoad();
321+
322+
double loadMaxSpeed = loadHopperCustomSpeeds.getEncodingManager().getDecimalEncodedValue(VehicleSpeed.key("bike")).getMaxOrMaxStorableDecimal();
323+
324+
loadHopperCustomSpeeds.close();
325+
326+
assertEquals(maxSpeed, loadMaxSpeed, 1);
327+
328+
}
329+
330+
331+
269332
}
270333

0 commit comments

Comments
 (0)