adinkra4/
adinkra4.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;
10const ORANGE: Color = 8;
11const ORANGE_DASHED: Color = 9;
12
13const BLACK: Color = 0;
14const WHITE: Color = 1;
15
16fn main() {
17    let mut g = Graph::new();
18
19    // 0
20    g.push(Node {
21        color: BLACK,
22        self_connected: false,
23        edges: vec![
24            Constraint {edge: RED, node: WHITE},
25            Constraint {edge: GREEN, node: WHITE},
26            Constraint {edge: BLUE_DASHED, node: WHITE},
27            Constraint {edge: ORANGE, node: WHITE},
28        ]
29    });
30    // 1
31    g.push(Node {
32        color: WHITE,
33        self_connected: false,
34        edges: vec![
35            Constraint {edge: RED, node: BLACK},
36            Constraint {edge: GREEN_DASHED, node: BLACK},
37            Constraint {edge: BLUE_DASHED, node: BLACK},
38            Constraint {edge: ORANGE_DASHED, node: BLACK},
39        ]
40    });
41    // 2
42    g.push(Node {
43        color: WHITE,
44        self_connected: false,
45        edges: vec![
46            Constraint {edge: GREEN, node: BLACK},
47            Constraint {edge: RED, node: BLACK},
48            Constraint {edge: BLUE_DASHED, node: BLACK},
49            Constraint {edge: ORANGE_DASHED, node: BLACK},
50        ]
51    });
52    // 3
53    g.push(Node {
54        color: BLACK,
55        self_connected: false,
56        edges: vec![
57            Constraint {edge: RED, node: WHITE},
58            Constraint {edge: GREEN_DASHED, node: WHITE},
59            Constraint {edge: BLUE, node: WHITE},
60            Constraint {edge: ORANGE_DASHED, node: WHITE},
61        ]
62    });
63    // 4
64    g.push(Node {
65        color: WHITE,
66        self_connected: false,
67        edges: vec![
68            Constraint {edge: RED_DASHED, node: BLACK},
69            Constraint {edge: GREEN_DASHED, node: BLACK},
70            Constraint {edge: BLUE_DASHED, node: BLACK},
71            Constraint {edge: ORANGE_DASHED, node: BLACK},
72        ]
73    });
74    // 5
75    g.push(Node {
76        color: BLACK,
77        self_connected: false,
78        edges: vec![
79            Constraint {edge: RED, node: WHITE},
80            Constraint {edge: GREEN_DASHED, node: WHITE},
81            Constraint {edge: BLUE_DASHED, node: WHITE},
82            Constraint {edge: ORANGE, node: WHITE},
83        ]
84    });
85    // 6
86    g.push(Node {
87        color: WHITE,
88        self_connected: false,
89        edges: vec![
90            Constraint {edge: RED, node: BLACK},
91            Constraint {edge: GREEN_DASHED, node: BLACK},
92            Constraint {edge: BLUE, node: BLACK},
93            Constraint {edge: ORANGE, node: BLACK},
94        ]
95    });
96    // 7
97    g.push(Node {
98        color: BLACK,
99        self_connected: false,
100        edges: vec![
101            Constraint {edge: RED_DASHED, node: WHITE},
102            Constraint {edge: GREEN_DASHED, node: WHITE},
103            Constraint {edge: BLUE_DASHED, node: WHITE},
104            Constraint {edge: ORANGE, node: WHITE},
105        ]
106    });
107    // 8
108    g.push(Node {
109        color: WHITE,
110        self_connected: false,
111        edges: vec![
112            Constraint {edge: ORANGE, node: BLACK},
113            Constraint {edge: BLUE_DASHED, node: BLACK},
114            Constraint {edge: RED, node: BLACK},
115            Constraint {edge: GREEN, node: BLACK},
116        ]
117    });
118    // 9
119    g.push(Node {
120        color: BLACK,
121        self_connected: false,
122        edges: vec![
123            Constraint {edge: BLUE_DASHED, node: WHITE},
124            Constraint {edge: ORANGE_DASHED, node: WHITE},
125            Constraint {edge: RED_DASHED, node: WHITE},
126            Constraint {edge: GREEN_DASHED, node: WHITE},
127        ]
128    });
129    // 10
130    g.push(Node {
131        color: WHITE,
132        self_connected: false,
133        edges: vec![
134            Constraint {edge: RED_DASHED, node: BLACK},
135            Constraint {edge: ORANGE, node: BLACK},
136            Constraint {edge: BLUE_DASHED, node: BLACK},
137            Constraint {edge: GREEN, node: BLACK},
138        ]
139    });
140    // 11
141    g.push(Node {
142        color: BLACK,
143        self_connected: false,
144        edges: vec![
145            Constraint {edge: BLUE_DASHED, node: WHITE},
146            Constraint {edge: ORANGE_DASHED, node: WHITE},
147            Constraint {edge: RED, node: WHITE},
148            Constraint {edge: GREEN, node: WHITE},
149        ]
150    });
151    // 12
152    g.push(Node {
153        color: WHITE,
154        self_connected: false,
155        edges: vec![
156            Constraint {edge: ORANGE, node: BLACK},
157            Constraint {edge: GREEN_DASHED, node: BLACK},
158            Constraint {edge: RED_DASHED, node: BLACK},
159            Constraint {edge: BLUE_DASHED, node: BLACK},
160        ]
161    });
162    // 13
163    g.push(Node {
164        color: BLACK,
165        self_connected: false,
166        edges: vec![
167            Constraint {edge: RED_DASHED, node: WHITE},
168            Constraint {edge: ORANGE, node: WHITE},
169            Constraint {edge: GREEN, node: WHITE},
170            Constraint {edge: BLUE, node: WHITE},
171        ]
172    });
173    // 14
174    g.push(Node {
175        color: WHITE,
176        self_connected: false,
177        edges: vec![
178            Constraint {edge: BLUE, node: BLACK},
179            Constraint {edge: ORANGE_DASHED, node: BLACK},
180            Constraint {edge: RED_DASHED, node: BLACK},
181            Constraint {edge: GREEN, node: BLACK},
182        ]
183    });
184    // 15
185    g.push(Node {
186        color: BLACK,
187        self_connected: false,
188        edges: vec![
189            Constraint {edge: BLUE_DASHED, node: WHITE},
190            Constraint {edge: RED_DASHED, node: WHITE},
191            Constraint {edge: GREEN, node: WHITE},
192            Constraint {edge: ORANGE_DASHED, node: WHITE},
193        ]
194    });
195
196    // Uncomment for improved performance.
197    /*
198    g.set((0, 1), RED);
199    g.set((0, 8), ORANGE);
200    g.set((0, 2), GREEN);
201    g.set((0, 4), BLUE_DASHED);
202    g.set((2, 3), RED);
203    g.set((2, 5), BLUE_DASHED);
204    g.set((1, 3), GREEN_DASHED);
205    g.set((1, 11), ORANGE_DASHED);
206    g.set((8, 11), RED);
207    g.set((12, 13), RED_DASHED);
208    g.set((14, 15), RED_DASHED);
209    g.set((3, 14), ORANGE_DASHED);
210    g.set((5, 6), RED);
211    g.set((10, 13), GREEN);
212    g.set((1, 7), BLUE_DASHED);
213    */
214
215    // Require anticommutativity for every quad.
216    g.commute_quad = Some(false);
217
218    let solve_settings = SolveSettings::new(); // .debug(true); // .sleep_ms(1000);
219    if let Some(solution) = g.solve(solve_settings) {
220        // solution.puzzle.print();
221        // let nodes = &["black,fontcolor=white,label=\"\"", "white,label=\"\""];
222        let nodes = &["black,fontcolor=white", "white"];
223        let edges = &[
224            "red", "red,style=dashed",
225            "green", "green,style=dashed",
226            "blue", "blue,style=dashed",
227            "orange", "orange,style=dashed",
228        ];
229        println!("{}", solution.puzzle.graphviz("neato", nodes, edges));
230    } else {
231        eprintln!("<no solution>");
232    }
233}