ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Gluco::SimpSolver Class Reference

#include <SimpSolver.h>

Inheritance diagram for Gluco::SimpSolver:
Collaboration diagram for Gluco::SimpSolver:

Classes

struct  ClauseDeleted
 
struct  ElimLt
 

Public Member Functions

 SimpSolver ()
 
 ~SimpSolver ()
 
Var newVar (bool polarity=true, bool dvar=true)
 
void addVar (Var v)
 
bool addClause (const vec< Lit > &ps)
 
bool addEmptyClause ()
 
bool addClause (Lit p)
 
bool addClause (Lit p, Lit q)
 
bool addClause (Lit p, Lit q, Lit r)
 
bool addClause_ (vec< Lit > &ps)
 
bool substitute (Var v, Lit x)
 
void setFrozen (Var v, bool b)
 
bool isEliminated (Var v) const
 
bool solve (const vec< Lit > &assumps, bool do_simp=true, bool turn_off_simp=false)
 
lbool solveLimited (const vec< Lit > &assumps, bool do_simp=true, bool turn_off_simp=false)
 
bool solve (bool do_simp=true, bool turn_off_simp=false)
 
bool solve (Lit p, bool do_simp=true, bool turn_off_simp=false)
 
bool solve (Lit p, Lit q, bool do_simp=true, bool turn_off_simp=false)
 
bool solve (Lit p, Lit q, Lit r, bool do_simp=true, bool turn_off_simp=false)
 
bool eliminate (bool turn_off_elim=false)
 
virtual void reset ()
 
virtual void garbageCollect ()
 
- Public Member Functions inherited from Gluco::Solver
 Solver ()
 
virtual ~Solver ()
 
void sat_solver_set_var_fanin_lit (int, int, int)
 
void sat_solver_start_new_round ()
 
void sat_solver_mark_cone (int)
 
Var newVar (bool polarity=true, bool dvar=true)
 
void addVar (Var v)
 
bool addClause (const vec< Lit > &ps)
 
bool addEmptyClause ()
 
bool addClause (Lit p)
 
bool addClause (Lit p, Lit q)
 
bool addClause (Lit p, Lit q, Lit r)
 
bool addClause_ (vec< Lit > &ps)
 
bool simplify ()
 
bool solve (const vec< Lit > &assumps)
 
lbool solveLimited (const vec< Lit > &assumps)
 
bool solve ()
 
bool solve (Lit p)
 
bool solve (Lit p, Lit q)
 
bool solve (Lit p, Lit q, Lit r)
 
bool okay () const
 
void toDimacs (FILE *f, const vec< Lit > &assumps)
 
void toDimacs (const char *file, const vec< Lit > &assumps)
 
void toDimacs (FILE *f, Clause &c, vec< Var > &map, Var &max)
 
void printLit (Lit l)
 
void printClause (CRef c)
 
void printInitialClause (CRef c)
 
void toDimacs (const char *file)
 
void toDimacs (const char *file, Lit p)
 
void toDimacs (const char *file, Lit p, Lit q)
 
void toDimacs (const char *file, Lit p, Lit q, Lit r)
 
void setPolarity (Var v, bool b)
 
void setDecisionVar (Var v, bool b)
 
lbool value (Var x) const
 
lbool value (Lit p) const
 
lbool modelValue (Var x) const
 
lbool modelValue (Lit p) const
 
int nAssigns () const
 
int nClauses () const
 
int nLearnts () const
 
int nVars () const
 
int nFreeVars () const
 
int * getCex () const
 
void setIncrementalMode ()
 
void initNbInitialVars (int nb)
 
void printIncrementalStats ()
 
void setConfBudget (int64_t x)
 
void setPropBudget (int64_t x)
 
void budgetOff ()
 
void interrupt ()
 
void clearInterrupt ()
 
void checkGarbage (double gf)
 
void checkGarbage ()
 

Public Attributes

int parsing
 
int grow
 
int clause_lim
 
int subsumption_lim
 
double simp_garbage_frac
 
bool use_asymm
 
bool use_rcheck
 
bool use_elim
 
int merges
 
int asymm_lits
 
int eliminated_vars
 
int eliminated_clauses
 
- Public Attributes inherited from Gluco::Solver
int SolverType
 
void * pCnfMan
 
int(* pCnfFunc )(void *p, int, int *)
 
int nCallConfl
 
bool terminate_search_early
 
int * pstop
 
uint64_t nRuntimeLimit
 
vec< int > user_vec
 
vec< Lituser_lits
 
int jftr
 
vec< lboolmodel
 
vec< Litconflict
 
int verbosity
 
int verbEveryConflicts
 
int showModel
 
double K
 
double R
 
double sizeLBDQueue
 
double sizeTrailQueue
 
int firstReduceDB
 
int incReduceDB
 
int specialIncReduceDB
 
unsigned int lbLBDFrozenClause
 
int lbSizeMinimizingClause
 
unsigned int lbLBDMinimizingClause
 
double var_decay
 
double clause_decay
 
double random_var_freq
 
double random_seed
 
int ccmin_mode
 
int phase_saving
 
bool rnd_pol
 
bool rnd_init_act
 
double garbage_frac
 
FILE * certifiedOutput
 
bool certifiedUNSAT
 
int64_t nbRemovedClauses
 
int64_t nbReducedClauses
 
int64_t nbDL2
 
int64_t nbBin
 
int64_t nbUn
 
int64_t nbReduceDB
 
int64_t solves
 
int64_t starts
 
int64_t decisions
 
int64_t rnd_decisions
 
int64_t propagations
 
int64_t conflicts
 
int64_t conflictsRestarts
 
int64_t nbstopsrestarts
 
int64_t nbstopsrestartssame
 
int64_t lastblockatrestart
 
int64_t dec_vars
 
int64_t clauses_literals
 
int64_t learnts_literals
 
int64_t max_literals
 
int64_t tot_literals
 

Protected Member Functions

lbool solve_ (bool do_simp=true, bool turn_off_simp=false)
 
