adinkra3/
adinkra3.rs

1use graph_solver::*;
2
3// Notice that edges start with `2`.
4const RED: Color = 2;
5const RED_DASHED: Color = 3;
6const GREEN: Color = 4;
7const GREEN_DASHED: Color = 5;
8const BLUE: Color = 6;
9const BLUE_DASHED: Color = 7;
10
11const BLACK: Color = 0;
12const WHITE: Color = 1;
13
14fn main() {
15    let mut g = Graph::new();
16    // 0
17    g.push(Node {
18        color: BLACK,
19        self_connected: false,
20        edges: vec![
21            Constraint {edge: RED, node: WHITE},
22            Constraint {edge: GREEN, node: WHITE},
23            Constraint {edge: BLUE_DASHED, node: WHITE},
24        ]
25    });
26    // 1
27    g.push(Node {
28        color: WHITE,
29        self_connected: false,
30        edges: vec![
31            Constraint {edge: RED, node: BLACK},
32            Constraint {edge: GREEN_DASHED, node: BLACK},
33            Constraint {edge: BLUE_DASHED, node: BLACK},
34        ]
35    });
36    // 2
37    g.push(Node {
38        color: WHITE,
39        self_connected: false,
40        edges: vec![
41            Constraint {edge: GREEN, node: BLACK},
42            Constraint {edge: RED, node: BLACK},
43            Constraint {edge: BLUE_DASHED, node: BLACK},
44        ]
45    });
46    // 3
47    g.push(Node {
48        color: BLACK,
49        self_connected: false,
50        edges: vec![
51            Constraint {edge: RED, node: WHITE},
52            Constraint {edge: GREEN_DASHED, node: WHITE},
53            Constraint {edge: BLUE, node: WHITE},
54        ]
55    });
56    // 4
57    g.push(Node {
58        color: WHITE,
59        self_connected: false,
60        edges: vec![
61            Constraint {edge: RED_DASHED, node: BLACK},
62            Constraint {edge: GREEN_DASHED, node: BLACK},
63            Constraint {edge: BLUE_DASHED, node: BLACK},
64        ]
65    });
66    // 5
67    g.push(Node {
68        color: BLACK,
69        self_connected: false,
70        edges: vec![
71            Constraint {edge: RED, node: WHITE},
72            Constraint {edge: GREEN_DASHED, node: WHITE},
73            Constraint {edge: BLUE_DASHED, node: WHITE},
74        ]
75    });
76    // 6
77    g.push(Node {
78        color: WHITE,
79        self_connected: false,
80        edges: vec![
81            Constraint {edge: RED, node: BLACK},
82            Constraint {edge: GREEN_DASHED, node: BLACK},
83            Constraint {edge: BLUE, node: BLACK},
84        ]
85    });
86    // 7
87    g.push(Node {
88        color: BLACK,
89        self_connected: false,
90        edges: vec![
91            Constraint {edge: RED_DASHED, node: WHITE},
92            Constraint {edge: GREEN_DASHED, node: WHITE},
93            Constraint {edge: BLUE_DASHED, node: WHITE},
94        ]
95    });
96
97    // Require anticommutativity for every quad.
98    g.commute_quad = Some(false);
99
100    let solve_settings = SolveSettings::new(); // .debug(true); // .sleep_ms(1000);
101    if let Some(solution) = g.solve(solve_settings) {
102        // solution.puzzle.print();
103        let nodes = &["black,fontcolor=white,label=\"\"", "white,label=\"\""];
104        let edges = &[
105            "red", "red,style=dashed",
106            "green", "green,style=dashed",
107            "blue", "blue,style=dashed",
108        ];
109        println!("{}", solution.puzzle.graphviz("sfdp", nodes, edges));
110    } else {
111        eprintln!("<no solution>");
112    }
113}