pub struct ProofLog { /* private fields */ }Expand description
A proof log which logs the proof steps necessary to prove unsatisfiability or optimality. We allow the following types of proofs:
- A CP proof log - This can be created using
ProofLog::cp. - A DIMACS proof log - This can be created using
ProofLog::dimacs.
When a proof log should not be generated, use the implementation of Default.
Implementations§
Source§impl ProofLog
impl ProofLog
Sourcepub fn cp(file_path: &Path, log_hints: bool) -> Result<ProofLog, Error>
pub fn cp(file_path: &Path, log_hints: bool) -> Result<ProofLog, Error>
Create a CP proof logger.
Examples found in repository?
examples/nqueens.rs (line 38)
25fn main() {
26 let Cli {
27 n,
28 proof: proof_path,
29 } = Cli::parse();
30
31 if n < 2 {
32 println!("Please provide an 'n > 1'");
33 return;
34 }
35
36 let Ok(proof_log) = proof_path
37 .as_ref()
38 .map(|path| ProofLog::cp(path, true))
39 .transpose()
40 .map(|proof| proof.unwrap_or_default())
41 else {
42 eprintln!(
43 "Failed to create proof file at {}",
44 proof_path.unwrap().display()
45 );
46 return;
47 };
48
49 let mut solver = Solver::with_options(SolverOptions {
50 proof_log,
51 ..Default::default()
52 });
53
54 // Create the constraint tags for the three all_different constraints.
55 let c1_tag = solver.new_constraint_tag();
56 let c2_tag = solver.new_constraint_tag();
57 let c3_tag = solver.new_constraint_tag();
58
59 let variables = (0..n)
60 .map(|i| solver.new_named_bounded_integer(0, n as i32 - 1, format!("q{i}")))
61 .collect::<Vec<_>>();
62
63 let _ = solver
64 .add_constraint(constraints::all_different(variables.clone(), c1_tag))
65 .post();
66
67 let diag1 = variables
68 .iter()
69 .cloned()
70 .enumerate()
71 .map(|(i, var)| var.offset(i as i32))
72 .collect::<Vec<_>>();
73 let diag2 = variables
74 .iter()
75 .cloned()
76 .enumerate()
77 .map(|(i, var)| var.offset(-(i as i32)))
78 .collect::<Vec<_>>();
79
80 let _ = solver
81 .add_constraint(constraints::all_different(diag1, c2_tag))
82 .post();
83 let _ = solver
84 .add_constraint(constraints::all_different(diag2, c3_tag))
85 .post();
86
87 let mut brancher = solver.default_brancher();
88 match solver.satisfy(&mut brancher, &mut Indefinite) {
89 SatisfactionResult::Satisfiable(satisfiable) => {
90 let solution = satisfiable.solution();
91
92 let row_separator = format!("{}+", "+---".repeat(n as usize));
93
94 for row in 0..n {
95 println!("{row_separator}");
96
97 let queen_col = solution.get_integer_value(variables[row as usize]) as u32;
98
99 for col in 0..n {
100 let string = if queen_col == col { "| * " } else { "| " };
101
102 print!("{string}");
103 }
104
105 println!("|");
106 }
107
108 println!("{row_separator}");
109 }
110 SatisfactionResult::Unsatisfiable(_, _) => {
111 println!("{n}-queens is unsatisfiable.");
112 }
113 SatisfactionResult::Unknown(_, _) => {
114 println!("Timeout.");
115 }
116 };
117}Trait Implementations§
Auto Trait Implementations§
impl Freeze for ProofLog
impl RefUnwindSafe for ProofLog
impl Send for ProofLog
impl Sync for ProofLog
impl Unpin for ProofLog
impl UnwindSafe for ProofLog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more