Skip to content

Commit

Permalink
Merge pull request #5732 from entur/fix_roundabout_direct_routing
Browse files Browse the repository at this point in the history
Fix street routing on roundabout
  • Loading branch information
vpaturet authored Mar 20, 2024
2 parents 3d23683 + b2ee65f commit 384e1e6
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean isEquivalentTo(Edge e) {
/**
* Returns true if this edge is the reverse of another.
*/
public boolean isReverseOf(Edge e) {
public final boolean isReverseOf(Edge e) {
return (this.getFromVertex() == e.getToVertex() && this.getToVertex() == e.getFromVertex());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ public boolean isEquivalentTo(Edge e) {
return (e == this || e == parentEdge);
}

@Override
public boolean isReverseOf(Edge e) {
Edge other = e;
if (e instanceof TemporaryPartialStreetEdge) {
other = ((TemporaryPartialStreetEdge) e).parentEdge;
}

// TODO(flamholz): is there a case where a partial edge has a reverse of its own?
return parentEdge.isReverseOf(other);
}

/**
* Returns true if this edge is trivial - beginning and ending at the same point.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.opentripplanner.street.integration;

import java.time.Instant;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.opentripplanner.ConstantsForTests;
import org.opentripplanner.TestOtpModel;
import org.opentripplanner.astar.model.GraphPath;
import org.opentripplanner.model.GenericLocation;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.api.request.StreetMode;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.impl.GraphPathFinder;
import org.opentripplanner.street.model.edge.Edge;
import org.opentripplanner.street.model.vertex.Vertex;
import org.opentripplanner.street.search.TemporaryVerticesContainer;
import org.opentripplanner.street.search.state.State;
import org.opentripplanner.test.support.ResourceLoader;

class WalkRoutingTest {

static final Instant dateTime = Instant.now();
private final Graph roundabout;

{
TestOtpModel model = ConstantsForTests.buildOsmGraph(
ResourceLoader.of(WalkRoutingTest.class).file("roundabout.osm.pbf")
);
roundabout = model.graph();

model.transitModel().index();
roundabout.index(model.transitModel().getStopModel());
}

/**
* Both https://www.openstreetmap.org/way/146988098 and
* https://www.openstreetmap.org/way/146988099 are routable for pedestrians, the routing engine
* should return a path from any point of the first way to any point of the second.
* <br>
* See also <a href="https://github.com/opentripplanner/OpenTripPlanner/issues/5706">issue
* #5706</a>
*/
@Test
void shouldRouteAroundRoundabout() {
var start = new GenericLocation(59.94646, 10.77511);
var end = new GenericLocation(59.94641, 10.77522);
Assertions.assertDoesNotThrow(() -> route(roundabout, start, end));
}

private static List<GraphPath<State, Edge, Vertex>> route(
Graph graph,
GenericLocation from,
GenericLocation to
) {
RouteRequest request = new RouteRequest();
request.setDateTime(dateTime);
request.setFrom(from);
request.setTo(to);
request.journey().direct().setMode(StreetMode.WALK);

try (
var temporaryVertices = new TemporaryVerticesContainer(
graph,
request,
request.journey().direct().mode(),
request.journey().direct().mode()
)
) {
var gpf = new GraphPathFinder(null);
return gpf.graphPathFinderEntryPoint(request, temporaryVertices);
}
}
}
Binary file not shown.

0 comments on commit 384e1e6

Please sign in to comment.