use of org.opentripplanner.profile.ProfileRequest in project OpenTripPlanner by opentripplanner.
the class JobSimulator method sendFakeJob.
public void sendFakeJob() {
String jobId = compactUUID();
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.registerModule(AgencyAndIdSerializer.makeModule());
mapper.registerModule(QualifiedModeSetSerializer.makeModule());
mapper.registerModule(JodaLocalDateSerializer.makeModule());
mapper.registerModule(TraverseModeSetSerializer.makeModule());
List<AnalystClusterRequest> requests = new ArrayList<>();
IntStream.range(0, nOrigins).forEach(i -> {
// Enqueue one fake origin
ProfileRequest profileRequest = new ProfileRequest();
profileRequest.fromLat = 45.515;
profileRequest.fromLon = -122.643;
// new TraverseModeSet(TraverseMode.TRANSIT);
profileRequest.transitModes = null;
// profileRequest.accessModes ...
AnalystClusterRequest clusterRequest = new AnalystClusterRequest(pointSetId, graphId, profileRequest);
clusterRequest.jobId = jobId;
clusterRequest.id = Integer.toString(i);
clusterRequest.outputLocation = s3prefix + "_output";
clusterRequest.destinationPointsetId = pointSetId;
requests.add(clusterRequest);
});
// try {
// objectMapper.writeValue(System.out, requests);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
String url = String.format("http://localhost:9001/enqueue/jobs");
HttpPost httpPost = new HttpPost(url);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
mapper.writeValue(out, requests);
// System.out.println(out.toString());
httpPost.setEntity(new ByteArrayEntity(out.toByteArray()));
HttpResponse response = httpClient.execute(httpPost);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.opentripplanner.profile.ProfileRequest in project OpenTripPlanner by opentripplanner.
the class ConvertToFrequencyTest method testBidirectional.
/**
* Test bidirectional conversion
*/
@Test
public void testBidirectional() throws Exception {
Graph gg = buildGraphNoTransit();
addTransitBidirectional(gg);
link(gg);
gg.index(new DefaultStreetVertexIndexFactory());
ProfileRequest pr2 = new ProfileRequest();
pr2.date = new LocalDate(2015, 6, 10);
pr2.fromTime = 7 * 3600;
pr2.toTime = 9 * 3600;
pr2.fromLat = pr2.toLat = 39.9621;
pr2.fromLon = pr2.toLon = -83.0007;
pr2.accessModes = pr2.egressModes = pr2.directModes = new QualifiedModeSet("WALK");
pr2.transitModes = new TraverseModeSet("TRANSIT");
ConvertToFrequency ctf = new ConvertToFrequency();
ctf.groupBy = ConvertToFrequency.ConversionGroup.ROUTE_DIRECTION;
ctf.routeId = new String[] { "route" };
ctf.windowStart = 5 * 3600;
ctf.windowEnd = 10 * 3600;
pr2.scenario = new Scenario(0);
pr2.scenario.modifications = Arrays.asList(ctf);
RepeatedRaptorProfileRouter rrpr2 = new RepeatedRaptorProfileRouter(gg, pr2);
rrpr2.route();
assertTrue(rrpr2.raptorWorkerData.hasFrequencies);
assertEquals(2, rrpr2.raptorWorkerData.timetablesForPattern.size());
// make sure we got trips in both directions
RaptorWorkerTimetable tt = rrpr2.raptorWorkerData.timetablesForPattern.get(0);
RaptorWorkerTimetable tt2 = rrpr2.raptorWorkerData.timetablesForPattern.get(1);
assertEquals(2, tt2.stopIndices.length);
assertEquals(2, tt.stopIndices.length);
assertEquals(tt.stopIndices[0], tt2.stopIndices[1]);
assertEquals(tt.stopIndices[1], tt2.stopIndices[0]);
}
use of org.opentripplanner.profile.ProfileRequest in project OpenTripPlanner by opentripplanner.
the class InitialStopsTest method testInitialStopWalkSpeedIncrease.
/**
* Test that increasing the walk speed on a walk-to-transit search
* a) decreases or leaves unchanged all access times.
* b) allows access to a superset of the originally accessible stops.
* c) decreases at least some access times.
*
* There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
*/
@Test
public void testInitialStopWalkSpeedIncrease() throws Exception {
Graph g = buildGraphNoTransit();
addRegularStopGrid(g);
addTransitMultipleLines(g);
link(g);
g.index(new DefaultStreetVertexIndexFactory());
ProfileRequest req = new ProfileRequest();
req.fromLon = req.toLon = -83.0118;
req.fromLat = req.toLat = 39.9908;
req.date = new LocalDate(2015, 9, 17);
req.bikeSpeed = 4.1f;
req.walkSpeed = 1.3f;
req.fromTime = 7 * 3600;
req.toTime = 9 * 3600;
req.maxBikeTime = 20;
req.maxWalkTime = 20;
req.transitModes = new TraverseModeSet("TRANSIT");
req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("WALK");
RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
assertFalse(initialStops1.isEmpty());
// let's get crazy, set walk speed really high.
req.walkSpeed = 25f;
data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
// we should find decreases to at least some stops
boolean foundDecreases = false;
for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
it.advance();
// the reached stops from the faster search should be a superset of the reached stops from the slower search
assertTrue(initialStops2.containsKey(it.key()));
assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
}
assertTrue("No decreases were found due to increased walk speed", foundDecreases);
}
use of org.opentripplanner.profile.ProfileRequest in project OpenTripPlanner by opentripplanner.
the class InitialStopsTest method testInitialStopBikeSpeedIncrease.
/**
* Test that increasing the bike speed on a bike-to-transit search
* a) decreases or leaves unchanged all access times.
* b) allows access to a superset of the originally accessible stops.
*
* There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
*/
@Test
public void testInitialStopBikeSpeedIncrease() throws Exception {
Graph g = buildGraphNoTransit();
addRegularStopGrid(g);
addTransitMultipleLines(g);
link(g);
g.index(new DefaultStreetVertexIndexFactory());
ProfileRequest req = new ProfileRequest();
req.fromLon = req.toLon = -83.0118;
req.fromLat = req.toLat = 39.9908;
req.date = new LocalDate(2015, 9, 17);
req.bikeSpeed = 4.1f;
req.walkSpeed = 1.3f;
req.fromTime = 7 * 3600;
req.toTime = 9 * 3600;
req.maxBikeTime = 20;
req.transitModes = new TraverseModeSet("TRANSIT");
req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("BICYCLE");
RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
assertFalse(initialStops1.isEmpty());
// let's get crazy, set bike speed really high.
req.bikeSpeed = 25f;
data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
// we should find decreases to at least some stops
boolean foundDecreases = false;
for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
it.advance();
// the reached stops from the faster search should be a superset of the reached stops from the slower search
assertTrue(initialStops2.containsKey(it.key()));
assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
}
assertTrue(foundDecreases);
}
use of org.opentripplanner.profile.ProfileRequest in project OpenTripPlanner by opentripplanner.
the class RepeatedRaptorTestResource method oneOrigin.
private void oneOrigin(double lat, double lon, String banAgency) {
ProfileRequest req = new ProfileRequest();
req.fromLat = lat;
req.fromLon = lon;
req.fromTime = 60 * 60 * 8;
req.toTime = 60 * 60 * 9;
req.walkSpeed = 2;
req.bikeSpeed = 4;
req.carSpeed = 8;
req.date = new LocalDate(2015, 04, 20);
// minutes
req.maxWalkTime = 20;
req.accessModes = new QualifiedModeSet("WALK");
req.egressModes = new QualifiedModeSet("WALK");
req.transitModes = new TraverseModeSet("TRANSIT");
req.analyst = true;
if (surfaceCache == null) {
LOG.error("You must run OTP with the --analyst option to enable spatial analysis features.");
}
final RepeatedRaptorProfileRouter router_a = new RepeatedRaptorProfileRouter(graph, req);
final RepeatedRaptorProfileRouter router_b = new RepeatedRaptorProfileRouter(graph, req);
router_b.banAgency = banAgency;
try {
router_a.route();
router_b.route();
} catch (VertexNotFoundException ex) {
LOG.error("vertex not found");
return;
}
System.out.printf("stop, min_a, min_b, min_diff, max_a, max_b, max_diff\n");
boolean decreased = false;
// Compare the propagated results
decreased = false;
TimeSurface.RangeSet timeSurfaces_a = router_a.timeSurfaceRangeSet;
TimeSurface.RangeSet timeSurfaces_b = router_b.timeSurfaceRangeSet;
for (Vertex destVertex : timeSurfaces_a.min.times.keySet()) {
int min_a = timeSurfaces_a.min.getTime(destVertex);
int max_a = timeSurfaces_a.max.getTime(destVertex);
int avg_a = timeSurfaces_a.avg.getTime(destVertex);
int min_b = timeSurfaces_b.min.getTime(destVertex);
int max_b = timeSurfaces_b.max.getTime(destVertex);
int avg_b = timeSurfaces_b.avg.getTime(destVertex);
long min_diff = (long) min_b - min_a;
long max_diff = (long) max_b - max_a;
long avg_diff = (long) avg_b - avg_a;
if (min_b == TimeSurface.UNREACHABLE) {
min_diff = Integer.MAX_VALUE;
max_diff = Integer.MAX_VALUE;
avg_diff = Integer.MAX_VALUE;
}
n_total += 1;
if (min_diff < 0 || max_diff < 0 || avg_diff < 0) {
n_decrease += 1;
sum_decrease += max_diff;
// Time decreased due to banning a route. This is bad, print it out.
System.out.printf("\"%s\",%d,%d,%d,%d,%d,%d\n", destVertex.getName(), min_a, min_b, min_diff, max_a, max_b, max_diff);
decreased = true;
} else if (avg_diff > 0) {
n_increase += 1;
}
}
if (decreased) {
LOG.error("Decreases happened at propagated street vertices for this origin!");
}
LOG.info("Street Vertices: {} increased, {} decreased out of {} destinations total", n_increase, n_decrease, n_total);
}
Aggregations