src/sat/bsat/satSolver.h File Reference

#include "satVec.h"
#include "satMem.h"
Include dependency graph for satSolver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  stats_t
struct  sat_solver_t

Typedefs

typedef int lit
typedef char lbool
typedef long long sint64
typedef struct sat_solver_t sat_solver
typedef struct stats_t stats
typedef struct clause_t clause

Functions

static lit toLit (int v)
static lit toLitCond (int v, int c)
static lit lit_neg (lit l)
static int lit_var (lit l)
static int lit_sign (lit l)
static int lit_print (lit l)
static lit lit_read (int s)
sat_solversat_solver_new (void)
void sat_solver_delete (sat_solver *s)
bool sat_solver_addclause (sat_solver *s, lit *begin, lit *end)
bool sat_solver_simplify (sat_solver *s)
int sat_solver_solve (sat_solver *s, lit *begin, lit *end, sint64 nConfLimit, sint64 nInsLimit, sint64 nConfLimitGlobal, sint64 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_setnvars (sat_solver *s, int n)
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)
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)

Variables

static const bool true = 1
static const bool false = 0
static const int var_Undef = -1
static const lit lit_Undef = -2
static const lbool l_Undef = 0
static const lbool l_True = 1
static const lbool l_False = -1

Typedef Documentation

typedef struct clause_t clause

Definition at line 124 of file satSolver.h.

typedef char lbool

Definition at line 47 of file satSolver.h.

typedef int lit

Definition at line 46 of file satSolver.h.

typedef struct sat_solver_t sat_solver

Definition at line 80 of file satSolver.h.

typedef long long sint64

Definition at line 55 of file satSolver.h.

typedef struct stats_t stats

Definition at line 100 of file satSolver.h.


Function Documentation

static lit lit_neg ( lit  l  )  [inline, static]

Definition at line 69 of file satSolver.h.

00069 { return l ^ 1; }

static int lit_print ( lit  l  )  [inline, static]

Definition at line 72 of file satSolver.h.

00072 { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }

static lit lit_read ( int  s  )  [inline, static]

Definition at line 73 of file satSolver.h.

00073 { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }

static int lit_sign ( lit  l  )  [inline, static]

Definition at line 71 of file satSolver.h.

00071 { return l & 1; }

static int lit_var ( lit  l  )  [inline, static]

Definition at line 70 of file satSolver.h.

00070 { return l >> 1; }

bool sat_solver_addclause ( sat_solver s,
lit begin,
lit end 
)

Definition at line 1048 of file satSolver.c.

01049 {
01050     lit *i,*j;
01051     int maxvar;
01052     lbool* values;
01053     lit last;
01054 
01055     if (begin == end) return false;
01056 
01057     //printlits(begin,end); printf("\n");
01058     // insertion sort
01059     maxvar = lit_var(*begin);
01060     for (i = begin + 1; i < end; i++){
01061         lit l = *i;
01062         maxvar = lit_var(l) > maxvar ? lit_var(l) : maxvar;
01063         for (j = i; j > begin && *(j-1) > l; j--)
01064             *j = *(j-1);
01065         *j = l;
01066     }
01067     sat_solver_setnvars(s,maxvar+1);
01068 //    sat_solver_setnvars(s, lit_var(*(end-1))+1 );
01069 
01070     //printlits(begin,end); printf("\n");
01071     values = s->assigns;
01072 
01073     // delete duplicates
01074     last = lit_Undef;
01075     for (i = j = begin; i < end; i++){
01076         //printf("lit: "L_LIT", value = %d\n", L_lit(*i), (lit_sign(*i) ? -values[lit_var(*i)] : values[lit_var(*i)]));
01077         lbool sig = !lit_sign(*i); sig += sig - 1;
01078         if (*i == lit_neg(last) || sig == values[lit_var(*i)])
01079             return true;   // tautology
01080         else if (*i != last && values[lit_var(*i)] == l_Undef)
01081             last = *j++ = *i;
01082     }
01083 
01084     //printf("final: "); printlits(begin,j); printf("\n");
01085 
01086     if (j == begin)          // empty clause
01087         return false;
01088 
01090     // add clause to internal storage
01091     if ( s->pStore )
01092     {
01093         extern int Sto_ManAddClause( void * p, lit * pBeg, lit * pEnd );
01094         int RetValue = Sto_ManAddClause( s->pStore, begin, j );
01095         assert( RetValue );
01096     }
01098 
01099     if (j - begin == 1) // unit clause
01100         return enqueue(s,*begin,(clause*)0);
01101 
01102     // create new clause
01103     vecp_push(&s->clauses,clause_new(s,begin,j,0));
01104 
01105 
01106     s->stats.clauses++;
01107     s->stats.clauses_literals += j - begin;
01108 
01109     return true;
01110 }

