use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestGraphPath method testGraphPathOptimize.
public void testGraphPathOptimize() throws Exception {
String feedId = graph.getFeedIds().iterator().next();
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_c = graph.getVertex(feedId + ":C");
Vertex stop_e = graph.getVertex(feedId + ":E");
ShortestPathTree spt;
GraphPath path;
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
options.setRoutingContext(graph, stop_a.getLabel(), stop_e.getLabel());
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_e, false);
/* do not optimize yet, since we are testing optimization */
assertNotNull(path);
// Check that the resulting path visits the stops in the right order.
List<Vertex> stopvs = Lists.newArrayList();
for (State state : path.states) {
if (state.getVertex() instanceof TransitStop) {
stopvs.add(state.getVertex());
}
}
assertTrue(stopvs.get(0) == stop_a);
assertTrue(stopvs.get(1) == stop_c);
assertTrue(stopvs.get(2) == stop_e);
long bestStart = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 20, 0);
assertNotSame(bestStart, path.getStartTime());
path = spt.getPath(stop_e, true);
/* optimize */
assertEquals(bestStart, path.getStartTime());
}
use of org.opentripplanner.routing.core.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());
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TurnCostTest method testForwardDefaultNoTurnCosts.
@Test
public void testForwardDefaultNoTurnCosts() {
RoutingRequest options = proto.clone();
options.setRoutingContext(_graph, topRight, bottomLeft);
// Without turn costs, this path costs 2x100 + 2x50 = 300.
checkForwardRouteDuration(options, 300);
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class SimpleStreetSplitterTest method testFindEndVertexForParkAndRide.
/**
* Tests that traverse mode WALK is used when getting closest end vertex for park and ride.
*/
@Test
public void testFindEndVertexForParkAndRide() {
GenericLocation genericLocation = new GenericLocation(10, 23);
RoutingRequest routingRequest = new RoutingRequest();
routingRequest.setMode(TraverseMode.CAR);
routingRequest.parkAndRide = true;
spySimpleStreetSplitter.getClosestVertex(genericLocation, routingRequest, true);
verify(spySimpleStreetSplitter).link(any(Vertex.class), eq(TraverseMode.WALK), eq(routingRequest));
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestOpenStreetMapGraphBuilder method testBuildingAreas.
/**
* This reads test file with area
* and tests if it can be routed if visibility is used and if it isn't
*
* Routing needs to be successful in both options since without visibility calculation
* area rings are used.
* @param skipVisibility if true visibility calculations are skipped
* @throws UnsupportedEncodingException
*/
private void testBuildingAreas(boolean skipVisibility) throws UnsupportedEncodingException {
Graph gg = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.skipVisibility = skipVisibility;
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(URLDecoder.decode(getClass().getResource("usf_area.osm.gz").getFile(), "UTF-8"));
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(gg, extra);
new StreetVertexIndexServiceImpl(gg);
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", gg));
Router a = otpServer.getGraphService().getRouter("A");
RoutingRequest request = new RoutingRequest("WALK");
// This are vertices that can be connected only over edges on area (with correct permissions)
// It tests if it is possible to route over area without visibility calculations
Vertex bottomV = gg.getVertex("osm:node:580290955");
Vertex topV = gg.getVertex("osm:node:559271124");
request.setRoutingContext(a.graph, bottomV, topV);
GraphPathFinder graphPathFinder = new GraphPathFinder(a);
List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
assertNotNull(pathList);
assertFalse(pathList.isEmpty());
for (GraphPath path : pathList) {
assertFalse(path.states.isEmpty());
}
}
Aggregations