abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
satSolver.c File Reference
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include "satSolver.h"
#include "satStore.h"

Go to the source code of this file.

Data Structures

struct  varinfo_t
 

Macros

#define SAT_USE_ANALYZE_FINAL
 
#define L_IND   "%-*d"
 
#define L_ind   sat_solver_dl(s)*2+2,sat_solver_dl(s)
 
#define L_LIT   "%sx%d"
 
#define L_lit(p)   lit_sign(p)?"~":"", (lit_var(p))
 

Functions

static void check (int expr)
 
static void printlits (lit *begin, lit *end)
 
static double drand (double *seed)
 
static int irand (double *seed, int size)
 
static int var_level (sat_solver *s, int v)
 
static int var_value (sat_solver *s, int v)
 
static int var_polar (sat_solver *s, int v)
 
static void var_set_level (sat_solver *s, int v, int lev)
 
static void var_set_value (sat_solver *s, int v, int val)
 
static void var_set_polar (sat_solver *s, int v, int pol)
 
static int var_tag (sat_solver *s, int v)
 
static void var_set_tag (sat_solver *s, int v, int tag)
 
static void var_add_tag (sat_solver *s, int v, int tag)
 
static void solver2_clear_tags (sat_solver *s, int start)
 
int sat_solver_get_var_value (sat_solver *s, int v)
 
static int sat_solver_dl (sat_solver *s)
 
static vecisat_solver_read_wlist (sat_solver *s, lit l)
 
static void order_update (sat_solver *s, int v)
 
static void order_assigned (sat_solver *s, int v)
 
static void order_unassigned (sat_solver *s, int v)
 
static int order_select (sat_solver *s, float random_var_freq)
 
static void act_var_rescale (sat_solver *s)
 
static void act_clause_rescale (sat_solver *s)
 
static void act_var_bump (sat_solver *s, int v)
 
static void act_var_bump_global (sat_solver *s, int v)
 
static void act_var_bump_factor (sat_solver *s, int v)
 
static void act_clause_bump (sat_solver *s, clause *c)
 
static void act_var_decay (sat_solver *s)
 
static void act_clause_decay (sat_solver *s)
 
static void selectionsort (void **array, int size, int(*comp)(const void *, const void *))
 
static void sortrnd (void **array, int size, int(*comp)(const void *, const void *), double *seed)
 
static int sat_clause_compute_lbd (sat_solver *s, clause *c)
 
int sat_solver_clause_new (sat_solver *s, lit *begin, lit *end, int learnt)
 
static int sat_solver_enqueue (sat_solver *s, lit l, int from)
 
static int sat_solver_assume (sat_solver *s, lit l)
 
static void sat_solver_canceluntil (sat_solver *s, int level)
 
static void sat_solver_canceluntil_rollback (sat_solver *s, int NewBound)
 
static void sat_solver_record (sat_solver *s, veci *cls)
 
int sat_solver_count_assigned (sat_solver *s)
 
static double sat_solver_progress (sat_solver *s)
 
static int sat_solver_lit_removable (sat_solver *s, int x, int minl)
 
static void sat_solver_analyze_final (sat_solver *s, int hConf, int skip_first)
 
static void sat_solver_analyze (sat_solver *s, int h, veci *learnt)
 
int sat_solver_propagate (sat_solver *s)
 
sat_solversat_solver_new (void)
 
void sat_solver_setnvars (sat_solver *s, int n)
 
void sat_solver_delete (sat_solver *s)
 
void sat_solver_restart (sat_solver *s)
 
double sat_solver_memory (sat_solver *s)
 
int sat_solver_simplify (sat_solver *s)
 
void sat_solver_reducedb (sat_solver *s)
 
void sat_solver_rollback (sat_solver *s)
 
int sat_solver_addclause (sat_solver *s, lit *begin, lit *end)
 
double luby (double y, int x)
 
void luby_test ()
 
static lbool sat_solver_search (sat_solver *s, ABC_INT64_T nof_conflicts)
 
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)
 
int sat_solver_nvars (sat_solver *s)
 
int sat_solver_nclauses (sat_solver *s)
 
int sat_solver_nconflicts (sat_solver *s)
 
void sat_solver_store_alloc (sat_solver *s)
 
void sat_solver_store_write (sat_solver *s, char *pFileName)
 
void sat_solver_store_free (sat_solver *s)
 
int sat_solver_store_change_last (sat_solver *s)
 
void sat_solver_store_mark_roots (sat_solver *s)
 
void sat_solver_store_mark_clauses_a (sat_solver *s)
 
void * sat_solver_store_release (sat_solver *s)
 

Variables

static const int var0 = 1
 
static const int var1 = 0
 
static const int varX = 3
 

Macro Definition Documentation

#define L_IND   "%-*d"

Definition at line 40 of file satSolver.c.

#define L_ind   sat_solver_dl(s)*2+2,sat_solver_dl(s)

Definition at line 41 of file satSolver.c.

#define L_LIT   "%sx%d"

Definition at line 42 of file satSolver.c.

#define L_lit (   p)    lit_sign(p)?"~":"", (lit_var(p))

Definition at line 43 of file satSolver.c.

#define SAT_USE_ANALYZE_FINAL

Definition at line 32 of file satSolver.c.

Function Documentation

static void act_clause_bump ( sat_solver s,
clause c 
)
inlinestatic

Definition at line 324 of file satSolver.c.

324  {
325  unsigned* act = (unsigned *)veci_begin(&s->act_clas) + c->lits[c->size];
326  *act += s->cla_inc;
327  if ( *act & 0x80000000 )
329 }
lit lits[0]
Definition: satClause.h:56
veci act_clas
Definition: satSolver.h:104
static void act_clause_rescale(sat_solver *s)
Definition: satSolver.c:284
unsigned size
Definition: satClause.h:55
static int * veci_begin(veci *v)
Definition: satVec.h:45
static void act_clause_decay ( sat_solver s)
inlinestatic

Definition at line 332 of file satSolver.c.

332 { s->cla_inc += (s->cla_inc >> 10); }
static void act_clause_rescale ( sat_solver s)
inlinestatic

Definition at line 284 of file satSolver.c.

284  {
285  static abctime Total = 0;
286  abctime clk = Abc_Clock();
287  unsigned* activity = (unsigned *)veci_begin(&s->act_clas);
288  int i;
289  for (i = 0; i < veci_size(&s->act_clas); i++)
290  activity[i] >>= 14;
291  s->cla_inc >>= 14;
292  s->cla_inc = Abc_MaxInt( s->cla_inc, (1<<10) );
293  Total += Abc_Clock() - clk;
294 // printf( "Rescaling... Cla inc = %5d Conf = %10d ", s->cla_inc, s->stats.conflicts );
295 // Abc_PrintTime( 1, "Time", Total );
296 }
veci act_clas
Definition: satSolver.h:104
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
ABC_INT64_T abctime
Definition: abc_global.h:278
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
static void act_var_bump ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 298 of file satSolver.c.

298  {
299  s->activity[v] += s->var_inc;
300  if (s->activity[v] & 0x80000000)
301  act_var_rescale(s);
302  if (s->orderpos[v] != -1)
303  order_update(s,v);
304 }
unsigned * activity
Definition: satSolver.h:122
int * orderpos
Definition: satSolver.h:135
static void act_var_rescale(sat_solver *s)
Definition: satSolver.c:275
static void order_update(sat_solver *s, int v)
Definition: satSolver.c:138
static void act_var_bump_factor ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 314 of file satSolver.c.

314  {
315  if ( !s->factors )
316  return;
317  s->activity[v] += (int)(s->var_inc * s->factors[v]);
318  if (s->activity[v] & 0x80000000)
319  act_var_rescale(s);
320  if (s->orderpos[v] != -1)
321  order_update(s,v);
322 }
unsigned * activity
Definition: satSolver.h:122
double * factors
Definition: satSolver.h:168
int * orderpos
Definition: satSolver.h:135
static void act_var_rescale(sat_solver *s)
Definition: satSolver.c:275
static void order_update(sat_solver *s, int v)
Definition: satSolver.c:138
static void act_var_bump_global ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 305 of file satSolver.c.

305  {
306  if ( !s->pGlobalVars )
307  return;
308  s->activity[v] += (int)(s->var_inc * 3 * s->pGlobalVars[v]);
309  if (s->activity[v] & 0x80000000)
310  act_var_rescale(s);
311  if (s->orderpos[v] != -1)
312  order_update(s,v);
313 }
unsigned * activity
Definition: satSolver.h:122
int * orderpos
Definition: satSolver.h:135
int * pGlobalVars
Definition: satSolver.h:178
static void act_var_rescale(sat_solver *s)
Definition: satSolver.c:275
static void order_update(sat_solver *s, int v)
Definition: satSolver.c:138
static void act_var_decay ( sat_solver s)
inlinestatic

Definition at line 331 of file satSolver.c.

331 { s->var_inc += (s->var_inc >> 4); }
static void act_var_rescale ( sat_solver s)
inlinestatic

Definition at line 275 of file satSolver.c.

275  {
276  unsigned* activity = s->activity;
277  int i;
278  for (i = 0; i < s->size; i++)
279  activity[i] >>= 19;
280  s->var_inc >>= 19;
281  s->var_inc = Abc_MaxInt( s->var_inc, (1<<4) );
282 }
unsigned * activity
Definition: satSolver.h:122
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static void check ( int  expr)
inlinestatic

Definition at line 46 of file satSolver.c.

46 { assert(expr); }
#define assert(ex)
Definition: util_old.h:213
static double drand ( double *  seed)
inlinestatic

Definition at line 60 of file satSolver.c.

60  {
61  int q;
62  *seed *= 1389796;
63  q = (int)(*seed / 2147483647);
64  *seed -= (double)q * 2147483647;
65  return *seed / 2147483647; }
static int irand ( double *  seed,
int  size 
)
inlinestatic

Definition at line 69 of file satSolver.c.

69  {
70  return (int)(drand(seed) * size); }
static double drand(double *seed)
Definition: satSolver.c:60
static int size
Definition: cuddSign.c:86
double luby ( double  y,
int  x 
)

Definition at line 1555 of file satSolver.c.

1556 {
1557  int size, seq;
1558  for (size = 1, seq = 0; size < x+1; seq++, size = 2*size + 1);
1559  while (size-1 != x){
1560  size = (size-1) >> 1;
1561  seq--;
1562  x = x % size;
1563  }
1564  return pow(y, (double)seq);
1565 }
static int size
Definition: cuddSign.c:86
void luby_test ( )

Definition at line 1567 of file satSolver.c.

1568 {
1569  int i;
1570  for ( i = 0; i < 20; i++ )
1571  printf( "%d ", (int)luby(2,i) );
1572  printf( "\n" );
1573 }
double luby(double y, int x)
Definition: satSolver.c:1555
static void order_assigned ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 158 of file satSolver.c.

159 {
160 }
static int order_select ( sat_solver s,
float  random_var_freq 
)
inlinestatic

Definition at line 173 of file satSolver.c.

174 {
175  int* heap = veci_begin(&s->order);
176  int* orderpos = s->orderpos;
177  // Random decision:
178  if (drand(&s->random_seed) < random_var_freq){
179  int next = irand(&s->random_seed,s->size);
180  assert(next >= 0 && next < s->size);
181  if (var_value(s, next) == varX)
182  return next;
183  }
184  // Activity based decision:
185  while (veci_size(&s->order) > 0){
186  int next = heap[0];
187  int size = veci_size(&s->order)-1;
188  int x = heap[size];
189  veci_resize(&s->order,size);
190  orderpos[next] = -1;
191  if (size > 0){
192  int i = 0;
193  int child = 1;
194  while (child < size){
195  if (child+1 < size && s->activity[heap[child]] < s->activity[heap[child+1]])
196  child++;
197  assert(child < size);
198  if (s->activity[x] >= s->activity[heap[child]])
199  break;
200  heap[i] = heap[child];
201  orderpos[heap[i]] = i;
202  i = child;
203  child = 2 * child + 1;
204  }
205  heap[i] = x;
206  orderpos[heap[i]] = i;
207  }
208  if (var_value(s, next) == varX)
209  return next;
210  }
211  return var_Undef;
212 }
static int irand(double *seed, int size)
Definition: satSolver.c:69
static double drand(double *seed)
Definition: satSolver.c:60
struct hash_element * next
Definition: place_test.c:27
unsigned * activity
Definition: satSolver.h:122
double random_seed
Definition: satSolver.h:151
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
int * orderpos
Definition: satSolver.h:135
static int size
Definition: cuddSign.c:86
#define assert(ex)
Definition: util_old.h:213
#define var_Undef
Definition: SolverTypes.h:43
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
static const int varX
Definition: satSolver.c:78
static void order_unassigned ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 162 of file satSolver.c.

163 {
164  int* orderpos = s->orderpos;
165  if (orderpos[v] == -1){
166  orderpos[v] = veci_size(&s->order);
167  veci_push(&s->order,v);
168  order_update(s,v);
169 //printf( "+%d ", v );
170  }
171 }
static void veci_push(veci *v, int e)
Definition: satVec.h:53
int * orderpos
Definition: satSolver.h:135
static void order_update(sat_solver *s, int v)
Definition: satSolver.c:138
static int veci_size(veci *v)
Definition: satVec.h:46
static void order_update ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 138 of file satSolver.c.

