Expand description
Deterministic graph generators (igraph_constructors.h).
This module turns igraph’s deterministic constructors into associated
functions of Graph returning Result<Graph>: given the same
arguments they always build the very same graph, with the same vertex and
edge ids. (Random generators live in crate::games.)
use igraph::prelude::*;
// The Petersen graph, three ways: by name, as G(5, 2), and from its LCF code.
let by_name = Graph::famous("Petersen").unwrap();
let gp = Graph::generalized_petersen(5, 2).unwrap();
assert_eq!((by_name.vcount(), by_name.ecount()), (10, 15));
assert_eq!((gp.vcount(), gp.ecount()), (10, 15));
// Both are 3-regular.
for g in [&by_name, &gp] {
let degrees = g.degree(VertexSelector::All, NeighborMode::All, Loops::Twice).unwrap();
assert!(degrees.iter().all(|&d| d == 3));
}
// A 3x4 grid, a 6-cycle and a star with 5 leaves.
let grid = Graph::square_lattice(&[3, 4], 1, false, false, None).unwrap();
assert_eq!((grid.vcount(), grid.ecount()), (12, 17));
let c6 = Graph::cycle_graph(6, false, false).unwrap();
assert_eq!(c6.ecount(), 6);
let star = Graph::star(6, StarMode::Undirected, 0).unwrap();
assert_eq!(star.degree_of(0, NeighborMode::All, Loops::Twice).unwrap(), 5);§Provided functionality
| Family | Functions |
|---|---|
| From matrices | Graph::adjacency, Graph::weighted_adjacency, Graph::sparse_adjacency, Graph::sparse_weighted_adjacency |
| From edge lists | Graph::small (see also Graph::from_edges) |
| Paths, cycles, stars | Graph::ring, Graph::path_graph, Graph::cycle_graph, Graph::star, Graph::wheel |
| Complete graphs | Graph::full, Graph::full_citation, Graph::full_multipartite, Graph::turan |
| Lattices | Graph::square_lattice, Graph::triangular_lattice, Graph::hexagonal_lattice, Graph::hypercube |
| Trees | Graph::kary_tree, Graph::symmetric_tree, Graph::regular_tree, Graph::tree_from_parent_vector, Graph::from_prufer |
| Circulant-like | Graph::circulant, Graph::generalized_petersen, Graph::lcf, Graph::extended_chordal_ring |
| Word graphs | Graph::de_bruijn, Graph::kautz |
| Named graphs | Graph::famous (with FamousGraph), Graph::atlas, Graph::mycielski_graph |
| Degree sequences | Graph::realize_degree_sequence, Graph::realize_bipartite_degree_sequence |
| Derived graphs | Graph::linegraph |
The corresponding chapter of the C documentation is Deterministic graph generators.
§Conventions
- Vertex counts and sizes are
usize; values that may legitimately be negative (shifts, parent ids, degrees coming fromGraph::degree) arei64. - Every function returns an
Errorrather than panicking on invalid input; most errors areErrorKind::InvalidValue.
§See also
| Need | Where |
|---|---|
| Random graphs (Erdős–Rényi, random regular, random trees, degree sequences, …) | crate::games, e.g. Graph::erdos_renyi_game_gnm, Graph::k_regular_game, Graph::tree_game, Graph::degree_sequence_game |
| The inverse conversions (graph → matrix, tree → Prüfer code) | Graph::get_adjacency, Graph::get_adjacency_sparse, Graph::to_prufer in crate::conversion |
| Bipartite constructors | Graph::full_bipartite, BipartiteGraph in crate::bipartite |
| Graphs derived from other graphs | Graph::complementer, Graph::mycielskian, Graph::disjoint_union in crate::operators |
| Is a degree sequence realizable at all? | is_graphical, is_bigraphical |
| Comparing generated graphs up to relabelling | Graph::isomorphic, Graph::count_automorphisms in crate::isomorphism |
| Drawing them | Graph::layout_circle (rings), Graph::layout_star, Graph::layout_grid (lattices), Graph::layout_reingold_tilford (trees) in crate::layout |
| Reading graphs from files | crate::foreign |
use igraph::prelude::*;
// LCF notation and the named graph agree up to relabelling: the Heawood
// graph two ways.
let heawood = Graph::famous("Heawood")?;
assert!(Graph::lcf(14, &[5, -5], 7)?.isomorphic(&heawood)?);
// Its automorphism group PGL(2, 7) has order 336, and its girth is 6.
assert_eq!(heawood.count_automorphisms(None)?, 336.0);
assert_eq!(heawood.girth()?, Some(6));
// Round trip through the adjacency matrix of the conversion module.
let a = heawood.get_adjacency(GetAdjacency::Both, None, Loops::Twice)?;
assert_eq!(Graph::adjacency(&a, Adjacency::Undirected, Loops::Twice)?, heawood);§Differences from the C library
A few defects of igraph 1.0.0 and 1.0.1 (the generator sources are unchanged in 1.0.1) are worked around on the Rust side, so the wrappers behave as documented:
Graph::sparse_adjacency/Graph::sparse_weighted_adjacencyagree with their dense counterparts even when an entry below the diagonal has no mirror entry (igraph drops it in the unweightedMaxmode and in the weightedMax,MinandPlusmodes), and when explicit zeros are given in theUndirectedmode (igraph’s structural symmetry test would reject them).Graph::adjacencyandGraph::sparse_adjacencyreject NaN, infinite, negative and fractional edge counts (igraph casts them to integers unchecked).Graph::starandGraph::wheelwithn = 1give the singleton graph (igraph returns the null graph).Graph::lcfwithn = 0gives the null graph (igraph divides by zero), and LCF shifts and chordal ring offsets are reduced modulo the number of vertices (igraph adds them without overflow checks).Graph::extended_chordal_ringaccepts a chord matrix without columns (igraph divides by the number of columns).
Re-exports§
pub use crate::constants::AllowedEdgeTypes;
Enums§
- Famous
Graph - The named graphs known to
Graph::famous.