void sat_solver_delete ( sat_solver s  ) 

Definition at line 1001 of file satSolver.c.

01002 {
01003 
01004 #ifdef SAT_USE_SYSTEM_MEMORY_MANAGEMENT
01005     int i;
01006     for (i = 0; i < vecp_size(&s->clauses); i++)
01007         free(vecp_begin(&s->clauses)[i]);
01008     for (i = 0; i < vecp_size(&s->learnts); i++)
01009         free(vecp_begin(&s->learnts)[i]);
01010 #else
01011     Sat_MmStepStop( s->pMem, 0 );
01012 #endif
01013 
01014     // delete vectors
01015     vecp_delete(&s->clauses);
01016     vecp_delete(&s->learnts);
01017     veci_delete(&s->order);
01018     veci_delete(&s->trail_lim);
01019     veci_delete(&s->tagged);
01020     veci_delete(&s->stack);
01021     veci_delete(&s->model);
01022     veci_delete(&s->act_vars);
01023     free(s->binary);
01024 
01025     // delete arrays
01026     if (s->wlists != 0){
01027         int i;
01028         for (i = 0; i < s->size*2; i++)
01029             vecp_delete(&s->wlists[i]);
01030 
01031         // if one is different from null, all are
01032         free(s->wlists   );
01033         free(s->activity );
01034         free(s->factors  );
01035         free(s->assigns  );
01036         free(s->orderpos );
01037         free(s->reasons  );
01038         free(s->levels   );
01039         free(s->trail    );
01040         free(s->tags     );
01041     }
01042 
01043     sat_solver_store_free(s);
01044     free(s);
01045 }

int sat_solver_nclauses ( sat_solver s  ) 

Definition at line 1254 of file satSolver.c.

01255 {
01256     return vecp_size(&s->clauses);
01257 }

int sat_solver_nconflicts ( sat_solver s  ) 

Definition at line 1260 of file satSolver.c.

01261 {
01262     return (int)s->stats.conflicts;
01263 }

sat_solver* sat_solver_new ( void   ) 

Definition at line 935 of file satSolver.c.

00936 {
00937     sat_solver* s = (sat_solver*)malloc(sizeof(sat_solver));
00938     memset( s, 0, sizeof(sat_solver) );
00939 
00940     // initialize vectors
00941     vecp_new(&s->clauses);
00942     vecp_new(&s->learnts);
00943     veci_new(&s->order);
00944     veci_new(&s->trail_lim);
00945     veci_new(&s->tagged);
00946     veci_new(&s->stack);
00947     veci_new(&s->model);
00948     veci_new(&s->act_vars);
00949 
00950     // initialize arrays
00951     s->wlists    = 0;
00952     s->activity  = 0;
00953     s->factors   = 0;
00954     s->assigns   = 0;
00955     s->orderpos  = 0;
00956     s->reasons   = 0;
00957     s->levels    = 0;
00958     s->tags      = 0;
00959     s->trail     = 0;
00960 
00961 
00962     // initialize other vars
00963     s->size                   = 0;
00964     s->cap                    = 0;
00965     s->qhead                  = 0;
00966     s->qtail                  = 0;
00967     s->cla_inc                = 1;
00968     s->cla_decay              = 1;
00969     s->var_inc                = 1;
00970     s->var_decay              = 1;
00971     s->root_level             = 0;
00972     s->simpdb_assigns         = 0;
00973     s->simpdb_props           = 0;
00974     s->random_seed            = 91648253;
00975     s->progress_estimate      = 0;
00976     s->binary                 = (clause*)malloc(sizeof(clause) + sizeof(lit)*2);
00977     s->binary->size_learnt    = (2 << 1);
00978     s->verbosity              = 0;
00979 
00980     s->stats.starts           = 0;
00981     s->stats.decisions        = 0;
00982     s->stats.propagations     = 0;
00983     s->stats.inspects         = 0;
00984     s->stats.conflicts        = 0;
00985     s->stats.clauses          = 0;
00986     s->stats.clauses_literals = 0;
00987     s->stats.learnts          = 0;
00988     s->stats.learnts_literals = 0;
00989     s->stats.max_literals     = 0;
00990     s->stats.tot_literals     = 0;
00991 
00992 #ifdef SAT_USE_SYSTEM_MEMORY_MANAGEMENT
00993     s->pMem = NULL;
00994 #else
00995     s->pMem = Sat_MmStepStart( 10 );
00996 #endif
00997     return s;
00998 }

