pub struct CaDiCal { /* private fields */ }Expand description
A CaDiCaL solver.
Methods that take a literal panic if it is 0 or i32::MIN (except
CaDiCal::add and CaDiCal::constrain, where 0 ends the clause), and
methods with a state precondition panic when it does not hold. CaDiCaL
itself would abort the whole process in both cases.
With the factor option (off by default), or factorcheck set to 2,
clauses may only use variables declared with
CaDiCal::declare_more_variables (or CaDiCal::resize); adding others
panics. One case is not checked: with factor the solver adds extension
variables of its own, and passing one of those to a method that takes a
literal still aborts.
CaDiCaL’s own checking options, e.g. checkfrozen (which makes reusing
a variable that was not frozen across solve calls fatal), abort the
process when their check fails; that is what they are for.
CaDiCaL reads options from CADICAL_<OPTION> environment variables. The
debugging variable CADICAL_LIDRUP_TRACE makes every solver write a proof
to the given file, and CaDiCaL aborts the process when a second solver
is created while it is set.
Implementations§
Source§impl CaDiCal
impl CaDiCal
pub fn new() -> Self
Sourcepub fn add(&mut self, lit: i32)
pub fn add(&mut self, lit: i32)
Core functionality as in the IPASIR incremental SAT solver interface.
(recall ‘READY = CONFIGURING | STEADY | SATISFIED | UNSATISFIED | INCONCLUSIVE’).
Further note that ‘lit’ is required to be different from ‘INT_MIN’ and
different from ‘0’ except for ‘add’.
Add valid literal to clause or zero to terminate clause.
require (VALID) recall ‘VALID = READY | ADDING’
if (lit) ensure (ADDING) and thus VALID but not READY
if (!lit) ensure (STEADY ) and thus READY
Sourcepub fn clause1(&mut self, l1: i32)
pub fn clause1(&mut self, l1: i32)
Here are functions simplifying clause addition. The given literals
should all be valid (different from ‘INT_MIN’ and different from ‘0’).
require (VALID) ensure (STEADY )
pub fn clause2(&mut self, l1: i32, l2: i32)
pub fn clause3(&mut self, l1: i32, l2: i32, l3: i32)
pub fn clause4(&mut self, l1: i32, l2: i32, l3: i32, l4: i32)
pub fn clause5(&mut self, l1: i32, l2: i32, l3: i32, l4: i32, l5: i32)
pub fn clause6(&mut self, v: &[i32])
Sourcepub fn inconsistent(&mut self) -> bool
pub fn inconsistent(&mut self) -> bool
This function can be used to check if the formula is already inconsistent (contains the empty clause or was proven to be root-level unsatisfiable).
Sourcepub fn assume(&mut self, lit: i32)
pub fn assume(&mut self, lit: i32)
Assume valid non zero literal for next call to ‘solve’. These assumptions are reset after the call to ‘solve’ as well as after returning from ‘simplify’ and ’lookahead.
require (READY) ensure (STEADY )
Sourcepub fn solve(&mut self) -> Status
pub fn solve(&mut self) -> Status
Try to solve the current formula. Returns
0 = UNKNOWN (limit reached or interrupted through ‘terminate’) 10 = SATISFIABLE 20 = UNSATISFIABLE
require (READY) ensure (INCONCLUSIVE | SATISFIED | UNSATISFIED)
Note, that while in this call the solver actually transitions to state ‘SOLVING’, which however is only visible from a different context, i.e., from a different thread or from a signal handler. Only right before returning from this call it goes into a ‘READY’ state.
§Panics
If the solver is in the middle of adding a clause or constraint (not READY). CaDiCaL would otherwise abort the process.
Sourcepub fn val(&mut self, lit: i32) -> i32
pub fn val(&mut self, lit: i32) -> i32
Get value (-lit=false, lit=true) of valid non-zero literal.
require (SATISFIED) ensure (SATISFIED)
§Panics
If the solver is not in the SATISFIED state or lit is not a valid
literal (zero or i32::MIN). CaDiCaL would otherwise abort the process.
Sourcepub fn flip(&mut self, lit: i32) -> bool
pub fn flip(&mut self, lit: i32) -> bool
Try to flip the value of the given literal without falsifying the formula. Returns ‘true’ if this was successful. Otherwise the model is not changed and ‘false’ is returned. If a literal was eliminated or substituted flipping will fail on that literal and in particular the solver will not taint it nor restore any clauses.
The ‘flip’ function can only flip the value of a variables not acting as witness on the reconstruction stack.
As a side effect of calling this function first all assigned variables are propagated again without using blocking literal. Thus the first call to this function after obtaining a model adds a substantial overhead. Subsequent calls will not need to properly propagate again.
Furthermore if the reconstruction stack is non-empty and has been traversed to reconstruct a full extended model for eliminated variables (and to satisfy removed blocked clauses), the values of these witness variables obtained via ‘val’ before become invalid. The user thus will need to call ‘val’ again after calling ‘flip’ which will trigger then a traversal of the reconstruction stack.
So try to avoid mixing ‘flip’ and ‘val’ (for efficiency only). Further, this functionality is currently not supported in the presence of an external propagator.
require (SATISFIED) ensure (SATISFIED)
§Panics
If the solver is not in the SATISFIED state, lit is not a valid
literal, or an external propagator is connected. CaDiCaL would
otherwise abort the process.
Sourcepub fn flippable(&mut self, lit: i32) -> bool
pub fn flippable(&mut self, lit: i32) -> bool
Same as ‘flip’ without actually flipping it. This functionality is currently not supported in the presence of an external propagator.
require (SATISFIED) ensure (SATISFIED)
§Panics
If the solver is not in the SATISFIED state, lit is not a valid
literal, or an external propagator is connected. CaDiCaL would
otherwise abort the process.
Sourcepub fn failed(&mut self, lit: i32) -> bool
pub fn failed(&mut self, lit: i32) -> bool
Determine whether the valid non-zero literal is in the core. Returns ‘true’ if the literal is in the core and ‘false’ otherwise. Note that the core does not have to be minimal.
require (UNSATISFIED) ensure (UNSATISFIED)
§Panics
If the solver is not in the UNSATISFIED state or lit is not a valid
literal (zero or i32::MIN). CaDiCaL would otherwise abort the process.
Sourcepub fn connect_terminator<T: Terminator + 'static>(&mut self, terminator: T)
pub fn connect_terminator<T: Terminator + 'static>(&mut self, terminator: T)
Add call-back which is checked regularly for termination. There can only be one terminator connected. If a second (non-zero) one is added the first one is implicitly disconnected.
require (VALID) ensure (VALID)
The solver takes ownership of terminator and drops it when it is
disconnected, replaced, or the solver is dropped. To read its state
afterwards, pass an Rc<RefCell<_>> and keep a clone of the Rc.
The callback must be 'static, so it cannot borrow from a value that
might be dropped while the solver still calls it:
let mut solver = CaDiCal::new();
let mut calls = 0;
solver.connect_terminator(Cb(&mut calls)); // error: `calls` does not live long enoughpub fn disconnect_terminator(&mut self)
Sourcepub fn connect_learner<T: Learner + 'static>(&mut self, learner: T)
pub fn connect_learner<T: Learner + 'static>(&mut self, learner: T)
Add call-back which allows to export learned clauses.
require (VALID) ensure (VALID)
The solver takes ownership of learner and drops it when it is
disconnected, replaced, or the solver is dropped. To read its state
afterwards, pass an Rc<RefCell<_>> and keep a clone of the Rc.
The callback must be 'static, so it cannot borrow from a value that
might be dropped while the solver still calls it:
let mut solver = CaDiCal::new();
let mut calls = 0;
solver.connect_learner(Cb(&mut calls)); // error: `calls` does not live long enoughpub fn disconnect_learner(&mut self)
Sourcepub fn connect_fixed_listener<F: FixedAssignmentListener + 'static>(
&mut self,
fixed_listener: F,
)
pub fn connect_fixed_listener<F: FixedAssignmentListener + 'static>( &mut self, fixed_listener: F, )
Add call-back which allows to observe when a variable is fixed.
require (VALID) ensure (VALID)
The solver takes ownership of fixed_listener and drops it when it is
disconnected, replaced, or the solver is dropped. To read its state
afterwards, pass an Rc<RefCell<_>> and keep a clone of the Rc.
The callback must be 'static, so it cannot borrow from a value that
might be dropped while the solver still calls it:
let mut solver = CaDiCal::new();
let mut calls = 0;
solver.connect_fixed_listener(Cb(&mut calls)); // error: `calls` does not live long enoughpub fn disconnect_fixed_listener(&mut self)
Sourcepub fn connect_external_propagator<T: ExternalPropagator + 'static>(
&mut self,
propagator: T,
)
pub fn connect_external_propagator<T: ExternalPropagator + 'static>( &mut self, propagator: T, )
Add call-back which allows to learn, propagate and backtrack based on
external constraints. Only one external propagator can be connected
and after connection every related variables must be ‘observed’ (use
‘add_observed_var’ function).
Disconnection of the external propagator resets all the observed
variables.
require (VALID) ensure (VALID)
The solver takes ownership of propagator and drops it when it is
disconnected, replaced, or the solver is dropped. To read its state
afterwards, pass an Rc<RefCell<_>> and keep a clone of the Rc.
Connecting a propagator disconnects any propagator connected earlier,
which also resets the observed variables.
pub fn disconnect_external_propagator(&mut self)
Sourcepub fn add_observed_var(&mut self, var: i32)
pub fn add_observed_var(&mut self, var: i32)
Mark as ‘observed’ those variables that are relevant to the external propagator. External propagation, clause addition during search and notifications are all over these observed variabes. A variable can not be observed witouth having an external propagator connected. Observed variables are “frozen” internally, and so inprocessing will not consider them as candidates for elimination. An observed variable is allowed to be a fresh variable and it can be added also during solving.
require (VALID_OR_SOLVING)
ensure (VALID_OR_SOLVING)
Observing a variable that preprocessing or inprocessing has already
eliminated is not checked and aborts the process. Observe variables
before solving, or CaDiCal::freeze them.
§Panics
If no external propagator is connected. CaDiCaL would otherwise
abort the process.
Sourcepub fn remove_observed_var(&mut self, var: i32)
pub fn remove_observed_var(&mut self, var: i32)
Removes the ‘observed’ flag from the given variable. A variable can be set unobserved only between solve calls, not during it (to guarantee that no yet unexplained external propagation involves it).
require (VALID) ensure (VALID)
§Panics
If no external propagator is connected. CaDiCaL would otherwise
abort the process.
Sourcepub fn reset_observed_vars(&mut self)
pub fn reset_observed_vars(&mut self)
Removes all the ‘observed’ flags from the variables. Disconnecting the propagator invokes this step as well.
require (VALID) ensure (VALID)
§Panics
If no external propagator is connected. CaDiCaL would otherwise
abort the process.
Sourcepub fn is_decision(&mut self, lit: i32) -> bool
pub fn is_decision(&mut self, lit: i32) -> bool
Get reason of valid observed literal (true = it is an observed variable and it got assigned by a decision during the CDCL loop. Otherwise: false.
require (VALID_OR_SOLVING)
ensure (VALID_OR_SOLVING)
Sourcepub fn constrain(&mut self, lit: i32)
pub fn constrain(&mut self, lit: i32)
Adds a literal to the constraint clause. Same functionality as ‘add’ but the clause only exists for the next call to solve (same lifetime as assumptions). Only one constraint may exists at a time. A new constraint replaces the old. The main application of this functonality is the model checking algorithm IC3. See our FMCAD’21 paper [FroleyksBiere-FMCAD’19] for more details.
Add valid literal to the constraint clause or zero to terminate it.
require (VALID) /// recall ‘VALID = READY |
ADDING’ if (lit) ensure (ADDING) /// and thus VALID but not
READY if (!lit) && !adding_clause ensure (STEADY ) // and thus READY
Sourcepub fn constraint_failed(&mut self) -> bool
pub fn constraint_failed(&mut self) -> bool
Determine whether the constraint was used to proof the unsatisfiability. Note that the formula might still be unsatisfiable without the constraint.
require (UNSATISFIED) ensure (UNSATISFIED)
§Panics
If the solver is not in the UNSATISFIED state. CaDiCaL would otherwise abort the process.
Sourcepub fn lookahead(&mut self) -> i32
pub fn lookahead(&mut self) -> i32
This function determines a good splitting literal. The result can be zero if the formula is proven to be satisfiable or unsatisfiable. This can then be checked by ‘state ()’. If the formula is empty and the function is not able to determine satisfiability also zero is returned but the state remains steady.
require (READY) ensure (STEADY |SATISFIED|UNSATISFIED)
§Panics
If the solver is in the middle of adding a clause or constraint (not
READY), which CaDiCaL would silently cut short.
Sourcepub fn generate_cubes(
&mut self,
x: i32,
min_depth: i32,
result_cubes: &mut Vec<i32>,
) -> i32
pub fn generate_cubes( &mut self, x: i32, min_depth: i32, result_cubes: &mut Vec<i32>, ) -> i32
Generate cubes for cube-and-conquer, up to the given depth.
Note: CaDiCaL 3.0.1 does not map the literals of the generated cubes
back to the user’s variable numbering (External::generate_cubes
discards the mapped values), so after preprocessing has renumbered
variables the cubes may refer to internal variables.
Sourcepub fn reset_assumptions(&mut self)
pub fn reset_assumptions(&mut self)
§Panics
If the solver is in the middle of adding a clause or constraint (not
READY), which CaDiCaL would silently cut short.
Sourcepub fn reset_constraint(&mut self)
pub fn reset_constraint(&mut self)
§Panics
If the solver is in the middle of adding a clause or constraint (not
READY), which CaDiCaL would silently cut short.
Sourcepub fn status(&self) -> Status
pub fn status(&self) -> Status
Similar to ‘state ()’ but using the staddard competition exit codes of ‘10’ for ‘SATISFIABLE’, ‘20’ for ‘UNSATISFIABLE’ and ‘0’ otherwise.
Sourcepub fn signature() -> String
pub fn signature() -> String
return the name and version of the incremental SAT solving library
Sourcepub fn copy(source: &CaDiCal, destination: &mut CaDiCal)
pub fn copy(source: &CaDiCal, destination: &mut CaDiCal)
Copy ‘this’ into a fresh ‘other’. The copy procedure is not a deep clone, but only copies irredundant clauses and units. It also makes sure that witness reconstruction works with the copy as with the original formula such that both solvers have the same models. Assumptions are not copied. Options however are copied as well as flags which remember the current state of variables in preprocessing.
require (READY) /// for ‘this’ ensure (READY) /// for ‘this’
other.require (CONFIGURING) other.ensure (CONFIGURING | STEADY )
A pending constraint (see CaDiCal::constrain) is copied as an
ordinary, permanent clause.
§Panics
If source is not READY (e.g. a clause was started with
CaDiCal::add but not terminated), if destination is not in the
CONFIGURING state, or if source has clauses (including frozen units)
and the factor or factorcheck options of either solver require
declared variables (the copy would add them before declaring any).
CaDiCaL would otherwise abort the process.
Sourcepub fn vars(&mut self) -> i32
pub fn vars(&mut self) -> i32
Variables are usually added and initialized implicitly whenever a literal is used as an argument except for the functions ‘val’, ‘fixed’, ‘failed’ and ‘frozen’. However, the library internally keeps a maximum variable index, which can be queried.
require (VALID | SOLVING) ensure (VALID | SOLVING)
Sourcepub fn resize(&mut self, min_max_var: i32)
pub fn resize(&mut self, min_max_var: i32)
Increase the maximum variable index explicitly. This function makes
sure that at least ‘min_max_var’ variables are initialized. Since it
might need to reallocate tables, it destroys a satisfying assignment
and has the same state transition and conditions as ‘assume’ etc.
require (READY) ensure (STEADY )
§Panics
If the solver is in the middle of adding a clause or constraint (not
READY), which CaDiCaL would silently cut short.
Sourcepub fn declare_more_variables(
&mut self,
number_of_additional_new_vars: i32,
) -> i32
pub fn declare_more_variables( &mut self, number_of_additional_new_vars: i32, ) -> i32
Increase the maximum variable index by a number of new variables.
initializes ‘number_of_additional_new_vars’ new variables and protects
them from being used by the solver as extension variables (BVA).
It returns the new maximum variable index which is the highest variable name of the consecutive range of newly declared variables. It has the same state transition and conditions as ‘resize’ above.
require (READY) ensure (STEADY)
§Panics
If the solver is in the middle of adding a clause or constraint (not
READY), which CaDiCaL would silently cut short, or if
number_of_additional_new_vars is negative or would overflow the
variable index.
Sourcepub fn declare_one_more_variable(&mut self) -> i32
pub fn declare_one_more_variable(&mut self) -> i32
Returns the next fresh variable that was not used internally.
§Panics
If the solver is in the middle of adding a clause or constraint (not
READY), which CaDiCaL would silently cut short.
Sourcepub fn get_statistic_value(&self, name: &str) -> i64
pub fn get_statistic_value(&self, name: &str) -> i64
Get the value of some statistics or -1 if the statistics does not exist or is not supported. Only requires the state to be initialized.
Sourcepub fn reserve(&mut self, min_max_var: i32)
👎Deprecated since 0.8.0: renamed to resize in CaDiCaL 3
pub fn reserve(&mut self, min_max_var: i32)
renamed to resize in CaDiCaL 3
Renamed to CaDiCal::resize in CaDiCaL 3.
Sourcepub fn is_valid_option(name: &str) -> bool
pub fn is_valid_option(name: &str) -> bool
Option handling. Determine whether ‘name’ is a valid option name.
Sourcepub fn is_preprocessing_option(name: &str) -> bool
pub fn is_preprocessing_option(name: &str) -> bool
Determine whether ‘name’ enables a specific preprocessing technique.
Sourcepub fn is_valid_long_option(arg: &str) -> bool
pub fn is_valid_long_option(arg: &str) -> bool
Determine whether ‘arg’ is a valid long option of the form --<name>,
--<name>=<val> or --no-<name> similar to ‘set_long_option’ below.
Legal values are ‘true’, ‘false’, or [-]<mantissa>[e<exponent>].
Sourcepub fn get(&mut self, name: &str) -> i32
pub fn get(&mut self, name: &str) -> i32
Get the current value of the option ‘name’. If ‘name’ is invalid then zero is returned. Here ‘–…’ arguments as invalid options.
Sourcepub fn prefix(&mut self, verbose_message_prefix: &str)
pub fn prefix(&mut self, verbose_message_prefix: &str)
Set the default verbose message prefix (default “c “).
Sourcepub fn set(&mut self, name: &str, val: i32) -> bool
pub fn set(&mut self, name: &str, val: i32) -> bool
This crate builds CaDiCaL with QUIET, which removes the options
quiet, verbose, report and log; setting them returns false.
Explicit version of setting an option. If the option <name> exists
and <val> can be parsed then ‘true’ is returned. If the option value
is out of range the actual value is computed as the closest (minimum or
maximum) value possible, but still ‘true’ is returned.
require (CONFIGURING) ensure (CONFIGURING)
Thus options can only bet set right after initialization.
§Panics
If the solver is not in the CONFIGURING state, unless name is one of
log, quiet, report and verbose. CaDiCaL would otherwise abort the process.
Sourcepub fn set_long_option(&mut self, arg: &str) -> bool
pub fn set_long_option(&mut self, arg: &str) -> bool
This function accepts options in command line syntax:
--<name>=<val>, --<name>, or --no-<name>
It actually calls the previous ‘set’ function after parsing ‘arg’. The
same values are expected as for ‘is_valid_long_option’ above and as
with ‘set’ any value outside of the range of legal values for a
particular option are set to either the minimum or maximum depending on
which side of the valid interval they lie.
require (CONFIGURING) ensure (CONFIGURING)
§Panics
If the solver is not in the CONFIGURING state. CaDiCaL would otherwise abort the process.
Sourcepub fn is_valid_configuration(name: &str) -> bool
pub fn is_valid_configuration(name: &str) -> bool
Determine whether ‘name’ is a valid configuration.
Sourcepub fn configure(&mut self, name: &str) -> bool
pub fn configure(&mut self, name: &str) -> bool
Overwrite (some) options with the forced values of the configuration. The result is ‘true’ iff the ‘name’ is a valid configuration.
require (CONFIGURING) ensure (CONFIGURING)
§Panics
If the solver is not in the CONFIGURING state. CaDiCaL would otherwise abort the process.
Sourcepub fn optimize(&mut self, val: i32)
pub fn optimize(&mut self, val: i32)
Increase preprocessing and inprocessing limits: each limit marked as
optimizable is multiplied by 2^<val> or 10^<val> (depending on the
option) and capped at its maximum. Values below ‘0’ are ignored and
values above ‘31’ are reduced to ‘31’.
require (READY) ensure (READY)
Sourcepub fn limit(&mut self, arg: &str, val: i32) -> bool
pub fn limit(&mut self, arg: &str, val: i32) -> bool
Specify search limits, where currently ‘name’ can be “conflicts”, “decisions”, “preprocessing”, or “localsearch”. The first two limits are unbounded by default. Thus using a negative limit for conflicts or decisions switches back to the default of unlimited search (for that particular limit). The preprocessing limit determines the number of preprocessing rounds, which is zero by default. Similarly, the local search limit determines the number of local search rounds (also zero by default). As with ‘set’, the return value denotes whether the limit ‘name’ is valid. These limits are only valid for the next ‘solve’ or ‘simplify’ call and reset to their default after ‘solve’ returns (as well as overwritten and reset during calls to ‘simplify’ and ‘lookahead’). We actually also have an internal “terminate” limit which however should only be used for testing and debugging.
require (READY) ensure (READY)
pub fn is_valid_limit(&mut self, arg: &str) -> bool
Sourcepub fn active(&self) -> i32
pub fn active(&self) -> i32
The number of currently active variables and clauses can be queried by these functions. Variables become active if a clause is added with it. They become inactive if they are eliminated or fixed at the root level Clauses become inactive if they are satisfied, subsumed, eliminated. Redundant clauses are reduced regularly and thus the ‘redundant’ function is less useful.
require (VALID) ensure (VALID)
Number of active variables.
Sourcepub fn irredundant(&self) -> i64
pub fn irredundant(&self) -> i64
Number of active irredundant clauses.
Sourcepub fn simplify(&mut self, rounds: i32) -> Status
pub fn simplify(&mut self, rounds: i32) -> Status
This function executes the given number of preprocessing rounds. It is similar to ‘solve’ with ‘limits (“preprocessing”, rounds)’ except that no CDCL nor local search, nor lucky phases are executed. The result values are also the same: 0=UNKNOWN, 10=SATISFIABLE, 20=UNSATISFIABLE. As ‘solve’ it resets current assumptions and limits before returning. The numbers of rounds should not be negative. If the number of rounds is zero only clauses are restored (if necessary) and top level unit propagation is performed, which both take some time.
require (READY) ensure (INCONCLUSIVE | SATISFIED | UNSATISFIED)
§Panics
If the solver is in the middle of adding a clause or constraint (not READY),
or if rounds is negative. CaDiCaL would otherwise abort the process.
Sourcepub fn propagate(&mut self) -> Status
pub fn propagate(&mut self) -> Status
This function executes the given number of preprocessing rounds
without search: it only performs unit propagation by assuming the
currently defined (potentially empty) set of assumptions. In case unit
propagation leads to a conflict it returns UNSATISFIABLE. Otherwise
it usually returns UNKNOWN, and the implied literals can be queried
with CaDiCal::implied. In rare cases (no decision needed) it
returns SATISFIABLE.
require (READY) ensure (INCONCLUSIVE | SATISFIED | UNSATISFIED)
§Panics
If the solver is in the middle of adding a clause or constraint (not
READY), which CaDiCaL would silently cut short.
Sourcepub fn implied(&mut self) -> Vec<i32>
pub fn implied(&mut self) -> Vec<i32>
The literals implied by the last call to CaDiCal::propagate.
require (INCONCLUSIVE | SATISFIED) ensure (INCONCLUSIVE | SATISFIED)
§Panics
If the solver is not in the INCONCLUSIVE or SATISFIED state.
CaDiCaL would otherwise abort the process.
Sourcepub fn terminate(&mut self)
pub fn terminate(&mut self)
Force termination of ‘solve’ asynchronously.
Since solve borrows the solver mutably, this can only be called
between solve calls, where it makes the next solve return
Status::UNKNOWN (unless the formula is trivially decided, e.g.
already inconsistent). To stop a running solve from another thread,
connect a TerminateFlag instead.
require (SOLVING | READY) ensure (STEADY ) /// actually not immediately (synchronously)
Sourcepub fn frozen(&self, lit: i32) -> bool
pub fn frozen(&self, lit: i32) -> bool
We have the following common reference counting functions, which avoid
to restore clauses but require substantial user guidance. This was the
only way to use inprocessing in incremental SAT solving in Lingeling
(and before in MiniSAT’s ‘freeze’ / ‘thaw’) and which did not use
automatic clause restoring. In general this is slower than
restoring clauses and should not be used.
In essence the user freezes variables which potentially are still needed in clauses added or assumptions used after the next ‘solve’ call. As in Lingeling you can freeze a variable multiple times, but then have to melt it the same number of times again in order to enable variable eliminating on it etc. The arguments can be literals (negative indices) but conceptually variables are frozen.
In the old way of doing things without restore you should not use a variable incrementally (in ‘add’ or ‘assume’), which was used before and potentially could have been eliminated in a previous ‘solve’ call. This can lead to spurious satisfying assignment. In order to check this API contract one can use the ‘checkfrozen’ option. This has the drawback that restoring clauses implicitly would fail with a fatal error message even if in principle the solver could just restore clauses. Thus this option is disabled by default.
See our SAT’19 paper [FazekasBiereScholl-SAT’19] for more details.
require (VALID) ensure (VALID)
pub fn freeze(&mut self, lit: i32)
Sourcepub fn melt(&mut self, lit: i32)
pub fn melt(&mut self, lit: i32)
Undo one CaDiCal::freeze of lit.
§Panics
If lit is not frozen. CaDiCaL would otherwise abort the process.
Sourcepub fn fixed(&self, lit: i32) -> i32
pub fn fixed(&self, lit: i32) -> i32
Root level assigned variables can be queried with this function. It returns ‘1’ if the literal is implied by the formula, ‘-1’ if its negation is implied, or ‘0’ if this is unclear at this point.
require (VALID) ensure (VALID)
Sourcepub fn phase(&mut self, lit: i32)
pub fn phase(&mut self, lit: i32)
Force the default decision phase of a variable to a certain value.
pub fn unphase(&mut self, lit: i32)
Sourcepub fn trace_proof1(&mut self, file: &str, name: &str) -> bool
pub fn trace_proof1(&mut self, file: &str, name: &str) -> bool
Enables clausal proof tracing in DRAT format and returns ‘true’ if successfully opened for writing. Writing proofs has to be enabled before calling ‘solve’, ‘add’ and ‘dimacs’, that is in state ‘CONFIGURING’. Otherwise only partial proofs would be written.
require (CONFIGURING) ensure (CONFIGURING)
Write DRAT proof. name is ignored. As with CaDiCal::trace_proof2,
a .gz, .bz2, .xz or .7z suffix compresses the proof through
the external program of that name, and false is returned if it is
not in PATH.
§Panics
If the solver is not in the CONFIGURING state, or a proof file was
already closed with CaDiCal::close_proof_trace. CaDiCaL would
otherwise abort or crash.
Sourcepub fn trace_proof2(&mut self, path: &str) -> bool
pub fn trace_proof2(&mut self, path: &str) -> bool
Open & write proof. A .gz, .bz2, .xz or .7z suffix compresses
the proof through the external program of that name; false is
returned if it is not in PATH or the file cannot be written.
§Panics
If the solver is not in the CONFIGURING state, or a proof file was
already closed with CaDiCal::close_proof_trace. CaDiCaL would
otherwise abort or crash.
Sourcepub fn flush_proof_trace(&mut self, print: bool)
pub fn flush_proof_trace(&mut self, print: bool)
Flushing the proof trace file eventually calls ‘fflush’ on the actual file or pipe and thus if this function returns all the proof steps should have been written (with the same guarantees as ‘fflush’).
The additional optional argument forces to print the number of addition and deletion steps in the proof even if the verbosity level is zero but not if quiet is set as well. The default for the stand-alone solver is to print this information (in the ‘closing proof’ section) but for API usage of the library we want to stay silent unless explicitly requested or verbosity is non-zero (and as explained quiet is not set).
This function can be called multiple times.
require (VALID) ensure (VALID)
§Panics
If no proof file is open (see CaDiCal::trace_proof2). CaDiCaL
would otherwise abort the process.
Sourcepub fn close_proof_trace(&mut self, print: bool)
pub fn close_proof_trace(&mut self, print: bool)
Close proof trace early. Similar to ‘flush’ we allow the user to
control with ‘print’ in a more fine-grained way whether statistics
about the size of the written proof file and if compressed on-the-fly
the number of actual bytes written (including deflation percentage) are
printed. Before actually closing (or detaching in case of writing to
<stdout>) we check whether ‘flush_proof_trace’ was called since the
last time a proof step (addition or deletion) was traced. If this is
not the case we would call ‘flush_proof_trace’ with the same ‘print’
argument.
require (VALID) ensure (VALID)
§Panics
If no proof file is open, including when it was already closed.
CaDiCaL would otherwise abort the process.
Sourcepub fn connect_proof_tracer1<T: ProofTracer + 'static>(
&mut self,
tracer: T,
antecedents: bool,
finalize_clauses: bool,
)
pub fn connect_proof_tracer1<T: ProofTracer + 'static>( &mut self, tracer: T, antecedents: bool, finalize_clauses: bool, )
Enables clausal proof tracing with or without antecedents using the Tracer interface defined in ‘tracer.hpp’.
CaDiCaL’s built-in FileTracer and StatTracer are not exposed
directly; use CaDiCal::trace_proof1 or CaDiCal::trace_proof2
to write a proof file.
require (CONFIGURING) ensure (CONFIGURING)
The solver takes ownership of tracer and drops it when it is
disconnected, replaced, or the solver is dropped. To read its state
afterwards, pass an Rc<RefCell<_>> and keep a clone of the Rc.
Connecting a tracer disconnects any tracer connected earlier.
ProofTracer::finalize_clause is only called when finalize_clauses
is true.
§Panics
If the solver is not in the CONFIGURING state, i.e. clauses have
already been added. CaDiCaL would otherwise abort the process.
Sourcepub fn conclude(&mut self)
pub fn conclude(&mut self)
Triggers the conclusion of incremental proofs.
if the solver is SATISFIED it will trigger extend ()
and give the model to the proof tracer through conclude_sat ()
if the solver is UNSATISFIED it will trigger failing ()
which will learn new clauses as explained below:
In case of failed assumptions will provide a core negated
as a clause through the proof tracer interface.
With a failing contraint these can be multiple clauses.
Then it will trigger a conclude_unsat event with the id(s)
of the newly learnt clauses or the id of the global conflict.
require (SATISFIED || UNSATISFIED) ensure (SATISFIED || UNSATISFIED)
§Panics
If the solver has not finished a solve (it is not SATISFIED,
UNSATISFIED or INCONCLUSIVE). CaDiCaL would otherwise abort the process.
Sourcepub fn disconnect_proof_tracer1(&mut self)
pub fn disconnect_proof_tracer1(&mut self)
Disconnect the proof tracer connected with
CaDiCal::connect_proof_tracer1 and drop it. Does nothing if no
tracer is connected.
require (VALID) ensure (VALID)
Sourcepub fn configurations()
pub fn configurations()
print configuration usage options
Sourcepub fn statistics(&mut self)
pub fn statistics(&mut self)
require (!DELETING) ensure (!DELETING)
print statistics
This crate builds CaDiCaL with QUIET, so this prints nothing.
Sourcepub fn resources(&mut self)
pub fn resources(&mut self)
print resource usage (time and memory)
This crate builds CaDiCaL with QUIET, so this prints nothing.
Sourcepub fn options(&mut self)
pub fn options(&mut self)
require (VALID) ensure (VALID)
print current option and value list
This crate builds CaDiCaL with QUIET, so this prints nothing.
Sourcepub fn traverse_clauses<I: ClauseIterator>(&self, i: &mut I) -> bool
pub fn traverse_clauses<I: ClauseIterator>(&self, i: &mut I) -> bool
Traverse irredundant clauses or the extension stack in reverse order.
The return value is false if traversal is aborted early due to one of the visitor functions returning false. See description of the iterators below for more details on how to use these functions.
require (VALID) ensure (VALID)
pub fn traverse_witnesses_backward<I: WitnessIterator>(&self, i: &mut I) -> bool
pub fn traverse_witnesses_forward<I: WitnessIterator>(&self, i: &mut I) -> bool
Sourcepub fn read_dimacs1(
&mut self,
file: &str,
name: &str,
vars: &mut i32,
strict: i32,
) -> Result<(), String>
pub fn read_dimacs1( &mut self, file: &str, name: &str, vars: &mut i32, strict: i32, ) -> Result<(), String>
Files with explicit path argument support compressed input and output if appropriate helper functions ‘gzip’ etc. are available. They are called through opening a pipe to an external command.
If the ‘strict’ argument is zero then the number of variables and clauses specified in the DIMACS headers are ignored, i.e., the header ‘p cnf 0 0’ is always legal. If the ‘strict’ argument is larger ‘1’ strict formatting of the header is required, i.e., single spaces everywhere and no trailing white space.
Returns Err with CaDiCaL’s error message if unsuccessful.
require (VALID) ensure (VALID)
§Errors
If the file cannot be opened or parsed.
§Panics
If the solver is not in the CONFIGURING state, i.e. clauses have
already been added. CaDiCaL would otherwise abort the process.
Sourcepub fn read_dimacs2(
&mut self,
path: &str,
vars: &mut i32,
strict: i32,
) -> Result<(), String>
pub fn read_dimacs2( &mut self, path: &str, vars: &mut i32, strict: i32, ) -> Result<(), String>
Sourcepub fn read_dimacs3(
&mut self,
file: &str,
name: &str,
vars: &mut i32,
strict: i32,
incremental: &mut bool,
cubes: &mut Vec<i32>,
) -> Result<(), String>
pub fn read_dimacs3( &mut self, file: &str, name: &str, vars: &mut i32, strict: i32, incremental: &mut bool, cubes: &mut Vec<i32>, ) -> Result<(), String>
The following routines work the same way but parse both DIMACS and
INCCNF files (with ‘p inccnf’ header and a <cube> lines). If the
parser finds and ‘p inccnf’ header or cubes then ‘*incremental’ is set
to true and the cubes are stored in the given vector (each cube
terminated by a zero).
§Errors
If the file cannot be opened or parsed.
§Panics
If the solver is not in the CONFIGURING state, i.e. clauses have
already been added. CaDiCaL would otherwise abort the process.
Sourcepub fn read_dimacs4(
&mut self,
path: &str,
vars: &mut i32,
strict: i32,
incremental: &mut bool,
cubes: &mut Vec<i32>,
) -> Result<(), String>
pub fn read_dimacs4( &mut self, path: &str, vars: &mut i32, strict: i32, incremental: &mut bool, cubes: &mut Vec<i32>, ) -> Result<(), String>
Sourcepub fn write_dimacs(
&mut self,
path: &str,
min_max_var: i32,
) -> Result<(), String>
pub fn write_dimacs( &mut self, path: &str, min_max_var: i32, ) -> Result<(), String>
Write current irredundant clauses and all derived unit clauses to a file in DIMACS format. Clauses on the extension stack are not included, nor any redundant clauses.
The ‘min_max_var’ parameter gives a lower bound on the number <vars>
of variables used in the DIMACS p cnf <vars> ... header.
Returns Err with CaDiCaL’s error message if unsuccessful.
require (VALID) ensure (VALID)
§Errors
If the file cannot be written.
Trait Implementations§
Source§impl Clone for CaDiCal
Cloning copies the formula and options (see CaDiCal::copy) but not any
connected callbacks; the clone starts with none connected. Like copy, it
panics if the solver is not READY, e.g. in the middle of adding a clause.
impl Clone for CaDiCal
Cloning copies the formula and options (see CaDiCal::copy) but not any
connected callbacks; the clone starts with none connected. Like copy, it
panics if the solver is not READY, e.g. in the middle of adding a clause.