Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

Counterpart of igraph_t (see references/igraph/include/igraph_datatype.h).

Phase-0 callers (bfs, read_edgelist, oracle tests) only depended on with_vertices, add_edge, add_edges, vcount, ecount, neighbors, degree — those signatures are preserved here, so existing call sites compile unchanged. New for Phase 1: new (with directed flag), is_directed.

Implementations§

Source§

impl Graph

Source

pub fn new(n: u32, directed: bool) -> IgraphResult<Self>

Construct an empty graph on n vertices.

Counterpart of igraph_empty(); directed defaults to false if you use Graph::with_vertices instead.

§Examples
use rust_igraph::Graph;

let g = Graph::new(5, true).unwrap();
assert_eq!(g.vcount(), 5);
assert_eq!(g.ecount(), 0);
assert!(g.is_directed());
Source

pub fn from_edges( edges: &[(u32, u32)], directed: bool, n_override: Option<u32>, ) -> IgraphResult<Self>

Build a graph from an edge list, inferring the vertex count from the highest endpoint.

This is the most ergonomic way to create a small graph. The vertex count is max(u, v) + 1 over all (u, v) pairs (or 0 if edges is empty and n_override is None).

n_override can force a minimum vertex count (useful when you want isolated vertices beyond the edges). Pass None to auto-derive.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0, 1), (1, 2), (2, 0)], false, None).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3);
assert!(!g.is_directed());
Source

pub fn from_weighted_edges( edges: &[(u32, u32, f64)], directed: bool, n_override: Option<u32>, ) -> IgraphResult<(Self, Vec<f64>)>

Build a graph from weighted edges, returning both the graph and the weight vector (indexed by edge id).

Each element of edges is (from, to, weight). The resulting weight vector has length equal to the edge count, with weights[eid] corresponding to the edge added from the eid-th tuple.

§Examples
use rust_igraph::Graph;

let (g, weights) = Graph::from_weighted_edges(
    &[(0, 1, 1.5), (1, 2, 2.0), (2, 0, 0.5)],
    false,
    None,
).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3);
assert_eq!(weights, vec![1.5, 2.0, 0.5]);
Source

pub fn from_edge_list_str(s: &str) -> IgraphResult<Self>

Parse an undirected graph from an edge-list string.

Each non-empty, non-comment line should contain two whitespace-separated vertex ids. Lines starting with # are ignored. This is the most convenient way to construct a graph inline (e.g. in tests or examples).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edge_list_str("0 1\n1 2\n2 0").unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3);
Source

pub fn from_adjacency_matrix( matrix: &[Vec<f64>], directed: bool, ) -> IgraphResult<Self>

Construct a graph from an adjacency matrix.

Counterpart of igraph_adjacency(). The matrix should be a square n×n slice-of-slices where matrix[i][j] gives the number of edges from vertex i to vertex j (or the edge weight; see below).

For undirected graphs (directed = false), only the upper triangle is used (including diagonal for self-loops); the lower triangle is ignored. Each non-zero entry matrix[i][j] (with i <= j) creates one edge.

For directed graphs, every non-zero entry creates one edge.

Entries are rounded to the nearest integer to determine edge count. If you need fractional weights, use from_adjacency_matrix_weighted.

§Errors

Returns an error if the matrix is not square.

§Examples
use rust_igraph::Graph;

let adj = vec![
    vec![0.0, 1.0, 1.0],
    vec![1.0, 0.0, 1.0],
    vec![1.0, 1.0, 0.0],
];
let g = Graph::from_adjacency_matrix(&adj, false).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3); // triangle
Source

pub fn from_adjacency_matrix_weighted( matrix: &[Vec<f64>], directed: bool, ) -> IgraphResult<(Self, Vec<f64>)>

Construct a graph from an adjacency matrix, also returning edge weights.

Like from_adjacency_matrix, but instead of rounding entries to edge counts, each non-zero entry creates exactly one edge with the matrix value as its weight.

Returns the graph and a weight vector aligned with edge indices.

§Errors

Returns an error if the matrix is not square.

§Examples
use rust_igraph::Graph;

let adj = vec![
    vec![0.0, 2.5, 0.0],
    vec![2.5, 0.0, 1.0],
    vec![0.0, 1.0, 0.0],
];
let (g, weights) = Graph::from_adjacency_matrix_weighted(&adj, false).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 2);
assert!((weights[0] - 2.5).abs() < 1e-10);
assert!((weights[1] - 1.0).abs() < 1e-10);
Source

pub fn from_adjacency_list( adj_list: &[Vec<u32>], directed: bool, ) -> IgraphResult<Self>

Construct a graph from an adjacency list.

adj_list[v] contains the neighbors of vertex v. The number of vertices is adj_list.len().

For undirected graphs (directed = false), an edge (u, v) should appear in both adj_list[u] and adj_list[v]; each pair is counted once (duplicates are deduplicated by only adding edge (u, v) when u <= v or when it appears only in adj_list[u]).

For directed graphs, adj_list[v] lists the out-neighbors of v.

§Errors

Returns an error if any neighbor index is out of range.

§Examples
use rust_igraph::Graph;

// Triangle: 0-1, 1-2, 0-2
let adj = vec![vec![1, 2], vec![0, 2], vec![0, 1]];
let g = Graph::from_adjacency_list(&adj, false).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3);
use rust_igraph::Graph;

// Directed: 0->1, 0->2, 1->2
let adj = vec![vec![1, 2], vec![2], vec![]];
let g = Graph::from_adjacency_list(&adj, true).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3);
assert!(g.is_directed());
Source

pub fn with_vertices(n: u32) -> Self

Construct an empty undirected graph on n vertices.

Builds the graph directly (no intermediate Result) since an empty undirected graph with n vertices cannot fail to construct.

§Examples
use rust_igraph::Graph;

let g = Graph::with_vertices(4);
assert_eq!(g.vcount(), 4);
assert!(!g.is_directed());
Source

pub fn vcount(&self) -> u32

Number of vertices. Counterpart of igraph_vcount().

§Examples
use rust_igraph::Graph;

let g = Graph::with_vertices(10);
assert_eq!(g.vcount(), 10);
Source

pub fn ecount(&self) -> usize

Number of edges. Counterpart of igraph_ecount().

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
assert_eq!(g.ecount(), 2);
Source

pub fn is_directed(&self) -> bool

true if the graph is directed. Counterpart of igraph_is_directed().

§Examples
use rust_igraph::Graph;

let g = Graph::new(3, true).unwrap();
assert!(g.is_directed());

let g2 = Graph::with_vertices(3);
assert!(!g2.is_directed());
Source

pub fn vertex_ids(&self) -> impl Iterator<Item = VertexId>

Iterator over vertex ids 0..vcount().

§Examples
use rust_igraph::Graph;

let g = Graph::with_vertices(4);
let ids: Vec<u32> = g.vertex_ids().collect();
assert_eq!(ids, vec![0, 1, 2, 3]);
Source

pub fn edge_ids(&self) -> impl Iterator<Item = u32>

Iterator over edge ids 0..ecount().

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let ids: Vec<u32> = g.edge_ids().collect();
assert_eq!(ids, vec![0, 1]);
Source

pub fn edges(&self) -> impl Iterator<Item = (VertexId, VertexId)> + '_

Iterator over all edges as (from, to) pairs.

Yields edges in edge-id order. For undirected graphs, from <= to (canonicalised storage order).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let edges: Vec<(u32, u32)> = g.edges().collect();
assert_eq!(edges, vec![(0, 1), (1, 2)]);
Source

pub fn iter(&self) -> EdgeIter<'_>

Returns an iterator over edges as (from, to) pairs in edge-id order.

This is the named-return counterpart to the IntoIterator impl for &Graph, enabling graph.iter().filter(...) usage.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();

let edges: Vec<_> = g.iter().collect();
assert_eq!(edges, vec![(0, 1), (1, 2)]);
Source

pub fn has_edge(&self, from: VertexId, to: VertexId) -> bool

Check whether an edge exists between from and to.

On undirected graphs (u, v) and (v, u) are equivalent. Returns false for out-of-range vertex ids rather than erroring.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
assert!(g.has_edge(0, 1));
assert!(g.has_edge(1, 0)); // undirected
assert!(!g.has_edge(0, 2));
Source

pub fn add_vertices(&mut self, nv: u32) -> IgraphResult<(VertexId, VertexId)>

Append nv isolated vertices, returning the inclusive id range (first, last) of the new vertices. If nv == 0 returns (self.n, self.n) and does nothing.

Counterpart of igraph_add_vertices().

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
let (first, last) = g.add_vertices(2).unwrap();
assert_eq!(first, 3);
assert_eq!(last, 4);
assert_eq!(g.vcount(), 5);
Source

pub fn add_edge(&mut self, u: VertexId, v: VertexId) -> IgraphResult<()>

Add a single edge from u to v.

Self-loops and parallel edges are allowed. For undirected graphs the edge is canonicalised so the stored from <= to.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
assert_eq!(g.ecount(), 2);
Source

pub fn add_edges<I>(&mut self, edges: I) -> IgraphResult<()>
where I: IntoIterator<Item = (VertexId, VertexId)>,

Add a sequence of edges. After all edges are appended, the indexes (oi / ii / os / is) are rebuilt in one pass — counterpart of igraph_add_edges (type_indexededgelist.c:254-367).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(4);
g.add_edges(vec![(0, 1), (1, 2), (2, 3)]).unwrap();
assert_eq!(g.ecount(), 3);
Source

pub fn neighbors(&self, v: VertexId) -> IgraphResult<Vec<VertexId>>

Out-edge neighbour iterator for vertex v.

For undirected graphs this returns all neighbours (since the indexing tracks both endpoints symmetrically). Order is the upstream igraph order — edges are visited in oi order, then ii order, with duplicates suppressed when the same edge is incident on both.

Counterpart of igraph_neighbors(graph, _, vid, IGRAPH_ALL, ...).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
let neis = g.neighbors(0).unwrap();
assert_eq!(neis, vec![1, 2, 3]);
Source

pub fn neighbors_iter(&self, v: VertexId) -> IgraphResult<NeighborsIter<'_>>

Zero-allocation iterator over the neighbors of vertex v.

For directed graphs, yields out-neighbors in ascending order. For undirected graphs, yields all neighbors in ascending order (merged from out-edge and in-edge sublists without allocation).

Prefer this over Graph::neighbors in hot loops where avoiding a Vec allocation matters.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
let neis: Vec<u32> = g.neighbors_iter(0).unwrap().collect();
assert_eq!(neis, vec![1, 2, 3]);
Source

pub fn to_adjacency_list(&self) -> IgraphResult<Vec<Vec<VertexId>>>

Convert the graph to an adjacency list representation.

Returns a Vec<Vec<u32>> where result[v] contains the neighbors of vertex v. For directed graphs, returns out-neighbors.

For undirected graphs, each edge (u, v) causes v to appear in result[u] and u to appear in result[v].

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let adj = g.to_adjacency_list().unwrap();
assert_eq!(adj[0], vec![1]);
assert_eq!(adj[1], vec![0, 2]);
assert_eq!(adj[2], vec![1]);
Source

pub fn to_adjacency_matrix(&self) -> Vec<Vec<f64>>

Return the adjacency matrix as a dense n × n matrix of f64.

Entry [i][j] is the number of edges from vertex i to vertex j. For undirected graphs the matrix is symmetric. Self-loops contribute 1 to [i][i] (not 2).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let m = g.to_adjacency_matrix();
assert_eq!(m[0][1], 1.0);
assert_eq!(m[1][0], 1.0);
assert_eq!(m[0][2], 0.0);
Source

pub fn degree(&self, v: VertexId) -> IgraphResult<usize>

Degree of vertex v — number of edges incident to it.

On undirected graphs every edge counts once except a self-loop which counts twice (matches upstream igraph’s IGRAPH_LOOPS = TWICE default at type_indexededgelist.c:1162).

Counterpart of igraph_degree_1(_, _, _, IGRAPH_ALL, IGRAPH_LOOPS_TWICE).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
assert_eq!(g.degree(0).unwrap(), 2);
assert_eq!(g.degree(1).unwrap(), 1);
Source

pub fn out_degree(&self, v: VertexId) -> IgraphResult<usize>

Out-degree of vertex v (number of outgoing edges).

For undirected graphs, this equals the total degree.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,0)], true, None).unwrap();
assert_eq!(g.out_degree(0).unwrap(), 2);
assert_eq!(g.out_degree(1).unwrap(), 1);
Source

pub fn in_degree(&self, v: VertexId) -> IgraphResult<usize>

In-degree of vertex v (number of incoming edges).

For undirected graphs, this equals the total degree.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,0)], true, None).unwrap();
assert_eq!(g.in_degree(0).unwrap(), 1);
assert_eq!(g.in_degree(1).unwrap(), 1);
assert_eq!(g.in_degree(2).unwrap(), 1);
Source

pub fn max_degree(&self) -> usize

Maximum degree across all vertices (total degree for undirected, out-degree for directed). Returns 0 for empty graphs.

Counterpart of igraph_maxdegree().

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
assert_eq!(g.max_degree(), 3);
Source

pub fn min_degree(&self) -> usize

Minimum degree across all vertices (total degree for undirected, out-degree for directed). Returns 0 for empty graphs.

Counterpart of igraph_mindegree() (custom extension).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
// vertex 3 has degree 0
assert_eq!(g.min_degree(), 0);
Source

pub fn edge_source(&self, eid: u32) -> IgraphResult<VertexId>

Source endpoint of edge eid. Counterpart of IGRAPH_FROM (igraph_interface.h:115).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 2).unwrap();
assert_eq!(g.edge_source(0).unwrap(), 0);
Source

pub fn edge_target(&self, eid: u32) -> IgraphResult<VertexId>

Target endpoint of edge eid. Counterpart of IGRAPH_TO (igraph_interface.h:128).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 2).unwrap();
assert_eq!(g.edge_target(0).unwrap(), 2);
Source

pub fn edge(&self, eid: u32) -> IgraphResult<(VertexId, VertexId)>

Both endpoints of edge eid, ordered as (from, to). Counterpart of igraph_edge (igraph_interface.h:71).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
let (from, to) = g.edge(0).unwrap();
assert_eq!(from, 0);
assert_eq!(to, 1);
Source

pub fn edge_other(&self, eid: u32, vid: VertexId) -> IgraphResult<VertexId>

The other endpoint of eid given one endpoint vid. Counterpart of IGRAPH_OTHER (igraph_interface.h:145). Errors if vid is not actually an endpoint of eid.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 2).unwrap();
assert_eq!(g.edge_other(0, 0).unwrap(), 2);
assert_eq!(g.edge_other(0, 2).unwrap(), 0);
Source

pub fn incident(&self, v: VertexId) -> IgraphResult<Vec<u32>>

Edge ids incident to vertex v, in the same iteration order as Graph::neighbors.

For undirected graphs returns the union of out-side (oi) and in-side (ii) edges — every edge incident to v once, except self-loops which appear twice (matching igraph_neighbors / igraph_degree’s IGRAPH_LOOPS_TWICE default at type_indexededgelist.c:1162).

For directed graphs returns out-edges only, mirroring this AWU’s neighbors() choice. (The full mode-aware variant lands later alongside igraph_neighbors(mode = IN/OUT/ALL).)

Counterpart of igraph_incident(_, _, v, IGRAPH_ALL, IGRAPH_LOOPS_TWICE) for undirected; IGRAPH_OUT mode for directed.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap(); // edge 0
g.add_edge(0, 2).unwrap(); // edge 1
let inc = g.incident(0).unwrap();
assert_eq!(inc.len(), 2);
Source

pub fn get_eid(&self, from: VertexId, to: VertexId) -> IgraphResult<u32>

Edge id between from and to, if any.

On undirected graphs (u, v) and (v, u) are equivalent. On directed graphs the search follows the edge direction from -> to. Returns crate::IgraphError::InvalidArgument when no such edge exists; for the “no error, return None” variant use Self::find_eid.

Counterpart of igraph_get_eid(_, _, from, to, /*directed=*/true, /*error=*/true) from references/igraph/src/graph/type_indexededgelist.c:1522-1555. Phase-1 minimal slice: linear scan across the from-bucket; the upstream binary-search optimisation lands in a perf pass.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
assert_eq!(g.get_eid(0, 1).unwrap(), 0);
assert_eq!(g.get_eid(1, 2).unwrap(), 1);
assert!(g.get_eid(0, 2).is_err());
Source

pub fn find_eid( &self, from: VertexId, to: VertexId, ) -> IgraphResult<Option<u32>>

Edge id between from and to, or None if not connected.

Same semantics as Self::get_eid but no-error variant matching upstream’s error=false mode. When parallel edges exist, returns the lowest edge id (matching upstream’s “always returns the same edge ID” guarantee).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
assert_eq!(g.find_eid(0, 1).unwrap(), Some(0));
assert_eq!(g.find_eid(0, 2).unwrap(), None);
Source