int sat_solver_nvars ( sat_solver s  ) 

Definition at line 1248 of file satSolver.c.

01249 {
01250     return s->size;
01251 }

void sat_solver_setnvars ( sat_solver s,
int  n 
)

Definition at line 362 of file satSolver.c.

00363 {
00364     int var;
00365 
00366     if (s->cap < n){
00367 
00368         while (s->cap < n) s->cap = s->cap*2+1;
00369 
00370         s->wlists    = (vecp*)   realloc(s->wlists,   sizeof(vecp)*s->cap*2);
00371         s->activity  = (double*) realloc(s->activity, sizeof(double)*s->cap);
00372         s->factors   = (double*) realloc(s->factors,  sizeof(double)*s->cap);
00373         s->assigns   = (lbool*)  realloc(s->assigns,  sizeof(lbool)*s->cap);
00374         s->orderpos  = (int*)    realloc(s->orderpos, sizeof(int)*s->cap);
00375         s->reasons   = (clause**)realloc(s->reasons,  sizeof(clause*)*s->cap);
00376         s->levels    = (int*)    realloc(s->levels,   sizeof(int)*s->cap);
00377         s->tags      = (lbool*)  realloc(s->tags,     sizeof(lbool)*s->cap);
00378         s->trail     = (lit*)    realloc(s->trail,    sizeof(lit)*s->cap);
00379     }
00380 
00381     for (var = s->size; var < n; var++){
00382         vecp_new(&s->wlists[2*var]);
00383         vecp_new(&s->wlists[2*var+1]);
00384         s->activity [var] = 0;
00385         s->factors  [var] = 0;
00386         s->assigns  [var] = l_Undef;
00387         s->orderpos [var] = veci_size(&s->order);
00388         s->reasons  [var] = (clause*)0;
00389         s->levels   [var] = 0;
00390         s->tags     [var] = l_Undef;
00391         
00392         /* does not hold because variables enqueued at top level will not be reinserted in the heap
00393            assert(veci_size(&s->order) == var); 
00394          */
00395         veci_push(&s->order,var);
00396         order_update(s, var);
00397     }
00398 
00399     s->size = n > s->size ? n : s->size;
00400 }

bool sat_solver_simplify ( sat_solver s  ) 

Definition at line 1113 of file satSolver.c.

01114 {
01115     clause** reasons;
01116     int type;
01117 
01118     assert(sat_solver_dlevel(s) == 0);
01119 
01120     if (sat_solver_propagate(s) != 0)
01121         return false;
01122 
01123     if (s->qhead == s->simpdb_assigns || s->simpdb_props > 0)
01124         return true;
01125 
01126     reasons = s->reasons;
01127     for (type = 0; type < 2; type++){
01128         vecp*    cs  = type ? &s->learnts : &s->clauses;
01129         clause** cls = (clause**)vecp_begin(cs);
01130 
01131         int i, j;
01132         for (j = i = 0; i < vecp_size(cs); i++){
01133             if (reasons[lit_var(*clause_begin(cls[i]))] != cls[i] &&
01134                 clause_simplify(s,cls[i]) == l_True)
01135                 clause_remove(s,cls[i]);
01136             else
01137                 cls[j++] = cls[i];
01138         }
01139         vecp_resize(cs,j);
01140     }
01141 
01142     s->simpdb_assigns = s->qhead;
01143     // (shouldn't depend on 'stats' really, but it will do for now)
01144     s->simpdb_props   = (int)(s->stats.clauses_literals + s->stats.learnts_literals);
01145 
01146     return true;
01147 }

int sat_solver_solve ( sat_solver s,
lit begin,
lit end,
sint64  nConfLimit,
sint64  nInsLimit,
sint64  nConfLimitGlobal,
sint64  nInsLimitGlobal 
)

Definition at line 1150 of file satSolver.c.

