Search in sources :

Example 11 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class TripTimesTest method testBikesAllowed.

@Test
public void testBikesAllowed() {
    Graph graph = new Graph();
    Trip trip = new Trip();
    Route route = new Route();
    trip.setRoute(route);
    List<StopTime> stopTimes = Arrays.asList(new StopTime(), new StopTime());
    TripTimes s = new TripTimes(trip, stopTimes, new Deduplicator());
    RoutingRequest request = new RoutingRequest(TraverseMode.BICYCLE);
    Vertex v = new SimpleConcreteVertex(graph, "", 0.0, 0.0);
    request.setRoutingContext(graph, v, v);
    State s0 = new State(request);
    assertFalse(s.tripAcceptable(s0, 0));
    BikeAccess.setForTrip(trip, BikeAccess.ALLOWED);
    assertTrue(s.tripAcceptable(s0, 0));
    BikeAccess.setForTrip(trip, BikeAccess.NOT_ALLOWED);
    assertFalse(s.tripAcceptable(s0, 0));
}
Also used : SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 12 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class PartialStreetEdgeTest method testTraversal.

@Test
public void testTraversal() {
    RoutingRequest options = new RoutingRequest();
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(_graph, v1, v2);
    // Partial edge with same endpoints as the parent.
    PartialStreetEdge pEdge1 = new PartialStreetEdge(e1, v1, v2, e1.getGeometry(), "partial e1", e1.getDistance());
    PartialStreetEdge pEdge2 = new PartialStreetEdge(e2, v2, v3, e2.getGeometry(), "partial e2", e2.getDistance());
    // Traverse both the partial and parent edges.
    State s0 = new State(options);
    State s1 = e1.traverse(s0);
    State partialS0 = new State(options);
    State partialS1 = pEdge1.traverse(partialS0);
    // Traversal of original and partial edges should yield the same results.
    assertEquals(s1.getTimeSeconds(), partialS1.getTimeSeconds());
    assertEquals(s1.getElapsedTimeSeconds(), partialS1.getElapsedTimeSeconds());
    assertEquals(s1.getWeight(), partialS1.getWeight(), 0.0);
    // Now traverse the second partial/parent edge pair.
    State s2 = e2.traverse(s1);
    State partialS2 = pEdge2.traverse(partialS1);
    // Same checks as above.
    assertEquals(s2.getTimeSeconds(), partialS2.getTimeSeconds());
    assertEquals(s2.getElapsedTimeSeconds(), partialS2.getElapsedTimeSeconds());
    assertEquals(s2.getWeight(), partialS2.getWeight(), 0.0);
}
Also used : State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 13 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class PartialStreetEdgeTest method testTraversalOfSubdividedEdge.

@Test
public void testTraversalOfSubdividedEdge() {
    Coordinate nearestPoint = new Coordinate(0.5, 2.0);
    List<StreetEdge> edges = new ArrayList<StreetEdge>();
    edges.add(e2);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(_graph, "middle of e2", new NonLocalizedString("foo"), edges, nearestPoint, true);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(_graph, "middle of e2", new NonLocalizedString("foo"), edges, nearestPoint, false);
    RoutingRequest options = new RoutingRequest();
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(_graph, v1, v2);
    // All intersections take 10 minutes - we'll notice if one isn't counted.
    double turnDurationSecs = 10.0 * 60.0;
    options.traversalCostModel = (new DummyCostModel(turnDurationSecs));
    options.turnReluctance = (1.0);
    State s0 = new State(options);
    State s1 = e1.traverse(s0);
    State s2 = e2.traverse(s1);
    State s3 = e3.traverse(s2);
    Edge partialE2First = end.getIncoming().iterator().next();
    Edge partialE2Second = start.getOutgoing().iterator().next();
    State partialS0 = new State(options);
    State partialS1 = e1.traverse(partialS0);
    State partialS2A = partialE2First.traverse(partialS1);
    State partialS2B = partialE2Second.traverse(partialS2A);
    State partialS3 = e3.traverse(partialS2B);
    // Should start at the same time.
    assertEquals(s0.getTimeSeconds(), partialS0.getTimeSeconds());
    // Time and cost should be the same up to a rounding difference.
    assertTrue(Math.abs(s3.getTimeSeconds() - partialS3.getTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3.getElapsedTimeSeconds() - partialS3.getElapsedTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3.getWeight() - partialS3.getWeight()) <= 1);
    // All intersections take 0 seconds now.
    options.traversalCostModel = (new DummyCostModel(0.0));
    State s0NoCost = new State(options);
    State s1NoCost = e1.traverse(s0NoCost);
    State s2NoCost = e2.traverse(s1NoCost);
    State s3NoCost = e3.traverse(s2NoCost);
    State partialS0NoCost = new State(options);
    State partialS1NoCost = e1.traverse(partialS0NoCost);
    State partialS2ANoCost = partialE2First.traverse(partialS1NoCost);
    State partialS2BNoCost = partialE2Second.traverse(partialS2ANoCost);
    State partialS3NoCost = e3.traverse(partialS2BNoCost);
    // Time and cost should be the same up to a rounding difference.
    assertTrue(Math.abs(s3NoCost.getTimeSeconds() - partialS3NoCost.getTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3NoCost.getElapsedTimeSeconds() - partialS3NoCost.getElapsedTimeSeconds()) <= 1);
    assertTrue(Math.abs(s3NoCost.getWeight() - partialS3NoCost.getWeight()) <= 1);
    // Difference in duration and weight between now and before should be
    // entirely due to the crossing of 2 intersections at v2 and v3.
    double expectedDifference = 2 * 10 * 60.0;
    double durationDiff = s3.getTimeSeconds() - s3NoCost.getTimeSeconds();
    double partialDurationDiff = partialS3.getTimeSeconds() - partialS3NoCost.getTimeSeconds();
    assertTrue(Math.abs(durationDiff - expectedDifference) <= 1);
    assertTrue(Math.abs(partialDurationDiff - expectedDifference) <= 1);
    // Turn reluctance is 1.0, so weight == duration.
    double weightDiff = s3.getWeight() - s3NoCost.getWeight();
    double partialWeightDiff = partialS3.getWeight() - partialS3NoCost.getWeight();
    assertTrue(Math.abs(weightDiff - expectedDifference) <= 1);
    assertTrue(Math.abs(partialWeightDiff - expectedDifference) <= 1);
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) ArrayList(java.util.ArrayList) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 14 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class PlainStreetEdgeTest method testTraverseAsCar.

