pub struct EditGraph { /* private fields */ }
Expand description
An implementation of the MutableGraph trait with additional convenient editing and generating functions.
Implementations§
Source§impl EditGraph
impl EditGraph
Sourcepub fn independent(n: u32) -> EditGraph
pub fn independent(n: u32) -> EditGraph
Generates an empty graph (independent set) on n
vertices.
Sourcepub fn biclique(s: u32, t: u32) -> EditGraph
pub fn biclique(s: u32, t: u32) -> EditGraph
Generates a complete bipartite graph (biclique) on s
+t
vertices.
Sourcepub fn complete_kpartite<'a, I>(sizes: I) -> EditGraphwhere
I: IntoIterator<Item = &'a u32>,
pub fn complete_kpartite<'a, I>(sizes: I) -> EditGraphwhere
I: IntoIterator<Item = &'a u32>,
Generates a complete k-partite graph.
§Arguments
sizes
- The sizes of each partite set as a sequence of integers.
Sourcepub fn disj_union(&self, graph: &impl Graph) -> EditGraph
pub fn disj_union(&self, graph: &impl Graph) -> EditGraph
Creates a new graph that is the disjoint union of self
and graph
.
The vertices of the second graph are relabelled to avoid index clashes.
Sourcepub fn disj_unions<'a, I, G>(it: I) -> EditGraph
pub fn disj_unions<'a, I, G>(it: I) -> EditGraph
Computes the disjoint unions of all graphs in the iterator it
.
Sourcepub fn normalize(&self) -> (EditGraph, FxHashMap<Vertex, Vertex>)
pub fn normalize(&self) -> (EditGraph, FxHashMap<Vertex, Vertex>)
Creates a copy of the graph in which vertices are labelled from $0$ to $n-1$, where $n$ is the number of vertices in the graph. The relative order of the indices is preserved, e.g. the smallest vertex from the original graph will be labelled $0$ and the largest one $n-1$.
Returns a tuple (graph
, map
) where graph
is the relabelled graph and
map
stores the mapping from new vertices to old vertices.
Sourcepub fn contract<'a, I>(&mut self, vertices: I) -> Vertex
pub fn contract<'a, I>(&mut self, vertices: I) -> Vertex
Contracts all vertices
into the first vertex of the sequence. The contracted vertex has
as its neighbours all vertices that were adjacent to at least one vertex in vertices
.
This function panics if the sequence is empty.
Returns the contracted vertex.
Sourcepub fn contract_pair(&mut self, u: &Vertex, v: &Vertex)
pub fn contract_pair(&mut self, u: &Vertex, v: &Vertex)
Contracts the pair ${u,v}$ be identifying $v$ with $u$. The operation removes $v$ from the graph and adds $v$’s neighbours to $u$.
Panics if either of the two vertices does not exist.
Sourcepub fn contract_into<'a, I>(&mut self, center: &Vertex, vertices: I)
pub fn contract_into<'a, I>(&mut self, center: &Vertex, vertices: I)
Contracts all vertices
into the center
vertex. The contracted vertex has
as its neighbours all vertices that were adjacent to at least one vertex in vertices
.
Source§impl EditGraph
impl EditGraph
Sourcepub fn from_txt(filename: &str) -> Result<EditGraph>
pub fn from_txt(filename: &str) -> Result<EditGraph>
Loads the graph from a text file which contains edges separated by line breaks. Edges must be pairs of integers separated by a space.
For example, assume the file edges.txt
contains the following:
0 1
0 2
0 3
We can then load the file as follows:
use graphbench::graph::*;
use graphbench::editgraph::EditGraph;
use graphbench::iterators::EdgeIterable;
fn main() {
let graph = EditGraph::from_txt("edges.txt").expect("Could not open edges.txt");
println!("Vertices: {:?}", graph.vertices().collect::<Vec<&Vertex>>());
println!("Edges: {:?}", graph.edges().collect::<Vec<Edge>>());
}
Sourcepub fn from_gzipped(filename: &str) -> Result<EditGraph>
pub fn from_gzipped(filename: &str) -> Result<EditGraph>
Loads the graph from a gzipped text file which otherwise follows the format described in EditGraph::from_txt.
Trait Implementations§
Source§impl Graph for EditGraph
impl Graph for EditGraph
Source§fn num_vertices(&self) -> usize
fn num_vertices(&self) -> usize
Source§fn adjacent(&self, u: &Vertex, v: &Vertex) -> bool
fn adjacent(&self, u: &Vertex, v: &Vertex) -> bool
u
and v
are connected by an edge.Source§fn contains(&self, u: &Vertex) -> bool
fn contains(&self, u: &Vertex) -> bool
u
is contained in the graph.Source§fn vertices<'a>(&'a self) -> Box<dyn Iterator<Item = &Vertex> + 'a>
fn vertices<'a>(&'a self) -> Box<dyn Iterator<Item = &Vertex> + 'a>
Source§fn neighbours<'a>(
&'a self,
u: &Vertex,
) -> Box<dyn Iterator<Item = &Vertex> + 'a>
fn neighbours<'a>( &'a self, u: &Vertex, ) -> Box<dyn Iterator<Item = &Vertex> + 'a>
u
.Source§fn degrees(&self) -> VertexMap<u32>
fn degrees(&self) -> VertexMap<u32>
Source§fn neighbourhood<'a, I>(&self, vertices: I) -> FxHashSet<Vertex>
fn neighbourhood<'a, I>(&self, vertices: I) -> FxHashSet<Vertex>
vertices
over vertices, returns all vertices of the graph
which are neighbours of those vertices but not part of vertices
themselves.Source§fn closed_neighbourhood<'a, I>(&self, vertices: I) -> FxHashSet<Vertex>
fn closed_neighbourhood<'a, I>(&self, vertices: I) -> FxHashSet<Vertex>
vertices
over vertices, returns all vertices of the graph
which are neighbours of those vertices as well as all vertices contained in vertices
.Source§fn r_neighbours(&self, u: &Vertex, r: usize) -> FxHashSet<Vertex>
fn r_neighbours(&self, u: &Vertex, r: usize) -> FxHashSet<Vertex>
r
to u
.Source§impl MutableGraph for EditGraph
impl MutableGraph for EditGraph
Source§fn with_capacity(n_guess: usize) -> Self
fn with_capacity(n_guess: usize) -> Self
Source§fn add_edge(&mut self, u: &Vertex, v: &Vertex) -> bool
fn add_edge(&mut self, u: &Vertex, v: &Vertex) -> bool
uv
to the graph. Read moreSource§fn remove_edge(&mut self, u: &Vertex, v: &Vertex) -> bool
fn remove_edge(&mut self, u: &Vertex, v: &Vertex) -> bool
uv
from the graph. Read moreSource§fn remove_vertex(&mut self, u: &Vertex) -> bool
fn remove_vertex(&mut self, u: &Vertex) -> bool
u
from the graph. Read moreSource§fn add_vertices(&mut self, vertices: impl Iterator<Item = Vertex>) -> u32
fn add_vertices(&mut self, vertices: impl Iterator<Item = Vertex>) -> u32
vertices
to the graph. Read moreSource§fn add_edges(&mut self, edges: impl Iterator<Item = Edge>) -> u32
fn add_edges(&mut self, edges: impl Iterator<Item = Edge>) -> u32
edges
to the graph. Read moreSource§fn remove_loops(&mut self) -> usize
fn remove_loops(&mut self) -> usize
Source§fn remove_isolates(&mut self) -> usize
fn remove_isolates(&mut self) -> usize
impl Eq for EditGraph
Auto Trait Implementations§
impl Freeze for EditGraph
impl RefUnwindSafe for EditGraph
impl Send for EditGraph
impl Sync for EditGraph
impl Unpin for EditGraph
impl UnwindSafe for EditGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<G> EdgeIterable<G> for Gwhere
G: Graph,
impl<G> EdgeIterable<G> for Gwhere
G: Graph,
Source§fn edges(&self) -> EdgeIterator<'_, G> ⓘ
fn edges(&self) -> EdgeIterator<'_, G> ⓘ
Source§impl<G> GraphAlgorithms for Gwhere
G: Graph,
impl<G> GraphAlgorithms for Gwhere
G: Graph,
Source§fn components(&self) -> Vec<HashSet<u32, BuildHasherDefault<FxHasher>>>
fn components(&self) -> Vec<HashSet<u32, BuildHasherDefault<FxHasher>>>
Source§fn degeneracy(
&self,
) -> (u32, u32, Vec<u32>, HashMap<u32, u32, BuildHasherDefault<FxHasher>>)
fn degeneracy( &self, ) -> (u32, u32, Vec<u32>, HashMap<u32, u32, BuildHasherDefault<FxHasher>>)
Source§fn is_bipartite(&self) -> BipartiteWitness
fn is_bipartite(&self) -> BipartiteWitness
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more