use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class AStarTest method testBack.
@Test
public void testBack() {
RoutingRequest options = new RoutingRequest();
options.walkSpeed = 1.0;
options.setArriveBy(true);
options.setRoutingContext(_graph, _graph.getVertex("56th_24th"), _graph.getVertex("leary_20th"));
ShortestPathTree tree = new AStar().getShortestPathTree(options);
GraphPath path = tree.getPath(_graph.getVertex("56th_24th"), false);
List<State> states = path.states;
assertTrue(states.size() == 6 || states.size() == 7);
assertEquals("56th_24th", states.get(0).getVertex().getLabel());
int n;
// we could go either way around the block formed by 56th, 22nd, market, and 24th.
if (states.size() == 7) {
assertEquals("market_24th", states.get(1).getVertex().getLabel());
assertEquals("market_ballard", states.get(2).getVertex().getLabel());
n = 0;
} else {
assertEquals("56th_22nd", states.get(1).getVertex().getLabel());
n = -1;
}
assertEquals("market_22nd", states.get(n + 3).getVertex().getLabel());
assertEquals("market_leary", states.get(n + 4).getVertex().getLabel());
assertEquals("leary_vernon", states.get(n + 5).getVertex().getLabel());
assertEquals("leary_20th", states.get(n + 6).getVertex().getLabel());
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class AStarTest method testForwardExtraEdges.
@Test
public void testForwardExtraEdges() {
RoutingRequest options = new RoutingRequest();
options.walkSpeed = 1.0;
TemporaryStreetLocation from = new TemporaryStreetLocation("near_shilshole_22nd", new Coordinate(-122.385050, 47.666620), new NonLocalizedString("near_shilshole_22nd"), false);
new TemporaryConcreteEdge(from, _graph.getVertex("shilshole_22nd"));
TemporaryStreetLocation to = new TemporaryStreetLocation("near_56th_20th", new Coordinate(-122.382347, 47.669518), new NonLocalizedString("near_56th_20th"), true);
new TemporaryConcreteEdge(_graph.getVertex("56th_20th"), to);
options.setRoutingContext(_graph, from, to);
ShortestPathTree tree = new AStar().getShortestPathTree(options);
options.cleanup();
GraphPath path = tree.getPath(to, false);
List<State> states = path.states;
assertEquals(9, states.size());
assertEquals("near_shilshole_22nd", states.get(0).getVertex().getLabel());
assertEquals("shilshole_22nd", states.get(1).getVertex().getLabel());
assertEquals("ballard_22nd", states.get(2).getVertex().getLabel());
assertEquals("market_22nd", states.get(3).getVertex().getLabel());
assertEquals("market_leary", states.get(4).getVertex().getLabel());
assertEquals("market_russell", states.get(5).getVertex().getLabel());
assertEquals("market_20th", states.get(6).getVertex().getLabel());
assertEquals("56th_20th", states.get(7).getVertex().getLabel());
assertEquals("near_56th_20th", states.get(8).getVertex().getLabel());
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class TestBanning method doTestBannedTrips.
/**
* Test trip banning. We compute a set of shortest routes between two random stops in the Portland graph. We then ban, for each route, up to a
* certain amount of trips used in this route, one by one, and recompute the path. The banned trips must not appear in the new computed route.
*
* This is using a seeded random generator to easily make a reproducible and arbitrary list
* of start/end points and trip to ban. It allow for a (bit) more coverage than doing a
* single hand-picked test only.
*
* @param partial True to test partial trip banning, false for complete trip
* @param seed Value to use for random generator seed -- Keep the same value for consistency.
*/
public void doTestBannedTrips(boolean partial, int seed) {
Graph graph = ConstantsForTests.getInstance().getPortlandGraph();
String feedId = graph.getFeedIds().iterator().next();
Random rand = new Random(seed);
for (int i = 0; i < 20; i++) {
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 34, 25);
// Pick two random locations
Vertex start = null;
Vertex end = null;
while (start == null) start = graph.getVertex(feedId + ":" + rand.nextInt(10000));
while (end == null) end = graph.getVertex(feedId + ":" + rand.nextInt(10000));
options.setRoutingContext(graph, start, end);
ShortestPathTree spt = null;
int n = rand.nextInt(5) + 3;
for (int j = 0; j < n; j++) {
spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(end, true);
if (path == null || spt == null)
// No path found
break;
// List of used [trip,stop index] in the path
Set<T2<AgencyAndId, BannedStopSet>> usedTripDefs = new HashSet<T2<AgencyAndId, BannedStopSet>>();
for (State s : path.states) {
if (s.getBackEdge() instanceof TransitBoardAlight) {
TransitBoardAlight tbae = (TransitBoardAlight) s.getBackEdge();
int boardingStopIndex = tbae.getStopIndex();
AgencyAndId tripId = s.getTripId();
BannedStopSet stopSet;
if (partial) {
stopSet = new BannedStopSet();
stopSet.add(boardingStopIndex);
} else {
stopSet = BannedStopSet.ALL;
}
if (tripId != null)
usedTripDefs.add(new T2<AgencyAndId, BannedStopSet>(tripId, stopSet));
}
}
// Used trips should not contains a banned trip
for (T2<AgencyAndId, BannedStopSet> usedTripDef : usedTripDefs) {
BannedStopSet bannedStopSet = options.bannedTrips.get(usedTripDef.first);
if (bannedStopSet != null) {
for (Integer stopIndex : usedTripDef.second) {
assertFalse(bannedStopSet.contains(stopIndex));
}
}
}
if (usedTripDefs.size() == 0)
// Not a transit trip, no sense to ban trip any longer
break;
// Pick a random used trip + stop set to ban
List<T2<AgencyAndId, BannedStopSet>> usedTripDefsList = new ArrayList<T2<AgencyAndId, BannedStopSet>>(usedTripDefs);
T2<AgencyAndId, BannedStopSet> tripDefToBan = usedTripDefsList.get(rand.nextInt(usedTripDefs.size()));
options.bannedTrips.put(tripDefToBan.first, tripDefToBan.second);
}
options.bannedTrips.clear();
}
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class TurnRestrictionTest method testForwardAsCar.
@Test
public void testForwardAsCar() {
RoutingRequest options = new RoutingRequest(TraverseMode.CAR);
options.carSpeed = 1.0;
options.setRoutingContext(_graph, topRight, bottomLeft);
ShortestPathTree tree = new AStar().getShortestPathTree(options);
GraphPath path = tree.getPath(bottomLeft, false);
assertNotNull(path);
// If not for turn restrictions, the shortest path would be to take 1st to Main,
// Main to 2nd, 2nd to Broad and Broad until the corner of Broad and 3rd.
// However, most of these turns are not allowed. Instead, the shortest allowed
// path is 1st to Broad, Broad to 3rd.
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());
}
use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.
the class PlainStreetEdgeTest method testBikeSwitch.
/**
* Test the bike switching penalty feature, both its cost penalty and its separate time penalty.
*/
@Test
public void testBikeSwitch() {
StreetEdge e0 = edge(v0, v1, 0.0, StreetTraversalPermission.PEDESTRIAN);
StreetEdge e1 = edge(v1, v2, 0.0, StreetTraversalPermission.BICYCLE);
StreetEdge e2 = edge(v2, v0, 0.0, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
RoutingRequest noPenalty = proto.clone();
noPenalty.setMode(TraverseMode.BICYCLE);
noPenalty.setRoutingContext(_graph, v0, v0);
State s0 = new State(noPenalty);
State s1 = e0.traverse(s0);
State s2 = e1.traverse(s1);
State s3 = e2.traverse(s2);
RoutingRequest withPenalty = proto.clone();
withPenalty.bikeSwitchTime = (42);
withPenalty.bikeSwitchCost = (23);
withPenalty.setMode(TraverseMode.BICYCLE);
withPenalty.setRoutingContext(_graph, v0, v0);
State s4 = new State(withPenalty);
State s5 = e0.traverse(s4);
State s6 = e1.traverse(s5);
State s7 = e2.traverse(s6);
assertEquals(0, s0.getElapsedTimeSeconds());
assertEquals(0, s1.getElapsedTimeSeconds());
assertEquals(0, s2.getElapsedTimeSeconds());
assertEquals(0, s3.getElapsedTimeSeconds());
assertEquals(0.0, s0.getWeight(), 0.0);
assertEquals(0.0, s1.getWeight(), 0.0);
assertEquals(0.0, s2.getWeight(), 0.0);
assertEquals(0.0, s3.getWeight(), 0.0);
assertEquals(0.0, s4.getWeight(), 0.0);
assertEquals(23.0, s5.getWeight(), 0.0);
assertEquals(23.0, s6.getWeight(), 0.0);
assertEquals(23.0, s7.getWeight(), 0.0);
assertEquals(0, s4.getElapsedTimeSeconds());
assertEquals(42, s5.getElapsedTimeSeconds());
assertEquals(42, s6.getElapsedTimeSeconds());
assertEquals(42, s7.getElapsedTimeSeconds());
}
Aggregations