139 {
140  int* orderpos = s->orderpos;
141  int* heap = veci_begin(&s->order);
142  int i = orderpos[v];
143  int x = heap[i];
144  int parent = (i - 1) / 2;
145 
146  assert(s->orderpos[v] != -1);
147 
148  while (i != 0 && s->activity[x] > s->activity[heap[parent]]){
149  heap[i] = heap[parent];
150  orderpos[heap[i]] = i;
151  i = parent;
152  parent = (i - 1) / 2;
153  }
154  heap[i] = x;
155  orderpos[x] = i;
156 }
unsigned * activity
Definition: satSolver.h:122
int * orderpos
Definition: satSolver.h:135
#define assert(ex)
Definition: util_old.h:213
static int * veci_begin(veci *v)
Definition: satVec.h:45
static void printlits ( lit begin,
lit end 
)
static

Definition at line 48 of file satSolver.c.

49 {
50  int i;
51  for (i = 0; i < end - begin; i++)
52  printf(L_LIT" ",L_lit(begin[i]));
53 }
#define L_lit(p)
Definition: satSolver.c:43
#define L_LIT
Definition: satSolver.c:42
static int sat_clause_compute_lbd ( sat_solver s,
clause c 
)
inlinestatic

Definition at line 383 of file satSolver.c.

384 {
385  int i, lev, minl = 0, lbd = 0;
386  for (i = 0; i < (int)c->size; i++)
387  {
388  lev = var_level(s, lit_var(c->lits[i]));
389  if ( !(minl & (1 << (lev & 31))) )
390  {
391  minl |= 1 << (lev & 31);
392  lbd++;
393 // printf( "%d ", lev );
394  }
395  }
396 // printf( " -> %d\n", lbd );
397  return lbd;
398 }
lit lits[0]
Definition: satClause.h:56
static int lit_var(lit l)
Definition: satVec.h:145
unsigned size
Definition: satClause.h:55
static int var_level(sat_solver *s, int v)
Definition: satSolver.c:88
int sat_solver_addclause ( sat_solver s,
lit begin,
lit end 
)

Definition at line 1492 of file satSolver.c.

1493 {
1494  int fVerbose = 0;
1495  lit *i,*j;
1496  int maxvar;
1497  lit last;
1498  assert( begin < end );
1499  if ( fVerbose )
1500  {
1501  for ( i = begin; i < end; i++ )
1502  printf( "%s%d ", (*i)&1 ? "!":"", (*i)>>1 );
1503  printf( "\n" );
1504  }
1505 
1506  veci_resize( &s->temp_clause, 0 );
1507  for ( i = begin; i < end; i++ )
1508  veci_push( &s->temp_clause, *i );
1509  begin = veci_begin( &s->temp_clause );
1510  end = begin + veci_size( &s->temp_clause );
1511 
1512  // insertion sort
1513  maxvar = lit_var(*begin);
1514  for (i = begin + 1; i < end; i++){
1515  lit l = *i;
1516  maxvar = lit_var(l) > maxvar ? lit_var(l) : maxvar;
1517  for (j = i; j > begin && *(j-1) > l; j--)
1518  *j = *(j-1);
1519  *j = l;
1520  }
1521  sat_solver_setnvars(s,maxvar+1);
1522 
1523  ///////////////////////////////////
1524  // add clause to internal storage
1525  if ( s->pStore )
1526  {
1527  int RetValue = Sto_ManAddClause( (Sto_Man_t *)s->pStore, begin, end );
1528  assert( RetValue );
1529  (void) RetValue;
1530  }
1531  ///////////////////////////////////
1532 
1533  // delete duplicates
1534  last = lit_Undef;
1535  for (i = j = begin; i < end; i++){
1536  //printf("lit: "L_LIT", value = %d\n", L_lit(*i), (lit_sign(*i) ? -s->assignss[lit_var(*i)] : s->assignss[lit_var(*i)]));
1537  if (*i == lit_neg(last) || var_value(s, lit_var(*i)) == lit_sign(*i))
1538  return true; // tautology
1539  else if (*i != last && var_value(s, lit_var(*i)) == varX)
1540  last = *j++ = *i;
1541  }
1542 // j = i;
1543 
1544  if (j == begin) // empty clause
1545  return false;
1546 
1547  if (j - begin == 1) // unit clause
1548  return sat_solver_enqueue(s,*begin,0);
1549 
1550  // create new clause
1551  sat_solver_clause_new(s,begin,j,0);
1552  return true;
1553 }
int sat_solver_clause_new(sat_solver *s, lit *begin, lit *end, int learnt)
Definition: satSolver.c:402
veci temp_clause
Definition: satSolver.h:188
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_push(veci *v, int e)
Definition: satVec.h:53
void * pStore
Definition: satSolver.h:180
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
int lit
Definition: satVec.h:130
static lit lit_neg(lit l)
Definition: satVec.h:144
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
void sat_solver_setnvars(sat_solver *s, int n)
Definition: satSolver.c:1072
static const lit lit_Undef
Definition: satVec.h:136
static int lit_sign(lit l)
Definition: satVec.h:146
int Sto_ManAddClause(Sto_Man_t *p, lit *pBeg, lit *pEnd)
Definition: satStore.c:160
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_enqueue(sat_solver *s, lit l, int from)
Definition: satSolver.c:466
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
static const int varX
Definition: satSolver.c:78
static void sat_solver_analyze ( sat_solver s,
int  h,
veci learnt 
)
static

Definition at line 775 of file satSolver.c.

