Skip to content

Commit

Permalink
Quickly add some new walking uptake functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Oct 29, 2024
1 parent ba7d971 commit f333f43
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/config_uptake.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ The possible values for `"uptake"`:
- `"identity"` -- every route counts as 1, equivalent to just counting every trip
- `{ "CutoffMaxDistanceMeters": 16000 }` -- trips over 16km are skipped entirely, otherwise they count as 1
- `"GovTargetPCT"` and `"GoDutchPCT"` are uptake models from the PCT, using distance and gradient (**currently hardcoded to 0**)

TODO: New walking uptake functions not described yet
5 changes: 5 additions & 0 deletions od2net/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ pub enum Uptake {
GovTargetPCT,
/// Defined by https://github.com/ITSLeeds/pct/blob/HEAD/R/uptake.R
GoDutchPCT,
// TODO describe
WalkToSchool {
upper_limit: f64,
exponent: f64,
},
}

#[derive(Serialize, Deserialize)]
Expand Down
10 changes: 10 additions & 0 deletions od2net/src/plugins/uptake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub fn calculate_uptake(uptake: &Uptake, total_distance_meters: f64) -> f64 {
}
Uptake::GovTargetPCT => pct_gov_target(total_distance_meters, gradient),
Uptake::GoDutchPCT => pct_go_dutch(total_distance_meters, gradient),
Uptake::WalkToSchool {
upper_limit,
exponent,
} => walk_to_school(total_distance_meters, *upper_limit, *exponent),
}
}

Expand Down Expand Up @@ -78,6 +82,12 @@ fn inverse_logit(p: f64) -> f64 {
result
}

fn walk_to_school(distance_meters: f64, upper_limit: f64, exponent: f64) -> f64 {
let distance_km = distance_meters / 1000.0;
let p = (-distance_km * exponent).exp();
p.min(upper_limit)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit f333f43

Please sign in to comment.