pub fn get_all_eids_between( &self, from: VertexId, to: VertexId, ) -> IgraphResult<Vec<u32>>

All edge ids between from and to, including parallel edges and (for self-loops) the loop edge once.

Counterpart of igraph_get_all_eids_between() from references/igraph/src/graph/type_indexededgelist.c:~1700. On undirected graphs (u, v) and (v, u) are equivalent. The returned vector is sorted ascending by edge id.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(2);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 1).unwrap(); // parallel edge
let eids = g.get_all_eids_between(0, 1).unwrap();
assert_eq!(eids, vec![0, 1]);
Source

pub fn delete_edges(&mut self, edges: &[u32]) -> IgraphResult<()>

Remove the given edges from the graph.

edges may contain the same id more than once — the second and later occurrences are no-ops. Remaining edges keep their pairwise relative order but are renumbered so edge ids stay contiguous starting at 0. Returns IgraphError::EdgeOutOfRange if any id is >= ecount(); on error the graph is left unchanged.

Counterpart of igraph_delete_edges (references/igraph/src/graph/type_indexededgelist.c:500).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(0, 2).unwrap();
g.delete_edges(&[1]).unwrap(); // remove edge 1-2
assert_eq!(g.ecount(), 2);
Source

pub fn delete_vertices(&mut self, vertices: &[VertexId]) -> IgraphResult<()>

Remove the given vertices and all their incident edges.

vertices may repeat ids freely. Surviving vertices get renumbered so the new id space is 0..new_vcount in their previous relative order. Returns IgraphError::VertexOutOfRange if any id is >= vcount(); on error the graph is left unchanged.

Counterpart of igraph_delete_vertices (references/igraph/src/graph/type_indexededgelist.c:540).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.delete_vertices(&[1]).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 1); // only edge 2-3 survives (renumbered)
Source

pub fn delete_vertices_map( &mut self, vertices: &[VertexId], ) -> IgraphResult<(Vec<Option<VertexId>>, Vec<VertexId>)>

Like delete_vertices, but also returns the old↔new vertex id mappings.

Returns (map, invmap) where:

  • map[old_id] == Some(new_id) if the vertex was retained, else None. Length is the original vertex count.
  • invmap[new_id] == old_id. Length is the new vertex count.

Counterpart of igraph_delete_vertices_map (references/igraph/src/graph/type_indexededgelist.c:645).

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(2, 3).unwrap();
let (map, invmap) = g.delete_vertices_map(&[1, 2]).unwrap();
assert_eq!(g.vcount(), 2);
assert_eq!(map, vec![Some(0), None, None, Some(1)]);
assert_eq!(invmap, vec![0, 3]);
Source

pub fn cache_get(&self, prop: CachedProperty) -> Option<bool>

Look up a cached boolean property without computing it.

Returns None if the property has not been cached yet. Pair with Self::cache_set in compute functions:

if let Some(v) = g.cache_get(CachedProperty::IsDag) { return v; }
let v = compute_is_dag(g);
g.cache_set(CachedProperty::IsDag, v);
v

Counterpart of igraph_i_property_cache_has + _get_bool from references/igraph/src/graph/caching.c.

use rust_igraph::{Graph, CachedProperty};

let g = Graph::with_vertices(3);
assert!(g.cache_get(CachedProperty::HasLoop).is_none());
g.cache_set(CachedProperty::HasLoop, true);
assert_eq!(g.cache_get(CachedProperty::HasLoop), Some(true));
Source

pub fn cache_set(&self, prop: CachedProperty, value: bool)

Store the value of a cached boolean property.

Takes &self (interior mutability via Cell) — populating the cache from a compute function is not considered a mutation of the graph, matching igraph C semantics where compute helpers take const igraph_t * and still write to the cache.

Counterpart of igraph_i_property_cache_set_bool.

Source

pub fn cache_invalidate(&self, prop: CachedProperty)

Drop the cached value of a single property (no-op if not cached).

Use this if you change the graph via a private path that doesn’t go through add_edges / delete_*.

Counterpart of igraph_i_property_cache_invalidate.

use rust_igraph::{Graph, CachedProperty};

let g = Graph::with_vertices(3);
g.cache_set(CachedProperty::HasLoop, true);
g.cache_invalidate(CachedProperty::HasLoop);
assert!(g.cache_get(CachedProperty::HasLoop).is_none());
Source

pub fn cache_invalidate_all(&self)

Drop every cached boolean property.

Counterpart of igraph_i_property_cache_invalidate_all.

use rust_igraph::{Graph, CachedProperty};

let g = Graph::with_vertices(3);
g.cache_set(CachedProperty::HasLoop, true);
g.cache_invalidate_all();
assert!(g.cache_get(CachedProperty::HasLoop).is_none());
Source§

impl Graph

Source

pub fn density(&self) -> IgraphResult<Option<f64>>

Compute the density of this graph.

Density is the ratio of actual edges to possible edges. Returns None for graphs with fewer than 2 vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let d = g.density().unwrap().unwrap();
assert!((d - 1.0).abs() < 1e-10); // K_3 is fully connected
Source

pub fn is_connected(&self) -> IgraphResult<bool>

Check whether the graph is connected.

For directed graphs this checks weak connectivity by default.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_connected().unwrap());
Source

pub fn is_simple(&self) -> IgraphResult<bool>

Check whether the graph is simple (no self-loops, no multi-edges).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_simple().unwrap());
Source

pub fn connected_components(&self) -> IgraphResult<ConnectedComponents>

Compute connected components.

§Examples
use rust_igraph::Graph;

let mut g = Graph::new(4, false).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(2, 3).unwrap();
let cc = g.connected_components().unwrap();
assert_eq!(cc.count, 2);
Source

pub fn pagerank(&self) -> IgraphResult<Vec<f64>>

Compute PageRank centrality for all vertices.

Uses the default damping factor (0.85).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let pr = g.pagerank().unwrap();
assert_eq!(pr.len(), 3);
Source

pub fn betweenness(&self) -> IgraphResult<Vec<f64>>

Compute betweenness centrality for all vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let bc = g.betweenness().unwrap();
// Middle vertices have higher betweenness
assert!(bc[1] > bc[0]);
Source

pub fn closeness(&self) -> IgraphResult<Vec<Option<f64>>>

Compute closeness centrality for all vertices.

For each vertex, closeness is the reciprocal of the average shortest path distance to all reachable vertices. Returns None for isolated vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let cl = g.closeness().unwrap();
assert_eq!(cl.len(), 4);
// Middle vertices have higher closeness
assert!(cl[1].unwrap() > cl[0].unwrap());
Source

pub fn eigenvector_centrality(&self) -> IgraphResult<Vec<f64>>

Compute eigenvector centrality for all vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let ec = g.eigenvector_centrality().unwrap();
assert_eq!(ec.len(), 3);
Source

pub fn clustering_coefficients(&self) -> IgraphResult<Vec<Option<f64>>>

Compute per-vertex local clustering coefficients.

Returns the fraction of actual edges between each vertex’s neighbours out of all possible edges. Vertices with fewer than 2 neighbours return None.

§Examples
use rust_igraph::Graph;

// A triangle: all vertices have clustering coefficient 1.0
let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let cc = g.clustering_coefficients().unwrap();
assert!((cc[0].unwrap() - 1.0).abs() < 1e-10);
Source

pub fn complement(&self) -> IgraphResult<Graph>

Compute the complement graph.

The complement has the same vertices but edges wherever the original does not (excluding self-loops by default).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1)], false, Some(3)).unwrap();
let c = g.complement().unwrap();
// K_3 has 3 edges; original has 1; complement has 2
assert_eq!(c.ecount(), 2);
Source

pub fn line_graph(&self) -> IgraphResult<Graph>

Construct the line graph L(G).

The line graph has one vertex per edge of this graph. Two vertices in L(G) are adjacent iff the corresponding edges share an endpoint.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
let lg = g.line_graph().unwrap();
assert_eq!(lg.vcount(), 3);
assert_eq!(lg.ecount(), 3);
Source

pub fn louvain(&self) -> IgraphResult<LouvainResult>

Detect communities using the Louvain algorithm.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,2), (3,4), (3,5), (4,5), (2,3)],
    false, None,
).unwrap();
let result = g.louvain().unwrap();
assert!(result.modularity > 0.0);
Source

pub fn leiden(&self) -> IgraphResult<LeidenResult>

Detect communities using the Leiden algorithm.

Leiden improves upon Louvain by guaranteeing well-connected communities and avoiding the “poorly connected community” pathology.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,2), (3,4), (3,5), (4,5), (2,3)],
    false, None,
).unwrap();
let result = g.leiden().unwrap();
assert!(result.quality > 0.0);
Source

pub fn bridges(&self) -> IgraphResult<Vec<u32>>

Find all bridge edges (edges whose removal disconnects the graph).

§Examples
use rust_igraph::Graph;

// 0-1-2 with 1-2 as bridge vs. 0-1, 0-2, 1-2 (triangle, no bridges)
let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let br = g.bridges().unwrap();
assert_eq!(br.len(), 2); // both edges are bridges in a path
Source

pub fn coreness(&self) -> IgraphResult<Vec<u32>>

Compute the k-core decomposition (coreness of each vertex).

The coreness of a vertex is the largest k such that the vertex belongs to a k-core — a maximal subgraph where every vertex has degree at least k.

§Examples
use rust_igraph::Graph;

// Triangle (0,1,2) plus pendant vertex 3 attached to 0
let g = Graph::from_edges(&[(0,1), (1,2), (2,0), (0,3)], false, None).unwrap();
let cores = g.coreness().unwrap();
assert_eq!(cores[0], 2); // part of the triangle
assert_eq!(cores[3], 1); // pendant
Source

pub fn induced_subgraph( &self, vertices: &[VertexId], ) -> IgraphResult<InducedSubgraphResult>

Create the induced subgraph on the given vertex set.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3), (3,0)], false, None).unwrap();
let sub = g.induced_subgraph(&[0, 1, 2]).unwrap();
assert_eq!(sub.graph.vcount(), 3);
assert_eq!(sub.graph.ecount(), 2); // edges 0-1 and 1-2
Source

pub fn to_dot(&self, labels: Option<&[String]>) -> IgraphResult<String>

Export the graph in DOT (Graphviz) format as a string.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let dot = g.to_dot(None).unwrap();
assert!(dot.contains("--"));
Source

pub fn bfs(&self, root: VertexId) -> IgraphResult<Vec<VertexId>>

BFS traversal from a root vertex, returning visit order.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,3)], false, None).unwrap();
let order = g.bfs(0).unwrap();
assert_eq!(order[0], 0);
assert_eq!(order.len(), 4);
Source

pub fn dfs(&self, root: VertexId) -> IgraphResult<Vec<VertexId>>

DFS traversal from a root vertex, returning visit order.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,3)], false, None).unwrap();
let order = g.dfs(0).unwrap();
assert_eq!(order[0], 0);
assert_eq!(order.len(), 4);
Source

pub fn shortest_paths( &self, source: VertexId, ) -> IgraphResult<Vec<Vec<VertexId>>>

Unweighted shortest paths from a source to all reachable vertices.

Returns a vector of paths (each path is a Vec<VertexId>).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let paths = g.shortest_paths(0).unwrap();
assert_eq!(paths[3], vec![0, 1, 2, 3]);
Source

pub fn dijkstra( &self, source: VertexId, weights: &[f64], ) -> IgraphResult<Vec<Option<f64>>>

Weighted shortest-path distances from a source (Dijkstra).

Returns distances to all vertices; None for unreachable vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let weights = vec![1.0, 2.0, 3.0];
let dist = g.dijkstra(0, &weights).unwrap();
assert!((dist[3].unwrap() - 6.0).abs() < 1e-10);
Source

pub fn degree_sequence(&self) -> IgraphResult<Vec<u32>>

Compute the degree sequence (degree of each vertex).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,2)], false, None).unwrap();
let seq = g.degree_sequence().unwrap();
assert_eq!(seq, vec![2, 2, 2]);
Source

pub fn diameter(&self) -> IgraphResult<Option<u32>>

Compute the graph diameter (longest shortest path).

Returns None for graphs with zero vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
assert_eq!(g.diameter().unwrap(), Some(3));
Source

pub fn transitivity(&self) -> IgraphResult<Option<f64>>

Compute the global transitivity (clustering coefficient).

Returns None if there are no connected triples.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let t = g.transitivity().unwrap().unwrap();
assert!((t - 1.0).abs() < 1e-10); // triangle is fully transitive
Source

pub fn clique_number(&self) -> IgraphResult<u32>

Compute the clique number (size of the largest clique).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0), (2,3)], false, None).unwrap();
assert_eq!(g.clique_number().unwrap(), 3);
Source

pub fn largest_cliques(&self) -> IgraphResult<Vec<Vec<VertexId>>>

Find all largest cliques (cliques of maximum size).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2), (2,3)], false, None).unwrap();
let lc = g.largest_cliques().unwrap();
assert_eq!(lc.len(), 1);
assert_eq!(lc[0].len(), 3);
Source

pub fn maximal_cliques_count(&self) -> IgraphResult<u64>

Count maximal cliques without enumerating them.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2), (2,3)], false, None).unwrap();
assert!(g.maximal_cliques_count().unwrap() >= 2);
Source

pub fn clique_size_hist(&self) -> IgraphResult<Vec<u64>>

Histogram of clique sizes in the graph.

Returns a vector where entry i is the number of cliques of size i.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let hist = g.clique_size_hist().unwrap();
assert!(hist.len() >= 3);
Source

pub fn average_local_efficiency(&self) -> IgraphResult<f64>

Average local efficiency of the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let eff = g.average_local_efficiency().unwrap();
assert!(eff > 0.0);
Source

pub fn count_mutual(&self) -> IgraphResult<usize>

Count mutual (reciprocal) edges in a directed graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,0), (1,2)], true, None).unwrap();
let m = g.count_mutual().unwrap();
assert_eq!(m, 1);
Source

pub fn maximal_independent_vertex_sets( &self, ) -> IgraphResult<Vec<Vec<VertexId>>>

Find all maximal independent vertex sets.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let sets = g.maximal_independent_vertex_sets().unwrap();
assert!(!sets.is_empty());
Source

pub fn largest_independent_vertex_sets( &self, ) -> IgraphResult<Vec<Vec<VertexId>>>

Find all largest independent vertex sets.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let sets = g.largest_independent_vertex_sets().unwrap();
assert!(sets.iter().all(|s| s.len() == 2));
Source

pub fn edge_coloring_greedy(&self) -> IgraphResult<Vec<u32>>

Greedy edge coloring.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let colors = g.edge_coloring_greedy().unwrap();
assert_eq!(colors.len(), 3);
Source

pub fn chromatic_number_upper_bound(&self) -> IgraphResult<u32>

Upper bound on the chromatic number.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
assert!(g.chromatic_number_upper_bound().unwrap() >= 3);
Source

pub fn is_perfect(&self) -> IgraphResult<bool>

Test whether the graph is perfect (Strong Perfect Graph Theorem).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
assert!(g.is_perfect().unwrap());
Source

pub fn transitivity_avglocal(&self) -> IgraphResult<f64>

Average local transitivity (clustering coefficient).

Vertices with degree < 2 are treated as having transitivity 0.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let avg = g.transitivity_avglocal().unwrap();
assert!(avg > 0.9);
Source

pub fn mean_degree(&self) -> IgraphResult<Option<f64>>

Mean degree of all vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let md = g.mean_degree().unwrap();
assert!((md.unwrap() - 2.0).abs() < 1e-10);
Source

pub fn degeneracy(&self) -> IgraphResult<u32>

Graph degeneracy (maximum k for which a k-core exists).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
assert_eq!(g.degeneracy().unwrap(), 2);
Source

pub fn convergence_degree(&self) -> IgraphResult<Vec<f64>>

Convergence degree of each edge.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let cd = g.convergence_degree().unwrap();
assert_eq!(cd.len(), g.ecount());
Source

pub fn count_loops(&self) -> IgraphResult<usize>

Count self-loops in the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert_eq!(g.count_loops().unwrap(), 0);
Source

pub fn avg_nearest_neighbor_degree(&self) -> IgraphResult<Vec<Option<f64>>>

Average nearest neighbor degree for each vertex.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let knn = g.avg_nearest_neighbor_degree().unwrap();
assert_eq!(knn.len(), 3);
Source

pub fn bibcoupling(&self) -> IgraphResult<Vec<u32>>

Bibliographic coupling scores between all vertex pairs.

Returns a flat n*n matrix where entry [i*n + j] is the coupling score between vertices i and j.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,2), (1,2)], true, None).unwrap();
let n = g.vcount() as usize;
let bc = g.bibcoupling().unwrap();
assert_eq!(bc.len(), n * n);
Source

pub fn biconnected_components(&self) -> IgraphResult<BiconnectedComponents>

Biconnected components of the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0), (2,3)], false, None).unwrap();
let bc = g.biconnected_components().unwrap();
assert_eq!(bc.components.len(), 2);
Source

