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

Go to the source code of this file.

Data Structures

struct  sat_solver_t
 

Typedefs

typedef struct sat_solver_t sat_solver
 
typedef struct varinfo_t varinfo
 

Functions

sat_solversat_solver_new (void)
 
void sat_solver_delete (sat_solver *s)
 
int sat_solver_addclause (sat_solver *s, lit *begin, lit *end)
 
int sat_solver_clause_new (sat_solver *s, lit *begin, lit *end, int learnt)
 
int sat_solver_simplify (sat_solver *s)
 
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)
 
void sat_solver_restart (sat_solver *s)
 
void sat_solver_rollback (sat_solver *s)
 
int sat_solver_nvars (sat_solver *s)
 
int sat_solver_nclauses (sat_solver *s)
 
int sat_solver_nconflicts (sat_solver *s)
 
double sat_solver_memory (sat_solver *s)
 
int sat_solver_count_assigned (sat_solver *s)
 
void sat_solver_setnvars (sat_solver *s, int n)
 
int sat_solver_get_var_value (sat_solver *s, int v)
 
void Sat_SolverWriteDimacs (sat_solver *p, char *pFileName, lit *assumptionsBegin, lit *assumptionsEnd, int incrementVars)
 
void Sat_SolverPrintStats (FILE *pFile, sat_solver *p)
 
int * Sat_SolverGetModel (sat_solver *p, int *pVars, int nVars)
 
void Sat_SolverDoubleClauses (sat_solver *p, int iVar)
 
void Sat_SolverTraceStart (sat_solver *pSat, char *pName)
 DECLARATIONS ///. More...
 
void Sat_SolverTraceStop (sat_solver *pSat)
 
void Sat_SolverTraceWrite (sat_solver *pSat, int *pBeg, int *pEnd, int fRoot)
 
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)
 
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)
 
static clauseclause_read (sat_solver *s, cla h)
 
static int sat_solver_var_value (sat_solver *s, int v)
 
static int sat_solver_var_literal (sat_solver *s, int v)
 
static void sat_solver_act_var_clear (sat_solver *s)
 
static void sat_solver_compress (sat_solver *s)
 
static int sat_solver_final (sat_solver *s, int **ppArray)
 
static abctime sat_solver_set_runtime_limit (sat_solver *s, abctime Limit)
 
static int sat_solver_set_random (sat_solver *s, int fNotUseRandom)
 
static void sat_solver_bookmark (sat_solver *s)
 
static void sat_solver_set_pivot_variables (sat_solver *s, int *pPivots, int nPivots)
 
static int sat_solver_count_usedvars (sat_solver *s)
 
static int sat_solver_add_const (sat_solver *pSat, int iVar, int fCompl)
 
static int sat_solver_add_buffer (sat_solver *pSat, int iVarA, int iVarB, int fCompl)
 
static int sat_solver_add_buffer_enable (sat_solver *pSat, int iVarA, int iVarB, int iVarEn, int fCompl)
 
static int sat_solver_add_and (sat_solver *pSat, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl)
 
static int sat_solver_add_xor (sat_solver *pSat, int iVarA, int iVarB, int iVarC, int fCompl)
 
static int sat_solver_add_mux (sat_solver *pSat, int iVarC, int iVarT, int iVarE, int iVarZ)
 
static int sat_solver_add_mux41 (sat_solver *pSat, int iVarC0, int iVarC1, int iVarD0, int iVarD1, int iVarD2, int iVarD3, int iVarZ)
 
static int sat_solver_add_xor_and (sat_solver *pSat, int iVarF, int iVarA, int iVarB, int iVarC)
 
static int sat_solver_add_constraint (sat_solver *pSat, int iVar, int iVar2, int fCompl)
 

Typedef Documentation

typedef struct sat_solver_t sat_solver

Definition at line 42 of file satSolver.h.

typedef struct varinfo_t varinfo

Definition at line 89 of file satSolver.h.

Function Documentation

static clause* clause_read ( sat_solver s,
cla  h 
)
inlinestatic

Definition at line 195 of file satSolver.h.

196 {
197  return Sat_MemClauseHand( &s->Mem, h );
198 }
Sat_Mem_t Mem
Definition: satSolver.h:99
static clause * Sat_MemClauseHand(Sat_Mem_t *p, cla h)
Definition: satClause.h:98
static void sat_solver_act_var_clear ( sat_solver s)
static

Definition at line 210 of file satSolver.h.

211 {
212  int i;
213  for (i = 0; i < s->size; i++)
214  s->activity[i] = 0;
215  s->var_inc = 1;
216 }
unsigned * activity
Definition: satSolver.h:122
static int sat_solver_add_and ( sat_solver pSat,
int  iVar,
int  iVar0,
int  iVar1,
int  fCompl0,
int  fCompl1,
int  fCompl 
)
inlinestatic

Definition at line 324 of file satSolver.h.

325 {
326  lit Lits[3];
327  int Cid;
328 
329  Lits[0] = toLitCond( iVar, !fCompl );
330  Lits[1] = toLitCond( iVar0, fCompl0 );
331  Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
332  assert( Cid );
333 
334  Lits[0] = toLitCond( iVar, !fCompl );
335  Lits[1] = toLitCond( iVar1, fCompl1 );
336  Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
337  assert( Cid );
338 
339  Lits[0] = toLitCond( iVar, fCompl );
340  Lits[1] = toLitCond( iVar0, !fCompl0 );
341  Lits[2] = toLitCond( iVar1, !fCompl1 );
342  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
343  assert( Cid );
344  return 3;
345 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_add_buffer ( sat_solver pSat,
int  iVarA,
int  iVarB,
int  fCompl 
)
inlinestatic

Definition at line 288 of file satSolver.h.

289 {
290  lit Lits[2];
291  int Cid;
292  assert( iVarA >= 0 && iVarB >= 0 );
293 
294  Lits[0] = toLitCond( iVarA, 0 );
295  Lits[1] = toLitCond( iVarB, !fCompl );
296  Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
297  assert( Cid );
298 
299  Lits[0] = toLitCond( iVarA, 1 );
300  Lits[1] = toLitCond( iVarB, fCompl );
301  Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
302  assert( Cid );
303  return 2;
304 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_add_buffer_enable ( sat_solver pSat,
int  iVarA,
int  iVarB,
int  iVarEn,
int  fCompl 
)
inlinestatic

Definition at line 305 of file satSolver.h.

306 {
307  lit Lits[3];
308  int Cid;
309  assert( iVarA >= 0 && iVarB >= 0 && iVarEn >= 0 );
310 
311  Lits[0] = toLitCond( iVarA, 0 );
312  Lits[1] = toLitCond( iVarB, !fCompl );
313  Lits[2] = toLitCond( iVarEn, 1 );
314  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
315  assert( Cid );
316 
317  Lits[0] = toLitCond( iVarA, 1 );
318  Lits[1] = toLitCond( iVarB, fCompl );
319  Lits[2] = toLitCond( iVarEn, 1 );
320  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
321  assert( Cid );
322  return 2;
323 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_add_const ( sat_solver pSat,
int  iVar,
int  fCompl 
)
inlinestatic

Definition at line 277 of file satSolver.h.

278 {
279  lit Lits[1];
280  int Cid;
281  assert( iVar >= 0 );
282 
283  Lits[0] = toLitCond( iVar, fCompl );
284  Cid = sat_solver_addclause( pSat, Lits, Lits + 1 );
285  assert( Cid );
286  return 1;
287 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_add_constraint ( sat_solver pSat,
int  iVar,
int  iVar2,
int  fCompl 
)
inlinestatic

Definition at line 526 of file satSolver.h.

527 {
528  lit Lits[2];
529  int Cid;
530  assert( iVar >= 0 );
531 
532  Lits[0] = toLitCond( iVar, fCompl );
533  Lits[1] = toLitCond( iVar2, 0 );
534  Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
535  assert( Cid );
536 
537  Lits[0] = toLitCond( iVar, fCompl );
538  Lits[1] = toLitCond( iVar2, 1 );
539  Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
540  assert( Cid );
541  return 2;
542 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_add_mux ( sat_solver pSat,
int  iVarC,
int  iVarT,
int  iVarE,
int  iVarZ 
)
inlinestatic

Definition at line 377 of file satSolver.h.

378 {
379  lit Lits[3];
380  int Cid;
381  assert( iVarC >= 0 && iVarT >= 0 && iVarE >= 0 && iVarZ >= 0 );
382 
383  Lits[0] = toLitCond( iVarC, 1 );
384  Lits[1] = toLitCond( iVarT, 1 );
385  Lits[2] = toLitCond( iVarZ, 0 );
386  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
387  assert( Cid );
388 
389  Lits[0] = toLitCond( iVarC, 1 );
390  Lits[1] = toLitCond( iVarT, 0 );
391  Lits[2] = toLitCond( iVarZ, 1 );
392  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
393  assert( Cid );
394 
395  Lits[0] = toLitCond( iVarC, 0 );
396  Lits[1] = toLitCond( iVarE, 1 );
397  Lits[2] = toLitCond( iVarZ, 0 );
398  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
399  assert( Cid );
400 
401  Lits[0] = toLitCond( iVarC, 0 );
402  Lits[1] = toLitCond( iVarE, 0 );
403  Lits[2] = toLitCond( iVarZ, 1 );
404  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
405  assert( Cid );
406 
407  if ( iVarT == iVarE )
408  return 4;
409 
410  Lits[0] = toLitCond( iVarT, 0 );
411  Lits[1] = toLitCond( iVarE, 0 );
412  Lits[2] = toLitCond( iVarZ, 1 );
413  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
414  assert( Cid );
415 
416  Lits[0] = toLitCond( iVarT, 1 );
417  Lits[1] = toLitCond( iVarE, 1 );
418  Lits[2] = toLitCond( iVarZ, 0 );
419  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
420  assert( Cid );
421  return 6;
422 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_add_mux41 ( sat_solver pSat,
int  iVarC0,
int  iVarC1,
int  iVarD0,
int  iVarD1,
int  iVarD2,
int  iVarD3,
int  iVarZ 
)
inlinestatic

Definition at line 423 of file satSolver.h.

424 {
425  lit Lits[4];
426  int Cid;
427  assert( iVarC0 >= 0 && iVarC1 >= 0 && iVarD0 >= 0 && iVarD1 >= 0 && iVarD2 >= 0 && iVarD3 >= 0 && iVarZ >= 0 );
428 
429  Lits[0] = toLitCond( iVarD0, 1 );
430  Lits[1] = toLitCond( iVarC0, 0 );
431  Lits[2] = toLitCond( iVarC1, 0 );
432  Lits[3] = toLitCond( iVarZ, 0 );
433  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
434  assert( Cid );
435 
436  Lits[0] = toLitCond( iVarD1, 1 );
437  Lits[1] = toLitCond( iVarC0, 1 );
438  Lits[2] = toLitCond( iVarC1, 0 );
439  Lits[3] = toLitCond( iVarZ, 0 );
440  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
441  assert( Cid );
442 
443  Lits[0] = toLitCond( iVarD2, 1 );
444  Lits[1] = toLitCond( iVarC0, 0 );
445  Lits[2] = toLitCond( iVarC1, 1 );
446  Lits[3] = toLitCond( iVarZ, 0 );
447  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
448  assert( Cid );
449 
450  Lits[0] = toLitCond( iVarD3, 1 );
451  Lits[1] = toLitCond( iVarC0, 1 );
452  Lits[2] = toLitCond( iVarC1, 1 );
453  Lits[3] = toLitCond( iVarZ, 0 );
454  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
455  assert( Cid );
456 
457 
458  Lits[0] = toLitCond( iVarD0, 0 );
459  Lits[1] = toLitCond( iVarC0, 0 );
460  Lits[2] = toLitCond( iVarC1, 0 );
461  Lits[3] = toLitCond( iVarZ, 1 );
462  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
463  assert( Cid );
464 
465  Lits[0] = toLitCond( iVarD1, 0 );
466  Lits[1] = toLitCond( iVarC0, 1 );
467  Lits[2] = toLitCond( iVarC1, 0 );
468  Lits[3] = toLitCond( iVarZ, 1 );
469  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
470  assert( Cid );
471 
472  Lits[0] = toLitCond( iVarD2, 0 );
473  Lits[1] = toLitCond( iVarC0, 0 );
474  Lits[2] = toLitCond( iVarC1, 1 );
475  Lits[3] = toLitCond( iVarZ, 1 );
476  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
477  assert( Cid );
478 
479  Lits[0] = toLitCond( iVarD3, 0 );
480  Lits[1] = toLitCond( iVarC0, 1 );
481  Lits[2] = toLitCond( iVarC1, 1 );
482  Lits[3] = toLitCond( iVarZ, 1 );
483  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
484  assert( Cid );
485  return 8;
486 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_add_xor ( sat_solver pSat,
int  iVarA,
int  iVarB,
int  iVarC,
int  fCompl 
)
inlinestatic

Definition at line 346 of file satSolver.h.

347 {
348  lit Lits[3];
349  int Cid;
350  assert( iVarA >= 0 && iVarB >= 0 && iVarC >= 0 );
351 
352  Lits[0] = toLitCond( iVarA, !fCompl );
353  Lits[1] = toLitCond( iVarB, 1 );
354  Lits[2] = toLitCond( iVarC, 1 );
355  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
356  assert( Cid );
357 
358  Lits[0] = toLitCond( iVarA, !fCompl );
359  Lits[1] = toLitCond( iVarB, 0 );
360  Lits[2] = toLitCond( iVarC, 0 );
361  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
362  assert( Cid );
363 
364  Lits[0] = toLitCond( iVarA, fCompl );
365  Lits[1] = toLitCond( iVarB, 1 );
366  Lits[2] = toLitCond( iVarC, 0 );
367  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
368  assert( Cid );
369 
370  Lits[0] = toLitCond( iVarA, fCompl );
371  Lits[1] = toLitCond( iVarB, 0 );
372  Lits[2] = toLitCond( iVarC, 1 );
373  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
374  assert( Cid );
375  return 4;
376 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_add_xor_and ( sat_solver pSat,
int  iVarF,
int  iVarA,
int  iVarB,
int  iVarC 
)
inlinestatic

Definition at line 487 of file satSolver.h.

488 {
489  // F = (a (+) b) * c
490  lit Lits[4];
491  int Cid;
492  assert( iVarF >= 0 && iVarA >= 0 && iVarB >= 0 && iVarC >= 0 );
493 
494  Lits[0] = toLitCond( iVarF, 1 );
495  Lits[1] = toLitCond( iVarA, 1 );
496  Lits[2] = toLitCond( iVarB, 1 );
497  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
498  assert( Cid );
499 
500  Lits[0] = toLitCond( iVarF, 1 );
501  Lits[1] = toLitCond( iVarA, 0 );
502  Lits[2] = toLitCond( iVarB, 0 );
503  Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
504  assert( Cid );
505 
506  Lits[0] = toLitCond( iVarF, 1 );
507  Lits[1] = toLitCond( iVarC, 0 );
508  Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
509  assert( Cid );
510 
511  Lits[0] = toLitCond( iVarF, 0 );
512  Lits[1] = toLitCond( iVarA, 1 );
513  Lits[2] = toLitCond( iVarB, 0 );
514  Lits[3] = toLitCond( iVarC, 1 );
515  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
516  assert( Cid );
517 
518  Lits[0] = toLitCond( iVarF, 0 );
519  Lits[1] = toLitCond( iVarA, 0 );
520  Lits[2] = toLitCond( iVarB, 1 );
521  Lits[3] = toLitCond( iVarC, 1 );
522  Cid = sat_solver_addclause( pSat, Lits, Lits + 4 );
523  assert( Cid );
524  return 5;
525 }
int lit
Definition: satVec.h:130
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
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_bookmark ( sat_solver s)
inlinestatic

Definition at line 247 of file satSolver.h.

248 {
249  assert( s->qhead == s->qtail );
250  s->iVarPivot = s->size;
251  s->iTrailPivot = s->qhead;
252  Sat_MemBookMark( &s->Mem );
253  if ( s->activity2 )
254  {
255  s->var_inc2 = s->var_inc;
256  memcpy( s->activity2, s->activity, sizeof(unsigned) * s->iVarPivot );
257  }
258 }
unsigned * activity
Definition: satSolver.h:122
Sat_Mem_t Mem
Definition: satSolver.h:99
char * memcpy()
unsigned * activity2
Definition: satSolver.h:123
int iTrailPivot
Definition: satSolver.h:108
#define assert(ex)
Definition: util_old.h:213
static void Sat_MemBookMark(Sat_Mem_t *p)
Definition: satClause.h:249
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
static void sat_solver_compress ( sat_solver s)
static

Definition at line 217 of file satSolver.h.

218 {
219  if ( s->qtail != s->qhead )
220  {
221  int RetValue = sat_solver_simplify(s);
222  assert( RetValue != 0 );
223  (void) RetValue;
224  }
225 }
#define assert(ex)
Definition: util_old.h:213
int sat_solver_simplify(sat_solver *s)
Definition: satSolver.c:1276
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
static int sat_solver_count_usedvars ( sat_solver s)
inlinestatic

Definition at line 265 of file satSolver.h.

266 {
267  int i, nVars = 0;
268  for ( i = 0; i < s->size; i++ )
269  if ( s->pFreqs[i] )
270  {
271  s->pFreqs[i] = 0;
272  nVars++;
273  }
274  return nVars;
275 }
char * pFreqs
Definition: satSolver.h:125
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_final ( sat_solver s,
int **  ppArray 
)
static

Definition at line 227 of file satSolver.h.

228 {
229  *ppArray = s->conf_final.ptr;
230  return s->conf_final.size;
231 }
int * ptr
Definition: satVec.h:34
veci conf_final
Definition: satSolver.h:145
int size
Definition: satVec.h:33
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
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 }
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 void sat_solver_set_pivot_variables ( sat_solver s,
int *  pPivots,
int  nPivots 
)
inlinestatic

Definition at line 259 of file satSolver.h.

260 {
261  s->pivot_vars.cap = nPivots;
262  s->pivot_vars.size = nPivots;
263  s->pivot_vars.ptr = pPivots;
264 }
int * ptr
Definition: satVec.h:34
int cap
Definition: satVec.h:32
veci pivot_vars
Definition: satSolver.h:173
int size
Definition: satVec.h:33
static int sat_solver_set_random ( sat_solver s,
int  fNotUseRandom 
)
static

Definition at line 240 of file satSolver.h.

241 {
242  int fNotUseRandomOld = s->fNotUseRandom;
243  s->fNotUseRandom = fNotUseRandom;
244  return fNotUseRandomOld;
245 }
int fNotUseRandom
Definition: satSolver.h:176
static abctime sat_solver_set_runtime_limit ( sat_solver s,
abctime  Limit 
)
static

Definition at line 233 of file satSolver.h.

234 {
235  abctime nRuntimeLimit = s->nRuntimeLimit;
236  s->nRuntimeLimit = Limit;
237  return nRuntimeLimit;
238 }
abctime nRuntimeLimit
Definition: satSolver.h:165
ABC_INT64_T abctime
Definition: abc_global.h:278
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
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 int sat_solver_var_literal ( sat_solver s,
int  v 
)
static

Definition at line 205 of file satSolver.h.

206 {
207  assert( v >= 0 && v < s->size );
208  return toLitCond( v, s->model[v] != l_True );
209 }
int * model
Definition: satSolver.h:144
#define l_True
Definition: SolverTypes.h:84
static lit toLitCond(int v, int c)
Definition: satVec.h:143
static int size
Definition: cuddSign.c:86
#define assert(ex)
Definition: util_old.h:213
static int sat_solver_var_value ( sat_solver s,
int  v 
)
static

Definition at line 200 of file satSolver.h.

201 {
202  assert( v >= 0 && v < s->size );
203  return (int)(s->model[v] == l_True);
204 }
int * model
Definition: satSolver.h:144
#define l_True
Definition: SolverTypes.h:84
static int size
Definition: cuddSign.c:86
#define assert(ex)
Definition: util_old.h:213
void Sat_SolverDoubleClauses ( sat_solver p,
int  iVar 
)

Function*************************************************************

Synopsis [Duplicates all clauses, complements unit clause of the given var.]

Description []

SideEffects []

SeeAlso []

Definition at line 308 of file satUtil.c.

309 {
310  assert( 0 );
311 /*
312  clause * pClause;
313  lit Lit, * pLits;
314  int RetValue, nClauses, nVarsOld, nLitsOld, nLits, c, v;
315  // get the number of variables
316  nVarsOld = p->size;
317  nLitsOld = 2 * p->size;
318  // extend the solver to depend on two sets of variables
319  sat_solver_setnvars( p, 2 * p->size );
320  // duplicate implications
321  for ( v = 0; v < nVarsOld; v++ )
322  if ( p->assigns[v] != l_Undef )
323  {
324  Lit = nLitsOld + toLitCond( v, p->assigns[v]==l_False );
325  if ( v == iVar )
326  Lit = lit_neg(Lit);
327  RetValue = sat_solver_addclause( p, &Lit, &Lit + 1 );
328  assert( RetValue );
329  }
330  // duplicate clauses
331  nClauses = vecp_size(&p->clauses);
332  for ( c = 0; c < nClauses; c++ )
333  {
334  pClause = (clause *)p->clauses.ptr[c];
335  nLits = clause_size(pClause);
336  pLits = clause_begin(pClause);
337  for ( v = 0; v < nLits; v++ )
338  pLits[v] += nLitsOld;
339  RetValue = sat_solver_addclause( p, pLits, pLits + nLits );
340  assert( RetValue );
341  for ( v = 0; v < nLits; v++ )
342  pLits[v] -= nLitsOld;
343  }
344 */
345 }
#define assert(ex)
Definition: util_old.h:213
int* Sat_SolverGetModel ( sat_solver p,
int *  pVars,
int  nVars 
)

Function*************************************************************

Synopsis [Returns a counter-example.]

Description []

SideEffects []

SeeAlso []

Definition at line 266 of file satUtil.c.

267 {
268  int * pModel;
269  int i;
270  pModel = ABC_CALLOC( int, nVars+1 );
271  for ( i = 0; i < nVars; i++ )
272  pModel[i] = sat_solver_var_value(p, pVars[i]);
273  return pModel;
274 }
static int sat_solver_var_value(sat_solver *s, int v)
Definition: satSolver.h:200
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
void Sat_SolverPrintStats ( FILE *  pFile,
sat_solver p 
)

Function*************************************************************

Synopsis [Writes the given clause in a file in DIMACS format.]

Description []

SideEffects []

SeeAlso []

Definition at line 188 of file satUtil.c.

189 {
190 // printf( "calls : %10d (%d)\n", (int)p->nCalls, (int)p->nCalls2 );
191  printf( "starts : %10d\n", (int)p->stats.starts );
192  printf( "conflicts : %10d\n", (int)p->stats.conflicts );
193  printf( "decisions : %10d\n", (int)p->stats.decisions );
194  printf( "propagations : %10d\n", (int)p->stats.propagations );
195 // printf( "inspects : %10d\n", (int)p->stats.inspects );
196 // printf( "inspects2 : %10d\n", (int)p->stats.inspects2 );
197 }
ABC_INT64_T decisions
Definition: satVec.h:154
stats_t stats
Definition: satSolver.h:156
ABC_INT64_T conflicts
Definition: satVec.h:154
ABC_INT64_T propagations
Definition: satVec.h:154
unsigned starts
Definition: satVec.h:153
void Sat_SolverTraceStart ( sat_solver pSat,
char *  pName 
)

DECLARATIONS ///.

CFile****************************************************************

FileName [satTrace.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [SAT sat_solver.]

Synopsis [Records the trace of SAT solving in the CNF form.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
satTrace.c,v 1.4 2005/09/16 22:55:03 casem Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Start the trace recording.]

Description []

SideEffects []

SeeAlso []

Definition at line 53 of file satTrace.c.

54 {
55  assert( pSat->pFile == NULL );
56  pSat->pFile = fopen( pName, "w" );
57  fprintf( pSat->pFile, " \n" );
58  pSat->nClauses = 0;
59  pSat->nRoots = 0;
60 }
FILE * pFile
Definition: satSolver.h:184
#define assert(ex)
Definition: util_old.h:213
void Sat_SolverTraceStop ( sat_solver pSat)

Function*************************************************************

Synopsis [Stops the trace recording.]

Description []

SideEffects []

SeeAlso []

Definition at line 73 of file satTrace.c.

74 {
75  if ( pSat->pFile == NULL )
76  return;
77  rewind( pSat->pFile );
78  fprintf( pSat->pFile, "p %d %d %d", sat_solver_nvars(pSat), pSat->nClauses, pSat->nRoots );
79  fclose( pSat->pFile );
80  pSat->pFile = NULL;
81 }
FILE * pFile
Definition: satSolver.h:184
int sat_solver_nvars(sat_solver *s)
Definition: satSolver.c:1896
VOID_HACK rewind()
void Sat_SolverTraceWrite ( sat_solver pSat,
int *  pBeg,
int *  pEnd,
int  fRoot 
)

Function*************************************************************

Synopsis [Writes one clause into the trace file.]

Description []

SideEffects []

SeeAlso []

Definition at line 95 of file satTrace.c.

96 {
97  if ( pSat->pFile == NULL )
98  return;
99  pSat->nClauses++;
100  pSat->nRoots += fRoot;
101  for ( ; pBeg < pEnd ; pBeg++ )
102  fprintf( pSat->pFile, " %d", lit_print(*pBeg) );
103  fprintf( pSat->pFile, " 0\n" );
104 }
FILE * pFile
Definition: satSolver.h:184
static int lit_print(lit l)
Definition: satVec.h:147
void Sat_SolverWriteDimacs ( sat_solver p,
char *  pFileName,
lit assumpBegin,
lit assumpEnd,
int  incrementVars 
)

Function*************************************************************

Synopsis [Write the clauses in the solver into a file in DIMACS format.]

Description []

SideEffects []

SeeAlso []

Definition at line 71 of file satUtil.c.

72 {
73  Sat_Mem_t * pMem = &p->Mem;
74  FILE * pFile;
75  clause * c;
76  int i, k, nUnits;
77 
78  // count the number of unit clauses
79  nUnits = 0;
80  for ( i = 0; i < p->size; i++ )
81  if ( p->levels[i] == 0 && p->assigns[i] != 3 )
82  nUnits++;
83 
84  // start the file
85  pFile = fopen( pFileName, "wb" );
86  if ( pFile == NULL )
87  {
88  printf( "Sat_SolverWriteDimacs(): Cannot open the ouput file.\n" );
89  return;
90  }
91 // fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
92  fprintf( pFile, "p cnf %d %d\n", p->size, Sat_MemEntryNum(&p->Mem, 0)-1+Sat_MemEntryNum(&p->Mem, 1)+nUnits+(int)(assumpEnd-assumpBegin) );
93 
94  // write the original clauses
95  Sat_MemForEachClause( pMem, c, i, k )
96  Sat_SolverClauseWriteDimacs( pFile, c, incrementVars );
97 
98  // write the learned clauses
99 // Sat_MemForEachLearned( pMem, c, i, k )
100 // Sat_SolverClauseWriteDimacs( pFile, c, incrementVars );
101 
102  // write zero-level assertions
103  for ( i = 0; i < p->size; i++ )
104  if ( p->levels[i] == 0 && p->assigns[i] != 3 ) // varX
105  fprintf( pFile, "%s%d%s\n",
106  (p->assigns[i] == 1)? "-": "", // var0
107  i + (int)(incrementVars>0),
108  (incrementVars) ? " 0" : "");
109 
110  // write the assump
111  if (assumpBegin) {
112  for (; assumpBegin != assumpEnd; assumpBegin++) {
113  fprintf( pFile, "%s%d%s\n",
114  lit_sign(*assumpBegin)? "-": "",
115  lit_var(*assumpBegin) + (int)(incrementVars>0),
116  (incrementVars) ? " 0" : "");
117  }
118  }
119 
120  fprintf( pFile, "\n" );
121  fclose( pFile );
122 }
Sat_Mem_t Mem
Definition: satSolver.h:99
static int lit_var(lit l)
Definition: satVec.h:145
char * assigns
Definition: satSolver.h:130
static ABC_NAMESPACE_IMPL_START void Sat_SolverClauseWriteDimacs(FILE *pFile, clause *pC, int fIncrement)
DECLARATIONS ///.
Definition: satUtil.c:50
for(p=first;p->value< newval;p=p->next)
if(last==0)
Definition: sparse_int.h:34
static int size
Definition: cuddSign.c:86
static int lit_sign(lit l)
Definition: satVec.h:146
#define Sat_MemForEachClause(p, c, i, k)
Definition: satClause.h:117
static int Sat_MemEntryNum(Sat_Mem_t *p, int lrn)
Definition: satClause.h:99
int * levels
Definition: satSolver.h:129