01151 {
01152     sint64  nof_conflicts = 100;
01153     sint64  nof_learnts   = sat_solver_nclauses(s) / 3;
01154     lbool   status        = l_Undef;
01155     lbool*  values        = s->assigns;
01156     lit*    i;
01157 
01158     // set the external limits
01159     s->nCalls++;
01160     s->nRestarts  = 0;
01161     s->nConfLimit = 0;
01162     s->nInsLimit  = 0;
01163     if ( nConfLimit )
01164         s->nConfLimit = s->stats.conflicts + nConfLimit;
01165     if ( nInsLimit )
01166         s->nInsLimit = s->stats.inspects + nInsLimit;
01167     if ( nConfLimitGlobal && (s->nConfLimit == 0 || s->nConfLimit > nConfLimitGlobal) )
01168         s->nConfLimit = nConfLimitGlobal;
01169     if ( nInsLimitGlobal && (s->nInsLimit == 0 || s->nInsLimit > nInsLimitGlobal) )
01170         s->nInsLimit = nInsLimitGlobal;
01171 
01172     //printf("solve: "); printlits(begin, end); printf("\n");
01173     for (i = begin; i < end; i++){
01174         switch (lit_sign(*i) ? -values[lit_var(*i)] : values[lit_var(*i)]){
01175         case 1: /* l_True: */
01176             break;
01177         case 0: /* l_Undef */
01178             assume(s, *i);
01179             if (sat_solver_propagate(s) == NULL)
01180                 break;
01181             // fallthrough
01182         case -1: /* l_False */
01183             sat_solver_canceluntil(s, 0);
01184             return l_False;
01185         }
01186     }
01187     s->nCalls2++;
01188 
01189     s->root_level = sat_solver_dlevel(s);
01190 
01191     if (s->verbosity >= 1){
01192         printf("==================================[MINISAT]===================================\n");
01193         printf("| Conflicts |     ORIGINAL     |              LEARNT              | Progress |\n");
01194         printf("|           | Clauses Literals |   Limit Clauses Literals  Lit/Cl |          |\n");
01195         printf("==============================================================================\n");
01196     }
01197 
01198     while (status == l_Undef){
01199         double Ratio = (s->stats.learnts == 0)? 0.0 :
01200             s->stats.learnts_literals / (double)s->stats.learnts;
01201 
01202         if (s->verbosity >= 1)
01203         {
01204             printf("| %9.0f | %7.0f %8.0f | %7.0f %7.0f %8.0f %7.1f | %6.3f %% |\n", 
01205                 (double)s->stats.conflicts,
01206                 (double)s->stats.clauses, 
01207                 (double)s->stats.clauses_literals,
01208                 (double)nof_learnts, 
01209                 (double)s->stats.learnts, 
01210                 (double)s->stats.learnts_literals,
01211                 Ratio,
01212                 s->progress_estimate*100);
01213             fflush(stdout);
01214         }
01215         status = sat_solver_search(s, nof_conflicts, nof_learnts);
01216         nof_conflicts = nof_conflicts * 3 / 2; //*= 1.5;
01217         nof_learnts   = nof_learnts * 11 / 10; //*= 1.1;
01218 
01219         // quit the loop if reached an external limit
01220         if ( s->nConfLimit && s->stats.conflicts > s->nConfLimit )
01221         {
01222 //            printf( "Reached the limit on the number of conflicts (%d).\n", s->nConfLimit );
01223             break;
01224         }
01225         if ( s->nInsLimit  && s->stats.inspects > s->nInsLimit )
01226         {
01227 //            printf( "Reached the limit on the number of implications (%d).\n", s->nInsLimit );
01228             break;
01229         }
01230     }
01231     if (s->verbosity >= 1)
01232         printf("==============================================================================\n");
01233 
01234     sat_solver_canceluntil(s,0);
01235 
01237     if ( status == l_False && s->pStore )
01238     {
01239         extern int Sto_ManAddClause( void * p, lit * pBeg, lit * pEnd );
01240         int RetValue = Sto_ManAddClause( s->pStore, NULL, NULL );
01241         assert( RetValue );
01242     }
01244     return status;
01245 }

void sat_solver_store_alloc ( sat_solver s  ) 

Definition at line 1268 of file satSolver.c.

01269 {
01270     extern void * Sto_ManAlloc();
01271     assert( s->pStore == NULL );
01272     s->pStore = Sto_ManAlloc();
01273 }

void sat_solver_store_free ( sat_solver s  ) 

Definition at line 1281 of file satSolver.c.

01282 {
01283     extern void Sto_ManFree( void * p );
01284     if ( s->pStore ) Sto_ManFree( s->pStore );
01285     s->pStore = NULL;
01286 }

void sat_solver_store_mark_clauses_a ( sat_solver s  ) 

Definition at line 1294 of file satSolver.c.

01295 {
01296     extern void Sto_ManMarkClausesA( void * p );
01297     if ( s->pStore ) Sto_ManMarkClausesA( s->pStore );
01298 }

void sat_solver_store_mark_roots ( sat_solver s  ) 

Definition at line 1288 of file satSolver.c.

01289 {
01290     extern void Sto_ManMarkRoots( void * p );
01291     if ( s->pStore ) Sto_ManMarkRoots( s->pStore );
01292 }

void* sat_solver_store_release ( sat_solver s  ) 

Definition at line 1300 of file satSolver.c.

01301 {
01302     void * pTemp;
01303     if ( s->pStore == NULL )
01304         return NULL;
01305     pTemp = s->pStore;
01306     s->pStore = NULL;
01307     return pTemp;
01308 }

void sat_solver_store_write ( sat_solver s,
char *  pFileName 
)

Definition at line 1275 of file satSolver.c.

01276 {
01277     extern void Sto_ManDumpClauses( void * p, char * pFileName );
01278     if ( s->pStore ) Sto_ManDumpClauses( s->pStore, pFileName );
01279 }

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 193 of file satUtil.c.

00194 {
00195     clause * pClause;
00196     lit Lit, * pLits;
00197     int RetValue, nClauses, nVarsOld, nLitsOld, nLits, c, v;
00198     // get the number of variables
00199     nVarsOld = p->size;
00200     nLitsOld = 2 * p->size;
00201     // extend the solver to depend on two sets of variables
00202     sat_solver_setnvars( p, 2 * p->size );
00203     // duplicate implications
00204     for ( v = 0; v < nVarsOld; v++ )
00205         if ( p->assigns[v] != l_Undef )
00206         {
00207             Lit = nLitsOld + toLitCond( v, p->assigns[v]==l_False );
00208             if ( v == iVar )
00209                 Lit = lit_neg(Lit);
00210             RetValue = sat_solver_addclause( p, &Lit, &Lit + 1 );
00211             assert( RetValue );
00212         }
00213     // duplicate clauses
00214     nClauses = vecp_size(&p->clauses);
00215     for ( c = 0; c < nClauses; c++ )
00216     {
00217         pClause = p->clauses.ptr[c];
00218         nLits = clause_size(pClause);
00219         pLits = clause_begin(pClause);
00220         for ( v = 0; v < nLits; v++ )
00221             pLits[v] += nLitsOld;
00222         RetValue = sat_solver_addclause( p, pLits, pLits + nLits );
00223         assert( RetValue );
00224         for ( v = 0; v < nLits; v++ )
00225             pLits[v] -= nLitsOld;
00226     }
00227 }

int* Sat_SolverGetModel ( sat_solver p,
int *  pVars,
int  nVars 
)

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

Synopsis [Returns a counter-example.]

Description []

SideEffects []

SeeAlso []

Definition at line 169 of file satUtil.c.

00170 {
00171     int * pModel;
00172     int i;
00173     pModel = ALLOC( int, nVars );
00174     for ( i = 0; i < nVars; i++ )
00175     {
00176         assert( pVars[i] >= 0 && pVars[i] < p->size );
00177         pModel[i] = (int)(p->model.ptr[pVars[i]] == l_True);
00178     }
00179     return pModel;    
00180 }

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 147 of file satUtil.c.

00148 {
00149 //    printf( "calls         : %8d (%d)\n", (int)p->nCalls, (int)p->nCalls2 );
00150     printf( "starts        : %8d\n", (int)p->stats.starts );
00151     printf( "conflicts     : %8d\n", (int)p->stats.conflicts );
00152     printf( "decisions     : %8d\n", (int)p->stats.decisions );
00153     printf( "propagations  : %8d\n", (int)p->stats.propagations );
00154     printf( "inspects      : %8d\n", (int)p->stats.inspects );
00155 //    printf( "inspects2     : %8d\n", (int)p->stats.inspects2 );
00156 }

void Sat_SolverTraceStart ( sat_solver pSat,
char *  pName 
)

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

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

Synopsis [Start the trace recording.]

Description []

SideEffects []

SeeAlso []

Definition at line 52 of file satTrace.c.

00053 {
00054     assert( pSat->pFile == NULL );
00055     pSat->pFile = fopen( pName, "w" );
00056     fprintf( pSat->pFile, "                                        \n" );
00057     pSat->nClauses = 0;
00058     pSat->nRoots = 0;
00059 }   

void Sat_SolverTraceStop ( sat_solver pSat  ) 

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

Synopsis [Stops the trace recording.]

Description []

SideEffects []

SeeAlso []

Definition at line 72 of file satTrace.c.

00073 {
00074     if ( pSat->pFile == NULL )
00075         return;
00076     rewind( pSat->pFile );
00077     fprintf( pSat->pFile, "p %d %d %d", sat_solver_nvars(pSat), pSat->nClauses, pSat->nRoots );
00078     fclose( pSat->pFile );
00079     pSat->pFile = NULL;
00080 }

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 94 of file satTrace.c.

00095 {
00096     if ( pSat->pFile == NULL )
00097         return;
00098     pSat->nClauses++;
00099     pSat->nRoots += fRoot;
00100     for ( ; pBeg < pEnd ; pBeg++ )
00101         fprintf( pSat->pFile, " %d", lit_print(*pBeg) );
00102     fprintf( pSat->pFile, " 0\n" );
00103 }

void Sat_SolverWriteDimacs ( sat_solver p,
char *  pFileName,
lit assumptionsBegin,
lit assumptionsEnd,
int  incrementVars 
)

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 56 of file satUtil.c.

00057 {
00058     FILE * pFile;
00059     void ** pClauses;
00060     int nClauses, i;
00061 
00062     // count the number of clauses
00063     nClauses = p->clauses.size + p->learnts.size;
00064     for ( i = 0; i < p->size; i++ )
00065         if ( p->levels[i] == 0 && p->assigns[i] != l_Undef )
00066             nClauses++;
00067 
00068     // start the file
00069     pFile = fopen( pFileName, "wb" );
00070     if ( pFile == NULL )
00071     {
00072         printf( "Sat_SolverWriteDimacs(): Cannot open the ouput file.\n" );
00073         return;
00074     }
00075     fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
00076     fprintf( pFile, "p cnf %d %d\n", p->size, nClauses );
00077 
00078     // write the original clauses
00079     nClauses = p->clauses.size;
00080     pClauses = p->clauses.ptr;
00081     for ( i = 0; i < nClauses; i++ )
00082         Sat_SolverClauseWriteDimacs( pFile, pClauses[i], incrementVars );
00083 
00084     // write the learned clauses
00085     nClauses = p->learnts.size;
00086     pClauses = p->learnts.ptr;
00087     for ( i = 0; i < nClauses; i++ )
00088         Sat_SolverClauseWriteDimacs( pFile, pClauses[i], incrementVars );
00089 
00090     // write zero-level assertions
00091     for ( i = 0; i < p->size; i++ )
00092         if ( p->levels[i] == 0 && p->assigns[i] != l_Undef )
00093             fprintf( pFile, "%s%d%s\n",
00094                      (p->assigns[i] == l_False)? "-": "",
00095                      i + (int)(incrementVars>0),
00096                      (incrementVars) ? " 0" : "");
00097 
00098     // write the assumptions
00099     if (assumptionsBegin) {
00100         for (; assumptionsBegin != assumptionsEnd; assumptionsBegin++) {
00101             fprintf( pFile, "%s%d%s\n",
00102                      lit_sign(*assumptionsBegin)? "-": "",
00103                      lit_var(*assumptionsBegin) + (int)(incrementVars>0),
00104                      (incrementVars) ? " 0" : "");
00105         }
00106     }
00107 
00108     fprintf( pFile, "\n" );
00109     fclose( pFile );
00110 }   

static lit toLit ( int  v  )  [inline, static]

Definition at line 67 of file satSolver.h.

00067 { return v + v; }

static lit toLitCond ( int  v,
int  c 
) [inline, static]

Definition at line 68 of file satSolver.h.

00068 { return v + v + (c != 0); }


Variable Documentation

const bool false = 0 [static]

Definition at line 44 of file satSolver.h.

const lbool l_False = -1 [static]

Definition at line 65 of file satSolver.h.

const lbool l_True = 1 [static]

Definition at line 64 of file satSolver.h.

const lbool l_Undef = 0 [static]

Definition at line 63 of file satSolver.h.

const lit lit_Undef = -2 [static]

Definition at line 61 of file satSolver.h.

const bool true = 1 [static]

Definition at line 43 of file satSolver.h.

const int var_Undef = -1 [static]

Definition at line 60 of file satSolver.h.


Generated on Tue Jan 5 12:19:37 2010 for abc70930 by  doxygen 1.6.1