seven_bridges/
seven-bridges.rs

1/*
2Seven Bridges of Königsberg
3https://en.wikipedia.org/wiki/Seven_Bridges_of_K%C3%B6nigsberg
4*/
5
6use graph_solver::*;
7
8fn main() {
9    let mut g = Graph::new();
10
11    let black_edge = Constraint {node: 0, edge: 2};
12    let red_edge = Constraint {node: 0, edge: 3};
13    let f = |black, red| Node {
14        color: 0,
15        self_connected: false,
16        edges: {
17            let mut res = vec![];
18            for _ in 0..black {res.push(black_edge)}
19            for _ in 0..red {res.push(red_edge)}
20            res
21        }
22    };
23    g.push(f(1, 1));
24    g.push(f(2, 1));
25    g.push(f(1, 1));
26    g.push(f(1, 2));
27    g.push(f(1, 3));
28    g.push(f(0, 3));
29    g.push(f(1, 1));
30    g.push(f(2, 1));
31    g.push(f(1, 1));
32
33    g.set((0, 1), 2);
34    g.set((1, 2), 2);
35    g.set((0, 2), 1);
36    g.set((1, 4), 3);
37    g.set((2, 3), 1);
38    g.set((2, 4), 1);
39    g.set((3, 5), 1);
40    g.set((3, 7), 1);
41    g.set((3, 4), 2);
42
43    g.connected = true;
44
45    let solve_settings = SolveSettings::new()
46        .debug(false)
47        .sleep_ms(1000);
48    if let Some(solution) = g.solve(solve_settings) {
49        // solution.puzzle.print();
50        println!("{}", solution.puzzle.graphviz(
51            "sfdp",
52            &["white"],
53            &["black", "red"]
54        ));
55    } else {
56        eprintln!("<no solution>");
57    }
58}