Skip to main content

Workspace

Struct Workspace 

Source
pub struct Workspace<'g> { /* private fields */ }
Expand description

Workspace holds the reusable per-solve buffers for one Graph. Create one per thread (it borrows the graph immutably); it is not shareable while in use because its methods take &mut self.

Implementations§

Source§

impl Workspace<'_>

Source

pub fn assign(&mut self, dest_id: usize, demand: &[f64]) -> DestResult<'_>

Runs the full assignment (optimal strategy + demand loading) for one destination index. demand is a per-node slice of trips heading to dest_id (demand[dest_id] is ignored). The result borrows the workspace and is valid until the next assign on it.

Source

pub fn solve_each<F: FnMut(&DestResult<'_>)>( &mut self, od: &HashMap<String, HashMap<String, f64>>, callback: F, )

Assigns every destination present in od (an origin -> destination -> demand matrix) and calls callback with the arena-indexed result for each. It transposes od into per-destination columns once (reusing the workspace buffers), so there are no per-destination allocations after warm-up. The result is reused between calls, so copy out anything that must outlive the callback.

§Example

Build the graph once, reuse the workspace, and assign a full OD (here one trip A -> B on the paper network):

use std::collections::{HashMap, HashSet};
use hyperpaths_rs::{DestResult, Graph, Link};

let nodes: HashSet<String> = ["A", "X", "X2", "Y", "Y3", "B"]
    .iter()
    .map(|s| s.to_string())
    .collect();
let links = vec![
    Link::new("A", "B", "Line 1", 25.0, 6.0),
    Link::new("A", "X2", "Line 2", 7.0, 6.0),
    Link::new("X2", "X", "Line 2", 0.0, 0.0),
    Link::new("X", "X2", "Line 2", 0.0, 6.0),
    Link::new("X2", "Y", "Line 2", 6.0, 0.0),
    Link::new("Y3", "Y", "Line 3", 0.0, 15.0),
    Link::new("Y", "B", "Line 4", 10.0, 3.0),
    Link::new("X", "Y3", "Line 3", 4.0, 15.0),
    Link::new("Y", "Y3", "Line 3", 0.0, 15.0),
    Link::new("Y3", "B", "Line 3", 4.0, 0.0),
];

let graph = Graph::new(&links, &nodes);
let mut w = graph.new_workspace();
let a = graph.node_index("A").unwrap();

let od = HashMap::from([("A".to_string(), HashMap::from([("B".to_string(), 1.0)]))]);

let mut a_to_b = 0.0;
w.solve_each(&od, |res: &DestResult| {
    a_to_b = res.labels[a];
});
assert!((a_to_b - 27.75).abs() < 1e-9);

Auto Trait Implementations§

§

impl<'g> Freeze for Workspace<'g>

§

impl<'g> RefUnwindSafe for Workspace<'g>

§

impl<'g> Send for Workspace<'g>

§

impl<'g> Sync for Workspace<'g>

§

impl<'g> Unpin for Workspace<'g>

§

impl<'g> UnsafeUnpin for Workspace<'g>

§

impl<'g> UnwindSafe for Workspace<'g>

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.