Skip to main content

Graph

Struct Graph 

Source
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

Source

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);
Source

pub fn num_nodes(&self) -> usize

Number of nodes (size demand buffers with this).

Number of links.

Source

pub fn node_index(&self, name: &str) -> Option<usize>

Arena index of a node name, or None if unknown.

Source

pub fn node_name(&self, id: usize) -> &str

Name of an arena node index.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.