-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from mattwigway/fareto
Fareto
- Loading branch information
Showing
5 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.ipea.r5r.Process; | ||
|
||
import java.text.ParseException; | ||
import java.util.concurrent.ForkJoinPool; | ||
|
||
import org.ipea.r5r.RDataFrame; | ||
import org.ipea.r5r.RoutingProperties; | ||
import org.ipea.r5r.R5.R5ParetoServer; | ||
|
||
import com.conveyal.r5.analyst.cluster.RegionalTask; | ||
import com.conveyal.r5.transit.TransportNetwork; | ||
|
||
/** | ||
* This outputs the Pareto itinerary planner results directly to JSON. | ||
*/ | ||
public class FaretoDebug extends R5Process { | ||
public FaretoDebug(ForkJoinPool threadPool, TransportNetwork transportNetwork, | ||
RoutingProperties routingProperties) { | ||
super(threadPool, transportNetwork, routingProperties); | ||
} | ||
|
||
public R5ParetoServer.ParetoReturn pathResults = null; | ||
|
||
@Override | ||
protected boolean isOneToOne() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected RDataFrame runProcess(int index) throws ParseException { | ||
RegionalTask request = buildRequest(index); | ||
request.fromLat = fromLats[0]; | ||
request.fromLon = fromLons[0]; | ||
request.toLat = toLats[0]; | ||
request.toLon = toLons[0]; | ||
request.maxFare = 150_000_000; | ||
|
||
R5ParetoServer computer = new R5ParetoServer(request, transportNetwork); | ||
pathResults = computer.handle(); | ||
|
||
// to match R5Process interface, return type must be dataframe. We work around this by returning an empty | ||
// dataframe. Cannot return null because value is used in mergeDataFrame | ||
return new RDataFrame(0); | ||
} | ||
|
||
@Override | ||
protected RDataFrame buildDataFrameStructure(String fromId, int nRows) { | ||
// to avoid NPEs in mergeDataFrame, something must be returned | ||
return new RDataFrame(nRows); | ||
} | ||
|
||
@Override | ||
protected void buildDestinationPointSet() { | ||
// not needed in this class | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#' Output Fareto-format JSON for visualization with Fareto | ||
#' | ||
#' This is primarily intended for debugging the fare system code. Fareto is an external tool | ||
#' that provides visualization for R5's McRAPTOR fare calculator. To use this, | ||
#' run fareto_debug(...) as if you were running paretoFrontier(...). The return value is a JSON-formatted | ||
#' string. Use [rfareto](https://github.com/mattwigway/rfareto) to visualize the results. | ||
fareto_debug <- function(r5r_core, | ||
origins, | ||
destinations, | ||
mode = c("WALK", "TRANSIT"), | ||
mode_egress = "WALK", | ||
departure_datetime = Sys.time(), | ||
time_window = 10L, | ||
percentiles = 50L, | ||
max_walk_time = Inf, | ||
max_bike_time = Inf, | ||
max_car_time = Inf, | ||
max_trip_duration = 120L, | ||
fare_structure = NULL, | ||
walk_speed = 3.6, | ||
bike_speed = 12, | ||
max_rides = 3, | ||
max_lts = 2, | ||
n_threads = Inf, | ||
verbose = FALSE, | ||
progress = FALSE) { | ||
|
||
checkmate::assert_class(r5r_core, "jobjRef") | ||
|
||
origins <- assign_points_input(origins, "origins") | ||
destinations <- assign_points_input(destinations, "destinations") | ||
mode_list <- assign_mode(mode, mode_egress) | ||
departure <- assign_departure(departure_datetime) | ||
max_walk_time <- assign_max_street_time( | ||
max_walk_time, | ||
walk_speed, | ||
max_trip_duration, | ||
"walk" | ||
) | ||
max_bike_time <- assign_max_street_time( | ||
max_bike_time, | ||
bike_speed, | ||
max_trip_duration, | ||
"bike" | ||
) | ||
max_car_time <- assign_max_street_time( | ||
max_car_time, | ||
8, # 8 km/h, R5's default. | ||
max_trip_duration, | ||
"car" | ||
) | ||
max_trip_duration <- assign_max_trip_duration( | ||
max_trip_duration, | ||
mode_list, | ||
max_walk_time, | ||
max_bike_time | ||
) | ||
|
||
if (nrow(origins) != 1 || nrow(destinations) != 1) { | ||
stop("fareto_debug requires exactly one origin and one destination") | ||
} | ||
|
||
set_time_window(r5r_core, time_window) | ||
set_percentiles(r5r_core, percentiles) | ||
set_monte_carlo_draws(r5r_core, 1, time_window) | ||
set_speed(r5r_core, walk_speed, "walk") | ||
set_speed(r5r_core, bike_speed, "bike") | ||
set_max_rides(r5r_core, max_rides) | ||
set_max_lts(r5r_core, max_lts) | ||
set_n_threads(r5r_core, n_threads) | ||
set_verbose(r5r_core, verbose) | ||
set_progress(r5r_core, progress) | ||
set_fare_structure(r5r_core, fare_structure) | ||
|
||
# call r5r_core method and process result ------------------------------- | ||
result <- r5r_core$faretoJson( | ||
origins$id, | ||
origins$lat, | ||
origins$lon, | ||
destinations$id, | ||
destinations$lat, | ||
destinations$lon, | ||
mode_list$direct_modes, | ||
mode_list$transit_mode, | ||
mode_list$access_mode, | ||
mode_list$egress_mode, | ||
departure$date, | ||
departure$time, | ||
max_walk_time, | ||
max_bike_time, | ||
max_car_time, | ||
max_trip_duration | ||
) | ||
|
||
return(result) | ||
} |
Binary file not shown.