Skip to content

Remove circular dependency between graph and vertex linker #6686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: dev-2.x
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.opentripplanner.routing.graphfinder.DirectGraphFinder;
import org.opentripplanner.routing.graphfinder.NearbyStop;
import org.opentripplanner.routing.graphfinder.StreetGraphFinder;
import org.opentripplanner.routing.linking.VertexLinker;
import org.opentripplanner.street.model.vertex.TransitStopVertex;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.service.TimetableRepository;
Expand All @@ -41,17 +42,20 @@ public class DirectTransferAnalyzer implements GraphBuilderModule {
private static final Logger LOG = LoggerFactory.getLogger(DirectTransferAnalyzer.class);

private final Graph graph;
private final VertexLinker linker;
private final TimetableRepository timetableRepository;
private final DataImportIssueStore issueStore;
private final double radiusMeters;

public DirectTransferAnalyzer(
Graph graph,
VertexLinker linker,
TimetableRepository timetableRepository,
DataImportIssueStore issueStore,
double radiusMeters
) {
this.graph = graph;
this.linker = linker;
this.timetableRepository = timetableRepository;
this.issueStore = issueStore;
this.radiusMeters = radiusMeters;
Expand All @@ -70,7 +74,7 @@ public void buildGraph() {
DirectGraphFinder nearbyStopFinderEuclidian = new DirectGraphFinder(
timetableRepository.getSiteRepository()::findRegularStops
);
StreetGraphFinder nearbyStopFinderStreets = new StreetGraphFinder(graph);
StreetGraphFinder nearbyStopFinderStreets = new StreetGraphFinder(graph, linker);

int stopsAnalyzed = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,20 @@ public class OsmBoardingLocationsModule implements GraphBuilderModule {
@Inject
public OsmBoardingLocationsModule(
Graph graph,
VertexLinker linker,
OsmInfoGraphBuildService osmInfoGraphBuildService
) {
this.graph = graph;
this.osmInfoGraphBuildService = osmInfoGraphBuildService;
this.vertexFactory = new VertexFactory(graph);
this.linker = linker;
}

@Override
public void buildGraph() {
LOG.info("Improving boarding locations by checking OSM entities...");

this.linker = graph.getLinkerSafe();
graph.index();
int successes = 0;

for (TransitStopVertex ts : graph.getVerticesOfType(TransitStopVertex.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opentripplanner.graph_builder.issues.ParkAndRideEntranceRemoved;
import org.opentripplanner.graph_builder.model.GraphBuilderModule;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.linking.VertexLinker;
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
import org.opentripplanner.service.vehicleparking.model.VehicleParking;
import org.opentripplanner.service.vehicleparking.model.VehicleParkingHelper;
Expand Down Expand Up @@ -52,30 +53,26 @@ public class StreetLinkerModule implements GraphBuilderModule {
private final VehicleParkingRepository parkingRepository;
private final TimetableRepository timetableRepository;
private final DataImportIssueStore issueStore;
private final boolean areaVisibility;
private final int maxAreaNodes;
private final VertexLinker vertexLinker;

public StreetLinkerModule(
Graph graph,
VertexLinker linker,
VehicleParkingRepository parkingRepository,
TimetableRepository timetableRepository,
DataImportIssueStore issueStore,
boolean areaVisibility,
int maxAreaNodes
DataImportIssueStore issueStore
) {
this.graph = graph;
this.parkingRepository = parkingRepository;
this.timetableRepository = timetableRepository;
this.issueStore = issueStore;
this.areaVisibility = areaVisibility;
this.maxAreaNodes = maxAreaNodes;
this.vertexLinker = linker;
}

@Override
public void buildGraph() {
timetableRepository.index();
graph.getLinkerSafe().setAreaVisibility(this.areaVisibility);
graph.getLinkerSafe().setMaxAreaNodes(this.maxAreaNodes);
graph.requestIndex();

if (graph.hasStreets) {
linkTransitStops(graph, timetableRepository);
Expand Down Expand Up @@ -158,22 +155,20 @@ private static boolean isAlreadyLinked(
* edge. This may lead to several links being created.
*/
private void linkStopToStreetNetwork(TransitStopVertex tStop, StopLinkType linkType) {
graph
.getLinker()
.linkVertexPermanently(
tStop,
WALK_ONLY,
LinkingDirection.BIDIRECTIONAL,
(transitVertex, streetVertex) -> {
var linkEdges = createStopLinkEdges((TransitStopVertex) transitVertex, streetVertex);

if (linkType == StopLinkType.WALK_AND_CAR && !streetVertex.isConnectedToDriveableEdge()) {
linkToDriveableEdge(tStop);
}

return linkEdges;
vertexLinker.linkVertexPermanently(
tStop,
WALK_ONLY,
LinkingDirection.BIDIRECTIONAL,
(transitVertex, streetVertex) -> {
var linkEdges = createStopLinkEdges((TransitStopVertex) transitVertex, streetVertex);

if (linkType == StopLinkType.WALK_AND_CAR && !streetVertex.isConnectedToDriveableEdge()) {
linkToDriveableEdge(tStop);
}
);

return linkEdges;
}
);
}

/**
Expand All @@ -185,15 +180,13 @@ private void linkStopToStreetNetwork(TransitStopVertex tStop, StopLinkType linkT
* @see https://github.com/opentripplanner/OpenTripPlanner/issues/5498
*/
private void linkToDriveableEdge(TransitStopVertex tStop) {
graph
.getLinker()
.linkVertexPermanently(
tStop,
CAR_ONLY,
LinkingDirection.BIDIRECTIONAL,
(transitVertex, streetVertex) ->
createStopLinkEdges((TransitStopVertex) transitVertex, streetVertex)
);
vertexLinker.linkVertexPermanently(
tStop,
CAR_ONLY,
LinkingDirection.BIDIRECTIONAL,
(transitVertex, streetVertex) ->
createStopLinkEdges((TransitStopVertex) transitVertex, streetVertex)
);
}

private static List<Edge> createStopLinkEdges(
Expand All @@ -206,74 +199,65 @@ private static List<Edge> createStopLinkEdges(
);
}

private static void linkVehicleParkingWithLinker(
Graph graph,
VehicleParkingEntranceVertex vehicleParkingVertex
) {
private void linkVehicleParkingWithLinker(VehicleParkingEntranceVertex vehicleParkingVertex) {
if (vehicleParkingVertex.isWalkAccessible()) {
graph
.getLinker()
.linkVertexPermanently(
vehicleParkingVertex,
new TraverseModeSet(TraverseMode.WALK),
LinkingDirection.BIDIRECTIONAL,
(vertex, streetVertex) ->
List.of(
StreetVehicleParkingLink.createStreetVehicleParkingLink(
(VehicleParkingEntranceVertex) vertex,
streetVertex
),
StreetVehicleParkingLink.createStreetVehicleParkingLink(
streetVertex,
(VehicleParkingEntranceVertex) vertex
)
vertexLinker.linkVertexPermanently(
vehicleParkingVertex,
new TraverseModeSet(TraverseMode.WALK),
LinkingDirection.BIDIRECTIONAL,
(vertex, streetVertex) ->
List.of(
StreetVehicleParkingLink.createStreetVehicleParkingLink(
(VehicleParkingEntranceVertex) vertex,
streetVertex
),
StreetVehicleParkingLink.createStreetVehicleParkingLink(
streetVertex,
(VehicleParkingEntranceVertex) vertex
)
);
)
);
}

if (vehicleParkingVertex.isCarAccessible()) {
graph
.getLinker()
.linkVertexPermanently(
vehicleParkingVertex,
new TraverseModeSet(TraverseMode.CAR),
LinkingDirection.BIDIRECTIONAL,
(vertex, streetVertex) ->
List.of(
StreetVehicleParkingLink.createStreetVehicleParkingLink(
(VehicleParkingEntranceVertex) vertex,
streetVertex
),
StreetVehicleParkingLink.createStreetVehicleParkingLink(
streetVertex,
(VehicleParkingEntranceVertex) vertex
)
vertexLinker.linkVertexPermanently(
vehicleParkingVertex,
new TraverseModeSet(TraverseMode.CAR),
LinkingDirection.BIDIRECTIONAL,
(vertex, streetVertex) ->
List.of(
StreetVehicleParkingLink.createStreetVehicleParkingLink(
(VehicleParkingEntranceVertex) vertex,
streetVertex
),
StreetVehicleParkingLink.createStreetVehicleParkingLink(
streetVertex,
(VehicleParkingEntranceVertex) vertex
)
);
)
);
}
}

private void linkTransitEntrances(Graph graph) {
LOG.info("Linking transit entrances to graph...");
for (TransitEntranceVertex tEntrance : graph.getVerticesOfType(TransitEntranceVertex.class)) {
graph
.getLinker()
.linkVertexPermanently(
tEntrance,
new TraverseModeSet(TraverseMode.WALK),
LinkingDirection.BIDIRECTIONAL,
(vertex, streetVertex) ->
List.of(
StreetTransitEntranceLink.createStreetTransitEntranceLink(
(TransitEntranceVertex) vertex,
streetVertex
),
StreetTransitEntranceLink.createStreetTransitEntranceLink(
streetVertex,
(TransitEntranceVertex) vertex
)
vertexLinker.linkVertexPermanently(
tEntrance,
new TraverseModeSet(TraverseMode.WALK),
LinkingDirection.BIDIRECTIONAL,
(vertex, streetVertex) ->
List.of(
StreetTransitEntranceLink.createStreetTransitEntranceLink(
(TransitEntranceVertex) vertex,
streetVertex
),
StreetTransitEntranceLink.createStreetTransitEntranceLink(
streetVertex,
(TransitEntranceVertex) vertex
)
);
)
);
}
}

Expand All @@ -294,14 +278,12 @@ private void linkStationCentroids(Graph graph) {
);

for (StationCentroidVertex station : graph.getVerticesOfType(StationCentroidVertex.class)) {
graph
.getLinker()
.linkVertexPermanently(
station,
new TraverseModeSet(TraverseMode.WALK),
LinkingDirection.BIDIRECTIONAL,
stationAndStreetVertexLinker
);
vertexLinker.linkVertexPermanently(
station,
new TraverseModeSet(TraverseMode.WALK),
LinkingDirection.BIDIRECTIONAL,
stationAndStreetVertexLinker
);
}
}

Expand All @@ -316,7 +298,7 @@ private void linkVehicleParks(Graph graph, DataImportIssueStore issueStore) {
}

if (vehicleParkingEntranceVertex.getParkingEntrance().getVertex() == null) {
linkVehicleParkingWithLinker(graph, vehicleParkingEntranceVertex);
linkVehicleParkingWithLinker(vehicleParkingEntranceVertex);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.opentripplanner.netex.NetexModule;
import org.opentripplanner.routing.fares.FareServiceFactory;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.linking.VertexLinker;
import org.opentripplanner.routing.linking.configure.VertexLinkerGraphBuildingModule;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.osminfo.configure.OsmInfoGraphBuildServiceModule;
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
Expand All @@ -47,6 +49,7 @@
GraphBuilderModules.class,
OsmInfoGraphBuildServiceModule.class,
EmissionGraphBuilderModule.class,
VertexLinkerGraphBuildingModule.class,
}
)
public interface GraphBuilderFactory {
Expand Down Expand Up @@ -83,6 +86,8 @@ public interface GraphBuilderFactory {

FareServiceFactory fareServiceFactory();

VertexLinker vertexLinker();

@Component.Builder
interface Builder {
@BindsInstance
Expand Down
Loading
Loading