public static Optional<AtlasPrimitiveRoute> from(final Route route) { if (route != null && route.size() > 0) { return Optional.of( new AtlasPrimitiveRoute(Iterables.translate(route, AtlasPrimitiveEdge::from))); } return Optional.empty(); }
/** * Determine if this route starts with the {@link Route} passed in. * * @param other * The {@link Route} to compare * @return true if this route starts with the route passed in */ public boolean startsWith(final Route other) { // If the other route is longer than this route, return false if (other.size() > this.size()) { return false; } final Iterator<Edge> otherIterator = other.iterator(); final Iterator<Edge> thisIterator = this.iterator(); // otherIterator has to be shorter than thisIterator, so loop over otherIterator while (otherIterator.hasNext()) { final Edge otherEdge = otherIterator.next(); final Edge thisEdge = thisIterator.next(); if (!thisEdge.equals(otherEdge)) { return false; } } return true; }
@Override public int indexOf(final Edge edge) { final int indexUp = this.upstream.indexOf(edge); if (indexUp >= 0) { return indexUp; } final int indexDown = this.downstream.indexOf(edge); if (indexDown >= 0) { return this.upstream.size() + indexDown; } return indexDown; }
if (candidateRoute.size() > 1)
@Override public boolean equals(final Object other) { if (other instanceof Route) { final Route that = (Route) other; if (this.size() == that.size()) { return new EqualsBuilder() .append(this.start().start().getLocation(), that.start().start().getLocation()) .append(this.end().end().getLocation(), that.end().end().getLocation()) .append(Iterables.asList(this), Iterables.asList(that)).isEquals(); } } return false; }
protected ComplexTurnRestriction(final AtlasEntity source, final Predicate<Edge> validEdge) { super(source); try { this.turnRestriction = TurnRestriction.from((Relation) source) .orElseThrow(() -> new CoreException( "{} is not a turn restriction according to Atlas", source.getIdentifier())); final Route route = this.turnRestriction.route(); final int routeLength = route.size(); if (routeLength < 2) { throw new CoreException("Must have at least two edges in the route"); } final long filteredLength = StreamSupport.stream(route.spliterator(), false) .filter(validEdge).count(); if (filteredLength < routeLength) { throw new CoreException("{} invalid edges", routeLength - filteredLength); } } catch (final Exception oops) { logger.trace("Unable to create ComplexTurnRestriction from {}", source, oops); setInvalidReason("Couldn't create ComplexTurnRestriction", oops); } }
final int numberOfEdges = this.size();
@Override public Edge get(final int index) { final int size = size(); if (index < 0 || index >= size) { throw new CoreException("Index {} out of Route's bounds: size = {}", index, size); } else { final int upstreamSize = this.upstream.size(); if (index < upstreamSize) { return this.upstream.get(index); } else { return this.downstream.get(index - upstreamSize); } } }
for (int index = 1; index < bigNodeRoute.size(); index++)
for (int index = 1; index < bigNodeRoute.size(); index++)
@Test public void testDeserializedIntegrity() { final Atlas deserialized = deserialized(); final Route route = AStarRouter.balanced(deserialized, Distance.meters(100)) .route(deserialized.edge(9), deserialized.edge(98)); Assert.assertEquals(2, route.size()); }
@Test public void testOverlappingNodesCrossingEdges() { final Atlas subAtlas1 = this.setup.overlappingAndCrossingSubAtlas1(); final Atlas subAtlas2 = this.setup.overlappingAndCrossingSubAtlas2(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); final Router router = AStarRouter.dijkstra(multiAtlas, Distance.meters(40)); final Route route1 = router.route( Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_5_LOCATION), Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_8_LOCATION)); Assert.assertEquals(2, route1.size()); final Route route2 = router.route( Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_5_LOCATION), Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_9_LOCATION)); Assert.assertEquals(2, route2.size()); }
@Test public void testOverlappingNodes() { final Atlas subAtlas1 = this.setup.overlappingSubAtlas1(); final Atlas subAtlas2 = this.setup.overlappingSubAtlas2(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); final Router router = AStarRouter.dijkstra(multiAtlas, Distance.meters(40)); final Route route = router.route( Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_5_LOCATION), Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_8_LOCATION)); Assert.assertEquals(2, route.size()); }
@Test public void testOverlappingAtAntimeridian() { final Atlas subAtlas1 = this.setup.subAtlasOnAntimeridianEast(); final Atlas subAtlas2 = this.setup.subAtlasOnAntimeridianWest(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); final Router router = AStarRouter.dijkstra(multiAtlas, Distance.meters(40)); final Route route = router.route( Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_1_LOCATION), Location.forString(MultiAtlasOverlappingNodesFixerTestRule.POINT_4_LOCATION)); Assert.assertEquals(2, route.size()); }
@Test public void testThreeSubAtlas() { final Atlas subAtlas1 = this.setup.aSubAtlas(); final Atlas subAtlas2 = this.setup.anotherSubAtlas(); final Atlas subAtlas3 = this.setup.aThirdSubAtlas(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2, subAtlas3); // Verify route final Route route = AStarRouter.dijkstra(multiAtlas, Distance.TEN_MILES).route( Location.forString(MultiAtlasBorderFixerTestRule.POINT_1_LOCATION), Location.forString(MultiAtlasBorderFixerTestRule.POINT_5_LOCATION)); Assert.assertEquals(4, route.size()); // Verify this inconsistent edge is gone Assert.assertNull(multiAtlas.edge(223456789120000L)); }