bool asymm (Var v, CRef cr)
 
bool asymmVar (Var v)
 
void updateElimHeap (Var v)
 
void gatherTouchedClauses ()
 
bool merge (const Clause &_ps, const Clause &_qs, Var v, vec< Lit > &out_clause)
 
bool merge (const Clause &_ps, const Clause &_qs, Var v, int &size)
 
bool backwardSubsumptionCheck (bool verbose=false)
 
bool eliminateVar (Var v)
 
void extendModel ()
 
void removeClause (CRef cr)
 
bool strengthenClause (CRef cr, Lit l)
 
void cleanUpClauses ()
 
bool implied (const vec< Lit > &c)
 
void relocAll (ClauseAllocator &to)
 
- Protected Member Functions inherited from Gluco::Solver
void insertVarOrder (Var x)
 
Lit pickBranchLit ()
 
void newDecisionLevel ()
 
void uncheckedEnqueue (Lit p, CRef from=CRef_Undef)
 
bool enqueue (Lit p, CRef from=CRef_Undef)
 
CRef propagate ()
 
void cancelUntil (int level)
 
void analyze (CRef confl, vec< Lit > &out_learnt, vec< Lit > &selectors, int &out_btlevel, unsigned int &nblevels, unsigned int &szWithoutSelectors)
 
void analyzeFinal (Lit p, vec< Lit > &out_conflict)
 
bool litRedundant (Lit p, uint32_t abstract_levels)
 
lbool search (int nof_conflicts)
 
lbool solve_ ()
 
void reduceDB ()
 
void removeSatisfied (vec< CRef > &cs)
 
void rebuildOrderHeap ()
 
void varDecayActivity ()
 
void varBumpActivity (Var v, double inc)
 
void varBumpActivity (Var v)
 
void claDecayActivity ()
 
void claBumpActivity (Clause &c)
 
void attachClause (CRef cr)
 
void detachClause (CRef cr, bool strict=false)
 
void removeClause (CRef cr)
 
bool locked (const Clause &c) const
 
bool satisfied (const Clause &c) const
 
unsigned int computeLBD (const vec< Lit > &lits, int end=-1)
 
unsigned int computeLBD (const Clause &c)
 
void minimisationWithBinaryResolution (vec< Lit > &out_learnt)
 
void relocAll (ClauseAllocator &to)
 
int decisionLevel () const
 
uint32_t abstractLevel (Var x) const
 
CRef reason (Var x) const
 
int level (Var x) const
 
double progressEstimate () const
 
bool withinBudget () const
 
bool isSelector (Var v)
 

Protected Attributes

int elimorder
 
bool use_simplification
 
vec< uint32_telimclauses
 
vec< char > touched
 
OccLists< Var, vec< CRef >, ClauseDeletedoccurs
 
vec< int > n_occ
 
Heap< ElimLtelim_heap
 
Queue< CRefsubsumption_queue
 
vec< char > frozen
 
vec< char > eliminated
 
int bwdsub_assigns
 
int n_touched
 
CRef bwdsub_tmpunit
 
- Protected Attributes inherited from Gluco::Solver
long curRestart
 
int lastIndexRed
 
bool ok
 
double cla_inc
 
vec< double > activity
 
double var_inc
 
OccLists< Lit, vec< Watcher >, WatcherDeletedwatches
 
OccLists< Lit, vec< Watcher >, WatcherDeletedwatchesBin
 
vec< CRefclauses
 
vec< CReflearnts
 
vec< lboolassigns
 
vec< char > polarity
 
vec< char > decision
 
vec< Littrail
 
vec< int > nbpos
 
vec< int > trail_lim
 
vec< VarDatavardata
 
int qhead
 
int simpDB_assigns
 
int64_t simpDB_props
 
vec< Litassumptions
 
Heap< VarOrderLtorder_heap
 
double progress_estimate
 
bool remove_satisfied
 
vec< unsigned int > permDiff
 
ClauseAllocator ca
 
int nbclausesbeforereduce
 
bqueue< unsigned int > trailQueue
 
bqueue< unsigned int > lbdQueue
 
float sumLBD
 
int sumAssumptions
 
vec< char > seen
 
vec< Litanalyze_stack
 
vec< Litanalyze_toclear
 
vec< Litadd_tmp
 
unsigned int MYFLAG
 
double max_learnts
 
double learntsize_adjust_confl
 
int learntsize_adjust_cnt
 
int64_t conflict_budget
 
int64_t propagation_budget
 
bool asynch_interrupt
 
int incremental
 
int nbVarsInitialFormula
 
double totalTime4Sat
 
double totalTime4Unsat
 
int nbSatCalls
 
int nbUnsatCalls
 
vec< int > assumptionPositions
 
vec< int > initialPositions
 

Additional Inherited Members

- Static Protected Member Functions inherited from Gluco::Solver
static VarData mkVarData (CRef cr, int l)
 
static double drand (double &seed)
 
static int irand (double &seed, int size)
 

Detailed Description

Definition at line 34 of file SimpSolver.h.

Constructor & Destructor Documentation

◆ SimpSolver()

SimpSolver::SimpSolver ( )

Definition at line 48 of file SimpSolver.cpp.

48 :
49 grow (opt_grow)
50 , clause_lim (opt_clause_lim)
51 , subsumption_lim (opt_subsumption_lim)
52 , simp_garbage_frac (opt_simp_garbage_frac)
53 , use_asymm (opt_use_asymm)
54 , use_rcheck (opt_use_rcheck)
55 , use_elim (opt_use_elim)
56 , merges (0)
57 , asymm_lits (0)
58 , eliminated_vars (0)
60 , elimorder (1)
61 , use_simplification (true)
64 , bwdsub_assigns (0)
65 , n_touched (0)
66{
67 vec<Lit> dummy(1,lit_Undef);
68 ca.extra_clause_field = true; // NOTE: must happen before allocating the dummy clause below.
69 bwdsub_tmpunit = ca.alloc(dummy);
70 remove_satisfied = false;
71}
Heap< ElimLt > elim_heap
Definition SimpSolver.h:138
double simp_garbage_frac
Definition SimpSolver.h:91
OccLists< Var, vec< CRef >, ClauseDeleted > occurs
Definition SimpSolver.h:136
vec< int > n_occ
Definition SimpSolver.h:137
ClauseAllocator ca
Definition Solver.h:261
bool remove_satisfied
Definition Solver.h:253
const Lit lit_Undef
Definition SolverTypes.h:81

