Search in sources :

Example 1 with DataImportIssueStore

use of org.opentripplanner.graph_builder.DataImportIssueStore in project OpenTripPlanner by opentripplanner.

the class DirectTransferAnalyzer method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
    /* Initialize graph index which is needed by the nearby stop finder. */
    graph.index = new GraphIndex(graph);
    LOG.info("Analyzing transfers (this can be time consuming)...");
    List<TransferInfo> directTransfersTooLong = new ArrayList<>();
    List<TransferInfo> directTransfersNotFound = new ArrayList<>();
    DirectGraphFinder nearbyStopFinderEuclidian = new DirectGraphFinder(graph);
    StreetGraphFinder nearbyStopFinderStreets = new StreetGraphFinder(graph);
    int stopsAnalyzed = 0;
    for (TransitStopVertex originStopVertex : Iterables.filter(graph.getVertices(), TransitStopVertex.class)) {
        if (++stopsAnalyzed % 1000 == 0) {
            LOG.info("{} stops analyzed", stopsAnalyzed);
        }
        /* Find nearby stops by euclidean distance */
        Coordinate c0 = originStopVertex.getCoordinate();
        Map<Stop, StopAtDistance> stopsEuclidean = nearbyStopFinderEuclidian.findClosestStops(c0.y, c0.x, radiusMeters).stream().filter(t -> t.stop instanceof Stop).collect(Collectors.toMap(t -> (Stop) t.stop, t -> t));
        /* Find nearby stops by street distance */
        Map<Stop, StopAtDistance> stopsStreets = nearbyStopFinderStreets.findClosestStops(c0.y, c0.x, radiusMeters * RADIUS_MULTIPLIER).stream().filter(t -> t.stop instanceof Stop).collect(Collectors.toMap(t -> (Stop) t.stop, t -> t));
        Stop originStop = originStopVertex.getStop();
        /* Get stops found by both street and euclidean search */
        List<Stop> stopsConnected = stopsEuclidean.keySet().stream().filter(t -> stopsStreets.keySet().contains(t) && t != originStop).collect(Collectors.toList());
        /* Get stops found by euclidean search but not street search */
        List<Stop> stopsUnconnected = stopsEuclidean.keySet().stream().filter(t -> !stopsStreets.keySet().contains(t) && t != originStop).collect(Collectors.toList());
        for (Stop destStop : stopsConnected) {
            StopAtDistance euclideanStop = stopsEuclidean.get(destStop);
            StopAtDistance streetStop = stopsStreets.get(destStop);
            TransferInfo transferInfo = new TransferInfo(originStop, destStop, euclideanStop.distance, streetStop.distance);
            /* Log transfer where the street distance is too long compared to the euclidean distance */
            if (transferInfo.ratio > MIN_RATIO_TO_LOG && transferInfo.streetDistance > MIN_STREET_DISTANCE_TO_LOG) {
                directTransfersTooLong.add(transferInfo);
            }
        }
        for (Stop destStop : stopsUnconnected) {
            StopAtDistance euclideanStop = stopsEuclidean.get(destStop);
            /* Log transfers that are found by euclidean search but not by street search */
            directTransfersNotFound.add(new TransferInfo(originStop, destStop, euclideanStop.distance, -1));
        }
    }
    /* Sort by street distance to euclidean distance ratio before adding to issues */
    directTransfersTooLong.sort(Comparator.comparingDouble(t -> t.ratio));
    Collections.reverse(directTransfersTooLong);
    for (TransferInfo transferInfo : directTransfersTooLong) {
        issueStore.add(new TransferRoutingDistanceTooLong(transferInfo.origin, transferInfo.destination, transferInfo.directDistance, transferInfo.streetDistance, transferInfo.ratio));
    }
    /* Sort by direct distance before adding to issues */
    directTransfersNotFound.sort(Comparator.comparingDouble(t -> t.directDistance));
    for (TransferInfo transferInfo : directTransfersNotFound) {
        issueStore.add(new TransferCouldNotBeRouted(transferInfo.origin, transferInfo.destination, transferInfo.directDistance));
    }
    LOG.info("Done analyzing transfers. {} transfers could not be routed and {} transfers had a too long routing" + " distance.", directTransfersNotFound.size(), directTransfersTooLong.size());
}
Also used : StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance) Iterables(com.google.common.collect.Iterables) Logger(org.slf4j.Logger) StreetGraphFinder(org.opentripplanner.routing.graphfinder.StreetGraphFinder) Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) LoggerFactory(org.slf4j.LoggerFactory) Coordinate(org.locationtech.jts.geom.Coordinate) DirectGraphFinder(org.opentripplanner.routing.graphfinder.DirectGraphFinder) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) TransferCouldNotBeRouted(org.opentripplanner.ext.transferanalyzer.annotations.TransferCouldNotBeRouted) List(java.util.List) GraphBuilderModule(org.opentripplanner.graph_builder.services.GraphBuilderModule) TransferRoutingDistanceTooLong(org.opentripplanner.ext.transferanalyzer.annotations.TransferRoutingDistanceTooLong) Graph(org.opentripplanner.routing.graph.Graph) Map(java.util.Map) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) Comparator(java.util.Comparator) Collections(java.util.Collections) TransferRoutingDistanceTooLong(org.opentripplanner.ext.transferanalyzer.annotations.TransferRoutingDistanceTooLong) Stop(org.opentripplanner.model.Stop) ArrayList(java.util.ArrayList) StreetGraphFinder(org.opentripplanner.routing.graphfinder.StreetGraphFinder) Coordinate(org.locationtech.jts.geom.Coordinate) DirectGraphFinder(org.opentripplanner.routing.graphfinder.DirectGraphFinder) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) TransferCouldNotBeRouted(org.opentripplanner.ext.transferanalyzer.annotations.TransferCouldNotBeRouted) StopAtDistance(org.opentripplanner.routing.graphfinder.StopAtDistance)

