ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sscSat.c File Reference
#include "sscInt.h"
#include "sat/cnf/cnf.h"
#include "aig/gia/giaAig.h"
Include dependency graph for sscSat.c:

Go to the source code of this file.

Functions

void Ssc_ManStartSolver (Ssc_Man_t *p)
 
void Ssc_ManCollectSatPattern (Ssc_Man_t *p, Vec_Int_t *vPattern)
 
Vec_Int_tSsc_ManFindPivotSat (Ssc_Man_t *p)
 
int Ssc_ManCheckEquivalence (Ssc_Man_t *p, int iRepr, int iNode, int fCompl)
 

Function Documentation

◆ Ssc_ManCheckEquivalence()

int Ssc_ManCheckEquivalence ( Ssc_Man_t * p,
int iRepr,
int iNode,
int fCompl )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 348 of file sscSat.c.

349{
350 int pLitsSat[2], RetValue;
351 abctime clk;
352 assert( iRepr != iNode );
353 if ( iRepr > iNode )
354 return l_Undef;
355 assert( iRepr < iNode );
356// if ( p->nTimeOut )
357// sat_solver_set_runtime_limit( p->pSat, p->nTimeOut * CLOCKS_PER_SEC + Abc_Clock() );
358
359 // create CNF
360 if ( iRepr )
361 Ssc_ManCnfNodeAddToSolver( p, iRepr );
362 Ssc_ManCnfNodeAddToSolver( p, iNode );
363 sat_solver_compress( p->pSat );
364
365 // order the literals
366 pLitsSat[0] = Abc_Var2Lit( Ssc_ObjSatVar(p, iRepr), 0 );
367 pLitsSat[1] = Abc_Var2Lit( Ssc_ObjSatVar(p, iNode), fCompl ^ (int)(iRepr > 0) );
368
369 // solve under assumptions
370 // A = 1; B = 0
371 clk = Abc_Clock();
372 RetValue = sat_solver_solve( p->pSat, pLitsSat, pLitsSat + 2, (ABC_INT64_T)p->pPars->nBTLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
373 if ( RetValue == l_False )
374 {
375 pLitsSat[0] = Abc_LitNot( pLitsSat[0] ); // compl
376 pLitsSat[1] = Abc_LitNot( pLitsSat[1] ); // compl
377 RetValue = sat_solver_addclause( p->pSat, pLitsSat, pLitsSat + 2 );
378 assert( RetValue );
379 p->timeSatUnsat += Abc_Clock() - clk;
380 }
381 else if ( RetValue == l_True )
382 {
383 Ssc_ManCollectSatPattern( p, p->vPattern );
384 p->timeSatSat += Abc_Clock() - clk;
385 return l_True;
386 }
387 else // if ( RetValue1 == l_Undef )
388 {
389 p->timeSatUndec += Abc_Clock() - clk;
390 return l_Undef;
391 }
392
393 // if the old node was constant 0, we already know the answer
394 if ( iRepr == 0 )
395 return l_False;
396
397 // solve under assumptions
398 // A = 0; B = 1
399 clk = Abc_Clock();
400 RetValue = sat_solver_solve( p->pSat, pLitsSat, pLitsSat + 2, (ABC_INT64_T)p->pPars->nBTLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
401 if ( RetValue == l_False )
402 {
403 pLitsSat[0] = Abc_LitNot( pLitsSat[0] );
404 pLitsSat[1] = Abc_LitNot( pLitsSat[1] );
405 RetValue = sat_solver_addclause( p->pSat, pLitsSat, pLitsSat + 2 );
406 assert( RetValue );
407 p->timeSatUnsat += Abc_Clock() - clk;
408 }
409 else if ( RetValue == l_True )
410 {
411 Ssc_ManCollectSatPattern( p, p->vPattern );
412 p->timeSatSat += Abc_Clock() - clk;
413 return l_True;
414 }
415 else // if ( RetValue1 == l_Undef )
416 {
417 p->timeSatUndec += Abc_Clock() - clk;
418 return l_Undef;
419 }
420 return l_False;
421}
ABC_INT64_T abctime
Definition abc_global.h:332
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define sat_solver_addclause
Definition cecSatG2.c:37
#define sat_solver_solve
Definition cecSatG2.c:45
Cube * p
Definition exorList.c:222
void Ssc_ManCollectSatPattern(Ssc_Man_t *p, Vec_Int_t *vPattern)
Definition sscSat.c:315
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ssc_ManCollectSatPattern()

void Ssc_ManCollectSatPattern ( Ssc_Man_t * p,
Vec_Int_t * vPattern )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 315 of file sscSat.c.

316{
317 Gia_Obj_t * pObj;
318 int i;
319 Vec_IntClear( vPattern );
320 Gia_ManForEachCi( p->pFraig, pObj, i )
321 Vec_IntPush( vPattern, sat_solver_var_value(p->pSat, Ssc_ObjSatVar(p, Gia_ObjId(p->pFraig, pObj))) );
322}
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
Here is the caller graph for this function:

◆ Ssc_ManFindPivotSat()

Vec_Int_t * Ssc_ManFindPivotSat ( Ssc_Man_t * p)

Definition at line 323 of file sscSat.c.

324{
325 Vec_Int_t * vInit;
326 int status = sat_solver_solve( p->pSat, NULL, NULL, p->pPars->nBTLimit, 0, 0, 0 );
327 if ( status == l_False )
328 return (Vec_Int_t *)(ABC_PTRINT_T)1;
329 if ( status == l_Undef )
330 return NULL;
331 assert( status == l_True );
332 vInit = Vec_IntAlloc( Gia_ManCiNum(p->pFraig) );
333 Ssc_ManCollectSatPattern( p, vInit );
334 return vInit;
335}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ssc_ManStartSolver()

void Ssc_ManStartSolver ( Ssc_Man_t * p)

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

Synopsis [Starts the SAT solver for constraints.]

Description []

SideEffects []

SeeAlso []

Definition at line 261 of file sscSat.c.

262{
263 Aig_Man_t * pMan = Gia_ManToAigSimple( p->pFraig );
264 Cnf_Dat_t * pDat = Cnf_Derive( pMan, 0 );
265 Gia_Obj_t * pObj;
266 sat_solver * pSat;
267 int i, status;
268 assert( p->pSat == NULL && p->vId2Var == NULL );
269 assert( Aig_ManObjNumMax(pMan) == Gia_ManObjNum(p->pFraig) );
270 Aig_ManStop( pMan );
271 // save variable mapping
272 p->nSatVarsPivot = p->nSatVars = pDat->nVars;
273 p->vId2Var = Vec_IntStart( Gia_ManCandNum(p->pAig) + Gia_ManCandNum(p->pCare) + 10 ); // mapping of each node into its SAT var
274 p->vVar2Id = Vec_IntStart( Gia_ManCandNum(p->pAig) + Gia_ManCandNum(p->pCare) + 10 ); // mapping of each SAT var into its node
275 Ssc_ObjSetSatVar( p, 0, pDat->pVarNums[0] );
276 Gia_ManForEachCi( p->pFraig, pObj, i )
277 {
278 int iObj = Gia_ObjId( p->pFraig, pObj );
279 Ssc_ObjSetSatVar( p, iObj, pDat->pVarNums[iObj] );
280 }
281//Cnf_DataWriteIntoFile( pDat, "dump.cnf", 1, NULL, NULL );
282 // start the SAT solver
283 pSat = sat_solver_new();
284 sat_solver_setnvars( pSat, pDat->nVars + 1000 );
285 for ( i = 0; i < pDat->nClauses; i++ )
286 {
287 if ( !sat_solver_addclause( pSat, pDat->pClauses[i], pDat->pClauses[i+1] ) )
288 {
289 Cnf_DataFree( pDat );
290 sat_solver_delete( pSat );
291 return;
292 }
293 }
294 Cnf_DataFree( pDat );
295 status = sat_solver_simplify( pSat );
296 if ( status == 0 )
297 {
298 sat_solver_delete( pSat );
299 return;
300 }
301 p->pSat = pSat;
302}
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
#define sat_solver
Definition cecSatG2.c:34
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition cnfCore.c:165
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
Definition giaAig.c:408
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int nVars
Definition cnf.h:59
int * pVarNums
Definition cnf.h:63
int ** pClauses
Definition cnf.h:62
int nClauses
Definition cnf.h:61
Here is the call graph for this function:
Here is the caller graph for this function: