Struct librualg::graph::Graph [−][src]
Implementations
impl<Indent> Graph<Indent> where
Indent: Eq + Ord + Clone,
[src]
Indent: Eq + Ord + Clone,
pub fn new() -> Self
[src]
pub fn bfs(&self, from: Indent) -> BTreeMap<Indent, VertexProperties<Indent>>
[src]
BFS (Breadth-First Search) algorithm. Returns an ancestor vector along the graph traversal path
use librualg::graph::Graph; let mut graph = Graph::new(); graph.add_oriented_edge(1, 2, 0.0); graph.add_oriented_edge(2, 3, 0.0); graph.add_oriented_edge(2, 4, 0.0); graph.add_oriented_edge(2, 5, 0.0); graph.add_oriented_edge(4, 8, 0.0); graph.add_oriented_edge(8, 17, 0.0); let parents = graph.bfs(1); assert_eq!(graph.search_path(5, &parents).unwrap(), vec![1, 2, 5]); assert_eq!(graph.search_path(17, &parents).unwrap(), vec![1, 2, 4, 8, 17]);
pub fn dfs(&self, from: Indent) -> BTreeMap<Indent, VertexProperties<Indent>>
[src]
DFS (Depth-First Search) algorithm. Returns an ancestor vector along the graph traversal path
use librualg::graph::Graph; let mut graph = Graph::new(); graph.add_oriented_edge(1, 2, 0.0); graph.add_oriented_edge(2, 3, 0.0); graph.add_oriented_edge(3, 5, 0.0); let res = graph.bfs(1); assert_eq!(graph.search_path(5, &res).unwrap(), vec![1, 2, 3, 5]);
pub fn dijkstra(
&self,
from: Indent
) -> (BTreeMap<Indent, VertexProperties<Indent>>, BTreeMap<Indent, f32>)
[src]
&self,
from: Indent
) -> (BTreeMap<Indent, VertexProperties<Indent>>, BTreeMap<Indent, f32>)
Dijkstra algorithm. Returns an ancestor vector along the graph traversal path and distances to the other vertexs
use librualg::graph::Graph; let mut graph = Graph::new(); graph.add_oriented_edge(1, 2, 2.0); graph.add_oriented_edge(2, 3, 5.0); graph.add_oriented_edge(3, 5, 7.0); graph.add_oriented_edge(1, 5, 19.0); let (parents, distances) = graph.dijkstra(1); assert_eq!(graph.search_path(5, &parents).unwrap(), vec![1, 2, 3, 5]); assert_eq!(graph.search_path(3, &parents).unwrap(), vec![1, 2, 3]); assert_eq!(*distances.get(&5).unwrap(), 14.0);
pub fn add_oriented_edge(&mut self, from: Indent, to: Indent, weight: f32)
[src]
Adds a new oriented edge to the graph
pub fn search_path(
&self,
target: Indent,
parents: &BTreeMap<Indent, VertexProperties<Indent>>
) -> Option<Vec<Indent>>
[src]
&self,
target: Indent,
parents: &BTreeMap<Indent, VertexProperties<Indent>>
) -> Option<Vec<Indent>>
Returns the path in the graph between two vertices based on the ancestor vector Returns None if the path does not exist
use librualg::graph::Graph; let mut graph = Graph::new(); graph.add_oriented_edge(1, 2, 0.0); graph.add_oriented_edge(2, 3, 0.0); graph.add_oriented_edge(2, 4, 0.0); graph.add_oriented_edge(2, 5, 0.0); graph.add_oriented_edge(4, 8, 0.0); graph.add_oriented_edge(8, 17, 0.0); let parents = graph.bfs(1); assert_eq!(graph.search_path(5, &parents).unwrap(), vec![1, 2, 5]); assert_eq!(graph.search_path(17, &parents).unwrap(), vec![1, 2, 4, 8, 17]); let parents = graph.bfs(101); assert_eq!(graph.search_path(101, &parents), None);
Trait Implementations
Auto Trait Implementations
impl<Indent> RefUnwindSafe for Graph<Indent> where
Indent: RefUnwindSafe,
Indent: RefUnwindSafe,
impl<Indent> Send for Graph<Indent> where
Indent: Send,
Indent: Send,
impl<Indent> Sync for Graph<Indent> where
Indent: Sync,
Indent: Sync,
impl<Indent> Unpin for Graph<Indent>
impl<Indent> UnwindSafe for Graph<Indent> where
Indent: RefUnwindSafe,
Indent: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,