776 {
777  lit* trail = s->trail;
778  int cnt = 0;
779  lit p = lit_Undef;
780  int ind = s->qtail-1;
781  lit* lits;
782  int i, j, minl;
783  veci_push(learnt,lit_Undef);
784  do{
785  assert(h != 0);
786  if (clause_is_lit(h)){
787  int x = lit_var(clause_read_lit(h));
788  if (var_tag(s, x) == 0 && var_level(s, x) > 0){
789  var_set_tag(s, x, 1);
790  act_var_bump(s,x);
791  if (var_level(s, x) == sat_solver_dl(s))
792  cnt++;
793  else
794  veci_push(learnt,clause_read_lit(h));
795  }
796  }else{
797  clause* c = clause_read(s, h);
798  if (clause_learnt(c))
799  act_clause_bump(s,c);
800  lits = clause_begin(c);
801  //printlits(lits,lits+clause_size(c)); printf("\n");
802  for (j = (p == lit_Undef ? 0 : 1); j < clause_size(c); j++){
803  int x = lit_var(lits[j]);
804  if (var_tag(s, x) == 0 && var_level(s, x) > 0){
805  var_set_tag(s, x, 1);
806  act_var_bump(s,x);
807  // bump variables propaged by the LBD=2 clause
808 // if ( s->reasons[x] && clause_read(s, s->reasons[x])->lbd <= 2 )
809 // act_var_bump(s,x);
810  if (var_level(s,x) == sat_solver_dl(s))
811  cnt++;
812  else
813  veci_push(learnt,lits[j]);
814  }
815  }
816  }
817 
818  while ( !var_tag(s, lit_var(trail[ind--])) );
819 
820  p = trail[ind+1];
821  h = s->reasons[lit_var(p)];
822  cnt--;
823 
824  }while (cnt > 0);
825 
826  *veci_begin(learnt) = lit_neg(p);
827 
828  lits = veci_begin(learnt);
829  minl = 0;
830  for (i = 1; i < veci_size(learnt); i++){
831  int lev = var_level(s, lit_var(lits[i]));
832  minl |= 1 << (lev & 31);
833  }
834 
835  // simplify (full)
836  for (i = j = 1; i < veci_size(learnt); i++){
837  if (s->reasons[lit_var(lits[i])] == 0 || !sat_solver_lit_removable(s,lit_var(lits[i]),minl))
838  lits[j++] = lits[i];
839  }
840 
841  // update size of learnt + statistics
842  veci_resize(learnt,j);
843  s->stats.tot_literals += j;
844 
845 
846  // clear tags
847  solver2_clear_tags(s,0);
848 
849 #ifdef DEBUG
850  for (i = 0; i < s->size; i++)
851  assert(!var_tag(s, i));
852 #endif
853 
854 #ifdef VERBOSEDEBUG
855  printf(L_IND"Learnt {", L_ind);
856  for (i = 0; i < veci_size(learnt); i++) printf(" "L_LIT, L_lit(lits[i]));
857 #endif
858  if (veci_size(learnt) > 1){
859  int max_i = 1;
860  int max = var_level(s, lit_var(lits[1]));
861  lit tmp;
862 
863  for (i = 2; i < veci_size(learnt); i++)
864  if (var_level(s, lit_var(lits[i])) > max){
865  max = var_level(s, lit_var(lits[i]));
866  max_i = i;
867  }
868 
869  tmp = lits[1];
870  lits[1] = lits[max_i];
871  lits[max_i] = tmp;
872  }
873 #ifdef VERBOSEDEBUG
874  {
875  int lev = veci_size(learnt) > 1 ? var_level(s, lit_var(lits[1])) : 0;
876  printf(" } at level %d\n", lev);
877  }
878 #endif
879 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define L_lit(p)
Definition: satSolver.c:43
ABC_INT64_T tot_literals
Definition: satVec.h:155
static int sat_solver_lit_removable(sat_solver *s, int x, int minl)
Definition: satSolver.c:634
int * reasons
Definition: satSolver.h:136
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_push(veci *v, int e)
Definition: satVec.h:53
#define L_ind
Definition: satSolver.c:41
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
#define L_LIT
Definition: satSolver.c:42
stats_t stats
Definition: satSolver.h:156
int lit
Definition: satVec.h:130
static lit lit_neg(lit l)
Definition: satVec.h:144
static int clause_size(clause *c)
Definition: satClause.h:146
static void var_set_tag(sat_solver *s, int v, int tag)
Definition: satSolver.c:98
static double max
Definition: cuddSubsetHB.c:134
static int clause_learnt(clause *c)
Definition: satClause.h:143
static void solver2_clear_tags(sat_solver *s, int start)
Definition: satSolver.c:110
static int sat_solver_dl(sat_solver *s)
Definition: satSolver.c:132
static const lit lit_Undef
Definition: satVec.h:136
static int var_tag(sat_solver *s, int v)
Definition: satSolver.c:97
static int clause_is_lit(cla h)
Definition: satClause.h:139
static lit * clause_begin(clause *c)
Definition: satClause.h:147
#define L_IND
Definition: satSolver.c:40
lit * trail
Definition: satSolver.h:137
static lit clause_read_lit(cla h)
Definition: satClause.h:140
static clause * clause_read(sat_solver *s, cla h)
Definition: satSolver.h:195
static void act_var_bump(sat_solver *s, int v)
Definition: satSolver.c:298
static void act_clause_bump(sat_solver *s, clause *c)
Definition: satSolver.c:324
#define assert(ex)
Definition: util_old.h:213
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int var_level(sat_solver *s, int v)
Definition: satSolver.c:88
static int veci_size(veci *v)
Definition: satVec.h:46
static void sat_solver_analyze_final ( sat_solver s,
int  hConf,
int  skip_first 
)
static

Definition at line 729 of file satSolver.c.

730 {
731  clause* conf = clause_read(s, hConf);
732  int i, j, start;
733  veci_resize(&s->conf_final,0);
734  if ( s->root_level == 0 )
735  return;
736  assert( veci_size(&s->tagged) == 0 );
737 // assert( s->tags[lit_var(p)] == l_Undef );
738 // s->tags[lit_var(p)] = l_True;
739  for (i = skip_first ? 1 : 0; i < clause_size(conf); i++)
740  {
741  int x = lit_var(clause_begin(conf)[i]);
742  if (var_level(s, x) > 0)
743  var_set_tag(s, x, 1);
744  }
745 
746  start = (s->root_level >= veci_size(&s->trail_lim))? s->qtail-1 : (veci_begin(&s->trail_lim))[s->root_level];
747  for (i = start; i >= (veci_begin(&s->trail_lim))[0]; i--){
748  int x = lit_var(s->trail[i]);
749  if (var_tag(s,x)){
750  if (s->reasons[x] == 0){
751  assert(var_level(s, x) > 0);
752  veci_push(&s->conf_final,lit_neg(s->trail[i]));
753  }else{
754  if (clause_is_lit(s->reasons[x])){
755  lit q = clause_read_lit(s->reasons[x]);
756  assert(lit_var(q) >= 0 && lit_var(q) < s->size);
757  if (var_level(s, lit_var(q)) > 0)
758  var_set_tag(s, lit_var(q), 1);
759  }
760  else{
761  clause* c = clause_read(s, s->reasons[x]);
762  int* lits = clause_begin(c);
763  for (j = 1; j < clause_size(c); j++)
764  if (var_level(s, lit_var(lits[j])) > 0)
765  var_set_tag(s, lit_var(lits[j]), 1);
766  }
767  }
768  }
769  }
770  solver2_clear_tags(s,0);
771 }
int * reasons
Definition: satSolver.h:136
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_push(veci *v, int e)
Definition: satVec.h:53
int root_level
Definition: satSolver.h:148
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
for(p=first;p->value< newval;p=p->next)
int lit
Definition: satVec.h:130
static lit lit_neg(lit l)
Definition: satVec.h:144
static int clause_size(clause *c)
Definition: satClause.h:146
static void var_set_tag(sat_solver *s, int v, int tag)
Definition: satSolver.c:98
veci conf_final
Definition: satSolver.h:145
static void solver2_clear_tags(sat_solver *s, int start)
Definition: satSolver.c:110
veci trail_lim
Definition: satSolver.h:142
static int var_tag(sat_solver *s, int v)
Definition: satSolver.c:97
static int clause_is_lit(cla h)
Definition: satClause.h:139
static lit * clause_begin(clause *c)
Definition: satClause.h:147
lit * trail
Definition: satSolver.h:137
static lit clause_read_lit(cla h)
Definition: satClause.h:140
static clause * clause_read(sat_solver *s, cla h)
Definition: satSolver.h:195
#define assert(ex)
Definition: util_old.h:213
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int var_level(sat_solver *s, int v)
Definition: satSolver.c:88
static int veci_size(veci *v)
Definition: satVec.h:46
static int sat_solver_assume ( sat_solver s,
lit  l 
)
inlinestatic

Definition at line 516 of file satSolver.c.

516  {
517  assert(s->qtail == s->qhead);
518  assert(var_value(s, lit_var(l)) == varX);
519 #ifdef VERBOSEDEBUG
520  printf(L_IND"assume("L_LIT") ", L_ind, L_lit(l));
521  printf( "act = %.20f\n", s->activity[lit_var(l)] );
522 #endif
523  veci_push(&s->trail_lim,s->qtail);
524  return sat_solver_enqueue(s,l,0);
525 }
#define L_lit(p)
Definition: satSolver.c:43
unsigned * activity
Definition: satSolver.h:122
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_push(veci *v, int e)
Definition: satVec.h:53
#define L_ind
Definition: satSolver.c:41
#define L_LIT
Definition: satSolver.c:42
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
veci trail_lim
Definition: satSolver.h:142
#define L_IND
Definition: satSolver.c:40
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_enqueue(sat_solver *s, lit l, int from)
Definition: satSolver.c:466
static const int varX
Definition: satSolver.c:78
static void sat_solver_canceluntil ( sat_solver s,
int  level 
)
static

Definition at line 528 of file satSolver.c.

528  {
529  int bound;
530  int lastLev;
531  int c;
532 
533  if (sat_solver_dl(s) <= level)
534  return;
535 
536  assert( veci_size(&s->trail_lim) > 0 );
537  bound = (veci_begin(&s->trail_lim))[level];
538  lastLev = (veci_begin(&s->trail_lim))[veci_size(&s->trail_lim)-1];
539 
540  ////////////////////////////////////////
541  // added to cancel all assignments
542 // if ( level == -1 )
543 // bound = 0;
544  ////////////////////////////////////////
545 
546  for (c = s->qtail-1; c >= bound; c--) {
547  int x = lit_var(s->trail[c]);
548  var_set_value(s, x, varX);
549  s->reasons[x] = 0;
550  if ( c < lastLev )
551  var_set_polar( s, x, !lit_sign(s->trail[c]) );
552  }
553 
554  for (c = s->qhead-1; c >= bound; c--)
555  order_unassigned(s,lit_var(s->trail[c]));
556 
557  s->qhead = s->qtail = bound;
558  veci_resize(&s->trail_lim,level);
559 }
static void var_set_polar(sat_solver *s, int v, int pol)
Definition: satSolver.c:94
int * reasons
Definition: satSolver.h:136
static void order_unassigned(sat_solver *s, int v)
Definition: satSolver.c:162
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
static void var_set_value(sat_solver *s, int v, int val)
Definition: satSolver.c:93
static int sat_solver_dl(sat_solver *s)
Definition: satSolver.c:132
veci trail_lim
Definition: satSolver.h:142
lit * trail
Definition: satSolver.h:137
static int lit_sign(lit l)
Definition: satVec.h:146
#define assert(ex)
Definition: util_old.h:213
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
static const int varX
Definition: satSolver.c:78
static void sat_solver_canceluntil_rollback ( sat_solver s,
int  NewBound 
)
static

Definition at line 561 of file satSolver.c.

561  {
562  int c, x;
563 
564  assert( sat_solver_dl(s) == 0 );
565  assert( s->qtail == s->qhead );
566  assert( s->qtail >= NewBound );
567 
568  for (c = s->qtail-1; c >= NewBound; c--)
569  {
570  x = lit_var(s->trail[c]);
571  var_set_value(s, x, varX);
572  s->reasons[x] = 0;
573  }
574 
575  for (c = s->qhead-1; c >= NewBound; c--)
576  order_unassigned(s,lit_var(s->trail[c]));
577 
578  s->qhead = s->qtail = NewBound;
579 }
int * reasons
Definition: satSolver.h:136
static void order_unassigned(sat_solver *s, int v)
Definition: satSolver.c:162
static int lit_var(lit l)
Definition: satVec.h:145
static void var_set_value(sat_solver *s, int v, int val)
Definition: satSolver.c:93
static int sat_solver_dl(sat_solver *s)
Definition: satSolver.c:132
lit * trail
Definition: satSolver.h:137
#define assert(ex)
Definition: util_old.h:213
static const int varX
Definition: satSolver.c:78
int sat_solver_clause_new ( sat_solver s,
lit begin,
lit end,
int  learnt 
)

Definition at line 402 of file satSolver.c.

403 {
404  int fUseBinaryClauses = 1;
405  int size;
406  clause* c;
407  int h;
408 
409  assert(end - begin > 1);
410  assert(learnt >= 0 && learnt < 2);
411  size = end - begin;
412 
413  // do not allocate memory for the two-literal problem clause
414  if ( fUseBinaryClauses && size == 2 && !learnt )
415  {
416  veci_push(sat_solver_read_wlist(s,lit_neg(begin[0])),(clause_from_lit(begin[1])));
417  veci_push(sat_solver_read_wlist(s,lit_neg(begin[1])),(clause_from_lit(begin[0])));
418  s->stats.clauses++;
420  return 0;
421  }
422 
423  // create new clause
424 // h = Vec_SetAppend( &s->Mem, NULL, size + learnt + 1 + 1 ) << 1;
425  h = Sat_MemAppend( &s->Mem, begin, size, learnt, 0 );
426  assert( !(h & 1) );
427  if ( s->hLearnts == -1 && learnt )
428  s->hLearnts = h;
429  if (learnt)
430  {
431  c = clause_read( s, h );
432  c->lbd = sat_clause_compute_lbd( s, c );
433  assert( clause_id(c) == veci_size(&s->act_clas) );
434 // veci_push(&s->learned, h);
435 // act_clause_bump(s,clause_read(s, h));
436  veci_push(&s->act_clas, (1<<10));
437  s->stats.learnts++;
439  }
440  else
441  {
442  s->stats.clauses++;
444  }
445 
446  assert(begin[0] >= 0);
447  assert(begin[0] < s->size*2);
448  assert(begin[1] >= 0);
449  assert(begin[1] < s->size*2);
450 
451  assert(lit_neg(begin[0]) < s->size*2);
452  assert(lit_neg(begin[1]) < s->size*2);
453 
454  //veci_push(sat_solver_read_wlist(s,lit_neg(begin[0])),c);
455  //veci_push(sat_solver_read_wlist(s,lit_neg(begin[1])),c);
456  veci_push(sat_solver_read_wlist(s,lit_neg(begin[0])),(size > 2 ? h : clause_from_lit(begin[1])));
457  veci_push(sat_solver_read_wlist(s,lit_neg(begin[1])),(size > 2 ? h : clause_from_lit(begin[0])));
458 
459  return h;
460 }
ABC_INT64_T clauses_literals
Definition: satVec.h:155
Sat_Mem_t Mem
Definition: satSolver.h:99
unsigned lbd
Definition: satClause.h:54
static void veci_push(veci *v, int e)
Definition: satVec.h:53
veci act_clas
Definition: satSolver.h:104
static veci * sat_solver_read_wlist(sat_solver *s, lit l)
Definition: satSolver.c:133
stats_t stats
Definition: satSolver.h:156
static int clause_id(clause *c)
Definition: satClause.h:144
ABC_INT64_T learnts_literals
Definition: satVec.h:155
static lit lit_neg(lit l)
Definition: satVec.h:144
static int size
Definition: cuddSign.c:86
static int sat_clause_compute_lbd(sat_solver *s, clause *c)
Definition: satSolver.c:383
unsigned learnts
Definition: satVec.h:153
unsigned clauses
Definition: satVec.h:153
static clause * clause_read(sat_solver *s, cla h)
Definition: satSolver.h:195
static int clause_from_lit(lit l)
GLOBAL VARIABLES ///.
Definition: satClause.h:138
static int Sat_MemAppend(Sat_Mem_t *p, int *pArray, int nSize, int lrn, int fPlus1)
Definition: satClause.h:301
#define assert(ex)
Definition: util_old.h:213
static int veci_size(veci *v)
Definition: satVec.h:46
int sat_solver_count_assigned ( sat_solver s)

Definition at line 609 of file satSolver.c.

610 {
611  // count top-level assignments
612  int i, Count = 0;
613  assert(sat_solver_dl(s) == 0);
614  for ( i = 0; i < s->size; i++ )
615  if (var_value(s, i) != varX)
616  Count++;
617  return Count;
618 }
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
static int sat_solver_dl(sat_solver *s)
Definition: satSolver.c:132
#define assert(ex)
Definition: util_old.h:213
static const int varX
Definition: satSolver.c:78
void sat_solver_delete ( sat_solver s)

Definition at line 1141 of file satSolver.c.

1142 {
1143 // Vec_SetFree_( &s->Mem );
1144  Sat_MemFree_( &s->Mem );
1145 
1146  // delete vectors
1147  veci_delete(&s->order);
1148  veci_delete(&s->trail_lim);
1149  veci_delete(&s->tagged);
1150 // veci_delete(&s->learned);
1151  veci_delete(&s->act_clas);
1152  veci_delete(&s->stack);
1153 // veci_delete(&s->model);
1154  veci_delete(&s->act_vars);
1155  veci_delete(&s->unit_lits);
1156  veci_delete(&s->pivot_vars);
1157  veci_delete(&s->temp_clause);
1158  veci_delete(&s->conf_final);
1159 
1160  // delete arrays
1161  if (s->reasons != 0){
1162  int i;
1163  for (i = 0; i < s->cap*2; i++)
1164  veci_delete(&s->wlists[i]);
1165  ABC_FREE(s->wlists );
1166 // ABC_FREE(s->vi );
1167  ABC_FREE(s->levels );
1168  ABC_FREE(s->assigns );
1169  ABC_FREE(s->polarity );
1170  ABC_FREE(s->tags );
1171  ABC_FREE(s->loads );
1172  ABC_FREE(s->activity );
1173  ABC_FREE(s->activity2);
1174  ABC_FREE(s->pFreqs );
1175  ABC_FREE(s->factors );
1176  ABC_FREE(s->orderpos );
1177  ABC_FREE(s->reasons );
1178  ABC_FREE(s->trail );
1179  ABC_FREE(s->model );
1180  }
1181 
1183  ABC_FREE(s);
1184 }
int * model
Definition: satSolver.h:144
veci act_vars
Definition: satSolver.h:167
veci unit_lits
Definition: satSolver.h:172
veci * wlists
Definition: satSolver.h:103
unsigned * activity
Definition: satSolver.h:122
int * reasons
Definition: satSolver.h:136
Sat_Mem_t Mem
Definition: satSolver.h:99
veci temp_clause
Definition: satSolver.h:188
char * tags
Definition: satSolver.h:132
static void veci_delete(veci *v)
Definition: satVec.h:44
veci act_clas
Definition: satSolver.h:104
char * polarity
Definition: satSolver.h:131
char * assigns
Definition: satSolver.h:130
static void Sat_MemFree_(Sat_Mem_t *p)
Definition: satClause.h:277
double * factors
Definition: satSolver.h:168
char * loads
Definition: satSolver.h:133
int * orderpos
Definition: satSolver.h:135
char * pFreqs
Definition: satSolver.h:125
veci conf_final
Definition: satSolver.h:145
unsigned * activity2
Definition: satSolver.h:123
veci trail_lim
Definition: satSolver.h:142
lit * trail
Definition: satSolver.h:137
veci pivot_vars
Definition: satSolver.h:173
#define ABC_FREE(obj)
Definition: abc_global.h:232
void sat_solver_store_free(sat_solver *s)
Definition: satSolver.c:1927
int * levels
Definition: satSolver.h:129
static int sat_solver_dl ( sat_solver s)
inlinestatic

Definition at line 132 of file satSolver.c.

132 { return veci_size(&s->trail_lim); }
veci trail_lim
Definition: satSolver.h:142
static int veci_size(veci *v)
Definition: satVec.h:46
static int sat_solver_enqueue ( sat_solver s,
lit  l,
int  from 
)
inlinestatic

Definition at line 466 of file satSolver.c.

467 {
468  int v = lit_var(l);
469  if ( s->pFreqs[v] == 0 )
470 // {
471  s->pFreqs[v] = 1;
472 // s->nVarUsed++;
473 // }
474 
475 #ifdef VERBOSEDEBUG
476  printf(L_IND"enqueue("L_LIT")\n", L_ind, L_lit(l));
477 #endif
478  if (var_value(s, v) != varX)
479  return var_value(s, v) == lit_sign(l);
480  else{
481 /*
482  if ( s->pCnfFunc )
483  {
484  if ( lit_sign(l) )
485  {
486  if ( (s->loads[v] & 1) == 0 )
487  {
488  s->loads[v] ^= 1;
489  s->pCnfFunc( s->pCnfMan, l );
490  }
491  }
492  else
493  {
494  if ( (s->loads[v] & 2) == 0 )
495  {
496  s->loads[v] ^= 2;
497  s->pCnfFunc( s->pCnfMan, l );
498  }
499  }
500  }
501 */
502  // New fact -- store it.
503 #ifdef VERBOSEDEBUG
504  printf(L_IND"bind("L_LIT")\n", L_ind, L_lit(l));
505 #endif
506  var_set_value(s, v, lit_sign(l));
507  var_set_level(s, v, sat_solver_dl(s));
508  s->reasons[v] = from;
509  s->trail[s->qtail++] = l;
510  order_assigned(s, v);
511  return true;
512  }
513 }
#define L_lit(p)
Definition: satSolver.c:43
int * reasons
Definition: satSolver.h:136
static int lit_var(lit l)
Definition: satVec.h:145
#define L_ind
Definition: satSolver.c:41
#define L_LIT
Definition: satSolver.c:42
static void var_set_value(sat_solver *s, int v, int val)
Definition: satSolver.c:93
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
char * pFreqs
Definition: satSolver.h:125
static void var_set_level(sat_solver *s, int v, int lev)
Definition: satSolver.c:92
static void order_assigned(sat_solver *s, int v)
Definition: satSolver.c:158
static int sat_solver_dl(sat_solver *s)
Definition: satSolver.c:132
#define L_IND
Definition: satSolver.c:40
lit * trail
Definition: satSolver.h:137
static int lit_sign(lit l)
Definition: satVec.h:146
static const int varX
Definition: satSolver.c:78
int sat_solver_get_var_value ( sat_solver s,
int  v 
)

Definition at line 117 of file satSolver.c.

118 {
119  if ( var_value(s, v) == var0 )
120  return l_False;
121  if ( var_value(s, v) == var1 )
122  return l_True;
123  if ( var_value(s, v) == varX )
124  return l_Undef;
125  assert( 0 );
126  return 0;
127 }
static const int var1
Definition: satSolver.c:77
#define l_Undef
Definition: SolverTypes.h:86
#define l_True
Definition: SolverTypes.h:84
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
static const int var0
Definition: satSolver.c:76
#define l_False
Definition: SolverTypes.h:85
#define assert(ex)
Definition: util_old.h:213
static const int varX
Definition: satSolver.c:78
static int sat_solver_lit_removable ( sat_solver s,
int  x,
int  minl 
)
static

Definition at line 634 of file satSolver.c.

635 {
636  int top = veci_size(&s->tagged);
637 
638  assert(s->reasons[x] != 0);
639  veci_resize(&s->stack,0);
640  veci_push(&s->stack,x);
641 
642  while (veci_size(&s->stack)){
643  int v = veci_pop(&s->stack);
644  assert(s->reasons[v] != 0);
645  if (clause_is_lit(s->reasons[v])){
646  v = lit_var(clause_read_lit(s->reasons[v]));
647  if (!var_tag(s,v) && var_level(s, v)){
648  if (s->reasons[v] != 0 && ((1 << (var_level(s, v) & 31)) & minl)){
649  veci_push(&s->stack,v);
650  var_set_tag(s, v, 1);
651  }else{
652  solver2_clear_tags(s, top);
653  return 0;
654  }
655  }
656  }else{
657  clause* c = clause_read(s, s->reasons[v]);
658  lit* lits = clause_begin(c);
659  int i;
660  for (i = 1; i < clause_size(c); i++){
661  int v = lit_var(lits[i]);
662  if (!var_tag(s,v) && var_level(s, v)){
663  if (s->reasons[v] != 0 && ((1 << (var_level(s, v) & 31)) & minl)){
664  veci_push(&s->stack,lit_var(lits[i]));
665  var_set_tag(s, v, 1);
666  }else{
667  solver2_clear_tags(s, top);
668  return 0;
669  }
670  }
671  }
672  }
673  }
674  return 1;
675 }
int * reasons
Definition: satSolver.h:136
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_push(veci *v, int e)
Definition: satVec.h:53
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
int lit
Definition: satVec.h:130
static int clause_size(clause *c)
Definition: satClause.h:146
static void var_set_tag(sat_solver *s, int v, int tag)
Definition: satSolver.c:98
static int veci_pop(veci *v)
Definition: satVec.h:52
static void solver2_clear_tags(sat_solver *s, int start)
Definition: satSolver.c:110
static int var_tag(sat_solver *s, int v)
Definition: satSolver.c:97
static int clause_is_lit(cla h)
Definition: satClause.h:139
static lit * clause_begin(clause *c)
Definition: satClause.h:147
static lit clause_read_lit(cla h)
Definition: satClause.h:140
static clause * clause_read(sat_solver *s, cla h)
Definition: satSolver.h:195
#define assert(ex)
Definition: util_old.h:213
static int var_level(sat_solver *s, int v)
Definition: satSolver.c:88
static int veci_size(veci *v)
Definition: satVec.h:46
double sat_solver_memory ( sat_solver s)

Definition at line 1236 of file satSolver.c.

1237 {
1238  int i;
1239  double Mem = sizeof(sat_solver);
1240  for (i = 0; i < s->cap*2; i++)
1241  Mem += s->wlists[i].cap * sizeof(int);
1242  Mem += s->cap * sizeof(veci); // ABC_FREE(s->wlists );
1243  Mem += s->cap * sizeof(int); // ABC_FREE(s->levels );
1244  Mem += s->cap * sizeof(char); // ABC_FREE(s->assigns );
1245  Mem += s->cap * sizeof(char); // ABC_FREE(s->polarity );
1246  Mem += s->cap * sizeof(char); // ABC_FREE(s->tags );
1247  Mem += s->cap * sizeof(char); // ABC_FREE(s->loads );
1248 #ifdef USE_FLOAT_ACTIVITY
1249  Mem += s->cap * sizeof(double); // ABC_FREE(s->activity );
1250 #else
1251  Mem += s->cap * sizeof(unsigned); // ABC_FREE(s->activity );
1252  if ( s->activity2 )
1253  Mem += s->cap * sizeof(unsigned); // ABC_FREE(s->activity2);
1254 #endif
1255  if ( s->factors )
1256  Mem += s->cap * sizeof(double); // ABC_FREE(s->factors );
1257  Mem += s->cap * sizeof(int); // ABC_FREE(s->orderpos );
1258  Mem += s->cap * sizeof(int); // ABC_FREE(s->reasons );
1259  Mem += s->cap * sizeof(lit); // ABC_FREE(s->trail );
1260  Mem += s->cap * sizeof(int); // ABC_FREE(s->model );
1261 
1262  Mem += s->order.cap * sizeof(int);
1263  Mem += s->trail_lim.cap * sizeof(int);
1264  Mem += s->tagged.cap * sizeof(int);
1265 // Mem += s->learned.cap * sizeof(int);
1266  Mem += s->stack.cap * sizeof(int);
1267  Mem += s->act_vars.cap * sizeof(int);
1268  Mem += s->unit_lits.cap * sizeof(int);
1269  Mem += s->act_clas.cap * sizeof(int);
1270  Mem += s->temp_clause.cap * sizeof(int);
1271  Mem += s->conf_final.cap * sizeof(int);
1272  Mem += Sat_MemMemoryAll( &s->Mem );
1273  return Mem;
1274 }
veci act_vars
Definition: satSolver.h:167
static double Sat_MemMemoryAll(Sat_Mem_t *p)
Definition: satClause.h:109
veci unit_lits
Definition: satSolver.h:172
veci * wlists
Definition: satSolver.h:103
Sat_Mem_t Mem
Definition: satSolver.h:99
veci temp_clause
Definition: satSolver.h:188
veci act_clas
Definition: satSolver.h:104
int lit
Definition: satVec.h:130
double * factors
Definition: satSolver.h:168
veci conf_final
Definition: satSolver.h:145
unsigned * activity2
Definition: satSolver.h:123
struct veci_t veci
Definition: satVec.h:36
veci trail_lim
Definition: satSolver.h:142
int cap
Definition: satVec.h:32
struct sat_solver_t sat_solver
Definition: satSolver.h:42
int sat_solver_nclauses ( sat_solver s)

Definition at line 1902 of file satSolver.c.

1903 {
1904  return s->stats.clauses;
1905 }
stats_t stats
Definition: satSolver.h:156
unsigned clauses
Definition: satVec.h:153
int sat_solver_nconflicts ( sat_solver s)

Definition at line 1908 of file satSolver.c.

1909 {
1910  return (int)s->stats.conflicts;
1911 }
stats_t stats
Definition: satSolver.h:156
ABC_INT64_T conflicts
Definition: satVec.h:154
sat_solver* sat_solver_new ( void  )

Definition at line 1001 of file satSolver.c.

1002 {
1003  sat_solver* s = (sat_solver*)ABC_CALLOC( char, sizeof(sat_solver));
1004 
1005 // Vec_SetAlloc_(&s->Mem, 15);
1006  Sat_MemAlloc_(&s->Mem, 15);
1007  s->hLearnts = -1;
1008  s->hBinary = Sat_MemAppend( &s->Mem, NULL, 2, 0, 0 );
1009  s->binary = clause_read( s, s->hBinary );
1010 
1011  s->nLearntStart = LEARNT_MAX_START_DEFAULT; // starting learned clause limit
1012  s->nLearntDelta = LEARNT_MAX_INCRE_DEFAULT; // delta of learned clause limit
1013  s->nLearntRatio = LEARNT_MAX_RATIO_DEFAULT; // ratio of learned clause limit
1014  s->nLearntMax = s->nLearntStart;
1015 
1016  // initialize vectors
1017  veci_new(&s->order);
1018  veci_new(&s->trail_lim);
1019  veci_new(&s->tagged);
1020 // veci_new(&s->learned);
1021  veci_new(&s->act_clas);
1022  veci_new(&s->stack);
1023 // veci_new(&s->model);
1024  veci_new(&s->act_vars);
1025  veci_new(&s->unit_lits);
1026  veci_new(&s->temp_clause);
1027  veci_new(&s->conf_final);
1028 
1029  // initialize arrays
1030  s->wlists = 0;
1031  s->activity = 0;
1032  s->orderpos = 0;
1033  s->reasons = 0;
1034  s->trail = 0;
1035 
1036  // initialize other vars
1037  s->size = 0;
1038  s->cap = 0;
1039  s->qhead = 0;
1040  s->qtail = 0;
1041 #ifdef USE_FLOAT_ACTIVITY
1042  s->var_inc = 1;
1043  s->cla_inc = 1;
1044  s->var_decay = (float)(1 / 0.95 );
1045  s->cla_decay = (float)(1 / 0.999);
1046 #else
1047  s->var_inc = (1 << 5);
1048  s->cla_inc = (1 << 11);
1049 #endif
1050  s->root_level = 0;
1051 // s->simpdb_assigns = 0;
1052 // s->simpdb_props = 0;
1053  s->random_seed = 91648253;
1054  s->progress_estimate = 0;
1055 // s->binary = (clause*)ABC_ALLOC( char, sizeof(clause) + sizeof(lit)*2);
1056 // s->binary->size_learnt = (2 << 1);
1057  s->verbosity = 0;
1058 
1059  s->stats.starts = 0;
1060  s->stats.decisions = 0;
1061  s->stats.propagations = 0;
1062  s->stats.inspects = 0;
1063  s->stats.conflicts = 0;
1064  s->stats.clauses = 0;
1065  s->stats.clauses_literals = 0;
1066  s->stats.learnts = 0;
1067  s->stats.learnts_literals = 0;
1068  s->stats.tot_literals = 0;
1069  return s;
1070 }
ABC_INT64_T clauses_literals
Definition: satVec.h:155
veci act_vars
Definition: satSolver.h:167
veci unit_lits
Definition: satSolver.h:172
veci * wlists
Definition: satSolver.h:103
unsigned * activity
Definition: satSolver.h:122
ABC_INT64_T tot_literals
Definition: satVec.h:155
int * reasons
Definition: satSolver.h:136
double random_seed
Definition: satSolver.h:151
Sat_Mem_t Mem
Definition: satSolver.h:99
veci temp_clause
Definition: satSolver.h:188
int root_level
Definition: satSolver.h:148
veci act_clas
Definition: satSolver.h:104
#define LEARNT_MAX_START_DEFAULT
INCLUDES ///.
Definition: satClause.h:37
ABC_INT64_T decisions
Definition: satVec.h:154
stats_t stats
Definition: satSolver.h:156
ABC_INT64_T learnts_literals
Definition: satVec.h:155
int nLearntDelta
Definition: satSolver.h:159
int * orderpos
Definition: satSolver.h:135
int nLearntMax
Definition: satSolver.h:157
static void veci_new(veci *v)
Definition: satVec.h:38
veci conf_final
Definition: satSolver.h:145
veci trail_lim
Definition: satSolver.h:142
ABC_INT64_T inspects
Definition: satVec.h:154
clause * binary
Definition: satSolver.h:102
int nLearntRatio
Definition: satSolver.h:160
unsigned learnts
Definition: satVec.h:153
ABC_INT64_T conflicts
Definition: satVec.h:154
int nLearntStart
Definition: satSolver.h:158
lit * trail
Definition: satSolver.h:137
unsigned clauses
Definition: satVec.h:153
static clause * clause_read(sat_solver *s, cla h)
Definition: satSolver.h:195
#define LEARNT_MAX_INCRE_DEFAULT
Definition: satClause.h:38
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static void Sat_MemAlloc_(Sat_Mem_t *p, int nPageSize)
Definition: satClause.h:193
ABC_INT64_T propagations
Definition: satVec.h:154
static int Sat_MemAppend(Sat_Mem_t *p, int *pArray, int nSize, int lrn, int fPlus1)
Definition: satClause.h:301
unsigned starts
Definition: satVec.h:153
double progress_estimate
Definition: satSolver.h:152
#define LEARNT_MAX_RATIO_DEFAULT
Definition: satClause.h:39
int sat_solver_nvars ( sat_solver s)

Definition at line 1896 of file satSolver.c.

1897 {
1898  return s->size;
1899 }
static double sat_solver_progress ( sat_solver s)
static

Definition at line 620 of file satSolver.c.

621 {
622  int i;
623  double progress = 0;
624  double F = 1.0 / s->size;
625  for (i = 0; i < s->size; i++)
626  if (var_value(s, i) != varX)
627  progress += pow(F, var_level(s, i));
628  return progress / s->size;
629 }
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
static int var_level(sat_solver *s, int v)
Definition: satSolver.c:88
static const int varX
Definition: satSolver.c:78
int sat_solver_propagate ( sat_solver s)

Definition at line 883 of file satSolver.c.

884 {
885  int hConfl = 0;
886  lit* lits;
887  lit false_lit;
888 
889  //printf("sat_solver_propagate\n");
890  while (hConfl == 0 && s->qtail - s->qhead > 0){
891  lit p = s->trail[s->qhead++];
892 
893 #ifdef TEST_CNF_LOAD
894  int v = lit_var(p);
895  if ( s->pCnfFunc )
896  {
897  if ( lit_sign(p) )
898  {
899  if ( (s->loads[v] & 1) == 0 )
900  {
901  s->loads[v] ^= 1;
902  s->pCnfFunc( s->pCnfMan, p );
903  }
904  }
905  else
906  {
907  if ( (s->loads[v] & 2) == 0 )
908  {
909  s->loads[v] ^= 2;
910  s->pCnfFunc( s->pCnfMan, p );
911  }
912  }
913  }
914  {
915 #endif
916 
917  veci* ws = sat_solver_read_wlist(s,p);
918  int* begin = veci_begin(ws);
919  int* end = begin + veci_size(ws);
920  int*i, *j;
921 
922  s->stats.propagations++;
923 // s->simpdb_props--;
924 
925  //printf("checking lit %d: "L_LIT"\n", veci_size(ws), L_lit(p));
926  for (i = j = begin; i < end; ){
927  if (clause_is_lit(*i)){
928 
929  int Lit = clause_read_lit(*i);
930  if (var_value(s, lit_var(Lit)) == lit_sign(Lit)){
931  *j++ = *i++;
932  continue;
933  }
934 
935  *j++ = *i;
937  hConfl = s->hBinary;
938  (clause_begin(s->binary))[1] = lit_neg(p);
939  (clause_begin(s->binary))[0] = clause_read_lit(*i++);
940  // Copy the remaining watches:
941  while (i < end)
942  *j++ = *i++;
943  }
944  }else{
945 
946  clause* c = clause_read(s,*i);
947  lits = clause_begin(c);
948 
949  // Make sure the false literal is data[1]:
950  false_lit = lit_neg(p);
951  if (lits[0] == false_lit){
952  lits[0] = lits[1];
953  lits[1] = false_lit;
954  }
955  assert(lits[1] == false_lit);
956 
957  // If 0th watch is true, then clause is already satisfied.
958  if (var_value(s, lit_var(lits[0])) == lit_sign(lits[0]))
959  *j++ = *i;
960  else{
961  // Look for new watch:
962  lit* stop = lits + clause_size(c);
963  lit* k;
964  for (k = lits + 2; k < stop; k++){
965  if (var_value(s, lit_var(*k)) != !lit_sign(*k)){
966  lits[1] = *k;
967  *k = false_lit;
968  veci_push(sat_solver_read_wlist(s,lit_neg(lits[1])),*i);
969  goto next; }
970  }
971 
972  *j++ = *i;
973  // Clause is unit under assignment:
974  if ( c->lrn )
975  c->lbd = sat_clause_compute_lbd(s, c);
976  if (!sat_solver_enqueue(s,lits[0], *i)){
977  hConfl = *i++;
978  // Copy the remaining watches:
979  while (i < end)
980  *j++ = *i++;
981  }
982  }
983  }
984  next:
985  i++;
986  }
987 
988  s->stats.inspects += j - veci_begin(ws);
989  veci_resize(ws,j - veci_begin(ws));
990 #ifdef TEST_CNF_LOAD
991  }
992 #endif
993  }
994 
995  return hConfl;
996 }
struct hash_element * next
Definition: place_test.c:27
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned lbd
Definition: satClause.h:54
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_push(veci *v, int e)
Definition: satVec.h:53
Definition: satVec.h:31
static veci * sat_solver_read_wlist(sat_solver *s, lit l)
Definition: satSolver.c:133
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
stats_t stats
Definition: satSolver.h:156
int lit
Definition: satVec.h:130
static lit lit_neg(lit l)
Definition: satVec.h:144
static int clause_size(clause *c)
Definition: satClause.h:146
char * loads
Definition: satSolver.h:133
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
void * pCnfMan
Definition: satSolver.h:191
ABC_INT64_T inspects
Definition: satVec.h:154
clause * binary
Definition: satSolver.h:102
static int sat_clause_compute_lbd(sat_solver *s, clause *c)
Definition: satSolver.c:383
static int clause_is_lit(cla h)
Definition: satClause.h:139
static lit * clause_begin(clause *c)
Definition: satClause.h:147
lit * trail
Definition: satSolver.h:137
int(* pCnfFunc)(void *p, int)
Definition: satSolver.h:192
static int lit_sign(lit l)
Definition: satVec.h:146
static lit clause_read_lit(cla h)
Definition: satClause.h:140
static clause * clause_read(sat_solver *s, cla h)
Definition: satSolver.h:195
static int clause_from_lit(lit l)
GLOBAL VARIABLES ///.
Definition: satClause.h:138
ABC_INT64_T propagations
Definition: satVec.h:154
unsigned lrn
Definition: satClause.h:51
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_enqueue(sat_solver *s, lit l, int from)
Definition: satSolver.c:466
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
static veci* sat_solver_read_wlist ( sat_solver s,
lit  l 
)
inlinestatic

