Skip to content

Commit

Permalink
fix test code path for single destination
Browse files Browse the repository at this point in the history
also remove unused opportunity density grids
  • Loading branch information
abyrd committed Oct 18, 2023
1 parent b4375b0 commit 9a1d114
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 52 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/conveyal/r5/analyst/TravelTimeComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.conveyal.r5.analyst.fare.InRoutingFareCalculator;
import com.conveyal.r5.analyst.scenario.PickupWaitTimes;
import com.conveyal.r5.api.util.LegMode;
import com.conveyal.r5.common.Util;
import com.conveyal.r5.point_to_point.builder.PointToPointQuery;
import com.conveyal.r5.profile.DominatingList;
import com.conveyal.r5.profile.FareDominatingList;
Expand All @@ -30,6 +31,7 @@

import static com.conveyal.r5.analyst.scenario.PickupWaitTimes.NO_SERVICE_HERE;
import static com.conveyal.r5.analyst.scenario.PickupWaitTimes.NO_WAIT_ALL_STOPS;
import static com.conveyal.r5.common.Util.isNullOrEmpty;
import static com.conveyal.r5.profile.PerTargetPropagater.MM_PER_METER;

/**
Expand Down Expand Up @@ -87,8 +89,8 @@ public OneOriginResult computeTravelTimes() {
) {
// Freeform destinations. Destination PointSet was set by handleOneRequest in the main AnalystWorker.
destinations = request.destinationPointSets[0];
} else if (request.destinationPointSets != null) {
LOG.warn("ONLY VALID IN TESTING: Using PointSet object embedded in request where this is not standard.");
} else if (!isNullOrEmpty(request.destinationPointSets)) {
LOG.warn("ONLY VALID IN TESTING: Using PointSet object embedded in request outside regional analysis.");
destinations = request.destinationPointSets[0];
} else {
// Gridded (non-freeform) destinations. This method finds them differently for regional and single requests.
Expand Down
24 changes: 0 additions & 24 deletions src/test/java/com/conveyal/r5/analyst/network/GridLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,6 @@ public Envelope gridEnvelope () {
return new Envelope(originPoint.x, farCorner.x, originPoint.y, farCorner.y);
}

/**
* Create a gridded pointset coextensive with this grid, with the given number of opportunities in each cell.
* TODO maybe derive this from the network's gridded pointset rather than the GridLayout.
*/
public Grid makeUniformOpportunityDataset (double density) {
Grid grid = new Grid(DEFAULT_ZOOM, this.gridEnvelope());
for (double[] column : grid.grid) {
Arrays.fill(column, density);
}
return grid;
}

/**
* Create a gridded pointset coextensive with this grid, with the given number of opportunities in each cell in the
* eastern half of the grid.
*/
public Grid makeRightHalfOpportunityDataset (double density) {
Grid grid = new Grid(DEFAULT_ZOOM, this.gridEnvelope());
for (int c = grid.grid.length / 2; c < grid.grid.length; c++) {
Arrays.fill(grid.grid[c], density);
}
return grid;
}

