use of org.opentripplanner.analyst.cluster.TaskStatistics 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.analyst.cluster.TaskStatistics 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.analyst.cluster.TaskStatistics in project OpenTripPlanner by opentripplanner.
the class RepeatedRaptorComparison method main.
public static void main(String... args) {
if (args.length == 0) {
System.err.println("too few arguments.");
return;
}
// build a graph
File graphDir = new File(args[0]);
Graph graph = buildGraph(graphDir);
DB comparisonDb = null;
BTreeMap<Fun.Tuple3<String, String, ResultEnvelope.Which>, Integer> comparison = null;
// open the comparison file, if we have one.
if (args.length > 1) {
comparisonDb = DBMaker.newFileDB(new File(args[1])).readOnly().transactionDisable().closeOnJvmShutdown().cacheSize(24).asyncWriteEnable().make();
comparison = comparisonDb.getTreeMap("results");
}
String outputName = args.length > 2 ? args[2] : MavenVersion.VERSION.commit + ".db";
DB outputDb = DBMaker.newFileDB(new File(outputName)).transactionDisable().cacheSize(48).closeOnJvmShutdown().make();
final BTreeMap<Fun.Tuple3<String, String, ResultEnvelope.Which>, Integer> output = outputDb.createTreeMap("results").valueSerializer(Serializer.JAVA).makeOrGet();
// if we have a comparison file, get the pointset from it. Otherwise choose some randomly.
Collection<String> vertexLabels;
PointSet pset;
if (comparison != null) {
// clooge, pointset is stored in its own map in db.
pset = comparisonDb.<String, PointSet>getTreeMap("pointset").get("pointset");
} else {
// choose some vertices
List<Vertex> vertices = graph.getVertices().stream().filter(v -> v.getLabel().startsWith("osm:node:")).limit(1000).collect(Collectors.toList());
// make a pointset
pset = new PointSet(vertices.size());
int featIdx = 0;
for (Vertex v : vertices) {
PointFeature pf = new PointFeature();
pf.setId(v.getLabel());
pf.setLat(v.getLat() + OFFSET_Y);
pf.setLon(v.getLon() + OFFSET_X);
pset.addFeature(pf, featIdx++);
}
outputDb.createTreeMap("pointset").<String, PointSet>make().put("pointset", pset);
}
SampleSet ss = new SampleSet(pset, graph.getSampleFactory());
final BTreeMap<Fun.Tuple3<String, String, ResultEnvelope.Which>, Integer> comparisonResults = comparison;
Histogram bestCaseHisto = new Histogram("Best case");
Histogram avgCaseHisto = new Histogram("Average");
Histogram worstCaseHisto = new Histogram("Worst case");
ProfileRequest template = new ProfileRequest();
template.accessModes = new QualifiedModeSet("WALK");
template.analyst = true;
template.maxWalkTime = 20 * 60;
template.walkSpeed = 1.3f;
template.fromTime = 7 * 3600;
template.toTime = 9 * 3600;
template.date = new LocalDate(2015, 8, 4);
RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(template, graph, ss, new TaskStatistics());
// do the computation and comparison
IntStream.range(0, pset.featureCount()).parallel().forEach(idx -> {
if (idx % 100 == 0)
System.out.println(idx + " points complete");
Coordinate coord = pset.getCoordinate(idx);
String origin = pset.getFeature(idx).getId();
ProfileRequest req;
try {
req = template.clone();
} catch (CloneNotSupportedException e) {
/* can't happen */
throw new RuntimeException(e);
}
req.maxWalkTime = 20 * 60;
req.fromLat = req.toLat = coord.y;
req.fromLon = req.toLon = coord.x;
// 7 to 9 AM
req.fromTime = 7 * 3600;
req.toTime = 9 * 3600;
req.transitModes = new TraverseModeSet("TRANSIT");
RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(graph, req, ss);
rrpr.raptorWorkerData = data;
rrpr.includeTimes = true;
// TODO we really want to disable both isochrone and accessibility generation here.
// Because a sampleSet is provided it's going to make accessibility information (not isochrones).
ResultEnvelope results = new ResultEnvelope();
try {
results = rrpr.route();
} catch (Exception e) {
LOG.error("Exception during routing", e);
return;
}
for (ResultEnvelope.Which which : new ResultEnvelope.Which[] { ResultEnvelope.Which.BEST_CASE, ResultEnvelope.Which.AVERAGE, ResultEnvelope.Which.WORST_CASE }) {
Histogram histogram;
ResultSet resultSet;
switch(which) {
case BEST_CASE:
histogram = bestCaseHisto;
resultSet = results.bestCase;
break;
case WORST_CASE:
histogram = worstCaseHisto;
resultSet = results.worstCase;
break;
case AVERAGE:
histogram = avgCaseHisto;
resultSet = results.avgCase;
break;
default:
histogram = null;
resultSet = null;
}
// comparison.
for (int i = 0; i < resultSet.times.length; i++) {
int time = resultSet.times[i];
// TODO this is creating a PointFeature obj to hold the id at each call
// Cache?
String dest = pset.getFeature(i).getId();
Fun.Tuple3<String, String, ResultEnvelope.Which> key = new Fun.Tuple3<>(origin, dest, which);
output.put(key, time);
if (time < 0) {
LOG.error("Path from {} to {} has negative time {}", origin, dest, time);
}
if (comparisonResults != null) {
int time0 = comparisonResults.get(key);
int deltaMinutes;
if (time0 == RaptorWorker.UNREACHED && time != RaptorWorker.UNREACHED)
deltaMinutes = (time / 60) - 120;
else if (time == RaptorWorker.UNREACHED && time0 != RaptorWorker.UNREACHED)
deltaMinutes = 120 - (time0 / 60);
else
deltaMinutes = (time - time0) / 60;
// histograms are not threadsafe
synchronized (histogram) {
histogram.add(deltaMinutes);
}
}
}
}
});
output.close();
if (comparisonDb != null) {
comparisonDb.close();
bestCaseHisto.displayHorizontal();
System.out.println("mean: " + bestCaseHisto.mean());
avgCaseHisto.displayHorizontal();
System.out.println("mean: " + avgCaseHisto.mean());
worstCaseHisto.displayHorizontal();
System.out.println("mean: " + worstCaseHisto.mean());
}
}
Aggregations