pub struct Graph { /* private fields */ }Expand description
An undirected graph without self-loops or multiple edges.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn from_vectors(
vectors: &[i64],
dim: usize,
allowed: &[i64],
) -> Result<Graph, Error>
pub fn from_vectors( vectors: &[i64], dim: usize, allowed: &[i64], ) -> Result<Graph, Error>
The graph on integer vectors of length dim, held one after another in vectors, with two
joined when their inner product is one of allowed.
Sets of vectors with prescribed inner products are then cliques: rows of a Hadamard matrix
are pairwise orthogonal (allowed = [0]), equiangular lines have inner products ±c. The
inner products are computed in parallel straight into the adjacency matrix, so no edge list
is built, which matters when there are hundreds of millions of edges. Entries must be small
enough that inner products fit an i64.
Sourcepub fn from_words(words: &[u64], distances: &[u32]) -> Graph
pub fn from_words(words: &[u64], distances: &[u32]) -> Graph
The graph on binary words of up to 64 bits, each given as an integer whose bit i is the
word’s i-th entry, with two joined when their Hamming distance (the number of places in
which they differ) is one of distances.
A binary code of minimum distance d is then a clique when distances is d..=len, and an
independent set in the graph with distances 1..d. Distances are computed in parallel
straight into the adjacency matrix, each as one exclusive or and a bit count.
Examples found in repository?
38fn main() {
39 let rounds: usize = std::env::args()
40 .nth(1)
41 .and_then(|a| a.parse().ok())
42 .unwrap_or(5);
43 let all15: Vec<u64> = (0..1u64 << 15).collect();
44 let all16: Vec<u64> = (0..1u64 << 16).collect();
45 let weight5: Vec<u64> = (0..1u64 << 18).filter(|w| w.count_ones() == 5).collect();
46 let workloads: [(&str, &[u64], &[u32]); 3] = [
47 ("from_words_all15_d1-3", &all15, &[1, 2, 3]),
48 ("from_words_weight5_len18_d1-5", &weight5, &[1, 2, 3, 4, 5]),
49 ("from_words_all16_d1-3", &all16, &[1, 2, 3]),
50 ];
51 for (name, words, distances) in workloads {
52 let t = time(rounds, || Graph::from_words(words, distances).num_edges());
53 println!("RESULT {name} {t:.4}");
54 }
55 // the control: a search, which counts no bits in its hot loop
56 let g = generate(Model::Exponential, 1000, 500, &mut Xoshiro::new(1)).expect("a random graph");
57 let mut p = SearchParams::new(100, 4950); // a 100-clique: unreachable, so every experiment makes all its moves
58 p.experiments = 32;
59 p.max_moves = 2000;
60 let t = time(rounds, || search(&g, &p).expect("a search").successes());
61 println!("RESULT search_control {t:.4}");
62}Sourcepub fn from_edges<I>(n: usize, edges: I) -> Result<Graph, Error>
pub fn from_edges<I>(n: usize, edges: I) -> Result<Graph, Error>
Builds a graph on n vertices from an edge list.
Sourcepub fn num_vertices(&self) -> usize
pub fn num_vertices(&self) -> usize
Number of vertices.
Sourcepub fn num_edges(&self) -> usize
pub fn num_edges(&self) -> usize
Number of edges.
Examples found in repository?
38fn main() {
39 let rounds: usize = std::env::args()
40 .nth(1)
41 .and_then(|a| a.parse().ok())
42 .unwrap_or(5);
43 let all15: Vec<u64> = (0..1u64 << 15).collect();
44 let all16: Vec<u64> = (0..1u64 << 16).collect();
45 let weight5: Vec<u64> = (0..1u64 << 18).filter(|w| w.count_ones() == 5).collect();
46 let workloads: [(&str, &[u64], &[u32]); 3] = [
47 ("from_words_all15_d1-3", &all15, &[1, 2, 3]),
48 ("from_words_weight5_len18_d1-5", &weight5, &[1, 2, 3, 4, 5]),
49 ("from_words_all16_d1-3", &all16, &[1, 2, 3]),
50 ];
51 for (name, words, distances) in workloads {
52 let t = time(rounds, || Graph::from_words(words, distances).num_edges());
53 println!("RESULT {name} {t:.4}");
54 }
55 // the control: a search, which counts no bits in its hot loop
56 let g = generate(Model::Exponential, 1000, 500, &mut Xoshiro::new(1)).expect("a random graph");
57 let mut p = SearchParams::new(100, 4950); // a 100-clique: unreachable, so every experiment makes all its moves
58 p.experiments = 32;
59 p.max_moves = 2000;
60 let t = time(rounds, || search(&g, &p).expect("a search").successes());
61 println!("RESULT search_control {t:.4}");
62}Sourcepub fn has_edge(&self, u: usize, v: usize) -> bool
pub fn has_edge(&self, u: usize, v: usize) -> bool
Whether {u, v} is an edge. Panics if either vertex is out of range.
Sourcepub fn row(&self, u: usize) -> &[u64]
pub fn row(&self, u: usize) -> &[u64]
Row u of the adjacency matrix as a bitset: bit v % 64 of word v / 64 is set iff
{u, v} is an edge. Test bits with bit.
Sourcepub fn edges(&self) -> impl Iterator<Item = (usize, usize)> + '_
pub fn edges(&self) -> impl Iterator<Item = (usize, usize)> + '_
Edges (u, v) with u < v, in lexicographic order.
Sourcepub fn density(&self) -> f64
pub fn density(&self) -> f64
Edge density m / (n choose 2), or 0 for graphs with fewer than two vertices.
Sourcepub fn into_builder(self) -> GraphBuilder
pub fn into_builder(self) -> GraphBuilder
Converts back into a builder, e.g. to modify the graph.
Sourcepub fn induced_edge_count(&self, vertices: &[usize]) -> usize
pub fn induced_edge_count(&self, vertices: &[usize]) -> usize
Number of edges among vertices, which must be distinct.
Sourcepub fn components(&self) -> (Vec<usize>, usize)
pub fn components(&self) -> (Vec<usize>, usize)
Connected components, as a component index per vertex plus the number of components.
Trait Implementations§
impl Eq for Graph
Source§impl SearchGraph for Graph
impl SearchGraph for Graph
fn num_vertices(&self) -> usize
fn adjacency_row(&self, u: usize) -> &[u64]
Source§fn edge_value(&self, u: usize, v: usize) -> i64
fn edge_value(&self, u: usize, v: usize) -> i64
{u, v} contributes to the subgraph’s value: its weight, or 0 or 1.Source§fn objective_bound(&self) -> i64
fn objective_bound(&self) -> i64
sub_search, the total weight in wsub_search.Source§fn max_row_value(&self, _u: usize) -> i64
fn max_row_value(&self, _u: usize) -> i64
AdjacencyRow::value in u’s row: 1 in an unweighted graph, the
largest weight at u in a weighted one. The search uses it to skip rows that cannot hold a
best move; the default, a bound too large to skip any, is always correct.impl StructuralPartialEq for Graph
Auto Trait Implementations§
impl Forget for Graph
impl Freeze for Graph
impl Move 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more