Struct hypergraph::Hypergraph
source · pub struct Hypergraph<V, HE> { /* private fields */ }
Expand description
A directed hypergraph composed of generic vertices and hyperedges.
Implementations§
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn add_hyperedge(
&mut self,
vertices: Vec<VertexIndex>,
weight: HE
) -> Result<HyperedgeIndex, HypergraphError<V, HE>>
pub fn add_hyperedge( &mut self, vertices: Vec<VertexIndex>, weight: HE ) -> Result<HyperedgeIndex, HypergraphError<V, HE>>
Adds a hyperedge as an array of vertices indexes and a custom weight in the hypergraph. Returns the weighted index of the hyperedge.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn clear_hyperedges(&mut self) -> Result<(), HypergraphError<V, HE>>
pub fn clear_hyperedges(&mut self) -> Result<(), HypergraphError<V, HE>>
Clears all the hyperedges from the hypergraph.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn contract_hyperedge_vertices(
&mut self,
hyperedge_index: HyperedgeIndex,
vertices: Vec<VertexIndex>,
target: VertexIndex
) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
pub fn contract_hyperedge_vertices( &mut self, hyperedge_index: HyperedgeIndex, vertices: Vec<VertexIndex>, target: VertexIndex ) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
Contracts a set of the vertices of a hyperedge into one single vertex. Returns the updated vertices. Based on https://en.wikipedia.org/wiki/Edge_contraction
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn count_hyperedges(&self) -> usize
pub fn count_hyperedges(&self) -> usize
Returns the number of hyperedges in the hypergraph.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_hyperedge_vertices(
&self,
hyperedge_index: HyperedgeIndex
) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
pub fn get_hyperedge_vertices( &self, hyperedge_index: HyperedgeIndex ) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
Gets the vertices of a hyperedge.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_hyperedge_weight(
&self,
hyperedge_index: HyperedgeIndex
) -> Result<&HE, HypergraphError<V, HE>>
pub fn get_hyperedge_weight( &self, hyperedge_index: HyperedgeIndex ) -> Result<&HE, HypergraphError<V, HE>>
Gets the weight of a hyperedge from its index.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_hyperedges_connecting(
&self,
from: VertexIndex,
to: VertexIndex
) -> Result<Vec<HyperedgeIndex>, HypergraphError<V, HE>>
pub fn get_hyperedges_connecting( &self, from: VertexIndex, to: VertexIndex ) -> Result<Vec<HyperedgeIndex>, HypergraphError<V, HE>>
Gets the hyperedges directly connecting a vertex to another.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_hyperedges_intersections(
&self,
hyperedges: Vec<HyperedgeIndex>
) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
pub fn get_hyperedges_intersections( &self, hyperedges: Vec<HyperedgeIndex> ) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
Gets the intersections of a set of hyperedges as a vector of vertices.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn join_hyperedges(
&mut self,
hyperedges: &[HyperedgeIndex]
) -> Result<(), HypergraphError<V, HE>>
pub fn join_hyperedges( &mut self, hyperedges: &[HyperedgeIndex] ) -> Result<(), HypergraphError<V, HE>>
Joins two or more hyperedges from the hypergraph into one single entity. All the vertices are moved to the first hyperedge in the provided order.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn remove_hyperedge(
&mut self,
hyperedge_index: HyperedgeIndex
) -> Result<(), HypergraphError<V, HE>>
pub fn remove_hyperedge( &mut self, hyperedge_index: HyperedgeIndex ) -> Result<(), HypergraphError<V, HE>>
Removes a hyperedge by index.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
pub fn reverse_hyperedge( &mut self, hyperedge_index: HyperedgeIndex ) -> Result<(), HypergraphError<V, HE>>
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn update_hyperedge_vertices(
&mut self,
hyperedge_index: HyperedgeIndex,
vertices: Vec<VertexIndex>
) -> Result<(), HypergraphError<V, HE>>
pub fn update_hyperedge_vertices( &mut self, hyperedge_index: HyperedgeIndex, vertices: Vec<VertexIndex> ) -> Result<(), HypergraphError<V, HE>>
Updates the vertices of a hyperedge by index.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn update_hyperedge_weight(
&mut self,
hyperedge_index: HyperedgeIndex,
weight: HE
) -> Result<(), HypergraphError<V, HE>>
pub fn update_hyperedge_weight( &mut self, hyperedge_index: HyperedgeIndex, weight: HE ) -> Result<(), HypergraphError<V, HE>>
Updates the weight of a hyperedge by index.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn add_vertex(
&mut self,
weight: V
) -> Result<VertexIndex, HypergraphError<V, HE>>
pub fn add_vertex( &mut self, weight: V ) -> Result<VertexIndex, HypergraphError<V, HE>>
Adds a vertex with a custom weight to the hypergraph. Returns the index of the vertex.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn count_vertices(&self) -> usize
pub fn count_vertices(&self) -> usize
Returns the number of vertices in the hypergraph.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_adjacent_vertices_from(
&self,
from: VertexIndex
) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
pub fn get_adjacent_vertices_from( &self, from: VertexIndex ) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
Gets the list of all vertices connected from a given vertex.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_adjacent_vertices_to(
&self,
to: VertexIndex
) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
pub fn get_adjacent_vertices_to( &self, to: VertexIndex ) -> Result<Vec<VertexIndex>, HypergraphError<V, HE>>
Gets the list of all vertices connected to a given vertex.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_dijkstra_connections(
&self,
from: VertexIndex,
to: VertexIndex
) -> Result<Vec<(VertexIndex, Option<HyperedgeIndex>)>, HypergraphError<V, HE>>
pub fn get_dijkstra_connections( &self, from: VertexIndex, to: VertexIndex ) -> Result<Vec<(VertexIndex, Option<HyperedgeIndex>)>, HypergraphError<V, HE>>
Gets a list of the cheapest path of vertices between two vertices as a
vector of tuples of the form (VertexIndex, Option<HyperedgeIndex>)
where the second member is the hyperedge that has been traversed to
reach the vertex.
Please note that the initial tuple holds None
as hyperedge since none
has been traversed yet.
The implementation of the algorithm is partially based on:
https://doc.rust-lang.org/std/collections/binary_heap/#examples
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_full_adjacent_vertices_from(
&self,
from: VertexIndex
) -> Result<Vec<(VertexIndex, Vec<HyperedgeIndex>)>, HypergraphError<V, HE>>
pub fn get_full_adjacent_vertices_from( &self, from: VertexIndex ) -> Result<Vec<(VertexIndex, Vec<HyperedgeIndex>)>, HypergraphError<V, HE>>
Gets the list of all vertices connected from a given vertex as tuples
of the form (VertexIndex
, Vec
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_full_adjacent_vertices_to(
&self,
to: VertexIndex
) -> Result<Vec<(VertexIndex, Vec<HyperedgeIndex>)>, HypergraphError<V, HE>>
pub fn get_full_adjacent_vertices_to( &self, to: VertexIndex ) -> Result<Vec<(VertexIndex, Vec<HyperedgeIndex>)>, HypergraphError<V, HE>>
Gets the list of all vertices connected to a given vertex as tuples of
the form (VertexIndex
, Vec
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_full_vertex_hyperedges(
&self,
vertex_index: VertexIndex
) -> Result<Vec<Vec<VertexIndex>>, HypergraphError<V, HE>>
pub fn get_full_vertex_hyperedges( &self, vertex_index: VertexIndex ) -> Result<Vec<Vec<VertexIndex>>, HypergraphError<V, HE>>
Gets the hyperedges of a vertex as a vector of vectors of VertexIndex
.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_vertex_degree_in(
&self,
to: VertexIndex
) -> Result<usize, HypergraphError<V, HE>>
pub fn get_vertex_degree_in( &self, to: VertexIndex ) -> Result<usize, HypergraphError<V, HE>>
Gets the in-degree of a vertex. https://en.wikipedia.org/wiki/Directed_graph#Indegree_and_outdegree
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_vertex_degree_out(
&self,
from: VertexIndex
) -> Result<usize, HypergraphError<V, HE>>
pub fn get_vertex_degree_out( &self, from: VertexIndex ) -> Result<usize, HypergraphError<V, HE>>
Gets the out-degree of a vertex. https://en.wikipedia.org/wiki/Directed_graph#Indegree_and_outdegree
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_vertex_hyperedges(
&self,
vertex_index: VertexIndex
) -> Result<Vec<HyperedgeIndex>, HypergraphError<V, HE>>
pub fn get_vertex_hyperedges( &self, vertex_index: VertexIndex ) -> Result<Vec<HyperedgeIndex>, HypergraphError<V, HE>>
Gets the hyperedges of a vertex as a vector of HyperedgeIndex
.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn get_vertex_weight(
&self,
vertex_index: VertexIndex
) -> Result<&V, HypergraphError<V, HE>>
pub fn get_vertex_weight( &self, vertex_index: VertexIndex ) -> Result<&V, HypergraphError<V, HE>>
Gets the weight of a vertex from its index.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn remove_vertex(
&mut self,
vertex_index: VertexIndex
) -> Result<(), HypergraphError<V, HE>>
pub fn remove_vertex( &mut self, vertex_index: VertexIndex ) -> Result<(), HypergraphError<V, HE>>
Removes a vertex by index.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
sourcepub fn update_vertex_weight(
&mut self,
vertex_index: VertexIndex,
weight: V
) -> Result<(), HypergraphError<V, HE>>
pub fn update_vertex_weight( &mut self, vertex_index: VertexIndex, weight: V ) -> Result<(), HypergraphError<V, HE>>
Updates the weight of a vertex by index.
source§impl<V, HE> Hypergraph<V, HE>where
V: VertexTrait,
HE: HyperedgeTrait,
impl<V, HE> Hypergraph<V, HE>where V: VertexTrait, HE: HyperedgeTrait,
Hypergraph implementations.