◆ ~SimpSolver()

SimpSolver::~SimpSolver ( )

Definition at line 74 of file SimpSolver.cpp.

75{
76}

Member Function Documentation

◆ addClause() [1/4]

bool Gluco::SimpSolver::addClause ( const vec< Lit > & ps)
inline

Definition at line 183 of file SimpSolver.h.

183{ ps.copyTo(add_tmp); return addClause_(add_tmp); }
bool addClause_(vec< Lit > &ps)
vec< Lit > add_tmp
Definition Solver.h:276
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addClause() [2/4]

bool Gluco::SimpSolver::addClause ( Lit p)
inline

Definition at line 185 of file SimpSolver.h.

185{ add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp); }
Cube * p
Definition exorList.c:222
Here is the call graph for this function:

◆ addClause() [3/4]

bool Gluco::SimpSolver::addClause ( Lit p,
Lit q )
inline

Definition at line 186 of file SimpSolver.h.

186{ add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp); }
Here is the call graph for this function:

◆ addClause() [4/4]

bool Gluco::SimpSolver::addClause ( Lit p,
Lit q,
Lit r )
inline

Definition at line 187 of file SimpSolver.h.

187{ add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp); }
Here is the call graph for this function:

◆ addClause_()

bool SimpSolver::addClause_ ( vec< Lit > & ps)

Definition at line 138 of file SimpSolver.cpp.

139{
140#ifndef NDEBUG
141 for (int i = 0; i < ps.size(); i++)
142 assert(!isEliminated(var(ps[i])));
143#endif
144 int nclauses = clauses.size();
145
146 if (use_rcheck && implied(ps))
147 return true;
148
149 if (!Solver::addClause_(ps))
150 return false;
151
152 if(!parsing && certifiedUNSAT) {
153 for (int i = 0; i < ps.size(); i++)
154 fprintf(certifiedOutput, "%i " , (var(ps[i]) + 1) * (-2 * sign(ps[i]) + 1) );
155 fprintf(certifiedOutput, "0\n");
156 }
157
158 if (use_simplification && clauses.size() == nclauses + 1){
159 CRef cr = clauses.last();
160 const Clause& c = ca[cr];
161
162 // NOTE: the clause is added to the queue immediately and then
163 // again during 'gatherTouchedClauses()'. If nothing happens
164 // in between, it will only be checked once. Otherwise, it may
165 // be checked twice unnecessarily. This is an unfortunate
166 // consequence of how backward subsumption is used to mimic
167 // forward subsumption.
168 subsumption_queue.insert(cr);
169 for (int i = 0; i < c.size(); i++){
170 occurs[var(c[i])].push(cr);
171 n_occ[toInt(c[i])]++;
172 touched[var(c[i])] = 1;
173 n_touched++;
174 if (elim_heap.inHeap(var(c[i])))
175 elim_heap.increase(var(c[i]));
176 }
177 }
178
179 return true;
180}
unsigned size
bool implied(const vec< Lit > &c)
Queue< CRef > subsumption_queue
Definition SimpSolver.h:139
vec< char > touched
Definition SimpSolver.h:134
bool isEliminated(Var v) const
Definition SimpSolver.h:175
FILE * certifiedOutput
Definition Solver.h:188
bool addClause_(vec< Lit > &ps)
Definition Glucose.cpp:224
bool certifiedUNSAT
Definition Solver.h:189
vec< CRef > clauses
Definition Solver.h:237
int size(void) const
Definition Vec.h:65
int toInt(Var v)
Definition SolverTypes.h:74
RegionAllocator< uint32_t >::Ref CRef
int var(Lit p)
Definition SolverTypes.h:71
bool sign(Lit p)
Definition SolverTypes.h:70
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addEmptyClause()

bool Gluco::SimpSolver::addEmptyClause ( )
inline

Definition at line 184 of file SimpSolver.h.

184{ add_tmp.clear(); return addClause_(add_tmp); }
Here is the call graph for this function:

◆ addVar()

void Gluco::SimpSolver::addVar ( Var v)
inline

Definition at line 200 of file SimpSolver.h.

200{ while (v >= nVars()) newVar(); }
Var newVar(bool polarity=true, bool dvar=true)
int nVars() const
Definition Solver.h:426
Here is the call graph for this function:
Here is the caller graph for this function:

◆ asymm()

bool SimpSolver::asymm ( Var v,
CRef cr )
protected

Definition at line 417 of file SimpSolver.cpp.

418{
419 Clause& c = ca[cr];
420 assert(decisionLevel() == 0);
421
422 if (c.mark() || satisfied(c)) return true;
423
424 trail_lim.push(trail.size());
425 Lit l = lit_Undef;
426 for (int i = 0; i < c.size(); i++)
427 if (var(c[i]) != v && value(c[i]) != l_False)
428 uncheckedEnqueue(~c[i]);
429 else
430 l = c[i];
431
432 if (propagate() != CRef_Undef){
433 cancelUntil(0);
434 asymm_lits++;
435 if (!strengthenClause(cr, l))
436 return false;
437 }else
438 cancelUntil(0);
439
440 return true;
441}
#define l_False
Definition bmcBmcS.c:36
ABC_NAMESPACE_IMPL_START typedef signed char value
unsigned mark
bool strengthenClause(CRef cr, Lit l)
int decisionLevel() const
Definition Solver.h:417
CRef propagate()
Definition Glucose.cpp:803
vec< int > trail_lim
Definition Solver.h:245
void cancelUntil(int level)
Definition Glucose.cpp:471
vec< Lit > trail
Definition Solver.h:243
void uncheckedEnqueue(Lit p, CRef from=CRef_Undef)
Definition Glucose.cpp:783
bool satisfied(const Clause &c) const
Definition Glucose.cpp:352
const CRef CRef_Undef
Here is the call graph for this function:
Here is the caller graph for this function:

◆ asymmVar()

bool SimpSolver::asymmVar ( Var v)
protected

Definition at line 444 of file SimpSolver.cpp.

445{
447
448 const vec<CRef>& cls = occurs.lookup(v);
449
450 if (value(v) != l_Undef || cls.size() == 0)
451 return true;
452
453 for (int i = 0; i < cls.size(); i++)
454 if (!asymm(v, cls[i]))
455 return false;
456
458}
#define l_Undef
Definition bmcBmcS.c:34
bool asymm(Var v, CRef cr)
bool backwardSubsumptionCheck(bool verbose=false)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ backwardSubsumptionCheck()

bool SimpSolver::backwardSubsumptionCheck ( bool verbose = false)
protected

Definition at line 350 of file SimpSolver.cpp.

351{
352 int cnt = 0;
353 int subsumed = 0;
354 int deleted_literals = 0;
355 assert(decisionLevel() == 0);
356
357 while (subsumption_queue.size() > 0 || bwdsub_assigns < trail.size()){
358
359 // Empty subsumption queue and return immediately on user-interrupt:
360 if (asynch_interrupt){
361 subsumption_queue.clear();
362 bwdsub_assigns = trail.size();
363 break; }
364
365 // Check top-level assignments by creating a dummy clause and placing it in the queue:
366 if (subsumption_queue.size() == 0 && bwdsub_assigns < trail.size()){
367 Lit l = trail[bwdsub_assigns++];
368 ca[bwdsub_tmpunit][0] = l;
369 ca[bwdsub_tmpunit].calcAbstraction();
371
372 CRef cr = subsumption_queue.peek(); subsumption_queue.pop();
373 Clause& c = ca[cr];
374
375 if (c.mark()) continue;
376
377 if (verbose && verbosity >= 2 && cnt++ % 1000 == 0)
378 printf("subsumption left: %10d (%10d subsumed, %10d deleted literals)\r", subsumption_queue.size(), subsumed, deleted_literals);
379
380 assert(c.size() > 1 || value(c[0]) == l_True); // Unit-clauses should have been propagated before this point.
381
382 // Find best variable to scan:
383 Var best = var(c[0]);
384 for (int i = 1; i < c.size(); i++)
385 if (occurs[var(c[i])].size() < occurs[best].size())
386 best = var(c[i]);
387
388 // Search all candidates:
389 vec<CRef>& _cs = occurs.lookup(best);
390 CRef* cs = (CRef*)_cs;
391
392 for (int j = 0; j < _cs.size(); j++)
393 if (c.mark())
394 break;
395 else if (!ca[cs[j]].mark() && cs[j] != cr && (subsumption_lim == -1 || ca[cs[j]].size() < subsumption_lim)){
396 Lit l = c.subsumes(ca[cs[j]]);
397
398 if (l == lit_Undef)
399 subsumed++, removeClause(cs[j]);
400 else if (l != lit_Error){
401 deleted_literals++;
402
403 if (!strengthenClause(cs[j], ~l))
404 return false;
405
406 // Did current candidate get deleted from cs? Then check candidate at index j again:
407 if (var(l) == best)
408 j--;
409 }
410 }
411 }
412
413 return true;
414}
#define l_True
Definition bmcBmcS.c:35
Lit subsumes(const Clause &other) const
void removeClause(CRef cr)
lbool value(Var x) const
Definition Solver.h:419
bool asynch_interrupt
Definition Solver.h:288
int verbosity
Definition Solver.h:158
const Lit lit_Error
Definition SolverTypes.h:82
int Var
Definition SolverTypes.h:52
unsigned long long size
Definition giaNewBdd.h:39
signed char mark
Definition value.h:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanUpClauses()

void SimpSolver::cleanUpClauses ( )
protected

Definition at line 702 of file SimpSolver.cpp.

703{
704 occurs.cleanAll();
705 int i,j;
706 for (i = j = 0; i < clauses.size(); i++)
707 if (ca[clauses[i]].mark() == 0)
708 clauses[j++] = clauses[i];
709 clauses.shrink(i - j);
710}
Here is the caller graph for this function:

◆ eliminate()

bool SimpSolver::eliminate ( bool turn_off_elim = false)

Definition at line 610 of file SimpSolver.cpp.

611{
612 //abctime clk = Abc_Clock();
613 if (!simplify())
614 return false;
615 else if (!use_simplification)
616 return true;
617
618 // Main simplification loop:
619 //
620
621 int toPerform = clauses.size()<=4800000;
622
623 if(!toPerform) {
624 printf("c Too many clauses... No preprocessing\n");
625 }
626
627 while (toPerform && (n_touched > 0 || bwdsub_assigns < trail.size() || elim_heap.size() > 0)){
628
630 // printf(" ## (time = %6.2f s) BWD-SUB: queue = %d, trail = %d\n", cpuTime(), subsumption_queue.size(), trail.size() - bwdsub_assigns);
631 if ((subsumption_queue.size() > 0 || bwdsub_assigns < trail.size()) &&
633 ok = false; goto cleanup; }
634
635 // Empty elim_heap and return immediately on user-interrupt:
636 if (asynch_interrupt){
637 assert(bwdsub_assigns == trail.size());
638 assert(subsumption_queue.size() == 0);
639 assert(n_touched == 0);
640 elim_heap.clear();
641 goto cleanup; }
642
643 // printf(" ## (time = %6.2f s) ELIM: vars = %d\n", cpuTime(), elim_heap.size());
644 for (int cnt = 0; !elim_heap.empty(); cnt++){
645 Var elim = elim_heap.removeMin();
646
647 if (asynch_interrupt) break;
648
649 if (isEliminated(elim) || value(elim) != l_Undef) continue;
650
651 if (verbosity >= 2 && cnt % 100 == 0)
652 printf("elimination left: %10d\r", elim_heap.size());
653
654 if (use_asymm){
655 // Temporarily freeze variable. Otherwise, it would immediately end up on the queue again:
656 bool was_frozen = frozen[elim] != 0;
657 frozen[elim] = true;
658 if (!asymmVar(elim)){
659 ok = false; goto cleanup; }
660 frozen[elim] = was_frozen; }
661
662 // At this point, the variable may have been set by assymetric branching, so check it
663 // again. Also, don't eliminate frozen variables:
664 if (use_elim && value(elim) == l_Undef && !frozen[elim] && !eliminateVar(elim)){
665 ok = false; goto cleanup; }
666
668 }
669
670 assert(subsumption_queue.size() == 0);
671 }
672 cleanup:
673
674 // If no more simplification is needed, free all simplification-related data structures:
675 if (turn_off_elim){
676 touched .clear(true);
677 occurs .clear(true);
678 n_occ .clear(true);
679 elim_heap.clear(true);
680 subsumption_queue.clear(true);
681
682 use_simplification = false;
683 remove_satisfied = true;
684 ca.extra_clause_field = false;
685
686 // Force full cleanup (this is safe and desirable since it only happens once):
689 }else{
690 // Cheaper cleanup:
691 cleanUpClauses(); // TODO: can we make 'cleanUpClauses()' not be linear in the problem size somehow?
692 checkGarbage();
693 }
694
695 if (verbosity >= 1 && elimclauses.size() > 0)
696 printf("c | Eliminated clauses: %10.2f Mb |\n",
697 double(elimclauses.size() * sizeof(uint32_t)) / (1024*1024));
698 return ok;
699}
unsigned int uint32_t
Definition Fxch.h:32
vec< char > frozen
Definition SimpSolver.h:140
bool eliminateVar(Var v)
bool asymmVar(Var v)
virtual void garbageCollect()
void gatherTouchedClauses()
vec< uint32_t > elimclauses
Definition SimpSolver.h:133
void checkGarbage()
Definition Solver.h:395
void rebuildOrderHeap()
Definition Glucose.cpp:981
bool simplify()
Definition Glucose.cpp:999
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eliminateVar()

bool SimpSolver::eliminateVar ( Var v)
protected

Definition at line 494 of file SimpSolver.cpp.

495{
496 int i, j;
497 assert(!frozen[v]);
498 assert(!isEliminated(v));
499 assert(value(v) == l_Undef);
500
501 // Split the occurrences into positive and negative:
502 //
503 const vec<CRef>& cls = occurs.lookup(v);
504 vec<CRef> pos, neg;
505 for (i = 0; i < cls.size(); i++)
506 (find(ca[cls[i]], mkLit(v)) ? pos : neg).push(cls[i]);
507
508 // Check wether the increase in number of clauses stays within the allowed ('grow'). Moreover, no
509 // clause must exceed the limit on the maximal clause size (if it is set):
510 //
511 int cnt = 0;
512 int clause_size = 0;
513
514 for (i = 0; i < pos.size(); i++)
515 for (j = 0; j < neg.size(); j++)
516 if (merge(ca[pos[i]], ca[neg[j]], v, clause_size) &&
517 (++cnt > cls.size() + grow || (clause_lim != -1 && clause_size > clause_lim)))
518 return true;
519
520 // Delete and store old clauses:
521 eliminated[v] = true;
522 setDecisionVar(v, false);
524
525 if (pos.size() > neg.size()){
526 for (i = 0; i < neg.size(); i++)
527 mkElimClause(elimclauses, v, ca[neg[i]]);
528 mkElimClause(elimclauses, mkLit(v));
529 eliminated_clauses += neg.size();
530 }else{
531 for (i = 0; i < pos.size(); i++)
532 mkElimClause(elimclauses, v, ca[pos[i]]);
533 mkElimClause(elimclauses, ~mkLit(v));
534 eliminated_clauses += pos.size();
535 }
536
537
538 // Produce clauses in cross product:
539 vec<Lit>& resolvent = add_tmp;
540 for (i = 0; i < pos.size(); i++)
541 for (j = 0; j < neg.size(); j++)
542 if (merge(ca[pos[i]], ca[neg[j]], v, resolvent) && !addClause_(resolvent))
543 return false;
544
545 for (i = 0; i < cls.size(); i++)
546 removeClause(cls[i]);
547
548 // Free occurs list for this variable:
549 occurs[v].clear(true);
550
551 // Free watchers lists for this variable, if possible:
552 if (watches[ mkLit(v)].size() == 0) watches[ mkLit(v)].clear(true);
553 if (watches[~mkLit(v)].size() == 0) watches[~mkLit(v)].clear(true);
554
556}
bool merge(const Clause &_ps, const Clause &_qs, Var v, vec< Lit > &out_clause)
vec< char > eliminated
Definition SimpSolver.h:141
OccLists< Lit, vec< Watcher >, WatcherDeleted > watches
Definition Solver.h:234
void setDecisionVar(Var v, bool b)
Definition Solver.h:430
bool pos
Definition globals.c:30
Lit mkLit(Var var, bool sign=false)
Definition SolverTypes.h:67
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extendModel()

void SimpSolver::extendModel ( )
protected

Definition at line 593 of file SimpSolver.cpp.

594{
595 int i, j;
596 Lit x;
597
598 for (i = elimclauses.size()-1; i > 0; i -= j){
599 for (j = elimclauses[i--]; j > 1; j--, i--)
601 goto next;
602
603 x = toLit(elimclauses[i]);
604 model[var(x)] = lbool(!sign(x));
605 next:;
606 }
607}
vec< lbool > model
Definition Solver.h:152
lbool modelValue(Var x) const
Definition Solver.h:421
Lit toLit(int i)
Definition SolverTypes.h:76
signed char lbool
Definition satVec.h:135
Here is the call graph for this function:
Here is the caller graph for this function:

◆ garbageCollect()

void SimpSolver::garbageCollect ( )
virtual

Reimplemented from Gluco::Solver.

Definition at line 741 of file SimpSolver.cpp.

742{
743 // Initialize the next region to a size corresponding to the estimated utilization degree. This
744 // is not precise but should avoid some unnecessary reallocations for the new region:
745 ClauseAllocator to(ca.size() - ca.wasted());
746
748 to.extra_clause_field = ca.extra_clause_field; // NOTE: this is important to keep (or lose) the extra fields.
749 relocAll(to);
751 if (verbosity >= 2)
752 printf("| Garbage collection: %12d bytes => %12d bytes |\n",
754 to.moveTo(ca);
755}
void relocAll(ClauseAllocator &to)
void relocAll(ClauseAllocator &to)
Definition Glucose.cpp:1386
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gatherTouchedClauses()

void SimpSolver::gatherTouchedClauses ( )
protected

Definition at line 301 of file SimpSolver.cpp.

302{
303 if (n_touched == 0) return;
304
305 int i,j;
306 for (i = j = 0; i < subsumption_queue.size(); i++)
307 if (ca[subsumption_queue[i]].mark() == 0)
308 ca[subsumption_queue[i]].mark(2);
309
310 for (i = 0; i < touched.size(); i++)
311 if (touched[i]){
312 const vec<CRef>& cs = occurs.lookup(i);
313 for (j = 0; j < cs.size(); j++)
314 if (ca[cs[j]].mark() == 0){
315 subsumption_queue.insert(cs[j]);
316 ca[cs[j]].mark(2);
317 }
318 touched[i] = 0;
319 }
320
321 for (i = 0; i < subsumption_queue.size(); i++)
322 if (ca[subsumption_queue[i]].mark() == 2)
323 ca[subsumption_queue[i]].mark(0);
324
325 n_touched = 0;
326}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ implied()

bool SimpSolver::implied ( const vec< Lit > & c)
protected

Definition at line 329 of file SimpSolver.cpp.

330{
331 assert(decisionLevel() == 0);
332
333 trail_lim.push(trail.size());
334 for (int i = 0; i < c.size(); i++)
335 if (value(c[i]) == l_True){
336 cancelUntil(0);
337 return false;
338 }else if (value(c[i]) != l_False){
339 assert(value(c[i]) == l_Undef);
340 uncheckedEnqueue(~c[i]);
341 }
342
343 bool result = propagate() != CRef_Undef;
344 cancelUntil(0);
345 return result;
346}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEliminated()

bool Gluco::SimpSolver::isEliminated ( Var v) const
inline

Definition at line 175 of file SimpSolver.h.

175{ return eliminated.size() > 0 ? eliminated[v] != 0 : 0; }
Here is the caller graph for this function:

◆ merge() [1/2]

bool SimpSolver::merge ( const Clause & _ps,
const Clause & _qs,
Var v,
int & size )
protected

Definition at line 271 of file SimpSolver.cpp.

272{
273 merges++;
274
275 bool ps_smallest = _ps.size() < _qs.size();
276 const Clause& ps = ps_smallest ? _qs : _ps;
277 const Clause& qs = ps_smallest ? _ps : _qs;
278 const Lit* __ps = (const Lit*)ps;
279 const Lit* __qs = (const Lit*)qs;
280
281 size = ps.size()-1;
282
283 for (int i = 0; i < qs.size(); i++){
284 if (var(__qs[i]) != v){
285 for (int j = 0; j < ps.size(); j++)
286 if (var(__ps[j]) == var(__qs[i])) {
287 if (__ps[j] == ~__qs[i])
288 return false;
289 else
290 goto next;
291 }
292 size++;
293 }
294 next:;
295 }
296
297 return true;
298}
Here is the call graph for this function:

◆ merge() [2/2]

bool SimpSolver::merge ( const Clause & _ps,
const Clause & _qs,
Var v,
vec< Lit > & out_clause )
protected

Definition at line 238 of file SimpSolver.cpp.

239{
240 merges++;
241 out_clause.clear();
242
243 bool ps_smallest = _ps.size() < _qs.size();
244 const Clause& ps = ps_smallest ? _qs : _ps;
245 const Clause& qs = ps_smallest ? _ps : _qs;
246
247 int i, j;
248 for (i = 0; i < qs.size(); i++){
249 if (var(qs[i]) != v){
250 for (j = 0; j < ps.size(); j++)
251 if (var(ps[j]) == var(qs[i])) {
252 if (ps[j] == ~qs[i])
253 return false;
254 else
255 goto next;
256 }
257 out_clause.push(qs[i]);
258 }
259 next:;
260 }
261
262 for (i = 0; i < ps.size(); i++)
263 if (var(ps[i]) != v)
264 out_clause.push(ps[i]);
265
266 return true;
267}
void clear(bool dealloc=false)
Definition Vec.h:124
void push(void)
Definition Vec.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ newVar()

Var SimpSolver::newVar ( bool polarity = true,
bool dvar = true )

Definition at line 79 of file SimpSolver.cpp.

79 {
80 Var v = Solver::newVar(sign, dvar);
81
82 frozen .push((char)false);
83 eliminated.push((char)false);
84
86 n_occ .push(0);
87 n_occ .push(0);
88 occurs .init(v);
89 touched .push(0);
90 elim_heap .insert(v);
91 }
92 return v; }
Var newVar(bool polarity=true, bool dvar=true)
Definition Glucose.cpp:202
Here is the call graph for this function:
Here is the caller graph for this function:

◆ relocAll()

void SimpSolver::relocAll ( ClauseAllocator & to)
protected

Definition at line 717 of file SimpSolver.cpp.

718{
719 int i;
720 if (!use_simplification) return;
721
722 // All occurs lists:
723 //
724 for (i = 0; i < nVars(); i++){
725 vec<CRef>& cs = occurs[i];
726 for (int j = 0; j < cs.size(); j++)
727 ca.reloc(cs[j], to);
728 }
729
730 // Subsumption queue:
731 //
732 for (i = 0; i < subsumption_queue.size(); i++)
733 ca.reloc(subsumption_queue[i], to);
734
735 // Temporary clause:
736 //
737 ca.reloc(bwdsub_tmpunit, to);
738}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeClause()

void SimpSolver::removeClause ( CRef cr)
protected

Definition at line 183 of file SimpSolver.cpp.

184{
185 const Clause& c = ca[cr];
186
188 for (int i = 0; i < c.size(); i++){
189 n_occ[toInt(c[i])]--;
190 updateElimHeap(var(c[i]));
191 occurs.smudge(var(c[i]));
192 }
193
195}
void updateElimHeap(Var v)
Definition SimpSolver.h:176
void removeClause(CRef cr)
Definition Glucose.cpp:333
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void SimpSolver::reset ( )
virtual

Reimplemented from Gluco::Solver.

Definition at line 757 of file SimpSolver.cpp.

758{
760 grow = opt_grow;
762 elimclauses.clear(false);
763 touched.clear(false);
764 occurs.clear(false);
765 n_occ.clear(false);
766 elim_heap.clear(false);
767 subsumption_queue.clear(false);
768 frozen.clear(false);
769 eliminated.clear(false);
770 vec<Lit> dummy(1,lit_Undef);
771 ca.extra_clause_field = true; // NOTE: must happen before allocating the dummy clause below.
772 bwdsub_tmpunit = ca.alloc(dummy);
773 remove_satisfied = false;
774}
virtual void reset()
Definition Glucose.cpp:1440
Here is the call graph for this function:

◆ setFrozen()

void Gluco::SimpSolver::setFrozen ( Var v,
bool b )
inline

Definition at line 188 of file SimpSolver.h.

188{ frozen[v] = (char)b; if (use_simplification && !b) { updateElimHeap(v); } }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ solve() [1/5]

bool Gluco::SimpSolver::solve ( bool do_simp = true,
bool turn_off_simp = false )
inline

Definition at line 190 of file SimpSolver.h.

190{ budgetOff(); assumptions.clear(); return solve_(do_simp, turn_off_simp) == l_True; }
vec< Lit > assumptions
Definition Solver.h:250
lbool solve_()
Definition Glucose.cpp:1209
void budgetOff()
Definition Solver.h:442
Here is the call graph for this function:

◆ solve() [2/5]

bool Gluco::SimpSolver::solve ( const vec< Lit > & assumps,
bool do_simp = true,
bool turn_off_simp = false )
inline

Definition at line 194 of file SimpSolver.h.

194 {
195 budgetOff(); assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp) == l_True; }
Here is the call graph for this function:

