1 |
|
/****************************************************************************************[Solver.h] |
2 |
|
Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson |
3 |
|
Copyright (c) 2007-2010, Niklas Sorensson |
4 |
|
|
5 |
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
6 |
|
associated documentation files (the "Software"), to deal in the Software without restriction, |
7 |
|
including without limitation the rights to use, copy, modify, merge, publish, distribute, |
8 |
|
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
9 |
|
furnished to do so, subject to the following conditions: |
10 |
|
|
11 |
|
The above copyright notice and this permission notice shall be included in all copies or |
12 |
|
substantial portions of the Software. |
13 |
|
|
14 |
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT |
15 |
|
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
16 |
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
17 |
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT |
18 |
|
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
19 |
|
**************************************************************************************************/ |
20 |
|
|
21 |
|
#ifndef BVMinisat_Solver_h |
22 |
|
#define BVMinisat_Solver_h |
23 |
|
|
24 |
|
#include <vector> |
25 |
|
|
26 |
|
#include "base/check.h" |
27 |
|
#include "context/context.h" |
28 |
|
#include "proof/clause_id.h" |
29 |
|
#include "prop/bvminisat/core/SolverTypes.h" |
30 |
|
#include "prop/bvminisat/mtl/Alg.h" |
31 |
|
#include "prop/bvminisat/mtl/Heap.h" |
32 |
|
#include "prop/bvminisat/mtl/Vec.h" |
33 |
|
#include "prop/bvminisat/utils/Options.h" |
34 |
|
#include "util/resource_manager.h" |
35 |
|
|
36 |
|
namespace cvc5 { |
37 |
|
|
38 |
|
namespace BVMinisat { |
39 |
|
class Solver; |
40 |
|
} |
41 |
|
|
42 |
|
namespace BVMinisat { |
43 |
|
|
44 |
|
/** Interface for minisat callbacks */ |
45 |
2 |
class Notify { |
46 |
|
|
47 |
|
public: |
48 |
|
|
49 |
2 |
virtual ~Notify() {} |
50 |
|
|
51 |
|
/** |
52 |
|
* If the notify returns false, the solver will break out of whatever it's currently doing |
53 |
|
* with an "unknown" answer. |
54 |
|
*/ |
55 |
|
virtual bool notify(Lit lit) = 0; |
56 |
|
|
57 |
|
/** |
58 |
|
* Notify about a new learnt clause with marked literals only. |
59 |
|
*/ |
60 |
|
virtual void notify(vec<Lit>& learnt) = 0; |
61 |
|
|
62 |
|
virtual void spendResource(Resource r) = 0; |
63 |
|
virtual void safePoint(Resource r) = 0; |
64 |
|
}; |
65 |
|
|
66 |
|
//================================================================================================= |
67 |
|
// Solver -- the main class: |
68 |
|
class Solver { |
69 |
|
public: |
70 |
|
typedef Var TVar; |
71 |
|
typedef Lit TLit; |
72 |
|
typedef Clause TClause; |
73 |
|
typedef CRef TCRef; |
74 |
|
typedef vec<Lit> TLitVec; |
75 |
|
|
76 |
|
static CRef TCRef_Undef; |
77 |
|
static CRef TCRef_Lazy; |
78 |
|
private: |
79 |
|
/** To notify */ |
80 |
|
Notify* d_notify; |
81 |
|
|
82 |
|
/** cvc5 context */ |
83 |
|
cvc5::context::Context* c; |
84 |
|
|
85 |
|
/** True constant */ |
86 |
|
Var varTrue; |
87 |
|
|
88 |
|
/** False constant */ |
89 |
|
Var varFalse; |
90 |
|
|
91 |
|
public: |
92 |
|
|
93 |
|
// Constructor/Destructor: |
94 |
|
// |
95 |
|
Solver(cvc5::context::Context* c); |
96 |
|
virtual ~Solver(); |
97 |
|
|
98 |
|
void setNotify(Notify* toNotify); |
99 |
|
|
100 |
|
// Problem specification: |
101 |
|
// |
102 |
|
Var newVar(bool polarity = true, |
103 |
|
bool dvar = true); // Add a new variable with parameters specifying |
104 |
|
// variable mode. |
105 |
|
Var trueVar() const { return varTrue; } |
106 |
|
Var falseVar() const { return varFalse; } |
107 |
|
|
108 |
|
bool addClause(const vec<Lit>& ps, |
109 |
|
ClauseId& id); // Add a clause to the solver. |
110 |
|
bool addEmptyClause(); // Add the empty clause, making the solver |
111 |
|
// contradictory. |
112 |
|
bool addClause(Lit p, ClauseId& id); // Add a unit clause to the solver. |
113 |
|
bool addClause(Lit p, |
114 |
|
Lit q, |
115 |
|
ClauseId& id); // Add a binary clause to the solver. |
116 |
|
bool addClause(Lit p, |
117 |
|
Lit q, |
118 |
|
Lit r, |
119 |
|
ClauseId& id); // Add a ternary clause to the solver. |
120 |
|
bool addClause_( |
121 |
|
vec<Lit>& ps, |
122 |
|
ClauseId& id); // Add a clause to the solver without making superflous |
123 |
|
// internal copy. Will change the passed vector 'ps'. |
124 |
|
|
125 |
|
// Solving: |
126 |
|
// |
127 |
|
bool simplify(); // Removes already satisfied clauses. |
128 |
|
lbool solve(const vec<Lit>& assumps); // Search for a model that respects a |
129 |
|
// given set of assumptions. |
130 |
|
lbool solveLimited( |
131 |
|
const vec<Lit>& assumps); // Search for a model that respects a given set |
132 |
|
// of assumptions (With resource constraints). |
133 |
|
lbool solve(); // Search without assumptions. |
134 |
|
lbool solve(Lit p); // Search for a model that respects a single assumption. |
135 |
|
lbool solve(Lit p, |
136 |
|
Lit q); // Search for a model that respects two assumptions. |
137 |
|
lbool solve(Lit p, |
138 |
|
Lit q, |
139 |
|
Lit r); // Search for a model that respects three assumptions. |
140 |
|
bool okay() const; // FALSE means solver is in a conflicting state |
141 |
|
lbool assertAssumption( |
142 |
|
Lit p, |
143 |
|
bool propagate); // Assert a new assumption, start BCP if propagate = true |
144 |
|
lbool propagateAssumptions(); // Do BCP over asserted assumptions |
145 |
|
void popAssumption(); // Pop an assumption |
146 |
|
|
147 |
|
void toDimacs(FILE* f, |
148 |
|
const vec<Lit>& assumps); // Write CNF to file in DIMACS-format. |
149 |
|
void toDimacs(const char* file, const vec<Lit>& assumps); |
150 |
|
void toDimacs(FILE* f, Clause& c, vec<Var>& map, Var& max); |
151 |
|
|
152 |
|
// Convenience versions of 'toDimacs()': |
153 |
|
void toDimacs(const char* file); |
154 |
|
void toDimacs(const char* file, Lit p); |
155 |
|
void toDimacs(const char* file, Lit p, Lit q); |
156 |
|
void toDimacs(const char* file, Lit p, Lit q, Lit r); |
157 |
|
|
158 |
|
// Variable mode: |
159 |
|
// |
160 |
|
void setPolarity( |
161 |
|
Var v, bool b); // Declare which polarity the decision heuristic should |
162 |
|
// use for a variable. Requires mode 'polarity_user'. |
163 |
|
void setDecisionVar(Var v, |
164 |
|
bool b); // Declare if a variable should be eligible for |
165 |
|
// selection in the decision heuristic. |
166 |
|
|
167 |
|
// Read state: |
168 |
|
// |
169 |
|
lbool value(Var x) const; // The current value of a variable. |
170 |
|
lbool value(Lit p) const; // The current value of a literal. |
171 |
|
lbool modelValue( |
172 |
|
Var x) const; // The value of a variable in the last model. The last call |
173 |
|
// to solve must have been satisfiable. |
174 |
|
lbool modelValue( |
175 |
|
Lit p) const; // The value of a literal in the last model. The last call |
176 |
|
// to solve must have been satisfiable. |
177 |
|
int nAssigns() const; // The current number of assigned literals. |
178 |
|
int nClauses() const; // The current number of original clauses. |
179 |
|
int nLearnts() const; // The current number of learnt clauses. |
180 |
|
int nVars() const; // The current number of variables. |
181 |
|
int nFreeVars() const; |
182 |
|
|
183 |
|
// Resource contraints: |
184 |
|
// |
185 |
|
void setConfBudget(int64_t x); |
186 |
|
void setPropBudget(int64_t x); |
187 |
|
void budgetOff(); |
188 |
|
void interrupt(); // Trigger a (potentially asynchronous) interruption of the |
189 |
|
// solver. |
190 |
|
void clearInterrupt(); // Clear interrupt indicator flag. |
191 |
|
|
192 |
|
// Memory managment: |
193 |
|
// |
194 |
|
virtual void garbageCollect(); |
195 |
|
void checkGarbage(double gf); |
196 |
|
void checkGarbage(); |
197 |
|
|
198 |
|
// Extra results: (read-only member variable) |
199 |
|
// |
200 |
|
vec<lbool> model; // If problem is satisfiable, this vector contains the model |
201 |
|
// (if any). |
202 |
|
vec<Lit> conflict; // If problem is unsatisfiable (possibly under |
203 |
|
// assumptions), this vector represent the final conflict |
204 |
|
// clause expressed in the assumptions. |
205 |
|
|
206 |
|
// Mode of operation: |
207 |
|
// |
208 |
|
int verbosity; |
209 |
|
double var_decay; |
210 |
|
double clause_decay; |
211 |
|
double random_var_freq; |
212 |
|
double random_seed; |
213 |
|
bool luby_restart; |
214 |
|
int ccmin_mode; // Controls conflict clause minimization (0=none, 1=basic, |
215 |
|
// 2=deep). |
216 |
|
int phase_saving; // Controls the level of phase saving (0=none, 1=limited, |
217 |
|
// 2=full). |
218 |
|
bool rnd_pol; // Use random polarities for branching heuristics. |
219 |
|
bool |
220 |
|
rnd_init_act; // Initialize variable activities with a small random value. |
221 |
|
double garbage_frac; // The fraction of wasted memory allowed before a garbage |
222 |
|
// collection is triggered. |
223 |
|
|
224 |
|
int restart_first; // The initial restart limit. (default 100) |
225 |
|
double restart_inc; // The factor with which the restart limit is multiplied |
226 |
|
// in each restart. (default 1.5) |
227 |
|
double |
228 |
|
learntsize_factor; // The intitial limit for learnt clauses is a factor of |
229 |
|
// the original clauses. (default 1 / 3) |
230 |
|
double learntsize_inc; // The limit for learnt clauses is multiplied with this |
231 |
|
// factor each restart. (default 1.1) |
232 |
|
|
233 |
|
int learntsize_adjust_start_confl; |
234 |
|
double learntsize_adjust_inc; |
235 |
|
|
236 |
|
// Statistics: (read-only member variable) |
237 |
|
// |
238 |
|
int64_t solves, starts, decisions, rnd_decisions, propagations, conflicts; |
239 |
|
int64_t dec_vars, clauses_literals, learnts_literals, max_literals, |
240 |
|
tot_literals; |
241 |
|
|
242 |
|
// Bitvector Propagations |
243 |
|
// |
244 |
|
|
245 |
|
void addMarkerLiteral(Var var); |
246 |
|
|
247 |
|
bool need_to_propagate; // true if we added new clauses, set to true in |
248 |
|
// propagation |
249 |
|
bool only_bcp; // solving mode in which only boolean constraint propagation is |
250 |
|
// done |
251 |
|
void setOnlyBCP(bool val) { only_bcp = val; } |
252 |
|
void explain(Lit l, std::vector<Lit>& explanation); |
253 |
|
|
254 |
|
protected: |
255 |
|
// has a clause been added |
256 |
|
bool clause_added; |
257 |
|
|
258 |
|
// Helper structures: |
259 |
|
// |
260 |
|
struct VarData |
261 |
|
{ |
262 |
|
CRef reason; |
263 |
|
int level; }; |
264 |
3568 |
static inline VarData mkVarData(CRef cr, int l){ VarData d = {cr, l}; return d; } |
265 |
|
|
266 |
|
struct Watcher { |
267 |
|
CRef cref; |
268 |
|
Lit blocker; |
269 |
8582 |
Watcher(CRef cr, Lit p) : cref(cr), blocker(p) {} |
270 |
|
bool operator==(const Watcher& w) const { return cref == w.cref; } |
271 |
444 |
bool operator!=(const Watcher& w) const { return cref != w.cref; } |
272 |
|
}; |
273 |
|
|
274 |
|
struct WatcherDeleted |
275 |
|
{ |
276 |
|
const ClauseAllocator& ca; |
277 |
2 |
WatcherDeleted(const ClauseAllocator& _ca) : ca(_ca) {} |
278 |
3538 |
bool operator()(const Watcher& w) const { return ca[w.cref].mark() == 1; } |
279 |
|
}; |
280 |
|
|
281 |
|
struct VarOrderLt { |
282 |
|
const vec<double>& activity; |
283 |
24048 |
bool operator () (Var x, Var y) const { return activity[x] > activity[y]; } |
284 |
2 |
VarOrderLt(const vec<double>& act) : activity(act) { } |
285 |
|
}; |
286 |
|
|
287 |
|
// Solver state: |
288 |
|
// |
289 |
|
bool ok; // If FALSE, the constraints are already unsatisfiable. No part of the solver state may be used! |
290 |
|
vec<CRef> clauses; // List of problem clauses. |
291 |
|
vec<CRef> learnts; // List of learnt clauses. |
292 |
|
double cla_inc; // Amount to bump next clause with. |
293 |
|
vec<double> activity; // A heuristic measurement of the activity of a variable. |
294 |
|
double var_inc; // Amount to bump next variable with. |
295 |
|
OccLists<Lit, vec<Watcher>, WatcherDeleted> |
296 |
|
watches; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true). |
297 |
|
vec<lbool> assigns; // The current assignments. |
298 |
|
vec<char> polarity; // The preferred polarity of each variable. |
299 |
|
vec<char> marker; // Is the variable a marker literal |
300 |
|
vec<char> decision; // Declares if a variable is eligible for selection in the decision heuristic. |
301 |
|
vec<Lit> trail; // Assignment stack; stores all assigments made in the order they were made. |
302 |
|
vec<int> trail_lim; // Separator indices for different decision levels in 'trail'. |
303 |
|
vec<VarData> vardata; // Stores reason and level for each variable. |
304 |
|
int qhead; // Head of queue (as index into the trail -- no more explicit propagation queue in MiniSat). |
305 |
|
int simpDB_assigns; // Number of top-level assignments since last execution of 'simplify()'. |
306 |
|
int64_t simpDB_props; // Remaining number of propagations that must be made before next execution of 'simplify()'. |
307 |
|
vec<Lit> assumptions; // Current set of assumptions provided to solve by the user. |
308 |
|
Heap<VarOrderLt> order_heap; // A priority queue of variables ordered with respect to the variable activity. |
309 |
|
double progress_estimate;// Set by 'search()'. |
310 |
|
bool remove_satisfied; // Indicates whether possibly inefficient linear scan for satisfied clauses should be performed in 'simplify'. |
311 |
|
|
312 |
|
ClauseAllocator ca; |
313 |
|
|
314 |
|
// Temporaries (to reduce allocation overhead). Each variable is prefixed by the method in which it is |
315 |
|
// used, exept 'seen' wich is used in several places. |
316 |
|
// |
317 |
|
vec<char> seen; |
318 |
|
vec<Lit> analyze_stack; |
319 |
|
vec<Lit> analyze_toclear; |
320 |
|
vec<Lit> add_tmp; |
321 |
|
|
322 |
|
double max_learnts; |
323 |
|
double learntsize_adjust_confl; |
324 |
|
int learntsize_adjust_cnt; |
325 |
|
|
326 |
|
// Resource contraints: |
327 |
|
// |
328 |
|
int64_t conflict_budget; // -1 means no budget. |
329 |
|
int64_t propagation_budget; // -1 means no budget. |
330 |
|
bool asynch_interrupt; |
331 |
|
|
332 |
|
// Main internal methods: |
333 |
|
// |
334 |
|
void insertVarOrder (Var x); // Insert a variable in the decision order priority queue. |
335 |
|
Lit pickBranchLit (); // Return the next decision variable. |
336 |
|
void newDecisionLevel (); // Begins a new decision level. |
337 |
|
void uncheckedEnqueue (Lit p, CRef from = CRef_Undef); // Enqueue a literal. Assumes value of literal is undefined. |
338 |
|
bool enqueue (Lit p, CRef from = CRef_Undef); // Test if fact 'p' contradicts current state, enqueue otherwise. |
339 |
|
CRef propagate (); // Perform unit propagation. Returns possibly conflicting clause. |
340 |
|
void cancelUntil (int level); // Backtrack until a certain level. |
341 |
|
|
342 |
|
enum UIP { |
343 |
|
UIP_FIRST, |
344 |
|
UIP_LAST |
345 |
|
}; |
346 |
|
|
347 |
|
void analyze (CRef confl, vec<Lit>& out_learnt, int& out_btlevel, UIP uip = UIP_FIRST); // (bt = backtrack) |
348 |
|
void analyzeFinal (Lit p, vec<Lit>& out_conflict); // COULD THIS BE IMPLEMENTED BY THE ORDINARIY "analyze" BY SOME REASONABLE GENERALIZATION? |
349 |
|
void analyzeFinal2(Lit p, CRef confl_clause, vec<Lit>& out_conflict); |
350 |
|
bool litRedundant (Lit p, uint32_t abstract_levels); // (helper method for 'analyze()') |
351 |
|
lbool search (int nof_conflicts, UIP uip = UIP_FIRST); // Search for a given number of conflicts. |
352 |
|
lbool solve_ (); // Main solve method (assumptions given in 'assumptions'). |
353 |
|
void reduceDB (); // Reduce the set of learnt clauses. |
354 |
|
void removeSatisfied (vec<CRef>& cs); // Shrink 'cs' to contain only non-satisfied clauses. |
355 |
|
void rebuildOrderHeap (); |
356 |
|
|
357 |
|
// Maintaining Variable/Clause activity: |
358 |
|
// |
359 |
|
void varDecayActivity (); // Decay all variables with the specified factor. Implemented by increasing the 'bump' value instead. |
360 |
|
void varBumpActivity (Var v, double inc); // Increase a variable with the current 'bump' value. |
361 |
|
void varBumpActivity (Var v); // Increase a variable with the current 'bump' value. |
362 |
|
void claDecayActivity (); // Decay all clauses with the specified factor. Implemented by increasing the 'bump' value instead. |
363 |
|
void claBumpActivity (Clause& c); // Increase a clause with the current 'bump' value. |
364 |
|
|
365 |
|
// Operations on clauses: |
366 |
|
// |
367 |
|
void attachClause (CRef cr); // Attach a clause to watcher lists. |
368 |
|
void detachClause (CRef cr, bool strict = false); // Detach a clause to watcher lists. |
369 |
|
void removeClause (CRef cr); // Detach and free a clause. |
370 |
|
bool locked (const Clause& c) const; // Returns TRUE if a clause is a reason for some implication in the current state. |
371 |
|
bool satisfied (const Clause& c) const; // Returns TRUE if a clause is satisfied in the current state. |
372 |
|
|
373 |
|
void relocAll (ClauseAllocator& to); |
374 |
|
|
375 |
|
// Misc: |
376 |
|
// |
377 |
|
int decisionLevel () const; // Gives the current decisionlevel. |
378 |
|
uint32_t abstractLevel (Var x) const; // Used to represent an abstraction of sets of decision levels. |
379 |
|
CRef reason (Var x) const; |
380 |
|
int level (Var x) const; |
381 |
|
double progressEstimate () const; // DELETE THIS ?? IT'S NOT VERY USEFUL ... |
382 |
|
bool withinBudget(Resource r) const; |
383 |
|
|
384 |
|
// Static helpers: |
385 |
|
// |
386 |
|
|
387 |
|
// Returns a random float 0 <= x < 1. Seed must never be 0. |
388 |
876 |
static inline double drand(double& seed) { |
389 |
876 |
seed *= 1389796; |
390 |
876 |
int q = (int)(seed / 2147483647); |
391 |
876 |
seed -= (double)q * 2147483647; |
392 |
876 |
return seed / 2147483647; } |
393 |
|
|
394 |
|
// Returns a random integer 0 <= x < size. Seed must never be 0. |
395 |
|
static inline int irand(double& seed, int size) { |
396 |
|
return (int)(drand(seed) * size); } |
397 |
|
|
398 |
|
// Less than for literals in an added clause when proofs are on. |
399 |
|
struct assign_lt { |
400 |
|
Solver& d_solver; |
401 |
|
assign_lt(Solver& solver) : d_solver(solver) {} |
402 |
|
bool operator () (Lit x, Lit y) { |
403 |
|
lbool x_value = d_solver.value(x); |
404 |
|
lbool y_value = d_solver.value(y); |
405 |
|
// Two unassigned literals are sorted arbitrarily |
406 |
|
if (x_value == l_Undef && y_value == l_Undef) { |
407 |
|
return x < y; |
408 |
|
} |
409 |
|
// Unassigned literals are put to front |
410 |
|
if (x_value == l_Undef) return true; |
411 |
|
if (y_value == l_Undef) return false; |
412 |
|
// Literals of the same value are sorted by decreasing levels |
413 |
|
if (x_value == y_value) { |
414 |
|
return d_solver.level(var(x)) > d_solver.level(var(y)); |
415 |
|
} else { |
416 |
|
// True literals go up front |
417 |
|
if (x_value == l_True) { |
418 |
|
return true; |
419 |
|
} else { |
420 |
|
return false; |
421 |
|
} |
422 |
|
} |
423 |
|
} |
424 |
|
}; |
425 |
|
|
426 |
|
}; |
427 |
|
|
428 |
|
|
429 |
|
//================================================================================================= |
430 |
|
// Implementation of inline methods: |
431 |
|
|
432 |
814 |
inline CRef Solver::reason(Var x) const |
433 |
|
{ |
434 |
814 |
Assert(x < vardata.size()); |
435 |
814 |
return vardata[x].reason; |
436 |
|
} |
437 |
3492 |
inline int Solver::level(Var x) const |
438 |
|
{ |
439 |
3492 |
Assert(x < vardata.size()); |
440 |
3492 |
return vardata[x].level; |
441 |
|
} |
442 |
|
|
443 |
3584 |
inline void Solver::insertVarOrder(Var x) { |
444 |
3584 |
if (!order_heap.inHeap(x) && decision[x]) order_heap.insert(x); } |
445 |
|
|
446 |
172 |
inline void Solver::varDecayActivity() { var_inc *= (1 / var_decay); } |
447 |
1168 |
inline void Solver::varBumpActivity(Var v) { varBumpActivity(v, var_inc); } |
448 |
1168 |
inline void Solver::varBumpActivity(Var v, double inc) { |
449 |
1168 |
if ( (activity[v] += inc) > 1e100 ) { |
450 |
|
// Rescale: |
451 |
|
for (int i = 0; i < nVars(); i++) |
452 |
|
activity[i] *= 1e-100; |
453 |
|
var_inc *= 1e-100; } |
454 |
|
|
455 |
|
// Update order_heap with respect to new activity: |
456 |
1168 |
if (order_heap.inHeap(v)) |
457 |
644 |
order_heap.decrease(v); } |
458 |
|
|
459 |
172 |
inline void Solver::claDecayActivity() { cla_inc *= (1 / clause_decay); } |
460 |
312 |
inline void Solver::claBumpActivity(Clause& clause) |
461 |
|
{ |
462 |
312 |
if ((clause.activity() += cla_inc) > 1e20) |
463 |
|
{ |
464 |
|
// Rescale: |
465 |
|
for (int i = 0; i < learnts.size(); i++) ca[learnts[i]].activity() *= 1e-20; |
466 |
|
cla_inc *= 1e-20; |
467 |
|
} |
468 |
312 |
} |
469 |
|
|
470 |
6 |
inline void Solver::checkGarbage(void){ return checkGarbage(garbage_frac); } |
471 |
252 |
inline void Solver::checkGarbage(double gf){ |
472 |
252 |
if (ca.wasted() > ca.size() * gf) |
473 |
2 |
garbageCollect(); } |
474 |
|
|
475 |
|
// NOTE: enqueue does not set the ok flag! (only public methods do) |
476 |
36 |
inline bool Solver::enqueue (Lit p, CRef from) { return value(p) != l_Undef ? value(p) != l_False : (uncheckedEnqueue(p, from), true); } |
477 |
|
inline bool Solver::addClause (const vec<Lit>& ps, ClauseId& id) { ps.copyTo(add_tmp); return addClause_(add_tmp, id); } |
478 |
|
inline bool Solver::addEmptyClause () { add_tmp.clear(); ClauseId tmp; return addClause_(add_tmp, tmp); } |
479 |
|
inline bool Solver::addClause (Lit p, ClauseId& id) { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp, id); } |
480 |
|
inline bool Solver::addClause (Lit p, Lit q, ClauseId& id) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp, id); } |
481 |
|
inline bool Solver::addClause (Lit p, Lit q, Lit r, ClauseId& id) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp, id); } |
482 |
742 |
inline bool Solver::locked(const Clause& clause) const |
483 |
|
{ |
484 |
1540 |
return value(clause[0]) == l_True && reason(var(clause[0])) != CRef_Undef |
485 |
1534 |
&& ca.lea(reason(var(clause[0]))) == &clause; |
486 |
|
} |
487 |
876 |
inline void Solver::newDecisionLevel() { trail_lim.push(trail.size()); } |
488 |
|
|
489 |
13348 |
inline int Solver::decisionLevel () const { return trail_lim.size(); } |
490 |
|
inline uint32_t Solver::abstractLevel (Var x) const { return 1 << (level(x) & 31); } |
491 |
3036 |
inline lbool Solver::value (Var x) const { return assigns[x]; } |
492 |
35872 |
inline lbool Solver::value (Lit p) const { return assigns[var(p)] ^ sign(p); } |
493 |
|
inline lbool Solver::modelValue (Var x) const { return model[x]; } |
494 |
|
inline lbool Solver::modelValue (Lit p) const { return model[var(p)] ^ sign(p); } |
495 |
900 |
inline int Solver::nAssigns () const { return trail.size(); } |
496 |
2 |
inline int Solver::nClauses () const { return clauses.size(); } |
497 |
|
inline int Solver::nLearnts () const { return learnts.size(); } |
498 |
1446 |
inline int Solver::nVars () const { return vardata.size(); } |
499 |
|
inline int Solver::nFreeVars () const { return (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]); } |
500 |
|
inline void Solver::setPolarity (Var v, bool b) { polarity[v] = b; } |
501 |
382 |
inline void Solver::setDecisionVar(Var v, bool b) |
502 |
|
{ |
503 |
382 |
if (b && !decision[v]) |
504 |
282 |
dec_vars++; |
505 |
100 |
else if (!b && decision[v]) |
506 |
96 |
dec_vars--; |
507 |
|
|
508 |
382 |
decision[v] = b; |
509 |
382 |
insertVarOrder(v); |
510 |
382 |
} |
511 |
|
inline void Solver::setConfBudget(int64_t x){ conflict_budget = conflicts + x; } |
512 |
|
inline void Solver::setPropBudget(int64_t x){ propagation_budget = propagations + x; } |
513 |
|
inline void Solver::interrupt(){ asynch_interrupt = true; } |
514 |
|
inline void Solver::clearInterrupt(){ asynch_interrupt = false; } |
515 |
2 |
inline void Solver::budgetOff(){ conflict_budget = propagation_budget = -1; } |
516 |
|
|
517 |
|
inline lbool Solver::solve () { budgetOff(); return solve_(); } |
518 |
|
inline lbool Solver::solve (Lit p) { budgetOff(); assumptions.push(p); return solve_(); } |
519 |
|
inline lbool Solver::solve (Lit p, Lit q) { budgetOff(); assumptions.push(p); assumptions.push(q); return solve_(); } |
520 |
|
inline lbool Solver::solve (Lit p, Lit q, Lit r) { budgetOff(); assumptions.push(p); assumptions.push(q); assumptions.push(r); return solve_(); } |
521 |
|
inline lbool Solver::solve (const vec<Lit>& assumps){ budgetOff(); assumps.copyTo(assumptions); return solve_(); } |
522 |
|
inline lbool Solver::solveLimited (const vec<Lit>& assumps){ assumps.copyTo(assumptions); return solve_(); } |
523 |
|
inline bool Solver::okay () const { return ok; } |
524 |
|
|
525 |
|
inline void Solver::toDimacs (const char* file){ vec<Lit> as; toDimacs(file, as); } |
526 |
|
inline void Solver::toDimacs (const char* file, Lit p){ vec<Lit> as; as.push(p); toDimacs(file, as); } |
527 |
|
inline void Solver::toDimacs (const char* file, Lit p, Lit q){ vec<Lit> as; as.push(p); as.push(q); toDimacs(file, as); } |
528 |
|
inline void Solver::toDimacs (const char* file, Lit p, Lit q, Lit r){ vec<Lit> as; as.push(p); as.push(q); as.push(r); toDimacs(file, as); } |
529 |
|
|
530 |
|
|
531 |
|
//================================================================================================= |
532 |
|
// Debug etc: |
533 |
|
|
534 |
|
|
535 |
|
//================================================================================================= |
536 |
|
} // namespace BVMinisat |
537 |
|
} // namespace cvc5 |
538 |
|
|
539 |
|
#endif |