Struct graph_search::Graph

source ·
pub struct Graph { /* private fields */ }
Expand description

A graph is represeted by as a weighted Adjenceny matrix

Implementations§

source§

impl Graph

source

pub fn new(input: Vec<Vec<Option<i32>>>) -> Graph

new allows for initializing the graph struct with a given adjecency matrix

§Arguments
  • input - an adjecency matrix in made out of a two-dimensional Vec of weights. Weights are represented as i32:s and can thus be positive or negative numbers.
§Example
 let rawgraph = vec![vec![Some(0), Some(20), Some(80), Some(50),     None,     None],
                     vec![   None,  Some(0),     None,     None,     None,     None],
                     vec![   None,     None,  Some(0),     None,     None,     None],
                     vec![   None,     None,     None,  Some(0), Some(50),     None],
                     vec![   None,     None, Some(20),     None,  Some(0), Some(50)],
                     vec![   None,     None,     None,     None,     None,  Some(0)]];
let g = Graph::new(rawgraph);

breadth_first_search implements breadth first search from start to the target and returns the path found as a VecDeque<usize> of nodes. This is an optional type as there might not be a path.

NOTE as this is breadth first search this search ignores any assigned weight to nodes.

§Arguments
  • start - an usize designating the start node, or row in the adjecency matrix
  • target - an usize designating the target node, or row in the adjecency matrix
§Returns

Either the found path between start and target as a VecDeque of usize:s or None if there is no path.

depth_first_search implements depth first search from start to the target and returns the path found as a VecDeque<usize> of nodes. This is an optional type as there might not be a path.

NOTE as this is depth first search this search ignores any assigned weight to nodes.

§Arguments
  • start - an usize designating the start node, or row in the adjecency matrix
  • target - an usize designating the target node, or row in the adjecency matrix
§Returns

Either the found path between start and target as a VecDeque of usize:s or None if there is no path.

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin 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>,

§

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>,

§

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.