Search in sources :

Example 61 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class TestRouteMatcher method testRouteMatcher.

public void testRouteMatcher() {
    Route r1 = new Route();
    r1.setId(new FeedScopedId("A1", "42"));
    r1.setShortName("R1");
    Route r2 = new Route();
    r2.setId(new FeedScopedId("A1", "43"));
    r2.setShortName("R2");
    Route r1b = new Route();
    r1b.setId(new FeedScopedId("A2", "42"));
    r1b.setShortName("R1");
    Route r3 = new Route();
    r3.setId(new FeedScopedId("A1", "44"));
    r3.setShortName("R3_b");
    RouteMatcher emptyMatcher = RouteMatcher.emptyMatcher();
    assertFalse(emptyMatcher.matches(r1));
    assertFalse(emptyMatcher.matches(r1b));
    assertFalse(emptyMatcher.matches(r2));
    RouteMatcher matcherR1i = RouteMatcher.parse("A1__42");
    assertTrue(matcherR1i.matches(r1));
    assertFalse(matcherR1i.matches(r1b));
    assertFalse(matcherR1i.matches(r2));
    RouteMatcher matcherR2n = RouteMatcher.parse("A1_R2");
    assertFalse(matcherR2n.matches(r1));
    assertFalse(matcherR2n.matches(r1b));
    assertTrue(matcherR2n.matches(r2));
    RouteMatcher matcherR1R2 = RouteMatcher.parse("A1_R1,A1__43,A2__43");
    assertTrue(matcherR1R2.matches(r1));
    assertFalse(matcherR1R2.matches(r1b));
    assertTrue(matcherR1R2.matches(r2));
    RouteMatcher matcherR1n = RouteMatcher.parse("_R1");
    assertTrue(matcherR1n.matches(r1));
    assertTrue(matcherR1n.matches(r1b));
    assertFalse(matcherR1n.matches(r2));
    RouteMatcher matcherR1R1bR2 = RouteMatcher.parse("A1_R1,A2_R1,A1_R2");
    assertTrue(matcherR1R1bR2.matches(r1));
    assertTrue(matcherR1R1bR2.matches(r1b));
    assertTrue(matcherR1R1bR2.matches(r2));
    RouteMatcher matcherR3e = RouteMatcher.parse("A1_R3 b");
    assertFalse(matcherR3e.matches(r1));
    assertFalse(matcherR3e.matches(r1b));
    assertFalse(matcherR3e.matches(r2));
    assertTrue(matcherR3e.matches(r3));
    RouteMatcher nullList = RouteMatcher.parse(null);
    assertTrue(nullList == RouteMatcher.emptyMatcher());
    RouteMatcher emptyList = RouteMatcher.parse("");
    assertTrue(emptyList == RouteMatcher.emptyMatcher());
    RouteMatcher degenerate = RouteMatcher.parse(",,,");
    assertTrue(degenerate == RouteMatcher.emptyMatcher());
    boolean thrown = false;
    try {
        RouteMatcher badMatcher = RouteMatcher.parse("A1_R1_42");
    } catch (IllegalArgumentException e) {
        thrown = true;
    }
    assertTrue(thrown);
    Route r1c = new Route();
    r1c.setId(new FeedScopedId("A_1", "R_42"));
    r1c.setShortName("R_42");
    RouteMatcher matcherR1c = RouteMatcher.parse("A\\_1_R 42");
    assertTrue(matcherR1c.matches(r1c));
    assertFalse(matcherR1c.matches(r1));
    assertFalse(matcherR1c.matches(r1b));
    RouteMatcher matcherR1c2 = RouteMatcher.parse("A\\_1__R\\_42");
    assertTrue(matcherR1c2.matches(r1c));
    assertFalse(matcherR1c2.matches(r1));
    assertFalse(matcherR1c2.matches(r1b));
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) Route(org.opentripplanner.model.Route)

Example 62 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class FeedScopedIdFactoryTest method setFeedScope.

@Test
public void setFeedScope() {
    FeedScopedId feedScopedId1 = MappingSupport.ID_FACTORY.createId("NSR:StopPlace:1");
    assertEquals("TEST:NSR:StopPlace:1", feedScopedId1.toString());
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) Test(org.junit.Test)

Example 63 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class TripPatternCache method generateUniqueTripPatternCode.

/**
 * Generate unique trip pattern code for real-time added trip pattern. This function roughly
 * follows the format of {@link TripPattern#generateUniqueIds(java.util.Collection)}.
 *
 * @param tripPattern trip pattern to generate code for
 * @return unique trip pattern code
 */