@Test
public void testTraverseAsCar() {
    StreetEdge e1 = edge(v1, v2, 100.0, StreetTraversalPermission.ALL);
    e1.setCarSpeed(10.0f);
    RoutingRequest options = proto.clone();
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(_graph, v1, v2);
    State s0 = new State(options);
    State s1 = e1.traverse(s0);
    // Should use the speed on the edge.
    double expectedWeight = e1.getDistance() / e1.getCarSpeed();
    long expectedDuration = (long) Math.ceil(expectedWeight);
    assertEquals(expectedDuration, s1.getElapsedTimeSeconds(), 0.0);
    assertEquals(expectedWeight, s1.getWeight(), 0.0);
}
Also used : State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 15 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class PlainStreetEdgeTest method testTraverseModeSwitchWalk.

/**
 * Test the traversal of two edges with different traverse modes, with a focus on walking.
 * This test will fail unless the following three conditions are met:
 * 1. Turn costs are computed based on the back edge's traverse mode during reverse traversal.
 * 2. Turn costs are computed such that bike walking is taken into account correctly.
 * 3. Enabling bike mode on a routing request bases the bike walking speed on the walking speed.
 */
@Test
public void testTraverseModeSwitchWalk() {
    StreetEdge e0 = edge(v0, v1, 50.0, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
    StreetEdge e1 = edge(v1, v2, 18.4, StreetTraversalPermission.PEDESTRIAN);
    v1.trafficLight = (true);
    RoutingRequest forward = proto.clone();
    forward.setMode(TraverseMode.BICYCLE);
    forward.setRoutingContext(_graph, v0, v2);
    State s0 = new State(forward);
    State s1 = e0.traverse(s0);
    State s2 = e1.traverse(s1);
    RoutingRequest reverse = proto.clone();
    reverse.setMode(TraverseMode.BICYCLE);
    reverse.setArriveBy(true);
    reverse.setRoutingContext(_graph, v0, v2);
    State s3 = new State(reverse);
    State s4 = e1.traverse(s3);
    State s5 = e0.traverse(s4);
    assertEquals(42, s2.getElapsedTimeSeconds());
    assertEquals(42, s5.getElapsedTimeSeconds());
}
Also used : State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Aggregations

State (org.opentripplanner.routing.core.State)78 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)42 GraphPath (org.opentripplanner.routing.spt.GraphPath)25 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)24 Test (org.junit.Test)23 Edge (org.opentripplanner.routing.graph.Edge)22 Vertex (org.opentripplanner.routing.graph.Vertex)20 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)8 Graph (org.opentripplanner.routing.graph.Graph)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)6 LineString (com.vividsolutions.jts.geom.LineString)5 HashSet (java.util.HashSet)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Trip (org.onebusaway.gtfs.model.Trip)5 StateEditor (org.opentripplanner.routing.core.StateEditor)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)5