Skip to content

Commit

Permalink
Merge commit '3825a024000a7bc576ab2f5a19b44bb1dd333822' into boarding…
Browse files Browse the repository at this point in the history
…-locations
  • Loading branch information
miklcct committed Dec 19, 2024
2 parents 0771f0f + 3825a02 commit 12e5eb2
Show file tree
Hide file tree
Showing 29 changed files with 355 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import org.opentripplanner.graph_builder.issue.api.DataImportIssueSummary;
import org.opentripplanner.graph_builder.model.GraphBuilderModule;
import org.opentripplanner.graph_builder.module.configure.DaggerGraphBuilderFactory;
import org.opentripplanner.graph_builder.module.configure.GraphBuilderFactory;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
import org.opentripplanner.service.worldenvelope.WorldEnvelopeRepository;
import org.opentripplanner.standalone.config.BuildConfig;
Expand Down Expand Up @@ -62,6 +64,7 @@ public static GraphBuilder create(
BuildConfig config,
GraphBuilderDataSources dataSources,
Graph graph,
OsmInfoGraphBuildRepository osmInfoGraphBuildRepository,
TimetableRepository timetableRepository,
WorldEnvelopeRepository worldEnvelopeRepository,
VehicleParkingRepository vehicleParkingService,
Expand All @@ -78,10 +81,11 @@ public static GraphBuilder create(

timetableRepository.initTimeZone(config.transitModelTimeZone);

var builder = DaggerGraphBuilderFactory
.builder()
GraphBuilderFactory.Builder builder = DaggerGraphBuilderFactory.builder();
builder
.config(config)
.graph(graph)
.osmInfoGraphBuildRepository(osmInfoGraphBuildRepository)
.timetableRepository(timetableRepository)
.worldEnvelopeRepository(worldEnvelopeRepository)
.vehicleParkingRepository(vehicleParkingService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.opentripplanner.routing.graph.index.StreetIndex;
import org.opentripplanner.routing.linking.LinkingDirection;
import org.opentripplanner.routing.linking.VertexLinker;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildService;
import org.opentripplanner.street.model.StreetTraversalPermission;
import org.opentripplanner.street.model.edge.AreaEdge;
import org.opentripplanner.street.model.edge.BoardingLocationToStopLink;
Expand Down Expand Up @@ -63,14 +64,20 @@ public class OsmBoardingLocationsModule implements GraphBuilderModule {

private final Graph graph;

private final OsmInfoGraphBuildService osmInfoGraphBuildService;
private final TimetableRepository timetableRepository;
private final VertexFactory vertexFactory;

private VertexLinker linker;

@Inject
public OsmBoardingLocationsModule(Graph graph, TimetableRepository timetableRepository) {
public OsmBoardingLocationsModule(
Graph graph,
OsmInfoGraphBuildService osmInfoGraphBuildService,
TimetableRepository timetableRepository
) {
this.graph = graph;
this.osmInfoGraphBuildService = osmInfoGraphBuildService;
this.timetableRepository = timetableRepository;
this.vertexFactory = new VertexFactory(graph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
import org.opentripplanner.gtfs.graphbuilder.GtfsModule;
import org.opentripplanner.netex.NetexModule;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.osminfo.configure.OsmInfoGraphBuildServiceModule;
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
import org.opentripplanner.service.worldenvelope.WorldEnvelopeRepository;
import org.opentripplanner.standalone.config.BuildConfig;
import org.opentripplanner.street.model.StreetLimitationParameters;
import org.opentripplanner.transit.service.TimetableRepository;

@Singleton
@Component(modules = { GraphBuilderModules.class })
@Component(modules = { GraphBuilderModules.class, OsmInfoGraphBuildServiceModule.class })
public interface GraphBuilderFactory {
//DataImportIssueStore issueStore();
GraphBuilder graphBuilder();
Expand Down Expand Up @@ -80,6 +82,9 @@ interface Builder {
@BindsInstance
Builder timetableRepository(TimetableRepository timetableRepository);

@BindsInstance
Builder osmInfoGraphBuildRepository(OsmInfoGraphBuildRepository osmInfoGraphBuildRepository);

@BindsInstance
Builder worldEnvelopeRepository(WorldEnvelopeRepository worldEnvelopeRepository);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
import org.opentripplanner.osm.OsmProvider;
import org.opentripplanner.routing.api.request.preference.WalkPreferences;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
import org.opentripplanner.standalone.config.BuildConfig;
import org.opentripplanner.street.model.StreetLimitationParameters;
import org.opentripplanner.transit.service.TimetableRepository;

/**
* Configure all modules which is not simple enough to be injected.
* Configure all modules that are not simple enough to be injected.
*/
@Module
public class GraphBuilderModules {
Expand All @@ -60,7 +61,8 @@ static OsmModule provideOsmModule(
GraphBuilderDataSources dataSources,
BuildConfig config,
Graph graph,
VehicleParkingRepository parkingService,
OsmInfoGraphBuildRepository osmInfoGraphBuildRepository,
VehicleParkingRepository vehicleParkingRepository,
DataImportIssueStore issueStore,
StreetLimitationParameters streetLimitationParameters
) {
Expand All @@ -78,7 +80,7 @@ static OsmModule provideOsmModule(
}

return OsmModule
.of(providers, graph, parkingService)
.of(providers, graph, osmInfoGraphBuildRepository, vehicleParkingRepository)
.withEdgeNamer(config.edgeNamer)
.withAreaVisibility(config.areaVisibility)
.withPlatformEntriesLinking(config.platformEntriesLinking)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.opentripplanner.osm.wayproperty.WayProperties;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.util.ElevationUtils;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.osminfo.model.OsmWayReferences;
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
import org.opentripplanner.service.vehicleparking.model.VehicleParking;
import org.opentripplanner.street.model.StreetLimitationParameters;
Expand Down Expand Up @@ -55,7 +57,10 @@ public class OsmModule implements GraphBuilderModule {
*/
private final List<OsmProvider> providers;
private final Graph graph;
// TODO: Use this to store edge stop references
private final OsmInfoGraphBuildRepository osmInfoGraphBuildRepository;
private final VehicleParkingRepository parkingRepository;

private final DataImportIssueStore issueStore;
private final OsmProcessingParameters params;
private final SafetyValueNormalizer normalizer;
Expand All @@ -66,36 +71,40 @@ public class OsmModule implements GraphBuilderModule {
OsmModule(
Collection<OsmProvider> providers,
Graph graph,
VehicleParkingRepository parkingService,
OsmInfoGraphBuildRepository osmInfoGraphBuildRepository,
VehicleParkingRepository parkingRepository,
DataImportIssueStore issueStore,
StreetLimitationParameters streetLimitationParameters,
OsmProcessingParameters params
) {
this.providers = List.copyOf(providers);
this.graph = graph;
this.osmInfoGraphBuildRepository = osmInfoGraphBuildRepository;
this.parkingRepository = parkingRepository;
this.issueStore = issueStore;
this.params = params;
this.osmdb = new OsmDatabase(issueStore);
this.vertexGenerator = new VertexGenerator(osmdb, graph, params.boardingAreaRefTags());
this.normalizer = new SafetyValueNormalizer(graph, issueStore);
this.streetLimitationParameters = Objects.requireNonNull(streetLimitationParameters);
this.parkingRepository = parkingService;
}

public static OsmModuleBuilder of(
Collection<OsmProvider> providers,
Graph graph,
VehicleParkingRepository service
OsmInfoGraphBuildRepository osmInfoGraphBuildRepository,
VehicleParkingRepository vehicleParkingRepository
) {
return new OsmModuleBuilder(providers, graph, service);
return new OsmModuleBuilder(providers, graph, osmInfoGraphBuildRepository, vehicleParkingRepository);
}

public static OsmModuleBuilder of(
OsmProvider provider,
Graph graph,
VehicleParkingRepository service
OsmInfoGraphBuildRepository osmInfoGraphBuildRepository,
VehicleParkingRepository vehicleParkingRepository
) {
return of(List.of(provider), graph, service);
return of(List.of(provider), graph, osmInfoGraphBuildRepository, vehicleParkingRepository);
}

@Override
Expand Down Expand Up @@ -414,6 +423,8 @@ private void buildBasicGraph() {
StreetEdge backStreet = streets.back();
normalizer.applyWayProperties(street, backStreet, wayData, way);

osmInfoGraphBuildRepository.addReferences(street, new OsmWayReferences(List.of(street.toString())));

applyEdgesToTurnRestrictions(way, startNode, endNode, street, backStreet);
startNode = endNode;
osmStartNode = osmdb.getNode(startNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.opentripplanner.graph_builder.services.osm.EdgeNamer;
import org.opentripplanner.osm.OsmProvider;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
import org.opentripplanner.street.model.StreetLimitationParameters;

Expand All @@ -19,6 +20,7 @@ public class OsmModuleBuilder {
private final Collection<OsmProvider> providers;
private final Graph graph;
private final VehicleParkingRepository parkingRepository;
private final OsmInfoGraphBuildRepository osmInfoGraphBuildRepository;
private Set<String> boardingAreaRefTags = Set.of();
private DataImportIssueStore issueStore = DataImportIssueStore.NOOP;
private EdgeNamer edgeNamer = new DefaultNamer();
Expand All @@ -32,10 +34,12 @@ public class OsmModuleBuilder {
OsmModuleBuilder(
Collection<OsmProvider> providers,
Graph graph,
OsmInfoGraphBuildRepository osmInfoGraphBuildRepository,
VehicleParkingRepository parkingRepository
) {
this.providers = providers;
this.graph = graph;
this.osmInfoGraphBuildRepository = osmInfoGraphBuildRepository;
this.parkingRepository = parkingRepository;
}

Expand Down Expand Up @@ -88,6 +92,7 @@ public OsmModule build() {
return new OsmModule(
providers,
graph,
osmInfoGraphBuildRepository,
parkingRepository,
issueStore,
streetLimitationParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.opentripplanner.model.projectinfo.GraphFileHeader;
import org.opentripplanner.model.projectinfo.OtpProjectInfo;
import org.opentripplanner.routing.graph.kryosupport.KryoBuilder;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
import org.opentripplanner.service.worldenvelope.WorldEnvelopeRepository;
import org.opentripplanner.standalone.config.BuildConfig;
Expand Down Expand Up @@ -56,6 +57,10 @@ public class SerializedGraphObject implements Serializable {
private static final Logger LOG = LoggerFactory.getLogger(SerializedGraphObject.class);

public final Graph graph;

@Nullable
public final OsmInfoGraphBuildRepository osmInfoGraphBuildRepository;

public final TimetableRepository timetableRepository;
public final WorldEnvelopeRepository worldEnvelopeRepository;
private final Collection<Edge> edges;
Expand Down Expand Up @@ -84,6 +89,7 @@ public class SerializedGraphObject implements Serializable {

public SerializedGraphObject(
Graph graph,
@Nullable OsmInfoGraphBuildRepository osmInfoGraphBuildRepository,
TimetableRepository timetableRepository,
WorldEnvelopeRepository worldEnvelopeRepository,
VehicleParkingRepository parkingRepository,
Expand All @@ -96,6 +102,7 @@ public SerializedGraphObject(
) {
this.graph = graph;
this.edges = graph.getEdges();
this.osmInfoGraphBuildRepository = osmInfoGraphBuildRepository;
this.timetableRepository = timetableRepository;
this.worldEnvelopeRepository = worldEnvelopeRepository;
this.parkingRepository = parkingRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.opentripplanner.service.osminfo;

import java.io.Serializable;
import java.util.Optional;
import org.opentripplanner.service.osminfo.model.OsmWayReferences;
import org.opentripplanner.street.model.edge.Edge;

/**
* Store OSM data used during graph build, but after the OSM Graph Builder is done.
* <p>
* This is a repository to support the {@link OsmInfoGraphBuildService}.
*/
public interface OsmInfoGraphBuildRepository extends Serializable {
/**
* TODO Add doc
*/
void addReferences(Edge edge, OsmWayReferences info);

/**
* TODO Add doc
*/
Optional<OsmWayReferences> findReferences(Edge edge);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.opentripplanner.service.osminfo;

import java.util.Optional;
import org.opentripplanner.service.osminfo.model.OsmWayReferences;
import org.opentripplanner.street.model.edge.Edge;

/**
* The responsibility of this service is to provide information from Open Street Map, which
* is NOT in the OTP street graph. The graph build happens in phases, and some data is read in
* from the OSM files, but needed later on. For example, we might need info from OSM to link street
* edges/vertexes with transit stops/platforms. We do not want to put data in the OTP street graph
* unless it is relevant for routing. So, for information that is read by the OsmGraphBuilder, but
* needed later on, we have this service.
*
* THIS SERVICE IS ONLY AVAILABLE DURING GRAPH BUILD, NOT DURING ROUTING. *
*/
public interface OsmInfoGraphBuildService {
/**
* TODO Add doc
*/
Optional<OsmWayReferences> findReferences(Edge edge);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.opentripplanner.service.osminfo.configure;

import dagger.Binds;
import dagger.Module;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildRepository;

@Module
public interface OsmInfoGraphBuildRepositoryModule {
@Binds
OsmInfoGraphBuildRepository bind(DefaultOsmInfoGraphBuildRepository repository);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.opentripplanner.service.osminfo.configure;

import dagger.Binds;
import dagger.Module;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildService;
import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildService;

@Module
public interface OsmInfoGraphBuildServiceModule {
@Binds
OsmInfoGraphBuildService bind(DefaultOsmInfoGraphBuildService service);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.opentripplanner.service.osminfo.internal;

import jakarta.inject.Inject;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.osminfo.model.OsmWayReferences;
import org.opentripplanner.street.model.edge.Edge;

public class DefaultOsmInfoGraphBuildRepository
implements OsmInfoGraphBuildRepository, Serializable {

private final Map<Edge, OsmWayReferences> references = new HashMap<>();

@Inject
public DefaultOsmInfoGraphBuildRepository() {}

@Override
public void addReferences(Edge edge, OsmWayReferences info) {
Objects.requireNonNull(edge);
Objects.requireNonNull(info);
this.references.put(edge, info);
}

@Override
public Optional<OsmWayReferences> findReferences(Edge edge) {
return Optional.ofNullable(references.get(edge));
}

@Override
public String toString() {
return "DefaultOsmInfoGraphBuildRepository{references size = " + references.size() + "}";
}
}
Loading

0 comments on commit 12e5eb2

Please sign in to comment.