private String generateUniqueTripPatternCode(TripPattern tripPattern) {
    FeedScopedId routeId = tripPattern.route.getId();
    String direction = tripPattern.directionId != -1 ? String.valueOf(tripPattern.directionId) : "";
    if (counter == Integer.MAX_VALUE) {
        counter = 0;
    } else {
        counter++;
    }
    // OBA library uses underscore as separator, we're moving toward colon.
    String code = String.format("%s:%s:%s:rt#%d", routeId.getFeedId(), routeId.getId(), direction, counter);
    return code;
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 64 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class GtfsTest method plan.

public Leg[] plan(long dateTime, String fromVertex, String toVertex, String onTripId, boolean wheelchairAccessible, boolean preferLeastTransfers, TraverseMode preferredMode, String excludedRoute, String excludedStop, int legCount) {
    final TraverseMode mode = preferredMode != null ? preferredMode : TraverseMode.TRANSIT;
    RoutingRequest routingRequest = new RoutingRequest();
    routingRequest.setNumItineraries(1);
    routingRequest.setArriveBy(dateTime < 0);
    routingRequest.dateTime = Math.abs(dateTime);
    if (fromVertex != null && !fromVertex.isEmpty()) {
        routingRequest.from = LocationStringParser.getGenericLocation(null, feedId.getId() + ":" + fromVertex);
    }
    if (toVertex != null && !toVertex.isEmpty()) {
        routingRequest.to = LocationStringParser.getGenericLocation(null, feedId.getId() + ":" + toVertex);
    }
    if (onTripId != null && !onTripId.isEmpty()) {
        routingRequest.startingTransitTripId = (new FeedScopedId(feedId.getId(), onTripId));
    }
    routingRequest.setRoutingContext(graph);
    routingRequest.setWheelchairAccessible(wheelchairAccessible);
    routingRequest.transferCost = (preferLeastTransfers ? 300 : 0);
    routingRequest.setStreetSubRequestModes(new TraverseModeSet(TraverseMode.WALK, mode));
    // TODO route matcher still using underscores because it's quite nonstandard and should be eliminated from the 1.0 release rather than reworked
    if (excludedRoute != null && !excludedRoute.isEmpty()) {
        routingRequest.setBannedRoutesFromSting(feedId.getId() + "__" + excludedRoute);
    }
    if (excludedStop != null && !excludedStop.isEmpty()) {
        throw new UnsupportedOperationException("Stop banning is not yet implemented in OTP2");
    }
    routingRequest.setOtherThanPreferredRoutesPenalty(0);
    // The walk board cost is set low because it interferes with test 2c1.
    // As long as boarding has a very low cost, waiting should not be "better" than riding
    // since this makes interlining _worse_ than alighting and re-boarding the same line.
    // TODO rethink whether it makes sense to weight waiting to board _less_ than 1.
    routingRequest.setWaitReluctance(1);
    routingRequest.setWalkBoardCost(30);
    List<GraphPath> paths = new GraphPathFinder(router).getPaths(routingRequest);
    List<Itinerary> itineraries = GraphPathToItineraryMapper.mapItineraries(paths, routingRequest);
    // Stored in instance field for use in individual tests
    itinerary = itineraries.get(0);
    assertEquals(legCount, itinerary.legs.size());
    return itinerary.legs.toArray(new Leg[legCount]);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) Itinerary(org.opentripplanner.model.plan.Itinerary) FeedScopedId(org.opentripplanner.model.FeedScopedId) TraverseMode(org.opentripplanner.routing.core.TraverseMode) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder)

Example 65 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceImplTest method testGetStopForId.

@Test
public void testGetStopForId() {
    Stop stop = subject.getStopForId(new FeedScopedId("Z", "P"));
    assertEquals("<Stop Z:P>", stop.toString());
}
Also used : Stop(org.opentripplanner.model.Stop) FeedScopedId(org.opentripplanner.model.FeedScopedId) Test(org.junit.Test)

Aggregations

FeedScopedId (org.opentripplanner.model.FeedScopedId)117 Trip (org.opentripplanner.model.Trip)32 Test (org.junit.Test)29 Stop (org.opentripplanner.model.Stop)25 TripPattern (org.opentripplanner.model.TripPattern)25 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)21 ArrayList (java.util.ArrayList)20 Route (org.opentripplanner.model.Route)15 HashSet (java.util.HashSet)11 List (java.util.List)11 Agency (org.opentripplanner.model.Agency)11 Collection (java.util.Collection)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 ZonedDateTime (java.time.ZonedDateTime)8 TransitEntity (org.opentripplanner.model.TransitEntity)8 RoutingService (org.opentripplanner.routing.RoutingService)8 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)8 Notice (org.opentripplanner.model.Notice)7 Station (org.opentripplanner.model.Station)7