Example 2 with DataImportIssueStore

use of org.opentripplanner.graph_builder.DataImportIssueStore in project OpenTripPlanner by opentripplanner.

the class TestGeometryAndBlockProcessor method setUp.

public void setUp() throws Exception {
    graph = new Graph();
    this.issueStore = new DataImportIssueStore(true);
    context = contextBuilder(ConstantsForTests.FAKE_GTFS).withIssueStoreAndDeduplicator(graph).build();
    feedId = context.getFeedId().getId();
    GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
    factory.run(graph, issueStore);
    graph.putService(CalendarServiceData.class, context.getCalendarServiceData());
    String[] stops = { feedId + ":A", feedId + ":B", feedId + ":C", feedId + ":D", feedId + ":E", feedId + ":entrance_a", feedId + ":entrance_b" };
    for (int i = 0; i < stops.length; ++i) {
        TransitStopVertex stop = (TransitStopVertex) (graph.getVertex(stops[i]));
        IntersectionVertex front = new IntersectionVertex(graph, "near_1_" + stop.getStop().getId(), stop.getX() + 0.0001, stop.getY() + 0.0001);
        IntersectionVertex back = new IntersectionVertex(graph, "near_2_" + stop.getStop().getId(), stop.getX() - 0.0001, stop.getY() - 0.0001);
        StreetEdge street1 = new StreetEdge(front, back, GeometryUtils.makeLineString(stop.getX() + 0.0001, stop.getY() + 0.0001, stop.getX() - 0.0001, stop.getY() - 0.0001), "street", 100, StreetTraversalPermission.ALL, false);
        StreetEdge street2 = new StreetEdge(back, front, GeometryUtils.makeLineString(stop.getX() - 0.0001, stop.getY() - 0.0001, stop.getX() + 0.0001, stop.getY() + 0.0001), "street", 100, StreetTraversalPermission.ALL, true);
    }
    StreetLinkerModule ttsnm = new StreetLinkerModule();
    // Linkers aren't run otherwise
    graph.hasStreets = true;
    graph.hasTransit = true;
    ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
}
Also used : GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Graph(org.opentripplanner.routing.graph.Graph) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule)

