Skip to content

Commit

Permalink
Merge branch 'area-walk-linking' into dev-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
optionsome committed Mar 16, 2023
2 parents d822282 + 05c07ae commit a4395f3
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ private boolean connectVertexToStop(TransitStopVertex ts, StreetIndex index, Gra
new TraverseModeSet(TraverseMode.WALK),
LinkingDirection.BOTH_WAYS,
(osmBoardingLocationVertex, splitVertex) -> {
if (osmBoardingLocationVertex == splitVertex) {
return List.of();
}
// the OSM boarding location vertex is not connected to the street network, so we
// need to link it first
return List.of(
Expand Down Expand Up @@ -170,8 +173,7 @@ private boolean connectVertexToStop(TransitStopVertex ts, StreetIndex index, Gra
name,
edgeList.references
);
edgeList.addVertex(boardingLocation);

linker.addPermanentAreaVertex(boardingLocation, edgeList);
linkBoardingLocationToStop(ts, stopCode, boardingLocation);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ public static TransitRouterResult route(
additionalSearchDays,
debugTimingAggregator
);
return transitRouter.route();
try (
var temporaryVertices = new TemporaryVerticesContainer(
serverContext.graph(),
request,
request.journey().access().mode(),
request.journey().egress().mode()
)
) {
return transitRouter.route(temporaryVertices);
}
}

private TransitRouterResult route() {
private TransitRouterResult route(TemporaryVerticesContainer temporaryVertices) {
if (!request.journey().transit().enabled()) {
return new TransitRouterResult(List.of(), null);
}
Expand All @@ -92,7 +101,7 @@ private TransitRouterResult route() {

debugTimingAggregator.finishedPatternFiltering();

var accessEgresses = getAccessEgresses();
var accessEgresses = getAccessEgresses(temporaryVertices);

debugTimingAggregator.finishedAccessEgress(
accessEgresses.getAccesses().size(),
Expand Down Expand Up @@ -150,46 +159,37 @@ private TransitRouterResult route() {
return new TransitRouterResult(itineraries, transitResponse.requestUsed().searchParams());
}

private AccessEgresses getAccessEgresses() {
private AccessEgresses getAccessEgresses(TemporaryVerticesContainer temporaryVertices) {
var accessEgressMapper = new AccessEgressMapper();
var accessList = new ArrayList<DefaultAccessEgress>();
var egressList = new ArrayList<DefaultAccessEgress>();

try (
var temporaryVertices = new TemporaryVerticesContainer(
serverContext.graph(),
request,
request.journey().access().mode(),
request.journey().egress().mode()
)
) {
var accessCalculator = (Runnable) () -> {
debugTimingAggregator.startedAccessCalculating();
accessList.addAll(getAccessEgresses(accessEgressMapper, temporaryVertices, false));
debugTimingAggregator.finishedAccessCalculating();
};

var egressCalculator = (Runnable) () -> {
debugTimingAggregator.startedEgressCalculating();
egressList.addAll(getAccessEgresses(accessEgressMapper, temporaryVertices, true));
debugTimingAggregator.finishedEgressCalculating();
};

if (OTPFeature.ParallelRouting.isOn()) {
try {
CompletableFuture
.allOf(
CompletableFuture.runAsync(accessCalculator),
CompletableFuture.runAsync(egressCalculator)
)
.join();
} catch (CompletionException e) {
RoutingValidationException.unwrapAndRethrowCompletionException(e);
}
} else {
accessCalculator.run();
egressCalculator.run();
var accessCalculator = (Runnable) () -> {
debugTimingAggregator.startedAccessCalculating();
accessList.addAll(getAccessEgresses(accessEgressMapper, temporaryVertices, false));
debugTimingAggregator.finishedAccessCalculating();
};

var egressCalculator = (Runnable) () -> {
debugTimingAggregator.startedEgressCalculating();
egressList.addAll(getAccessEgresses(accessEgressMapper, temporaryVertices, true));
debugTimingAggregator.finishedEgressCalculating();
};

if (OTPFeature.ParallelRouting.isOn()) {
try {
CompletableFuture
.allOf(
CompletableFuture.runAsync(accessCalculator),
CompletableFuture.runAsync(egressCalculator)
)
.join();
} catch (CompletionException e) {
RoutingValidationException.unwrapAndRethrowCompletionException(e);
}
} else {
accessCalculator.run();
egressCalculator.run();
}

verifyAccessEgress(accessList, egressList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import org.opentripplanner.framework.geometry.GeometryUtils;
import org.opentripplanner.street.model.StreetTraversalPermission;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.vertex.SplitterVertex;
import org.opentripplanner.street.model.vertex.IntersectionVertex;
import org.opentripplanner.transit.model.site.AreaStop;
import org.opentripplanner.transit.service.StopModel;

class FlexLocationAdder {

static void addFlexLocations(StreetEdge edge, SplitterVertex v0, StopModel stopModel) {
static void addFlexLocations(StreetEdge edge, IntersectionVertex v0, StopModel stopModel) {
if (edge.getPermission().allows(StreetTraversalPermission.PEDESTRIAN_AND_CAR)) {
Point p = GeometryUtils.getGeometryFactory().createPoint(v0.getCoordinate());
Envelope env = p.getEnvelopeInternal();
Expand Down
Loading

0 comments on commit a4395f3

Please sign in to comment.