|
1 | 1 | package com.conveyal.r5.streets; |
2 | 2 |
|
3 | 3 | import com.conveyal.osmlib.OSM; |
| 4 | +import com.conveyal.r5.analyst.FreeFormPointSet; |
| 5 | +import com.conveyal.r5.analyst.cluster.TransportNetworkConfig; |
4 | 6 | import com.conveyal.r5.profile.StreetMode; |
| 7 | +import com.conveyal.r5.streets.EdgeStore.Edge; |
| 8 | +import com.conveyal.r5.streets.EdgeStore.EdgeFlag; |
5 | 9 | import com.conveyal.r5.streets.VertexStore.VertexFlag; |
6 | 10 | import gnu.trove.TIntCollection; |
7 | 11 | import gnu.trove.iterator.TIntIterator; |
|
16 | 20 |
|
17 | 21 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
18 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
19 | 24 | import static org.junit.jupiter.api.Assertions.assertFalse; |
20 | 25 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
21 | 26 | import static org.junit.jupiter.api.Assertions.assertTrue; |
@@ -420,4 +425,69 @@ public void testMissingNodes () { |
420 | 425 | }); |
421 | 426 | } |
422 | 427 |
|
| 428 | + /** |
| 429 | + * Make sure that the stop linking and split distance calculations are affected by their configuration options. |
| 430 | + */ |
| 431 | + @Test |
| 432 | + public void testConfigurableSplitDistancesAndIslandRemoval() { |
| 433 | + int[] exponents = {0, 1, 2}; |
| 434 | + // to test different options, do this three times with values doubling each time |
| 435 | + for (int exponent : exponents) { |
| 436 | + int multiplier = (int) Math.pow(2, exponent); |
| 437 | + |
| 438 | + OSM osm = new OSM(null); |
| 439 | + osm.intersectionDetection = true; |
| 440 | + // re-use one of our existing resources, rather than bloating the repo with a new one just for this test |
| 441 | + osm.readFromUrl(StreetLayerTest.class.getResource("reisterstown-via-restriction.pbf").toString()); |
| 442 | + |
| 443 | + TransportNetworkConfig cfg = new TransportNetworkConfig(); |
| 444 | + cfg.stopLinkRadiusMeters = 50d * multiplier; |
| 445 | + cfg.pointsetLinkRadiusMeters = 100d * multiplier; |
| 446 | + cfg.minSubgraphSize = 5 * multiplier; |
| 447 | + |
| 448 | + StreetLayer sl = new StreetLayer(cfg); |
| 449 | + sl.loadFromOsm(osm, true, true); |
| 450 | + sl.buildEdgeLists(); |
| 451 | + sl.indexStreets(); |
| 452 | + |
| 453 | + assertEquals(sl.getStopLinkRadiusMeters(), 50d * multiplier); |
| 454 | + assertEquals(sl.getPointsetLinkRadiusMeters(), 100d * multiplier); |
| 455 | + assertEquals(sl.getMinSubgraphSize(), 5 * multiplier); |
| 456 | + |
| 457 | + // This is an island with size 6: https://www.openstreetmap.org/way/140476882#map=19/39.409392/-76.642615&layers=D |
| 458 | + // Because it is at the edge of the PBF, West Joppa Road is not in the PBF, so Riderwood Stn and |
| 459 | + // connected driveways form an island. Because the driveways are marked access=private and thus No Thru Traffic, |
| 460 | + // they are not considered part of the island, and the nodes at the ends of them are separate islands, so the |
| 461 | + // only nodes are the end of the street, where it intersects itself, and where it intersects each driveway. |
| 462 | + // there should still be permissions around it |
| 463 | + int eid = sl.edgeStore.osmids.indexOf(140476882L); |
| 464 | + // seek to the forward edge (edge pair * 2) |
| 465 | + Edge e = sl.edgeStore.getCursor(eid * 2); |
| 466 | + // this island should be removed if exponent equals 1 or 2 (min subgraph size equals 10 or 20) |
| 467 | + // island removal is done by removing permissions |
| 468 | + assertEquals(e.allowsStreetMode(StreetMode.WALK), exponent == 0); |
| 469 | + // make sure we are looking at the correct edge |
| 470 | + assertEquals(e.getOSMID(), 140476882L); |
| 471 | + |
| 472 | + // this location is about 150 m from road |
| 473 | + double lat = 39.408907; |
| 474 | + double lon = -76.736807; |
| 475 | + |
| 476 | + // getOrCreateVertexNear is used to link stops, so when exponent is 0 or 1 (stop distance is 50 or 100), |
| 477 | + // should not link |
| 478 | + if (exponent == 0 || exponent == 1) assertEquals(sl.getOrCreateVertexNear(lat, lon, StreetMode.WALK), -1); |
| 479 | + else assertNotEquals(sl.getOrCreateVertexNear(lat, lon, StreetMode.WALK), -1); |
| 480 | + |
| 481 | + FreeFormPointSet ps = new FreeFormPointSet(new Coordinate(lon, lat)); |
| 482 | + LinkedPointSet lps = new LinkedPointSet(ps, sl, StreetMode.WALK, null); |
| 483 | + // linked point sets should only be unlinked when exponent is 0 (pointset distance is 100) |
| 484 | + if (exponent == 0) assertEquals(lps.edges[0], -1); |
| 485 | + else assertNotEquals(lps.edges[0], -1); |
| 486 | + |
| 487 | + // street router linking should behave same way |
| 488 | + StreetRouter r = new StreetRouter(sl); |
| 489 | + assertEquals(r.setOrigin(lat, lon), exponent != 0); |
| 490 | + assertEquals(r.setDestination(lat, lon), exponent != 0); |
| 491 | + } |
| 492 | + } |
423 | 493 | } |
0 commit comments