ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Solver.h
Go to the documentation of this file.
1/****************************************************************************************[Solver.h]
2 Glucose -- Copyright (c) 2009, Gilles Audemard, Laurent Simon
3 CRIL - Univ. Artois, France
4 LRI - Univ. Paris Sud, France
5
6Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of
7Glucose are exactly the same as Minisat on which it is based on. (see below).
8
9---------------
10Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
11Copyright (c) 2007-2010, Niklas Sorensson
12
13Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
14associated documentation files (the "Software"), to deal in the Software without restriction,
15including without limitation the rights to use, copy, modify, merge, publish, distribute,
16sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions:
18
19The above copyright notice and this permission notice shall be included in all copies or
20substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
23NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
26OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27**************************************************************************************************/
28
29#ifndef Glucose_Solver_h
30#define Glucose_Solver_h
31
32#include "sat/glucose2/Vec.h"
33#include "sat/glucose2/Heap.h"
34#include "sat/glucose2/Alg.h"
39
41
43
44namespace Gluco2 {
45
46//=================================================================================================
47// Solver -- the main class:
48
49class Solver {
50public:
51
52 int SolverType; // ABC identifies Glucose's type as 0
53
54 // Constructor/Destructor:
55 //
56 Solver();
57 virtual ~Solver();
58
59 // ABC callbacks
60 void * pCnfMan; // external CNF manager
61 int(*pCnfFunc)(void * p, int, int*); // external callback. messages: 0: unsat; 1: sat; -1: still working
62 int nCallConfl; // callback will be called every this number of conflicts
63 bool terminate_search_early; // used to stop the solver early if it as instructed by an external caller
64 int * pstop; // another callback
65 uint64_t nRuntimeLimit; // runtime limit
68
69 // circuit-based solving
70 int jftr;
71 void sat_solver_set_var_fanin_lit(int, int, int);
73 void sat_solver_mark_cone(int);
74 void sat_solver_set_jftr(int);
75 int sat_solver_jftr();
76 void sat_solver_reset();
77
78 // Problem specification:
79 //
80 Var newVar (bool polarity = true, bool dvar = true); // Add a new variable with parameters specifying variable mode.
81 void addVar (Var v); // Add enough variables to make sure there is variable v.
82
83 bool addClause (const vec<Lit>& ps); // Add a clause to the solver.
84 bool addEmptyClause(); // Add the empty clause, making the solver contradictory.
85 bool addClause (Lit p); // Add a unit clause to the solver.
86 bool addClause (Lit p, Lit q); // Add a binary clause to the solver.
87 bool addClause (Lit p, Lit q, Lit r); // Add a ternary clause to the solver.
88 bool addClause_( vec<Lit>& ps); // Add a clause to the solver without making superflous internal copy. Will
89 // change the passed vector 'ps'.
90
91 // Solving:
92 //
93 bool simplify (); // Removes already satisfied clauses.
94 bool solve (const vec<Lit>& assumps); // Search for a model that respects a given set of assumptions.
95 lbool solveLimited (const vec<Lit>& assumps); // Search for a model that respects a given set of assumptions (With resource constraints).
96 bool solve (); // Search without assumptions.
97 bool solve (Lit p); // Search for a model that respects a single assumption.
98 bool solve (Lit p, Lit q); // Search for a model that respects two assumptions.
99 bool solve (Lit p, Lit q, Lit r); // Search for a model that respects three assumptions.
100 bool okay () const; // FALSE means solver is in a conflicting state
101
102 void toDimacs (FILE* f, const vec<Lit>& assumps); // Write CNF to file in DIMACS-format.
103 void toDimacs (const char *file, const vec<Lit>& assumps);
104 void toDimacs (FILE* f, Clause& c, vec<Var>& map, Var& max);
105 void printLit(Lit l);
106 void printClause(CRef c);
107 void printInitialClause(CRef c);
108 // Convenience versions of 'toDimacs()':
109 void toDimacs (const char* file);
110 void toDimacs (const char* file, Lit p);
111 void toDimacs (const char* file, Lit p, Lit q);
112 void toDimacs (const char* file, Lit p, Lit q, Lit r);
113
114 // Variable mode:
115 //
116 void setPolarity (Var v, bool b); // Declare which polarity the decision heuristic should use for a variable. Requires mode 'polarity_user'.
117 void setDecisionVar (Var v, bool b, bool use_oheap = true); // Declare if a variable should be eligible for selection in the decision heuristic.
118
119 // Read state:
120 //
121 lbool value (Var x) const; // The current value of a variable.
122 lbool value (Lit p) const; // The current value of a literal.
123 lbool modelValue (Var x) const; // The value of a variable in the last model. The last call to solve must have been satisfiable.
124 lbool modelValue (Lit p) const; // The value of a literal in the last model. The last call to solve must have been satisfiable.
125 int nAssigns () const; // The current number of assigned literals.
126 int nClauses () const; // The current number of original clauses.
127 int nLearnts () const; // The current number of learnt clauses.
128 int nVars () const; // The current number of variables.
129 int nFreeVars () const;
130 int * getCex () const;
131 int level (Var x) const; // moved level() to public to compile "struct JustOrderLt" -- alanmi
132
133 // Incremental mode
134 void setIncrementalMode();
135 void initNbInitialVars(int nb);
137
138 // Resource contraints:
139 //
140 void setConfBudget(int64_t x);
141 void setPropBudget(int64_t x);
142 void budgetOff();
143 void interrupt(); // Trigger a (potentially asynchronous) interruption of the solver.
144 void clearInterrupt(); // Clear interrupt indicator flag.
145
146 // Memory managment:
147 //
148 virtual void reset();
149 virtual void garbageCollect(); // virtuality causes segfault for some reason
150 void checkGarbage(double gf);
151 void checkGarbage();
152
153
154
155
156 // Extra results: (read-only member variable)
157 //
158 vec<lbool> model; // If problem is satisfiable, this vector contains the model (if any).
159 vec<Lit> conflict; // If problem is unsatisfiable (possibly under assumptions),
160 // this vector represent the final conflict clause expressed in the assumptions.
161
162 // Mode of operation:
163 //
167 // Constants For restarts
168 double K;
169 double R;
172
173 // Constants for reduce DB
177 unsigned int lbLBDFrozenClause;
178
179 // Constant for reducing clause
182
183 double var_decay;
187 int ccmin_mode; // Controls conflict clause minimization (0=none, 1=basic, 2=deep).
188 int phase_saving; // Controls the level of phase saving (0=none, 1=limited, 2=full).
189 bool rnd_pol; // Use random polarities for branching heuristics.
190 bool rnd_init_act; // Initialize variable activities with a small random value.
191 double garbage_frac; // The fraction of wasted memory allowed before a garbage collection is triggered.
192
193 // Certified UNSAT ( Thanks to Marijn Heule)
196
197
198 // Statistics: (read-only member variable)
199 //
202
203protected:
205 // Helper structures:
206 //
207 struct VarData { CRef reason; int level; };
208 static inline VarData mkVarData(CRef cr, int l){ VarData d = {cr, l}; return d; }
209
210 struct Watcher {
213 Watcher(CRef cr, Lit p) : cref(cr), blocker(p) {}
214 bool operator==(const Watcher& w) const { return cref == w.cref; }
215 bool operator!=(const Watcher& w) const { return cref != w.cref; }
216 };
217
219 {
221 WatcherDeleted(const ClauseAllocator& _ca) : ca(_ca) {}
222 bool operator()(const Watcher& w) const { return ca[w.cref].mark() == 1; }
223 };
224
225 struct VarOrderLt {
227 bool operator () (Var x, Var y) const { return activity[x] > activity[y]; }
228 VarOrderLt(const vec<double>& act) : activity(act) { }
229 };
230
231
232 // Solver state:
233 //
235 bool ok; // If FALSE, the constraints are already unsatisfiable. No part of the solver state may be used!
236 double cla_inc; // Amount to bump next clause with.
237 vec<double> activity; // A heuristic measurement of the activity of a variable.
238 double var_inc; // Amount to bump next variable with.
240 watches; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true).
242 watchesBin; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true).
243 vec<CRef> clauses; // List of problem clauses.
244 vec<CRef> learnts; // List of learnt clauses.
245
246 vec<lbool> assigns; // The current assignments.
247 vec<char> polarity; // The preferred polarity of each variable.
248 vec<char> decision; // Declares if a variable is eligible for selection in the decision heuristic.
249 vec<Lit> trail; // Assignment stack; stores all assigments made in the order they were made.
251 vec<int> trail_lim; // Separator indices for different decision levels in 'trail'.
252 vec<VarData> vardata; // Stores reason and level for each variable.
253 int qhead; // Head of queue (as index into the trail -- no more explicit propagation queue in MiniSat).
254 int simpDB_assigns; // Number of top-level assignments since last execution of 'simplify()'.
255 int64_t simpDB_props; // Remaining number of propagations that must be made before next execution of 'simplify()'.
256 vec<Lit> assumptions; // Current set of assumptions provided to solve by the user.
257 Heap<VarOrderLt> order_heap; // A priority queue of variables ordered with respect to the variable activity.
258 double progress_estimate;// Set by 'search()'.
259 bool remove_satisfied; // Indicates whether possibly inefficient linear scan for satisfied clauses should be performed in 'simplify'.
260 vec<unsigned int> permDiff; // permDiff[var] contains the current conflict number... Used to count the number of LBD
261
262#ifdef UPDATEVARACTIVITY
263 // UPDATEVARACTIVITY trick (see competition'09 companion paper)
264 vec<Lit> lastDecisionLevel;
265#endif
266
268
269 int nbclausesbeforereduce; // To know when it is time to reduce clause database
270
271 bqueue<unsigned int> trailQueue,lbdQueue; // Bounded queues for restarts.
272 float sumLBD; // used to compute the global average of LBD. Restarts...
274
275
276 // Temporaries (to reduce allocation overhead). Each variable is prefixed by the method in which it is
277 // used, exept 'seen' wich is used in several places.
278 //
283 unsigned int MYFLAG;
284
285
289
290 // Resource contraints:
291 //
292 int64_t conflict_budget; // -1 means no budget.
293 int64_t propagation_budget; // -1 means no budget.
295
296
297 // Variables added for incremental mode
298 int incremental; // Use incremental SAT Solver
299 int nbVarsInitialFormula; // nb VAR in formula without assumptions (incremental SAT)
303
304
305 // Main internal methods:
306 //
307 void insertVarOrder (Var x); // Insert a variable in the decision order priority queue.
308 Lit pickBranchLit (); // Return the next decision variable.
309 void newDecisionLevel (); // Begins a new decision level.
310 void uncheckedEnqueue (Lit p, CRef from = CRef_Undef); // Enqueue a literal. Assumes value of literal is undefined.
311 bool enqueue (Lit p, CRef from = CRef_Undef); // Test if fact 'p' contradicts current state, enqueue otherwise.
312 CRef propagate (); // Perform unit propagation. Returns possibly conflicting clause.
313 void cancelUntil (int level); // Backtrack until a certain level.
314 void analyze (CRef confl, vec<Lit>& out_learnt, vec<Lit> & selectors, int& out_btlevel,unsigned int &nblevels,unsigned int &szWithoutSelectors); // (bt = backtrack)
315 void analyzeFinal (Lit p, vec<Lit>& out_conflict); // COULD THIS BE IMPLEMENTED BY THE ORDINARIY "analyze" BY SOME REASONABLE GENERALIZATION?
316 bool litRedundant (Lit p, uint32_t abstract_levels); // (helper method for 'analyze()')
317 lbool search (int nof_conflicts); // Search for a given number of conflicts.
318 lbool solve_ (); // Main solve method (assumptions given in 'assumptions').
319 void reduceDB (); // Reduce the set of learnt clauses.
320 void removeSatisfied (vec<CRef>& cs); // Shrink 'cs' to contain only non-satisfied clauses.
321 void rebuildOrderHeap ();
322
323 // Maintaining Variable/Clause activity:
324 //
325 void varDecayActivity (); // Decay all variables with the specified factor. Implemented by increasing the 'bump' value instead.
326 void varBumpActivity (Var v, double inc); // Increase a variable with the current 'bump' value.
327 void varBumpActivity (Var v); // Increase a variable with the current 'bump' value.
328 void claDecayActivity (); // Decay all clauses with the specified factor. Implemented by increasing the 'bump' value instead.
329 void claBumpActivity (Clause& c); // Increase a clause with the current 'bump' value.
330
331 // Operations on clauses:
332 //
333 void attachClause (CRef cr); // Attach a clause to watcher lists.
334 void detachClause (CRef cr, bool strict = false); // Detach a clause to watcher lists.
335 void removeClause (CRef cr); // Detach and free a clause.
336 bool locked (const Clause& c) const; // Returns TRUE if a clause is a reason for some implication in the current state.
337 bool satisfied (const Clause& c) const; // Returns TRUE if a clause is satisfied in the current state.
338
339 unsigned int computeLBD(const vec<Lit> & lits,int end=-1);
340 unsigned int computeLBD(const Clause &c);
342
343 void relocAll (ClauseAllocator& to);
344
345 // Misc:
346 //
347 int decisionLevel () const; // Gives the current decisionlevel.
348 uint32_t abstractLevel (Var x) const; // Used to represent an abstraction of sets of decision levels.
349 CRef reason (Var x) const;
350 double progressEstimate () const; // DELETE THIS ?? IT'S NOT VERY USEFUL ...
351 bool withinBudget () const;
352 inline bool isSelector(Var v) {return (incremental && v>nbVarsInitialFormula);}
353
354 // Static helpers:
355 //
356
357 // Returns a random float 0 <= x < 1. Seed must never be 0.
358 static inline double drand(double& seed) {
359 seed *= 1389796;
360 int q = (int)(seed / 2147483647);
361 seed -= (double)q * 2147483647;
362 return seed / 2147483647; }
363
364 // Returns a random integer 0 <= x < size. Seed must never be 0.
365 static inline int irand(double& seed, int size) {
366 return (int)(drand(seed) * size); }
367
368
369 // circuit-based solver
370protected:
371 void uncheckedEnqueue2(Lit p, CRef from = CRef_Undef);
373
374 void addJwatch( Var host, Var member, int index );
375 //void delJwatch( Var member );
376
377 struct NodeData { Lit lit0; Lit lit1; unsigned sort:30; unsigned dir:1; unsigned now:1; };
378 static inline NodeData mkNodeData(){ NodeData w; w.lit0 = toLit(~0); w.lit1 = toLit(~0); w.sort = 0; w.dir = 0; w.now = 0; return w; }
380 //vec<Lit> var2FaninLits; // (~0): undefine
383 CRef itpc; // the interpreted clause of a gate
384 void inplace_sort( Var v );
385
386 bool isTwoFanin ( Var v ) const ; // this var has two fanins
387 bool isAND ( Var v ) const { return getFaninVar0(v) < getFaninVar1(v); }
388 bool isJReason ( Var v ) const { return isTwoFanin(v) && ( l_False == value(v) || (!isAND(v) && l_Undef != value(v)) ); }
389 Lit getFaninLit0( Var v ) const { return var2NodeData[ v ].lit0; }
390 Lit getFaninLit1( Var v ) const { return var2NodeData[ v ].lit1; }
391 bool getFaninC0 ( Var v ) const { return sign(getFaninLit0(v)); }
392 bool getFaninC1 ( Var v ) const { return sign(getFaninLit1(v)); }
393 Var getFaninVar0( Var v ) const { return var(getFaninLit0(v)); }
394 Var getFaninVar1( Var v ) const { return var(getFaninLit1(v)); }
395 Lit getFaninPlt0( Var v ) const { return mkLit(getFaninVar0(v), 1 == polarity[getFaninVar0(v)]); }
396 Lit getFaninPlt1( Var v ) const { return mkLit(getFaninVar1(v), 1 == polarity[getFaninVar1(v)]); }
397 Lit maxActiveLit(Lit lit0, Lit lit1) const { return activity[var(lit0)] < activity[var(lit1)]? lit1: lit0; }
398
399 Lit gateJustFanin(Var v) const ; // l_Undef=satisfied, 0/1 = fanin0/fanin1 requires justify
400 void gateAddJwatch(Var v,int index);
404 void setItpcSize( int sz ); // sz <= 3
405
406 // directly call by original glucose functions
407 void updateJustActivity( Var v );
408 void ResetJustData(bool fCleanMemory);
409 Lit pickJustLit( int& index );
410 void justCheck();
411 void pushJustQueue(Var v, int index);
412 void restoreJustQueue(int level); // call with cancelUntil
413 void gateClearJwatch( Var v, int backtrack_level );
414
416
417 CRef interpret( Var v, Var t );
418 CRef castCRef( Lit p ); // interpret a gate into a clause
420
421 CRef Var2CRef( Var v ) const { return v | (1<<(sizeof(CRef)*8-1)); }
422 Var CRef2Var( CRef cr ) const { return cr & ~(1<<(sizeof(CRef)*8-1)); }
423 bool isGateCRef( CRef cr ) const { return CRef_Undef != cr && 0 != (cr & (1<<(sizeof(CRef)*8-1))); }
424
426
427 //Heap<JustOrderLt> jheap;
428 int jhead;
429
430 struct JustKey {
431 typedef double Key;
432 typedef Var Data;
433 typedef int Attr;
437 Data data() const { return _data; }
438 Key key() const { return _key; }
439 Attr attr() const { return _attr; }
440 JustKey():_key(0),_data(0),_attr(0){}
441 JustKey( const Key& nkey, const Data& ndata, const Attr& nattr ): _key(nkey), _data(ndata), _attr(nattr) {}
442 };
444 const Solver * pS;
445 bool operator () (const JustKey& x, const JustKey& y) const {
446 if( x.key() != y.key() ) return x.key() > y.key();
447 if( pS->level( x.data() ) != pS->level( y.data() ) )
448 return pS->level( x.data() ) < pS->level( y.data() );
449 return x.data() > y.data();
450 }
451 JustOrderLt2(const Solver * _pS) : pS(_pS) { }
452 };
456
458 void loadJust_rec( Var v );
459 void loadJust();
461public:
462 void markTill( Var v0, int nlim );
463 void markApprox( Var v0, Var v1, int nlim );
464
465 void prelocate( int var_num );
466 void setVarFaninLits( Var v, Lit lit1, Lit lit2 );
467 void setVarFaninLits( int v, int lit1, int lit2 ){ setVarFaninLits( Var(v), toLit(lit1), toLit(lit2) ); }
468 //void delVarFaninLits( Var v);
469
470 void setNewRound(){ travId ++ ; }
471 void markCone( Var v );
472 void setJust( int njftr ){ jftr = njftr; }
473 bool isRoundWatch( Var v ) const { return travId==var2TravId[v]; }
474 void justReset(){ jftr = 0; reset(); }
475
476
477 //const JustData& getJustData(int v) const { return jdata[v]; }
478 double varActivity(int v) const { return activity[v];}
479 //double justActivity(int v) const { return jdata[v].act_fanin;}
480 int varPolarity(int v){ return polarity[v]? 1: 0;}
481 vec<Lit> JustModel; // model obtained by justification enabled
482
483 int justUsage() const ;
484 int solveLimited( int * , int nlits );
485};
486
487
488//=================================================================================================
489// Implementation of inline methods:
490
491inline CRef Solver::reason(Var x) const { return vardata[x].reason; }
492inline int Solver::level (Var x) const { return vardata[x].level; }
493
495 #ifdef CGLUCOSE_EXP
496 if (!justUsage() && !order_heap.inHeap(x) && decision[x]) order_heap.insert(x);
497 #else
498 if (!order_heap.inHeap(x) && decision[x]) order_heap.insert(x);
499 #endif
500}
501
502inline void Solver::varDecayActivity() { var_inc *= (1 / var_decay); }
504inline void Solver::varBumpActivity(Var v, double inc) {
505 if ( (activity[v] += inc) > 1e100 ) {
506 heap_rescale = 1;
507 // Rescale:
508 for (int i = 0; i < nVars(); i++)
509 activity[i] *= 1e-100;
510 var_inc *= 1e-100; }
511
512 // Update order_heap with respect to new activity:
513 if (!justUsage() && order_heap.inHeap(v))
514 order_heap.decrease(v);
515}
516
519 if ( (c.activity() += cla_inc) > 1e20 ) {
520 // Rescale:
521 for (int i = 0; i < learnts.size(); i++)
522 ca[learnts[i]].activity() *= (float)1e-20;
523 cla_inc *= 1e-20; } }
524
526inline void Solver::checkGarbage(double gf){
527 if (ca.wasted() > ca.size() * gf)
529
530// NOTE: enqueue does not set the ok flag! (only public methods do)
531inline bool Solver::enqueue (Lit p, CRef from) { return value(p) != l_Undef ? value(p) != l_False : (uncheckedEnqueue(p, from), true); }
532inline bool Solver::addClause (const vec<Lit>& ps) { ps.copyTo(add_tmp); return addClause_(add_tmp); }
533inline bool Solver::addEmptyClause () { add_tmp.clear(); return addClause_(add_tmp); }
534inline bool Solver::addClause (Lit p) { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp); }
535inline bool Solver::addClause (Lit p, Lit q) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp); }
536inline bool Solver::addClause (Lit p, Lit q, Lit r) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp); }
537inline bool Solver::locked (const Clause& c) const {
538 #ifdef CGLUCOSE_EXP
539
540 if(c.size()>2)
541 return value(c[0]) == l_True && reason(var(c[0])) != CRef_Undef && !isGateCRef(reason(var(c[0]))) && ca.lea(reason(var(c[0]))) == &c;
542 return
543 (value(c[0]) == l_True && reason(var(c[0])) != CRef_Undef && !isGateCRef(reason(var(c[0]))) && ca.lea(reason(var(c[0]))) == &c)
544 ||
545 (value(c[1]) == l_True && reason(var(c[1])) != CRef_Undef && !isGateCRef(reason(var(c[1]))) && ca.lea(reason(var(c[1]))) == &c);
546
547 #else
548
549 if(c.size()>2)
550 return value(c[0]) == l_True && reason(var(c[0])) != CRef_Undef && ca.lea(reason(var(c[0]))) == &c;
551 return
552 (value(c[0]) == l_True && reason(var(c[0])) != CRef_Undef && ca.lea(reason(var(c[0]))) == &c)
553 ||
554 (value(c[1]) == l_True && reason(var(c[1])) != CRef_Undef && ca.lea(reason(var(c[1]))) == &c);
555
556 #endif
557 }
558inline void Solver::newDecisionLevel() {trail_lim.push(trail.size());}
559
560inline int Solver::decisionLevel () const { return trail_lim.size(); }
561inline uint32_t Solver::abstractLevel (Var x) const { return 1 << (level(x) & 31); }
562inline lbool Solver::value (Var x) const { return assigns[x]; }
563inline lbool Solver::value (Lit p) const { return assigns[var(p)] ^ sign(p); }
564inline lbool Solver::modelValue (Var x) const { return model[x]; }
565inline lbool Solver::modelValue (Lit p) const { return model[var(p)] ^ sign(p); }
566inline int Solver::nAssigns () const { return trail.size(); }
567inline int Solver::nClauses () const { return clauses.size(); }
568inline int Solver::nLearnts () const { return learnts.size(); }
569inline int Solver::nVars () const { return vardata.size(); }
570inline int Solver::nFreeVars () const { return (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]); }
571inline int * Solver::getCex () const { return (int*) &JustModel[0]; }
572inline void Solver::setPolarity (Var v, bool b) { polarity[v] = b; }
573inline void Solver::setDecisionVar(Var v, bool b, bool use_oheap)
574{
575 if ( b && !decision[v]) dec_vars++;
576 else if (!b && decision[v]) dec_vars--;
577
578 decision[v] = b;
579 if( use_oheap ) insertVarOrder(v);
580}
581inline void Solver::setConfBudget(int64_t x){ conflict_budget = conflicts + x; }
583inline void Solver::interrupt(){ asynch_interrupt = true; }
586inline bool Solver::withinBudget() const {
587 return !asynch_interrupt &&
588 (conflict_budget < 0 || conflicts < (uint64_t)conflict_budget) &&
590
591// FIXME: after the introduction of asynchronous interrruptions the solve-versions that return a
592// pure bool do not give a safe interface. Either interrupts must be possible to turn off here, or
593// all calls to solve must return an 'lbool'. I'm not yet sure which I prefer.
594inline bool Solver::solve () { budgetOff(); assumptions.clear(); return solve_() == l_True; }
595inline bool Solver::solve (Lit p) { budgetOff(); assumptions.clear(); assumptions.push(p); return solve_() == l_True; }
596inline bool Solver::solve (Lit p, Lit q) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); return solve_() == l_True; }
597inline bool Solver::solve (Lit p, Lit q, Lit r) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); assumptions.push(r); return solve_() == l_True; }
598inline bool Solver::solve (const vec<Lit>& assumps){ budgetOff(); assumps.copyTo(assumptions); return solve_() == l_True; }
599inline lbool Solver::solveLimited (const vec<Lit>& assumps){ assumps.copyTo(assumptions); return solve_(); }
600inline bool Solver::okay () const { return ok; }
601
602inline void Solver::toDimacs (const char* file){ vec<Lit> as; toDimacs(file, as); }
603inline void Solver::toDimacs (const char* file, Lit p){ vec<Lit> as; as.push(p); toDimacs(file, as); }
604inline void Solver::toDimacs (const char* file, Lit p, Lit q){ vec<Lit> as; as.push(p); as.push(q); toDimacs(file, as); }
605inline 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); }
606
607inline void Solver::addVar(Var v) { while (v >= nVars()) newVar(); }
608
609inline void Solver::sat_solver_set_var_fanin_lit(int v, int lit0, int lit1) { setVarFaninLits( Var(v), toLit(lit0), toLit(lit1) ); }
611inline void Solver::sat_solver_mark_cone(int v) { markCone(v); }
612inline void Solver::sat_solver_set_jftr( int njftr ){ setJust(njftr); }
613inline int Solver::sat_solver_jftr(){ return jftr; }
615inline int Solver::solveLimited( int * lit0, int nlits ){
616 assumptions.clear();
617 for(int i = 0; i < nlits; i ++)
618 assumptions.push(toLit(lit0[i]));
619 lbool res = solve_();
620 return res == l_True ? 1 : (res == l_False ? -1 : 0);
621}
622//=================================================================================================
623// Debug etc:
624
625
626inline void Solver::printLit(Lit l)
627{
628 printf("%s%d:%c", sign(l) ? "-" : "", var(l)+1, value(l) == l_True ? '1' : (value(l) == l_False ? '0' : 'X'));
629}
630
631
633{
634 Clause &c = ca[cr];
635 for (int i = 0; i < c.size(); i++){
636 printLit(c[i]);
637 printf(" ");
638 }
639}
640
642{
643 Clause &c = ca[cr];
644 for (int i = 0; i < c.size(); i++){
645 if(!isSelector(var(c[i]))) {
646 printLit(c[i]);
647 printf(" ");
648 }
649 }
650}
651
652
653//=================================================================================================
654}
655
656
658
660
661#endif
unsigned int uint32_t
Definition Fxch.h:32
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
ABC_NAMESPACE_IMPL_START typedef signed char value
#define sat_solver_mark_cone
Definition cecSatG2.c:52
#define sat_solver_set_var_fanin_lit
Definition cecSatG2.c:50
#define sat_solver_set_jftr
Definition cecSatG2.c:49
float & activity()
vec< Lit > user_lits
Definition Solver.h:67
vec< int > initialPositions
Definition Solver.h:302
int varPolarity(int v)
Definition Solver.h:480
CRef interpret(Var v, Var t)
vec< int > user_vec
Definition Solver.h:66
vec< double > activity
Definition Solver.h:237
OccLists< Lit, vec< Watcher >, WatcherDeleted > watchesBin
Definition Solver.h:242
void insertVarOrder(Var x)
Definition Solver.h:494
void varDecayActivity()
Definition Solver.h:502
Lit pickJustLit(int &index)
Lit pickBranchLit()
Definition Glucose2.cpp:565
int incReduceDB
Definition Solver.h:175
bool addClause_(vec< Lit > &ps)
Definition Glucose2.cpp:268
vec< int > nbpos
Definition Solver.h:250
unsigned int MYFLAG
Definition Solver.h:283
int64_t decisions
Definition Solver.h:200
bool withinBudget() const
Definition Solver.h:586
uint64_t nRuntimeLimit
Definition Solver.h:65
int64_t learnts_literals
Definition Solver.h:201
lbool search(int nof_conflicts)
void toDimacs(FILE *f, const vec< Lit > &assumps)
CRef gatePropagateCheckFanout(Var v, Lit lfo)
vec< Lit > JustModel
Definition Solver.h:481
void claDecayActivity()
Definition Solver.h:517
int64_t clauses_literals
Definition Solver.h:201
bool isGateCRef(CRef cr) const
Definition Solver.h:423
void interrupt()
Definition Solver.h:583
double var_inc
Definition Solver.h:238
double clause_decay
Definition Solver.h:184
vec< int > assumptionPositions
Definition Solver.h:302
vec< Lit > conflict
Definition Solver.h:159
int nbVarsInitialFormula
Definition Solver.h:299
vec< Lit > trail
Definition Solver.h:249
void inplace_sort(Var v)
bool enqueue(Lit p, CRef from=CRef_Undef)
Definition Solver.h:531
void addVar(Var v)
Definition Solver.h:607
void cancelUntil(int level)
Definition Glucose2.cpp:515
static VarData mkVarData(CRef cr, int l)
Definition Solver.h:208
vec< unsigned int > permDiff
Definition Solver.h:260
uint32_t abstractLevel(Var x) const
Definition Solver.h:561
void addJwatch(Var host, Var member, int index)
unsigned int computeLBD(const vec< Lit > &lits, int end=-1)
Definition Glucose2.cpp:411
void markApprox(Var v0, Var v1, int nlim)
bool litRedundant(Lit p, uint32_t abstract_levels)
Definition Glucose2.cpp:841
long curRestart
Definition Solver.h:204
Var getFaninVar1(Var v) const
Definition Solver.h:394
vec< Lit > var2FanoutN
Definition Solver.h:382
int justUsage() const
bool locked(const Clause &c) const
Definition Solver.h:537
vec< unsigned > var2TravId
Definition Solver.h:381
vec< char > polarity
Definition Solver.h:247
Lit maxActiveLit(Lit lit0, Lit lit1) const
Definition Solver.h:397
int nbclausesbeforereduce
Definition Solver.h:269
vec< VarData > vardata
Definition Solver.h:252
int64_t simpDB_props
Definition Solver.h:255
int learntsize_adjust_cnt
Definition Solver.h:288
int64_t nbstopsrestarts
Definition Solver.h:200
unsigned int lbLBDFrozenClause
Definition Solver.h:177
void printClause(CRef c)
Definition Solver.h:632
vec< char > decision
Definition Solver.h:248
vec< Lit > analyze_stack
Definition Solver.h:280
void sat_solver_reset()
Definition Solver.h:614
double progress_estimate
Definition Solver.h:258
OccLists< Lit, vec< Watcher >, WatcherDeleted > watches
Definition Solver.h:240
void justReset()
Definition Solver.h:474
virtual void garbageCollect()
double progressEstimate() const
void relocAll(ClauseAllocator &to)
ClauseAllocator ca
Definition Solver.h:267
unsigned travId_prev
Definition Solver.h:425
CRef gatePropagateCheckThis(Var v)
int64_t conflicts
Definition Solver.h:200
vec< Lit > add_tmp
Definition Solver.h:282
void ResetJustData(bool fCleanMemory)
void removeClause(CRef cr)
Definition Glucose2.cpp:377
int level(Var x) const
Definition Solver.h:492
bool asynch_interrupt
Definition Solver.h:294
bool addEmptyClause()
Definition Solver.h:533
void printLit(Lit l)
Definition Solver.h:626
int64_t dec_vars
Definition Solver.h:201
int64_t nbUn
Definition Solver.h:200
void setItpcSize(int sz)
int nVars() const
Definition Solver.h:569
virtual void reset()
int64_t lastblockatrestart
Definition Solver.h:200
void restoreJustQueue(int level)
void sat_solver_start_new_round()
Definition Solver.h:610
void setDecisionVar(Var v, bool b, bool use_oheap=true)
Definition Solver.h:573
CRef getConfClause(CRef r)
vec< Lit > analyze_toclear
Definition Solver.h:281
void prelocate(int var_num)
void detachClause(CRef cr, bool strict=false)
Definition Glucose2.cpp:350
int sumAssumptions
Definition Solver.h:273
void rebuildOrderHeap()
int verbEveryConflicts
Definition Solver.h:165
vec< Var > vMarked
Definition Solver.h:460
int64_t conflictsRestarts
Definition Solver.h:200
int specialIncReduceDB
Definition Solver.h:176
float sumLBD
Definition Solver.h:272
CRef gatePropagateCheck(Var v, Var t)
vec< int > jlevel
Definition Solver.h:454
vec< CRef > clauses
Definition Solver.h:243
void setPropBudget(int64_t x)
Definition Solver.h:582
void minimisationWithBinaryResolution(vec< Lit > &out_learnt)
Definition Glucose2.cpp:473
int decisionLevel() const
Definition Solver.h:560
bool rnd_init_act
Definition Solver.h:190
double totalTime4Unsat
Definition Solver.h:300
void markTill(Var v0, int nlim)
bool certifiedUNSAT
Definition Solver.h:195
void attachClause(CRef cr)
Definition Glucose2.cpp:333
int firstReduceDB
Definition Solver.h:174
vec< int > jnext
Definition Solver.h:455
FILE * certifiedOutput
Definition Solver.h:194
int64_t starts
Definition Solver.h:200
unsigned travId
Definition Solver.h:425
static double drand(double &seed)
Definition Solver.h:358
bool addClause(const vec< Lit > &ps)
Definition Solver.h:532
int sat_solver_jftr()
Definition Solver.h:613
int nClauses() const
Definition Solver.h:567
void removeSatisfied(vec< CRef > &cs)
Var CRef2Var(CRef cr) const
Definition Solver.h:422
void analyzeFinal(Lit p, vec< Lit > &out_conflict)
Definition Glucose2.cpp:888
Heap2< JustOrderLt2, JustKey > jheap
Definition Solver.h:453
int64_t tot_literals
Definition Solver.h:201
void checkGarbage()
Definition Solver.h:525
void clearInterrupt()
Definition Solver.h:584
bqueue< unsigned int > trailQueue
Definition Solver.h:271
void setPolarity(Var v, bool b)
Definition Solver.h:572
void loadJust_rec(Var v)
void setNewRound()
Definition Solver.h:470
int64_t max_literals
Definition Solver.h:201
int phase_saving
Definition Solver.h:188
void budgetOff()
Definition Solver.h:585
double random_seed
Definition Solver.h:186
bool remove_satisfied
Definition Solver.h:259
void sat_solver_set_var_fanin_lit(int, int, int)
Definition Solver.h:609
vec< lbool > assigns
Definition Solver.h:246
double varActivity(int v) const
Definition Solver.h:478
int * getCex() const
Definition Solver.h:571
Var getFaninVar0(Var v) const
Definition Solver.h:393
int simpDB_assigns
Definition Solver.h:254
vec< lbool > model
Definition Solver.h:158
void varBumpActivity(Var v, double inc)
Definition Solver.h:504
void newDecisionLevel()
Definition Solver.h:558
double sizeLBDQueue
Definition Solver.h:170
bool solve()
Definition Solver.h:594
int SolverType
Definition Solver.h:52
CRef castCRef(Lit p)
lbool modelValue(Var x) const
Definition Solver.h:564
Heap< VarOrderLt > order_heap
Definition Solver.h:257
CRef reason(Var x) const
Definition Solver.h:491
static int irand(double &seed, int size)
Definition Solver.h:365
void * pCnfMan
Definition Solver.h:60
int64_t nbReduceDB
Definition Solver.h:200
int64_t nbDL2
Definition Solver.h:200
CRef Var2CRef(Var v) const
Definition Solver.h:421
static NodeData mkNodeData()
Definition Solver.h:378
double cla_inc
Definition Solver.h:236
int incremental
Definition Solver.h:298
bool isJReason(Var v) const
Definition Solver.h:388
void initNbInitialVars(int nb)
Definition Glucose2.cpp:211
double max_learnts
Definition Solver.h:286
void markCone(Var v)
bqueue< unsigned int > lbdQueue
Definition Solver.h:271
Lit getFaninPlt0(Var v) const
Definition Solver.h:395
bool terminate_search_early
Definition Solver.h:63
int64_t solves
Definition Solver.h:200
int nAssigns() const
Definition Solver.h:566
double var_decay
Definition Solver.h:183
void sat_solver_mark_cone(int)
Definition Solver.h:611
virtual ~Solver()
Definition Glucose2.cpp:194
vec< Lit > var2Fanout0
Definition Solver.h:382
CRef gatePropagate(Lit p)
int * pstop
Definition Solver.h:64
void pushJustQueue(Var v, int index)
int(* pCnfFunc)(void *p, int, int *)
Definition Solver.h:61
int64_t conflict_budget
Definition Solver.h:292
void setConfBudget(int64_t x)
Definition Solver.h:581
bool okay() const
Definition Solver.h:600
void sat_solver_set_jftr(int)
Definition Solver.h:612
int64_t nbstopsrestartssame
Definition Solver.h:200
void uncheckedEnqueue2(Lit p, CRef from=CRef_Undef)
Var newVar(bool polarity=true, bool dvar=true)
Definition Glucose2.cpp:223
double learntsize_adjust_confl
Definition Solver.h:287
void gateClearJwatch(Var v, int backtrack_level)
void setVarFaninLits(int v, int lit1, int lit2)
Definition Solver.h:467
int64_t propagation_budget
Definition Solver.h:293
int64_t nbReducedClauses
Definition Solver.h:200
bool isAND(Var v) const
Definition Solver.h:387
void setJust(int njftr)
Definition Solver.h:472
void setVarFaninLits(Var v, Lit lit1, Lit lit2)
vec< int > trail_lim
Definition Solver.h:251
double sizeTrailQueue
Definition Solver.h:171
vec< char > seen
Definition Solver.h:279
int lastIndexRed
Definition Solver.h:234
lbool solveLimited(const vec< Lit > &assumps)
Definition Solver.h:599
void claBumpActivity(Clause &c)
Definition Solver.h:518
unsigned int lbLBDMinimizingClause
Definition Solver.h:181
Lit getFaninLit1(Var v) const
Definition Solver.h:390
void printIncrementalStats()
int nbUnsatCalls
Definition Solver.h:301
bool isTwoFanin(Var v) const
void setIncrementalMode()
Definition Glucose2.cpp:206
bool isRoundWatch(Var v) const
Definition Solver.h:473
vec< Lit > assumptions
Definition Solver.h:256
int64_t propagations
Definition Solver.h:200
int nCallConfl
Definition Solver.h:62
int64_t nbBin
Definition Solver.h:200
int nFreeVars() const
Definition Solver.h:570
bool getFaninC1(Var v) const
Definition Solver.h:392
int64_t rnd_decisions
Definition Solver.h:200
bool isSelector(Var v)
Definition Solver.h:352
Lit gateJustFanin(Var v) const
int lbSizeMinimizingClause
Definition Solver.h:180
vec< CRef > learnts
Definition Solver.h:244
void analyze(CRef confl, vec< Lit > &out_learnt, vec< Lit > &selectors, int &out_btlevel, unsigned int &nblevels, unsigned int &szWithoutSelectors)
Definition Glucose2.cpp:604
Lit getFaninPlt1(Var v) const
Definition Solver.h:396
double totalTime4Sat
Definition Solver.h:300
void uncheckedEnqueue(Lit p, CRef from=CRef_Undef)
Definition Glucose2.cpp:925
vec< NodeData > var2NodeData
Definition Solver.h:379
void updateJustActivity(Var v)
lbool value(Var x) const
Definition Solver.h:562
void printInitialClause(CRef c)
Definition Solver.h:641
bool heap_rescale
Definition Solver.h:372
int64_t nbRemovedClauses
Definition Solver.h:200
double random_var_freq
Definition Solver.h:185
bool getFaninC0(Var v) const
Definition Solver.h:391
int nLearnts() const
Definition Solver.h:568
bool satisfied(const Clause &c) const
Definition Glucose2.cpp:396
void gateAddJwatch(Var v, int index)
double garbage_frac
Definition Solver.h:191
Lit getFaninLit0(Var v) const
Definition Solver.h:389
void push(void)
Definition Vec.h:77
void copyTo(vec< T > &copy) const
Definition Vec.h:94
void map()
Cube * p
Definition exorList.c:222
Definition Alg.h:28
Lit mkLit(Var var, bool sign=false)
Definition SolverTypes.h:69
bool sign(Lit p)
Definition SolverTypes.h:72
int var(Lit p)
Definition SolverTypes.h:73
const CRef CRef_Undef
int Var
Definition SolverTypes.h:54
RegionAllocator< uint32_t >::Ref CRef
Lit toLit(int i)
Definition SolverTypes.h:78
JustKey(const Key &nkey, const Data &ndata, const Attr &nattr)
Definition Solver.h:441
Attr attr() const
Definition Solver.h:439
Data data() const
Definition Solver.h:437
JustOrderLt2(const Solver *_pS)
Definition Solver.h:451
bool operator()(const JustKey &x, const JustKey &y) const
Definition Solver.h:445
bool operator()(Var x, Var y) const
Definition Solver.h:227
const vec< double > & activity
Definition Solver.h:226
VarOrderLt(const vec< double > &act)
Definition Solver.h:228
bool operator()(const Watcher &w) const
Definition Solver.h:222
WatcherDeleted(const ClauseAllocator &_ca)
Definition Solver.h:221
const ClauseAllocator & ca
Definition Solver.h:220
bool operator!=(const Watcher &w) const
Definition Solver.h:215
bool operator==(const Watcher &w) const
Definition Solver.h:214
Watcher(CRef cr, Lit p)
Definition Solver.h:213
Definition file.h:23