Definition at line 133 of file satSolver.c.

133 { return &s->wlists[l]; }
veci * wlists
Definition: satSolver.h:103
static void sat_solver_record ( sat_solver s,
veci cls 
)
static

Definition at line 581 of file satSolver.c.

582 {
583  lit* begin = veci_begin(cls);
584  lit* end = begin + veci_size(cls);
585  int h = (veci_size(cls) > 1) ? sat_solver_clause_new(s,begin,end,1) : 0;
586  sat_solver_enqueue(s,*begin,h);
587  assert(veci_size(cls) > 0);
588  if ( h == 0 )
589  veci_push( &s->unit_lits, *begin );
590 
591  ///////////////////////////////////
592  // add clause to internal storage
593  if ( s->pStore )
594  {
595  int RetValue = Sto_ManAddClause( (Sto_Man_t *)s->pStore, begin, end );
596  assert( RetValue );
597  (void) RetValue;
598  }
599  ///////////////////////////////////
600 /*
601  if (h != 0) {
602  act_clause_bump(s,clause_read(s, h));
603  s->stats.learnts++;
604  s->stats.learnts_literals += veci_size(cls);
605  }
606 */
607 }
veci unit_lits
Definition: satSolver.h:172
int sat_solver_clause_new(sat_solver *s, lit *begin, lit *end, int learnt)
Definition: satSolver.c:402
static void veci_push(veci *v, int e)
Definition: satVec.h:53
void * pStore
Definition: satSolver.h:180
int lit
Definition: satVec.h:130
int Sto_ManAddClause(Sto_Man_t *p, lit *pBeg, lit *pEnd)
Definition: satStore.c:160
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_enqueue(sat_solver *s, lit l, int from)
Definition: satSolver.c:466
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
void sat_solver_reducedb ( sat_solver s)