public String nextIntegerId() {
return Integer.toString(nextIntegerId++);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.conveyal.r5.analyst.FreeFormPointSet;
import com.conveyal.r5.analyst.Grid;
import com.conveyal.r5.analyst.PointSet;
import com.conveyal.r5.analyst.WebMercatorExtents;
import com.conveyal.r5.analyst.cluster.AnalysisWorkerTask;
import com.conveyal.r5.analyst.cluster.TravelTimeSurfaceTask;
import com.conveyal.r5.analyst.decay.StepDecayFunction;
Expand All @@ -14,6 +15,7 @@
import java.util.EnumSet;
import java.util.stream.IntStream;

import static com.conveyal.r5.analyst.WebMercatorGridPointSet.DEFAULT_ZOOM;
import static com.conveyal.r5.analyst.network.GridGtfsGenerator.WEEKDAY_DATE;
import static com.conveyal.r5.analyst.network.GridGtfsGenerator.WEEKEND_DATE;

Expand Down Expand Up @@ -52,6 +54,14 @@ public GridSinglePointTaskBuilder (GridLayout gridLayout) {
task.walkSpeed = gridLayout.streetGridSpacingMeters / gridLayout.walkBlockTraversalTimeSeconds;
// Record more detailed information to allow comparison to theoretical travel time distributions.
task.recordTravelTimeHistograms = true;
// Set the destination grid extents on the task, otherwise if no freeform PointSet is specifid, it will fail
// checks on the grid dimensions and zoom level.
WebMercatorExtents extents = WebMercatorExtents.forWgsEnvelope(gridLayout.gridEnvelope(), DEFAULT_ZOOM);
task.zoom = extents.zoom;
task.north = extents.north;
task.west = extents.west;
task.width = extents.width;
task.height = extents.height;
}

public GridSinglePointTaskBuilder setOrigin (int gridX, int gridY) {
Expand Down Expand Up @@ -90,26 +100,6 @@ public GridSinglePointTaskBuilder maxRides(int rides) {
return this;
}

/**
* Even if you're not actually using the opportunity count, you should call this to set the grid extents on the
* resulting task. Otherwise it will fail checks on the grid dimensions and zoom level.
*/
public GridSinglePointTaskBuilder uniformOpportunityDensity (double density) {
Grid grid = gridLayout.makeUniformOpportunityDataset(density);
task.destinationPointSets = new PointSet[] { grid };
task.destinationPointSetKeys = new String[] { "GRID" };

// In a single point task, the grid of destinations is given with these fields, not from the pointset object.
// The destination point set (containing the opportunity densities) must then match these same dimensions.
task.zoom = grid.extents.zoom;
task.north = grid.extents.north;
task.west = grid.extents.west;
task.width = grid.extents.width;
task.height = grid.extents.height;

return this;
}

/**
* When trying to verify more complex distributions, the Monte Carlo approach may introduce too much noise.
* Increasing the number of draws will yield a better approximation of the true travel time distribution
Expand All @@ -121,6 +111,9 @@ public GridSinglePointTaskBuilder monteCarloDraws (int draws) {
}

/**
* Create a FreeformPointSet with a single point in it situated at the specified street intersection, and embed
* that PointSet in the request. In normal usage supplying FreeformPointSets as destination is only done for
* regional analysis tasks, but a testing code path exists to handle their presence on single point requests.
* This eliminates any difficulty estimating the final segment of egress, walking from the street to a gridded
* travel time sample point. Although egress time is something we'd like to test too, it is not part of the transit
* routing we're concentrating on here, and will vary as the Simpson Desert street grid does not align with our
Expand All @@ -129,6 +122,8 @@ public GridSinglePointTaskBuilder monteCarloDraws (int draws) {
*/
public GridSinglePointTaskBuilder singleFreeformDestination(int x, int y) {
FreeFormPointSet ps = new FreeFormPointSet(gridLayout.getIntersectionLatLon(x, y));
// Downstream code expects to see the same number of keys and PointSet objects so initialize both.
task.destinationPointSetKeys = new String[] { "POINT_SET" };
task.destinationPointSets = new PointSet[] { ps };
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void testFilteredTripRandomization () throws Exception {
.weekendMorningPeak()
.setOrigin(20, 20)
.monteCarloDraws(1000)
.uniformOpportunityDensity(10)
.build();

TravelTimeComputer computer = new TravelTimeComputer(task, network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void testGridScheduled () throws Exception {
AnalysisWorkerTask task = gridLayout.newTaskBuilder()
.weekdayMorningPeak()
.setOrigin(20, 20)
.uniformOpportunityDensity(10)
.singleFreeformDestination(40, 40)
.build();

Expand Down Expand Up @@ -88,7 +87,6 @@ public void testGridFrequency () throws Exception {
AnalysisWorkerTask task = gridLayout.newTaskBuilder()
.weekdayMorningPeak()
.setOrigin(20, 20)
.uniformOpportunityDensity(10)
.singleFreeformDestination(40, 40)
.build();

Expand Down Expand Up @@ -123,7 +121,6 @@ public void testGridFrequencyAlternatives () throws Exception {
AnalysisWorkerTask task = gridLayout.newTaskBuilder()
.weekdayMorningPeak()
.setOrigin(20, 20)
.uniformOpportunityDensity(10)
.singleFreeformDestination(40, 40)
.monteCarloDraws(10000)
.build();
Expand Down Expand Up @@ -187,7 +184,6 @@ public void testOvertakingCases () throws Exception {
.departureTimeWindow(7, 0, 5)
.maxRides(1)
.setOrigin(30, 50)
.uniformOpportunityDensity(10)
.singleFreeformDestination(42, 50);

// 1. Standard rider: upstream overtaking means Trip B departs origin first and is fastest to destination.
Expand Down Expand Up @@ -230,7 +226,6 @@ public void testExperiments () throws Exception {
AnalysisWorkerTask task = gridLayout.newTaskBuilder()
.weekdayMorningPeak()
.setOrigin(20, 20)
.uniformOpportunityDensity(10)
.singleFreeformDestination(80, 80)
.monteCarloDraws(10000)
.build();
Expand Down

0 comments on commit 9a1d114

Please sign in to comment.