ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
satUtil.c File Reference
#include <stdio.h>
#include <assert.h>
#include "satSolver.h"
#include "satSolver2.h"
Include dependency graph for satUtil.c:

Go to the source code of this file.

Functions

void Sat_SolverWriteDimacs (sat_solver *p, char *pFileName, lit *assumpBegin, lit *assumpEnd, int incrementVars)
 
void Sat_Solver2WriteDimacs (sat_solver2 *p, char *pFileName, lit *assumpBegin, lit *assumpEnd, int incrementVars)
 
void Sat_SolverPrintStats (FILE *pFile, sat_solver *p)
 
void Sat_Solver2PrintStats (FILE *pFile, sat_solver2 *s)
 
int Sat_Solver2GetVarMem (sat_solver2 *s)
 
int * Sat_SolverGetModel (sat_solver *p, int *pVars, int nVars)
 
int * Sat_Solver2GetModel (sat_solver2 *p, int *pVars, int nVars)
 
void Sat_SolverDoubleClauses (sat_solver *p, int iVar)
 

Function Documentation

◆ Sat_Solver2GetModel()

int * Sat_Solver2GetModel ( sat_solver2 * p,
int * pVars,
int nVars )

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

Synopsis [Returns a counter-example.]

Description []

SideEffects []

SeeAlso []

Definition at line 291 of file satUtil.c.

292{
293 int * pModel;
294 int i;
295 pModel = ABC_CALLOC( int, nVars+1 );
296 for ( i = 0; i < nVars; i++ )
297 pModel[i] = sat_solver2_var_value(p, pVars[i]);
298 return pModel;
299}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
Cube * p
Definition exorList.c:222
Here is the caller graph for this function:

◆ Sat_Solver2GetVarMem()

int Sat_Solver2GetVarMem ( sat_solver2 * s)

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

Synopsis [Returns the number of bytes used for each variable.]

Description []

SideEffects []

SeeAlso []

Definition at line 244 of file satUtil.c.

245{
246 int Mem = 0;
247 Mem += (sizeof(s->activity[0]) == 4) ? sizeof(unsigned) : sizeof(double); // activity
248 Mem += 2 * sizeof(veci); // wlists
249 Mem += sizeof(int); // vi (variable info)
250 Mem += sizeof(int); // trail
251 Mem += sizeof(int); // orderpos
252 Mem += sizeof(int); // reasons
253 Mem += sizeof(int); // units
254 Mem += sizeof(int); // order
255 Mem += sizeof(int); // model
256 return Mem;
257}
struct veci_t veci
Definition satVec.h:36
unsigned * activity
Definition satSolver2.h:112

◆ Sat_Solver2PrintStats()

void Sat_Solver2PrintStats ( FILE * pFile,
sat_solver2 * s )

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 214 of file satUtil.c.

215{
216 printf( "starts : %10d\n", (int)s->stats.starts );
217 printf( "conflicts : %10d\n", (int)s->stats.conflicts );
218 printf( "decisions : %10d\n", (int)s->stats.decisions );
219 printf( "propagations : %10d\n", (int)s->stats.propagations );
220// printf( "inspects : %10d\n", (int)s->stats.inspects );
221// printf( "inspects2 : %10d\n", (int)s->stats.inspects2 );
222/*
223 printf( "memory for variables %.1f MB (free %6.2f %%) and clauses %.1f MB (free %6.2f %%)\n",
224 1.0 * Sat_Solver2GetVarMem(s) * s->size / (1<<20),
225 100.0 * (s->cap - s->size) / s->cap,
226 4.0 * (s->clauses.cap + s->learnts.cap) / (1<<20),
227 100.0 * (s->clauses.cap - s->clauses.size +
228 s->learnts.cap - s->learnts.size) /
229 (s->clauses.cap + s->learnts.cap) );
230*/
231}
stats_t stats
Definition satSolver2.h:172
ABC_INT64_T decisions
Definition satVec.h:156
ABC_INT64_T conflicts
Definition satVec.h:156
unsigned starts
Definition satVec.h:155
ABC_INT64_T propagations
Definition satVec.h:156
Here is the caller graph for this function:

◆ Sat_Solver2WriteDimacs()

void Sat_Solver2WriteDimacs ( sat_solver2 * p,
char * pFileName,
lit * assumpBegin,
lit * assumpEnd,
int incrementVars )

Definition at line 126 of file satUtil.c.