◆ solve() [3/5]

bool Gluco::SimpSolver::solve ( Lit p,
bool do_simp = true,
bool turn_off_simp = false )
inline

Definition at line 191 of file SimpSolver.h.

191{ budgetOff(); assumptions.clear(); assumptions.push(p); return solve_(do_simp, turn_off_simp) == l_True; }
Here is the call graph for this function:

◆ solve() [4/5]

bool Gluco::SimpSolver::solve ( Lit p,
Lit q,
bool do_simp = true,
bool turn_off_simp = false )
inline

Definition at line 192 of file SimpSolver.h.

192{ budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); return solve_(do_simp, turn_off_simp) == l_True; }
Here is the call graph for this function:

◆ solve() [5/5]

bool Gluco::SimpSolver::solve ( Lit p,
Lit q,
Lit r,
bool do_simp = true,
bool turn_off_simp = false )
inline

Definition at line 193 of file SimpSolver.h.

193{ budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); assumptions.push(r); return solve_(do_simp, turn_off_simp) == l_True; }
Here is the call graph for this function:

◆ solve_()

lbool SimpSolver::solve_ ( bool do_simp = true,
bool turn_off_simp = false )
protected

Definition at line 96 of file SimpSolver.cpp.

97{
98 vec<Var> extra_frozen;
99 lbool result = l_True;
100
101 do_simp &= use_simplification;
102
103 if (do_simp){
104 // Assumptions must be temporarily frozen to run variable elimination:
105 for (int i = 0; i < assumptions.size(); i++){
106 Var v = var(assumptions[i]);
107
108 // If an assumption has been eliminated, remember it.
109 assert(!isEliminated(v));
110
111 if (!frozen[v]){
112 // Freeze and store.
113 setFrozen(v, true);
114 extra_frozen.push(v);
115 } }
116
117 result = lbool(eliminate(turn_off_simp));
118 }
119
120 if (result == l_True)
121 result = Solver::solve_();
122 else if (verbosity >= 1)
123 printf("===============================================================================\n");
124
125 if (result == l_True)
126 extendModel();
127
128 if (do_simp)
129 // Unfreeze the assumptions that were frozen:
130 for (int i = 0; i < extra_frozen.size(); i++)
131 setFrozen(extra_frozen[i], false);
132
133 return result;
134}
void setFrozen(Var v, bool b)
Definition SimpSolver.h:188
bool eliminate(bool turn_off_elim=false)
Here is the call graph for this function:

