pub struct Graph { /* private fields */ }Expand description
Graph is an immutable, interned transit network (integer arena). Build it
once with Graph::new and share it across threads; it is read-only.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new(all_links: &[Link], all_stops: &HashSet<String>) -> Graph
pub fn new(all_links: &[Link], all_stops: &HashSet<String>) -> Graph
Interns the network once. all_stops is interned first, so node indices
[0, all_stops.len()) are the stop nodes; any link endpoint outside
all_stops (out of contract) is appended after.
§Example
use std::collections::HashSet;
use hyperpaths_rs::{Graph, Link};
// One line A -> B: 6-minute headway, 10-minute ride.
let links = vec![Link::new("A", "B", "L1", 10.0, 6.0)];
let stops: HashSet<String> = ["A", "B"].iter().map(|s| s.to_string()).collect();
let graph = Graph::new(&links, &stops); // once; immutable, shareable
let mut w = graph.new_workspace(); // reusable buffers
let a = graph.node_index("A").unwrap();
let b = graph.node_index("B").unwrap();
let mut demand = vec![0.0; graph.num_nodes()];
demand[a] = 1.0; // one trip from A to B
let res = w.assign(b, &demand);
// Expected time A -> B: 6 min wait + 10 min ride.
assert!((res.labels[a] - 16.0).abs() < 1e-9);
assert!((res.link_vol[0] - 1.0).abs() < 1e-9);Sourcepub fn node_index(&self, name: &str) -> Option<usize>
pub fn node_index(&self, name: &str) -> Option<usize>
Arena index of a node name, or None if unknown.
Sourcepub fn new_workspace(&self) -> Workspace<'_>
pub fn new_workspace(&self) -> Workspace<'_>
Allocates the working buffers for this graph once; reuse the workspace across destinations and requests.
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
impl UnwindSafe for Graph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more