Skip to main content

compute_sf

Function compute_sf 

Source
pub fn compute_sf<'a>(
    all_links: &'a [Link],
    all_stops: &HashSet<String>,
    destination: &str,
    od_matrix: &HashMap<String, HashMap<String, f64>>,
) -> SFResult<'a>
Expand description

compute_sf computes the Spiess-Florian algorithm

Examples found in repository?
examples/paper/main.rs (line 25)
5fn main() {
6    let all_nodes: HashSet<String> = ["A", "X", "X2", "Y", "Y3", "B"]
7        .iter()
8        .map(|s| s.to_string())
9        .collect();
10    let all_links = vec![
11        Link::new("A", "B", "Line 1", 25.0, 6.0),
12        Link::new("A", "X2", "Line 2", 7.0, 6.0),
13        Link::new("X2", "X", "Line 2", 0.0, 0.0),
14        Link::new("X", "X2", "Line 2", 0.0, 6.0),
15        Link::new("X2", "Y", "Line 2", 6.0, 0.0),
16        Link::new("Y3", "Y", "Line 3", 0.0, 15.0),
17        Link::new("Y", "B", "Line 4", 10.0, 3.0),
18        Link::new("X", "Y3", "Line 3", 4.0, 15.0),
19        Link::new("Y", "Y3", "Line 3", 0.0, 15.0),
20        Link::new("Y3", "B", "Line 3", 4.0, 0.0),
21    ];
22    let destination_node = "B";
23    let od_matrix: HashMap<String, HashMap<String, f64>> =
24        HashMap::from([("A".to_string(), HashMap::from([("B".to_string(), 1.0)]))]);
25    let res = compute_sf(&all_links, &all_nodes, destination_node, &od_matrix);
26    println!("Optimal strategy:");
27    println!("\tNode labels:");
28    for (node_id, node_label) in &res.strategy.labels {
29        println!("\t\tu_{{i}} = {}: {:.6}", node_id, node_label);
30    }
31    println!("\tNodes probablities:");
32    for (node_id, freq) in &res.strategy.freqs {
33        println!("\t\tf_{{i}} = {}: {:.6}", node_id, freq);
34    }
35    println!("\tAttractive links set:");
36    for link in &res.strategy.a_set {
37        println!("\t\t a = (i, j) = ({}, {})", link.from_node, link.to_node);
38    }
39    println!("Volumes:");
40    println!("\tLinks volumes:");
41    for (from_node, to_map) in &res.volumes.links {
42        for (to_node, volume) in to_map {
43            println!(
44                "\t\tv_{{i, j}} = ({}, {}): {:.6}",
45                from_node, to_node, volume
46            );
47        }
48    }
49    println!("\tNodes volumes:");
50    for (node_id, volume) in &res.volumes.nodes {
51        println!("\t\tv_{{i}} = {}: {:.6}", node_id, volume);
52    }
53}