Definition at line 1284 of file satSolver.c.

1285 {
1286  static abctime TimeTotal = 0;
1287  abctime clk = Abc_Clock();
1288  Sat_Mem_t * pMem = &s->Mem;
1289  int nLearnedOld = veci_size(&s->act_clas);
1290  int * act_clas = veci_begin(&s->act_clas);
1291  int * pPerm, * pArray, * pSortValues, nCutoffValue;
1292  int i, k, j, Id, Counter, CounterStart, nSelected;
1293  clause * c;
1294 
1295  assert( s->nLearntMax > 0 );
1296  assert( nLearnedOld == Sat_MemEntryNum(pMem, 1) );
1297  assert( nLearnedOld == (int)s->stats.learnts );
1298 
1299  s->nDBreduces++;
1300 
1301 // printf( "Calling reduceDB with %d learned clause limit.\n", s->nLearntMax );
1302  s->nLearntMax = s->nLearntStart + s->nLearntDelta * s->nDBreduces;
1303 // return;
1304 
1305  // create sorting values
1306  pSortValues = ABC_ALLOC( int, nLearnedOld );
1307  Sat_MemForEachLearned( pMem, c, i, k )
1308  {
1309  Id = clause_id(c);
1310  pSortValues[Id] = (((7 - Abc_MinInt(c->lbd, 7)) << 28) | (act_clas[Id] >> 4));
1311 // pSortValues[Id] = act[Id];
1312  assert( pSortValues[Id] >= 0 );
1313  }
1314 
1315  // preserve 1/20 of last clauses
1316  CounterStart = nLearnedOld - (s->nLearntMax / 20);
1317 
1318  // preserve 3/4 of most active clauses
1319  nSelected = nLearnedOld*s->nLearntRatio/100;
1320 
1321  // find non-decreasing permutation
1322  pPerm = Abc_MergeSortCost( pSortValues, nLearnedOld );
1323  assert( pSortValues[pPerm[0]] <= pSortValues[pPerm[nLearnedOld-1]] );
1324  nCutoffValue = pSortValues[pPerm[nLearnedOld-nSelected]];
1325  ABC_FREE( pPerm );
1326 // ActCutOff = ABC_INFINITY;
1327 
1328  // mark learned clauses to remove
1329  Counter = j = 0;
1330  Sat_MemForEachLearned( pMem, c, i, k )
1331  {
1332  assert( c->mark == 0 );
1333  if ( Counter++ > CounterStart || clause_size(c) < 3 || pSortValues[clause_id(c)] > nCutoffValue || s->reasons[lit_var(c->lits[0])] == Sat_MemHand(pMem, i, k) )
1334  act_clas[j++] = act_clas[clause_id(c)];
1335  else // delete
1336  {
1337  c->mark = 1;
1339  s->stats.learnts--;
1340  }
1341  }
1342  assert( s->stats.learnts == (unsigned)j );
1343  assert( Counter == nLearnedOld );
1344  veci_resize(&s->act_clas,j);
1345  ABC_FREE( pSortValues );
1346 
1347  // update ID of each clause to be its new handle
1348  Counter = Sat_MemCompactLearned( pMem, 0 );
1349  assert( Counter == (int)s->stats.learnts );
1350 
1351  // update reasons
1352  for ( i = 0; i < s->size; i++ )
1353  {
1354  if ( !s->reasons[i] ) // no reason
1355  continue;
1356  if ( clause_is_lit(s->reasons[i]) ) // 2-lit clause
1357  continue;
1358  if ( !clause_learnt_h(pMem, s->reasons[i]) ) // problem clause
1359  continue;
1360  c = clause_read( s, s->reasons[i] );
1361  assert( c->mark == 0 );
1362  s->reasons[i] = clause_id(c); // updating handle here!!!
1363  }
1364 
1365  // update watches
1366  for ( i = 0; i < s->size*2; i++ )
1367  {
1368  pArray = veci_begin(&s->wlists[i]);
1369  for ( j = k = 0; k < veci_size(&s->wlists[i]); k++ )
1370  {
1371  if ( clause_is_lit(pArray[k]) ) // 2-lit clause
1372  pArray[j++] = pArray[k];
1373  else if ( !clause_learnt_h(pMem, pArray[k]) ) // problem clause
1374  pArray[j++] = pArray[k];
1375  else
1376  {
1377  c = clause_read(s, pArray[k]);
1378  if ( !c->mark ) // useful learned clause
1379  pArray[j++] = clause_id(c); // updating handle here!!!
1380  }
1381  }
1382  veci_resize(&s->wlists[i],j);
1383  }
1384 
1385  // perform final move of the clauses
1386  Counter = Sat_MemCompactLearned( pMem, 1 );
1387  assert( Counter == (int)s->stats.learnts );
1388 
1389  // report the results
1390  TimeTotal += Abc_Clock() - clk;
1391  if ( s->fVerbose )
1392  {
1393  Abc_Print(1, "reduceDB: Keeping %7d out of %7d clauses (%5.2f %%) ",
1394  s->stats.learnts, nLearnedOld, 100.0 * s->stats.learnts / nLearnedOld );
1395  Abc_PrintTime( 1, "Time", TimeTotal );
1396  }
1397 }
lit lits[0]
Definition: satClause.h:56
veci * wlists
Definition: satSolver.h:103
int * reasons
Definition: satSolver.h:136
Sat_Mem_t Mem
Definition: satSolver.h:99
unsigned lbd
Definition: satClause.h:54
static int lit_var(lit l)
Definition: satVec.h:145
veci act_clas
Definition: satSolver.h:104
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
static abctime Abc_Clock()
Definition: abc_global.h:279
stats_t stats
Definition: satSolver.h:156
static int clause_id(clause *c)
Definition: satClause.h:144
int nDBreduces
Definition: satSolver.h:161
#define Sat_MemForEachLearned(p, c, i, k)
Definition: satClause.h:126
ABC_INT64_T learnts_literals
Definition: satVec.h:155
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
int * Abc_MergeSortCost(int *pCosts, int nSize)
Definition: utilSort.c:238
static int clause_size(clause *c)
Definition: satClause.h:146
int nLearntDelta
Definition: satSolver.h:159
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
int nLearntMax
Definition: satSolver.h:157
static int clause_learnt_h(Sat_Mem_t *p, cla h)
Definition: satClause.h:142
unsigned mark
Definition: satClause.h:52
static int Counter
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
static int pPerm[13719]
Definition: rwrTemp.c:32
int nLearntRatio
Definition: satSolver.h:160
unsigned learnts
Definition: satVec.h:153
static int clause_is_lit(cla h)
Definition: satClause.h:139
int nLearntStart
Definition: satSolver.h:158
#define ABC_FREE(obj)
Definition: abc_global.h:232
static clause * clause_read(sat_solver *s, cla h)
Definition: satSolver.h:195
static int Sat_MemEntryNum(Sat_Mem_t *p, int lrn)
Definition: satClause.h:99
#define assert(ex)
Definition: util_old.h:213
static int Sat_MemCompactLearned(Sat_Mem_t *p, int fDoMove)
Definition: satClause.h:366
ABC_INT64_T abctime
Definition: abc_global.h:278
static int * veci_begin(veci *v)
Definition: satVec.h:45
static cla Sat_MemHand(Sat_Mem_t *p, int i, int k)
Definition: satClause.h:101
static int veci_size(veci *v)
Definition: satVec.h:46
void sat_solver_restart ( sat_solver s)