pub fn minimum_size_separators(&self) -> IgraphResult<Vec<Vec<VertexId>>>

Find all minimum-size vertex separators.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,3), (2,3)], false, None).unwrap();
let seps = g.minimum_size_separators().unwrap();
assert!(!seps.is_empty());
Source

pub fn all_minimal_st_separators(&self) -> IgraphResult<Vec<Vec<VertexId>>>

Find all minimal s-t separators.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,3), (2,3)], false, None).unwrap();
let seps = g.all_minimal_st_separators().unwrap();
assert!(!seps.is_empty());
Source

pub fn adhesion(&self) -> IgraphResult<i64>

Graph adhesion (minimum edge connectivity over all pairs).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert_eq!(g.adhesion().unwrap(), 2);
Source

pub fn cohesion(&self) -> IgraphResult<i64>

Graph cohesion (minimum vertex connectivity over all pairs).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert_eq!(g.cohesion().unwrap(), 2);
Source

pub fn bfs_tree(&self, root: VertexId) -> IgraphResult<BfsTree>

BFS tree rooted at root.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let tree = g.bfs_tree(0).unwrap();
assert_eq!(tree.order.len(), 3);
Source

pub fn dfs_tree(&self, root: VertexId) -> IgraphResult<DfsTree>

DFS tree rooted at root.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let tree = g.dfs_tree(0).unwrap();
assert_eq!(tree.order.len(), 3);
Source

pub fn articulation_points(&self) -> IgraphResult<Vec<VertexId>>

Find all articulation points (cut vertices).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3), (1,3)], false, None).unwrap();
let ap = g.articulation_points().unwrap();
assert_eq!(ap, vec![1]); // vertex 1 is the only cut vertex
Source

pub fn topological_sort(&self) -> IgraphResult<Vec<VertexId>>

Topological sort (DAG only, returns error for cyclic graphs).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], true, None).unwrap();
let order = g.topological_sort().unwrap();
assert_eq!(order[0], 0); // source comes first
Source

pub fn minimum_spanning_tree(&self) -> IgraphResult<Vec<u32>>

Compute a minimum spanning tree (unweighted).

Returns the edge ids forming the MST.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0), (2,3)], false, None).unwrap();
let mst_edges = g.minimum_spanning_tree().unwrap();
assert_eq!(mst_edges.len(), 3); // n-1 edges for connected graph
Source

pub fn summary(&self) -> IgraphResult<GraphSummary>

Compute a quick structural summary of the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let s = g.summary().unwrap();
assert_eq!(s.vcount, 3);
assert!(s.connected);
Source

pub fn max_flow(&self, source: VertexId, target: VertexId) -> IgraphResult<f64>

Compute the maximum flow value between two vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,3), (2,3)], true, None
).unwrap();
let flow = g.max_flow(0, 3).unwrap();
assert!((flow - 2.0).abs() < 1e-10);
Source

pub fn decompose(&self) -> IgraphResult<Vec<Graph>>

Decompose the graph into its connected components as separate graphs.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (2,3)], false, None).unwrap();
let components = g.decompose().unwrap();
assert_eq!(components.len(), 2);
Source

pub fn is_biconnected(&self) -> IgraphResult<bool>

Check whether the graph is biconnected.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_biconnected().unwrap());
Source

pub fn label_propagation(&self) -> IgraphResult<LpaResult>

Run label propagation community detection.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (3,4), (4,5), (5,3)], false, None
).unwrap();
let result = g.label_propagation().unwrap();
assert!(result.membership.len() == 6);
Source

pub fn walktrap(&self) -> IgraphResult<WalktrapResult>

Run Walktrap community detection.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (3,4), (4,5), (5,3), (2,3)], false, None
).unwrap();
let result = g.walktrap().unwrap();
assert!(result.membership.len() == 6);
Source

pub fn fast_greedy(&self) -> IgraphResult<FastGreedyResult>

Run fast greedy modularity community detection.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (3,4), (4,5), (5,3), (2,3)], false, None
).unwrap();
let result = g.fast_greedy().unwrap();
assert!(result.membership.len() == 6);
Source

pub fn hits(&self) -> IgraphResult<HitsScores>

Compute hub and authority scores (HITS algorithm).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], true, None).unwrap();
let hits = g.hits().unwrap();
assert_eq!(hits.hub.len(), 3);
assert_eq!(hits.authority.len(), 3);
Source

pub fn katz_centrality(&self, alpha: f64, beta: f64) -> IgraphResult<Vec<f64>>

Compute Katz centrality for all vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let katz = g.katz_centrality(0.1, 1.0).unwrap();
assert_eq!(katz.len(), 3);
Source

pub fn assortativity(&self) -> IgraphResult<Option<f64>>

Compute degree assortativity of the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let a = g.assortativity().unwrap();
assert!(a.is_some());
Source

pub fn from_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from a file, auto-detecting the format from the extension.

Supported extensions: .gml, .graphml, .dot, .net (Pajek), .ncol, .lgl, .leda, .dl, .edges/.edgelist/.txt.

§Examples
use rust_igraph::Graph;

let g = Graph::from_file("network.gml").unwrap();
println!("{}", g.vcount());
Source

pub fn to_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write a graph to a file, auto-detecting the format from the extension.

Supported extensions: .gml, .graphml, .dot, .net (Pajek), .ncol, .lgl, .leda, .dl, .edges/.edgelist/.txt.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,0)], false, None).unwrap();
g.to_file("output.gml").unwrap();
Source

pub fn from_edgelist_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from an edge list file.

Each line should contain two space-separated vertex ids.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edgelist_file("my_graph.edges").unwrap();
println!("{}", g.vcount());
Source

pub fn to_edgelist_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in edge list format.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_edgelist_file("output.edges").unwrap();
Source

pub fn from_gml_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from a GML file.

§Examples
use rust_igraph::Graph;

let g = Graph::from_gml_file("network.gml").unwrap();
Source

pub fn to_gml_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in GML format.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_gml_file("output.gml").unwrap();
Source

pub fn from_graphml_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from a GraphML file.

§Examples
use rust_igraph::Graph;

let g = Graph::from_graphml_file("network.graphml").unwrap();
Source

pub fn to_graphml_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in GraphML format.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_graphml_file("output.graphml").unwrap();
Source

pub fn from_dot_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from a DOT (Graphviz) file.

§Examples
use rust_igraph::Graph;

let g = Graph::from_dot_file("network.dot").unwrap();
Source

pub fn to_dot_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in DOT (Graphviz) format.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_dot_file("output.dot").unwrap();
Source

pub fn from_pajek_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from a Pajek (.net) file.

§Examples
use rust_igraph::Graph;

let g = Graph::from_pajek_file("network.net").unwrap();
Source

pub fn to_pajek_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in Pajek (.net) format.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_pajek_file("output.net").unwrap();
Source

pub fn from_ncol_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from an NCOL file (Large Graph Layout edge list format).

Returns just the graph; use read_ncol directly to also obtain vertex names and edge weights.

§Examples
use rust_igraph::Graph;

let g = Graph::from_ncol_file("network.ncol").unwrap();
Source

pub fn to_ncol_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in NCOL format.

Writes vertex indices as names (no custom names or weights). Use write_ncol for full control.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_ncol_file("output.ncol").unwrap();
Source

pub fn from_lgl_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from an LGL file (Large Graph Layout adjacency list).

Returns just the graph; use read_lgl directly to also obtain vertex names and edge weights.

§Examples
use rust_igraph::Graph;

let g = Graph::from_lgl_file("network.lgl").unwrap();
Source

pub fn to_lgl_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in LGL format.

Writes vertex indices as names (no custom names or weights). Use write_lgl for full control.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_lgl_file("output.lgl").unwrap();
Source

pub fn from_leda_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from a LEDA native graph file.

Returns just the graph; use read_leda directly to also obtain vertex labels and edge weights.

§Examples
use rust_igraph::Graph;

let g = Graph::from_leda_file("network.lgr").unwrap();
Source

pub fn to_leda_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in LEDA native graph format.

Writes without vertex labels or edge weights. Use write_leda for full control.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_leda_file("output.lgr").unwrap();
Source

pub fn from_dl_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from a UCINET DL file.

Reads as undirected by default. Use read_dl directly for directed graphs or to obtain vertex labels and edge weights.

§Examples
use rust_igraph::Graph;

let g = Graph::from_dl_file("network.dl").unwrap();
Source

pub fn to_dl_file<P: AsRef<Path>>(&self, path: P) -> IgraphResult<()>

Write the graph to a file in UCINET DL format.

Writes without vertex labels or edge weights. Use write_dl for full control.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
g.to_dl_file("output.dl").unwrap();
Source

pub fn from_dimacs_file<P: AsRef<Path>>(path: P) -> IgraphResult<Self>

Read a graph from a DIMACS file.

Reads as directed by default (flow problems). Returns just the graph; use read_dimacs directly to also obtain source/target, capacities, or labels.

§Examples
use rust_igraph::Graph;

let g = Graph::from_dimacs_file("network.dimacs").unwrap();
Source

pub fn erdos_renyi(n: u32, p: f64, seed: u64) -> IgraphResult<Self>

Generate an Erdos-Renyi G(n, p) random graph.

Each possible edge exists independently with probability p.

§Examples
use rust_igraph::Graph;

let g = Graph::erdos_renyi(100, 0.05, 42).unwrap();
assert_eq!(g.vcount(), 100);
assert!(!g.is_directed());
Source

pub fn barabasi_albert(n: u32, m: u32, seed: u64) -> IgraphResult<Self>

Generate a Barabasi-Albert preferential attachment graph.

Starts with one vertex and adds n - 1 vertices, each connecting to m existing vertices chosen with probability proportional to degree.

§Examples
use rust_igraph::Graph;

let g = Graph::barabasi_albert(100, 2, 42).unwrap();
assert_eq!(g.vcount(), 100);
assert!(!g.is_directed());
Source

pub fn watts_strogatz(n: u32, k: u32, p: f64, seed: u64) -> IgraphResult<Self>

Generate a Watts-Strogatz small-world graph.

Creates a ring lattice with n vertices where each vertex is connected to its k nearest neighbours (must be even), then rewires each edge with probability p. This produces graphs with both high clustering and short path lengths — the “small-world” property.

§Examples
use rust_igraph::Graph;

let g = Graph::watts_strogatz(20, 4, 0.3, 42).unwrap();
assert_eq!(g.vcount(), 20);
assert_eq!(g.ecount(), 40); // n * k / 2 = 20 * 4 / 2
Source

pub fn strongly_connected_components(&self) -> IgraphResult<ConnectedComponents>

Compute strongly connected components (directed graphs).

For undirected graphs, this is equivalent to connected components.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0), (2,3)], true, None).unwrap();
let scc = g.strongly_connected_components().unwrap();
assert_eq!(scc.count, 2);
Source

pub fn shortest_path_to( &self, source: VertexId, target: VertexId, weights: Option<&[f64]>, ) -> IgraphResult<ShortestPath>

Find the shortest path between two vertices.

Uses BFS for unweighted graphs, Dijkstra/Bellman-Ford for weighted. Returns the vertex and edge sequences along the path.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,3), (0,3)], false, None
).unwrap();
let path = g.shortest_path_to(0, 3, None).unwrap();
assert_eq!(path.vertices, vec![0, 3]);
Source

pub fn average_path_length(&self) -> IgraphResult<Option<f64>>

Compute the average path length of the graph.

Returns the mean shortest-path distance over all reachable vertex pairs. Unreachable pairs are excluded. Returns None if the graph has fewer than 2 vertices or no reachable pairs exist.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let apl = g.average_path_length().unwrap().unwrap();
assert!((apl - 5.0 / 3.0).abs() < 1e-10); // (1+2+3+1+2+1)/6
Source

pub fn is_bipartite(&self) -> IgraphResult<BipartiteResult>

Check if the graph is bipartite and return the partition if so.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let result = g.is_bipartite().unwrap();
assert!(result.is_bipartite);
Source

pub fn simplify( &self, remove_multiple: bool, remove_loops: bool, ) -> IgraphResult<Graph>

Remove self-loops and/or multi-edges from the graph.

Returns a new simplified graph.

§Examples
use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 1).unwrap(); // multi-edge
g.add_edge(1, 1).unwrap(); // self-loop
let simple = g.simplify(true, true).unwrap();
assert_eq!(simple.ecount(), 1);
Source

pub fn reverse(&self) -> IgraphResult<Graph>

Reverse all edge directions (directed graphs only).

For undirected graphs, returns a copy of the graph unchanged.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], true, None).unwrap();
let r = g.reverse().unwrap();
assert_eq!(r.neighbors(2).unwrap(), vec![1]);
Source

pub fn to_directed(&self, mode: ToDirectedMode) -> IgraphResult<Graph>

Convert an undirected graph to directed.

In Mutual mode each undirected edge becomes two directed edges (u→v and v→u). In Arbitrary mode each edge gets one direction (smaller → larger vertex id). Already-directed graphs are copied unchanged.

§Examples
use rust_igraph::{Graph, ToDirectedMode};

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let d = g.to_directed(ToDirectedMode::Mutual).unwrap();
assert!(d.is_directed());
assert_eq!(d.ecount(), 4);
Source

pub fn to_undirected(&self, mode: ToUndirectedMode) -> IgraphResult<Graph>

Convert a directed graph to undirected.

Each keeps every directed edge as undirected. Collapse merges mutual pairs into one edge. Mutual keeps only edges that exist in both directions. Already-undirected graphs are copied unchanged.

§Examples
use rust_igraph::{Graph, ToUndirectedMode};

let g = Graph::from_edges(&[(0,1), (1,0), (1,2)], true, None).unwrap();
let u = g.to_undirected(ToUndirectedMode::Collapse).unwrap();
assert!(!u.is_directed());
assert_eq!(u.ecount(), 2);
Source

pub fn contract_vertices(&self, mapping: &[VertexId]) -> IgraphResult<Graph>

Contract vertices according to a mapping.

mapping[v] specifies the new vertex id for vertex v. Vertices with the same mapping value are merged into one vertex.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
// Merge vertices 0,1 → 0 and 2,3 → 1
let contracted = g.contract_vertices(&[0, 0, 1, 1]).unwrap();
assert_eq!(contracted.vcount(), 2);
Source

pub fn random_walk( &self, start: VertexId, steps: u32, seed: u64, ) -> IgraphResult<(Vec<VertexId>, Vec<u32>)>

Perform a random walk starting from a given vertex.

Returns the sequence of visited vertex ids (length = steps + 1 including the starting vertex, or shorter if the walk gets stuck).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,3), (3,0)], false, None
).unwrap();
let (vertices, edges) = g.random_walk(0, 10, 42).unwrap();
assert_eq!(vertices[0], 0);
assert!(vertices.len() <= 11);
assert_eq!(edges.len(), vertices.len() - 1);
Source

pub fn random_walk_node2vec( &self, start: VertexId, steps: u32, p: f64, q: f64, seed: u64, ) -> IgraphResult<(Vec<VertexId>, Vec<u32>)>

Second-order biased random walk (Node2Vec) from start.

p controls the likelihood of returning to the previous vertex; q controls exploration vs. exploitation (BFS-like vs DFS-like). When p = q = 1.0 this is equivalent to a standard random walk.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,3), (3,0), (0,2)], false, None
).unwrap();
let (vertices, _edges) = g.random_walk_node2vec(0, 10, 2.0, 0.5, 42).unwrap();
assert_eq!(vertices[0], 0);
Source

pub fn radius(&self) -> IgraphResult<Option<u32>>

Compute the radius (minimum eccentricity) of the graph.

Returns None for the empty graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
assert_eq!(g.radius().unwrap(), Some(2));
Source

pub fn eccentricity(&self) -> IgraphResult<Vec<u32>>

Compute the eccentricity of every vertex.

result[v] is the maximum shortest-path distance from vertex v.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert_eq!(g.eccentricity().unwrap(), vec![2, 1, 2]);
Source

pub fn girth(&self) -> IgraphResult<Option<u32>>

Compute the girth (length of the shortest cycle) of the graph.

Returns None if the graph is acyclic.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert_eq!(g.girth().unwrap(), Some(3));
Source

pub fn is_tree(&self, mode: DijkstraMode) -> IgraphResult<Option<VertexId>>

Check whether the graph is a tree.

Returns Some(root) where root is the first root vertex found, or None if the graph is not a tree. The mode parameter controls how edges are followed for directed graphs.

§Examples
use rust_igraph::{Graph, DijkstraMode};

let g = Graph::from_edges(&[(0,1), (1,2), (1,3)], false, None).unwrap();
assert!(g.is_tree(DijkstraMode::All).unwrap().is_some());
Source

pub fn is_dag(&self) -> bool

Check whether the directed graph is a DAG.

Returns false for undirected graphs.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], true, None).unwrap();
assert!(g.is_dag());
Source

pub fn count_triangles(&self) -> IgraphResult<u64>

Count the total number of triangles in the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert_eq!(g.count_triangles().unwrap(), 1);
Source

pub fn harmonic_centrality(&self) -> IgraphResult<Vec<f64>>

Compute the harmonic centrality of all vertices.

Harmonic centrality of v is the sum of inverse distances from v to all other reachable vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let h = g.harmonic_centrality().unwrap();
assert_eq!(h.len(), 3);
Source

pub fn neighborhood_size(&self, order: i32) -> IgraphResult<Vec<u32>>

Compute the k-hop neighborhood size for every vertex.

result[v] is the number of vertices within distance order from v (including v itself).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let sizes = g.neighborhood_size(1).unwrap();
assert_eq!(sizes, vec![2, 3, 3, 2]);
Source

pub fn vertex_connectivity(&self) -> IgraphResult<i64>

Compute the vertex connectivity (minimum vertex cut) of the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,3), (2,3)], false, None,
).unwrap();
assert_eq!(g.vertex_connectivity().unwrap(), 2);
Source

pub fn edge_connectivity(&self) -> IgraphResult<i64>

Compute the edge connectivity (minimum edge cut) of the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,3), (2,3)], false, None,
).unwrap();
assert_eq!(g.edge_connectivity().unwrap(), 2);
Source

pub fn subcomponent( &self, source: VertexId, mode: SubcomponentMode, ) -> IgraphResult<Vec<VertexId>>

Find all vertices reachable from source.

§Examples
use rust_igraph::{Graph, SubcomponentMode};

let g = Graph::from_edges(&[(0,1), (1,2), (3,4)], false, None).unwrap();
let comp = g.subcomponent(0, SubcomponentMode::All).unwrap();
assert_eq!(comp.len(), 3);
Source

pub fn cliques( &self, min_size: u32, max_size: u32, max_results: Option<usize>, ) -> IgraphResult<Vec<Vec<VertexId>>>

Find all cliques in the graph within a size range.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let c = g.cliques(3, 3, None).unwrap();
assert_eq!(c.len(), 1);
Source

pub fn maximal_cliques(&self) -> IgraphResult<Vec<Vec<VertexId>>>

Find all maximal cliques in the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let mc = g.maximal_cliques().unwrap();
assert_eq!(mc.len(), 1);
assert_eq!(mc[0].len(), 3);
Source

pub fn independence_number(&self) -> IgraphResult<u32>

Compute the independence number (max independent set size).

§Examples
use rust_igraph::Graph;

// Triangle: independence number is 1 (can pick at most 1 non-adjacent vertex pair... no, 1)
let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert_eq!(g.independence_number().unwrap(), 1);
Source

pub fn permute_vertices(&self, permutation: &[VertexId]) -> IgraphResult<Graph>

Permute the vertices of the graph.

permutation[v] gives the new id for vertex v. Returns a new graph with edges reconnected accordingly.

§Examples
use rust_igraph::Graph;

// permutation[new] = old: new 0 ← old 2, new 1 ← old 0, new 2 ← old 1
let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let p = g.permute_vertices(&[2, 0, 1]).unwrap();
assert!(p.has_edge(1, 2));
assert!(p.has_edge(2, 0));
Source

pub fn layout_fruchterman_reingold(&self) -> IgraphResult<Vec<(f64, f64)>>

Fruchterman-Reingold force-directed layout with default parameters.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let coords = g.layout_fruchterman_reingold().unwrap();
assert_eq!(coords.len(), 3);
Source

pub fn layout_kamada_kawai(&self) -> IgraphResult<Vec<[f64; 2]>>

Kamada-Kawai spring-embedder layout with default parameters.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let coords = g.layout_kamada_kawai().unwrap();
assert_eq!(coords.len(), 4);
Source

pub fn layout_drl(&self) -> IgraphResult<Vec<[f64; 2]>>

DrL (Distributed Recursive Layout) with default options.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let coords = g.layout_drl().unwrap();
assert_eq!(coords.len(), 3);
Source

pub fn layout_circle(&self) -> Vec<(f64, f64)>

Circular layout.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let coords = g.layout_circle();
assert_eq!(coords.len(), 3);
Source

pub fn layout_random(&self, seed: u64) -> Vec<(f64, f64)>

Random layout with the given RNG seed.

§Examples
use rust_igraph::Graph;

let g = Graph::with_vertices(5);
let coords = g.layout_random(42);
assert_eq!(coords.len(), 5);
Source

pub fn layout_grid(&self, width: i32) -> Vec<(f64, f64)>

Grid layout.

width specifies the number of columns. Pass 0 to auto-compute (ceil of square root of vertex count).

§Examples
use rust_igraph::Graph;

let g = Graph::with_vertices(9);
let coords = g.layout_grid(3);
assert_eq!(coords.len(), 9);
Source

pub fn count_adjacent_triangles(&self) -> IgraphResult<Vec<u64>>

Per-vertex triangle count.

result[v] is the number of triangles incident to vertex v.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,0),(2,3)], false, None).unwrap();
let t = g.count_adjacent_triangles().unwrap();
assert_eq!(t[0], 1);
assert_eq!(t[3], 0);
Source

pub fn transitivity_local_undirected(&self) -> IgraphResult<Vec<Option<f64>>>

Per-vertex local clustering coefficient (local transitivity).

result[v] is None for vertices with degree < 2.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,0),(2,3)], false, None).unwrap();
let lcc = g.transitivity_local_undirected().unwrap();
assert!(lcc[0].unwrap() > 0.9); // vertex 0 in triangle
assert!(lcc[3].is_none());       // degree 1
Source

pub fn reciprocity(&self) -> IgraphResult<Option<f64>>

Reciprocity of a directed graph.

Returns the fraction of edges that are reciprocated, or None for empty graphs.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,0),(1,2)], true, None).unwrap();
let r = g.reciprocity().unwrap().unwrap();
assert!((r - 2.0/3.0).abs() < 1e-12);
Source

pub fn constraint(&self, weights: Option<&[f64]>) -> IgraphResult<Vec<f64>>

Burt’s constraint for each vertex.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,2),(1,2)], false, None).unwrap();
let c = g.constraint(None).unwrap();
assert_eq!(c.len(), 3);
Source

pub fn has_multiple(&self) -> IgraphResult<bool>

Whether the graph has multi-edges.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,1)], false, None).unwrap();
assert!(g.has_multiple().unwrap());
Source

pub fn count_multiple(&self) -> IgraphResult<Vec<usize>>

Per-edge multiplicity count.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,1),(1,2)], false, None).unwrap();
let mc = g.count_multiple().unwrap();
assert_eq!(mc[0], 2);
assert_eq!(mc[2], 1);
Source

pub fn are_adjacent(&self, v1: VertexId, v2: VertexId) -> IgraphResult<bool>

Test whether two vertices are adjacent.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
assert!(g.are_adjacent(0, 1).unwrap());
assert!(!g.are_adjacent(0, 2).unwrap());
Source

pub fn triad_census(&self) -> IgraphResult<TriadCensus>

Triad census of a directed graph.

§Examples
use rust_igraph::{Graph, TriadType};

let g = Graph::from_edges(&[(0,1),(1,2),(2,0)], true, None).unwrap();
let tc = g.triad_census().unwrap();
assert!(tc.get(TriadType::T030C) > 0.0);
Source

pub fn dyad_census(&self) -> IgraphResult<DyadCensus>

Dyad census of a directed graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,0),(1,2)], true, None).unwrap();
let dc = g.dyad_census().unwrap();
assert!((dc.mutual - 1.0).abs() < 1e-12);
Source

pub fn similarity_jaccard(&self) -> IgraphResult<Vec<f64>>

Jaccard similarity between all pairs of vertices.

Returns a flattened n × n matrix (row-major).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,2),(1,2)], false, None).unwrap();
let sim = g.similarity_jaccard().unwrap();
assert_eq!(sim.len(), 9); // 3×3 matrix
Source

pub fn cocitation(&self) -> IgraphResult<Vec<u32>>

Co-citation scores for all vertex pairs.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,2),(1,2)], true, None).unwrap();
let cc = g.cocitation().unwrap();
assert!(!cc.is_empty());
Source

pub fn is_cograph(&self) -> IgraphResult<bool>

Check whether the graph is a cograph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,2)], false, None).unwrap();
assert!(g.is_cograph().unwrap());
Source

pub fn is_series_parallel(&self) -> IgraphResult<bool>

Check whether the graph is series-parallel.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
assert!(g.is_series_parallel().unwrap());
Source

pub fn is_outerplanar(&self) -> IgraphResult<bool>

Check whether the graph is outerplanar.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_outerplanar().unwrap());
Source

pub fn is_chordal(&self) -> IgraphResult<bool>

Check whether the graph is chordal.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (0,3), (1,3), (2,3)], false, None
).unwrap();
assert!(g.is_chordal().unwrap());
Source

pub fn is_forest(&self) -> IgraphResult<bool>

Check whether the graph is a forest (acyclic).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
assert!(g.is_forest().unwrap());
Source

pub fn fundamental_cycles(&self) -> IgraphResult<Vec<Vec<u32>>>

Compute a fundamental cycle basis of the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0)], false, None
).unwrap();
let cycles = g.fundamental_cycles().unwrap();
assert_eq!(cycles.len(), 1);
Source

pub fn minimum_cycle_basis(&self) -> IgraphResult<Vec<Vec<u32>>>

Compute a minimum weight cycle basis.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (1,3), (3,0)], false, None
).unwrap();
let basis = g.minimum_cycle_basis().unwrap();
assert_eq!(basis.len(), 2);
Source

pub fn feedback_arc_set(&self) -> IgraphResult<Vec<u32>>

Find a minimum feedback arc set.

Returns edges whose removal makes the graph acyclic.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], true, None).unwrap();
let fas = g.feedback_arc_set().unwrap();
assert!(!fas.is_empty());
Source

pub fn maximum_cut(&self) -> IgraphResult<MaxCutResult>

Find the maximum cut of the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,3)], false, None
).unwrap();
let result = g.maximum_cut().unwrap();
assert!(result.cut_value > 0);
Source

pub fn minimum_vertex_cover(&self) -> IgraphResult<Vec<u32>>

Find a minimum vertex cover.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let cover = g.minimum_vertex_cover().unwrap();
assert!(cover.contains(&1));
Source

pub fn minimum_edge_cover(&self) -> IgraphResult<Vec<u32>>

Find a minimum edge cover.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let cover = g.minimum_edge_cover().unwrap();
assert!(!cover.is_empty());
Source

pub fn maximum_independent_set(&self) -> IgraphResult<Vec<u32>>

Find a maximum independent set.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let mis = g.maximum_independent_set().unwrap();
assert_eq!(mis.len(), 2);
Source

pub fn vertex_coloring(&self) -> IgraphResult<Vec<u32>>

Greedy vertex coloring.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0)], false, None
).unwrap();
let colors = g.vertex_coloring().unwrap();
assert_eq!(colors.len(), 3);
// Adjacent vertices must have different colors
assert_ne!(colors[0], colors[1]);
Source

pub fn random_spanning_tree(&self, seed: u64) -> IgraphResult<Vec<u32>>

Sample a random spanning tree.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (1,3)], false, None
).unwrap();
let edges = g.random_spanning_tree(42).unwrap();
assert_eq!(edges.len(), 3);
Source

pub fn edge_betweenness_community(&self) -> IgraphResult<EdgeBetweennessResult>

Edge betweenness community detection.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (3,4), (4,5), (5,3), (2,3)],
    false, None
).unwrap();
let result = g.edge_betweenness_community().unwrap();
assert!(!result.membership.is_empty());
Source

pub fn canonical_permutation(&self) -> IgraphResult<Vec<u32>>

Compute a canonical vertex permutation.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let perm = g.canonical_permutation().unwrap();
assert_eq!(perm.len(), 3);
Source

pub fn count_automorphisms(&self) -> IgraphResult<f64>

Count automorphisms of the graph.

§Examples
use rust_igraph::Graph;

// K3 has 3! = 6 automorphisms
let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0)], false, None
).unwrap();
let count = g.count_automorphisms().unwrap();
assert!((count - 6.0).abs() < 1e-10);
Source

pub fn automorphism_group(&self) -> IgraphResult<Vec<Vec<u32>>>

Compute a generating set for the automorphism group.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let gens = g.automorphism_group().unwrap();
assert!(!gens.is_empty());
Source

pub fn sir( &self, beta: f64, gamma: f64, no_sim: usize, seed: u64, ) -> IgraphResult<Vec<Sir>>

Run a single SIR (Susceptible-Infected-Recovered) simulation.

beta is the infection rate, gamma is the recovery rate.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,3), (3,4)], false, None
).unwrap();
let result = g.sir(0.5, 0.1, 1, 42).unwrap();
assert!(!result.is_empty());
Source

pub fn spanner(&self, stretch: f64) -> IgraphResult<Vec<u32>>

Compute a graph spanner with the given stretch factor.

Returns edge indices forming the spanner subgraph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (1,3)], false, None
).unwrap();
let edges = g.spanner(3.0).unwrap();
assert!(!edges.is_empty());
Source

pub fn is_acyclic(&self) -> bool

Check whether this graph is acyclic (a DAG for directed, forest for undirected).

§Examples
use rust_igraph::Graph;

let tree = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(tree.is_acyclic());
Source

pub fn is_apex_forest(&self) -> IgraphResult<bool>

Check whether this graph is an apex forest.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_apex_forest().unwrap());
Source

pub fn is_apex_tree(&self) -> IgraphResult<bool>

Check whether this graph is an apex tree.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_apex_tree().unwrap());
Source

pub fn is_banner_free(&self) -> IgraphResult<bool>

Check whether this graph is banner-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_banner_free().unwrap());
Source

pub fn is_biclique(&self) -> IgraphResult<bool>

Check whether this graph is a biclique.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,2), (0,3), (1,2), (1,3)], false, None).unwrap();
assert!(g.is_biclique().unwrap());
Source

pub fn is_biregular(&self) -> IgraphResult<bool>

Check whether this graph is biregular.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,2), (0,3), (1,2), (1,3)], false, None).unwrap();
assert!(g.is_biregular().unwrap());
Source

pub fn is_block_graph(&self) -> IgraphResult<bool>

Check whether this graph is a block graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_block_graph().unwrap());
Source

pub fn is_bowtie_free(&self) -> IgraphResult<bool>

Check whether this graph is bowtie-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_bowtie_free().unwrap());
Source

pub fn is_bull_free(&self) -> IgraphResult<bool>

Check whether this graph is bull-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_bull_free().unwrap());
Source

pub fn is_c4_free(&self) -> IgraphResult<bool>

Check whether this graph is C4-free (contains no 4-cycle).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_c4_free().unwrap());
Source

pub fn is_c5_free(&self) -> IgraphResult<bool>

Check whether this graph is C5-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_c5_free().unwrap());
Source

pub fn is_cactus_graph(&self) -> IgraphResult<bool>

Check whether this graph is a cactus graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_cactus_graph().unwrap());
Source

pub fn is_caterpillar(&self) -> IgraphResult<bool>

Check whether this graph is a caterpillar.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (1,3)], false, None).unwrap();
assert!(g.is_caterpillar().unwrap());
Source

pub fn is_chain_graph(&self) -> IgraphResult<bool>

Check whether this graph is a chain graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,2), (0,3), (1,3)], false, None).unwrap();
assert!(g.is_chain_graph().unwrap());
Source

pub fn is_chordal_bipartite(&self) -> IgraphResult<bool>

Check whether this graph is chordal bipartite.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,2), (1,2)], false, None).unwrap();
assert!(g.is_chordal_bipartite().unwrap());
Source

pub fn is_claw_free(&self) -> IgraphResult<bool>

Check whether this graph is claw-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_claw_free().unwrap());
Source

pub fn is_cluster_graph(&self) -> IgraphResult<bool>

Check whether this graph is a cluster graph (disjoint union of cliques).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1)], false, None).unwrap();
assert!(g.is_cluster_graph().unwrap());
Source

pub fn is_co_bipartite(&self) -> IgraphResult<bool>

Check whether this graph is co-bipartite.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1)], false, None).unwrap();
assert!(g.is_co_bipartite().unwrap());
Source

pub fn is_co_chordal(&self) -> IgraphResult<bool>

Check whether this graph is co-chordal.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_co_chordal().unwrap());
Source

pub fn is_complete(&self) -> IgraphResult<bool>

Check whether this graph is a complete graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_complete().unwrap());
Source

pub fn is_complete_bipartite(&self) -> IgraphResult<bool>

Check whether this graph is a complete bipartite graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,2), (0,3), (1,2), (1,3)], false, None).unwrap();
assert!(g.is_complete_bipartite().unwrap());
Source

pub fn is_cricket_free(&self) -> IgraphResult<bool>

Check whether this graph is cricket-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_cricket_free().unwrap());
Source

pub fn is_cubic(&self) -> IgraphResult<bool>

Check whether this graph is cubic (3-regular).

§Examples
use rust_igraph::{Graph, full_graph};

let g = full_graph(4, false, false).unwrap();
assert!(g.is_cubic().unwrap());
Source

pub fn is_cycle(&self) -> IgraphResult<bool>

Check whether this graph is a cycle.

§Examples
use rust_igraph::{Graph, cycle_graph};

let g = cycle_graph(5, false, false).unwrap();
assert!(g.is_cycle().unwrap());
Source

pub fn is_dart_free(&self) -> IgraphResult<bool>

Check whether this graph is dart-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_dart_free().unwrap());
Source

pub fn is_diamond_free(&self) -> IgraphResult<bool>

Check whether this graph is diamond-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_diamond_free().unwrap());
Source

pub fn is_distance_hereditary(&self) -> IgraphResult<bool>

Check whether this graph is distance-hereditary.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_distance_hereditary().unwrap());
Source

pub fn is_eulerian(&self) -> IgraphResult<EulerianClassification>

Check whether this graph is Eulerian.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let class = g.is_eulerian().unwrap();
assert!(class.has_cycle);
Source

pub fn is_fork_free(&self) -> IgraphResult<bool>

Check whether this graph is fork-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_fork_free().unwrap());
Source

pub fn is_gem_free(&self) -> IgraphResult<bool>

Check whether this graph is gem-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_gem_free().unwrap());
Source

pub fn is_geodetic(&self) -> IgraphResult<bool>

Check whether this graph is geodetic.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_geodetic().unwrap());
Source

pub fn is_house_free(&self) -> IgraphResult<bool>

Check whether this graph is house-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_house_free().unwrap());
Source

pub fn is_k_degenerate(&self, k: u32) -> IgraphResult<bool>

Check whether this graph is k-degenerate.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_k_degenerate(1).unwrap());
Source

pub fn is_lobster(&self) -> IgraphResult<bool>

Check whether this graph is a lobster.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
assert!(g.is_lobster().unwrap());
Source

pub fn is_net_free(&self) -> IgraphResult<bool>

Check whether this graph is net-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_net_free().unwrap());
Source

pub fn is_p5_free(&self) -> IgraphResult<bool>

Check whether this graph is P5-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_p5_free().unwrap());
Source

pub fn is_path(&self) -> IgraphResult<bool>

Check whether this graph is a path.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
assert!(g.is_path().unwrap());
Source

pub fn is_paw_free(&self) -> IgraphResult<bool>

Check whether this graph is paw-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_paw_free().unwrap());
Source

pub fn is_proper_interval(&self) -> IgraphResult<bool>

Check whether this graph is a proper interval graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_proper_interval().unwrap());
Source

pub fn is_pseudo_forest(&self) -> IgraphResult<bool>

Check whether this graph is a pseudo-forest.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_pseudo_forest().unwrap());
Source

pub fn is_ptolemaic(&self) -> IgraphResult<bool>

Check whether this graph is Ptolemaic.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
assert!(g.is_ptolemaic().unwrap());
Source

pub fn is_self_complementary(&self) -> IgraphResult<bool>

Check whether this graph is self-complementary.

§Examples
use rust_igraph::Graph;

// P_4 (path on 4 vertices) is self-complementary
let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
assert!(g.is_self_complementary().unwrap());
Source

pub fn is_semicomplete(&self) -> IgraphResult<bool>

Check whether this graph is semicomplete.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], true, None).unwrap();
assert!(g.is_semicomplete().unwrap());
Source

pub fn is_spider(&self) -> IgraphResult<bool>

Check whether this graph is a spider.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (0,3)], false, None).unwrap();
assert!(g.is_spider().unwrap());
Source

pub fn is_split_graph(&self) -> IgraphResult<bool>

Check whether this graph is a split graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,2), (2,3)], false, None).unwrap();
assert!(g.is_split_graph().unwrap());
Source

pub fn is_star(&self) -> IgraphResult<bool>

Check whether this graph is a star.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (0,3)], false, None).unwrap();
assert!(g.is_star().unwrap());
Source

pub fn is_strongly_chordal(&self) -> IgraphResult<bool>

Check whether this graph is strongly chordal.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_strongly_chordal().unwrap());
Source

pub fn is_threshold_graph(&self) -> IgraphResult<bool>

Check whether this graph is a threshold graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,2)], false, None).unwrap();
assert!(g.is_threshold_graph().unwrap());
Source

pub fn is_tournament(&self) -> IgraphResult<bool>

Check whether this graph is a tournament.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], true, None).unwrap();
assert!(g.is_tournament().unwrap());
Source

pub fn is_triangle_free(&self) -> IgraphResult<bool>

Check whether this graph is triangle-free.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
assert!(g.is_triangle_free().unwrap());
Source

pub fn is_trivially_perfect(&self) -> IgraphResult<bool>

Check whether this graph is trivially perfect.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,2)], false, None).unwrap();
assert!(g.is_trivially_perfect().unwrap());
Source

pub fn is_unicyclic(&self) -> IgraphResult<bool>

Check whether this graph is unicyclic.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert!(g.is_unicyclic().unwrap());
Source

pub fn is_wheel(&self) -> IgraphResult<bool>

Check whether this graph is a wheel.

§Examples
use rust_igraph::Graph;

// W_4: center 0 connected to rim {1,2,3}, rim forms a cycle
let g = Graph::from_edges(
    &[(0,1), (0,2), (0,3), (1,2), (2,3), (3,1)],
    false, None
).unwrap();
assert!(g.is_wheel().unwrap());
Source

pub fn is_regular(&self) -> IgraphResult<bool>

Check whether the graph is regular (all vertices have the same degree).

§Examples
use rust_igraph::{Graph, full_graph};

let g = full_graph(4, false, false).unwrap();
assert!(g.is_regular().unwrap());
Source

pub fn is_strongly_regular(&self) -> IgraphResult<Option<StronglyRegularParams>>

Check whether the graph is strongly regular, returning parameters if so.

§Examples
use rust_igraph::{Graph, cycle_graph};

let g = cycle_graph(5, false, false).unwrap();
let result = g.is_strongly_regular().unwrap();
assert!(result.is_some());
Source

pub fn is_weakly_chordal(&self) -> IgraphResult<bool>

Check whether the graph is weakly chordal.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
assert!(g.is_weakly_chordal().unwrap());
Source

pub fn is_well_covered(&self) -> IgraphResult<bool>

Check whether the graph is well-covered.

§Examples
use rust_igraph::{Graph, full_graph};

let g = full_graph(4, false, false).unwrap();
assert!(g.is_well_covered().unwrap());
Source

pub fn is_windmill(&self) -> IgraphResult<Option<(u32, u32)>>

Check whether the graph is a windmill graph, returning (k, n) if so.

§Examples
use rust_igraph::{Graph, full_graph};

let g = full_graph(3, false, false).unwrap();
let result = g.is_windmill().unwrap();
assert!(result.is_some());
Source

pub fn is_complete_multipartite(&self) -> IgraphResult<Option<Vec<u32>>>

Check whether the graph is complete multipartite, returning partition sizes if so.

§Examples
use rust_igraph::{Graph, full_graph};

let g = full_graph(3, false, false).unwrap();
let result = g.is_complete_multipartite().unwrap();
assert!(result.is_some());
Source

pub fn satisfies_dirac(&self) -> IgraphResult<bool>

Check whether this graph satisfies Dirac’s condition for Hamiltonicity.

§Examples
use rust_igraph::{Graph, full_graph};

let g = full_graph(5, false, false).unwrap();
assert!(g.satisfies_dirac().unwrap());
Source

pub fn satisfies_ore(&self) -> IgraphResult<bool>

Check whether this graph satisfies Ore’s condition for Hamiltonicity.

§Examples
use rust_igraph::{Graph, full_graph};

let g = full_graph(5, false, false).unwrap();
assert!(g.satisfies_ore().unwrap());
Source

pub fn edge_betweenness(&self) -> IgraphResult<Vec<f64>>

Compute edge betweenness centrality.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let eb = g.edge_betweenness().unwrap();
assert_eq!(eb.len(), 3);
Source

pub fn betweenness_cutoff(&self, cutoff: u32) -> IgraphResult<Vec<f64>>

Compute betweenness centrality with a distance cutoff.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let bc = g.betweenness_cutoff(2).unwrap();
assert_eq!(bc.len(), 4);
Source

pub fn betweenness_weighted(&self, weights: &[f64]) -> IgraphResult<Vec<f64>>

Compute weighted betweenness centrality.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let bc = g.betweenness_weighted(&[1.0, 2.0]).unwrap();
assert_eq!(bc.len(), 3);
Source

pub fn closeness_weighted( &self, weights: &[f64], ) -> IgraphResult<Vec<Option<f64>>>

Compute weighted closeness centrality.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let cc = g.closeness_weighted(&[1.0, 2.0]).unwrap();
assert_eq!(cc.len(), 3);
Source

pub fn edge_betweenness_cutoff(&self, cutoff: u32) -> IgraphResult<Vec<f64>>

Compute edge betweenness centrality with a distance cutoff.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let eb = g.edge_betweenness_cutoff(2).unwrap();
assert_eq!(eb.len(), 3);
Source

pub fn edge_betweenness_weighted( &self, weights: &[f64], ) -> IgraphResult<Vec<f64>>

Compute weighted edge betweenness centrality.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let eb = g.edge_betweenness_weighted(&[1.0, 2.0]).unwrap();
assert_eq!(eb.len(), 2);
Source

pub fn harmonic_centrality_weighted( &self, weights: &[f64], ) -> IgraphResult<Vec<f64>>

Compute weighted harmonic centrality.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let hc = g.harmonic_centrality_weighted(&[1.0, 2.0]).unwrap();
assert_eq!(hc.len(), 3);
Source

pub fn pagerank_weighted(&self, weights: &[f64]) -> IgraphResult<Vec<f64>>

Compute weighted PageRank.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let pr = g.pagerank_weighted(&[1.0, 2.0]).unwrap();
assert_eq!(pr.len(), 3);
Source

pub fn cohesive_blocks(&self) -> IgraphResult<CohesiveBlocks>

Compute the cohesive block structure.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (2,3), (3,4), (4,5), (5,3)],
    false, None
).unwrap();
let blocks = g.cohesive_blocks().unwrap();
assert!(!blocks.blocks.is_empty());
Source

pub fn count_reachable(&self) -> IgraphResult<Vec<u32>>

Count reachable vertices from each vertex.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let counts = g.count_reachable().unwrap();
assert_eq!(counts, vec![3, 3, 3]);
Source

pub fn reachability_matrix(&self) -> IgraphResult<Vec<Vec<bool>>>

Compute the reachability matrix.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], true, None).unwrap();
let mat = g.reachability_matrix().unwrap();
assert!(mat[0][2]);
assert!(!mat[2][0]);
Source

pub fn transitive_closure(&self) -> IgraphResult<Graph>

Compute the transitive closure.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], true, None).unwrap();
let tc = g.transitive_closure().unwrap();
assert!(tc.has_edge(0, 2));
Source

pub fn mincut(&self, capacity: Option<&[f64]>) -> IgraphResult<Mincut>

Compute the global minimum cut.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,3), (2,3)], false, None
).unwrap();
let mc = g.mincut(None).unwrap();
assert!(mc.value >= 2.0 - 1e-10);
Source

pub fn mincut_value(&self, capacity: Option<&[f64]>) -> IgraphResult<f64>

Compute the global minimum cut value.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,3), (2,3)], false, None
).unwrap();
let val = g.mincut_value(None).unwrap();
assert!(val >= 2.0 - 1e-10);
Source

pub fn gomory_hu_tree( &self, capacity: Option<&[f64]>, ) -> IgraphResult<GomoryHuTree>

Compute the Gomory-Hu tree.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,2), (1,3)], false, None
).unwrap();
let tree = g.gomory_hu_tree(None).unwrap();
assert_eq!(tree.tree.vcount(), 4);
Source

pub fn all_st_cuts( &self, source: VertexId, target: VertexId, ) -> IgraphResult<StCuts>

Enumerate all minimum s-t cuts.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,3), (2,3)], true, None
).unwrap();
let cuts = g.all_st_cuts(0, 3).unwrap();
assert!(!cuts.cuts.is_empty());
Source

pub fn edge_disjoint_paths( &self, source: VertexId, target: VertexId, ) -> IgraphResult<i64>

Count edge-disjoint paths between two vertices.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (0,2), (1,3), (2,3)], false, None
).unwrap();
let count = g.edge_disjoint_paths(0, 3).unwrap();
assert_eq!(count, 2);
Source

pub fn distances(&self, source: VertexId) -> IgraphResult<Vec<Option<u32>>>

Compute BFS distances from a source vertex.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let dist = g.distances(0).unwrap();
assert_eq!(dist[3], Some(3));
Source

pub fn eulerian_path(&self) -> IgraphResult<Option<Vec<u32>>>

Compute an Eulerian path if one exists.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let path = g.eulerian_path().unwrap();
assert!(path.is_some());
Source

pub fn mean_distance(&self) -> IgraphResult<Option<f64>>

Compute mean geodesic distance.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let d = g.mean_distance().unwrap();
assert!(d.is_some());
Source

pub fn topological_sorting(&self) -> IgraphResult<Vec<VertexId>>

Topological sort of a directed graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], true, None).unwrap();
let order = g.topological_sorting().unwrap();
assert_eq!(order, vec![0, 1, 2]);
Source

pub fn list_triangles(&self) -> IgraphResult<Vec<(u32, u32, u32)>>

List all triangles in the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let tris = g.list_triangles().unwrap();
assert_eq!(tris.len(), 1);
Source

pub fn degree_distribution(&self) -> IgraphResult<Vec<u32>>

Compute the degree distribution.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let dist = g.degree_distribution().unwrap();
assert!(!dist.is_empty());
Source

pub fn get_edgelist(&self) -> IgraphResult<Vec<(VertexId, VertexId)>>

Get the edge list as (source, target) pairs.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let edges = g.get_edgelist().unwrap();
assert_eq!(edges.len(), 2);
Source

pub fn regularity(&self) -> IgraphResult<Option<u32>>

Compute the graph’s regularity (degree if regular, None otherwise).

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
assert_eq!(g.regularity().unwrap(), Some(2));
Source

pub fn find_cycle(&self) -> IgraphResult<CycleResult>

Find a cycle in the graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let result = g.find_cycle().unwrap();
assert!(!result.vertices.is_empty());
Source

pub fn joint_degree_matrix( &self, weights: Option<&[f64]>, ) -> IgraphResult<Vec<Vec<f64>>>

Compute the joint degree matrix.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let jdm = g.joint_degree_matrix(None).unwrap();
assert!(!jdm.is_empty());
Source

pub fn minimum_dominating_set(&self) -> IgraphResult<Vec<VertexId>>

Compute the minimum dominating set.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let dom = g.minimum_dominating_set().unwrap();
assert!(!dom.is_empty());
Source

pub fn graph_power(&self, order: u32) -> IgraphResult<Graph>

Compute the k-th power of this graph.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let g2 = g.graph_power(2).unwrap();
assert!(g2.has_edge(0, 2));
Source

pub fn trussness(&self) -> IgraphResult<Vec<u32>>

Compute the trussness of each edge.

§Examples
use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (2,3)], false, None
).unwrap();
let tr = g.trussness().unwrap();
assert_eq!(tr.len(), g.ecount());
Source

pub fn union(&self, other: &Graph) -> IgraphResult<Graph>

Union of two graphs on the same vertex set.

use rust_igraph::Graph;

let a = Graph::from_edges(&[(0,1)], false, None).unwrap();
let b = Graph::from_edges(&[(1,2)], false, None).unwrap();
let u = a.union(&b).unwrap();
assert_eq!(u.ecount(), 2);
Source

pub fn intersection(&self, other: &Graph) -> IgraphResult<Graph>

Intersection of two graphs on the same vertex set.

use rust_igraph::Graph;

let a = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let b = Graph::from_edges(&[(1,2), (2,3)], false, None).unwrap();
let i = a.intersection(&b).unwrap();
assert_eq!(i.ecount(), 1);
Source

pub fn difference(&self, other: &Graph) -> IgraphResult<Graph>

Edge difference: edges in self but not in other.

use rust_igraph::Graph;

let a = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let b = Graph::from_edges(&[(1,2)], false, None).unwrap();
let d = a.difference(&b).unwrap();
assert_eq!(d.ecount(), 1);
Source

pub fn disjoint_union(&self, other: &Graph) -> IgraphResult<Graph>

Disjoint union: concatenate vertex sets, then concatenate edge sets.

use rust_igraph::Graph;

let a = Graph::from_edges(&[(0,1)], false, None).unwrap();
let b = Graph::from_edges(&[(0,1)], false, None).unwrap();
let d = a.disjoint_union(&b).unwrap();
assert_eq!(d.vcount(), 4);
assert_eq!(d.ecount(), 2);
Source

pub fn join(&self, other: &Graph) -> IgraphResult<Graph>

Join: disjoint union plus all edges between the two vertex sets.

use rust_igraph::Graph;

let a = Graph::with_vertices(2);
let b = Graph::with_vertices(2);
let j = a.join(&b).unwrap();
assert_eq!(j.vcount(), 4);
assert_eq!(j.ecount(), 4);
Source

pub fn compose(&self, other: &Graph) -> IgraphResult<Graph>

Compose two graphs (relational composition).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], true, None).unwrap();
let c = g.compose(&g).unwrap();
assert!(c.ecount() > 0);
Source

pub fn cartesian_product(&self, other: &Graph) -> IgraphResult<Graph>

Cartesian product of two graphs.

use rust_igraph::Graph;

let p2 = Graph::from_edges(&[(0,1)], false, None).unwrap();
let grid = p2.cartesian_product(&p2).unwrap();
assert_eq!(grid.vcount(), 4);
Source

pub fn tensor_product(&self, other: &Graph) -> IgraphResult<Graph>

Tensor (categorical/direct) product of two graphs.

use rust_igraph::Graph;

let p2 = Graph::from_edges(&[(0,1)], false, None).unwrap();
let t = p2.tensor_product(&p2).unwrap();
assert_eq!(t.vcount(), 4);
Source

pub fn strong_product(&self, other: &Graph) -> IgraphResult<Graph>

Strong product of two graphs.

use rust_igraph::Graph;

let p2 = Graph::from_edges(&[(0,1)], false, None).unwrap();
let s = p2.strong_product(&p2).unwrap();
assert_eq!(s.vcount(), 4);
Source

pub fn lexicographic_product(&self, other: &Graph) -> IgraphResult<Graph>

Lexicographic product of two graphs.

use rust_igraph::Graph;

let a = Graph::from_edges(&[(0,1)], false, None).unwrap();
let b = Graph::with_vertices(2);
let l = a.lexicographic_product(&b).unwrap();
assert_eq!(l.vcount(), 4);
Source

pub fn connect_neighborhood(&self, order: u32) -> IgraphResult<Graph>

Connect each vertex to all vertices within distance order.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let c = g.connect_neighborhood(2).unwrap();
assert!(c.ecount() > g.ecount());
Source

pub fn rewire( &self, num_trials: usize, loops: bool, seed: u64, ) -> IgraphResult<Graph>

Rewire edges while preserving the degree sequence.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3), (3,0)], false, None).unwrap();
let r = g.rewire(100, false, 42).unwrap();
assert_eq!(r.ecount(), g.ecount());
Source

pub fn rewire_edges( &self, prob: f64, loops: bool, seed: u64, ) -> IgraphResult<Graph>

Randomly rewire each edge with probability prob.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let r = g.rewire_edges(0.5, false, 42).unwrap();
assert_eq!(r.vcount(), g.vcount());
Source

pub fn subgraph_from_edges( &self, eids: &[u32], ) -> IgraphResult<SubgraphFromEdgesResult>

Extract a subgraph induced by the given edge ids.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let s = g.subgraph_from_edges(&[0, 1]).unwrap();
assert_eq!(s.graph.ecount(), 2);
Source

pub fn even_tarjan_reduction(&self) -> IgraphResult<EvenTarjanResult>

The Even-Tarjan reduction of a directed graph.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], true, None).unwrap();
let et = g.even_tarjan_reduction().unwrap();
assert!(et.graph.vcount() > g.vcount());
Source

pub fn bipartite_projection( &self, types: &[bool], project_type: bool, ) -> IgraphResult<BipartiteProjection>

Bipartite projection onto one vertex type.

project_type selects which side: false projects the false-typed vertices, true projects the true-typed vertices.

use rust_igraph::Graph;

let mut g = Graph::new(4, false).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(1, 3).unwrap();
let types = vec![false, false, true, true];
let p = g.bipartite_projection(&types, false).unwrap();
assert_eq!(p.graph.vcount(), 2);
Source

pub fn bellman_ford_distances( &self, source: VertexId, weights: &[f64], ) -> IgraphResult<Vec<Option<f64>>>

Bellman-Ford shortest-path distances from a single source.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,3)], false, None).unwrap();
let w = vec![1.0; g.ecount()];
let d = g.bellman_ford_distances(0, &w).unwrap();
assert!((d[3].unwrap() - 3.0).abs() < 1e-9);
Source

pub fn floyd_warshall_distances( &self, weights: Option<&[f64]>, ) -> IgraphResult<Vec<Vec<Option<f64>>>>

Floyd-Warshall all-pairs shortest-path distances.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let d = g.floyd_warshall_distances(None).unwrap();
assert!((d[0][2].unwrap() - 2.0).abs() < 1e-9);
Source

pub fn k_shortest_paths( &self, source: VertexId, target: VertexId, weights: &[f64], k: usize, ) -> IgraphResult<Vec<KShortestPath>>

Find the k shortest paths between two vertices.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,3), (0,2), (2,3)], false, None,
).unwrap();
let w = vec![1.0; g.ecount()];
let paths = g.k_shortest_paths(0, 3, &w, 2).unwrap();
assert_eq!(paths.len(), 2);
Source

pub fn all_simple_paths( &self, from: u32, to: Option<&[u32]>, min_length: i32, max_length: i32, ) -> IgraphResult<Vec<Vec<u32>>>

Enumerate all simple paths from a source vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (0,2)], false, None).unwrap();
let paths = g.all_simple_paths(0, Some(&[2]), 1, 10).unwrap();
assert!(paths.len() >= 2);
Source

pub fn maximum_bipartite_matching( &self, types: &[bool], ) -> IgraphResult<MatchingResult>

Maximum bipartite matching.

use rust_igraph::Graph;

let mut g = Graph::new(4, false).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(1, 2).unwrap();
let types = vec![false, false, true, true];
let m = g.maximum_bipartite_matching(&types).unwrap();
assert_eq!(m.matching_size, 2);
Source

pub fn vertex_coloring_greedy( &self, heuristic: GreedyColoringHeuristic, ) -> IgraphResult<Vec<u32>>

Greedy vertex coloring.

use rust_igraph::{Graph, GreedyColoringHeuristic};

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let colors = g.vertex_coloring_greedy(GreedyColoringHeuristic::ColoredNeighbors).unwrap();
assert_eq!(colors.len(), 3);
Source

pub fn simple_cycles( &self, mode: SimpleCycleMode, min_length: u32, max_length: Option<u32>, ) -> IgraphResult<Vec<SimpleCycle>>

Enumerate all simple cycles.

use rust_igraph::{Graph, SimpleCycleMode};

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let cycles = g.simple_cycles(SimpleCycleMode::All, 3, None).unwrap();
assert!(!cycles.is_empty());
Source

pub fn leading_eigenvector( &self, weights: Option<&[f64]>, steps: Option<u32>, ) -> IgraphResult<LeadingEigenvectorResult>

Leading eigenvector community detection.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (3,4), (4,5), (5,3), (2,3)],
    false, None,
).unwrap();
let result = g.leading_eigenvector(None, None).unwrap();
assert!(result.membership.len() == g.vcount() as usize);
Source

pub fn fluid_communities(&self, k: u32) -> IgraphResult<FluidResult>

Fluid community detection.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,0), (3,4), (4,5), (5,3), (2,3)],
    false, None,
).unwrap();
let r = g.fluid_communities(2).unwrap();
assert_eq!(r.membership.len(), g.vcount() as usize);
Source

pub fn motifs_randesu(&self, size: u32) -> IgraphResult<Vec<f64>>

Motif census (subgraph isomorphism classes of a given size).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], true, None).unwrap();
let hist = g.motifs_randesu(3).unwrap();
assert!(!hist.is_empty());
Source

pub fn personalized_pagerank(&self, reset: &[f64]) -> IgraphResult<Vec<f64>>

Personalized PageRank with a custom reset distribution.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let reset = vec![1.0, 0.0, 0.0];
let pr = g.personalized_pagerank(&reset).unwrap();
assert_eq!(pr.len(), 3);
Source

pub fn isomorphic_vf2(&self, other: &Graph) -> IgraphResult<Vf2Isomorphism>

Test whether two graphs are isomorphic (VF2).

use rust_igraph::Graph;

let a = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let b = Graph::from_edges(&[(0,2), (2,1), (1,0)], false, None).unwrap();
let result = a.isomorphic_vf2(&b).unwrap();
assert!(result.iso);
Source

pub fn isomorphic(&self, other: &Graph) -> IgraphResult<bool>

Quick isomorphism test (delegates to the best available method).

use rust_igraph::Graph;

let a = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let b = Graph::from_edges(&[(0,2), (2,1), (1,0)], false, None).unwrap();
assert!(a.isomorphic(&b).unwrap());
Source

pub fn count_isomorphisms_vf2(&self, other: &Graph) -> IgraphResult<u64>

Count the number of isomorphisms between two graphs (VF2).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let count = g.count_isomorphisms_vf2(&g).unwrap();
assert_eq!(count, 6); // C3 has 6 automorphisms
Source

pub fn independent_vertex_sets( &self, min_size: u32, max_size: u32, ) -> IgraphResult<Vec<Vec<u32>>>

Find all maximal independent vertex sets.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let sets = g.independent_vertex_sets(1, 3).unwrap();
assert!(!sets.is_empty());
Source

pub fn global_efficiency(&self) -> IgraphResult<Option<f64>>

Global efficiency of the graph.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let e = g.global_efficiency().unwrap();
assert!(e.unwrap_or(0.0) > 0.0);
Source

pub fn local_efficiency(&self) -> IgraphResult<Vec<f64>>

Local efficiency for each vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (1,2), (2,0)], false, None).unwrap();
let e = g.local_efficiency().unwrap();
assert_eq!(e.len(), 3);
Source

pub fn assortativity_degree(&self) -> IgraphResult<Option<f64>>

Degree assortativity coefficient.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1), (1,2), (2,3), (3,4)], false, None,
).unwrap();
let r = g.assortativity_degree().unwrap();
assert!(r.is_some());
Source

pub fn diversity(&self, weights: &[f64]) -> IgraphResult<Vec<f64>>

Diversity (entropy) of vertex edge weights.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1), (0,2), (1,2)], false, None).unwrap();
let w = vec![1.0, 2.0, 3.0];
let d = g.diversity(&w).unwrap();
assert_eq!(d.len(), 3);
Source

pub fn distances_all(&self) -> IgraphResult<Vec<Option<u32>>>

All-pairs shortest-path distances (unweighted BFS).

Returns a flat n*n vector in row-major order where result[i*n + j] is the distance from vertex i to j, or None if unreachable.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let d = g.distances_all().unwrap();
assert_eq!(d[0 * 3 + 2], Some(2)); // path 0→1→2
Source

pub fn distances_from( &self, sources: &[VertexId], ) -> IgraphResult<Vec<Option<u32>>>

Shortest-path distances from a set of source vertices.

Returns a flat sources.len() * n vector in row-major order.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let d = g.distances_from(&[0]).unwrap();
assert_eq!(d[3], Some(3)); // vertex 3 is 3 hops from vertex 0
Source

pub fn get_shortest_paths( &self, source: VertexId, ) -> IgraphResult<Vec<Vec<VertexId>>>

Shortest-path trees from a source vertex (one path per target).

Returns a vector of vertex sequences, one per target vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let paths = g.get_shortest_paths(0).unwrap();
assert_eq!(paths[2], vec![0, 1, 2]);
Source

pub fn get_all_shortest_paths( &self, source: VertexId, ) -> IgraphResult<AllShortestPaths>

All shortest paths from a source vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,2),(1,3),(2,3)], false, None).unwrap();
let asp = g.get_all_shortest_paths(0).unwrap();
// Two shortest paths from 0 to 3: 0-1-3 and 0-2-3
assert_eq!(asp.paths[3].len(), 2);
Source

pub fn johnson_distances( &self, weights: &[f64], ) -> IgraphResult<Vec<Vec<Option<f64>>>>

Johnson’s algorithm for all-pairs shortest paths with edge weights.

Handles negative weights (but not negative cycles).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let d = g.johnson_distances(&[1.0, 2.0]).unwrap();
assert!((d[0][2].unwrap() - 3.0).abs() < 1e-10);
Source

pub fn widest_paths( &self, from: VertexId, weights: &[f64], ) -> IgraphResult<WidestPaths>

Widest (bottleneck) paths from a source vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let wp = g.widest_paths(0, &[10.0, 5.0]).unwrap();
assert!((wp.widths[2].unwrap() - 5.0).abs() < 1e-10);
Source

pub fn graph_center(&self) -> IgraphResult<Vec<VertexId>>

Graph center — vertices with minimum eccentricity.

use rust_igraph::{Graph, cycle_graph};

let g = cycle_graph(5, false, false).unwrap();
let center = g.graph_center().unwrap();
assert_eq!(center.len(), 5); // all vertices equidistant in a cycle
Source

pub fn path_length_hist( &self, directed: bool, ) -> IgraphResult<PathLengthHistResult>

Path-length histogram of the graph.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let h = g.path_length_hist(false).unwrap();
assert!(!h.hist.is_empty());
Source

pub fn eulerian_cycle(&self) -> IgraphResult<Vec<u32>>

Find an Eulerian cycle (every edge visited exactly once, returning to start).

use rust_igraph::cycle_graph;

let g = cycle_graph(5, false, false).unwrap();
let cycle = g.eulerian_cycle().unwrap();
assert_eq!(cycle.len(), 5); // 5 edges in C5
Source

pub fn hub_and_authority_scores(&self) -> IgraphResult<HitsScores>

HITS hub and authority scores.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], true, None).unwrap();
let hits = g.hub_and_authority_scores().unwrap();
assert_eq!(hits.hub.len(), 3);
Source

pub fn strength(&self, weights: &[f64]) -> IgraphResult<Vec<f64>>

Weighted vertex degree (strength).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,2),(1,2)], false, None).unwrap();
let s = g.strength(&[1.0, 2.0, 3.0]).unwrap();
assert!((s[0] - 3.0).abs() < 1e-10); // edges 0-1 (w=1) + 0-2 (w=2)
Source

pub fn knnk(&self) -> IgraphResult<Vec<Option<f64>>>

Average nearest-neighbor degree by degree class (knn(k)).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let k = g.knnk().unwrap();
assert!(k.len() > 0);
Source

pub fn transitivity_barrat( &self, weights: &[f64], ) -> IgraphResult<Vec<Option<f64>>>

Barrat’s weighted clustering coefficient per vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let t = g.transitivity_barrat(&[1.0, 1.0, 1.0]).unwrap();
assert!(t[0].unwrap() > 0.0);
Source

pub fn local_scan_1(&self, weights: Option<&[f64]>) -> IgraphResult<Vec<f64>>

Local scan statistic (order 1) — triangle counts per vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let s = g.local_scan_1(None).unwrap();
assert_eq!(s.len(), 3);

Maximum cardinality search ordering.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let mcs = g.maximum_cardinality_search().unwrap();
assert_eq!(mcs.alpha.len(), 3);
Source

pub fn max_degree_vertex(&self) -> IgraphResult<Option<VertexId>>

Vertex with the highest degree.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,2),(0,3),(1,2)], false, None).unwrap();
let v = g.max_degree_vertex().unwrap();
assert_eq!(v, Some(0)); // vertex 0 has degree 3
Source

pub fn has_loop(&self) -> IgraphResult<bool>

Whether the graph has at least one self-loop.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,1)], false, None).unwrap();
assert!(g.has_loop().unwrap());
Source

pub fn has_mutual(&self, loops: bool) -> IgraphResult<bool>

Whether the graph has at least one pair of mutual (reciprocal) edges.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,0)], true, None).unwrap();
assert!(g.has_mutual(true).unwrap());
Source

pub fn is_multiple(&self) -> IgraphResult<Vec<bool>>

Per-edge test: is each edge a multi-edge?

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,1),(1,2)], false, None).unwrap();
let m = g.is_multiple().unwrap();
assert!(m.iter().any(|&x| x)); // at least one multi-edge
Source

pub fn is_mutual(&self, loops: bool) -> IgraphResult<Vec<bool>>

Per-edge test: is each edge mutual (has a reciprocal)?

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,0),(0,2)], true, None).unwrap();
let m = g.is_mutual(true).unwrap();
assert!(m[0]); // edge 0→1 has reciprocal 1→0
Source

pub fn modularity( &self, membership: &[u32], resolution: f64, ) -> IgraphResult<Option<f64>>

Modularity of a given community assignment.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1),(1,2),(2,0),(3,4),(4,5),(5,3),(0,3)],
    false, None,
).unwrap();
let q = g.modularity(&[0,0,0,1,1,1], 1.0).unwrap();
assert!(q.unwrap() > 0.0);
Source

pub fn mycielskian(&self, k: u32) -> IgraphResult<Graph>

Mycielskian — triangle-free graph with increasing chromatic number.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1)], false, None).unwrap();
let m = g.mycielskian(1).unwrap();
assert!(m.vcount() > g.vcount());
Source

pub fn to_prufer(&self) -> IgraphResult<Vec<u32>>

Prüfer sequence of a labeled tree.

use rust_igraph::Graph;

// Path graph 0-1-2-3 is a tree
let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let seq = g.to_prufer().unwrap();
assert_eq!(seq.len(), 2); // n-2 elements for n=4
Source

pub fn bond_percolation( &self, edge_order: &[u32], ) -> IgraphResult<EdgelistPercolation>

Bond (edge) percolation — add edges one by one and track components.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let p = g.bond_percolation(&[0, 1, 2]).unwrap();
assert_eq!(p.giant_size.len(), 3); // one snapshot per step
Source

pub fn site_percolation( &self, vertex_order: &[VertexId], ) -> IgraphResult<SitePercolation>

Site (vertex) percolation — add vertices one by one and track components.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let p = g.site_percolation(&[0, 1, 2, 3]).unwrap();
assert_eq!(p.giant_size.len(), 4);
Source

pub fn reachability( &self, mode: ReachabilityMode, ) -> IgraphResult<ReachabilityResult>

Reachability matrix (transitive closure as a boolean matrix).

use rust_igraph::{Graph, ReachabilityMode};

let g = Graph::from_edges(&[(0,1),(1,2)], true, None).unwrap();
let r = g.reachability(ReachabilityMode::Out).unwrap();
assert!(r.is_reachable(0, 2)); // 0 can reach 2 transitively
Source

pub fn neighborhood_graphs(&self, order: i32) -> IgraphResult<Vec<Graph>>

Induced subgraphs of k-hop neighborhoods around each vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let nbrs = g.neighborhood_graphs(1).unwrap();
assert_eq!(nbrs.len(), 4); // one subgraph per vertex
Source

pub fn weighted_clique_number( &self, vertex_weights: &[f64], ) -> IgraphResult<f64>

Weighted clique number — maximum total weight of any clique.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let wc = g.weighted_clique_number(&[1.0, 2.0, 3.0]).unwrap();
assert!((wc - 6.0).abs() < 1e-10); // triangle, all 3 vertices
Source

pub fn isoclass(&self) -> IgraphResult<u32>

Isomorphism class of a small graph (up to 6 vertices).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let cls = g.isoclass().unwrap();
assert!(cls > 0);
Source

pub fn layout_mds( &self, dist: Option<&[Vec<f64>]>, ) -> IgraphResult<Vec<[f64; 2]>>

Multidimensional scaling layout.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let pos = g.layout_mds(None).unwrap();
assert_eq!(pos.len(), 4);
Source

pub fn layout_sphere(&self) -> Vec<(f64, f64, f64)>

Spherical layout (3D positions on a unit sphere).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let pos = g.layout_sphere();
assert_eq!(pos.len(), 3);
Source

pub fn louvain_weighted(&self, weights: &[f64]) -> IgraphResult<LouvainResult>

Louvain community detection with edge weights.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1),(1,2),(2,0),(3,4),(4,5),(5,3),(0,3)],
    false, None,
).unwrap();
let r = g.louvain_weighted(&[1.0; 7]).unwrap();
assert!(r.modularity > 0.0);
Source

pub fn leiden_weighted(&self, weights: &[f64]) -> IgraphResult<LeidenResult>

Leiden community detection with edge weights.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1),(1,2),(2,0),(3,4),(4,5),(5,3),(0,3)],
    false, None,
).unwrap();
let r = g.leiden_weighted(&[1.0; 7]).unwrap();
assert!(r.quality > 0.0);
Source

pub fn label_propagation_weighted( &self, weights: &[f64], ) -> IgraphResult<LpaResult>

Label propagation with edge weights.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1),(1,2),(2,0),(3,4),(4,5),(5,3),(0,3)],
    false, None,
).unwrap();
let r = g.label_propagation_weighted(&[1.0; 7]).unwrap();
assert_eq!(r.membership.len(), 6);
Source

pub fn walktrap_weighted(&self, weights: &[f64]) -> IgraphResult<WalktrapResult>

Walktrap community detection with edge weights.

use rust_igraph::Graph;

let g = Graph::from_edges(
    &[(0,1),(1,2),(2,0),(3,4),(4,5),(5,3),(0,3)],
    false, None,
).unwrap();
let r = g.walktrap_weighted(&[1.0; 7]).unwrap();
assert!(!r.modularity.is_empty());
Source

pub fn diameter_weighted(&self, weights: &[f64]) -> IgraphResult<Option<f64>>

Weighted diameter (longest shortest-path distance).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let d = g.diameter_weighted(&[1.0, 2.0]).unwrap();
assert!((d.unwrap() - 3.0).abs() < 1e-10);
Source

pub fn eccentricity_weighted(&self, weights: &[f64]) -> IgraphResult<Vec<f64>>

Weighted eccentricity per vertex.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let e = g.eccentricity_weighted(&[1.0, 2.0]).unwrap();
assert_eq!(e.len(), 3);
Source

pub fn radius_weighted(&self, weights: &[f64]) -> IgraphResult<Option<f64>>

Weighted graph radius.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let r = g.radius_weighted(&[1.0, 2.0]).unwrap();
assert!(r.is_some());
Source

pub fn knnk_weighted(&self, weights: &[f64]) -> IgraphResult<Vec<Option<f64>>>

Weighted knn(k) — average nearest-neighbor degree by degree class.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let k = g.knnk_weighted(&[1.0, 1.0, 1.0]).unwrap();
assert!(!k.is_empty());
Source

pub fn pagerank_linsys(&self) -> IgraphResult<Vec<f64>>

PageRank via linear-system solver (alternative to power iteration).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,0)], true, None).unwrap();
let pr = g.pagerank_linsys().unwrap();
assert_eq!(pr.len(), 3);
Source

pub fn local_scan_k( &self, k: u32, weights: Option<&[f64]>, ) -> IgraphResult<Vec<f64>>

Local scan statistic of order k.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let s = g.local_scan_k(1, None).unwrap();
assert_eq!(s.len(), 3);
Source

pub fn is_loop(&self) -> IgraphResult<Vec<bool>>

Per-edge test: is each edge a self-loop?

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,1),(2,3)], false, None).unwrap();
let loops = g.is_loop().unwrap();
assert!(!loops[0]); // 0-1 is not a loop
assert!(loops[1]);  // 1-1 is a loop
Source

pub fn is_clique( &self, vertices: &[VertexId], directed: bool, ) -> IgraphResult<bool>

Whether a set of vertices forms a clique.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
assert!(g.is_clique(&[0, 1, 2], false).unwrap());
Source

pub fn is_independent_vertex_set( &self, vertices: &[VertexId], ) -> IgraphResult<bool>

Whether a set of vertices forms an independent set.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
assert!(g.is_independent_vertex_set(&[0, 2]).unwrap());
Source

pub fn is_separator(&self, candidates: &[VertexId]) -> IgraphResult<bool>

Whether a set of vertices is a separator (its removal disconnects the graph).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
assert!(g.is_separator(&[1]).unwrap());
Source

pub fn is_minimal_separator( &self, candidates: &[VertexId], ) -> IgraphResult<bool>

Whether a separator is minimal.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
assert!(g.is_minimal_separator(&[1]).unwrap());
Source

pub fn is_vertex_coloring(&self, colors: &[u32]) -> IgraphResult<bool>

Whether a coloring is a valid vertex coloring.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
assert!(g.is_vertex_coloring(&[0, 1, 0]).unwrap());
Source

pub fn is_edge_coloring(&self, colors: &[u32]) -> IgraphResult<bool>

Whether a coloring is a valid edge coloring.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
assert!(g.is_edge_coloring(&[0, 1]).unwrap());
Source

pub fn is_vertex_cover(&self, cover: &[VertexId]) -> bool

Whether a set of vertices is a vertex cover.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
assert!(g.is_vertex_cover(&[1]));
Source

pub fn is_edge_cover(&self, cover: &[u32]) -> bool

Whether a set of edges is an edge cover.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
assert!(g.is_edge_cover(&[0, 1]));
Source

pub fn is_dominating_set(&self, dom_set: &[VertexId]) -> bool

Whether a set of vertices is a dominating set.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
assert!(g.is_dominating_set(&[1]));
Source

pub fn reverse_edges(&self, eids: &[u32]) -> IgraphResult<Graph>

Reverse specific edges in a directed graph.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], true, None).unwrap();
let r = g.reverse_edges(&[0]).unwrap();
assert_eq!(r.edge(0).unwrap(), (1, 0));
Source

pub fn induced_subgraph_edges(&self, vids: &[u32]) -> IgraphResult<Vec<u32>>

Edges induced by a subset of vertices.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let eids = g.induced_subgraph_edges(&[0, 1]).unwrap();
assert_eq!(eids.len(), 1); // only edge 0-1
Source

pub fn similarity_dice(&self) -> IgraphResult<Vec<f64>>

Dice similarity between all vertex pairs (n*n flat matrix).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let s = g.similarity_dice().unwrap();
let n = g.vcount() as usize;
assert_eq!(s.len(), n * n);
Source

pub fn similarity_inverse_log_weighted(&self) -> IgraphResult<Vec<f64>>

Inverse-log-weighted similarity between all vertex pairs.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let s = g.similarity_inverse_log_weighted().unwrap();
let n = g.vcount() as usize;
assert_eq!(s.len(), n * n);
Source

pub fn similarity_jaccard_es(&self, eids: &[u32]) -> IgraphResult<Vec<f64>>

Jaccard similarity for given edges.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let s = g.similarity_jaccard_es(&[0, 1]).unwrap();
assert_eq!(s.len(), 2);
Source

pub fn layout_lgl(&self, params: &LglParams) -> IgraphResult<Vec<[f64; 2]>>

Large Graph Layout (LGL).

use rust_igraph::{Graph, LglParams};

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let pos = g.layout_lgl(&LglParams::default()).unwrap();
assert_eq!(pos.len(), 4);
Source

pub fn layout_random_3d(&self, seed: u64) -> Vec<(f64, f64, f64)>

Random 3D layout.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let pos = g.layout_random_3d(42);
assert_eq!(pos.len(), 3);
Source

pub fn layout_grid_3d(&self, width: i32, height: i32) -> Vec<(f64, f64, f64)>

Grid 3D layout.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let pos = g.layout_grid_3d(2, 2);
assert_eq!(pos.len(), 4);
Source

pub fn motifs_randesu_no(&self, size: u32) -> IgraphResult<f64>

Count the total number of motifs of a given size.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, None).unwrap();
let n = g.motifs_randesu_no(3).unwrap();
assert!((n - 1.0).abs() < 1e-10); // one triangle
Source

pub fn graph_summary(&self) -> IgraphResult<GraphSummary>

Structural summary of the graph.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let s = g.graph_summary().unwrap();
assert_eq!(s.vcount, 3);
assert_eq!(s.ecount, 2);
Source

pub fn graph_summary_string(&self) -> IgraphResult<String>

Human-readable structural summary string.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let s = g.graph_summary_string().unwrap();
assert!(s.contains("Vertices: 3"));
assert!(s.contains("Edges: 2"));
Source

pub fn get_adjacency( &self, adj_type: AdjacencyType, loops: LoopHandling, ) -> IgraphResult<Vec<Vec<f64>>>

Adjacency matrix of the graph.

Returns a dense V×V matrix. For undirected graphs with AdjacencyType::Both, the result is symmetric.

use rust_igraph::{Graph, AdjacencyType, LoopHandling};

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let m = g.get_adjacency(AdjacencyType::Both, LoopHandling::Once).unwrap();
assert_eq!(m.len(), 3);
assert!((m[0][1] - 1.0).abs() < 1e-10);
assert!((m[0][2]).abs() < 1e-10);
Source

pub fn get_adjacency_weighted( &self, adj_type: AdjacencyType, weights: &[f64], loops: LoopHandling, ) -> IgraphResult<Vec<Vec<f64>>>

Weighted adjacency matrix of the graph.

use rust_igraph::{Graph, AdjacencyType, LoopHandling};

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let w = vec![2.0, 3.0];
let m = g.get_adjacency_weighted(AdjacencyType::Both, &w, LoopHandling::Once).unwrap();
assert!((m[0][1] - 2.0).abs() < 1e-10);
Source

pub fn get_laplacian(&self) -> IgraphResult<Vec<Vec<f64>>>

Laplacian matrix L = D - A (unnormalized, unweighted).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let lap = g.get_laplacian().unwrap();
assert!((lap[0][0] - 1.0).abs() < 1e-10); // degree of vertex 0
assert!((lap[1][1] - 2.0).abs() < 1e-10); // degree of vertex 1
Source

pub fn get_laplacian_full( &self, mode: DegreeMode, normalization: LaplacianNormalization, weights: Option<&[f64]>, ) -> IgraphResult<Vec<Vec<f64>>>

Laplacian matrix with normalization and optional weights.

use rust_igraph::{Graph, DegreeMode, LaplacianNormalization};

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let lap = g.get_laplacian_full(
    DegreeMode::All,
    LaplacianNormalization::Symmetric,
    None,
).unwrap();
assert!(lap[0][0] > 0.0);
Source

pub fn get_stochastic(&self, column_wise: bool) -> IgraphResult<Vec<Vec<f64>>>

Stochastic (transition) matrix of the graph.

Each row (or column, if column_wise is true) sums to 1.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,2),(1,2)], false, None).unwrap();
let s = g.get_stochastic(false).unwrap();
let row_sum: f64 = s[0].iter().sum();
assert!((row_sum - 1.0).abs() < 1e-10);
Source

pub fn adjacency_spectral_embedding( &self, no: usize, which: SpectralWhich, ) -> IgraphResult<AdjacencySpectralEmbeddingResult>

Adjacency spectral embedding into no dimensions.

Embeds the graph via the leading eigenvalues/eigenvectors of the adjacency matrix.

use rust_igraph::{Graph, SpectralWhich};

let g = Graph::from_edges(&[(0,1),(1,2),(2,3),(3,0)], false, None).unwrap();
let emb = g.adjacency_spectral_embedding(2, SpectralWhich::LargestMagnitude).unwrap();
assert_eq!(emb.embedding.len(), 4); // one row per vertex
Source

pub fn laplacian_spectral_embedding( &self, no: usize, which: SpectralWhich, lap_type: LaplacianType, ) -> IgraphResult<LaplacianSpectralEmbeddingResult>

Laplacian spectral embedding into no dimensions.

use rust_igraph::{Graph, SpectralWhich, LaplacianType};

let g = Graph::from_edges(&[(0,1),(1,2),(2,3),(3,0)], false, None).unwrap();
let emb = g.laplacian_spectral_embedding(
    2, SpectralWhich::SmallestAlgebraic, LaplacianType::DA,
).unwrap();
assert_eq!(emb.embedding.len(), 4);
Source

pub fn eigen_adjacency( &self, nev: usize, which: EigenWhich, ) -> IgraphResult<EigenDecomposition>

Eigenvalues and eigenvectors of the adjacency matrix.

use rust_igraph::{Graph, EigenWhich};

let g = Graph::from_edges(&[(0,1),(1,2),(2,0)], false, None).unwrap();
let eig = g.eigen_adjacency(2, EigenWhich::LargestAlgebraic).unwrap();
assert_eq!(eig.eigenvalues.len(), 2);
Source

pub fn feedback_vertex_set( &self, algo: FvsAlgorithm, ) -> IgraphResult<Vec<VertexId>>

Feedback vertex set — a minimal set of vertices whose removal makes the graph acyclic.

use rust_igraph::{Graph, FvsAlgorithm};

let g = Graph::from_edges(&[(0,1),(1,2),(2,0)], true, None).unwrap();
let fvs = g.feedback_vertex_set(FvsAlgorithm::Greedy).unwrap();
assert!(!fvs.is_empty()); // need to break the cycle
Source

pub fn complementer(&self) -> IgraphResult<Graph>

Complement graph (all edges that are not in the original).

Self-loops are excluded.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1)], false, Some(3)).unwrap();
let c = g.complementer().unwrap();
assert_eq!(c.ecount(), 2); // edges 0-2 and 1-2
Source

pub fn bipartite_projection_size( &self, types: &[bool], ) -> IgraphResult<BipartiteProjectionSize>

Bipartite projection sizes without building the projected graphs.

types assigns each vertex to one of two partitions (false/true).

use rust_igraph::Graph;

// K_{2,3} bipartite graph
let g = Graph::from_edges(
    &[(0,2),(0,3),(0,4),(1,2),(1,3),(1,4)], false, None
).unwrap();
let types = vec![false, false, true, true, true];
let sz = g.bipartite_projection_size(&types).unwrap();
assert_eq!(sz.vcount1, 2);
assert_eq!(sz.vcount2, 3);
Source

pub fn unfold_tree( &self, roots: &[VertexId], mode: DegreeMode, ) -> IgraphResult<UnfoldTreeResult>

Unfold the graph into a tree by BFS from root vertices.

Returns the unfolded tree and a mapping from new to old vertex ids.

use rust_igraph::{Graph, DegreeMode, DijkstraMode, UnfoldTreeResult};

let g = Graph::from_edges(&[(0,1),(1,2),(2,0)], false, None).unwrap();
let r = g.unfold_tree(&[0], DegreeMode::All).unwrap();
assert!(r.tree.is_tree(DijkstraMode::All).unwrap().is_some());
assert!(!r.vertex_index.is_empty());
Source

pub fn st_edge_connectivity( &self, source: u32, target: u32, ) -> IgraphResult<i64>

S-t edge connectivity between two vertices.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,2),(1,3),(2,3)], false, None).unwrap();
let k = g.st_edge_connectivity(0, 3).unwrap();
assert_eq!(k, 2);
Source

pub fn vertex_disjoint_paths( &self, source: u32, target: u32, ) -> IgraphResult<i64>

Vertex-disjoint paths between two vertices.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(0,2),(1,3),(2,3)], false, None).unwrap();
let n = g.vertex_disjoint_paths(0, 3).unwrap();
assert_eq!(n, 2);
Source

pub fn isomorphic_bliss( &self, other: &Graph, colors1: Option<&[u32]>, colors2: Option<&[u32]>, ) -> IgraphResult<Vf2Isomorphism>

Test isomorphism using BLISS canonical labeling.

use rust_igraph::{Graph, full_graph};

let g1 = full_graph(4, false, false).unwrap();
let g2 = full_graph(4, false, false).unwrap();
let result = g1.isomorphic_bliss(&g2, None, None).unwrap();
assert!(result.iso);
Source

pub fn subisomorphic_lad( &self, pattern: &Graph, induced: bool, domains: Option<&[Vec<u32>]>, ) -> IgraphResult<LadSubisomorphism>

LAD subgraph isomorphism test.

use rust_igraph::Graph;

let target = Graph::from_edges(&[(0,1),(1,2),(2,0),(2,3)], false, None).unwrap();
let pattern = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let iso = target.subisomorphic_lad(&pattern, false, None).unwrap();
assert!(iso.iso);
Source

pub fn betweenness_subset( &self, sources: &[u32], targets: &[u32], ) -> IgraphResult<Vec<f64>>

Betweenness centrality for a subset of vertices.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let bc = g.betweenness_subset(&[0, 1], &[2, 3]).unwrap();
assert_eq!(bc.len(), 4);
Source

pub fn edge_betweenness_subset( &self, sources: &[u32], targets: &[u32], ) -> IgraphResult<Vec<f64>>

Edge betweenness centrality for a subset of vertices.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, None).unwrap();
let ebc = g.edge_betweenness_subset(&[0, 1], &[2, 3]).unwrap();
assert_eq!(ebc.len(), 3);
Source

pub fn edge_betweenness_community_weighted( &self, weights: &[f64], ) -> IgraphResult<EdgeBetweennessResult>

Weighted edge betweenness community detection.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,0),(2,3),(3,4),(4,5),(5,3)], false, None).unwrap();
let w = vec![1.0; g.ecount() as usize];
let result = g.edge_betweenness_community_weighted(&w).unwrap();
assert!(!result.merges.is_empty());
Source

pub fn modularity_matrix( &self, weights: Option<&[f64]>, ) -> IgraphResult<Vec<Vec<f64>>>

Modularity matrix B = A - k*k’/2m.

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2),(2,0)], false, None).unwrap();
let b = g.modularity_matrix(None).unwrap();
assert_eq!(b.len(), 3);
Source

pub fn is_same_graph(&self, other: &Graph) -> bool

Whether the graph is the same as another (structural equality).

use rust_igraph::Graph;

let g1 = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let g2 = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
assert!(g1.is_same_graph(&g2));
Source

pub fn mean_distance_weighted( &self, weights: &[f64], ) -> IgraphResult<Option<f64>>

Mean distance (weighted).

use rust_igraph::Graph;

let g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
let w = vec![1.0, 2.0];
let md = g.mean_distance_weighted(&w).unwrap();
assert!(md.is_some());
Source

pub fn set_graph_attribute( &mut self, name: impl Into<String>, value: AttributeValue, )

Set a graph-level attribute.

Overwrites any existing value with the same name.

use rust_igraph::{Graph, AttributeValue};

let mut g = Graph::with_vertices(0);
g.set_graph_attribute("name", "test".into());
assert_eq!(
    g.graph_attribute("name").and_then(|v| v.as_str()),
    Some("test"),
);
Source

pub fn graph_attribute(&self, name: &str) -> Option<&AttributeValue>

Get a graph-level attribute by name.

use rust_igraph::{Graph, AttributeValue};

let g = Graph::with_vertices(0);
assert!(g.graph_attribute("missing").is_none());
Source

pub fn delete_graph_attribute(&mut self, name: &str) -> bool

Delete a graph-level attribute. Returns true if it existed.

Source

pub fn has_graph_attribute(&self, name: &str) -> bool

Check whether a graph-level attribute exists.

Source

pub fn graph_attribute_names(&self) -> Vec<&str>

List all graph-level attribute names.

use rust_igraph::{Graph, AttributeValue};

let mut g = Graph::with_vertices(0);
g.set_graph_attribute("name", "test".into());
g.set_graph_attribute("year", 2024.0.into());
let names = g.graph_attribute_names();
assert!(names.contains(&"name"));
assert!(names.contains(&"year"));
Source

pub fn set_vertex_attribute( &mut self, name: impl Into<String>, vertex: VertexId, value: AttributeValue, ) -> IgraphResult<()>

Set a vertex attribute for a single vertex.

Creates the attribute vector if it doesn’t exist. New entries for other vertices are filled with a type-appropriate default.

use rust_igraph::{Graph, AttributeValue};

let mut g = Graph::with_vertices(3);
g.set_vertex_attribute("label", 0, "Alice".into()).unwrap();
g.set_vertex_attribute("label", 1, "Bob".into()).unwrap();
assert_eq!(
    g.vertex_attribute("label", 0).and_then(|v| v.as_str()),
    Some("Alice"),
);
Source

pub fn set_vertex_attribute_all( &mut self, name: impl Into<String>, values: Vec<AttributeValue>, ) -> IgraphResult<()>

Set a vertex attribute for all vertices at once.

The values slice must have length equal to vcount().

use rust_igraph::{Graph, AttributeValue};

let mut g = Graph::with_vertices(3);
g.set_vertex_attribute_all(
    "color",
    vec![1.0.into(), 2.0.into(), 3.0.into()],
).unwrap();
let colors = g.vertex_attributes("color").unwrap();
assert_eq!(colors.len(), 3);
Source

pub fn vertex_attribute( &self, name: &str, vertex: VertexId, ) -> Option<&AttributeValue>

Get a vertex attribute for a single vertex.

Source

pub fn vertex_attributes(&self, name: &str) -> Option<&[AttributeValue]>

Get the full vertex attribute vector by name.

Source

pub fn delete_vertex_attribute(&mut self, name: &str) -> bool

Delete a vertex attribute. Returns true if it existed.

Source

pub fn has_vertex_attribute(&self, name: &str) -> bool

Check whether a vertex attribute exists.

Source

pub fn vertex_attribute_names(&self) -> Vec<&str>

List all vertex attribute names.

use rust_igraph::{Graph, AttributeValue};

let mut g = Graph::with_vertices(2);
g.set_vertex_attribute("name", 0, "A".into()).unwrap();
assert!(g.vertex_attribute_names().contains(&"name"));
Source

pub fn set_edge_attribute( &mut self, name: impl Into<String>, edge: u32, value: AttributeValue, ) -> IgraphResult<()>

Set an edge attribute for a single edge.

Creates the attribute vector if it doesn’t exist. New entries for other edges are filled with a type-appropriate default.

use rust_igraph::{Graph, AttributeValue};

let mut g = Graph::from_edges(&[(0,1),(1,2)], false, None).unwrap();
g.set_edge_attribute("weight", 0, 1.5.into()).unwrap();
assert_eq!(
    g.edge_attribute("weight", 0).and_then(|v| v.as_f64()),
    Some(1.5),
);
Source

pub fn set_edge_attribute_all( &mut self, name: impl Into<String>, values: Vec<AttributeValue>, ) -> IgraphResult<()>

Set an edge attribute for all edges at once.

The values slice must have length equal to ecount().

use rust_igraph::{Graph, AttributeValue};

let mut g = Graph::from_edges(&[(0,1),(1,2),(2,0)], false, None).unwrap();
g.set_edge_attribute_all(
    "weight",
    vec![1.0.into(), 2.0.into(), 3.0.into()],
).unwrap();
let w = g.edge_attributes("weight").unwrap();
assert_eq!(w.len(), 3);
Source

pub fn edge_attribute(&self, name: &str, edge: u32) -> Option<&AttributeValue>

Get an edge attribute for a single edge.

Source

pub fn edge_attributes(&self, name: &str) -> Option<&[AttributeValue]>

Get the full edge attribute vector by name.

Source

pub fn delete_edge_attribute(&mut self, name: &str) -> bool

Delete an edge attribute. Returns true if it existed.

Source

pub fn has_edge_attribute(&self, name: &str) -> bool

Check whether an edge attribute exists.

Source

pub fn edge_attribute_names(&self) -> Vec<&str>

List all edge attribute names.

use rust_igraph::{Graph, AttributeValue};

let mut g = Graph::from_edges(&[(0,1)], false, None).unwrap();
g.set_edge_attribute("weight", 0, 1.0.into()).unwrap();
assert!(g.edge_attribute_names().contains(&"weight"));

Trait Implementations§

Source§

impl Add for &Graph

Disjoint union by reference.

Source§

type Output = Graph

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Graph) -> Graph

Performs the + operation. Read more
Source§

impl Add for Graph

Disjoint union: g1 + g2 concatenates vertex sets and edge sets.

§Panics

Panics if the graphs have mismatched directedness.

§Examples

use rust_igraph::Graph;

let a = Graph::try_from(vec![(0u32, 1)].as_slice()).unwrap();
let b = Graph::try_from(vec![(0u32, 1), (1, 2)].as_slice()).unwrap();
let c = a + b;
assert_eq!(c.vcount(), 5);
assert_eq!(c.ecount(), 3);
Source§

type Output = Graph

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Graph) -> Graph

Performs the + operation. Read more
Source§

impl BitAnd for &Graph

Intersection by reference.

Source§

type Output = Graph

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &Graph) -> Graph

Performs the & operation. Read more
Source§

impl BitAnd for Graph

Intersection (min-multiplicity): g1 & g2.

§Panics

Panics if the graphs have mismatched directedness.

§Examples

use rust_igraph::Graph;

let mut a = Graph::new(3, false).unwrap();
a.add_edge(0, 1).unwrap();
a.add_edge(1, 2).unwrap();
let mut b = Graph::new(3, false).unwrap();
b.add_edge(1, 2).unwrap();
b.add_edge(2, 0).unwrap();
let c = a & b;
assert_eq!(c.ecount(), 1);
assert!(c.has_edge(1, 2));
Source§

type Output = Graph

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Graph) -> Graph

Performs the & operation. Read more
Source§

impl BitOr for &Graph

Union by reference.

Source§

type Output = Graph

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &Graph) -> Graph

Performs the | operation. Read more
Source§

impl BitOr for Graph

Union (max-multiplicity merge): g1 | g2.

§Panics

Panics if the graphs have mismatched directedness.

§Examples

use rust_igraph::Graph;

let mut a = Graph::new(3, false).unwrap();
a.add_edge(0, 1).unwrap();
let mut b = Graph::new(3, false).unwrap();
b.add_edge(1, 2).unwrap();
let c = a | b;
assert_eq!(c.ecount(), 2);
Source§

type Output = Graph

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Graph) -> Graph

Performs the | operation. Read more
Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Graph

Source§

fn default() -> Graph

Returns the “default value” for a type. Read more
Source§

impl Display for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Extend<(u32, u32)> for Graph

Extend a graph by adding edges from an iterator.

New vertices are automatically created as needed. This enables patterns like graph.extend(new_edges).

§Panics

Panics if an edge endpoint exceeds the current vertex count and cannot be added.

§Examples

use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.extend([(0u32, 1), (1, 2)]);
assert_eq!(g.ecount(), 2);

// Extending with a vertex beyond current count grows the graph
g.extend([(2u32, 5)]);
assert_eq!(g.vcount(), 6);
assert_eq!(g.ecount(), 3);
Source§

fn extend<I: IntoIterator<Item = (VertexId, VertexId)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<(u32, u32)> for Graph

Collect edges from an iterator into an undirected graph.

Vertex count is inferred from the maximum endpoint id. For directed graphs or explicit vertex counts, use Graph::from_edges.

§Panics

Panics if a vertex id would overflow u32::MAX.

§Examples

use rust_igraph::Graph;

let g: Graph = [(0u32, 1), (1, 2), (2, 0)].into_iter().collect();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3);
Source§

fn from_iter<I: IntoIterator<Item = (VertexId, VertexId)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Graph

Hash a graph by its structural content (directedness + vertex count + sorted edge set).

This is consistent with the PartialEq impl: structurally equal graphs produce the same hash.

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> IntoIterator for &'a Graph

Iterate over a graph’s edges by reference.

Yields (from, to) pairs in edge-id order, enabling the idiomatic for (u, v) in &graph { ... } pattern.

§Examples

use rust_igraph::Graph;

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();

let edges: Vec<_> = (&g).into_iter().collect();
assert_eq!(edges, vec![(0, 1), (1, 2)]);
Source§

type Item = (u32, u32)

The type of the elements being iterated over.
Source§

type IntoIter = Map<Zip<Iter<'a, u32>, Iter<'a, u32>>, fn((&'a u32, &'a u32)) -> (u32, u32)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Not for &Graph

Complement by reference.

Source§

type Output = Graph

The resulting type after applying the ! operator.
Source§

fn not(self) -> Graph

Performs the unary ! operation. Read more
Source§

impl Not for Graph

Complement: !g (all edges not in g, no self-loops).

§Examples

use rust_igraph::Graph;

// Complement of K_3 is an empty graph on 3 vertices.
let mut k3 = Graph::new(3, false).unwrap();
k3.add_edge(0, 1).unwrap();
k3.add_edge(1, 2).unwrap();
k3.add_edge(0, 2).unwrap();
let c = !k3;
assert_eq!(c.vcount(), 3);
assert_eq!(c.ecount(), 0);
Source§

type Output = Graph

The resulting type after applying the ! operator.
Source§

fn not(self) -> Graph

Performs the unary ! operation. Read more
Source§

impl PartialEq for Graph

Structural equality: two graphs are equal if they have the same directedness, same vertex count, and the same sorted edge set.

This is not isomorphism — vertex ids must match exactly.

§Examples

use rust_igraph::Graph;

let a = Graph::from_edges(&[(0,1), (1,2)], false, None).unwrap();
let b = Graph::from_edges(&[(1,2), (0,1)], false, None).unwrap();
assert_eq!(a, b); // same edges, different insertion order

let c = Graph::from_edges(&[(0,1), (1,2)], true, None).unwrap();
assert_ne!(a, c); // different directedness
Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for &Graph

Difference by reference.

Source§

type Output = Graph

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Graph) -> Graph

Performs the - operation. Read more
Source§

impl Sub for Graph

Difference: g1 - g2 (edges in g1 not in g2).

§Panics

Panics if the graphs have mismatched directedness.

§Examples

use rust_igraph::Graph;

let mut a = Graph::new(3, false).unwrap();
a.add_edge(0, 1).unwrap();
a.add_edge(1, 2).unwrap();
let mut b = Graph::new(3, false).unwrap();
b.add_edge(1, 2).unwrap();
let c = a - b;
assert_eq!(c.ecount(), 1);
assert!(c.has_edge(0, 1));
Source§

type Output = Graph

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Graph) -> Graph

Performs the - operation. Read more
Source§

impl TryFrom<&[(u32, u32)]> for Graph

Construct an undirected graph from a slice of (from, to) edge pairs.

Vertex count is inferred from the maximum endpoint id (plus one). This is a convenience for quick construction; for more control use Graph::from_edges or GraphBuilder.

§Examples

use rust_igraph::Graph;

let edges = vec![(0u32, 1), (1, 2), (2, 0)];
let g = Graph::try_from(edges.as_slice()).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3);
assert!(!g.is_directed());
Source§

type Error = IgraphError

The type returned in the event of a conversion error.
Source§

fn try_from(edges: &[(VertexId, VertexId)]) -> IgraphResult<Self>

Performs the conversion.
Source§

impl TryFrom<Vec<(u32, u32)>> for Graph

Construct an undirected graph from a Vec of (from, to) edge pairs.

§Examples

use rust_igraph::Graph;

let g = Graph::try_from(vec![(0u32, 1), (1, 2), (2, 3)]).unwrap();
assert_eq!(g.vcount(), 4);
assert_eq!(g.ecount(), 3);
Source§

type Error = IgraphError

The type returned in the event of a conversion error.
Source§

fn try_from(edges: Vec<(VertexId, VertexId)>) -> IgraphResult<Self>

Performs the conversion.
Source§

impl Eq for Graph

Auto Trait Implementations§

§

impl !Freeze for Graph

§

impl !RefUnwindSafe for Graph

§

impl Send for Graph

§

impl !Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.