|
20 | 20 | import com.graphhopper.config.CHProfile;
|
21 | 21 | import com.graphhopper.config.Profile;
|
22 | 22 | import com.graphhopper.routing.ev.RoadClass;
|
| 23 | +import com.graphhopper.routing.ev.VehicleSpeed; |
23 | 24 | import com.graphhopper.speeds.SpeedKmByHour;
|
24 | 25 | import com.graphhopper.speeds.WaySpeedsProvider;
|
25 | 26 | import com.graphhopper.util.*;
|
@@ -47,6 +48,8 @@ public class GraphHopperCustomSpeedsTest {
|
47 | 48 | private static final String GH_LOCATION = "target/graphhopper-test-gh";
|
48 | 49 | private static final String GH_LOCATION_CUSTOM_SPEEDS = "target/graphhopper-test-gh-custom_speeds";
|
49 | 50 |
|
| 51 | + private static final String GH_LOCATION_CUSTOM_SPEEDS_RELOAD = "target/graphhopper-test-gh-custom_speeds-reload"; |
| 52 | + |
50 | 53 | @BeforeEach
|
51 | 54 | @AfterEach
|
52 | 55 | public void setup() {
|
@@ -266,5 +269,65 @@ public Optional<SpeedKmByHour> speedForRoadClass(RoadClass roadClass) {
|
266 | 269 |
|
267 | 270 | }
|
268 | 271 |
|
| 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 | + |
269 | 332 | }
|
270 | 333 |
|
0 commit comments