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,487 @@
|
|
|
1
|
+
#ifndef _external_hpp_INCLUDED
|
|
2
|
+
#define _external_hpp_INCLUDED
|
|
3
|
+
|
|
4
|
+
/*------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
#include "range.hpp"
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
/*------------------------------------------------------------------------*/
|
|
12
|
+
|
|
13
|
+
namespace CaDiCaL {
|
|
14
|
+
|
|
15
|
+
using namespace std;
|
|
16
|
+
|
|
17
|
+
/*------------------------------------------------------------------------*/
|
|
18
|
+
|
|
19
|
+
// The CaDiCaL code is split into three layers:
|
|
20
|
+
//
|
|
21
|
+
// Solver: facade object providing the actual API of the solver
|
|
22
|
+
// External: communication layer between 'Solver' and 'Internal'
|
|
23
|
+
// Internal: the actual solver code
|
|
24
|
+
//
|
|
25
|
+
// Note, that 'Solver' is defined in 'cadical.hpp' and 'solver.cpp', while
|
|
26
|
+
// 'External' and 'Internal' in '{external,internal}.{hpp,cpp}'.
|
|
27
|
+
//
|
|
28
|
+
// Also note, that any user should access the library only through the
|
|
29
|
+
// 'Solver' API. For the library internal 'Parser' code we make an
|
|
30
|
+
// exception and allow access to both 'External' and 'Internal'. The former
|
|
31
|
+
// to enforce the same external to internal mapping of variables and the
|
|
32
|
+
// latter for profiling and messages. The same applies to 'App'.
|
|
33
|
+
//
|
|
34
|
+
// The 'External' class provided here stores the information needed to map
|
|
35
|
+
// external variable indices to internal variables (actually literals).
|
|
36
|
+
// This is helpful for shrinking the working size of the internal solver
|
|
37
|
+
// after many variables become inactive. It will also help to provide
|
|
38
|
+
// support for extended resolution in the future, since it allows to
|
|
39
|
+
// introduce only internally visible variables (even though we do not know
|
|
40
|
+
// how to support generating incremental proofs in this situation yet).
|
|
41
|
+
//
|
|
42
|
+
// External literals are usually called 'elit' and internal 'ilit'.
|
|
43
|
+
|
|
44
|
+
/*------------------------------------------------------------------------*/
|
|
45
|
+
|
|
46
|
+
struct Clause;
|
|
47
|
+
struct Internal;
|
|
48
|
+
struct CubesWithStatus;
|
|
49
|
+
|
|
50
|
+
/*------------------------------------------------------------------------*/
|
|
51
|
+
|
|
52
|
+
/*------------------------------------------------------------------------*/
|
|
53
|
+
|
|
54
|
+
struct External {
|
|
55
|
+
|
|
56
|
+
/*==== start of state ==================================================*/
|
|
57
|
+
|
|
58
|
+
Internal *internal; // The actual internal solver.
|
|
59
|
+
|
|
60
|
+
int max_var; // External maximum variable index.
|
|
61
|
+
size_t vsize; // Allocated external size.
|
|
62
|
+
|
|
63
|
+
vector<bool> vals; // Current external (extended) assignment.
|
|
64
|
+
vector<int> e2i; // External 'idx' to internal 'lit'.
|
|
65
|
+
|
|
66
|
+
vector<int> assumptions; // External assumptions.
|
|
67
|
+
vector<int> constraint; // External constraint. Terminated by zero.
|
|
68
|
+
|
|
69
|
+
vector<int64_t>
|
|
70
|
+
ext_units; // External units. Needed to compute LRAT for eclause
|
|
71
|
+
vector<bool> ext_flags; // to avoid duplicate units
|
|
72
|
+
vector<int> eclause; // External version of original input clause.
|
|
73
|
+
// The extension stack for reconstructing complete satisfying assignments
|
|
74
|
+
// (models) of the original external formula is kept in this external
|
|
75
|
+
// solver object. It keeps track of blocked clauses and clauses containing
|
|
76
|
+
// eliminated variable. These irredundant clauses are stored in terms of
|
|
77
|
+
// external literals on the 'extension' stack after mapping the
|
|
78
|
+
// internal literals given as arguments with 'externalize'.
|
|
79
|
+
|
|
80
|
+
bool extended; // Have been extended.
|
|
81
|
+
bool concluded;
|
|
82
|
+
vector<int> extension; // Solution reconstruction extension stack.
|
|
83
|
+
|
|
84
|
+
vector<bool> witness; // Literal witness on extension stack.
|
|
85
|
+
vector<bool> tainted; // Literal tainted in adding literals.
|
|
86
|
+
|
|
87
|
+
vector<bool> ervars; // Variables added through Extended Resolution.
|
|
88
|
+
|
|
89
|
+
vector<unsigned> frozentab; // Reference counts for frozen variables.
|
|
90
|
+
|
|
91
|
+
// Regularly checked terminator if non-zero. The terminator is set from
|
|
92
|
+
// 'Solver::set (Terminator *)' and checked by 'Internal::terminating ()'.
|
|
93
|
+
|
|
94
|
+
Terminator *terminator;
|
|
95
|
+
|
|
96
|
+
// If there is a learner export learned clauses.
|
|
97
|
+
|
|
98
|
+
Learner *learner;
|
|
99
|
+
|
|
100
|
+
void export_learned_empty_clause ();
|
|
101
|
+
void export_learned_unit_clause (int ilit);
|
|
102
|
+
void export_learned_large_clause (const vector<int> &);
|
|
103
|
+
|
|
104
|
+
// If there is a listener for fixed assignments.
|
|
105
|
+
|
|
106
|
+
FixedAssignmentListener *fixed_listener;
|
|
107
|
+
|
|
108
|
+
// If there is an external propagator.
|
|
109
|
+
|
|
110
|
+
ExternalPropagator *propagator;
|
|
111
|
+
|
|
112
|
+
vector<bool> is_observed; // Quick flag for each external variable
|
|
113
|
+
|
|
114
|
+
// Saved 'forgettable' original clauses coming from the external
|
|
115
|
+
// propagator. The value of the map starts with a Boolean flag indicating
|
|
116
|
+
// if the clause is still present or got already deleted, and then
|
|
117
|
+
// followed by the literals of the clause.
|
|
118
|
+
unordered_map<uint64_t, vector<int>> forgettable_original;
|
|
119
|
+
|
|
120
|
+
void add_observed_var (int elit);
|
|
121
|
+
void remove_observed_var (int elit);
|
|
122
|
+
void reset_observed_vars ();
|
|
123
|
+
|
|
124
|
+
bool observed (int elit);
|
|
125
|
+
bool is_witness (int elit);
|
|
126
|
+
bool is_decision (int elit);
|
|
127
|
+
|
|
128
|
+
void force_backtrack (int new_level);
|
|
129
|
+
|
|
130
|
+
//----------------------------------------------------------------------//
|
|
131
|
+
|
|
132
|
+
signed char *solution; // Given solution checking for debugging.
|
|
133
|
+
int solution_size; // Given solution checking for debugging.
|
|
134
|
+
vector<int> original; // Saved original formula for checking.
|
|
135
|
+
|
|
136
|
+
// If 'opts.checkfrozen' is set make sure that only literals are added
|
|
137
|
+
// which were never completely molten before. These molten literals are
|
|
138
|
+
// marked at the beginning of the 'solve' call. Note that variables
|
|
139
|
+
// larger than 'max_var' are not molten and can thus always be used in the
|
|
140
|
+
// future. Only needed to check and debug old style freeze semantics.
|
|
141
|
+
//
|
|
142
|
+
vector<bool> moltentab;
|
|
143
|
+
|
|
144
|
+
//----------------------------------------------------------------------//
|
|
145
|
+
|
|
146
|
+
const Range vars; // Provides safe variable iterations.
|
|
147
|
+
|
|
148
|
+
/*==== end of state ====================================================*/
|
|
149
|
+
|
|
150
|
+
// These two just factor out common sanity (assertion) checking code.
|
|
151
|
+
|
|
152
|
+
inline int vidx (int elit) const {
|
|
153
|
+
assert (elit);
|
|
154
|
+
assert (elit != INT_MIN);
|
|
155
|
+
int res = abs (elit);
|
|
156
|
+
assert (res <= max_var);
|
|
157
|
+
return res;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
inline int vlit (int elit) const {
|
|
161
|
+
assert (elit);
|
|
162
|
+
assert (elit != INT_MIN);
|
|
163
|
+
assert (abs (elit) <= max_var);
|
|
164
|
+
return elit;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
inline bool is_valid_input (int elit) {
|
|
168
|
+
assert (elit);
|
|
169
|
+
assert (elit != INT_MIN);
|
|
170
|
+
int eidx = abs (elit);
|
|
171
|
+
return eidx > max_var || !ervars[eidx];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/*----------------------------------------------------------------------*/
|
|
175
|
+
|
|
176
|
+
// The following five functions push individual literals or clauses on the
|
|
177
|
+
// extension stack. They all take internal literals as argument, and map
|
|
178
|
+
// them back to external literals first, before pushing them on the stack.
|
|
179
|
+
|
|
180
|
+
void push_zero_on_extension_stack ();
|
|
181
|
+
|
|
182
|
+
// Our general version of extension stacks always pushes a set of witness
|
|
183
|
+
// literals (for variable elimination the literal of the eliminated
|
|
184
|
+
// literal and for blocked clauses the blocking literal) followed by all
|
|
185
|
+
// the clause literals starting with and separated by zero.
|
|
186
|
+
//
|
|
187
|
+
void push_clause_literal_on_extension_stack (int ilit);
|
|
188
|
+
void push_witness_literal_on_extension_stack (int ilit);
|
|
189
|
+
|
|
190
|
+
void push_clause_on_extension_stack (Clause *);
|
|
191
|
+
void push_clause_on_extension_stack (Clause *, int witness);
|
|
192
|
+
void push_binary_clause_on_extension_stack (int64_t id, int witness,
|
|
193
|
+
int other);
|
|
194
|
+
|
|
195
|
+
// The main 'extend' function which extends an internal assignment to an
|
|
196
|
+
// external assignment using the extension stack (and sets 'extended').
|
|
197
|
+
//
|
|
198
|
+
void extend ();
|
|
199
|
+
void conclude_sat ();
|
|
200
|
+
|
|
201
|
+
/*----------------------------------------------------------------------*/
|
|
202
|
+
|
|
203
|
+
// Marking external literals.
|
|
204
|
+
|
|
205
|
+
unsigned elit2ulit (int elit) const {
|
|
206
|
+
assert (elit);
|
|
207
|
+
assert (elit != INT_MIN);
|
|
208
|
+
const int idx = abs (elit) - 1;
|
|
209
|
+
assert (idx <= max_var);
|
|
210
|
+
return 2u * idx + (elit < 0);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
bool marked (const vector<bool> &map, int elit) const {
|
|
214
|
+
const unsigned ulit = elit2ulit (elit);
|
|
215
|
+
return ulit < map.size () ? map[ulit] : false;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
void mark (vector<bool> &map, int elit) {
|
|
219
|
+
const unsigned ulit = elit2ulit (elit);
|
|
220
|
+
if (ulit >= map.size ())
|
|
221
|
+
map.resize (ulit + 1, false);
|
|
222
|
+
map[ulit] = true;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
void unmark (vector<bool> &map, int elit) {
|
|
226
|
+
const unsigned ulit = elit2ulit (elit);
|
|
227
|
+
if (ulit < map.size ())
|
|
228
|
+
map[ulit] = false;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/*----------------------------------------------------------------------*/
|
|
232
|
+
|
|
233
|
+
void push_external_clause_and_witness_on_extension_stack (
|
|
234
|
+
const vector<int> &clause, const vector<int> &witness, int64_t id);
|
|
235
|
+
|
|
236
|
+
void push_id_on_extension_stack (int64_t id);
|
|
237
|
+
|
|
238
|
+
// Restore a clause, which was pushed on the extension stack.
|
|
239
|
+
void restore_clause (const vector<int>::const_iterator &begin,
|
|
240
|
+
const vector<int>::const_iterator &end,
|
|
241
|
+
const int64_t id);
|
|
242
|
+
|
|
243
|
+
void restore_clauses ();
|
|
244
|
+
|
|
245
|
+
/*----------------------------------------------------------------------*/
|
|
246
|
+
|
|
247
|
+
// Explicitly freeze and melt literals (instead of just freezing
|
|
248
|
+
// internally and implicitly assumed literals). Passes on freezing and
|
|
249
|
+
// melting to the internal solver, which has separate frozen counters.
|
|
250
|
+
|
|
251
|
+
void freeze (int elit);
|
|
252
|
+
void melt (int elit);
|
|
253
|
+
|
|
254
|
+
bool frozen (int elit) {
|
|
255
|
+
assert (elit);
|
|
256
|
+
assert (elit != INT_MIN);
|
|
257
|
+
int eidx = abs (elit);
|
|
258
|
+
if (eidx > max_var)
|
|
259
|
+
return false;
|
|
260
|
+
if (eidx >= (int) frozentab.size ())
|
|
261
|
+
return false;
|
|
262
|
+
return frozentab[eidx] > 0;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/*----------------------------------------------------------------------*/
|
|
266
|
+
|
|
267
|
+
External (Internal *);
|
|
268
|
+
~External ();
|
|
269
|
+
|
|
270
|
+
void enlarge (int new_max_var); // Enlarge allocated 'vsize'.
|
|
271
|
+
void init (int new_max_var,
|
|
272
|
+
bool extension = false); // Initialize up-to 'new_max_var'.
|
|
273
|
+
|
|
274
|
+
int internalize (
|
|
275
|
+
int,
|
|
276
|
+
bool extension = false); // Translate external to internal literal.
|
|
277
|
+
|
|
278
|
+
/*----------------------------------------------------------------------*/
|
|
279
|
+
|
|
280
|
+
// According to the CaDiCaL API contract (as well as IPASIR) we have to
|
|
281
|
+
// forget about the previous assumptions after a 'solve' call. This
|
|
282
|
+
// should however be delayed until we transition out of an 'UNSATISFIED'
|
|
283
|
+
// state, i.e., after no more 'failed' calls are expected. Note that
|
|
284
|
+
// 'failed' requires to know the failing assumptions, and the 'failed'
|
|
285
|
+
// status of those should cleared before at start of the next 'solve'.
|
|
286
|
+
// As a consequence 'reset_assumptions' is only called from
|
|
287
|
+
// 'transition_to_unknown_state' in API calls in 'solver.cpp'.
|
|
288
|
+
|
|
289
|
+
void reset_assumptions ();
|
|
290
|
+
|
|
291
|
+
// Similarly to 'failed', 'conclude' needs to know about failing
|
|
292
|
+
// assumptions and therefore needs to be reset when leaving the
|
|
293
|
+
// 'UNSATISFIED' state.
|
|
294
|
+
//
|
|
295
|
+
void reset_concluded ();
|
|
296
|
+
|
|
297
|
+
// Similarly a valid external assignment obtained through 'extend' has to
|
|
298
|
+
// be reset at each point it risks to become invalid. This is done
|
|
299
|
+
// in the external layer in 'external.cpp' functions..
|
|
300
|
+
|
|
301
|
+
void reset_extended ();
|
|
302
|
+
|
|
303
|
+
// Finally, the semantics of incremental solving also require that limits
|
|
304
|
+
// are only valid for the next 'solve' call. Since the limits can not
|
|
305
|
+
// really be queried, handling them is less complex and they are just
|
|
306
|
+
// reset immediately at the end of 'External::solve'.
|
|
307
|
+
|
|
308
|
+
void reset_limits ();
|
|
309
|
+
|
|
310
|
+
/*----------------------------------------------------------------------*/
|
|
311
|
+
|
|
312
|
+
// Proxies to IPASIR functions.
|
|
313
|
+
|
|
314
|
+
void add (int elit);
|
|
315
|
+
void assume (int elit);
|
|
316
|
+
int solve (bool preprocess_only);
|
|
317
|
+
|
|
318
|
+
// We call it 'ival' as abbreviation for 'val' with 'int' return type to
|
|
319
|
+
// avoid bugs due to using 'signed char tmp = val (lit)', which might turn
|
|
320
|
+
// a negative value into a positive one (happened in 'extend').
|
|
321
|
+
|
|
322
|
+
// This is due to the IPASIR semantics which returns 'elit' if it is
|
|
323
|
+
// 'true' and '-elit' if it is 'false'. This is a bit confusing but has
|
|
324
|
+
// been standardized in IPASIR:
|
|
325
|
+
//
|
|
326
|
+
// Consiert 'eidx = 13' and 'vals[13] == false' then '13' is 'false' in
|
|
327
|
+
// this terminology of the IPASIR interface. Accordingly we get
|
|
328
|
+
//
|
|
329
|
+
// ival (13) = -13
|
|
330
|
+
//
|
|
331
|
+
// However and this is the confusing thing, as '-13' is true the 'ival'
|
|
332
|
+
// function should also return '-13':
|
|
333
|
+
//
|
|
334
|
+
// ival (-13) = -13
|
|
335
|
+
//
|
|
336
|
+
// Now with '13' assumed 'true' so 'vals[13] = true' we similarly have
|
|
337
|
+
//
|
|
338
|
+
// ival (13) = 13 as '13' is true'
|
|
339
|
+
//
|
|
340
|
+
// ival (-13) = 13 as '-13' is false
|
|
341
|
+
//
|
|
342
|
+
// To summarize we can think of the IPASIR 'ipasir_val' function, which
|
|
343
|
+
// 'CaDiCaL' follows as returning the phase of the literal which is true
|
|
344
|
+
// under the current assignment no matter whether you give the positive
|
|
345
|
+
// literal or its negation and thus 'ival (lit) == ival (-lit))"
|
|
346
|
+
|
|
347
|
+
inline int ival (int elit) const {
|
|
348
|
+
assert (elit != INT_MIN);
|
|
349
|
+
int eidx = abs (elit);
|
|
350
|
+
bool val = false;
|
|
351
|
+
if (eidx <= max_var && (size_t) eidx < vals.size ())
|
|
352
|
+
val = vals[eidx];
|
|
353
|
+
if (elit < 0)
|
|
354
|
+
val = !val;
|
|
355
|
+
return val ? elit : -elit;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
bool flip (int elit);
|
|
359
|
+
bool flippable (int elit);
|
|
360
|
+
|
|
361
|
+
bool failed (int elit);
|
|
362
|
+
|
|
363
|
+
void terminate ();
|
|
364
|
+
|
|
365
|
+
// Other important non IPASIR functions.
|
|
366
|
+
|
|
367
|
+
/*----------------------------------------------------------------------*/
|
|
368
|
+
|
|
369
|
+
// Add literal to external constraint.
|
|
370
|
+
//
|
|
371
|
+
void constrain (int elit);
|
|
372
|
+
|
|
373
|
+
// Returns true if 'solve' returned 20 because of the constraint.
|
|
374
|
+
//
|
|
375
|
+
bool failed_constraint ();
|
|
376
|
+
|
|
377
|
+
// Deletes the current constraint clause. Called on
|
|
378
|
+
// 'transition_to_unknown_state' and if a new constraint is added. Can be
|
|
379
|
+
// called directly using the API.
|
|
380
|
+
//
|
|
381
|
+
void reset_constraint ();
|
|
382
|
+
|
|
383
|
+
/*----------------------------------------------------------------------*/
|
|
384
|
+
|
|
385
|
+
int propagate_assumptions ();
|
|
386
|
+
void implied (std::vector<int> &entrailed);
|
|
387
|
+
void conclude_unknown ();
|
|
388
|
+
|
|
389
|
+
/*----------------------------------------------------------------------*/
|
|
390
|
+
int lookahead ();
|
|
391
|
+
CaDiCaL::CubesWithStatus generate_cubes (int, int);
|
|
392
|
+
|
|
393
|
+
int fixed (int elit) const; // Implemented in 'internal.hpp'.
|
|
394
|
+
|
|
395
|
+
/*----------------------------------------------------------------------*/
|
|
396
|
+
|
|
397
|
+
void phase (int elit);
|
|
398
|
+
void unphase (int elit);
|
|
399
|
+
|
|
400
|
+
/*----------------------------------------------------------------------*/
|
|
401
|
+
|
|
402
|
+
// Traversal functions for the witness stack and units. The explanation
|
|
403
|
+
// in 'external.cpp' for why we have to distinguish these cases.
|
|
404
|
+
|
|
405
|
+
bool traverse_all_frozen_units_as_clauses (ClauseIterator &);
|
|
406
|
+
bool traverse_all_non_frozen_units_as_witnesses (WitnessIterator &);
|
|
407
|
+
bool traverse_witnesses_backward (WitnessIterator &);
|
|
408
|
+
bool traverse_witnesses_forward (WitnessIterator &);
|
|
409
|
+
|
|
410
|
+
/*----------------------------------------------------------------------*/
|
|
411
|
+
|
|
412
|
+
// Copy flags for determining preprocessing state.
|
|
413
|
+
|
|
414
|
+
void copy_flags (External &other) const;
|
|
415
|
+
|
|
416
|
+
/*----------------------------------------------------------------------*/
|
|
417
|
+
|
|
418
|
+
// Check solver behaves as expected during testing and debugging.
|
|
419
|
+
|
|
420
|
+
void check_assumptions_satisfied ();
|
|
421
|
+
void check_constraint_satisfied ();
|
|
422
|
+
void check_failing ();
|
|
423
|
+
|
|
424
|
+
void check_solution_on_learned_clause ();
|
|
425
|
+
void check_solution_on_shrunken_clause (Clause *);
|
|
426
|
+
void check_solution_on_learned_unit_clause (int unit);
|
|
427
|
+
void check_no_solution_after_learning_empty_clause ();
|
|
428
|
+
|
|
429
|
+
void check_learned_empty_clause () {
|
|
430
|
+
if (solution)
|
|
431
|
+
check_no_solution_after_learning_empty_clause ();
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
void check_learned_unit_clause (int unit) {
|
|
435
|
+
if (solution)
|
|
436
|
+
check_solution_on_learned_unit_clause (unit);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
void check_learned_clause () {
|
|
440
|
+
if (solution)
|
|
441
|
+
check_solution_on_learned_clause ();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
void check_shrunken_clause (Clause *c) {
|
|
445
|
+
if (solution)
|
|
446
|
+
check_solution_on_shrunken_clause (c);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
void check_assignment (int (External::*assignment) (int) const);
|
|
450
|
+
|
|
451
|
+
void check_satisfiable ();
|
|
452
|
+
void check_unsatisfiable ();
|
|
453
|
+
|
|
454
|
+
void check_solve_result (int res);
|
|
455
|
+
|
|
456
|
+
void update_molten_literals ();
|
|
457
|
+
|
|
458
|
+
/*----------------------------------------------------------------------*/
|
|
459
|
+
|
|
460
|
+
// For debugging and testing only. See 'solution.hpp' for more details.
|
|
461
|
+
// TODO: if elit > solution_size, elit is an extension variable. For now
|
|
462
|
+
// the clause will count as satisfied regardless. For the future one
|
|
463
|
+
// should check that actually there is one consistent extension for the
|
|
464
|
+
// solution that satisfies the clauses with this extension variable (by
|
|
465
|
+
// setting it to a value once a clause is learned which is not satisfied
|
|
466
|
+
// already).
|
|
467
|
+
//
|
|
468
|
+
inline int sol (int elit) const {
|
|
469
|
+
assert (solution);
|
|
470
|
+
assert (elit != INT_MIN);
|
|
471
|
+
int eidx = abs (elit);
|
|
472
|
+
if (eidx > max_var)
|
|
473
|
+
return 0;
|
|
474
|
+
else if (eidx > solution_size)
|
|
475
|
+
return elit;
|
|
476
|
+
signed char value = solution[eidx];
|
|
477
|
+
if (!value)
|
|
478
|
+
return 0;
|
|
479
|
+
if (elit < 0)
|
|
480
|
+
value = -value;
|
|
481
|
+
return value > 0 ? elit : -elit;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
} // namespace CaDiCaL
|
|
486
|
+
|
|
487
|
+
#endif
|