ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
intCtrex.c
Go to the documentation of this file.
1
20
21#include "intInt.h"
22#include "proof/ssw/ssw.h"
23
25
26
30
34
46Aig_Man_t * Inter_ManFramesBmc( Aig_Man_t * pAig, int nFrames )
47{
48 Aig_Man_t * pFrames;
49 Aig_Obj_t * pObj, * pObjLi, * pObjLo;
50 int i, f;
51 assert( Saig_ManRegNum(pAig) > 0 );
52 assert( Saig_ManPoNum(pAig) == 1 );
53 pFrames = Aig_ManStart( Aig_ManNodeNum(pAig) * nFrames );
54 // map the constant node
55 Aig_ManConst1(pAig)->pData = Aig_ManConst1( pFrames );
56 // create variables for register outputs
57 Saig_ManForEachLo( pAig, pObj, i )
58 pObj->pData = Aig_ManConst0( pFrames );
59 // add timeframes
60 for ( f = 0; f < nFrames; f++ )
61 {
62 // create PI nodes for this frame
63 Saig_ManForEachPi( pAig, pObj, i )
64 pObj->pData = Aig_ObjCreateCi( pFrames );
65 // add internal nodes of this frame
66 Aig_ManForEachNode( pAig, pObj, i )
67 pObj->pData = Aig_And( pFrames, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
68 if ( f == nFrames - 1 )
69 break;
70 // transfer to register outputs
71 Saig_ManForEachLiLo( pAig, pObjLi, pObjLo, i )
72 pObjLi->pData = Aig_ObjChild0Copy(pObjLi);
73 // transfer to register outputs
74 Saig_ManForEachLiLo( pAig, pObjLi, pObjLo, i )
75 pObjLo->pData = pObjLi->pData;
76 }
77 // create POs for the output of the last frame
78 pObj = Aig_ManCo( pAig, 0 );
79 Aig_ObjCreateCo( pFrames, Aig_ObjChild0Copy(pObj) );
80 Aig_ManCleanup( pFrames );
81 return pFrames;
82}
83
95void * Inter_ManGetCounterExample( Aig_Man_t * pAig, int nFrames, int fVerbose )
96{
97 int nConfLimit = 1000000;
98 Abc_Cex_t * pCtrex = NULL;
99 Aig_Man_t * pFrames;
100 sat_solver * pSat;
101 Cnf_Dat_t * pCnf;
102 int status;
103 abctime clk = Abc_Clock();
104 Vec_Int_t * vCiIds;
105 // create timeframes
106 assert( Saig_ManPoNum(pAig) == 1 );
107 pFrames = Inter_ManFramesBmc( pAig, nFrames );
108 // derive CNF
109 pCnf = Cnf_Derive( pFrames, 0 );
110 Cnf_DataTranformPolarity( pCnf, 0 );
111 vCiIds = Cnf_DataCollectPiSatNums( pCnf, pFrames );
112 Aig_ManStop( pFrames );
113 // convert into SAT solver
114 pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
115 Cnf_DataFree( pCnf );
116 if ( pSat == NULL )
117 {
118 printf( "Counter-example generation in command \"int\" has failed.\n" );
119 printf( "Use command \"bmc2\" to produce a valid counter-example.\n" );
120 Vec_IntFree( vCiIds );
121 return NULL;
122 }
123 // simplify the problem
124 status = sat_solver_simplify(pSat);
125 if ( status == 0 )
126 {
127 Vec_IntFree( vCiIds );
128 sat_solver_delete( pSat );
129 return NULL;
130 }
131 // solve the miter
132 status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
133 // if the problem is SAT, get the counterexample
134 if ( status == l_True )
135 {
136 int i, * pModel = Sat_SolverGetModel( pSat, vCiIds->pArray, vCiIds->nSize );
137 pCtrex = Abc_CexAlloc( Saig_ManRegNum(pAig), Saig_ManPiNum(pAig), nFrames );
138 pCtrex->iFrame = nFrames - 1;
139 pCtrex->iPo = 0;
140 for ( i = 0; i < Vec_IntSize(vCiIds); i++ )
141 if ( pModel[i] )
142 Abc_InfoSetBit( pCtrex->pData, Saig_ManRegNum(pAig) + i );
143 ABC_FREE( pModel );
144 }
145 // free the sat_solver
146 sat_solver_delete( pSat );
147 Vec_IntFree( vCiIds );
148 // verify counter-example
149 status = Saig_ManVerifyCex( pAig, pCtrex );
150 if ( status == 0 )
151 printf( "Inter_ManGetCounterExample(): Counter-example verification has FAILED.\n" );
152 // report the results
153 if ( fVerbose )
154 {
155 ABC_PRT( "Total ctrex generation time", Abc_Clock() - clk );
156 }
157 return pCtrex;
158
159}
160
161
165
166
168
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition aigOper.c:104
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition aigObj.c:66
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
Definition aigMan.c:47
#define Aig_ManForEachNode(p, pObj, i)
Definition aig.h:413
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
int Aig_ManCleanup(Aig_Man_t *p)
Definition aigMan.c:265
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
Definition aigObj.c:45
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define l_True
Definition bmcBmcS.c:35
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition cnfCore.c:165
Vec_Int_t * Cnf_DataCollectPiSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition cnfMan.c:104
void Cnf_DataTranformPolarity(Cnf_Dat_t *pCnf, int fTransformPos)
Definition cnfMan.c:768
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
ABC_NAMESPACE_IMPL_START Aig_Man_t * Inter_ManFramesBmc(Aig_Man_t *pAig, int nFrames)
DECLARATIONS ///.
Definition intCtrex.c:46
void * Inter_ManGetCounterExample(Aig_Man_t *pAig, int nFrames, int fVerbose)
Definition intCtrex.c:95
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:579
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
Definition saig.h:101
#define Saig_ManForEachLo(p, pObj, i)
Definition saig.h:96
#define Saig_ManForEachPi(p, pObj, i)
Definition saig.h:91
int Saig_ManVerifyCex(Aig_Man_t *pAig, Abc_Cex_t *p)
Definition saigDup.c:281
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int * Sat_SolverGetModel(sat_solver *p, int *pVars, int nVars)
Definition satUtil.c:270
void * pData
Definition aig.h:87
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition utilCex.c:51
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition utilCex.h:39
#define assert(ex)
Definition util_old.h:213