Definition at line 1186 of file satSolver.c.

1187 {
1188  int i;
1189  Sat_MemRestart( &s->Mem );
1190  s->hLearnts = -1;
1191  s->hBinary = Sat_MemAppend( &s->Mem, NULL, 2, 0, 0 );
1192  s->binary = clause_read( s, s->hBinary );
1193 
1194  veci_resize(&s->act_clas, 0);
1195  veci_resize(&s->trail_lim, 0);
1196  veci_resize(&s->order, 0);
1197  for ( i = 0; i < s->size*2; i++ )
1198  s->wlists[i].size = 0;
1199 
1200  s->nDBreduces = 0;
1201 
1202  // initialize other vars
1203  s->size = 0;
1204 // s->cap = 0;
1205  s->qhead = 0;
1206  s->qtail = 0;
1207 #ifdef USE_FLOAT_ACTIVITY
1208  s->var_inc = 1;
1209  s->cla_inc = 1;
1210  s->var_decay = (float)(1 / 0.95 );
1211  s->cla_decay = (float)(1 / 0.999 );
1212 #else
1213  s->var_inc = (1 << 5);
1214  s->cla_inc = (1 << 11);
1215 #endif
1216  s->root_level = 0;
1217 // s->simpdb_assigns = 0;
1218 // s->simpdb_props = 0;
1219  s->random_seed = 91648253;
1220  s->progress_estimate = 0;
1221  s->verbosity = 0;
1222 
1223  s->stats.starts = 0;
1224  s->stats.decisions = 0;
1225  s->stats.propagations = 0;
1226  s->stats.inspects = 0;
1227  s->stats.conflicts = 0;
1228  s->stats.clauses = 0;
1229  s->stats.clauses_literals = 0;
1230  s->stats.learnts = 0;
1231  s->stats.learnts_literals = 0;
1232  s->stats.tot_literals = 0;
1233 }
ABC_INT64_T clauses_literals
Definition: satVec.h:155
veci * wlists
Definition: satSolver.h:103
ABC_INT64_T tot_literals
Definition: satVec.h:155
double random_seed
Definition: satSolver.h:151
Sat_Mem_t Mem
Definition: satSolver.h:99
int root_level
Definition: satSolver.h:148
static void Sat_MemRestart(Sat_Mem_t *p)
Definition: satClause.h:228
veci act_clas
Definition: satSolver.h:104
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
ABC_INT64_T decisions
Definition: satVec.h:154
stats_t stats
Definition: satSolver.h:156
int nDBreduces
Definition: satSolver.h:161
ABC_INT64_T learnts_literals
Definition: satVec.h:155
veci trail_lim
Definition: satSolver.h:142
ABC_INT64_T inspects
Definition: satVec.h:154
clause * binary
Definition: satSolver.h:102
unsigned learnts
Definition: satVec.h:153
ABC_INT64_T conflicts
Definition: satVec.h:154
unsigned clauses
Definition: satVec.h:153
static clause * clause_read(sat_solver *s, cla h)
Definition: satSolver.h:195
ABC_INT64_T propagations
Definition: satVec.h:154
int size
Definition: satVec.h:33
static int Sat_MemAppend(Sat_Mem_t *p, int *pArray, int nSize, int lrn, int fPlus1)
Definition: satClause.h:301
unsigned starts
Definition: satVec.h:153
double progress_estimate
Definition: satSolver.h:152
void sat_solver_rollback ( sat_solver s)

Definition at line 1401 of file satSolver.c.

1402 {
1403  Sat_Mem_t * pMem = &s->Mem;
1404  int i, k, j;
1405  static int Count = 0;
1406  Count++;
1407  assert( s->iVarPivot >= 0 && s->iVarPivot <= s->size );
1408  assert( s->iTrailPivot >= 0 && s->iTrailPivot <= s->qtail );
1409  // reset implication queue
1411  // update order
1412  if ( s->iVarPivot < s->size )
1413  {
1414  if ( s->activity2 )
1415  {
1416  s->var_inc = s->var_inc2;
1417  memcpy( s->activity, s->activity2, sizeof(unsigned) * s->iVarPivot );
1418  }
1419  veci_resize(&s->order, 0);
1420  for ( i = 0; i < s->iVarPivot; i++ )
1421  {
1422  if ( var_value(s, i) != varX )
1423  continue;
1424  s->orderpos[i] = veci_size(&s->order);
1425  veci_push(&s->order,i);
1426  order_update(s, i);
1427  }
1428  }
1429  // compact watches
1430  for ( i = 0; i < s->iVarPivot*2; i++ )
1431  {
1432  cla* pArray = veci_begin(&s->wlists[i]);
1433  for ( j = k = 0; k < veci_size(&s->wlists[i]); k++ )
1434  if ( Sat_MemClauseUsed(pMem, pArray[k]) )
1435  pArray[j++] = pArray[k];
1436  veci_resize(&s->wlists[i],j);
1437  }
1438  // reset watcher lists
1439  for ( i = 2*s->iVarPivot; i < 2*s->size; i++ )
1440  s->wlists[i].size = 0;
1441 
1442  // reset clause counts
1443  s->stats.clauses = pMem->BookMarkE[0];
1444  s->stats.learnts = pMem->BookMarkE[1];
1445  // rollback clauses
1446  Sat_MemRollBack( pMem );
1447 
1448  // resize learned arrays
1449  veci_resize(&s->act_clas, s->stats.learnts);
1450 
1451  // initialize other vars
1452  s->size = s->iVarPivot;
1453  if ( s->size == 0 )
1454  {
1455  // s->size = 0;
1456  // s->cap = 0;
1457  s->qhead = 0;
1458  s->qtail = 0;
1459 #ifdef USE_FLOAT_ACTIVITY
1460  s->var_inc = 1;
1461  s->cla_inc = 1;
1462  s->var_decay = (float)(1 / 0.95 );
1463  s->cla_decay = (float)(1 / 0.999 );
1464 #else
1465  s->var_inc = (1 << 5);
1466  s->cla_inc = (1 << 11);
1467 #endif
1468  s->root_level = 0;
1469  s->random_seed = 91648253;
1470  s->progress_estimate = 0;
1471  s->verbosity = 0;
1472 
1473  s->stats.starts = 0;
1474  s->stats.decisions = 0;
1475  s->stats.propagations = 0;
1476  s->stats.inspects = 0;
1477  s->stats.conflicts = 0;
1478  s->stats.clauses = 0;
1479  s->stats.clauses_literals = 0;
1480  s->stats.learnts = 0;
1481  s->stats.learnts_literals = 0;
1482  s->stats.tot_literals = 0;
1483 
1484  // initialize rollback
1485  s->iVarPivot = 0; // the pivot for variables
1486  s->iTrailPivot = 0; // the pivot for trail
1487  s->hProofPivot = 1; // the pivot for proof records
1488  }
1489 }
static void sat_solver_canceluntil_rollback(sat_solver *s, int NewBound)
Definition: satSolver.c:561
ABC_INT64_T clauses_literals
Definition: satVec.h:155
veci * wlists
Definition: satSolver.h:103
unsigned * activity
Definition: satSolver.h:122
ABC_INT64_T tot_literals
Definition: satVec.h:155
double random_seed
Definition: satSolver.h:151
Sat_Mem_t Mem
Definition: satSolver.h:99
static void veci_push(veci *v, int e)
Definition: satVec.h:53
int root_level
Definition: satSolver.h:148
int hProofPivot
Definition: satSolver.h:109
char * memcpy()
veci act_clas
Definition: satSolver.h:104
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
ABC_INT64_T decisions
Definition: satVec.h:154
stats_t stats
Definition: satSolver.h:156
int cla
Definition: satVec.h:131
ABC_INT64_T learnts_literals
Definition: satVec.h:155
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
int * orderpos
Definition: satSolver.h:135
unsigned * activity2
Definition: satSolver.h:123
static int size
Definition: cuddSign.c:86
ABC_INT64_T inspects
Definition: satVec.h:154
unsigned learnts
Definition: satVec.h:153
ABC_INT64_T conflicts
Definition: satVec.h:154
int iTrailPivot
Definition: satSolver.h:108
unsigned clauses
Definition: satVec.h:153
static void Sat_MemRollBack(Sat_Mem_t *p)
Definition: satClause.h:256
int BookMarkE[2]
Definition: satClause.h:75
ABC_INT64_T propagations
Definition: satVec.h:154
int size
Definition: satVec.h:33
static void order_update(sat_solver *s, int v)
Definition: satSolver.c:138
#define assert(ex)
Definition: util_old.h:213
static int Sat_MemClauseUsed(Sat_Mem_t *p, cla h)
Definition: satClause.h:104
unsigned starts
Definition: satVec.h:153
double progress_estimate
Definition: satSolver.h:152
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
static const int varX
Definition: satSolver.c:78
static lbool sat_solver_search ( sat_solver s,
ABC_INT64_T  nof_conflicts 
)
static

Definition at line 1575 of file satSolver.c.

1576 {
1577 // double var_decay = 0.95;
1578 // double clause_decay = 0.999;
1579  double random_var_freq = s->fNotUseRandom ? 0.0 : 0.02;
1580 
1581  ABC_INT64_T conflictC = 0;
1582  veci learnt_clause;
1583  int i;
1584 
1585  assert(s->root_level == sat_solver_dl(s));
1586 
1587  s->nRestarts++;
1588  s->stats.starts++;
1589 // s->var_decay = (float)(1 / var_decay ); // move this to sat_solver_new()
1590 // s->cla_decay = (float)(1 / clause_decay); // move this to sat_solver_new()
1591 // veci_resize(&s->model,0);
1592  veci_new(&learnt_clause);
1593 
1594  // use activity factors in every even restart
1595  if ( (s->nRestarts & 1) && veci_size(&s->act_vars) > 0 )
1596 // if ( veci_size(&s->act_vars) > 0 )
1597  for ( i = 0; i < s->act_vars.size; i++ )
1598  act_var_bump_factor(s, s->act_vars.ptr[i]);
1599 
1600  // use activity factors in every restart
1601  if ( s->pGlobalVars && veci_size(&s->act_vars) > 0 )
1602  for ( i = 0; i < s->act_vars.size; i++ )
1603  act_var_bump_global(s, s->act_vars.ptr[i]);
1604 
1605  for (;;){
1606  int hConfl = sat_solver_propagate(s);
1607  if (hConfl != 0){
1608  // CONFLICT
1609  int blevel;
1610 
1611 #ifdef VERBOSEDEBUG
1612  printf(L_IND"**CONFLICT**\n", L_ind);
1613 #endif
1614  s->stats.conflicts++; conflictC++;
1615  if (sat_solver_dl(s) == s->root_level){
1616 #ifdef SAT_USE_ANALYZE_FINAL
1617  sat_solver_analyze_final(s, hConfl, 0);
1618 #endif
1619  veci_delete(&learnt_clause);
1620  return l_False;
1621  }
1622 
1623  veci_resize(&learnt_clause,0);
1624  sat_solver_analyze(s, hConfl, &learnt_clause);
1625  blevel = veci_size(&learnt_clause) > 1 ? var_level(s, lit_var(veci_begin(&learnt_clause)[1])) : s->root_level;
1626  blevel = s->root_level > blevel ? s->root_level : blevel;
1627  sat_solver_canceluntil(s,blevel);
1628  sat_solver_record(s,&learnt_clause);
1629 #ifdef SAT_USE_ANALYZE_FINAL
1630 // if (learnt_clause.size() == 1) level[var(learnt_clause[0])] = 0; // (this is ugly (but needed for 'analyzeFinal()') -- in future versions, we will backtrack past the 'root_level' and redo the assumptions)
1631  if ( learnt_clause.size == 1 )
1632  var_set_level(s, lit_var(learnt_clause.ptr[0]), 0);
1633 #endif
1634  act_var_decay(s);
1635  act_clause_decay(s);
1636 
1637  }else{
1638  // NO CONFLICT
1639  int next;
1640 
1641  // Reached bound on number of conflicts:
1642  if ((nof_conflicts >= 0 && conflictC >= nof_conflicts) || (s->nRuntimeLimit && (s->stats.conflicts & 63) == 0 && Abc_Clock() > s->nRuntimeLimit)){
1645  veci_delete(&learnt_clause);
1646  return l_Undef; }
1647 
1648  // Reached bound on number of conflicts:
1649  if ( (s->nConfLimit && s->stats.conflicts > s->nConfLimit) ||
1650  (s->nInsLimit && s->stats.propagations > s->nInsLimit) )
1651  {
1654  veci_delete(&learnt_clause);
1655  return l_Undef;
1656  }
1657 
1658  // Simplify the set of problem clauses:
1659  if (sat_solver_dl(s) == 0 && !s->fSkipSimplify)
1661 
1662  // Reduce the set of learnt clauses:
1663 // if (s->nLearntMax && veci_size(&s->learned) - s->qtail >= s->nLearntMax)
1664  if (s->nLearntMax && veci_size(&s->act_clas) >= s->nLearntMax)
1666 
1667  // New variable decision:
1668  s->stats.decisions++;
1669  next = order_select(s,(float)random_var_freq);
1670 
1671  if (next == var_Undef){
1672  // Model found:
1673  int i;
1674  for (i = 0; i < s->size; i++)
1675  s->model[i] = (var_value(s,i)==var1 ? l_True : l_False);
1677  veci_delete(&learnt_clause);
1678 
1679  /*
1680  veci apa; veci_new(&apa);
1681  for (i = 0; i < s->size; i++)
1682  veci_push(&apa,(int)(s->model.ptr[i] == l_True ? toLit(i) : lit_neg(toLit(i))));
1683  printf("model: "); printlits((lit*)apa.ptr, (lit*)apa.ptr + veci_size(&apa)); printf("\n");
1684  veci_delete(&apa);
1685  */
1686 
1687  return l_True;
1688  }
1689 
1690  if ( var_polar(s, next) ) // positive polarity
1691  sat_solver_assume(s,toLit(next));
1692  else
1693  sat_solver_assume(s,lit_neg(toLit(next)));
1694  }
1695  }
1696 
1697  return l_Undef; // cannot happen
1698 }
static double sat_solver_progress(sat_solver *s)
Definition: satSolver.c:620
int fSkipSimplify
Definition: satSolver.h:175
int * model
Definition: satSolver.h:144
static void act_clause_decay(sat_solver *s)
Definition: satSolver.c:332
static const int var1
Definition: satSolver.c:77
static int order_select(sat_solver *s, float random_var_freq)
Definition: satSolver.c:173
veci act_vars
Definition: satSolver.h:167
int * ptr
Definition: satVec.h:34
struct hash_element * next
Definition: place_test.c:27
void sat_solver_reducedb(sat_solver *s)
Definition: satSolver.c:1284
static void sat_solver_analyze(sat_solver *s, int h, veci *learnt)
Definition: satSolver.c:775
#define l_Undef
Definition: SolverTypes.h:86
static int lit_var(lit l)
Definition: satVec.h:145
static void sat_solver_record(sat_solver *s, veci *cls)
Definition: satSolver.c:581
int root_level
Definition: satSolver.h:148
ABC_INT64_T nInsLimit
Definition: satSolver.h:164
static void act_var_bump_factor(sat_solver *s, int v)
Definition: satSolver.c:314
#define L_ind
Definition: satSolver.c:41
static void sat_solver_canceluntil(sat_solver *s, int level)
Definition: satSolver.c:528
static void veci_delete(veci *v)
Definition: satVec.h:44
Definition: satVec.h:31
#define l_True
Definition: SolverTypes.h:84
veci act_clas
Definition: satSolver.h:104
static void act_var_bump_global(sat_solver *s, int v)
Definition: satSolver.c:305
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
static abctime Abc_Clock()
Definition: abc_global.h:279
ABC_INT64_T decisions
Definition: satVec.h:154
stats_t stats
Definition: satSolver.h:156
int fNotUseRandom
Definition: satSolver.h:176
static lit lit_neg(lit l)
Definition: satVec.h:144
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
int nLearntMax
Definition: satSolver.h:157
static int var_polar(sat_solver *s, int v)
Definition: satSolver.c:90
static void veci_new(veci *v)
Definition: satVec.h:38
int * pGlobalVars
Definition: satSolver.h:178
static lit toLit(int v)
Definition: satVec.h:142
static void var_set_level(sat_solver *s, int v, int lev)
Definition: satSolver.c:92
abctime nRuntimeLimit
Definition: satSolver.h:165
static int sat_solver_dl(sat_solver *s)
Definition: satSolver.c:132
static void sat_solver_analyze_final(sat_solver *s, int hConf, int skip_first)
Definition: satSolver.c:729
ABC_INT64_T nConfLimit
Definition: satSolver.h:163
ABC_INT64_T conflicts
Definition: satVec.h:154
int sat_solver_simplify(sat_solver *s)
Definition: satSolver.c:1276
#define L_IND
Definition: satSolver.c:40
static int sat_solver_assume(sat_solver *s, lit l)
Definition: satSolver.c:516
#define l_False
Definition: SolverTypes.h:85
ABC_INT64_T propagations
Definition: satVec.h:154
int size
Definition: satVec.h:33
#define assert(ex)
Definition: util_old.h:213
int sat_solver_propagate(sat_solver *s)
Definition: satSolver.c:883
#define var_Undef
Definition: SolverTypes.h:43
unsigned starts
Definition: satVec.h:153
double progress_estimate
Definition: satSolver.h:152
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int var_level(sat_solver *s, int v)
Definition: satSolver.c:88
static int veci_size(veci *v)
Definition: satVec.h:46
static void act_var_decay(sat_solver *s)
Definition: satSolver.c:331
void sat_solver_setnvars ( sat_solver s,
int  n 
)

Definition at line 1072 of file satSolver.c.

1073 {
1074  int var;
1075 
1076  if (s->cap < n){
1077  int old_cap = s->cap;
1078  while (s->cap < n) s->cap = s->cap*2+1;
1079  if ( s->cap < 50000 )
1080  s->cap = 50000;
1081 
1082  s->wlists = ABC_REALLOC(veci, s->wlists, s->cap*2);
1083 // s->vi = ABC_REALLOC(varinfo,s->vi, s->cap);
1084  s->levels = ABC_REALLOC(int, s->levels, s->cap);
1085  s->assigns = ABC_REALLOC(char, s->assigns, s->cap);
1086  s->polarity = ABC_REALLOC(char, s->polarity, s->cap);
1087  s->tags = ABC_REALLOC(char, s->tags, s->cap);
1088  s->loads = ABC_REALLOC(char, s->loads, s->cap);
1089 #ifdef USE_FLOAT_ACTIVITY
1090  s->activity = ABC_REALLOC(double, s->activity, s->cap);
1091 #else
1092  s->activity = ABC_REALLOC(unsigned, s->activity, s->cap);
1093  s->activity2 = ABC_REALLOC(unsigned, s->activity2,s->cap);
1094 #endif
1095  s->pFreqs = ABC_REALLOC(char, s->pFreqs, s->cap);
1096 
1097  if ( s->factors )
1098  s->factors = ABC_REALLOC(double, s->factors, s->cap);
1099  s->orderpos = ABC_REALLOC(int, s->orderpos, s->cap);
1100  s->reasons = ABC_REALLOC(int, s->reasons, s->cap);
1101  s->trail = ABC_REALLOC(lit, s->trail, s->cap);
1102  s->model = ABC_REALLOC(int, s->model, s->cap);
1103  memset( s->wlists + 2*old_cap, 0, 2*(s->cap-old_cap)*sizeof(veci) );
1104  }
1105 
1106  for (var = s->size; var < n; var++){
1107  assert(!s->wlists[2*var].size);
1108  assert(!s->wlists[2*var+1].size);
1109  if ( s->wlists[2*var].ptr == NULL )
1110  veci_new(&s->wlists[2*var]);
1111  if ( s->wlists[2*var+1].ptr == NULL )
1112  veci_new(&s->wlists[2*var+1]);
1113 #ifdef USE_FLOAT_ACTIVITY
1114  s->activity[var] = 0;
1115 #else
1116  s->activity[var] = (1<<10);
1117 #endif
1118  s->pFreqs[var] = 0;
1119  if ( s->factors )
1120  s->factors [var] = 0;
1121 // *((int*)s->vi + var) = 0; s->vi[var].val = varX;
1122  s->levels [var] = 0;
1123  s->assigns [var] = varX;
1124  s->polarity[var] = 0;
1125  s->tags [var] = 0;
1126  s->loads [var] = 0;
1127  s->orderpos[var] = veci_size(&s->order);
1128  s->reasons [var] = 0;
1129  s->model [var] = 0;
1130 
1131  /* does not hold because variables enqueued at top level will not be reinserted in the heap
1132  assert(veci_size(&s->order) == var);
1133  */
1134  veci_push(&s->order,var);
1135  order_update(s, var);
1136  }
1137 
1138  s->size = n > s->size ? n : s->size;
1139 }
char * memset()
int * model
Definition: satSolver.h:144
int * ptr
Definition: satVec.h:34
veci * wlists
Definition: satSolver.h:103
unsigned * activity
Definition: satSolver.h:122
int * reasons
Definition: satSolver.h:136
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
int var(Lit p)
Definition: SolverTypes.h:62
static void veci_push(veci *v, int e)
Definition: satVec.h:53
char * tags
Definition: satSolver.h:132
Definition: satVec.h:31
char * polarity
Definition: satSolver.h:131
char * assigns
Definition: satSolver.h:130
int lit
Definition: satVec.h:130
double * factors
Definition: satSolver.h:168
char * loads
Definition: satSolver.h:133
int * orderpos
Definition: satSolver.h:135
char * pFreqs
Definition: satSolver.h:125
static void veci_new(veci *v)
Definition: satVec.h:38
unsigned * activity2
Definition: satSolver.h:123
lit * trail
Definition: satSolver.h:137
int size
Definition: satVec.h:33
int * levels
Definition: satSolver.h:129
static void order_update(sat_solver *s, int v)
Definition: satSolver.c:138
#define assert(ex)
Definition: util_old.h:213
static int veci_size(veci *v)
Definition: satVec.h:46
static const int varX
Definition: satSolver.c:78
int sat_solver_simplify ( sat_solver s)

Definition at line 1276 of file satSolver.c.

1277 {
1278  assert(sat_solver_dl(s) == 0);
1279  if (sat_solver_propagate(s) != 0)
1280  return false;
1281  return true;
1282 }
static int sat_solver_dl(sat_solver *s)
Definition: satSolver.c:132
#define assert(ex)
Definition: util_old.h:213
int sat_solver_propagate(sat_solver *s)
Definition: satSolver.c:883
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 
)

Definition at line 1700 of file satSolver.c.

1701 {
1702  int restart_iter = 0;
1703  ABC_INT64_T nof_conflicts;
1704 // ABC_INT64_T nof_learnts = sat_solver_nclauses(s) / 3;
1705  lbool status = l_Undef;
1706  lit* i;
1707 
1708  if ( s->fVerbose )
1709  printf( "Running SAT solver with parameters %d and %d and %d.\n", s->nLearntStart, s->nLearntDelta, s->nLearntRatio );
1710 
1711  ////////////////////////////////////////////////
1712  if ( s->fSolved )
1713  {
1714  if ( s->pStore )
1715  {
1716  int RetValue = Sto_ManAddClause( (Sto_Man_t *)s->pStore, NULL, NULL );
1717  assert( RetValue );
1718  (void) RetValue;
1719  }
1720  return l_False;
1721  }
1722  ////////////////////////////////////////////////
1723  veci_resize(&s->unit_lits, 0);
1724 
1725  // set the external limits
1726  s->nCalls++;
1727  s->nRestarts = 0;
1728  s->nConfLimit = 0;
1729  s->nInsLimit = 0;
1730  if ( nConfLimit )
1731  s->nConfLimit = s->stats.conflicts + nConfLimit;
1732  if ( nInsLimit )
1733 // s->nInsLimit = s->stats.inspects + nInsLimit;
1734  s->nInsLimit = s->stats.propagations + nInsLimit;
1735  if ( nConfLimitGlobal && (s->nConfLimit == 0 || s->nConfLimit > nConfLimitGlobal) )
1736  s->nConfLimit = nConfLimitGlobal;
1737  if ( nInsLimitGlobal && (s->nInsLimit == 0 || s->nInsLimit > nInsLimitGlobal) )
1738  s->nInsLimit = nInsLimitGlobal;
1739 
1740 #ifndef SAT_USE_ANALYZE_FINAL
1741 
1742  //printf("solve: "); printlits(begin, end); printf("\n");
1743  for (i = begin; i < end; i++){
1744 // switch (lit_sign(*i) ? -s->assignss[lit_var(*i)] : s->assignss[lit_var(*i)]){
1745  switch (var_value(s, *i)) {
1746  case var1: // l_True:
1747  break;
1748  case varX: // l_Undef
1749  sat_solver_assume(s, *i);
1750  if (sat_solver_propagate(s) == 0)
1751  break;
1752  // fallthrough
1753  case var0: // l_False
1754  sat_solver_canceluntil(s, 0);
1755  return l_False;
1756  }
1757  }
1758  s->root_level = sat_solver_dl(s);
1759 
1760 #endif
1761 
1762 /*
1763  // Perform assumptions:
1764  root_level = assumps.size();
1765  for (int i = 0; i < assumps.size(); i++){
1766  Lit p = assumps[i];
1767  assert(var(p) < nVars());
1768  if (!sat_solver_assume(p)){
1769  GClause r = reason[var(p)];
1770  if (r != GClause_NULL){
1771  Clause* confl;
1772  if (r.isLit()){
1773  confl = propagate_tmpbin;
1774  (*confl)[1] = ~p;
1775  (*confl)[0] = r.lit();
1776  }else
1777  confl = r.clause();
1778  analyzeFinal(confl, true);
1779  conflict.push(~p);
1780  }else
1781  conflict.clear(),
1782  conflict.push(~p);
1783  cancelUntil(0);
1784  return false; }
1785  Clause* confl = propagate();
1786  if (confl != NULL){
1787  analyzeFinal(confl), assert(conflict.size() > 0);
1788  cancelUntil(0);
1789  return false; }
1790  }
1791  assert(root_level == decisionLevel());
1792 */
1793 
1794 #ifdef SAT_USE_ANALYZE_FINAL
1795  // Perform assumptions:
1796  s->root_level = end - begin;
1797  for ( i = begin; i < end; i++ )
1798  {
1799  lit p = *i;
1800  assert(lit_var(p) < s->size);
1801  veci_push(&s->trail_lim,s->qtail);
1802  if (!sat_solver_enqueue(s,p,0))
1803  {
1804  int h = s->reasons[lit_var(p)];
1805  if (h)
1806  {
1807  if (clause_is_lit(h))
1808  {
1809  (clause_begin(s->binary))[1] = lit_neg(p);
1810  (clause_begin(s->binary))[0] = clause_read_lit(h);
1811  h = s->hBinary;
1812  }
1813  sat_solver_analyze_final(s, h, 1);
1814  veci_push(&s->conf_final, lit_neg(p));
1815  }
1816  else
1817  {
1818  veci_resize(&s->conf_final,0);
1819  veci_push(&s->conf_final, lit_neg(p));
1820  // the two lines below are a bug fix by Siert Wieringa
1821  if (var_level(s, lit_var(p)) > 0)
1822  veci_push(&s->conf_final, p);
1823  }
1824  sat_solver_canceluntil(s, 0);
1825  return l_False;
1826  }
1827  else
1828  {
1829  int fConfl = sat_solver_propagate(s);
1830  if (fConfl){
1831  sat_solver_analyze_final(s, fConfl, 0);
1832  assert(s->conf_final.size > 0);
1833  sat_solver_canceluntil(s, 0);
1834  return l_False; }
1835  }
1836  }
1837  assert(s->root_level == sat_solver_dl(s));
1838 #endif
1839 
1840  s->nCalls2++;
1841 
1842  if (s->verbosity >= 1){
1843  printf("==================================[MINISAT]===================================\n");
1844  printf("| Conflicts | ORIGINAL | LEARNT | Progress |\n");
1845  printf("| | Clauses Literals | Limit Clauses Literals Lit/Cl | |\n");
1846  printf("==============================================================================\n");
1847  }
1848 
1849  while (status == l_Undef){
1850  double Ratio = (s->stats.learnts == 0)? 0.0 :
1851  s->stats.learnts_literals / (double)s->stats.learnts;
1852  if ( s->nRuntimeLimit && Abc_Clock() > s->nRuntimeLimit )
1853  break;
1854  if (s->verbosity >= 1)
1855  {
1856  printf("| %9.0f | %7.0f %8.0f | %7.0f %7.0f %8.0f %7.1f | %6.3f %% |\n",
1857  (double)s->stats.conflicts,
1858  (double)s->stats.clauses,
1859  (double)s->stats.clauses_literals,
1860 // (double)nof_learnts,
1861  (double)0,
1862  (double)s->stats.learnts,
1863  (double)s->stats.learnts_literals,
1864  Ratio,
1865  s->progress_estimate*100);
1866  fflush(stdout);
1867  }
1868  nof_conflicts = (ABC_INT64_T)( 100 * luby(2, restart_iter++) );
1869  status = sat_solver_search(s, nof_conflicts);
1870 // nof_learnts = nof_learnts * 11 / 10; //*= 1.1;
1871  // quit the loop if reached an external limit
1872  if ( s->nConfLimit && s->stats.conflicts > s->nConfLimit )
1873  break;
1874  if ( s->nInsLimit && s->stats.propagations > s->nInsLimit )
1875  break;
1876  if ( s->nRuntimeLimit && Abc_Clock() > s->nRuntimeLimit )
1877  break;
1878  }
1879  if (s->verbosity >= 1)
1880  printf("==============================================================================\n");
1881 
1883 
1884  ////////////////////////////////////////////////
1885  if ( status == l_False && s->pStore )
1886  {
1887  int RetValue = Sto_ManAddClause( (Sto_Man_t *)s->pStore, NULL, NULL );
1888  assert( RetValue );
1889  (void) RetValue;
1890  }
1891  ////////////////////////////////////////////////
1892  return status;
1893 }
static const int var1
Definition: satSolver.c:77
ABC_INT64_T clauses_literals
Definition: satVec.h:155
char lbool
Definition: satVec.h:133
veci unit_lits
Definition: satSolver.h:172
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int * reasons
Definition: satSolver.h:136
#define l_Undef
Definition: SolverTypes.h:86
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_push(veci *v, int e)
Definition: satVec.h:53
int root_level
Definition: satSolver.h:148
ABC_INT64_T nInsLimit
Definition: satSolver.h:164
void * pStore
Definition: satSolver.h:180
static void sat_solver_canceluntil(sat_solver *s, int level)
Definition: satSolver.c:528
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
static abctime Abc_Clock()
Definition: abc_global.h:279
stats_t stats
Definition: satSolver.h:156
double luby(double y, int x)
Definition: satSolver.c:1555
int lit
Definition: satVec.h:130
ABC_INT64_T learnts_literals
Definition: satVec.h:155
static lit lit_neg(lit l)
Definition: satVec.h:144
int nLearntDelta
Definition: satSolver.h:159
static int var_value(sat_solver *s, int v)
Definition: satSolver.c:89
static const int var0
Definition: satSolver.c:76
veci conf_final
Definition: satSolver.h:145
abctime nRuntimeLimit
Definition: satSolver.h:165
static int sat_solver_dl(sat_solver *s)
Definition: satSolver.c:132
static void sat_solver_analyze_final(sat_solver *s, int hConf, int skip_first)
Definition: satSolver.c:729
veci trail_lim
Definition: satSolver.h:142
clause * binary
Definition: satSolver.h:102
int nLearntRatio
Definition: satSolver.h:160
static lbool sat_solver_search(sat_solver *s, ABC_INT64_T nof_conflicts)
Definition: satSolver.c:1575
ABC_INT64_T nConfLimit
Definition: satSolver.h:163
unsigned learnts
Definition: satVec.h:153
ABC_INT64_T conflicts
Definition: satVec.h:154
static int clause_is_lit(cla h)
Definition: satClause.h:139
int nLearntStart
Definition: satSolver.h:158
static lit * clause_begin(clause *c)
Definition: satClause.h:147
static int sat_solver_assume(sat_solver *s, lit l)
Definition: satSolver.c:516
unsigned clauses
Definition: satVec.h:153
static lit clause_read_lit(cla h)
Definition: satClause.h:140
int Sto_ManAddClause(Sto_Man_t *p, lit *pBeg, lit *pEnd)
Definition: satStore.c:160
#define l_False
Definition: SolverTypes.h:85
ABC_INT64_T propagations
Definition: satVec.h:154
int size
Definition: satVec.h:33
#define assert(ex)
Definition: util_old.h:213
int sat_solver_propagate(sat_solver *s)
Definition: satSolver.c:883
static int sat_solver_enqueue(sat_solver *s, lit l, int from)
Definition: satSolver.c:466
double progress_estimate
Definition: satSolver.h:152
static int var_level(sat_solver *s, int v)
Definition: satSolver.c:88
static const int varX
Definition: satSolver.c:78
void sat_solver_store_alloc ( sat_solver s)

Definition at line 1916 of file satSolver.c.

1917 {
1918  assert( s->pStore == NULL );
1919  s->pStore = Sto_ManAlloc();
1920 }
void * pStore
Definition: satSolver.h:180
Sto_Man_t * Sto_ManAlloc()
MACRO DEFINITIONS ///.
Definition: satStore.c:121
#define assert(ex)
Definition: util_old.h:213
int sat_solver_store_change_last ( sat_solver s)

Definition at line 1933 of file satSolver.c.

1934 {
1935  if ( s->pStore ) return Sto_ManChangeLastClause( (Sto_Man_t *)s->pStore );
1936  return -1;
1937 }
void * pStore
Definition: satSolver.h:180
int Sto_ManChangeLastClause(Sto_Man_t *p)
Definition: satStore.c:279
void sat_solver_store_free ( sat_solver s)

Definition at line 1927 of file satSolver.c.

1928 {
1929  if ( s->pStore ) Sto_ManFree( (Sto_Man_t *)s->pStore );
1930  s->pStore = NULL;
1931 }
void * pStore
Definition: satSolver.h:180
void Sto_ManFree(Sto_Man_t *p)
Definition: satStore.c:143
void sat_solver_store_mark_clauses_a ( sat_solver s)

Definition at line 1944 of file satSolver.c.

1945 {
1946  if ( s->pStore ) Sto_ManMarkClausesA( (Sto_Man_t *)s->pStore );
1947 }
void Sto_ManMarkClausesA(Sto_Man_t *p)
Definition: satStore.c:257
void * pStore
Definition: satSolver.h:180
void sat_solver_store_mark_roots ( sat_solver s)

Definition at line 1939 of file satSolver.c.

1940 {
1941  if ( s->pStore ) Sto_ManMarkRoots( (Sto_Man_t *)s->pStore );
1942 }
void * pStore
Definition: satSolver.h:180
void Sto_ManMarkRoots(Sto_Man_t *p)
Definition: satStore.c:235
void* sat_solver_store_release ( sat_solver s)

Definition at line 1949 of file satSolver.c.

1950 {
1951  void * pTemp;
1952  if ( s->pStore == NULL )
1953  return NULL;
1954  pTemp = s->pStore;
1955  s->pStore = NULL;
1956  return pTemp;
1957 }
void * pStore
Definition: satSolver.h:180
void sat_solver_store_write ( sat_solver s,
char *  pFileName 
)

Definition at line 1922 of file satSolver.c.

1923 {
1924  if ( s->pStore ) Sto_ManDumpClauses( (Sto_Man_t *)s->pStore, pFileName );
1925 }
void * pStore
Definition: satSolver.h:180
void Sto_ManDumpClauses(Sto_Man_t *p, char *pFileName)
Definition: satStore.c:305
static void selectionsort ( void **  array,
int  size,
int(*)(const void *, const void *)  comp 
)
inlinestatic

Definition at line 340 of file satSolver.c.

341 {
342  int i, j, best_i;
343  void* tmp;
344 
345  for (i = 0; i < size-1; i++){
346  best_i = i;
347  for (j = i+1; j < size; j++){
348  if (comp(array[j], array[best_i]) < 0)
349  best_i = j;
350  }
351  tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp;
352  }
353 }
static int size
Definition: cuddSign.c:86
static void solver2_clear_tags ( sat_solver s,
int  start 
)
inlinestatic

Definition at line 110 of file satSolver.c.

110  {
111  int i, * tagged = veci_begin(&s->tagged);
112  for (i = start; i < veci_size(&s->tagged); i++)
113  s->tags[tagged[i]] = 0;
114  veci_resize(&s->tagged,start);
115 }
char * tags
Definition: satSolver.h:132
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
static void sortrnd ( void **  array,
int  size,
int(*)(const void *, const void *)  comp,
double *  seed 
)
static

Definition at line 355 of file satSolver.c.

356 {
357  if (size <= 15)
358  selectionsort(array, size, comp);
359 
360  else{
361  void* pivot = array[irand(seed, size)];
362  void* tmp;
363  int i = -1;
364  int j = size;
365 
366  for(;;){
367  do i++; while(comp(array[i], pivot)<0);
368  do j--; while(comp(pivot, array[j])<0);
369 
370  if (i >= j) break;
371 
372  tmp = array[i]; array[i] = array[j]; array[j] = tmp;
373  }
374 
375  sortrnd(array , i , comp, seed);
376  sortrnd(&array[i], size-i, comp, seed);
377  }
378 }
static int irand(double *seed, int size)
Definition: satSolver.c:69
static void selectionsort(void **array, int size, int(*comp)(const void *, const void *))
Definition: satSolver.c:340
static void sortrnd(void **array, int size, int(*comp)(const void *, const void *), double *seed)
Definition: satSolver.c:355
static int size
Definition: cuddSign.c:86
static void var_add_tag ( sat_solver s,
int  v,
int  tag 
)
inlinestatic

Definition at line 104 of file satSolver.c.

104  {
105  assert( tag > 0 && tag < 16 );
106  if ( s->tags[v] == 0 )
107  veci_push( &s->tagged, v );
108  s->tags[v] |= tag;
109 }
static void veci_push(veci *v, int e)
Definition: satVec.h:53
char * tags
Definition: satSolver.h:132
#define assert(ex)
Definition: util_old.h:213
static int var_level ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 88 of file satSolver.c.

88 { return s->levels[v]; }
int * levels
Definition: satSolver.h:129
static int var_polar ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 90 of file satSolver.c.

90 { return s->polarity[v]; }
char * polarity
Definition: satSolver.h:131
static void var_set_level ( sat_solver s,
int  v,
int  lev 
)
inlinestatic

Definition at line 92 of file satSolver.c.

92 { s->levels[v] = lev; }
int * levels
Definition: satSolver.h:129
static void var_set_polar ( sat_solver s,
int  v,
int  pol 
)
inlinestatic

Definition at line 94 of file satSolver.c.

94 { s->polarity[v] = pol; }
char * polarity
Definition: satSolver.h:131
static void var_set_tag ( sat_solver s,
int  v,
int  tag 
)
inlinestatic

Definition at line 98 of file satSolver.c.

98  {
99  assert( tag > 0 && tag < 16 );
100  if ( s->tags[v] == 0 )
101  veci_push( &s->tagged, v );
102  s->tags[v] = tag;
103 }
static void veci_push(veci *v, int e)
Definition: satVec.h:53
char * tags
Definition: satSolver.h:132
#define assert(ex)
Definition: util_old.h:213
static void var_set_value ( sat_solver s,
int  v,
int  val 
)
inlinestatic

Definition at line 93 of file satSolver.c.

93 { s->assigns[v] = val; }
char * assigns
Definition: satSolver.h:130
static int var_tag ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 97 of file satSolver.c.

97 { return s->tags[v]; }
char * tags
Definition: satSolver.h:132
static int var_value ( sat_solver s,
int  v 
)
inlinestatic

Definition at line 89 of file satSolver.c.

89 { return s->assigns[v]; }
char * assigns
Definition: satSolver.h:130

Variable Documentation

const int var0 = 1
static

Definition at line 76 of file satSolver.c.

const int var1 = 0
static

Definition at line 77 of file satSolver.c.

const int varX = 3
static

Definition at line 78 of file satSolver.c.