Example 3 with DataImportIssueStore

use of org.opentripplanner.graph_builder.DataImportIssueStore in project OpenTripPlanner by opentripplanner.

the class NetexLoaderSmokeTest method smokeTestOfNetexLoadData.

/**
 * This test load a very simple Netex data set and do assertions on it.
 * For each type we assert some of the most important fields for one element
 * and then check the expected number of that type. This is not a replacement
 * for unit tests on mappers. Try to focus on relation between entities and Netex
 * import integration.
 */
@Test
public void smokeTestOfNetexLoadData() {
    // Given
    NetexBundle netexBundle = ConstantsForTests.createMinimalNetexBundle();
    // Run the check to make sure it does not throw an exception
    netexBundle.checkInputs();
    // When
    OtpTransitServiceBuilder transitBuilder = netexBundle.loadBundle(new Deduplicator(), new DataImportIssueStore(false));
    // Then - smoke test model
    OtpTransitService otpModel = transitBuilder.build();
    assertAgencies(otpModel.getAllAgencies());
    assertMultiModalStations(otpModel.getAllMultiModalStations());
    assertOperators(otpModel.getAllOperators());
    assertStops(otpModel.getAllStops());
    assertStations(otpModel.getAllStations());
    assertTripPatterns(otpModel.getTripPatterns());
    assertTrips(otpModel.getAllTrips());
    assertServiceIds(otpModel.getAllServiceIds());
    assertNoticeAssignments(otpModel.getNoticeAssignments());
    // And then - smoke test service calendar
    assetServiceCalendar(transitBuilder.buildCalendarServiceData());
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) NetexBundle(org.opentripplanner.netex.loader.NetexBundle) OtpTransitService(org.opentripplanner.model.OtpTransitService) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) Test(org.junit.Test)

Example 4 with DataImportIssueStore

use of org.opentripplanner.graph_builder.DataImportIssueStore in project OpenTripPlanner by opentripplanner.

the class SimpleStreetSplitterTest method buildSpy.

@Before
public void buildSpy() {
    Graph graph = new Graph();
    SimpleStreetSplitter simpleStreetSplitter = new SimpleStreetSplitter(graph, null, null, false, new DataImportIssueStore(false));
    spySimpleStreetSplitter = spy(simpleStreetSplitter);
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) Before(org.junit.Before)

Example 5 with DataImportIssueStore

use of org.opentripplanner.graph_builder.DataImportIssueStore in project OpenTripPlanner by opentripplanner.

the class BikeParkUpdater method setup.

@Override
public void setup(Graph graph) {
    // Creation of network linker library will not modify the graph
    linker = new SimpleStreetSplitter(graph, new DataImportIssueStore(false));
    // Adding a bike park station service needs a graph writer runnable
    bikeService = graph.getService(BikeRentalStationService.class, true);
}
Also used : DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) BikeRentalStationService(org.opentripplanner.routing.bike_rental.BikeRentalStationService) SimpleStreetSplitter(org.opentripplanner.graph_builder.linking.SimpleStreetSplitter)

Aggregations

DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)12 Test (org.junit.Test)5 Graph (org.opentripplanner.routing.graph.Graph)4 OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 SimpleStreetSplitter (org.opentripplanner.graph_builder.linking.SimpleStreetSplitter)2 Stop (org.opentripplanner.model.Stop)2 HierarchicalVersionMapById (org.opentripplanner.netex.loader.util.HierarchicalVersionMapById)2 BinaryOpenStreetMapProvider (org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider)2 BikeRentalStationService (org.opentripplanner.routing.bike_rental.BikeRentalStationService)2 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)2 Quay (org.rutebanken.netex.model.Quay)2 Iterables (com.google.common.collect.Iterables)1 TLongList (gnu.trove.list.TLongList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1