src/sat/bsat/satUtil.c File Reference

#include <stdio.h>
#include <assert.h>
#include "satSolver.h"
#include "extra.h"
Include dependency graph for satUtil.c:

Go to the source code of this file.

Data Structures

struct  clause_t

Functions

static int clause_size (clause *c)
static litclause_begin (clause *c)
static void Sat_SolverClauseWriteDimacs (FILE *pFile, clause *pC, bool fIncrement)
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)

Function Documentation

static lit* clause_begin ( clause c  )  [inline, static]

Definition at line 37 of file satUtil.c.

00037 { return c->lits;             }

static int clause_size ( clause c  )  [inline, static]

Definition at line 36 of file satUtil.c.

00036 { return c->size_learnt >> 1; }

void Sat_SolverClauseWriteDimacs ( FILE *  pFile,
clause pC,
bool  fIncrement 
) [static]

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 123 of file satUtil.c.

00124 {
00125     lit * pLits = clause_begin(pC);
00126     int nLits = clause_size(pC);
00127     int i;
00128 
00129     for ( i = 0; i < nLits; i++ )
00130         fprintf( pFile, "%s%d ", (lit_sign(pLits[i])? "-": ""),  lit_var(pLits[i]) + (int)(fIncrement>0) );
00131     if ( fIncrement )
00132         fprintf( pFile, "0" );
00133     fprintf( pFile, "\n" );
00134 }

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_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 }   


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