◆ solveLimited()

lbool Gluco::SimpSolver::solveLimited ( const vec< Lit > & assumps,
bool do_simp = true,
bool turn_off_simp = false )
inline

Definition at line 197 of file SimpSolver.h.

197 {
198 assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp); }
Here is the call graph for this function:

◆ strengthenClause()

bool SimpSolver::strengthenClause ( CRef cr,
Lit l )
protected

Definition at line 198 of file SimpSolver.cpp.

199{
200 Clause& c = ca[cr];
201 assert(decisionLevel() == 0);
203
204 // FIX: this is too inefficient but would be nice to have (properly implemented)
205 // if (!find(subsumption_queue, &c))
206 subsumption_queue.insert(cr);
207
208 if (certifiedUNSAT) {
209 for (int i = 0; i < c.size(); i++)
210 if (c[i] != l) fprintf(certifiedOutput, "%i " , (var(c[i]) + 1) * (-2 * sign(c[i]) + 1) );
211 fprintf(certifiedOutput, "0\n");
212 }
213
214 if (c.size() == 2){
215 removeClause(cr);
216 c.strengthen(l);
217 }else{
218 if (certifiedUNSAT) {
219 fprintf(certifiedOutput, "d ");
220 for (int i = 0; i < c.size(); i++)
221 fprintf(certifiedOutput, "%i " , (var(c[i]) + 1) * (-2 * sign(c[i]) + 1) );
222 fprintf(certifiedOutput, "0\n");
223 }
224
225 detachClause(cr, true);
226 c.strengthen(l);
227 attachClause(cr);
228 remove(occurs[var(l)], cr);
229 n_occ[toInt(l)]--;
231 }
232
233 return c.size() == 1 ? enqueue(c[0]) && propagate() == CRef_Undef : true;
234}
void strengthen(Lit p)
void detachClause(CRef cr, bool strict=false)
Definition Glucose.cpp:306
void attachClause(CRef cr)
Definition Glucose.cpp:289
bool enqueue(Lit p, CRef from=CRef_Undef)
Definition Solver.h:401
Here is the call graph for this function:
Here is the caller graph for this function:

◆ substitute()

bool SimpSolver::substitute ( Var v,
Lit x )

Definition at line 559 of file SimpSolver.cpp.

560{
561 assert(!frozen[v]);
562 assert(!isEliminated(v));
563 assert(value(v) == l_Undef);
564
565 if (!ok) return false;
566
567 eliminated[v] = true;
568 setDecisionVar(v, false);
569 const vec<CRef>& cls = occurs.lookup(v);
570
571 vec<Lit>& subst_clause = add_tmp;
572 for (int i = 0; i < cls.size(); i++){
573 Clause& c = ca[cls[i]];
574
575 subst_clause.clear();
576 for (int j = 0; j < c.size(); j++){
577 Lit p = c[j];
578 subst_clause.push(var(p) == v ? x ^ sign(p) : p);
579 }
580
581
582 if (!addClause_(subst_clause))
583 return ok = false;
584
585 removeClause(cls[i]);
586
587 }
588
589 return true;
590}
Here is the call graph for this function:

◆ updateElimHeap()

void Gluco::SimpSolver::updateElimHeap ( Var v)
inlineprotected

Definition at line 176 of file SimpSolver.h.

176 {
178 // if (!frozen[v] && !isEliminated(v) && value(v) == l_Undef)
179 if (elim_heap.inHeap(v) || (!frozen[v] && !isEliminated(v) && value(v) == l_Undef))
180 elim_heap.update(v); }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ asymm_lits

