1 #define __STDC_FORMAT_MACROS
2 #define __STDC_LIMIT_MACROS
30 using namespace Minisat;
36 static const char*
_cat =
"CORE";
77 , learntsize_factor((double)1/(double)3), learntsize_inc(1.1)
81 , learntsize_adjust_start_confl (100)
82 , learntsize_adjust_inc (1.5)
86 , solves(0), starts(0), decisions(0), rnd_decisions(0), propagations(0), conflicts(0)
87 , dec_vars(0), num_clauses(0), num_learnts(0), clauses_literals(0), learnts_literals(0), max_literals(0), tot_literals(0)
97 , progress_estimate (0)
98 , remove_satisfied (true)
103 , conflict_budget (-1)
104 , propagation_budget (-1)
105 , asynch_interrupt (false)
159 if (!
ok)
return false;
173 else if (ps.
size() == 1){
188 assert(c.
size() > 1);
198 assert(c.
size() > 1);
225 for (
int i = 0; i < c.
size(); i++)
343 for (i = j = 1; i < out_learnt.
size(); i++)
345 out_learnt[j++] = out_learnt[i];
348 for (i = j = 1; i < out_learnt.
size(); i++){
349 Var x =
var(out_learnt[i]);
352 out_learnt[j++] = out_learnt[i];
355 for (
int k = 1; k < c.
size(); k++)
357 out_learnt[j++] = out_learnt[i];
362 i = j = out_learnt.
size();
370 if (out_learnt.
size() == 1)
375 for (
int i = 2; i < out_learnt.
size(); i++)
379 Lit p = out_learnt[max_i];
380 out_learnt[max_i] = out_learnt[1];
392 enum { seen_undef = 0, seen_source = 1, seen_removable = 2, seen_failed = 3 };
393 assert(
seen[
var(p)] == seen_undef ||
seen[
var(p)] == seen_source);
400 for (uint32_t i = 1; ; i++){
401 if (i < (uint32_t)c->
size()){
412 for (
int i = 0; i < stack.
size(); i++)
413 if (
seen[
var(stack[i].l)] == seen_undef){
414 seen[
var(stack[i].l)] = seen_failed;
428 if (
seen[
var(p)] == seen_undef){
434 if (stack.
size() == 0)
break;
460 out_conflict.
clear();
472 assert(
level(x) > 0);
476 for (
int j = 1; j < c.
size(); j++)
519 for (i = j = (
Watcher*)ws, end = i + ws.
size(); i != end;){
523 *j++ = *i++;
continue; }
529 if (c[0] == false_lit)
530 c[0] = c[1], c[1] = false_lit;
531 assert(c[1] == false_lit);
538 *j++ = w;
continue; }
541 for (
int k = 2; k < c.size(); k++)
543 c[1] = c[k]; c[k] = false_lit;
581 return ca[x].size() > 2 && (ca[y].size() == 2 || ca[x].activity() < ca[y].activity()); }
593 if (c.
size() > 2 && !
locked(c) && (i < learnts.size() / 2 || c.
activity() < extra_lim))
596 learnts[j++] = learnts[i];
606 for (i = j = 0; i < cs.
size(); i++){
613 for (
int k = 2; k < c.
size(); k++)
615 c[k--] = c[c.
size()-1];
719 learnt_clause.
clear();
720 analyze(confl, learnt_clause, backtrack_level);
723 if (learnt_clause.
size() == 1){
742 printf(
"| %9d | %7d %8d %8d | %8d %8d %6.0f | %6.3f %% |\n",
750 if ((nof_conflicts >= 0 && conflictC >= nof_conflicts) || !
withinBudget()){
801 double F = 1.0 /
nVars();
806 progress += pow(F, i) * (end - beg);
809 return progress /
nVars();
824 static double luby(
double y,
int x){
829 for (size = 1, seq = 0; size < x+1; seq++, size = 2*size+1);
858 printf(
"============================[ Search Statistics ]==============================\n");
859 printf(
"| Conflicts | ORIGINAL | LEARNT | Progress |\n");
860 printf(
"| | Vars Clauses Literals | Limit Clauses Lit/Cl | |\n");
861 printf(
"===============================================================================\n");
865 int curr_restarts = 0;
874 printf(
"===============================================================================\n");
892 for (
int i = 0; i < assumps.
size(); i++){
906 for (
int j = trail_before; j <
trail.
size(); j++)
922 if (map.
size() <= x || map[x] == -1){
934 for (
int i = 0; i < c.
size(); i++)
936 fprintf(f,
"%s%d ",
sign(c[i]) ?
"-" :
"",
mapVar(
var(c[i]), map, max)+1);
943 FILE* f = fopen(file,
"wr");
945 fprintf(stderr,
"could not open file %s\n", file), exit(1);
955 fprintf(f,
"p cnf 1 2\n1 0\n-1 0\n");
970 for (
int j = 0; j < c.
size(); j++)
976 cnt += assumps.
size();
978 fprintf(f,
"p cnf %d %d\n", max, cnt);
980 for (
int i = 0; i < assumps.
size(); i++){
982 fprintf(f,
"%s%d 0\n",
sign(assumps[i]) ?
"-" :
"",
mapVar(
var(assumps[i]), map, max)+1);
989 printf(
"Wrote DIMACS with %d variables and %d clauses.\n", max, cnt);
997 printf(
"restarts : %" PRIu64
"\n",
starts);
1002 if (mem_used != 0) printf(
"Memory used : %.2f MB\n", mem_used);
1003 printf(
"CPU time : %g s\n", cpu_time);
1015 for (
int v = 0; v <
nVars(); v++)
1016 for (
int s = 0; s < 2; s++){
1019 for (
int j = 0; j < ws.
size(); j++)
1065 printf(
"| Garbage collection: %12d bytes => %12d bytes |\n",
RegionAllocator< uint32_t >::Ref CRef
static DoubleOption opt_garbage_frac(_cat,"gc-frac","The fraction of wasted memory allowed before a garbage collection is triggered", 0.20, DoubleRange(0, false, HUGE_VAL, false))
static double cpuTime(void)
bool locked(const Clause &c) const
static void append(const vec< T > &from, vec< T > &to)
const lbool l_False((uint8_t) 1)
void insert(K key, V val, V pad)
int learntsize_adjust_cnt
void sort(T *array, int size, LessThan lt)
static IntOption opt_phase_saving(_cat,"phase-saving","Controls the level of phase saving (0=none, 1=limited, 2=full)", 2, IntRange(0, 2))
void relocAll(ClauseAllocator &to)
Lit mkLit(Var var, bool sign=false)
static DoubleOption opt_random_seed(_cat,"rnd-seed","Used by the random variable selection", 91648253, DoubleRange(0, false, HUGE_VAL, false))
double learntsize_adjust_inc
bool withinBudget() const
void claBumpActivity(Clause &c)
void clear(bool free=false)
bool addClause(const vec< Lit > &ps)
int learntsize_adjust_start_confl
bool implies(const vec< Lit > &assumps, vec< Lit > &out)
const lbool l_Undef((uint8_t) 2)
void attachClause(CRef cr)
lbool search(int nof_conflicts)
void copyTo(vec< T > ©) const
const T & last(void) const
void setDecisionVar(Var v, bool b)
void cancelUntil(int level)
void insertVarOrder(Var x)
static DoubleOption opt_random_var_freq(_cat,"rnd-freq","The frequency with which the decision heuristic tries to choose a random variable", 0, DoubleRange(0, true, 1, true))
void detachClause(CRef cr, bool strict=false)
void removeSatisfied(vec< CRef > &cs)
void reserve(K key, V pad)
static BoolOption opt_luby_restart(_cat,"luby","Use the Luby restart sequence", true)
static DoubleOption opt_var_decay(_cat,"var-decay","The variable activity decay factor", 0.95, DoubleRange(0, false, 1, false))
uint64_t learnts_literals
static BoolOption opt_rnd_init_act(_cat,"rnd-init","Randomize the initial activity", false)
static double luby(double y, int x)
int decisionLevel() const
bool addClause_(vec< Lit > &ps)
uint64_t clauses_literals
static DoubleOption opt_clause_decay(_cat,"cla-decay","The clause activity decay factor", 0.999, DoubleRange(0, false, 1, false))
reduceDB_lt(ClauseAllocator &ca_)
void reloc(CRef &cr, ClauseAllocator &to)
Heap< Var, VarOrderLt > order_heap
void analyzeFinal(Lit p, LSet &out_conflict)
void removeClause(CRef cr)
vec< Lit > analyze_toclear
void toDimacs(FILE *f, const vec< Lit > &assumps)
static double drand(double &seed)
Var newVar(lbool upol=l_Undef, bool dvar=true)
const lbool l_True((uint8_t) 0)
vec< ShrinkStackElem > analyze_stack
void clear(bool dealloc=false)
static IntOption opt_restart_first(_cat,"rfirst","The base restart interval", 100, IntRange(1, INT32_MAX))
virtual void garbageCollect()
CRef alloc(const vec< Lit > &ps, bool learnt=false)
void push_(const T &elem)
static DoubleOption opt_restart_inc(_cat,"rinc","Restart interval increase factor", 2, DoubleRange(1, false, HUGE_VAL, false))
static int irand(double &seed, int size)
void uncheckedEnqueue(Lit p, CRef from=CRef_Undef)
void analyze(CRef confl, vec< Lit > &out_learnt, int &out_btlevel)
bool isRemoved(CRef cr) const
bool satisfied(const Clause &c) const
double progressEstimate() const
double memUsedPeak(bool strictlyPeak=false)
static Var mapVar(Var x, vec< Var > &map, Var &max)
static IntOption opt_min_learnts_lim(_cat,"min-learnts","Minimum learnt clause limit", 0, IntRange(0, INT32_MAX))
void varBumpActivity(Var v, double inc)
OccLists< Lit, vec< Watcher >, WatcherDeleted, MkIndexLit > watches
static VarData mkVarData(CRef cr, int l)
static IntOption opt_ccmin_mode(_cat,"ccmin-mode","Controls conflict clause minimization (0=none, 1=basic, 2=deep)", 2, IntRange(0, 2))
double learntsize_adjust_confl