127{
128 Sat_Mem_t * pMem = &p->Mem;
129 FILE * pFile;
130 clause * c;
131 int i, k, nUnits;
132
133 // count the number of unit clauses
134 nUnits = 0;
135 for ( i = 0; i < p->size; i++ )
136 if ( p->levels[i] == 0 && p->assigns[i] != 3 )
137 nUnits++;
138
139 // start the file
140 pFile = fopen( pFileName, "wb" );
141 if ( pFile == NULL )
142 {
143 printf( "Sat_SolverWriteDimacs(): Cannot open the ouput file.\n" );
144 return;
145 }
146// fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
147 fprintf( pFile, "p cnf %d %d\n", p->size, Sat_MemEntryNum(&p->Mem, 0)-1+Sat_MemEntryNum(&p->Mem, 1)+nUnits+(int)(assumpEnd-assumpBegin) );
148
149 // write the original clauses
150 Sat_MemForEachClause2( pMem, c, i, k )
151 Sat_SolverClauseWriteDimacs( pFile, c, incrementVars );
152
153 // write the learned clauses
154// Sat_MemForEachLearned( pMem, c, i, k )
155// Sat_SolverClauseWriteDimacs( pFile, c, incrementVars );
156
157 // write zero-level assertions
158 for ( i = 0; i < p->size; i++ )
159 if ( p->levels[i] == 0 && p->assigns[i] != 3 ) // varX
160 fprintf( pFile, "%s%d%s\n",
161 (p->assigns[i] == 1)? "-": "", // var0
162 i + (int)(incrementVars>0),
163 (incrementVars) ? " 0" : "");
164
165 // write the assump
166 if (assumpBegin) {
167 for (; assumpBegin != assumpEnd; assumpBegin++) {
168 fprintf( pFile, "%s%d%s\n",
169 lit_sign(*assumpBegin)? "-": "",
170 lit_var(*assumpBegin) + (int)(incrementVars>0),
171 (incrementVars) ? " 0" : "");
172 }
173 }
174
175 fprintf( pFile, "\n" );
176 fclose( pFile );
177}
#define Sat_MemForEachClause2(p, c, i, k)
Definition satClause.h:123
struct Sat_Mem_t_ Sat_Mem_t
Definition satClause.h:70

◆ Sat_SolverDoubleClauses()

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

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

◆ Sat_SolverGetModel()

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

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

Synopsis [Returns a counter-example.]

Description []

SideEffects []

SeeAlso []

Definition at line 270 of file satUtil.c.

271{
272 int * pModel;
273 int i;
274 pModel = ABC_CALLOC( int, nVars+1 );
275 for ( i = 0; i < nVars; i++ )
276 pModel[i] = sat_solver_var_value(p, pVars[i]);
277 return pModel;
278}
Here is the caller graph for this function:

◆ Sat_SolverPrintStats()

void Sat_SolverPrintStats ( FILE * pFile,
sat_solver * p )

Definition at line 193 of file satUtil.c.

194{
195 printf( "starts : %16.0f\n", Sat_Wrd2Dbl(p->stats.starts) );
196 printf( "conflicts : %16.0f\n", Sat_Wrd2Dbl(p->stats.conflicts) );
197 printf( "decisions : %16.0f\n", Sat_Wrd2Dbl(p->stats.decisions) );
198 printf( "propagations : %16.0f\n", Sat_Wrd2Dbl(p->stats.propagations) );
199// printf( "inspects : %10d\n", (int)p->stats.inspects );
200// printf( "inspects2 : %10d\n", (int)p->stats.inspects2 );
201}
Here is the caller graph for this function:

◆ Sat_SolverWriteDimacs()

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 [This procedure by default does not print binary clauses. To enable printing of binary clauses, please set fUseBinaryClauses to 0 in the body of procedure sat_solver_clause_new(sat_solver* s, lit* begin, lit* end, int learnt) in file "satSolver.c".]

SideEffects []

SeeAlso []

Definition at line 74 of file satUtil.c.

75{
76 Sat_Mem_t * pMem = &p->Mem;
77 FILE * pFile;
78 clause * c;
79 int i, k, nUnits;
80
81 // count the number of unit clauses
82 nUnits = 0;
83 for ( i = 0; i < p->size; i++ )
84 if ( p->levels[i] == 0 && p->assigns[i] != 3 )
85 nUnits++;
86
87 // start the file
88 pFile = pFileName ? fopen( pFileName, "wb" ) : stdout;
89 if ( pFile == NULL )
90 {
91 printf( "Sat_SolverWriteDimacs(): Cannot open the ouput file.\n" );
92 return;
93 }
94// fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
95 fprintf( pFile, "p cnf %d %d\n", p->size, Sat_MemEntryNum(&p->Mem, 0)-1+Sat_MemEntryNum(&p->Mem, 1)+nUnits+(int)(assumpEnd-assumpBegin) );
96
97 // write the original clauses
98 Sat_MemForEachClause( pMem, c, i, k )
99 Sat_SolverClauseWriteDimacs( pFile, c, incrementVars );
100
101 // write the learned clauses
102// Sat_MemForEachLearned( pMem, c, i, k )
103// Sat_SolverClauseWriteDimacs( pFile, c, incrementVars );
104
105 // write zero-level assertions
106 for ( i = 0; i < p->size; i++ )
107 if ( p->levels[i] == 0 && p->assigns[i] != 3 ) // varX
108 fprintf( pFile, "%s%d%s\n",
109 (p->assigns[i] == 1)? "-": "", // var0
110 i + (int)(incrementVars>0),
111 (incrementVars) ? " 0" : "");
112
113 // write the assump
114 if (assumpBegin) {
115 for (; assumpBegin != assumpEnd; assumpBegin++) {
116 fprintf( pFile, "%s%d%s\n",
117 lit_sign(*assumpBegin)? "-": "",
118 lit_var(*assumpBegin) + (int)(incrementVars>0),
119 (incrementVars) ? " 0" : "");
120 }
121 }
122
123 fprintf( pFile, "\n" );
124 if ( pFileName ) fclose( pFile );
125}
#define Sat_MemForEachClause(p, c, i, k)
Definition satClause.h:118
Here is the caller graph for this function: