subgraphsearch_core/lib.rs
1//! # subgraphsearch
2//!
3//! Randomized tabu search for vertex-induced subgraphs with a given number of vertices and
4//! edges, regular ones, or ones of a given total weight, together with random graph generators,
5//! graph operations, and readers and writers for standard graph formats.
6//!
7//! ```
8//! use subgraphsearch_core::{Graph, SearchParams, search};
9//!
10//! // find induced 4-vertex paths (3 edges) in a 12-cycle
11//! let g = Graph::from_edges(12, (0..12).map(|i| (i, (i + 1) % 12))).unwrap();
12//! let result = search(&g, &SearchParams::new(4, 3)).unwrap();
13//! let found = result.experiments.iter().find(|e| e.success).unwrap();
14//! assert_eq!(g.induced_edge_count(&found.vertices), 3);
15//! ```
16//!
17//! Modules:
18//! - [`graph`]: the [`Graph`] type.
19//! - [`search`](mod@search): the search itself, and [`regular`]: its regular-subgraph variant.
20//! - [`largest`](mod@largest): the largest induced path, cycle or tree, clique or independent set a
21//! search finds.
22//! - [`generate`] and [`ops`]: random graphs, complements, induced subgraphs, switching,
23//! incidence structures.
24//! - [`formats`]: graph6, sparse6, Matrix Market, edge lists, `sub_search` adjacency lists, DOT, GraphML.
25//! - [`rng`]: the original programs' generator (for exact reproduction) and xoshiro256++.
26//! - [`layout`]: force-directed layout for drawing graphs.
27//! - [`legacy`]: byte-for-byte emulation of the original `sub_search` and `ggen` programs.
28
29pub mod formats;
30pub mod generate;
31pub mod graph;
32pub mod largest;
33pub mod layout;
34pub mod legacy;
35pub mod ops;
36pub mod regular;
37pub mod rng;
38pub mod search;
39
40pub use formats::Format;
41pub use generate::Model;
42pub use graph::{Graph, GraphBuilder, WeightedGraph};
43pub use largest::{Largest, Shape, largest};
44pub use rng::RngKind;
45pub use search::{
46 AUTO_TABU_TENURE, DEFAULT_KICK_SIZE, Experiment, MAX_AUTO_TABU_TENURE, Regular, SearchGraph,
47 SearchParams, SearchResult, auto_tabu_tenure, search, search_sequential, search_settings,
48};
49
50/// Errors reported by this crate.
51#[derive(Debug, thiserror::Error)]
52pub enum Error {
53 #[error("vertex {vertex} is out of range [0, {n})")]
54 VertexOutOfRange { vertex: i64, n: usize },
55 #[error("self-loop at vertex {0}; graphs must be simple")]
56 SelfLoop(usize),
57 #[error("vertex {0} is listed twice")]
58 DuplicateVertex(usize),
59 #[error(
60 "{0} is not a valid subgraph size: it must be at least 2, larger than the number of fixed vertices, and smaller than the number of graph vertices"
61 )]
62 InvalidSubgraphSize(i64),
63 #[error("{0} is not a valid diversification frequency: it must be at least 1")]
64 InvalidDiversificationFrequency(i64),
65 #[error(
66 "the file holds {0} graphs; choose one (CLI: --index N, Python: index=N) or use them all (CLI: search --all, Python: read_all)"
67 )]
68 MultipleGraphs(usize),
69 #[error("{0}")]
70 Invalid(String),
71 #[error("{}{msg}", line.map(|l| format!("line {l}: ")).unwrap_or_default())]
72 Parse { line: Option<usize>, msg: String },
73 /// An error message exactly as the original C program would have printed it.
74 #[error("{0}")]
75 Legacy(String),
76 #[error(transparent)]
77 Io(#[from] std::io::Error),
78}