pub struct SolveSettings { /* private fields */ }Expand description
Stores settings for solver.
Default settings:
- solve_simple:
true - debug:
false - difference:
false - sleep_ms:
None
Implementations§
Source§impl SolveSettings
impl SolveSettings
Sourcepub fn new() -> SolveSettings
pub fn new() -> SolveSettings
Creates new solve settings.
Examples found in repository?
6fn main() {
7 let mut g = Graph::new();
8 let a = Node {
9 color: 0,
10 self_connected: false,
11 edges: vec![Constraint {edge: RED, node: 1}]
12 };
13 let b = Node {
14 color: 1,
15 self_connected: false,
16 edges: vec![Constraint {edge: RED, node: 0}]
17 };
18 g.push(a);
19 g.push(b);
20
21 let solve_settings = SolveSettings::new();
22 if let Some(solution) = g.solve(solve_settings) {
23 solution.puzzle.print();
24 }
25}More examples
6fn main() {
7 let mut g = Graph::new();
8
9 // Create a node pattern.
10 let a = Node {
11 color: 0,
12 self_connected: false,
13 edges: vec![Constraint {edge: EDGE, node: 0}; 2]
14 };
15
16 for _ in 0..3 {g.push(a.clone())}
17
18 let solve_settings = SolveSettings::new();
19 if let Some(solution) = g.solve(solve_settings) {
20 // solution.puzzle.print();
21 println!("{}", solution.puzzle.graphviz(
22 "sfdp",
23 &["black"],
24 &["black"]
25 ));
26 }
27}6fn main() {
7 let mut g = Graph::new();
8
9 // Create a node pattern.
10 let a = Node {
11 color: 0,
12 self_connected: false,
13 edges: vec![
14 Constraint {edge: EDGE, node: 0},
15 Constraint {edge: EDGE, node: 0},
16 ]
17 };
18
19 for _ in 0..5 {g.push(a.clone())}
20
21 let solve_settings = SolveSettings::new();
22 if let Some(solution) = g.solve(solve_settings) {
23 // solution.puzzle.print();
24 println!("{}", solution.puzzle.graphviz(
25 "sfdp",
26 &["black"],
27 &["black"]
28 ));
29 }
30}16fn main() {
17 let mut g = Graph::new();
18
19 // Create a node pattern with 3 edges.
20 let a = Node {
21 color: 0,
22 self_connected: false,
23 edges: vec![Constraint {edge: EDGE, node: 0}; 3]
24 };
25
26 // Add 8 vertices.
27 for _ in 0..8 {g.push(a.clone())}
28 g.no_triangles = true;
29
30 let solve_settings = SolveSettings::new();
31 if let Some(solution) = g.solve(solve_settings) {
32 println!("{}", solution.puzzle.graphviz(
33 "sfdp",
34 &["black"],
35 &["black"]
36 ));
37 } else {
38 eprintln!("<no solution>");
39 }
40}6fn main() {
7 let mut g = Graph::new();
8
9 // Create a node pattern.
10 let a = Node {
11 color: 0,
12 self_connected: false,
13 edges: vec![Constraint {edge: SOLID, node: 0}; 2]
14 };
15
16 // Add 4 nodes.
17 for _ in 0..4 {g.push(a.clone())}
18
19 let solve_settings = SolveSettings::new()
20 .debug(true).sleep_ms(2000);
21 if let Some(solution) = g.solve(solve_settings) {
22 // Prints:
23 // 0 0 0 0
24 // ========================================
25 // 0 2 1 0
26 // 2 0 0 1
27 // 1 0 0 2
28 // 0 1 2 0
29 solution.puzzle.print();
30 }
31}6fn main() {
7 let mut g = Graph::new();
8
9 // Create a node pattern.
10 let a = Node {
11 color: 0,
12 self_connected: false,
13 edges: vec![
14 Constraint {edge: EDGE, node: 0},
15 Constraint {edge: EDGE, node: 0},
16 ]
17 };
18
19 for _ in 0..6 {g.push(a.clone())}
20 g.push_pair((2, 3));
21
22 let solve_settings = SolveSettings::new();
23 if let Some(solution) = g.solve(solve_settings) {
24 // solution.puzzle.print();
25 println!("{}", solution.puzzle.graphviz(
26 "sfdp",
27 &["black,fontcolor=white"],
28 &["black"]
29 ));
30 }
31}Sourcepub fn set_solve_simple(&mut self, val: bool)
pub fn set_solve_simple(&mut self, val: bool)
Sets wheter to solve simple moves between each step.
Sourcepub fn solve_simple(self, val: bool) -> SolveSettings
pub fn solve_simple(self, val: bool) -> SolveSettings
Whether to solve simple moves between each step.
Sourcepub fn set_debug(&mut self, val: bool)
pub fn set_debug(&mut self, val: bool)
Sets whether to debug by printing out to standard output.
Sourcepub fn debug(self, val: bool) -> SolveSettings
pub fn debug(self, val: bool) -> SolveSettings
Whether to debug by printing out to standard output.
Examples found in repository?
6fn main() {
7 let mut g = Graph::new();
8
9 // Create a node pattern.
10 let a = Node {
11 color: 0,
12 self_connected: false,
13 edges: vec![Constraint {edge: SOLID, node: 0}; 2]
14 };
15
16 // Add 4 nodes.
17 for _ in 0..4 {g.push(a.clone())}
18
19 let solve_settings = SolveSettings::new()
20 .debug(true).sleep_ms(2000);
21 if let Some(solution) = g.solve(solve_settings) {
22 // Prints:
23 // 0 0 0 0
24 // ========================================
25 // 0 2 1 0
26 // 2 0 0 1
27 // 1 0 0 2
28 // 0 1 2 0
29 solution.puzzle.print();
30 }
31}More examples
7fn main() {
8 let mut g = Graph::new();
9
10 // Create a node pattern.
11 let a = Node {
12 color: 0,
13 self_connected: false,
14 edges: vec![
15 Constraint {edge: HORIZONTAL, node: 0},
16 Constraint {edge: VERTICAL, node: 0},
17 ]
18 };
19
20 // Add 4 nodes.
21 for _ in 0..4 {g.push(a.clone())}
22
23 let solve_settings = SolveSettings::new()
24 .debug(true).sleep_ms(2000);
25 if let Some(solution) = g.solve(solve_settings) {
26 // Prints:
27 // 0 0 0 0
28 // ========================================
29 // 0 2 1 0
30 // 2 0 0 1
31 // 1 0 0 2
32 // 0 1 2 0
33 solution.puzzle.print();
34 }
35}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}Sourcepub fn set_difference(&mut self, val: bool)
pub fn set_difference(&mut self, val: bool)
Sets whether to return the difference from initial puzzle.
Sourcepub fn difference(self, val: bool) -> SolveSettings
pub fn difference(self, val: bool) -> SolveSettings
Whether to return the difference from initial puzzle.
Sourcepub fn set_maybe_sleep_ms(&mut self, val: Option<u64>)
pub fn set_maybe_sleep_ms(&mut self, val: Option<u64>)
Sets how many milliseconds to sleep between each step, if any.
Sourcepub fn maybe_sleep_ms(self, val: Option<u64>) -> SolveSettings
pub fn maybe_sleep_ms(self, val: Option<u64>) -> SolveSettings
Sets how many milliseconds to sleep between each step, if any.
Sourcepub fn set_sleep_ms(&mut self, val: u64)
pub fn set_sleep_ms(&mut self, val: u64)
Sets how many milliseconds to sleep between each step.
Sourcepub fn sleep_ms(self, val: u64) -> SolveSettings
pub fn sleep_ms(self, val: u64) -> SolveSettings
How many milliseconds to sleep between each step.
Examples found in repository?
6fn main() {
7 let mut g = Graph::new();
8
9 // Create a node pattern.
10 let a = Node {
11 color: 0,
12 self_connected: false,
13 edges: vec![Constraint {edge: SOLID, node: 0}; 2]
14 };
15
16 // Add 4 nodes.
17 for _ in 0..4 {g.push(a.clone())}
18
19 let solve_settings = SolveSettings::new()
20 .debug(true).sleep_ms(2000);
21 if let Some(solution) = g.solve(solve_settings) {
22 // Prints:
23 // 0 0 0 0
24 // ========================================
25 // 0 2 1 0
26 // 2 0 0 1
27 // 1 0 0 2
28 // 0 1 2 0
29 solution.puzzle.print();
30 }
31}More examples
7fn main() {
8 let mut g = Graph::new();
9
10 // Create a node pattern.
11 let a = Node {
12 color: 0,
13 self_connected: false,
14 edges: vec![
15 Constraint {edge: HORIZONTAL, node: 0},
16 Constraint {edge: VERTICAL, node: 0},
17 ]
18 };
19
20 // Add 4 nodes.
21 for _ in 0..4 {g.push(a.clone())}
22
23 let solve_settings = SolveSettings::new()
24 .debug(true).sleep_ms(2000);
25 if let Some(solution) = g.solve(solve_settings) {
26 // Prints:
27 // 0 0 0 0
28 // ========================================
29 // 0 2 1 0
30 // 2 0 0 1
31 // 1 0 0 2
32 // 0 1 2 0
33 solution.puzzle.print();
34 }
35}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}Sourcepub fn set_maybe_max_iterations(&mut self, val: Option<u64>)
pub fn set_maybe_max_iterations(&mut self, val: Option<u64>)
Sets the maximum number of iterations before giving up.
Sourcepub fn maybe_max_iterations(self, val: Option<u64>) -> SolveSettings
pub fn maybe_max_iterations(self, val: Option<u64>) -> SolveSettings
The maximum number of iterations before giving up.
Sourcepub fn set_max_iterations(&mut self, val: u64)
pub fn set_max_iterations(&mut self, val: u64)
Sets the maximum number of iterations before giving up.
Sourcepub fn max_iterations(self, val: u64) -> SolveSettings
pub fn max_iterations(self, val: u64) -> SolveSettings
The maximum number of iterations before giving up.