Skip to main content

hyperpaths_rs/
spiess_floarian.rs

1use std::collections::{HashMap, HashSet};
2
3use crate::demand::{Volumes, assign_demand};
4use crate::hyperpath::{Strategy, find_optimal_strategy};
5use crate::transit_network::Link;
6
7/// SFResult is the result of running through the Spiess-Florian algorithm
8pub struct SFResult<'a> {
9    /// Optimal strategy
10    pub strategy: Strategy<'a>,
11    /// Assigned demand
12    pub volumes: Volumes,
13}
14
15/// compute_sf computes the Spiess-Florian algorithm
16pub fn compute_sf<'a>(
17    all_links: &'a [Link],
18    all_stops: &HashSet<String>,
19    destination: &str,
20    od_matrix: &HashMap<String, HashMap<String, f64>>,
21) -> SFResult<'a> {
22    // Part 1: Find optimal strategy
23    let ops = find_optimal_strategy(all_links, all_stops, destination);
24    // Part 2: Assign demand according to optimal strategy
25    let volumes = assign_demand(all_links, all_stops, &ops, od_matrix, destination);
26    SFResult {
27        strategy: ops,
28        volumes,
29    }
30}