Skip to main content

paper/
main.rs

1use std::collections::{HashMap, HashSet};
2
3use hyperpaths_rs::{compute_sf, Link};
4
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>> = HashMap::from([(
24        "A".to_string(),
25        HashMap::from([("B".to_string(), 1.0)]),
26    )]);
27    let res = compute_sf(&all_links, &all_nodes, destination_node, &od_matrix);
28    println!("Optimal strategy:");
29    println!("\tNode labels:");
30    for (node_id, node_label) in &res.strategy.labels {
31        println!("\t\tu_{{i}} = {}: {:.6}", node_id, node_label);
32    }
33    println!("\tNodes probablities:");
34    for (node_id, freq) in &res.strategy.freqs {
35        println!("\t\tf_{{i}} = {}: {:.6}", node_id, freq);
36    }
37    println!("\tAttractive links set:");
38    for link in &res.strategy.a_set {
39        println!("\t\t a = (i, j) = ({}, {})", link.from_node, link.to_node);
40    }
41    println!("Volumes:");
42    println!("\tLinks volumes:");
43    for (from_node, to_map) in &res.volumes.links {
44        for (to_node, volume) in to_map {
45            println!("\t\tv_{{i, j}} = ({}, {}): {:.6}", from_node, to_node, volume);
46        }
47    }
48    println!("\tNodes volumes:");
49    for (node_id, volume) in &res.volumes.nodes {
50        println!("\t\tv_{{i}} = {}: {:.6}", node_id, volume);
51    }
52}