cadical 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +26 -0
- data/README.md +101 -0
- data/ext/cadical/cadical/LICENSE +28 -0
- data/ext/cadical/cadical/README.md +65 -0
- data/ext/cadical/cadical/VERSION +1 -0
- data/ext/cadical/cadical/src/analyze.cpp +1360 -0
- data/ext/cadical/cadical/src/arena.cpp +30 -0
- data/ext/cadical/cadical/src/arena.hpp +105 -0
- data/ext/cadical/cadical/src/assume.cpp +616 -0
- data/ext/cadical/cadical/src/averages.cpp +34 -0
- data/ext/cadical/cadical/src/averages.hpp +37 -0
- data/ext/cadical/cadical/src/backbone.cpp +631 -0
- data/ext/cadical/cadical/src/backtrack.cpp +177 -0
- data/ext/cadical/cadical/src/backward.cpp +231 -0
- data/ext/cadical/cadical/src/bins.cpp +22 -0
- data/ext/cadical/cadical/src/bins.hpp +22 -0
- data/ext/cadical/cadical/src/block.cpp +824 -0
- data/ext/cadical/cadical/src/block.hpp +37 -0
- data/ext/cadical/cadical/src/cadical.cpp +1026 -0
- data/ext/cadical/cadical/src/cadical.hpp +1419 -0
- data/ext/cadical/cadical/src/ccadical.cpp +208 -0
- data/ext/cadical/cadical/src/ccadical.h +74 -0
- data/ext/cadical/cadical/src/checker.cpp +649 -0
- data/ext/cadical/cadical/src/checker.hpp +173 -0
- data/ext/cadical/cadical/src/clause.cpp +689 -0
- data/ext/cadical/cadical/src/clause.hpp +190 -0
- data/ext/cadical/cadical/src/collect.cpp +545 -0
- data/ext/cadical/cadical/src/compact.cpp +550 -0
- data/ext/cadical/cadical/src/condition.cpp +940 -0
- data/ext/cadical/cadical/src/config.cpp +101 -0
- data/ext/cadical/cadical/src/config.hpp +20 -0
- data/ext/cadical/cadical/src/congruence.cpp +7880 -0
- data/ext/cadical/cadical/src/congruence.hpp +757 -0
- data/ext/cadical/cadical/src/constrain.cpp +64 -0
- data/ext/cadical/cadical/src/contract.cpp +27 -0
- data/ext/cadical/cadical/src/contract.hpp +139 -0
- data/ext/cadical/cadical/src/cover.cpp +704 -0
- data/ext/cadical/cadical/src/cover.hpp +34 -0
- data/ext/cadical/cadical/src/decide.cpp +347 -0
- data/ext/cadical/cadical/src/decompose.cpp +738 -0
- data/ext/cadical/cadical/src/decompose.hpp +23 -0
- data/ext/cadical/cadical/src/deduplicate.cpp +275 -0
- data/ext/cadical/cadical/src/definition.cpp +283 -0
- data/ext/cadical/cadical/src/delay.hpp +38 -0
- data/ext/cadical/cadical/src/drattracer.cpp +153 -0
- data/ext/cadical/cadical/src/drattracer.hpp +55 -0
- data/ext/cadical/cadical/src/elim.cpp +1171 -0
- data/ext/cadical/cadical/src/elim.hpp +53 -0
- data/ext/cadical/cadical/src/elimfast.cpp +570 -0
- data/ext/cadical/cadical/src/ema.cpp +95 -0
- data/ext/cadical/cadical/src/ema.hpp +68 -0
- data/ext/cadical/cadical/src/extend.cpp +289 -0
- data/ext/cadical/cadical/src/external.cpp +1034 -0
- data/ext/cadical/cadical/src/external.hpp +487 -0
- data/ext/cadical/cadical/src/external_propagate.cpp +1316 -0
- data/ext/cadical/cadical/src/factor.cpp +1011 -0
- data/ext/cadical/cadical/src/factor.hpp +54 -0
- data/ext/cadical/cadical/src/file.cpp +506 -0
- data/ext/cadical/cadical/src/file.hpp +210 -0
- data/ext/cadical/cadical/src/flags.cpp +135 -0
- data/ext/cadical/cadical/src/flags.hpp +93 -0
- data/ext/cadical/cadical/src/flip.cpp +269 -0
- data/ext/cadical/cadical/src/format.cpp +89 -0
- data/ext/cadical/cadical/src/format.hpp +36 -0
- data/ext/cadical/cadical/src/frattracer.cpp +277 -0
- data/ext/cadical/cadical/src/frattracer.hpp +67 -0
- data/ext/cadical/cadical/src/gates.cpp +766 -0
- data/ext/cadical/cadical/src/heap.hpp +212 -0
- data/ext/cadical/cadical/src/idruptracer.cpp +566 -0
- data/ext/cadical/cadical/src/idruptracer.hpp +112 -0
- data/ext/cadical/cadical/src/instantiate.cpp +365 -0
- data/ext/cadical/cadical/src/instantiate.hpp +45 -0
- data/ext/cadical/cadical/src/internal.cpp +1265 -0
- data/ext/cadical/cadical/src/internal.hpp +1941 -0
- data/ext/cadical/cadical/src/inttypes.hpp +34 -0
- data/ext/cadical/cadical/src/ipasir.cpp +47 -0
- data/ext/cadical/cadical/src/ipasir.h +37 -0
- data/ext/cadical/cadical/src/kitten.c +2599 -0
- data/ext/cadical/cadical/src/kitten.h +97 -0
- data/ext/cadical/cadical/src/level.hpp +33 -0
- data/ext/cadical/cadical/src/lidruptracer.cpp +657 -0
- data/ext/cadical/cadical/src/lidruptracer.hpp +122 -0
- data/ext/cadical/cadical/src/limit.cpp +146 -0
- data/ext/cadical/cadical/src/limit.hpp +168 -0
- data/ext/cadical/cadical/src/logging.cpp +214 -0
- data/ext/cadical/cadical/src/logging.hpp +98 -0
- data/ext/cadical/cadical/src/lookahead.cpp +520 -0
- data/ext/cadical/cadical/src/lratchecker.cpp +833 -0
- data/ext/cadical/cadical/src/lratchecker.hpp +168 -0
- data/ext/cadical/cadical/src/lrattracer.cpp +200 -0
- data/ext/cadical/cadical/src/lrattracer.hpp +61 -0
- data/ext/cadical/cadical/src/lucky.cpp +506 -0
- data/ext/cadical/cadical/src/message.cpp +218 -0
- data/ext/cadical/cadical/src/message.hpp +65 -0
- data/ext/cadical/cadical/src/minimize.cpp +224 -0
- data/ext/cadical/cadical/src/mobical.cpp +5588 -0
- data/ext/cadical/cadical/src/occs.cpp +52 -0
- data/ext/cadical/cadical/src/occs.hpp +36 -0
- data/ext/cadical/cadical/src/options.cpp +359 -0
- data/ext/cadical/cadical/src/options.hpp +442 -0
- data/ext/cadical/cadical/src/parse.cpp +471 -0
- data/ext/cadical/cadical/src/parse.hpp +75 -0
- data/ext/cadical/cadical/src/phases.cpp +56 -0
- data/ext/cadical/cadical/src/phases.hpp +19 -0
- data/ext/cadical/cadical/src/probe.cpp +990 -0
- data/ext/cadical/cadical/src/profile.cpp +107 -0
- data/ext/cadical/cadical/src/profile.hpp +283 -0
- data/ext/cadical/cadical/src/proof.cpp +691 -0
- data/ext/cadical/cadical/src/proof.hpp +125 -0
- data/ext/cadical/cadical/src/propagate.cpp +584 -0
- data/ext/cadical/cadical/src/queue.cpp +90 -0
- data/ext/cadical/cadical/src/queue.hpp +74 -0
- data/ext/cadical/cadical/src/radix.hpp +180 -0
- data/ext/cadical/cadical/src/random.cpp +207 -0
- data/ext/cadical/cadical/src/random.h +44 -0
- data/ext/cadical/cadical/src/random.hpp +98 -0
- data/ext/cadical/cadical/src/range.hpp +125 -0
- data/ext/cadical/cadical/src/reap.cpp +127 -0
- data/ext/cadical/cadical/src/reap.hpp +28 -0
- data/ext/cadical/cadical/src/reduce.cpp +278 -0
- data/ext/cadical/cadical/src/reluctant.hpp +82 -0
- data/ext/cadical/cadical/src/rephase.cpp +402 -0
- data/ext/cadical/cadical/src/report.cpp +313 -0
- data/ext/cadical/cadical/src/resources.cpp +160 -0
- data/ext/cadical/cadical/src/resources.hpp +16 -0
- data/ext/cadical/cadical/src/restart.cpp +178 -0
- data/ext/cadical/cadical/src/restore.cpp +267 -0
- data/ext/cadical/cadical/src/score.cpp +51 -0
- data/ext/cadical/cadical/src/score.hpp +16 -0
- data/ext/cadical/cadical/src/shrink.cpp +507 -0
- data/ext/cadical/cadical/src/signal.cpp +136 -0
- data/ext/cadical/cadical/src/signal.hpp +33 -0
- data/ext/cadical/cadical/src/solution.cpp +50 -0
- data/ext/cadical/cadical/src/solver.cpp +1871 -0
- data/ext/cadical/cadical/src/stable.cpp +31 -0
- data/ext/cadical/cadical/src/stack.h +110 -0
- data/ext/cadical/cadical/src/stats.cpp +920 -0
- data/ext/cadical/cadical/src/stats.hpp +418 -0
- data/ext/cadical/cadical/src/subsume.cpp +645 -0
- data/ext/cadical/cadical/src/sweep.cpp +1960 -0
- data/ext/cadical/cadical/src/sweep.hpp +61 -0
- data/ext/cadical/cadical/src/terminal.cpp +38 -0
- data/ext/cadical/cadical/src/terminal.hpp +96 -0
- data/ext/cadical/cadical/src/ternary.cpp +450 -0
- data/ext/cadical/cadical/src/testing.hpp +24 -0
- data/ext/cadical/cadical/src/tier.cpp +189 -0
- data/ext/cadical/cadical/src/tracer.hpp +186 -0
- data/ext/cadical/cadical/src/transred.cpp +253 -0
- data/ext/cadical/cadical/src/unstable.cpp +29 -0
- data/ext/cadical/cadical/src/util.cpp +129 -0
- data/ext/cadical/cadical/src/util.hpp +181 -0
- data/ext/cadical/cadical/src/var.cpp +39 -0
- data/ext/cadical/cadical/src/var.hpp +22 -0
- data/ext/cadical/cadical/src/veripbtracer.cpp +427 -0
- data/ext/cadical/cadical/src/veripbtracer.hpp +106 -0
- data/ext/cadical/cadical/src/version.cpp +107 -0
- data/ext/cadical/cadical/src/version.hpp +13 -0
- data/ext/cadical/cadical/src/vivify.cpp +1893 -0
- data/ext/cadical/cadical/src/vivify.hpp +50 -0
- data/ext/cadical/cadical/src/walk.cpp +1088 -0
- data/ext/cadical/cadical/src/walk.hpp +91 -0
- data/ext/cadical/cadical/src/walk_full_occs.cpp +966 -0
- data/ext/cadical/cadical/src/warmup.cpp +403 -0
- data/ext/cadical/cadical/src/watch.cpp +126 -0
- data/ext/cadical/cadical/src/watch.hpp +77 -0
- data/ext/cadical/cadical_ext.c +778 -0
- data/ext/cadical/extconf.rb +26 -0
- data/lib/cadical/version.rb +3 -0
- data/lib/cadical.rb +12 -0
- metadata +218 -0
|
@@ -0,0 +1,1419 @@
|
|
|
1
|
+
#ifndef _cadical_hpp_INCLUDED
|
|
2
|
+
#define _cadical_hpp_INCLUDED
|
|
3
|
+
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
#include <cstdio>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
/*========================================================================*/
|
|
9
|
+
|
|
10
|
+
// We support semantic versioning (https://semver.org/), which means that we
|
|
11
|
+
// aim at not breaking API usage when increasing the minor or patch version,
|
|
12
|
+
// but assume API breaking changes when increasing the major version.
|
|
13
|
+
|
|
14
|
+
#define CADICAL_MAJOR 3 // Major semantic version.
|
|
15
|
+
#define CADICAL_MINOR 0 // Minor semantic version.
|
|
16
|
+
#define CADICAL_PATCH 0 // Semantic patch version.
|
|
17
|
+
|
|
18
|
+
namespace CaDiCaL {
|
|
19
|
+
|
|
20
|
+
/*========================================================================*/
|
|
21
|
+
|
|
22
|
+
// This provides the actual API of the CaDiCaL solver, which is implemented
|
|
23
|
+
// in the class 'Solver' below. Beside its constructor and destructor most
|
|
24
|
+
// important is the IPASIR part which you can find between 'BEGIN IPASIR'
|
|
25
|
+
// and 'END IPASIR' comments below. The following '[Example]' below might
|
|
26
|
+
// also be a good starting point to understand the API.
|
|
27
|
+
|
|
28
|
+
/*========================================================================*/
|
|
29
|
+
|
|
30
|
+
// The SAT competition standardized the exit code of SAT solvers to the
|
|
31
|
+
// following which then is also used return code for 'solve' functions.
|
|
32
|
+
// In the following example we use those constants for brevity though.
|
|
33
|
+
|
|
34
|
+
enum Status {
|
|
35
|
+
SATISFIABLE = 10,
|
|
36
|
+
UNSATISFIABLE = 20,
|
|
37
|
+
UNKNOWN = 0,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/*========================================================================*/
|
|
41
|
+
|
|
42
|
+
// [Example]
|
|
43
|
+
//
|
|
44
|
+
// The internal solver state follows the IPASIR API model used in the
|
|
45
|
+
// incremental track of the SAT competition. State transitions are
|
|
46
|
+
// triggered by member function calls, declared and described below.
|
|
47
|
+
//
|
|
48
|
+
// Consider the following code (from 'test/api/example.cpp') of API usage:
|
|
49
|
+
//
|
|
50
|
+
// CaDiCaL::Solver * solver = new CaDiCaL::Solver;
|
|
51
|
+
//
|
|
52
|
+
// // ------------------------------------------------------------------
|
|
53
|
+
// // Encode Problem and check without assumptions.
|
|
54
|
+
//
|
|
55
|
+
// int TIE = declare_one_more_variable ();
|
|
56
|
+
// int SHIRT = declare_one_more_variable ();
|
|
57
|
+
// assert (vars () >= 2);
|
|
58
|
+
//
|
|
59
|
+
// solver->add (-TIE), solver->add (SHIRT), solver->add (0);
|
|
60
|
+
// solver->add (TIE), solver->add (SHIRT), solver->add (0);
|
|
61
|
+
// solver->add (-TIE), solver->add (-SHIRT), solver->add (0);
|
|
62
|
+
//
|
|
63
|
+
// int res = solver->solve (); // Solve instance.
|
|
64
|
+
// assert (res == 10); // Check it is 'SATISFIABLE'.
|
|
65
|
+
//
|
|
66
|
+
// res = solver->val (TIE); // Obtain assignment of 'TIE'.
|
|
67
|
+
// assert (res < 0); // Check 'TIE' assigned to 'false'.
|
|
68
|
+
//
|
|
69
|
+
// res = solver->val (SHIRT); // Obtain assignment of 'SHIRT'.
|
|
70
|
+
// assert (res > 0); // Check 'SHIRT' assigned to 'true'.
|
|
71
|
+
//
|
|
72
|
+
// // ------------------------------------------------------------------
|
|
73
|
+
// // Incrementally solve again under one assumption.
|
|
74
|
+
//
|
|
75
|
+
// solver->assume (TIE); // Now force 'TIE' to true.
|
|
76
|
+
//
|
|
77
|
+
// res = solver->solve (); // Solve again incrementally.
|
|
78
|
+
// assert (res == 20); // Check it is 'UNSATISFIABLE'.
|
|
79
|
+
//
|
|
80
|
+
// res = solver->failed (TIE); // Check 'TIE' responsible.
|
|
81
|
+
// assert (res); // Yes, 'TIE' in core.
|
|
82
|
+
//
|
|
83
|
+
// res = solver->failed (SHIRT); // Check 'SHIRT' responsible.
|
|
84
|
+
// assert (!res); // No, 'SHIRT' not in core.
|
|
85
|
+
//
|
|
86
|
+
// // ------------------------------------------------------------------
|
|
87
|
+
// // Incrementally solve once more under another assumption.
|
|
88
|
+
//
|
|
89
|
+
// solver->assume (-SHIRT); // Now force 'SHIRT' to false.
|
|
90
|
+
//
|
|
91
|
+
// res = solver->solve (); // Solve again incrementally.
|
|
92
|
+
// assert (res == 20); // Check it is 'UNSATISFIABLE'.
|
|
93
|
+
//
|
|
94
|
+
// res = solver->failed (TIE); // Check 'TIE' responsible.
|
|
95
|
+
// assert (!res); // No, 'TIE' not in core.
|
|
96
|
+
//
|
|
97
|
+
// res = solver->failed (-SHIRT); // Check '!SHIRT' responsible.
|
|
98
|
+
// assert (res); // Yes, '!SHIRT' in core.
|
|
99
|
+
//
|
|
100
|
+
// // ------------------------------------------------------------------
|
|
101
|
+
//
|
|
102
|
+
// delete solver;
|
|
103
|
+
|
|
104
|
+
/*========================================================================*/
|
|
105
|
+
|
|
106
|
+
// [States and Transitions]
|
|
107
|
+
//
|
|
108
|
+
// Compared to IPASIR we also use an 'ADDING' state in which the solver
|
|
109
|
+
// stays while adding non-zero literals until the clause is completed
|
|
110
|
+
// through adding a zero literal. The additional 'INITIALIZING',
|
|
111
|
+
// 'CONFIGURING' and 'DELETING' states are also not part of IPASIR but also
|
|
112
|
+
// useful for testing and debugging.
|
|
113
|
+
//
|
|
114
|
+
// We have the following transitions which are all synchronous except for
|
|
115
|
+
// the reentrant 'terminate' call:
|
|
116
|
+
//
|
|
117
|
+
// new
|
|
118
|
+
// INITIALIZING --------------------------> CONFIGURING
|
|
119
|
+
//
|
|
120
|
+
// set / trace
|
|
121
|
+
// CONFIGURING --------------------------> CONFIGURING
|
|
122
|
+
//
|
|
123
|
+
// add (non zero literal)
|
|
124
|
+
// VALID --------------------------> ADDING
|
|
125
|
+
//
|
|
126
|
+
// add (zero literal)
|
|
127
|
+
// VALID --------------------------> STEADY
|
|
128
|
+
//
|
|
129
|
+
// assume (non zero literal)
|
|
130
|
+
// READY --------------------------> STEADY
|
|
131
|
+
//
|
|
132
|
+
// solve
|
|
133
|
+
// READY --------------------------> SOLVING
|
|
134
|
+
//
|
|
135
|
+
// (internal)
|
|
136
|
+
// SOLVING --------------------------> SOLVED
|
|
137
|
+
//
|
|
138
|
+
// val (non zero literal)
|
|
139
|
+
// SATISFIED --------------------------> SATISFIED
|
|
140
|
+
//
|
|
141
|
+
// failed (non zero literal)
|
|
142
|
+
// UNSATISFIED --------------------------> UNSATISFIED
|
|
143
|
+
//
|
|
144
|
+
// implied (non zero literal)
|
|
145
|
+
// INCONCLUSIVE --------------------------> INCONCLUSIVE
|
|
146
|
+
//
|
|
147
|
+
// delete
|
|
148
|
+
// VALID --------------------------> DELETING
|
|
149
|
+
//
|
|
150
|
+
// where
|
|
151
|
+
//
|
|
152
|
+
// SOLVED = SATISFIED | UNSATISFIED | INCONCLUSIVE
|
|
153
|
+
// READY = CONFIGURING | STEADY | SOLVED
|
|
154
|
+
// VALID = READY | ADDING
|
|
155
|
+
// INVALID = INITIALIZING | DELETING
|
|
156
|
+
//
|
|
157
|
+
// The 'SOLVING' state is only visible in different contexts, i.e., from
|
|
158
|
+
// another thread or from a signal handler. It is used to implement
|
|
159
|
+
// 'terminate'. Here is the only asynchronous transition:
|
|
160
|
+
//
|
|
161
|
+
// terminate (asynchronously)
|
|
162
|
+
// SOLVING -------------------------> STEADY
|
|
163
|
+
//
|
|
164
|
+
// The important behaviour to remember is that adding, assuming or
|
|
165
|
+
// constraining a literal (immediately) destroys the satisfying assignment
|
|
166
|
+
// in the 'SATISFIED' state and vice versa resets all assumptions in the
|
|
167
|
+
// 'UNSATISFIED' state. This is exactly the behaviour required by the IPASIR
|
|
168
|
+
// interface.
|
|
169
|
+
//
|
|
170
|
+
// Furthermore, the model can only be queried through 'val' in the
|
|
171
|
+
// 'SATISFIED' state, while extracting failed assumptions with 'failed' only
|
|
172
|
+
// in the 'UNSATISFIED' state. Solving can only be started in the 'STEADY '
|
|
173
|
+
// or 'CONFIGURING' state or after the previous call to 'solve' yielded an
|
|
174
|
+
// 'INCONCLUSIVE , 'SATISFIED' or 'UNSATISFIED' state.
|
|
175
|
+
//
|
|
176
|
+
// All literals have to be valid literals too, i.e., 32-bit integers
|
|
177
|
+
// different from 'INT_MIN'. If any of these requirements is violated the
|
|
178
|
+
// solver aborts with an 'API contract violation' message.
|
|
179
|
+
//
|
|
180
|
+
// HINT: If you do not understand why a contract is violated you can run
|
|
181
|
+
// 'mobical' on the failing API call trace. Point the environment variable
|
|
182
|
+
// 'CADICAL_API_TRACE' to the file where you want to save the trace during
|
|
183
|
+
// execution of your program linking against the library. You probably need
|
|
184
|
+
// for 'mobical' to use the option '--do-not-enforce-contracts' though to
|
|
185
|
+
// force running into the same contract violation.
|
|
186
|
+
//
|
|
187
|
+
// Additional API calls (like 'freeze' and 'melt') do not change the state
|
|
188
|
+
// of the solver and are all described below.
|
|
189
|
+
|
|
190
|
+
/*========================================================================*/
|
|
191
|
+
|
|
192
|
+
// States are represented by a bit-set in order to combine them.
|
|
193
|
+
|
|
194
|
+
enum State {
|
|
195
|
+
INITIALIZING = 1, // during initialization (invalid)
|
|
196
|
+
CONFIGURING = 2, // configure options (with 'set')
|
|
197
|
+
STEADY = 4, // ready to call 'solve'
|
|
198
|
+
ADDING = 8, // adding clause literals (zero missing)
|
|
199
|
+
SOLVING = 16, // while solving (within 'solve')
|
|
200
|
+
SATISFIED = 32, // satisfiable allows 'val'
|
|
201
|
+
UNSATISFIED = 64, // unsatisfiable allows 'failed'
|
|
202
|
+
DELETING = 128, // during and after deletion (invalid)
|
|
203
|
+
INCONCLUSIVE = 256, // unknown allows 'implied'
|
|
204
|
+
|
|
205
|
+
// These combined states are used to check contracts.
|
|
206
|
+
|
|
207
|
+
READY = CONFIGURING | STEADY | SATISFIED | UNSATISFIED | INCONCLUSIVE,
|
|
208
|
+
VALID = READY | ADDING,
|
|
209
|
+
INVALID = INITIALIZING | DELETING
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/*------------------------------------------------------------------------*/
|
|
213
|
+
|
|
214
|
+
// Opaque classes needed in the API and declared in the same namespace.
|
|
215
|
+
|
|
216
|
+
class File;
|
|
217
|
+
class Testing;
|
|
218
|
+
struct Internal;
|
|
219
|
+
struct External;
|
|
220
|
+
|
|
221
|
+
/*------------------------------------------------------------------------*/
|
|
222
|
+
|
|
223
|
+
// Forward declaration of call-back classes. See bottom of this file.
|
|
224
|
+
|
|
225
|
+
class Learner;
|
|
226
|
+
class FixedAssignmentListener;
|
|
227
|
+
class Terminator;
|
|
228
|
+
class ClauseIterator;
|
|
229
|
+
class WitnessIterator;
|
|
230
|
+
class ExternalPropagator;
|
|
231
|
+
class Tracer;
|
|
232
|
+
struct InternalTracer;
|
|
233
|
+
class FileTracer;
|
|
234
|
+
class StatTracer;
|
|
235
|
+
|
|
236
|
+
/*------------------------------------------------------------------------*/
|
|
237
|
+
|
|
238
|
+
class Solver {
|
|
239
|
+
|
|
240
|
+
public:
|
|
241
|
+
// ====== BEGIN IPASIR ===================================================
|
|
242
|
+
|
|
243
|
+
// This section implements the corresponding IPASIR functionality.
|
|
244
|
+
|
|
245
|
+
Solver ();
|
|
246
|
+
~Solver ();
|
|
247
|
+
|
|
248
|
+
static const char *signature (); // name of this library
|
|
249
|
+
|
|
250
|
+
// Core functionality as in the IPASIR incremental SAT solver interface.
|
|
251
|
+
// (recall 'READY = CONFIGURING | STEADY | SATISFIED | UNSATISFIED').
|
|
252
|
+
// Further note that 'lit' is required to be different from 'INT_MIN' and
|
|
253
|
+
// different from '0' except for 'add'.
|
|
254
|
+
|
|
255
|
+
// Add valid literal to clause or zero to terminate clause.
|
|
256
|
+
//
|
|
257
|
+
// require (VALID) // recall 'VALID = READY | ADDING'
|
|
258
|
+
// if (lit) ensure (ADDING) // and thus VALID but not READY
|
|
259
|
+
// if (!lit) ensure (STEADY ) // and thus READY
|
|
260
|
+
//
|
|
261
|
+
void add (int lit);
|
|
262
|
+
|
|
263
|
+
// Here are functions simplifying clause addition. The given literals
|
|
264
|
+
// should all be valid (different from 'INT_MIN' and different from '0').
|
|
265
|
+
//
|
|
266
|
+
// require (VALID)
|
|
267
|
+
// ensure (STEADY )
|
|
268
|
+
//
|
|
269
|
+
void clause (int); // Add unit clause.
|
|
270
|
+
void clause (int, int); // Add binary clause.
|
|
271
|
+
void clause (int, int, int); // Add ternary clause.
|
|
272
|
+
void clause (int, int, int, int); // Add quaternary clause.
|
|
273
|
+
void clause (int, int, int, int, int); // Add quinternary clause.
|
|
274
|
+
void clause (const std::vector<int> &); // Add literal vector as clause.
|
|
275
|
+
void clause (const int *, size_t); // Add literal array as clause.
|
|
276
|
+
|
|
277
|
+
// This function can be used to check if the formula is already
|
|
278
|
+
// inconsistent (contains the empty clause or was proven to be
|
|
279
|
+
// root-level unsatisfiable).
|
|
280
|
+
|
|
281
|
+
bool inconsistent ();
|
|
282
|
+
|
|
283
|
+
// Assume valid non zero literal for next call to 'solve'. These
|
|
284
|
+
// assumptions are reset after the call to 'solve' as well as after
|
|
285
|
+
// returning from 'simplify' and 'lookahead.
|
|
286
|
+
//
|
|
287
|
+
// require (READY)
|
|
288
|
+
// ensure (STEADY )
|
|
289
|
+
//
|
|
290
|
+
void assume (int lit);
|
|
291
|
+
|
|
292
|
+
// Try to solve the current formula. Returns
|
|
293
|
+
//
|
|
294
|
+
// 0 = UNKNOWN (limit reached or interrupted through 'terminate')
|
|
295
|
+
// 10 = SATISFIABLE
|
|
296
|
+
// 20 = UNSATISFIABLE
|
|
297
|
+
//
|
|
298
|
+
// require (READY)
|
|
299
|
+
// ensure (INCONCLUSIVE | SATISFIED | UNSATISFIED)
|
|
300
|
+
//
|
|
301
|
+
// Note, that while in this call the solver actually transitions to state
|
|
302
|
+
// 'SOLVING', which however is only visible from a different context,
|
|
303
|
+
// i.e., from a different thread or from a signal handler. Only right
|
|
304
|
+
// before returning from this call it goes into a 'READY' state.
|
|
305
|
+
//
|
|
306
|
+
int solve ();
|
|
307
|
+
|
|
308
|
+
// Get the value of a valid non-zero literal. This follows the IPASIR
|
|
309
|
+
// semantics which says to return 'lit' if 'lit' is assigned to 'true' and
|
|
310
|
+
// '-lit' if 'lit' is assigned to false. This has the consequence that
|
|
311
|
+
// the returned literal is always assigned to 'true' and thus might be a
|
|
312
|
+
// bit confusing. To avoid the headache of these semantics (which we
|
|
313
|
+
// unfortunately should follow to be compatabile with IPASIR) the user can
|
|
314
|
+
// simply use positive variable indices instead of literals. Then the
|
|
315
|
+
// returned integer is negative if the variable is assigned to 'false' and
|
|
316
|
+
// positive it is assigned to 'true'.
|
|
317
|
+
//
|
|
318
|
+
// require (SATISFIED)
|
|
319
|
+
// ensure (SATISFIED)
|
|
320
|
+
//
|
|
321
|
+
int val (
|
|
322
|
+
int lit,
|
|
323
|
+
bool use_default_value_for_declared_but_not_used_variable = true);
|
|
324
|
+
|
|
325
|
+
// Try to flip the value of the given literal without falsifying the
|
|
326
|
+
// formula. Returns 'true' if this was successful. Otherwise the model is
|
|
327
|
+
// not changed and 'false' is returned. If a literal was eliminated or
|
|
328
|
+
// substituted flipping will fail on that literal and in particular the
|
|
329
|
+
// solver will not taint it nor restore any clauses.
|
|
330
|
+
//
|
|
331
|
+
// The 'flip' function can only flip the value of a variables not acting
|
|
332
|
+
// as witness on the reconstruction stack.
|
|
333
|
+
//
|
|
334
|
+
// As a side effect of calling this function first all assigned variables
|
|
335
|
+
// are propagated again without using blocking literal. Thus the first
|
|
336
|
+
// call to this function after obtaining a model adds a substantial
|
|
337
|
+
// overhead. Subsequent calls will not need to properly propagate again.
|
|
338
|
+
//
|
|
339
|
+
// Furthermore if the reconstruction stack is non-empty and has been
|
|
340
|
+
// traversed to reconstruct a full extended model for eliminated
|
|
341
|
+
// variables (and to satisfy removed blocked clauses), the values of these
|
|
342
|
+
// witness variables obtained via 'val' before become invalid. The user
|
|
343
|
+
// thus will need to call 'val' again after calling 'flip' which will
|
|
344
|
+
// trigger then a traversal of the reconstruction stack.
|
|
345
|
+
//
|
|
346
|
+
// So try to avoid mixing 'flip' and 'val' (for efficiency only).
|
|
347
|
+
// Further, this functionality is currently not supported in the presence
|
|
348
|
+
// of an external propagator.
|
|
349
|
+
//
|
|
350
|
+
// require (SATISFIED)
|
|
351
|
+
// ensure (SATISFIED)
|
|
352
|
+
//
|
|
353
|
+
bool flip (int lit);
|
|
354
|
+
|
|
355
|
+
// Same as 'flip' without actually flipping it. This functionality is
|
|
356
|
+
// currently not supported in the presence of an external propagator.
|
|
357
|
+
//
|
|
358
|
+
// require (SATISFIED)
|
|
359
|
+
// ensure (SATISFIED)
|
|
360
|
+
//
|
|
361
|
+
bool flippable (int lit);
|
|
362
|
+
|
|
363
|
+
// Determine whether the valid non-zero literal is in the core.
|
|
364
|
+
// Returns 'true' if the literal is in the core and 'false' otherwise.
|
|
365
|
+
// Note that the core does not have to be minimal.
|
|
366
|
+
//
|
|
367
|
+
// require (UNSATISFIED)
|
|
368
|
+
// ensure (UNSATISFIED)
|
|
369
|
+
//
|
|
370
|
+
bool failed (int lit);
|
|
371
|
+
|
|
372
|
+
// Add call-back which is checked regularly for termination. There can
|
|
373
|
+
// only be one terminator connected. If a second (non-zero) one is added
|
|
374
|
+
// the first one is implicitly disconnected.
|
|
375
|
+
//
|
|
376
|
+
// require (VALID)
|
|
377
|
+
// ensure (VALID)
|
|
378
|
+
//
|
|
379
|
+
void connect_terminator (Terminator *terminator);
|
|
380
|
+
void disconnect_terminator ();
|
|
381
|
+
|
|
382
|
+
// Add call-back which allows to export learned clauses.
|
|
383
|
+
//
|
|
384
|
+
// require (VALID)
|
|
385
|
+
// ensure (VALID)
|
|
386
|
+
//
|
|
387
|
+
void connect_learner (Learner *learner);
|
|
388
|
+
void disconnect_learner ();
|
|
389
|
+
|
|
390
|
+
// ====== END IPASIR =====================================================
|
|
391
|
+
|
|
392
|
+
// Add call-back which allows to observe when a variable is fixed.
|
|
393
|
+
//
|
|
394
|
+
// require (VALID)
|
|
395
|
+
// ensure (VALID)
|
|
396
|
+
//
|
|
397
|
+
void connect_fixed_listener (FixedAssignmentListener *fixed_listener);
|
|
398
|
+
void disconnect_fixed_listener ();
|
|
399
|
+
|
|
400
|
+
// ====== BEGIN IPASIR-UP ================================================
|
|
401
|
+
|
|
402
|
+
// Add call-back which allows to learn, propagate and backtrack based on
|
|
403
|
+
// external constraints. Only one external propagator can be connected
|
|
404
|
+
// and after connection every related variables must be 'observed' (use
|
|
405
|
+
// 'add_observed_var' function).
|
|
406
|
+
// Disconnection of the external propagator resets all the observed
|
|
407
|
+
// variables.
|
|
408
|
+
//
|
|
409
|
+
// require (VALID)
|
|
410
|
+
// ensure (VALID)
|
|
411
|
+
//
|
|
412
|
+
void connect_external_propagator (ExternalPropagator *propagator);
|
|
413
|
+
void disconnect_external_propagator ();
|
|
414
|
+
|
|
415
|
+
// Mark as 'observed' those variables that are relevant to the external
|
|
416
|
+
// propagator. External propagation, clause addition during search and
|
|
417
|
+
// notifications are all over these observed variables.
|
|
418
|
+
// A variable can not be observed without having an external propagator
|
|
419
|
+
// already connected. Observed variables are "frozen" internally, and so
|
|
420
|
+
// inprocessing will not consider them as candidates for elimination.
|
|
421
|
+
// An observed variable is allowed to be a fresh variable and it can be
|
|
422
|
+
// added also during solving.
|
|
423
|
+
//
|
|
424
|
+
// require (VALID_OR_SOLVING)
|
|
425
|
+
// ensure (VALID_OR_SOLVING)
|
|
426
|
+
//
|
|
427
|
+
void add_observed_var (int var);
|
|
428
|
+
|
|
429
|
+
// Removes the 'observed' flag from the given variable. A variable can be
|
|
430
|
+
// set unobserved only when it is unassigned, in order to guarantee
|
|
431
|
+
// that no yet unexplained external propagation involves it.
|
|
432
|
+
//
|
|
433
|
+
// require (VALID_OR_SOLVING)
|
|
434
|
+
// ensure (VALID_OR_SOLVING)
|
|
435
|
+
//
|
|
436
|
+
void remove_observed_var (int var);
|
|
437
|
+
|
|
438
|
+
// Removes all the 'observed' flags from the variables. Disconnecting the
|
|
439
|
+
// propagator invokes this step as well.
|
|
440
|
+
//
|
|
441
|
+
// require (VALID)
|
|
442
|
+
// ensure (VALID)
|
|
443
|
+
//
|
|
444
|
+
void reset_observed_vars ();
|
|
445
|
+
|
|
446
|
+
// Get reason of valid observed literal (true = it is an observed variable
|
|
447
|
+
// and it got assigned by a decision during the CDCL loop. Otherwise:
|
|
448
|
+
// false.
|
|
449
|
+
//
|
|
450
|
+
// require (VALID_OR_SOLVING)
|
|
451
|
+
// ensure (VALID_OR_SOLVING)
|
|
452
|
+
//
|
|
453
|
+
bool is_decision (int lit);
|
|
454
|
+
|
|
455
|
+
// Force solve to backtrack to certain decision level. Can be called only
|
|
456
|
+
// during 'cb_decide' and 'cb_check_final_model' of a connected External
|
|
457
|
+
// Propagator. Invoking in any other time will trigger a runtime error.
|
|
458
|
+
// Otherwise, the External Propagator will be notified about the backtrack
|
|
459
|
+
// via 'notify_backtrack' and the search continues.
|
|
460
|
+
//
|
|
461
|
+
// require (SOLVING)
|
|
462
|
+
// ensure (SOLVING)
|
|
463
|
+
//
|
|
464
|
+
void force_backtrack (int new_level);
|
|
465
|
+
|
|
466
|
+
// ====== END IPASIR-UP ==================================================
|
|
467
|
+
|
|
468
|
+
//------------------------------------------------------------------------
|
|
469
|
+
// Adds a literal to the constraint clause. Same functionality as 'add'
|
|
470
|
+
// but the clause only exists for the next call to solve (same lifetime as
|
|
471
|
+
// assumptions). Only one constraint may exists at a time. A new
|
|
472
|
+
// constraint replaces the old. The main application of this functionality
|
|
473
|
+
// is the model checking algorithm IC3. See our FMCAD'21 paper
|
|
474
|
+
// [FroleyksBiere-FMCAD'19] for more details.
|
|
475
|
+
//
|
|
476
|
+
// Add valid literal to the constraint clause or zero to terminate it.
|
|
477
|
+
//
|
|
478
|
+
// require (VALID) // recall 'VALID = READY |
|
|
479
|
+
// ADDING' if (lit) ensure (ADDING) // and thus VALID but not
|
|
480
|
+
// READY if (!lit) && !adding_clause ensure (STEADY ) // and thus READY
|
|
481
|
+
//
|
|
482
|
+
void constrain (int lit);
|
|
483
|
+
|
|
484
|
+
// Determine whether the constraint was used to proof the
|
|
485
|
+
// unsatisfiability. Note that the formula might still be unsatisfiable
|
|
486
|
+
// without the constraint.
|
|
487
|
+
//
|
|
488
|
+
// require (UNSATISFIED)
|
|
489
|
+
// ensure (UNSATISFIED)
|
|
490
|
+
//
|
|
491
|
+
bool constraint_failed ();
|
|
492
|
+
|
|
493
|
+
// Collects a subset of those literals that are implied by unit
|
|
494
|
+
// propagation by assuming the currently defined (potentially empty)
|
|
495
|
+
// set of assumptions (see IPASIR assume(lit)) function. In case
|
|
496
|
+
// unit propagation over the defined set of assumptions (or over the
|
|
497
|
+
// clause database on its own) leads to conflict, the function
|
|
498
|
+
// returns 20 and the content of 'implicates' is undefined. In most
|
|
499
|
+
// other case, the function returns 0 (indicating 'UNKNOWN') and
|
|
500
|
+
// 'implicates' lists the non-conflicting current value of the
|
|
501
|
+
// trail. If ILB is off, in the rare case where where no decision
|
|
502
|
+
// was needed and propagation assigned all literals, then the
|
|
503
|
+
// 'implicates' lists will contain all assigned literals, which is a
|
|
504
|
+
// model. If ILB is on, propagate might also return SAT. In this
|
|
505
|
+
// case, 'implicates' will still only contain the implied literals.
|
|
506
|
+
|
|
507
|
+
// Returns
|
|
508
|
+
//
|
|
509
|
+
// 0 = UNKNOWN
|
|
510
|
+
// 10 = SATISFIABLE
|
|
511
|
+
// 20 = UNSATISFIABLE
|
|
512
|
+
//
|
|
513
|
+
// The 'UNKNOWN' result means that unit propagation did not lead to a
|
|
514
|
+
// conflict nor to a complete assignment, or limit reached or interrupted
|
|
515
|
+
// through 'terminate'.
|
|
516
|
+
//
|
|
517
|
+
// require (READY)
|
|
518
|
+
// ensure (INCONCLUSIVE | SATISFIED | UNSATISFIED)
|
|
519
|
+
//
|
|
520
|
+
int propagate ();
|
|
521
|
+
|
|
522
|
+
// See the comment for propagate above.
|
|
523
|
+
//
|
|
524
|
+
// require (INCONCLUSIVE)
|
|
525
|
+
// ensure (INCONCLUSIVE)
|
|
526
|
+
//
|
|
527
|
+
void implied (std::vector<int> &implicants);
|
|
528
|
+
|
|
529
|
+
//------------------------------------------------------------------------
|
|
530
|
+
// This function determines a good splitting literal. The result can be
|
|
531
|
+
// zero if the formula is proven to be satisfiable or unsatisfiable. This
|
|
532
|
+
// can then be checked by 'state ()'. If the formula is empty and
|
|
533
|
+
// the function is not able to determine satisfiability also zero is
|
|
534
|
+
// returned but the state remains steady.
|
|
535
|
+
//
|
|
536
|
+
// require (READY)
|
|
537
|
+
// ensure (INCONCLUSIVE | SATISFIED | UNSATISFIED)
|
|
538
|
+
//
|
|
539
|
+
int lookahead (void);
|
|
540
|
+
|
|
541
|
+
struct CubesWithStatus {
|
|
542
|
+
int status;
|
|
543
|
+
std::vector<std::vector<int>> cubes;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
CubesWithStatus generate_cubes (int, int min_depth = 0);
|
|
547
|
+
|
|
548
|
+
void reset_assumptions ();
|
|
549
|
+
void reset_constraint ();
|
|
550
|
+
|
|
551
|
+
// Return the current state of the solver as defined above.
|
|
552
|
+
//
|
|
553
|
+
const State &state () const { return _state; }
|
|
554
|
+
|
|
555
|
+
// Similar to 'state ()' but using the standard competition exit codes of
|
|
556
|
+
// '10' for 'SATISFIABLE', '20' for 'UNSATISFIABLE' and '0' otherwise.
|
|
557
|
+
//
|
|
558
|
+
int status () const {
|
|
559
|
+
if (_state == SATISFIED)
|
|
560
|
+
return SATISFIABLE;
|
|
561
|
+
else if (_state == UNSATISFIED)
|
|
562
|
+
return UNSATISFIABLE;
|
|
563
|
+
else
|
|
564
|
+
return UNKNOWN;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/*----------------------------------------------------------------------*/
|
|
568
|
+
|
|
569
|
+
static const char *version (); // return version string
|
|
570
|
+
|
|
571
|
+
/*----------------------------------------------------------------------*/
|
|
572
|
+
// Copy 'this' into a fresh 'other'. The copy procedure is not a deep
|
|
573
|
+
// clone, but only copies irredundant clauses and units. It also makes
|
|
574
|
+
// sure that witness reconstruction works with the copy as with the
|
|
575
|
+
// original formula such that both solvers have the same models.
|
|
576
|
+
// Assumptions are not copied. Options however are copied as well as
|
|
577
|
+
// flags which remember the current state of variables in preprocessing.
|
|
578
|
+
//
|
|
579
|
+
// require (READY) // for 'this'
|
|
580
|
+
// ensure (READY) // for 'this'
|
|
581
|
+
//
|
|
582
|
+
// other.require (CONFIGURING)
|
|
583
|
+
// other.ensure (CONFIGURING | STEADY )
|
|
584
|
+
//
|
|
585
|
+
void copy (Solver &other) const;
|
|
586
|
+
|
|
587
|
+
/*----------------------------------------------------------------------*/
|
|
588
|
+
// Variables are usually added and initialized implicitly whenever a
|
|
589
|
+
// literal is used as an argument except for the functions 'val', 'fixed',
|
|
590
|
+
// 'failed' and 'frozen'. However, the library internally keeps a maximum
|
|
591
|
+
// variable index, which can be queried.
|
|
592
|
+
//
|
|
593
|
+
// With factor (BVA) the solver might also add new variables. In that case
|
|
594
|
+
// the user is required to use this to check which variables are currently
|
|
595
|
+
// free before adding new variables of their own. The alternative is to
|
|
596
|
+
// declare more variables in batches with 'declare_more_variables'. Using
|
|
597
|
+
// 'resize' in combination with any technique that could add variables
|
|
598
|
+
// (currently only factor) is not advised. After each application of
|
|
599
|
+
// `add`, `vars ()` will return an updated value, even if you did not
|
|
600
|
+
// import the entire clause yet.
|
|
601
|
+
//
|
|
602
|
+
// require (VALID | SOLVING)
|
|
603
|
+
// ensure (VALID | SOLVING)
|
|
604
|
+
//
|
|
605
|
+
int vars ();
|
|
606
|
+
|
|
607
|
+
// Increase the maximum variable index explicitly. This function makes
|
|
608
|
+
// sure that at least 'min_max_var' variables are initialized. Since it
|
|
609
|
+
// might need to reallocate tables, it destroys a satisfying assignment
|
|
610
|
+
// and has the same state transition and conditions as 'assume' etc.
|
|
611
|
+
//
|
|
612
|
+
// require (READY)
|
|
613
|
+
// ensure (STEADY)
|
|
614
|
+
//
|
|
615
|
+
void resize (int min_max_var);
|
|
616
|
+
|
|
617
|
+
// Increase the maximum variable index by a number of new variables.
|
|
618
|
+
// initializes 'number_of_vars' new variables and protects them from
|
|
619
|
+
// being used by the solver as extension variables (BVA).
|
|
620
|
+
//
|
|
621
|
+
// It returns the new maximum variable index which is the highest
|
|
622
|
+
// variable name of the consecutive range of newly delcared variables.
|
|
623
|
+
// It has the same state transition and conditions as 'resize' above.
|
|
624
|
+
//
|
|
625
|
+
// require (READY)
|
|
626
|
+
// ensure (STEADY)
|
|
627
|
+
//
|
|
628
|
+
int declare_more_variables (int number_of_additional_new_vars);
|
|
629
|
+
|
|
630
|
+
// Returns the next fresh variable that was not used internally.
|
|
631
|
+
//
|
|
632
|
+
int declare_one_more_variable ();
|
|
633
|
+
|
|
634
|
+
// Get the value of some statistics or -1 if the statistics does not
|
|
635
|
+
// exist or is not support. Only requires the state to be initialized.
|
|
636
|
+
//
|
|
637
|
+
int64_t get_statistic_value (const char *const) const;
|
|
638
|
+
|
|
639
|
+
#ifndef NTRACING
|
|
640
|
+
//------------------------------------------------------------------------
|
|
641
|
+
// This function can be used to write API calls to a file. The same
|
|
642
|
+
// format is used which 'mobical' can read, execute and also shrink
|
|
643
|
+
// through delta debugging.
|
|
644
|
+
//
|
|
645
|
+
// Tracing API calls can also be achieved by using the environment
|
|
646
|
+
// variable 'CADICAL_API_TRACE'. That alternative is useful if you do not
|
|
647
|
+
// want to change the source code using the solver, e.g., if you only have
|
|
648
|
+
// a binary with the solver linked in. However, that method only allows
|
|
649
|
+
// to trace one solver instance, while with the following function API
|
|
650
|
+
// tracing can be enabled for different solver instances individually.
|
|
651
|
+
//
|
|
652
|
+
// The solver will flush the file after every trace API call but does not
|
|
653
|
+
// close it during deletion. It remains owned by the user of the library.
|
|
654
|
+
//
|
|
655
|
+
// require (VALID)
|
|
656
|
+
// ensure (VALID)
|
|
657
|
+
//
|
|
658
|
+
void trace_api_calls (FILE *file);
|
|
659
|
+
#endif
|
|
660
|
+
|
|
661
|
+
//------------------------------------------------------------------------
|
|
662
|
+
// Option handling.
|
|
663
|
+
|
|
664
|
+
// Determine whether 'name' is a valid option name.
|
|
665
|
+
//
|
|
666
|
+
static bool is_valid_option (const char *name);
|
|
667
|
+
|
|
668
|
+
// Determine whether 'name' enables a specific preprocessing technique.
|
|
669
|
+
//
|
|
670
|
+
static bool is_preprocessing_option (const char *name);
|
|
671
|
+
|
|
672
|
+
// Determine whether 'arg' is a valid long option of the form '--<name>',
|
|
673
|
+
// '--<name>=<val>' or '--no-<name>' similar to 'set_long_option' below.
|
|
674
|
+
// Legal values are 'true', 'false', or '[-]<mantissa>[e<exponent>]'.
|
|
675
|
+
|
|
676
|
+
static bool is_valid_long_option (const char *arg);
|
|
677
|
+
|
|
678
|
+
// Get the current value of the option 'name'. If 'name' is invalid then
|
|
679
|
+
// zero is returned. Here '--...' arguments as invalid options.
|
|
680
|
+
//
|
|
681
|
+
int get (const char *name);
|
|
682
|
+
|
|
683
|
+
// Set the default verbose message prefix (default "c ").
|
|
684
|
+
//
|
|
685
|
+
void prefix (const char *verbose_message_prefix);
|
|
686
|
+
|
|
687
|
+
// Explicit version of setting an option. If the option '<name>' exists
|
|
688
|
+
// and '<val>' can be parsed then 'true' is returned. If the option value
|
|
689
|
+
// is out of range the actual value is computed as the closest (minimum or
|
|
690
|
+
// maximum) value possible, but still 'true' is returned.
|
|
691
|
+
//
|
|
692
|
+
// require (CONFIGURING)
|
|
693
|
+
// ensure (CONFIGURING)
|
|
694
|
+
//
|
|
695
|
+
// Thus options can only bet set right after initialization.
|
|
696
|
+
//
|
|
697
|
+
bool set (const char *name, int val);
|
|
698
|
+
|
|
699
|
+
// This function accepts options in command line syntax:
|
|
700
|
+
//
|
|
701
|
+
// '--<name>=<val>', '--<name>', or '--no-<name>'
|
|
702
|
+
//
|
|
703
|
+
// It actually calls the previous 'set' function after parsing 'arg'. The
|
|
704
|
+
// same values are expected as for 'is_valid_long_option' above and as
|
|
705
|
+
// with 'set' any value outside of the range of legal values for a
|
|
706
|
+
// particular option are set to either the minimum or maximum depending on
|
|
707
|
+
// which side of the valid interval they lie.
|
|
708
|
+
//
|
|
709
|
+
// require (CONFIGURING)
|
|
710
|
+
// ensure (CONFIGURING)
|
|
711
|
+
//
|
|
712
|
+
bool set_long_option (const char *arg);
|
|
713
|
+
|
|
714
|
+
// Determine whether 'name' is a valid configuration.
|
|
715
|
+
//
|
|
716
|
+
static bool is_valid_configuration (const char *);
|
|
717
|
+
|
|
718
|
+
// Overwrite (some) options with the forced values of the configuration.
|
|
719
|
+
// The result is 'true' iff the 'name' is a valid configuration.
|
|
720
|
+
//
|
|
721
|
+
// require (CONFIGURING)
|
|
722
|
+
// ensure (CONFIGURING)
|
|
723
|
+
//
|
|
724
|
+
bool configure (const char *);
|
|
725
|
+
|
|
726
|
+
// Increase preprocessing and inprocessing limits by '10^<val>'. Values
|
|
727
|
+
// below '0' are ignored and values above '9' are reduced to '9'.
|
|
728
|
+
//
|
|
729
|
+
// require (READY)
|
|
730
|
+
// ensure (READY)
|
|
731
|
+
//
|
|
732
|
+
void optimize (int val);
|
|
733
|
+
|
|
734
|
+
// Specify search limits, where currently 'name' can be
|
|
735
|
+
//
|
|
736
|
+
// "conflicts",
|
|
737
|
+
// "decisions",
|
|
738
|
+
// "preprocessing", or
|
|
739
|
+
// "localsearch".
|
|
740
|
+
//
|
|
741
|
+
// The first two limits are unbounded by default. Thus using a negative
|
|
742
|
+
// limit for conflicts or decisions switches back to the default of
|
|
743
|
+
// unlimited search (for that particular limit). The preprocessing limit
|
|
744
|
+
// determines the number of preprocessing rounds, which is zero by
|
|
745
|
+
// default. Similarly, the local search limit determines the number of
|
|
746
|
+
// local search rounds (zero by default).
|
|
747
|
+
//
|
|
748
|
+
// As with 'set', the return value denotes whether the limit 'name' is
|
|
749
|
+
// valid. These limits are only valid for the next 'solve' or 'simplify'
|
|
750
|
+
// call and reset to their default after 'solve' returns (as well as
|
|
751
|
+
// overwritten and reset during calls to 'simplify' and 'lookahead'). We
|
|
752
|
+
// actually also have an internal "terminate" limit which however should
|
|
753
|
+
// only be used for testing and debugging.
|
|
754
|
+
//
|
|
755
|
+
// require (READY)
|
|
756
|
+
// ensure (READY)
|
|
757
|
+
//
|
|
758
|
+
bool limit (const char *arg, int val);
|
|
759
|
+
bool is_valid_limit (const char *arg);
|
|
760
|
+
|
|
761
|
+
// The number of currently active variables and clauses can be queried by
|
|
762
|
+
// these functions. Variables become active if a clause is added with it.
|
|
763
|
+
// They become inactive if they are eliminated or fixed at the root level
|
|
764
|
+
// Clauses become inactive if they are satisfied, subsumed, eliminated.
|
|
765
|
+
// Redundant clauses are reduced regularly and thus the 'redundant'
|
|
766
|
+
// function is less useful.
|
|
767
|
+
//
|
|
768
|
+
// require (VALID)
|
|
769
|
+
// ensure (VALID)
|
|
770
|
+
//
|
|
771
|
+
int active () const; // Number of active variables.
|
|
772
|
+
int64_t redundant () const; // Number of active redundant clauses.
|
|
773
|
+
int64_t irredundant () const; // Number of active irredundant clauses.
|
|
774
|
+
|
|
775
|
+
//------------------------------------------------------------------------
|
|
776
|
+
// This function executes the given number of preprocessing rounds. It is
|
|
777
|
+
// similar to 'solve' with 'limits ("preprocessing", rounds)' except that
|
|
778
|
+
// no CDCL nor local search, nor lucky phases are executed. The result
|
|
779
|
+
// values are also the same: 0=UNKNOWN, 10=SATISFIABLE, 20=UNSATISFIABLE.
|
|
780
|
+
//
|
|
781
|
+
// As 'solve' it resets current assumptions and limits before returning.
|
|
782
|
+
// The numbers of rounds should not be negative. If the number of rounds
|
|
783
|
+
// is zero only clauses are restored (if necessary) and top level unit
|
|
784
|
+
// propagation is performed, which both take some time.
|
|
785
|
+
//
|
|
786
|
+
// require (READY)
|
|
787
|
+
// ensure (INCONCLUSIVE | SATISFIED | UNSATISFIED)
|
|
788
|
+
//
|
|
789
|
+
int simplify (int rounds = 3);
|
|
790
|
+
|
|
791
|
+
//------------------------------------------------------------------------
|
|
792
|
+
// Force termination of 'solve' asynchronously.
|
|
793
|
+
//
|
|
794
|
+
// require (SOLVING | READY)
|
|
795
|
+
// ensure (INCONCLUSIVE ) // actually not immediately (synchronously)
|
|
796
|
+
//
|
|
797
|
+
void terminate ();
|
|
798
|
+
|
|
799
|
+
//------------------------------------------------------------------------
|
|
800
|
+
|
|
801
|
+
// We have the following common reference counting functions, which avoid
|
|
802
|
+
// to restore clauses but require substantial user guidance. This was the
|
|
803
|
+
// only way to use inprocessing in incremental SAT solving in Lingeling
|
|
804
|
+
// (and before in MiniSAT's 'freeze' / 'thaw') and which did not use
|
|
805
|
+
// automatic clause restoring. In general this is slower than
|
|
806
|
+
// restoring clauses and should not be used.
|
|
807
|
+
//
|
|
808
|
+
// In essence the user freezes variables which potentially are still
|
|
809
|
+
// needed in clauses added or assumptions used after the next 'solve'
|
|
810
|
+
// call. As in Lingeling you can freeze a variable multiple times, but
|
|
811
|
+
// then have to melt it the same number of times again in order to enable
|
|
812
|
+
// variable eliminating on it etc. The arguments can be literals
|
|
813
|
+
// (negative indices) but conceptually variables are frozen.
|
|
814
|
+
//
|
|
815
|
+
// In the old way of doing things without restore you should not use a
|
|
816
|
+
// variable incrementally (in 'add' or 'assume'), which was used before
|
|
817
|
+
// and potentially could have been eliminated in a previous 'solve' call.
|
|
818
|
+
// This can lead to spurious satisfying assignment. In order to check
|
|
819
|
+
// this API contract one can use the 'checkfrozen' option. This has the
|
|
820
|
+
// drawback that restoring clauses implicitly would fail with a fatal
|
|
821
|
+
// error message even if in principle the solver could just restore
|
|
822
|
+
// clauses. Thus this option is disabled by default.
|
|
823
|
+
//
|
|
824
|
+
// See our SAT'19 paper [FazekasBiereScholl-SAT'19] for more details.
|
|
825
|
+
//
|
|
826
|
+
// require (VALID)
|
|
827
|
+
// ensure (VALID)
|
|
828
|
+
//
|
|
829
|
+
bool frozen (int lit) const;
|
|
830
|
+
void freeze (int lit);
|
|
831
|
+
void melt (int lit); // Also needs 'require (frozen (lit))'.
|
|
832
|
+
|
|
833
|
+
//------------------------------------------------------------------------
|
|
834
|
+
|
|
835
|
+
// Root level assigned variables can be queried with this function.
|
|
836
|
+
// It returns '1' if the literal is implied by the formula, '-1' if its
|
|
837
|
+
// negation is implied, or '0' if this is unclear at this point.
|
|
838
|
+
//
|
|
839
|
+
// require (VALID)
|
|
840
|
+
// ensure (VALID)
|
|
841
|
+
//
|
|
842
|
+
int fixed (int lit) const;
|
|
843
|
+
|
|
844
|
+
//------------------------------------------------------------------------
|
|
845
|
+
// Force the default decision phase of a variable to a certain value.
|
|
846
|
+
//
|
|
847
|
+
void phase (int lit);
|
|
848
|
+
void unphase (int lit);
|
|
849
|
+
|
|
850
|
+
//------------------------------------------------------------------------
|
|
851
|
+
|
|
852
|
+
// Enables clausal proof tracing in various format and returns 'true' if
|
|
853
|
+
// successfully opened for writing. Writing proofs has to be enabled
|
|
854
|
+
// before calling 'solve', 'add' and 'dimacs', that is in state
|
|
855
|
+
// 'CONFIGURING'. Otherwise only partial proofs would be written.
|
|
856
|
+
//
|
|
857
|
+
// require (CONFIGURING)
|
|
858
|
+
// ensure (CONFIGURING)
|
|
859
|
+
//
|
|
860
|
+
bool trace_proof (FILE *file, const char *name); // Write proof.
|
|
861
|
+
bool trace_proof (const char *path); // Open & write proof.
|
|
862
|
+
|
|
863
|
+
// Flushing the proof trace file eventually calls 'fflush' on the actual
|
|
864
|
+
// file or pipe and thus if this function returns all the proof steps
|
|
865
|
+
// should have been written (with the same guarantees as 'fflush').
|
|
866
|
+
//
|
|
867
|
+
// The additional optional argument forces to print the number of addition
|
|
868
|
+
// and deletion steps in the proof even if the verbosity level is zero but
|
|
869
|
+
// not if quiet is set as well. The default for the stand-alone solver is
|
|
870
|
+
// to print this information (in the 'closing proof' section) but for API
|
|
871
|
+
// usage of the library we want to stay silent unless explicitly requested
|
|
872
|
+
// or verbosity is non-zero (and as explained quiet is not set).
|
|
873
|
+
//
|
|
874
|
+
// This function can be called multiple times.
|
|
875
|
+
//
|
|
876
|
+
// require (VALID)
|
|
877
|
+
// ensure (VALID)
|
|
878
|
+
//
|
|
879
|
+
void flush_proof_trace (bool print = false);
|
|
880
|
+
|
|
881
|
+
// Close proof trace early. Similar to 'flush' we allow the user to
|
|
882
|
+
// control with 'print' in a more fine-grained way whether statistics
|
|
883
|
+
// about the size of the written proof file and if compressed on-the-fly
|
|
884
|
+
// the number of actual bytes written (including deflation percentage) are
|
|
885
|
+
// printed. Before actually closing (or detaching in case of writing to
|
|
886
|
+
// '<stdout>') we check whether 'flush_proof_trace' was called since the
|
|
887
|
+
// last time a proof step (addition or deletion) was traced. If this is
|
|
888
|
+
// not the case we would call 'flush_proof_trace' with the same 'print'
|
|
889
|
+
// argument.
|
|
890
|
+
//
|
|
891
|
+
// require (VALID)
|
|
892
|
+
// ensure (VALID)
|
|
893
|
+
//
|
|
894
|
+
void close_proof_trace (bool print = false);
|
|
895
|
+
|
|
896
|
+
// Enables clausal proof tracing with or without antecedents using
|
|
897
|
+
// the Tracer interface defined in 'tracer.hpp'
|
|
898
|
+
//
|
|
899
|
+
// InternalTracer, StatTracer and FileTracer for internal use
|
|
900
|
+
//
|
|
901
|
+
// require (CONFIGURING)
|
|
902
|
+
// ensure (CONFIGURING)
|
|
903
|
+
//
|
|
904
|
+
void connect_proof_tracer (Tracer *tracer, bool antecedents,
|
|
905
|
+
bool finalize_clauses = false);
|
|
906
|
+
void connect_proof_tracer (InternalTracer *tracer, bool antecedents,
|
|
907
|
+
bool finalize_clauses = false);
|
|
908
|
+
void connect_proof_tracer (StatTracer *tracer, bool antecedents,
|
|
909
|
+
bool finalize_clauses = false);
|
|
910
|
+
void connect_proof_tracer (FileTracer *tracer, bool antecedents,
|
|
911
|
+
bool finalize_clauses = false);
|
|
912
|
+
|
|
913
|
+
// Triggers the conclusion of incremental proofs. If the solver is
|
|
914
|
+
// 'SATISFIED' it will trigger 'extend ()' and give the model to the proof
|
|
915
|
+
// tracer through 'conclude_sat ()' if the solver is 'UNSATISFIED' it will
|
|
916
|
+
// trigger 'failing ()' which will learn new clauses as explained below:
|
|
917
|
+
// In case of failed assumptions will provide a core negated as a clause
|
|
918
|
+
// through the proof tracer interface. With a failing constraint these
|
|
919
|
+
// can be multiple clauses. Then it will trigger a 'conclude_unsat ()'
|
|
920
|
+
// event with the ids of the newly learnt clauses or the id of the global
|
|
921
|
+
// conflict. In case the solver is in 'UNKNOWN', it will collect the
|
|
922
|
+
// currently "entrailed" literals and add them to the proof.
|
|
923
|
+
//
|
|
924
|
+
// require (SATISFIED | UNSATISFIED | UNKNOWN)
|
|
925
|
+
// ensure (SATISFIED | UNSATISFIED | UNKNOWN)
|
|
926
|
+
//
|
|
927
|
+
void conclude ();
|
|
928
|
+
|
|
929
|
+
// Disconnect proof tracer. Also done upon deletion of the solver
|
|
930
|
+
// instance. Returns true if successful.
|
|
931
|
+
//
|
|
932
|
+
// require (VALID)
|
|
933
|
+
// ensure (VALID)
|
|
934
|
+
//
|
|
935
|
+
bool disconnect_proof_tracer (Tracer *tracer);
|
|
936
|
+
bool disconnect_proof_tracer (StatTracer *tracer);
|
|
937
|
+
bool disconnect_proof_tracer (FileTracer *tracer);
|
|
938
|
+
|
|
939
|
+
//------------------------------------------------------------------------
|
|
940
|
+
|
|
941
|
+
static void usage (); // Print usage information for long options.
|
|
942
|
+
|
|
943
|
+
static void configurations (); // Print configuration usage options.
|
|
944
|
+
|
|
945
|
+
// Prints statistics to stdout
|
|
946
|
+
// require (!DELETING)
|
|
947
|
+
// ensure (!DELETING)
|
|
948
|
+
//
|
|
949
|
+
void statistics (); // Print statistics.
|
|
950
|
+
void resources (); // Print resource usage (time and memory).
|
|
951
|
+
|
|
952
|
+
// require (VALID)
|
|
953
|
+
// ensure (VALID)
|
|
954
|
+
//
|
|
955
|
+
void options (); // Print current option and value list.
|
|
956
|
+
|
|
957
|
+
//------------------------------------------------------------------------
|
|
958
|
+
// Traverse irredundant clauses or the extension stack in reverse order.
|
|
959
|
+
//
|
|
960
|
+
// The return value is false if traversal is aborted early due to one of
|
|
961
|
+
// the visitor functions returning false. See description of the
|
|
962
|
+
// iterators below for more details on how to use these functions.
|
|
963
|
+
//
|
|
964
|
+
// require (VALID)
|
|
965
|
+
// ensure (VALID)
|
|
966
|
+
//
|
|
967
|
+
bool traverse_clauses (ClauseIterator &) const;
|
|
968
|
+
bool traverse_witnesses_backward (WitnessIterator &) const;
|
|
969
|
+
bool traverse_witnesses_forward (WitnessIterator &) const;
|
|
970
|
+
|
|
971
|
+
//------------------------------------------------------------------------
|
|
972
|
+
// Files with explicit path argument support compressed input and output
|
|
973
|
+
// if appropriate helper functions 'gzip' etc. are available. They are
|
|
974
|
+
// called through opening a pipe to an external command.
|
|
975
|
+
//
|
|
976
|
+
// If the 'strict' argument is zero then the number of variables and
|
|
977
|
+
// clauses specified in the DIMACS headers are ignored, i.e., the header
|
|
978
|
+
// 'p cnf 0 0' is always legal. If the 'strict' argument is larger '1'
|
|
979
|
+
// strict formatting of the header is required, i.e., single spaces
|
|
980
|
+
// everywhere and no trailing white space.
|
|
981
|
+
//
|
|
982
|
+
// Returns zero if successful and otherwise an error message.
|
|
983
|
+
//
|
|
984
|
+
// require (VALID)
|
|
985
|
+
// ensure (VALID)
|
|
986
|
+
//
|
|
987
|
+
const char *read_dimacs (FILE *file, const char *name, int &vars,
|
|
988
|
+
int strict = 1);
|
|
989
|
+
|
|
990
|
+
const char *read_dimacs (const char *path, int &vars, int strict = 1);
|
|
991
|
+
|
|
992
|
+
// The following routines work the same way but parse both DIMACS and
|
|
993
|
+
// INCCNF files (with 'p inccnf' header and 'a <cube>' lines). If the
|
|
994
|
+
// parser finds and 'p inccnf' header or cubes then '*incremental' is set
|
|
995
|
+
// to true and the cubes are stored in the given vector (each cube
|
|
996
|
+
// terminated by a zero).
|
|
997
|
+
|
|
998
|
+
const char *read_dimacs (FILE *file, const char *name, int &vars,
|
|
999
|
+
int strict, bool &incremental,
|
|
1000
|
+
std::vector<int> &cubes);
|
|
1001
|
+
|
|
1002
|
+
const char *read_dimacs (const char *path, int &vars, int strict,
|
|
1003
|
+
bool &incremental, std::vector<int> &cubes);
|
|
1004
|
+
|
|
1005
|
+
//------------------------------------------------------------------------
|
|
1006
|
+
// Write current irredundant clauses and all derived unit clauses
|
|
1007
|
+
// to a file in DIMACS format. Clauses on the extension stack are
|
|
1008
|
+
// not included, nor any redundant clauses.
|
|
1009
|
+
//
|
|
1010
|
+
// The 'min_max_var' parameter gives a lower bound on the number '<vars>'
|
|
1011
|
+
// of variables used in the DIMACS 'p cnf <vars> ...' header.
|
|
1012
|
+
//
|
|
1013
|
+
// Returns zero if successful and otherwise an error message.
|
|
1014
|
+
//
|
|
1015
|
+
// require (VALID)
|
|
1016
|
+
// ensure (VALID)
|
|
1017
|
+
//
|
|
1018
|
+
const char *write_dimacs (const char *path, int min_max_var = 0);
|
|
1019
|
+
|
|
1020
|
+
// The extension stack for reconstruction a solution can be written too.
|
|
1021
|
+
//
|
|
1022
|
+
const char *write_extension (const char *path);
|
|
1023
|
+
|
|
1024
|
+
// Print build configuration to a file with prefix 'c '. If the file
|
|
1025
|
+
// is '<stdout>' or '<stderr>' then terminal color codes might be used.
|
|
1026
|
+
//
|
|
1027
|
+
static void build (FILE *file, const char *prefix = "c ");
|
|
1028
|
+
|
|
1029
|
+
private:
|
|
1030
|
+
//==== start of state ====================================================
|
|
1031
|
+
|
|
1032
|
+
// The solver is in the state ADDING if either the current clause or the
|
|
1033
|
+
// constraint (or both) is not yet terminated.
|
|
1034
|
+
//
|
|
1035
|
+
bool adding_clause;
|
|
1036
|
+
bool adding_constraint;
|
|
1037
|
+
|
|
1038
|
+
State _state; // API states as discussed above.
|
|
1039
|
+
|
|
1040
|
+
/*----------------------------------------------------------------------*/
|
|
1041
|
+
|
|
1042
|
+
// The 'Solver' class is a 'facade' object for 'External'. It exposes the
|
|
1043
|
+
// public API of 'External' but hides everything else (except for the some
|
|
1044
|
+
// private functions). It is supposed to make it easier to understand the
|
|
1045
|
+
// API and use the solver through the API.
|
|
1046
|
+
//
|
|
1047
|
+
// This approach has the benefit of decoupling this header file from all
|
|
1048
|
+
// internal data structures, which is particularly useful if the rest of
|
|
1049
|
+
// the source is not available. For instance if only a CaDiCaL library is
|
|
1050
|
+
// installed in a system, then only this header file has to be installed
|
|
1051
|
+
// too, and still allows to compile and link against the library.
|
|
1052
|
+
|
|
1053
|
+
/*----------------------------------------------------------------------*/
|
|
1054
|
+
|
|
1055
|
+
// More precisely the CaDiCaL code is split into three layers:
|
|
1056
|
+
//
|
|
1057
|
+
// Solver: facade object providing the actual API of the solver
|
|
1058
|
+
// External: communication layer between 'Solver' and 'Internal'
|
|
1059
|
+
// Internal: the actual solver code
|
|
1060
|
+
//
|
|
1061
|
+
// The 'External' and 'Internal' layers are declared and implemented in
|
|
1062
|
+
// the corresponding '{external,internal}.{hpp,cpp}' files (as expected),
|
|
1063
|
+
// while the 'Solver' facade class is defined in 'cadical.hpp' (here) but
|
|
1064
|
+
// implemented in 'solver.cpp'. The reason for this naming mismatch is,
|
|
1065
|
+
// that we want to use 'cadical.hpp' for the library header (this header
|
|
1066
|
+
// file) and call the binary of the stand alone SAT also 'cadical', which
|
|
1067
|
+
// is more naturally implemented in 'cadical.cpp'.
|
|
1068
|
+
//
|
|
1069
|
+
// Separating 'External' from 'Internal' also allows us to map external
|
|
1070
|
+
// literals to internal literals, which is useful with many fixed or
|
|
1071
|
+
// eliminated variables (during 'compact' the internal variable range is
|
|
1072
|
+
// reduced and external variables are remapped). Such an approach is also
|
|
1073
|
+
// necessary, if we want to use extended resolution in the future (such as
|
|
1074
|
+
// bounded variable addition).
|
|
1075
|
+
//
|
|
1076
|
+
Internal *internal; // Hidden internal solver.
|
|
1077
|
+
External *external; // Hidden API to internal solver mapping.
|
|
1078
|
+
|
|
1079
|
+
friend class Testing; // Access to 'internal' for testing only!
|
|
1080
|
+
|
|
1081
|
+
#ifndef NTRACING
|
|
1082
|
+
// The API calls to the solver can be traced by setting the environment
|
|
1083
|
+
// variable 'CADICAL_API_TRACE' to point to the path of a file to which
|
|
1084
|
+
// API calls are written. The same format is used which 'mobical' can
|
|
1085
|
+
// read, execute and also shrink through delta debugging.
|
|
1086
|
+
//
|
|
1087
|
+
// The environment variable is read in the constructor and the trace is
|
|
1088
|
+
// opened for writing and then closed again in the destructor.
|
|
1089
|
+
//
|
|
1090
|
+
// Alternatively one case use 'trace_api_calls'.
|
|
1091
|
+
//
|
|
1092
|
+
bool close_trace_api_file; // Close file if owned by solver.
|
|
1093
|
+
FILE *trace_api_file; // Also acts as flag that we are tracing.
|
|
1094
|
+
|
|
1095
|
+
static bool tracing_api_through_environment;
|
|
1096
|
+
|
|
1097
|
+
//===== end of state ====================================================
|
|
1098
|
+
|
|
1099
|
+
void trace_api_call (const char *) const;
|
|
1100
|
+
void trace_api_call (const char *, int) const;
|
|
1101
|
+
void trace_api_call (const char *, int, int) const;
|
|
1102
|
+
void trace_api_call (const char *, const char *) const;
|
|
1103
|
+
void trace_api_call (const char *, const char *, int) const;
|
|
1104
|
+
#endif
|
|
1105
|
+
|
|
1106
|
+
void transition_to_steady_state ();
|
|
1107
|
+
|
|
1108
|
+
//------------------------------------------------------------------------
|
|
1109
|
+
// Used in the stand alone solver application 'App' and the model based
|
|
1110
|
+
// tester 'Mobical'. So only these two classes need direct access to the
|
|
1111
|
+
// otherwise more application specific functions listed here together with
|
|
1112
|
+
// the internal DIMACS parser.
|
|
1113
|
+
|
|
1114
|
+
friend class App;
|
|
1115
|
+
friend class Mobical;
|
|
1116
|
+
friend class Parser;
|
|
1117
|
+
|
|
1118
|
+
// Read solution in competition format for debugging and testing.
|
|
1119
|
+
//
|
|
1120
|
+
// require (VALID)
|
|
1121
|
+
// ensure (VALID)
|
|
1122
|
+
//
|
|
1123
|
+
const char *read_solution (const char *path);
|
|
1124
|
+
|
|
1125
|
+
// Cross-compilation with 'MinGW' needs some work-around for 'printf'
|
|
1126
|
+
// style printing of 64-bit numbers including warning messages. The
|
|
1127
|
+
// followings lines are copies of similar code in 'inttypes.hpp' but we
|
|
1128
|
+
// want to keep the 'cadical.hpp' header file stand-alone.
|
|
1129
|
+
|
|
1130
|
+
#ifndef PRINTF_FORMAT
|
|
1131
|
+
#ifdef __MINGW32__
|
|
1132
|
+
#define __USE_MINGW_ANSI_STDIO 1
|
|
1133
|
+
#define PRINTF_FORMAT __MINGW_PRINTF_FORMAT
|
|
1134
|
+
#else
|
|
1135
|
+
#define PRINTF_FORMAT printf
|
|
1136
|
+
#endif
|
|
1137
|
+
#endif
|
|
1138
|
+
|
|
1139
|
+
// Gives warning messages for wrong 'printf' style format string usage.
|
|
1140
|
+
// Apparently ('gcc 9' at least) the first argument is 'this' here.
|
|
1141
|
+
//
|
|
1142
|
+
// TODO: support for other compilers (beside 'gcc' and 'clang').
|
|
1143
|
+
|
|
1144
|
+
#define CADICAL_ATTRIBUTE_FORMAT(FORMAT_POSITION, \
|
|
1145
|
+
VARIADIC_ARGUMENT_POSITION) \
|
|
1146
|
+
__attribute__ ((format (PRINTF_FORMAT, FORMAT_POSITION, \
|
|
1147
|
+
VARIADIC_ARGUMENT_POSITION)))
|
|
1148
|
+
|
|
1149
|
+
// Messages in a common style.
|
|
1150
|
+
//
|
|
1151
|
+
// require (VALID | DELETING)
|
|
1152
|
+
// ensure (VALID | DELETING)
|
|
1153
|
+
//
|
|
1154
|
+
void section (const char *); // Print section header.
|
|
1155
|
+
void message (const char *, ...) // ordinary message.
|
|
1156
|
+
CADICAL_ATTRIBUTE_FORMAT (2, 3);
|
|
1157
|
+
|
|
1158
|
+
void message (); // Empty line - only prefix.
|
|
1159
|
+
void error (const char *, ...) // Produce error message.
|
|
1160
|
+
CADICAL_ATTRIBUTE_FORMAT (2, 3);
|
|
1161
|
+
|
|
1162
|
+
// Explicit verbose level ('section' and 'message' use '0').
|
|
1163
|
+
//
|
|
1164
|
+
// require (VALID | DELETING)
|
|
1165
|
+
// ensure (VALID | DELETING)
|
|
1166
|
+
//
|
|
1167
|
+
void verbose (int level, const char *, ...)
|
|
1168
|
+
CADICAL_ATTRIBUTE_FORMAT (3, 4);
|
|
1169
|
+
|
|
1170
|
+
// Factoring out common code to both 'read_dimacs' functions above.
|
|
1171
|
+
//
|
|
1172
|
+
// require (VALID)
|
|
1173
|
+
// ensure (VALID)
|
|
1174
|
+
//
|
|
1175
|
+
const char *read_dimacs (File *, int &, int strict, bool *incremental = 0,
|
|
1176
|
+
std::vector<int> * = 0);
|
|
1177
|
+
|
|
1178
|
+
// Factored out common code for 'solve', 'simplify' and 'lookahead'.
|
|
1179
|
+
//
|
|
1180
|
+
int call_external_solve_and_check_results (bool preprocess_only);
|
|
1181
|
+
|
|
1182
|
+
//------------------------------------------------------------------------
|
|
1183
|
+
// Print DIMACS file to '<stdout>' for debugging and testing purposes,
|
|
1184
|
+
// including derived units and assumptions. Since it will print in terms
|
|
1185
|
+
// of internal literals it is otherwise not really useful. To write a
|
|
1186
|
+
// DIMACS formula in terms of external variables use 'write_dimacs'.
|
|
1187
|
+
//
|
|
1188
|
+
// require (!INITIALIZING)
|
|
1189
|
+
// ensure (!INITIALIZING)
|
|
1190
|
+
//
|
|
1191
|
+
void dump_cnf ();
|
|
1192
|
+
friend struct DumpCall; // Mobical calls 'dump_cnf' in
|
|
1193
|
+
// 'DumpCall::execute ()'.
|
|
1194
|
+
|
|
1195
|
+
/*----------------------------------------------------------------------*/
|
|
1196
|
+
|
|
1197
|
+
// Used in mobical to test external propagation internally.
|
|
1198
|
+
// These functions should not be called for any other purposes.
|
|
1199
|
+
//
|
|
1200
|
+
ExternalPropagator *get_propagator ();
|
|
1201
|
+
bool observed (int lit);
|
|
1202
|
+
bool is_witness (int lit);
|
|
1203
|
+
|
|
1204
|
+
friend struct LemmaCall;
|
|
1205
|
+
friend struct ObserveCall;
|
|
1206
|
+
friend struct DisconnectCall;
|
|
1207
|
+
friend class MockPropagator;
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
/*========================================================================*/
|
|
1211
|
+
|
|
1212
|
+
// Connected terminators are checked for termination regularly. If the
|
|
1213
|
+
// 'terminate' function of the terminator returns true the solver is
|
|
1214
|
+
// terminated synchronously as soon it calls this function.
|
|
1215
|
+
|
|
1216
|
+
class Terminator {
|
|
1217
|
+
public:
|
|
1218
|
+
virtual ~Terminator () {}
|
|
1219
|
+
virtual bool terminate () = 0;
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
// Connected learners which can be used to export learned clauses.
|
|
1223
|
+
// The 'learning' can check the size of the learn clause and only if it
|
|
1224
|
+
// returns true then the individual literals of the learned clause are given
|
|
1225
|
+
// to the learn through 'learn' one by one terminated by a zero literal.
|
|
1226
|
+
|
|
1227
|
+
class Learner {
|
|
1228
|
+
public:
|
|
1229
|
+
virtual ~Learner () {}
|
|
1230
|
+
virtual bool learning (int size) = 0;
|
|
1231
|
+
virtual void learn (int lit) = 0;
|
|
1232
|
+
};
|
|
1233
|
+
|
|
1234
|
+
// Connected listener gets notified whenever the truth value of a variable
|
|
1235
|
+
// is fixed (for example during inprocessing or due to derived unit
|
|
1236
|
+
// clauses).
|
|
1237
|
+
|
|
1238
|
+
class FixedAssignmentListener {
|
|
1239
|
+
public:
|
|
1240
|
+
virtual ~FixedAssignmentListener () {}
|
|
1241
|
+
|
|
1242
|
+
virtual void notify_fixed_assignment (int) = 0;
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
/*------------------------------------------------------------------------*/
|
|
1246
|
+
|
|
1247
|
+
// Allows to connect an external propagator to propagate values to variables
|
|
1248
|
+
// with an external clause as a reason or to learn new clauses during the
|
|
1249
|
+
// CDCL loop (without restart).
|
|
1250
|
+
|
|
1251
|
+
class ExternalPropagator {
|
|
1252
|
+
|
|
1253
|
+
public:
|
|
1254
|
+
bool is_lazy = false; // Lazy propagator only checks complete assignments.
|
|
1255
|
+
|
|
1256
|
+
bool are_reasons_forgettable =
|
|
1257
|
+
false; // Reason external clauses can be deleted.
|
|
1258
|
+
|
|
1259
|
+
virtual ~ExternalPropagator () {}
|
|
1260
|
+
|
|
1261
|
+
// Notify the propagator about assignments to observed variables.
|
|
1262
|
+
// The notification is not necessarily eager. It usually happens before
|
|
1263
|
+
// the call of propagator callbacks and when a driving clause is leading
|
|
1264
|
+
// to an assignment.
|
|
1265
|
+
//
|
|
1266
|
+
virtual void notify_assignment (const std::vector<int> &lits) = 0;
|
|
1267
|
+
|
|
1268
|
+
// The notification for the assignement follow the standard trail
|
|
1269
|
+
// used in SAT solvers. The assignment is a stack with (possibly
|
|
1270
|
+
// empty) decisions. New assignments are pushed at the end of the
|
|
1271
|
+
// stack. When backtracking, you get the information on how many
|
|
1272
|
+
// decision (called levels in SAT solvers) you have to keep:
|
|
1273
|
+
// new_level mean that all decision and decision and assignments
|
|
1274
|
+
// before decision number new_level are kept, all other (at the end
|
|
1275
|
+
// of stack) are removed.
|
|
1276
|
+
//
|
|
1277
|
+
// In particular, when backtracking to level '0', no decision is
|
|
1278
|
+
// left and only assignments done before the first decision
|
|
1279
|
+
// (literals that have to be true in all models of the formula) are
|
|
1280
|
+
// kept. The number will always be lower than the number of
|
|
1281
|
+
// decisions on the trail, so backtracking will always have an
|
|
1282
|
+
// effect.
|
|
1283
|
+
//
|
|
1284
|
+
virtual void notify_new_decision_level () = 0;
|
|
1285
|
+
virtual void notify_backtrack (size_t new_level) = 0;
|
|
1286
|
+
|
|
1287
|
+
// Check by the external propagator the found complete solution
|
|
1288
|
+
// (after solution reconstruction). If it returns false, the
|
|
1289
|
+
// propagator should needs to explain why, either by providing an
|
|
1290
|
+
// external clause during the next callback or introduce new
|
|
1291
|
+
// observed variables during this callback.
|
|
1292
|
+
//
|
|
1293
|
+
virtual bool cb_check_found_model (const std::vector<int> &model) = 0;
|
|
1294
|
+
|
|
1295
|
+
// Ask the external propagator for the next decision literal. If it
|
|
1296
|
+
// returns '0', the solver makes its own choice. If it is an already
|
|
1297
|
+
// assigned variable or a non-valid literal (e.g., not observed), a
|
|
1298
|
+
// runtime error is triggered.
|
|
1299
|
+
//
|
|
1300
|
+
virtual int cb_decide () { return 0; };
|
|
1301
|
+
|
|
1302
|
+
// Ask the external propagator if there is an external propagation to make
|
|
1303
|
+
// under the current assignment. It returns either a literal to be
|
|
1304
|
+
// propagated or '0', indicating that there is no external propagation
|
|
1305
|
+
// under the current assignment.
|
|
1306
|
+
// In case the returned literal is not an observed variable, a runtime
|
|
1307
|
+
// error is triggered.
|
|
1308
|
+
//
|
|
1309
|
+
virtual int cb_propagate () { return 0; };
|
|
1310
|
+
|
|
1311
|
+
// Ask the external propagator for the reason clause of a previous
|
|
1312
|
+
// external propagation step (done by 'cb_propagate ()'). The clause must
|
|
1313
|
+
// be added literal-by-literal closed with a '0'. Further, the clause must
|
|
1314
|
+
// contain the propagated literal.
|
|
1315
|
+
//
|
|
1316
|
+
// The clause will be learned as an Irredundant Non-Forgettable Clause,
|
|
1317
|
+
// unless the 'are_reasons_forgettable' flag is changed (see below at
|
|
1318
|
+
// 'cb_has_external_clause ()' more details about it).
|
|
1319
|
+
//
|
|
1320
|
+
virtual int cb_add_reason_clause_lit (int propagated_lit) {
|
|
1321
|
+
(void) propagated_lit;
|
|
1322
|
+
return 0;
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
// The following two functions are used to add external clauses to the
|
|
1326
|
+
// solver during the CDCL loop. The external clause is added
|
|
1327
|
+
// literal-by-literal and learned by the solver as an irredundant
|
|
1328
|
+
// (original) input clause.
|
|
1329
|
+
//
|
|
1330
|
+
// The clause can be arbitrary, but if it is root-satisfied or tautology,
|
|
1331
|
+
// the solver will ignore it without learning it. Root-falsified literals
|
|
1332
|
+
// are eagerly removed from the clause. Falsified clauses trigger
|
|
1333
|
+
// conflict analysis, propagating clauses trigger propagation. In case
|
|
1334
|
+
// 'chrono' is '0', the solver backtracks to propagate the new literal on
|
|
1335
|
+
// the correct decision level, as otherwise it potentially will be an
|
|
1336
|
+
// out-of-order assignment on the current level.
|
|
1337
|
+
//
|
|
1338
|
+
// Unit clauses always (unless root-satisfied, see above) trigger
|
|
1339
|
+
// backtracking (independently from the value of the 'chrono' option and
|
|
1340
|
+
// independently from being falsified or satisfied or unassigned) to level
|
|
1341
|
+
// '0'. Empty clause (or root falsified clause, see above) makes the
|
|
1342
|
+
// problem 'UNSATISFIABLE' and stops the search immediately. A literal '0'
|
|
1343
|
+
// must close the clause.
|
|
1344
|
+
//
|
|
1345
|
+
// The external propagator indicates that there is a clause to add. The
|
|
1346
|
+
// parameter of the function allows the user to indicate that how
|
|
1347
|
+
// 'forgettable' is the external clause. Forgettable clauses are allowed
|
|
1348
|
+
// to be removed by the SAT solver during clause database reduction.
|
|
1349
|
+
// However, it is up to the solver to decide when actually the clause is
|
|
1350
|
+
// deleted. For example, unit clauses, even forgettable ones, will not be
|
|
1351
|
+
// deleted. In case the clause is not 'forgettable' (the parameter is
|
|
1352
|
+
// false), the solver considers the clause to be irredundant.
|
|
1353
|
+
//
|
|
1354
|
+
// In case the solver produces incremental proofs, these external clauses
|
|
1355
|
+
// are added to the proof during solving at real-time, i.e., the proof
|
|
1356
|
+
// checker can ignore them until that point (so added as input clause, but
|
|
1357
|
+
// input after the query line).
|
|
1358
|
+
//
|
|
1359
|
+
// Reason clauses of external propagation steps are assumed to be
|
|
1360
|
+
// forgettable, parameter 'reason_forgettable' can be used to change it.
|
|
1361
|
+
//
|
|
1362
|
+
// Currently, every external clause is expected to be over observed
|
|
1363
|
+
// (therefore frozen) variables, hence no tainting or restore steps
|
|
1364
|
+
// are performed upon their addition. This will be changed in later
|
|
1365
|
+
// versions probably.
|
|
1366
|
+
//
|
|
1367
|
+
virtual bool cb_has_external_clause (bool &is_forgettable) = 0;
|
|
1368
|
+
|
|
1369
|
+
// The actual function called to add the external clause.
|
|
1370
|
+
//
|
|
1371
|
+
virtual int cb_add_external_clause_lit () = 0;
|
|
1372
|
+
};
|
|
1373
|
+
|
|
1374
|
+
/*------------------------------------------------------------------------*/
|
|
1375
|
+
|
|
1376
|
+
// Allows to traverse all remaining irredundant clauses. Satisfied and
|
|
1377
|
+
// eliminated clauses are not included, nor any derived units unless such
|
|
1378
|
+
// a unit literal is frozen. Falsified literals are skipped. If the solver
|
|
1379
|
+
// is inconsistent only the empty clause is traversed.
|
|
1380
|
+
//
|
|
1381
|
+
// If 'clause' returns 'false' traversal aborts early.
|
|
1382
|
+
|
|
1383
|
+
class ClauseIterator {
|
|
1384
|
+
public:
|
|
1385
|
+
virtual ~ClauseIterator () {}
|
|
1386
|
+
virtual bool clause (const std::vector<int> &) = 0;
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
/*------------------------------------------------------------------------*/
|
|
1390
|
+
|
|
1391
|
+
// Allows to traverse all clauses on the extension stack together with their
|
|
1392
|
+
// witness cubes. If the solver is inconsistent, i.e., an empty clause is
|
|
1393
|
+
// found and the formula is unsatisfiable, then nothing is traversed.
|
|
1394
|
+
//
|
|
1395
|
+
// The clauses traversed in 'traverse_clauses' together with the clauses on
|
|
1396
|
+
// the extension stack are logically equivalent to the original clauses.
|
|
1397
|
+
// See our SAT'19 paper for more details.
|
|
1398
|
+
//
|
|
1399
|
+
// The witness literals can be used to extend and fix an assignment on the
|
|
1400
|
+
// remaining clauses to satisfy the clauses on the extension stack too.
|
|
1401
|
+
//
|
|
1402
|
+
// All derived units of non-frozen variables are included too, but
|
|
1403
|
+
// not the units for frozen literals.
|
|
1404
|
+
//
|
|
1405
|
+
// If 'witness' returns false traversal aborts early.
|
|
1406
|
+
|
|
1407
|
+
class WitnessIterator {
|
|
1408
|
+
public:
|
|
1409
|
+
virtual ~WitnessIterator () {}
|
|
1410
|
+
virtual bool witness (const std::vector<int> &clause,
|
|
1411
|
+
const std::vector<int> &witness,
|
|
1412
|
+
int64_t id = 0) = 0;
|
|
1413
|
+
};
|
|
1414
|
+
|
|
1415
|
+
/*------------------------------------------------------------------------*/
|
|
1416
|
+
|
|
1417
|
+
} // namespace CaDiCaL
|
|
1418
|
+
|
|
1419
|
+
#endif
|