Crates.io | graph_solver |
lib.rs | graph_solver |
version | 0.4.0 |
source | src |
created_at | 2020-09-11 14:17:18.283851 |
updated_at | 2020-09-12 01:55:52.48033 |
description | An undirected graph constraint solver for node and edge colors |
homepage | https://github.com/advancedresearch/graph_solver |
repository | https://github.com/advancedresearch/graph_solver.git |
max_upload_size | |
id | 287391 |
size | 59,469 |
An undirected graph constraint solver for node and edge colors.
Brought to you by the AdvancedResearch community!
Graph solving is used to find visual representations of various algebras, such as Adinkra diagrams, but where the rules for generating the graphs efficiently is unknown.
To construct a cube using a graph solver requires specifying how nodes connect to other nodes. The information you give the solver is which colors these connections have, but without telling which nodes in the graph should be connected.
/*
=== CUBE EXAMPLE ===
Run with GraphViz (https://graphviz.org/):
cargo run --example cube | dot -Tpng > test.png
*/
use graph_solver::*;
// Notice that edges starts with `2`.
// This is because `0` is empty and `1` is no-edge.
const EDGE: Color = 2;
fn main() {
let mut g = Graph::new();
// Create a node pattern with 3 edges.
let a = Node {
color: 0,
self_connected: false,
edges: vec![Constraint {edge: EDGE, node: 0}; 3]
};
// Add 8 vertices.
for _ in 0..8 {g.push(a.clone())}
g.no_triangles = true;
let solve_settings = SolveSettings::new();
if let Some(solution) = g.solve(solve_settings) {
println!("{}", solution.puzzle.graphviz(
"sfdp",
&["black"],
&["black"]
));
} else {
eprintln!("<no solution>");
}
}
Each node has a color and a list of edge constraints. The edge constraint stores an edge color and a target color for the adjacent node.
This technique creates a powerful language to describe graphs compactly. For example, all nodes that are locally similar, can use a common description.
Any graphs can be determined using sufficient local information about the nodes and edges. To do this, one can assign each node and edge a unique number.
Therefore, to describe a graph in more detail, one can simply add more colors!
Uses the quickbacktrack library for constraint solving.
This allows starting with a partially solved graph, override solving strategies, debug, or comparing the solution vs the original.
u64
2
0
is means no choice (neither empty or colored).1
is means empty