Search in sources :

Example 16 with Route

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

the class TestBanning method testSetBannedOnRequest.

@Test
public void testSetBannedOnRequest() {
    Collection<Route> routes = getTestRoutes();
    RoutingRequest routingRequest = new RoutingRequest();
    routingRequest.setBannedRoutesFromSting("RB__RUT:Route:1");
    routingRequest.setBannedAgenciesFromSting("RB:RUT:Agency:2");
    Collection<FeedScopedId> bannedRoutes = routingRequest.getBannedRoutes(routes);
    Assert.assertEquals(2, bannedRoutes.size());
    Assert.assertTrue(bannedRoutes.contains(new FeedScopedId("RB", "RUT:Route:1")));
    Assert.assertTrue(bannedRoutes.contains(new FeedScopedId("RB", "RUT:Route:3")));
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Route(org.opentripplanner.model.Route) Test(org.junit.Test)

Example 17 with Route

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

the class TestBanning method getTestRoutes.

private Collection<Route> getTestRoutes() {
    Route route1 = new Route(new FeedScopedId("RB", "RUT:Route:1"));
    route1.setLongName("");
    Route route2 = new Route(new FeedScopedId("RB", "RUT:Route:2"));
    route2.setLongName("");
    Route route3 = new Route(new FeedScopedId("RB", "RUT:Route:3"));
    route3.setLongName("");
    Agency agency1 = new Agency(new FeedScopedId("RB", "RUT:Agency:1"), "A", "Europe/Paris");
    Agency agency2 = new Agency(new FeedScopedId("RB", "RUT:Agency:2"), "B", "Europe/Paris");
    route1.setAgency(agency1);
    route2.setAgency(agency1);
    route3.setAgency(agency2);
    return Arrays.asList(route1, route2, route3);
}
Also used : Agency(org.opentripplanner.model.Agency) FeedScopedId(org.opentripplanner.model.FeedScopedId) Route(org.opentripplanner.model.Route)

Example 18 with Route

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

the class RoutingRequestTransitDataProviderFilterTest method testBikesAllowed.

@Test
public void testBikesAllowed() {
    String FEED_ID = "F";
    Trip trip = new Trip(new FeedScopedId(FEED_ID, "T1"));
    Route route = new Route(new FeedScopedId(FEED_ID, "R1"));
    trip.setRoute(route);
    assertEquals(BikeAccess.UNKNOWN, RoutingRequestTransitDataProviderFilter.bikeAccessForTrip(trip));
    trip.setBikesAllowed(BikeAccess.ALLOWED);
    assertEquals(BikeAccess.ALLOWED, RoutingRequestTransitDataProviderFilter.bikeAccessForTrip(trip));
    trip.setBikesAllowed(BikeAccess.NOT_ALLOWED);
    assertEquals(BikeAccess.NOT_ALLOWED, RoutingRequestTransitDataProviderFilter.bikeAccessForTrip(trip));
    route.setBikesAllowed(BikeAccess.ALLOWED);
    assertEquals(BikeAccess.NOT_ALLOWED, RoutingRequestTransitDataProviderFilter.bikeAccessForTrip(trip));
    trip.setBikesAllowed(BikeAccess.UNKNOWN);
    assertEquals(BikeAccess.ALLOWED, RoutingRequestTransitDataProviderFilter.bikeAccessForTrip(trip));
    route.setBikesAllowed(BikeAccess.NOT_ALLOWED);
    assertEquals(BikeAccess.NOT_ALLOWED, RoutingRequestTransitDataProviderFilter.bikeAccessForTrip(trip));
}
Also used : Trip(org.opentripplanner.model.Trip) FeedScopedId(org.opentripplanner.model.FeedScopedId) Route(org.opentripplanner.model.Route) Test(org.junit.jupiter.api.Test)

Example 19 with Route

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

the class TestRouteMatcher method testRouteMatcher.

public void testRouteMatcher() {
    Route r1 = new Route(new FeedScopedId("A1", "42"));
    r1.setShortName("R1");
    Route r2 = new Route(new FeedScopedId("A1", "43"));
    r2.setShortName("R2");
    Route r1b = new Route(new FeedScopedId("A2", "42"));
    r1b.setShortName("R1");
    Route r3 = new Route(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(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 20 with Route

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

the class TestSpecificTransfer method testSpecificTransfer.

/**
 * Test different specific transfers
 */
public void testSpecificTransfer() {
    // Setup from trip with route
    Route fromRoute = new Route(new FeedScopedId("A1", "R1"));
    Trip fromTrip = new Trip(new FeedScopedId("A1", "T1"));
    fromTrip.setRoute(fromRoute);
    // Setup to trip with route
    Route toRoute = new Route(new FeedScopedId("A1", "R2"));
    Trip toTrip = new Trip(new FeedScopedId("A1", "T2"));
    toTrip.setRoute(toRoute);
    // Create full SpecificTransfer
    SpecificTransfer s1 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), fromTrip.getId(), toTrip.getId(), 1);
    assertTrue(s1.matches(fromTrip, toTrip));
    assertTrue(s1.getSpecificity() == SpecificTransfer.MAX_SPECIFICITY);
    assertTrue(s1.transferTime == 1);
    // Create empty SpecificTransfer
    SpecificTransfer s2 = new SpecificTransfer((FeedScopedId) null, null, null, null, 2);
    assertTrue(s2.matches(fromTrip, toTrip));
    assertTrue(s2.getSpecificity() == SpecificTransfer.MIN_SPECIFICITY);
    assertTrue(s2.transferTime == 2);
    // Create SpecificTransfer one trip missing
    SpecificTransfer s3 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), null, toTrip.getId(), 3);
    assertTrue(s3.matches(fromTrip, toTrip));
    assertTrue(s3.getSpecificity() == 3);
    assertTrue(s3.transferTime == 3);
    // Create SpecificTransfer one trip different
    SpecificTransfer s4 = new SpecificTransfer(fromRoute.getId(), toRoute.getId(), new FeedScopedId("A1", "T3"), toTrip.getId(), 4);
    assertFalse(s4.matches(fromTrip, toTrip));
    assertTrue(s4.getSpecificity() == SpecificTransfer.MAX_SPECIFICITY);
    assertTrue(s4.transferTime == 4);
    // Create SpecificTransfer one trip and route missing
    SpecificTransfer s5 = new SpecificTransfer(null, toRoute.getId(), null, toTrip.getId(), 5);
    assertTrue(s5.matches(fromTrip, toTrip));
    assertTrue(s5.getSpecificity() == 2);
    assertTrue(s5.transferTime == 5);
    // Create SpecificTransfer one trip only
    SpecificTransfer s6 = new SpecificTransfer(null, null, null, toTrip.getId(), 6);
    assertTrue(s6.matches(fromTrip, toTrip));
    assertTrue(s6.getSpecificity() == 2);
    assertTrue(s6.transferTime == 6);
    // Create SpecificTransfer one route only
    SpecificTransfer s7 = new SpecificTransfer(fromRoute.getId(), null, null, null, 7);
    assertTrue(s7.matches(fromTrip, toTrip));
    assertTrue(s7.getSpecificity() == 1);
    assertTrue(s7.transferTime == 7);
}
Also used : Trip(org.opentripplanner.model.Trip) FeedScopedId(org.opentripplanner.model.FeedScopedId) Route(org.opentripplanner.model.Route)

Aggregations

Route (org.opentripplanner.model.Route)58 FeedScopedId (org.opentripplanner.model.FeedScopedId)22 Trip (org.opentripplanner.model.Trip)22 TripPattern (org.opentripplanner.model.TripPattern)16 Test (org.junit.Test)14 Line (org.rutebanken.netex.model.Line)11 Agency (org.opentripplanner.model.Agency)10 ArrayList (java.util.ArrayList)7 Test (org.junit.jupiter.api.Test)7 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)7 Stop (org.opentripplanner.model.Stop)7 HashSet (java.util.HashSet)6 List (java.util.List)6 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)6 OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)6 NetexEntityIndex (org.opentripplanner.netex.index.NetexEntityIndex)6 RoutingService (org.opentripplanner.routing.RoutingService)6 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)6 StopTime (org.opentripplanner.model.StopTime)5 TransitMode (org.opentripplanner.model.TransitMode)5