int Gluco::SimpSolver::asymm_lits

Definition at line 100 of file SimpSolver.h.

◆ bwdsub_assigns

int Gluco::SimpSolver::bwdsub_assigns
protected

Definition at line 142 of file SimpSolver.h.

◆ bwdsub_tmpunit

CRef Gluco::SimpSolver::bwdsub_tmpunit
protected

Definition at line 147 of file SimpSolver.h.

◆ clause_lim

int Gluco::SimpSolver::clause_lim

Definition at line 88 of file SimpSolver.h.

◆ elim_heap

Heap<ElimLt> Gluco::SimpSolver::elim_heap
protected

Definition at line 138 of file SimpSolver.h.

◆ elimclauses

vec<uint32_t> Gluco::SimpSolver::elimclauses
protected

Definition at line 133 of file SimpSolver.h.

◆ eliminated

vec<char> Gluco::SimpSolver::eliminated
protected

Definition at line 141 of file SimpSolver.h.

◆ eliminated_clauses

int Gluco::SimpSolver::eliminated_clauses

Definition at line 102 of file SimpSolver.h.

◆ eliminated_vars

int Gluco::SimpSolver::eliminated_vars

Definition at line 101 of file SimpSolver.h.

◆ elimorder

int Gluco::SimpSolver::elimorder
protected

Definition at line 131 of file SimpSolver.h.

◆ frozen

vec<char> Gluco::SimpSolver::frozen
protected

Definition at line 140 of file SimpSolver.h.

◆ grow

int Gluco::SimpSolver::grow

Definition at line 87 of file SimpSolver.h.

◆ merges

int Gluco::SimpSolver::merges

Definition at line 99 of file SimpSolver.h.

◆ n_occ

vec<int> Gluco::SimpSolver::n_occ
protected

Definition at line 137 of file SimpSolver.h.

◆ n_touched

int Gluco::SimpSolver::n_touched
protected

Definition at line 143 of file SimpSolver.h.

◆ occurs

OccLists<Var, vec<CRef>, ClauseDeleted> Gluco::SimpSolver::occurs
protected

Definition at line 136 of file SimpSolver.h.

◆ parsing

int Gluco::SimpSolver::parsing

Definition at line 86 of file SimpSolver.h.

◆ simp_garbage_frac

double Gluco::SimpSolver::simp_garbage_frac

Definition at line 91 of file SimpSolver.h.

◆ subsumption_lim

int Gluco::SimpSolver::subsumption_lim

Definition at line 90 of file SimpSolver.h.

◆ subsumption_queue

Queue<CRef> Gluco::SimpSolver::subsumption_queue
protected

Definition at line 139 of file SimpSolver.h.

◆ touched

vec<char> Gluco::SimpSolver::touched
protected

Definition at line 134 of file SimpSolver.h.

◆ use_asymm

bool Gluco::SimpSolver::use_asymm

Definition at line 93 of file SimpSolver.h.

◆ use_elim

bool Gluco::SimpSolver::use_elim

Definition at line 95 of file SimpSolver.h.

◆ use_rcheck

bool Gluco::SimpSolver::use_rcheck

Definition at line 94 of file SimpSolver.h.

◆ use_simplification

bool Gluco::SimpSolver::use_simplification
protected

Definition at line 132 of file SimpSolver.h.


The documentation for this class was generated from the following files: