32 #define SAT_USE_ANALYZE_FINAL
41 #define L_ind sat_solver_dl(s)*2+2,sat_solver_dl(s)
43 #define L_lit(p) lit_sign(p)?"~":"", (lit_var(p))
51 for (i = 0; i < end - begin; i++)
60 static inline double drand(
double* seed) {
63 q = (int)(*seed / 2147483647);
64 *seed -= (double)q * 2147483647;
65 return *seed / 2147483647; }
99 assert( tag > 0 && tag < 16 );
100 if ( s->
tags[v] == 0 )
105 assert( tag > 0 && tag < 16 );
106 if ( s->
tags[v] == 0 )
113 s->
tags[tagged[i]] = 0;
144 int parent = (i - 1) / 2;
149 heap[i] = heap[parent];
150 orderpos[heap[i]] = i;
152 parent = (i - 1) / 2;
165 if (orderpos[v] == -1){
194 while (child < size){
195 if (child+1 < size && s->
activity[heap[child]] < s->
activity[heap[child+1]])
200 heap[i] = heap[child];
201 orderpos[heap[i]] = i;
203 child = 2 * child + 1;
206 orderpos[heap[i]] = i;
217 #ifdef USE_FLOAT_ACTIVITY
222 for (i = 0; i < s->
size; i++)
223 activity[i] *= 1e-100;
230 for (i = 0; i <
veci_size(&s->learnts); i++){
231 float a = clause_activity(cs[i]);
232 clause_setactivity(cs[i], a * (
float)1e-20);
266 float a = clause_activity(c) + s->
cla_inc;
267 clause_setactivity(c,a);
278 for (i = 0; i < s->
size; i++)
327 if ( *act & 0x80000000 )
340 static inline void selectionsort(
void** array,
int size,
int(*comp)(
const void *,
const void *))
345 for (i = 0; i < size-1; i++){
347 for (j = i+1; j <
size; j++){
348 if (comp(array[j], array[best_i]) < 0)
351 tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp;
355 static void sortrnd(
void** array,
int size,
int(*comp)(
const void *,
const void *),
double* seed)
361 void* pivot = array[
irand(seed, size)];
367 do i++;
while(comp(array[i], pivot)<0);
368 do j--;
while(comp(pivot, array[j])<0);
372 tmp = array[i]; array[i] = array[j]; array[j] = tmp;
375 sortrnd(array , i , comp, seed);
376 sortrnd(&array[i], size-i, comp, seed);
385 int i, lev, minl = 0, lbd = 0;
386 for (i = 0; i < (int)c->
size; i++)
389 if ( !(minl & (1 << (lev & 31))) )
391 minl |= 1 << (lev & 31);
404 int fUseBinaryClauses = 1;
410 assert(learnt >= 0 && learnt < 2);
414 if ( fUseBinaryClauses && size == 2 && !learnt )
546 for (c = s->
qtail-1; c >= bound; c--) {
554 for (c = s->
qhead-1; c >= bound; c--)
568 for (c = s->
qtail-1; c >= NewBound; c--)
575 for (c = s->
qhead-1; c >= NewBound; c--)
614 for ( i = 0; i < s->
size; i++ )
624 double F = 1.0 / s->
size;
625 for (i = 0; i < s->
size; i++)
628 return progress / s->
size;
727 #ifdef SAT_USE_ANALYZE_FINAL
739 for (i = skip_first ? 1 : 0; i <
clause_size(conf); i++)
780 int ind = s->
qtail-1;
832 minl |= 1 << (lev & 31);
836 for (i = j = 1; i <
veci_size(learnt); i++){
850 for (i = 0; i < s->
size; i++)
870 lits[1] = lits[max_i];
876 printf(
" } at level %d\n", lev);
890 while (hConfl == 0 && s->
qtail - s->
qhead > 0){
899 if ( (s->
loads[v] & 1) == 0 )
907 if ( (s->
loads[v] & 2) == 0 )
926 for (i = j = begin; i < end; ){
951 if (lits[0] == false_lit){
955 assert(lits[1] == false_lit);
964 for (k = lits + 2; k < stop; k++){
1041 #ifdef USE_FLOAT_ACTIVITY
1044 s->var_decay = (float)(1 / 0.95 );
1045 s->cla_decay = (float)(1 / 0.999);
1077 int old_cap = s->
cap;
1079 if ( s->
cap < 50000 )
1089 #ifdef USE_FLOAT_ACTIVITY
1106 for (var = s->
size; var < n; var++){
1113 #ifdef USE_FLOAT_ACTIVITY
1163 for (i = 0; i < s->
cap*2; i++)
1197 for ( i = 0; i < s->
size*2; i++ )
1207 #ifdef USE_FLOAT_ACTIVITY
1210 s->var_decay = (
float)(1 / 0.95 );
1211 s->cla_decay = (float)(1 / 0.999 );
1240 for (i = 0; i < s->
cap*2; i++)
1243 Mem += s->
cap *
sizeof(int);
1244 Mem += s->
cap *
sizeof(char);
1245 Mem += s->
cap *
sizeof(char);
1246 Mem += s->
cap *
sizeof(char);
1247 Mem += s->
cap *
sizeof(char);
1248 #ifdef USE_FLOAT_ACTIVITY
1249 Mem += s->
cap *
sizeof(double);
1251 Mem += s->
cap *
sizeof(unsigned);
1253 Mem += s->
cap *
sizeof(unsigned);
1256 Mem += s->
cap *
sizeof(double);
1257 Mem += s->
cap *
sizeof(int);
1258 Mem += s->
cap *
sizeof(int);
1259 Mem += s->
cap *
sizeof(
lit);
1260 Mem += s->
cap *
sizeof(int);
1291 int *
pPerm, * pArray, * pSortValues, nCutoffValue;
1292 int i, k, j, Id,
Counter, CounterStart, nSelected;
1306 pSortValues =
ABC_ALLOC(
int, nLearnedOld );
1310 pSortValues[Id] = (((7 -
Abc_MinInt(c->
lbd, 7)) << 28) | (act_clas[Id] >> 4));
1312 assert( pSortValues[Id] >= 0 );
1316 CounterStart = nLearnedOld - (s->
nLearntMax / 20);
1323 assert( pSortValues[pPerm[0]] <= pSortValues[pPerm[nLearnedOld-1]] );
1324 nCutoffValue = pSortValues[pPerm[nLearnedOld-nSelected]];
1343 assert( Counter == nLearnedOld );
1352 for ( i = 0; i < s->
size; i++ )
1366 for ( i = 0; i < s->
size*2; i++ )
1372 pArray[j++] = pArray[k];
1374 pArray[j++] = pArray[k];
1393 Abc_Print(1,
"reduceDB: Keeping %7d out of %7d clauses (%5.2f %%) ",
1405 static int Count = 0;
1435 pArray[j++] = pArray[k];
1439 for ( i = 2*s->
iVarPivot; i < 2*s->size; i++ )
1459 #ifdef USE_FLOAT_ACTIVITY
1462 s->var_decay = (float)(1 / 0.95 );
1463 s->cla_decay = (float)(1 / 0.999 );
1501 for ( i = begin; i < end; i++ )
1502 printf(
"%s%d ", (*i)&1 ?
"!":
"", (*i)>>1 );
1507 for ( i = begin; i < end; i++ )
1514 for (i = begin + 1; i < end; i++){
1517 for (j = i; j > begin && *(j-1) > l; j--)
1535 for (i = j = begin; i < end; i++){
1558 for (size = 1, seq = 0; size < x+1; seq++, size = 2*size + 1);
1559 while (size-1 != x){
1560 size = (size-1) >> 1;
1564 return pow(y, (
double)seq);
1570 for ( i = 0; i < 20; i++ )
1571 printf(
"%d ", (
int)
luby(2,i) );
1581 ABC_INT64_T conflictC = 0;
1616 #ifdef SAT_USE_ANALYZE_FINAL
1629 #ifdef SAT_USE_ANALYZE_FINAL
1631 if ( learnt_clause.
size == 1 )
1674 for (i = 0; i < s->
size; i++)
1702 int restart_iter = 0;
1703 ABC_INT64_T nof_conflicts;
1740 #ifndef SAT_USE_ANALYZE_FINAL
1743 for (i = begin; i < end; i++){
1794 #ifdef SAT_USE_ANALYZE_FINAL
1797 for ( i = begin; i < end; i++ )
1843 printf(
"==================================[MINISAT]===================================\n");
1844 printf(
"| Conflicts | ORIGINAL | LEARNT | Progress |\n");
1845 printf(
"| | Clauses Literals | Limit Clauses Literals Lit/Cl | |\n");
1846 printf(
"==============================================================================\n");
1856 printf(
"| %9.0f | %7.0f %8.0f | %7.0f %7.0f %8.0f %7.1f | %6.3f %% |\n",
1868 nof_conflicts = (ABC_INT64_T)( 100 *
luby(2, restart_iter++) );
1880 printf(
"==============================================================================\n");
static double sat_solver_progress(sat_solver *s)
static void act_clause_decay(sat_solver *s)
static void sat_solver_canceluntil_rollback(sat_solver *s, int NewBound)
static int order_select(sat_solver *s, float random_var_freq)
ABC_INT64_T clauses_literals
static void var_add_tag(sat_solver *s, int v, int tag)
static int irand(double *seed, int size)
static double Sat_MemMemoryAll(Sat_Mem_t *p)
static void var_set_polar(sat_solver *s, int v, int pol)
static double drand(double *seed)
void sat_solver_reducedb(sat_solver *s)
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
static void sat_solver_analyze(sat_solver *s, int h, veci *learnt)
static int sat_solver_lit_removable(sat_solver *s, int x, int minl)
int sat_solver_clause_new(sat_solver *s, lit *begin, lit *end, int learnt)
static void order_unassigned(sat_solver *s, int v)
#define ABC_REALLOC(type, obj, num)
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
static int lit_var(lit l)
static void sat_solver_record(sat_solver *s, veci *cls)
void Sto_ManMarkClausesA(Sto_Man_t *p)
static void veci_push(veci *v, int e)
void sat_solver_delete(sat_solver *s)
static void act_var_bump_factor(sat_solver *s, int v)
int sat_solver_nconflicts(sat_solver *s)
void * sat_solver_store_release(sat_solver *s)
static void Sat_MemRestart(Sat_Mem_t *p)
static void sat_solver_canceluntil(sat_solver *s, int level)
static void veci_delete(veci *v)
#define ABC_ALLOC(type, num)
static void act_var_bump_global(sat_solver *s, int v)
static veci * sat_solver_read_wlist(sat_solver *s, lit l)
#define LEARNT_MAX_START_DEFAULT
INCLUDES ///.
static void veci_resize(veci *v, int k)
static abctime Abc_Clock()
static int Abc_MaxInt(int a, int b)
double sat_solver_memory(sat_solver *s)
static void Sat_MemFree_(Sat_Mem_t *p)
static int clause_id(clause *c)
static void var_set_value(sat_solver *s, int v, int val)
double luby(double y, int x)
int sat_solver_count_assigned(sat_solver *s)
for(p=first;p->value< newval;p=p->next)
void sat_solver_store_write(sat_solver *s, char *pFileName)
#define Sat_MemForEachLearned(p, c, i, k)
void Sto_ManMarkRoots(Sto_Man_t *p)
static void check(int expr)
static void selectionsort(void **array, int size, int(*comp)(const void *, const void *))
ABC_INT64_T learnts_literals
static lit lit_neg(lit l)
static void Abc_PrintTime(int level, const char *pStr, abctime time)
int * Abc_MergeSortCost(int *pCosts, int nSize)
static int clause_size(clause *c)
int Sto_ManChangeLastClause(Sto_Man_t *p)
static int var_value(sat_solver *s, int v)
static int Abc_MinInt(int a, int b)
static int var_polar(sat_solver *s, int v)
static void veci_new(veci *v)
Sto_Man_t * Sto_ManAlloc()
MACRO DEFINITIONS ///.
static void var_set_level(sat_solver *s, int v, int lev)
static void sortrnd(void **array, int size, int(*comp)(const void *, const void *), double *seed)
static void var_set_tag(sat_solver *s, int v, int tag)
static int clause_learnt_h(Sat_Mem_t *p, cla h)
void sat_solver_store_alloc(sat_solver *s)
void sat_solver_setnvars(sat_solver *s, int n)
int sat_solver_nvars(sat_solver *s)
#define ABC_NAMESPACE_IMPL_END
static int veci_pop(veci *v)
static int clause_learnt(clause *c)
static void order_assigned(sat_solver *s, int v)
static void solver2_clear_tags(sat_solver *s, int start)
static int sat_solver_dl(sat_solver *s)
void sat_solver_store_mark_clauses_a(sat_solver *s)
void sat_solver_rollback(sat_solver *s)
static void sat_solver_analyze_final(sat_solver *s, int hConf, int skip_first)
static void Abc_Print(int level, const char *format,...)
void Sto_ManDumpClauses(Sto_Man_t *p, char *pFileName)
static const lit lit_Undef
static int var_tag(sat_solver *s, int v)
int sat_solver_nclauses(sat_solver *s)
#define ABC_NAMESPACE_IMPL_START
static int sat_clause_compute_lbd(sat_solver *s, clause *c)
static lbool sat_solver_search(sat_solver *s, ABC_INT64_T nof_conflicts)
void sat_solver_store_mark_roots(sat_solver *s)
static void act_clause_rescale(sat_solver *s)
static int clause_is_lit(cla h)
int sat_solver_simplify(sat_solver *s)
static lit * clause_begin(clause *c)
sat_solver * sat_solver_new(void)
static void printlits(lit *begin, lit *end)
int(* pCnfFunc)(void *p, int)
static int sat_solver_assume(sat_solver *s, lit l)
static int lit_sign(lit l)
void Sto_ManFree(Sto_Man_t *p)
static void act_var_rescale(sat_solver *s)
static void Sat_MemRollBack(Sat_Mem_t *p)
static lit clause_read_lit(cla h)
int Sto_ManAddClause(Sto_Man_t *p, lit *pBeg, lit *pEnd)
void sat_solver_store_free(sat_solver *s)
static clause * clause_read(sat_solver *s, cla h)
static void act_var_bump(sat_solver *s, int v)
#define LEARNT_MAX_INCRE_DEFAULT
#define ABC_CALLOC(type, num)
static int clause_from_lit(lit l)
GLOBAL VARIABLES ///.
static void Sat_MemAlloc_(Sat_Mem_t *p, int nPageSize)
static int Sat_MemEntryNum(Sat_Mem_t *p, int lrn)
static int Sat_MemAppend(Sat_Mem_t *p, int *pArray, int nSize, int lrn, int fPlus1)
static void order_update(sat_solver *s, int v)
static void act_clause_bump(sat_solver *s, clause *c)
int sat_solver_propagate(sat_solver *s)
int sat_solver_store_change_last(sat_solver *s)
static int Sat_MemClauseUsed(Sat_Mem_t *p, cla h)
static int sat_solver_enqueue(sat_solver *s, lit l, int from)
static int Sat_MemCompactLearned(Sat_Mem_t *p, int fDoMove)
void sat_solver_restart(sat_solver *s)
int sat_solver_get_var_value(sat_solver *s, int v)
static int * veci_begin(veci *v)
static int var_level(sat_solver *s, int v)
struct sat_solver_t sat_solver
static cla Sat_MemHand(Sat_Mem_t *p, int i, int k)
static int veci_size(veci *v)
#define LEARNT_MAX_RATIO_DEFAULT
static void act_var_decay(sat_solver *s)