Search in sources :

Example 56 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class TurnCostTest method testForwardCarConstTurnCosts.

@Test
public void testForwardCarConstTurnCosts() {
    RoutingRequest options = proto.clone();
    options.traversalCostModel = (new ConstantIntersectionTraversalCostModel(10.0));
    options.setMode(TraverseMode.CAR);
    options.setRoutingContext(graph, topRight, bottomLeft);
    // Without turn costs, this path costs 3x100 + 1x50 = 350.
    // Since there are 3 turns, the total cost should be 380.
    GraphPath path = checkForwardRouteDuration(options, 380);
    List<State> states = path.states;
    assertEquals(5, states.size());
    assertEquals("maple_1st", states.get(0).getVertex().getLabel());
    assertEquals("main_1st", states.get(1).getVertex().getLabel());
    assertEquals("broad_1st", states.get(2).getVertex().getLabel());
    assertEquals("broad_2nd", states.get(3).getVertex().getLabel());
    assertEquals("broad_3rd", states.get(4).getVertex().getLabel());
    assertEquals(0, states.get(0).getElapsedTimeSeconds());
    // maple_main1 = 50
    assertEquals(50, states.get(1).getElapsedTimeSeconds());
    // main1_2 = 100
    assertEquals(160, states.get(2).getElapsedTimeSeconds());
    // broad1_2 = 100
    assertEquals(270, states.get(3).getElapsedTimeSeconds());
    // broad2_3 = 100
    assertEquals(380, states.get(4).getElapsedTimeSeconds());
}
Also used : State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) ConstantIntersectionTraversalCostModel(org.opentripplanner.routing.core.ConstantIntersectionTraversalCostModel) Test(org.junit.Test)

Example 57 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method route.

protected void route(String from, String to) {
    Date when;
    // Year + 1900
    try {
        when = dateFormat.parse(searchDate.getText());
    } catch (ParseException e) {
        searchDate.setText("Format: " + dateFormat.toPattern());
        return;
    }
    TraverseModeSet modeSet = new TraverseModeSet();
    modeSet.setWalk(walkCheckBox.isSelected());
    modeSet.setBicycle(bikeCheckBox.isSelected());
    modeSet.setFerry(ferryCheckBox.isSelected());
    modeSet.setRail(trainCheckBox.isSelected());
    modeSet.setTram(trainCheckBox.isSelected());
    modeSet.setSubway(trainCheckBox.isSelected());
    modeSet.setFunicular(trainCheckBox.isSelected());
    modeSet.setGondola(trainCheckBox.isSelected());
    modeSet.setBus(busCheckBox.isSelected());
    modeSet.setCableCar(busCheckBox.isSelected());
    modeSet.setCar(carCheckBox.isSelected());
    // otherwise 'false' will clear trainish and busish
    if (transitCheckBox.isSelected())
        modeSet.setTransit(true);
    RoutingRequest options = new RoutingRequest(modeSet);
    options.setArriveBy(arriveByCheckBox.isSelected());
    // override low 2-4 minute values
    options.setWalkBoardCost(Integer.parseInt(boardingPenaltyField.getText()) * 60);
    // TODO LG Add ui element for bike board cost (for now bike = 2 * walk)
    options.setBikeBoardCost(Integer.parseInt(boardingPenaltyField.getText()) * 60 * 2);
    // there should be a ui element for walk distance and optimize type
    options.setOptimize(getSelectedOptimizeType());
    options.setMaxWalkDistance(Integer.parseInt(maxWalkField.getText()));
    options.setDateTime(when);
    options.setFromString(from);
    options.setToString(to);
    options.walkSpeed = Float.parseFloat(walkSpeed.getText());
    options.bikeSpeed = Float.parseFloat(bikeSpeed.getText());
    options.numItineraries = 1;
    System.out.println("--------");
    System.out.println("Path from " + from + " to " + to + " at " + when);
    System.out.println("\tModes: " + modeSet);
    System.out.println("\tOptions: " + options);
    options.numItineraries = (Integer.parseInt(this.nPaths.getText()));
    // apply callback if the options call for it
    // if( dontUseGraphicalCallbackCheckBox.isSelected() ){
    // TODO perhaps avoid using a GraphPathFinder and go one level down the call chain directly to a GenericAStar
    // TODO perhaps instead of giving the pathservice a callback, we can just put the visitor in the routing request
    GraphPathFinder finder = new GraphPathFinder(router);
    long t0 = System.currentTimeMillis();
    // TODO: check options properly intialized (AMB)
    List<GraphPath> paths = finder.graphPathFinderEntryPoint(options);
    long dt = System.currentTimeMillis() - t0;
    searchTimeElapsedLabel.setText("search time elapsed: " + dt + "ms");
    if (paths == null) {
        System.out.println("no path");
        showGraph.highlightGraphPath(null);
        return;
    }
    // now's a convenient time to set graphical SPT weights
    showGraph.simpleSPT.setWeights();
    showPathsInPanel(paths);
    // now's a good time to set showGraph's SPT drawing weights
    showGraph.setSPTFlattening(Float.parseFloat(sptFlattening.getText()));
    showGraph.setSPTThickness(Float.parseFloat(sptThickness.getText()));
    showGraph.redraw();
    options.cleanup();
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) ParseException(java.text.ParseException) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) Date(java.util.Date)

Example 58 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest 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 59 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class RoutingContextDestroyTest method temporaryChangesRemovedOnContextDestroy.

@Test
public void temporaryChangesRemovedOnContextDestroy() {
    // Given - A request
    RoutingRequest request = new RoutingRequest();
    request.from = from;
    request.to = to;
    // When - the context is created
    subject = new RoutingContext(request, g);
    // Then:
    originAndDestinationInsertedCorrect();
    // And When:
    subject.destroy();
    // Then - permanent vertexes
    for (Vertex v : permanentVertexes) {
        // - does not reference the any temporary nodes any more
        for (Edge e : v.getIncoming()) {
            assertVertexEdgeIsNotReferencingTemporaryElements(v, e, e.getFromVertex());
        }
        for (Edge e : v.getOutgoing()) {
            assertVertexEdgeIsNotReferencingTemporaryElements(v, e, e.getToVertex());
        }
    }
}
Also used : TemporaryVertex(org.opentripplanner.routing.vertextype.TemporaryVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TemporaryEdge(org.opentripplanner.routing.edgetype.TemporaryEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 60 with RoutingRequest

use of org.opentripplanner.routing.api.request.RoutingRequest in project OpenTripPlanner by opentripplanner.

the class SimpleTraversalCostModelTest method before.

@Before
public void before() {
    graph = new Graph();
    costModel = new SimpleIntersectionTraversalCostModel();
    // Initialize the routing request.
    options = new RoutingRequest();
    options.carSpeed = 1.0;
    options.walkSpeed = 1.0;
    options.carDecelerationSpeed = (2.0);
    options.carAccelerationSpeed = (2.0);
    options.setStreetSubRequestModes(TraverseModeSet.allModes());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) Before(org.junit.Before)

Aggregations

RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)102 GraphPath (org.opentripplanner.routing.spt.GraphPath)50 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)42 Test (org.junit.Test)37 State (org.opentripplanner.routing.core.State)33 Vertex (org.opentripplanner.routing.graph.Vertex)31 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)18 Edge (org.opentripplanner.routing.graph.Edge)17 TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)17 AStar (org.opentripplanner.routing.algorithm.astar.AStar)16 Graph (org.opentripplanner.routing.graph.Graph)15 StateEditor (org.opentripplanner.routing.core.StateEditor)13 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)13 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)11 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)10 HashSet (java.util.HashSet)9 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)9 TraverseMode (org.opentripplanner.routing.core.TraverseMode)7 ArrayList (java.util.ArrayList)6 Coordinate (org.locationtech.jts.geom.Coordinate)6