1use graph_solver::*;
2
3const 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 g.commute_quad = Some(false);
217
218 let solve_settings = SolveSettings::new(); if let Some(solution) = g.solve(solve_settings) {
220 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}