SSSPGraph

Struct SSSPGraph 

Source
pub struct SSSPGraph {
    pub adj: Vec<Vec<Edge>>,
    pub n: usize,
}
Expand description

Represents a graph for SSSP algorithms.

The graph is stored as an adjacency list.

Fields§

§adj: Vec<Vec<Edge>>

Adjacency list: adj[u] contains edges from node u.

§n: usize

Number of nodes in the graph.

Implementations§

Source§

impl SSSPGraph

Source

pub fn new(n: usize) -> Self

Creates a new empty graph with n nodes.

§Arguments
  • n - The number of nodes.
§Examples
use sssp_lib::graph::SSSPGraph;

let graph = SSSPGraph::new(5);
Source

pub fn add_edge(&mut self, u: usize, v: usize, w: f64)

Adds a directed edge from node u to node v with weight w.

If u or v is out of bounds, the edge is ignored.

§Arguments
  • u - The source node index.
  • v - The target node index.
  • w - The edge weight.
§Examples
use sssp_lib::graph::SSSPGraph;

let mut graph = SSSPGraph::new(3);
graph.add_edge(0, 1, 1.0);
Source

pub fn bmssp( &self, sources: Vec<(usize, f64)>, b_bound: f64, u_bound: usize, ) -> (HashMap<usize, f64>, HashMap<usize, usize>)

Runs the Bounded Memory Shortest Path (BMSSP) algorithm.

This is an internal method used by the SSSP algorithm with bounds on distance and work.

§Arguments
  • sources - A vector of (node, initial_distance) pairs.
  • b_bound - The maximum distance bound.
  • u_bound - The maximum work bound (number of relaxations).
§Returns

A tuple of (distances, parents) HashMaps.

Auto Trait Implementations§

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.