ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
satSolver2i.c
Go to the documentation of this file.
1
20
21#include "satSolver2.h"
22#include "aig/gia/gia.h"
23#include "aig/gia/giaAig.h"
24#include "sat/cnf/cnf.h"
25
27
28
32
33struct Int2_Man_t_
34{
35 sat_solver2 * pSat; // user's SAT solver
36 Vec_Int_t * vGloVars; // IDs of global variables
37 Vec_Int_t * vVar2Glo; // mapping of SAT variables into their global IDs
38 Gia_Man_t * pGia; // AIG manager to store the interpolant
39};
40
44
56Int2_Man_t * Int2_ManStart( sat_solver2 * pSat, int * pGloVars, int nGloVars )
57{
58 Int2_Man_t * p;
59 int i;
60 p = ABC_CALLOC( Int2_Man_t, 1 );
61 p->pSat = pSat;
62 p->vGloVars = Vec_IntAllocArrayCopy( pGloVars, nGloVars );
63 p->vVar2Glo = Vec_IntInvert( p->vGloVars, -1 );
64 p->pGia = Gia_ManStart( 10 * Vec_IntSize(p->vGloVars) );
65 p->pGia->pName = Abc_UtilStrsav( "interpolant" );
66 for ( i = 0; i < nGloVars; i++ )
67 Gia_ManAppendCi( p->pGia );
68 Gia_ManHashStart( p->pGia );
69 return p;
70}
72{
73 if ( p == NULL )
74 return;
75 Gia_ManStopP( &p->pGia );
76 Vec_IntFree( p->vGloVars );
77 Vec_IntFree( p->vVar2Glo );
78 ABC_FREE( p );
79}
81{
82 Int2_Man_t * p = pSat->pInt2;
83 Gia_Man_t * pTemp, * pGia = p->pGia; p->pGia = NULL;
84 // return NULL, if the interpolant is not ready (for example, when the solver returned 'sat')
85 if ( pSat->hProofLast == -1 )
86 return NULL;
87 // create AIG with one primary output
88 assert( Gia_ManPoNum(pGia) == 0 );
89 Gia_ManAppendCo( pGia, pSat->hProofLast );
90 pSat->hProofLast = -1;
91 // cleanup the resulting AIG
92 pGia = Gia_ManCleanup( pTemp = pGia );
93 Gia_ManStop( pTemp );
94 return (void *)pGia;
95}
96
109{
110 if ( c->lrn )
111 return veci_begin(&p->pSat->claProofs)[clause_id(c)];
112 if ( !c->partA )
113 return 1;
114 if ( c->lits[c->size] < 0 )
115 {
116 int i, Var, CiId, Res = 0;
117 for ( i = 0; i < (int)c->size; i++ )
118 {
119 // get ID of the global variable
120 if ( Abc_Lit2Var(c->lits[i]) >= Vec_IntSize(p->vVar2Glo) )
121 continue;
122 Var = Vec_IntEntry( p->vVar2Glo, Abc_Lit2Var(c->lits[i]) );
123 if ( Var < 0 )
124 continue;
125 // get literal of the AIG node
126 CiId = Gia_ObjId( p->pGia, Gia_ManCi(p->pGia, Var) );
127 // compute interpolant of the clause
128 Res = Gia_ManHashOr( p->pGia, Res, Abc_Var2Lit(CiId, Abc_LitIsCompl(c->lits[i])) );
129 }
130 c->lits[c->size] = Res;
131 }
132 return c->lits[c->size];
133}
134int Int2_ManChainResolve( Int2_Man_t * p, clause * c, int iLit, int varA )
135{
136 int iLit2 = Int2_ManChainStart( p, c );
137 assert( iLit >= 0 );
138 if ( varA )
139 iLit = Gia_ManHashOr( p->pGia, iLit, iLit2 );
140 else
141 iLit = Gia_ManHashAnd( p->pGia, iLit, iLit2 );
142 return iLit;
143}
144
159{
160 sat_solver2 * pSat;
161 Gia_Man_t * pInter;
162 Aig_Man_t * pMan;
163 Vec_Int_t * vGVars;
164 Cnf_Dat_t * pCnf;
165 Aig_Obj_t * pObj;
166 int Lit, Cid, Var, status, i;
167 abctime clk = Abc_Clock();
168 assert( Gia_ManRegNum(p) == 0 );
169 assert( Gia_ManCoNum(p) == 1 );
170
171 // derive CNFs
172 pMan = Gia_ManToAigSimple( p );
173 pCnf = Cnf_Derive( pMan, 1 );
174
175 // start the solver
176 pSat = sat_solver2_new();
177 pSat->fVerbose = 1;
178 sat_solver2_setnvars( pSat, 2*pCnf->nVars+1 );
179
180 // set A-variables (all used except PI/PO, which will be global variables)
181 Aig_ManForEachObj( pMan, pObj, i )
182 if ( pCnf->pVarNums[pObj->Id] >= 0 && !Aig_ObjIsCi(pObj) && !Aig_ObjIsCo(pObj) )
183 var_set_partA( pSat, pCnf->pVarNums[pObj->Id], 1 );
184
185 // add clauses of A
186 for ( i = 0; i < pCnf->nClauses; i++ )
187 {
188 Cid = sat_solver2_addclause( pSat, pCnf->pClauses[i], pCnf->pClauses[i+1], -1 );
189 clause2_set_partA( pSat, Cid, 1 ); // this API should be called for each clause of A
190 }
191
192 // add clauses of B (after shifting all CNF variables by pCnf->nVars)
193 Cnf_DataLift( pCnf, pCnf->nVars );
194 for ( i = 0; i < pCnf->nClauses; i++ )
195 sat_solver2_addclause( pSat, pCnf->pClauses[i], pCnf->pClauses[i+1], -1 );
196 Cnf_DataLift( pCnf, -pCnf->nVars );
197
198 // add PI equality clauses
199 vGVars = Vec_IntAlloc( Aig_ManCoNum(pMan)+1 );
200 Aig_ManForEachCi( pMan, pObj, i )
201 {
202 Var = pCnf->pVarNums[pObj->Id];
203 sat_solver2_add_buffer( pSat, Var, pCnf->nVars + Var, 0, 0, -1 );
204 Vec_IntPush( vGVars, Var );
205 }
206
207 // add an XOR clause in the end
208 Var = pCnf->pVarNums[Aig_ManCo(pMan,0)->Id];
209 sat_solver2_add_xor( pSat, Var, pCnf->nVars + Var, 2*pCnf->nVars, 0, 0, -1 );
210 Vec_IntPush( vGVars, Var );
211
212 // start the interpolation manager
213 pSat->pInt2 = Int2_ManStart( pSat, Vec_IntArray(vGVars), Vec_IntSize(vGVars) );
214
215 // solve the problem
216 Lit = toLitCond( 2*pCnf->nVars, 0 );
217 status = sat_solver2_solve( pSat, &Lit, &Lit + 1, 0, 0, 0, 0 );
218 assert( status == l_False );
219 Sat_Solver2PrintStats( stdout, pSat );
220
221 // derive interpolant
222 pInter = (Gia_Man_t *)Int2_ManReadInterpolant( pSat );
223 Gia_ManPrintStats( pInter, NULL );
224 Abc_PrintTime( 1, "Total interpolation time", Abc_Clock() - clk );
225
226 // clean up
227 Vec_IntFree( vGVars );
228 Cnf_DataFree( pCnf );
229 Aig_ManStop( pMan );
230 sat_solver2_delete( pSat );
231
232 // return interpolant
233 return pInter;
234}
235
239
240
242
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define Aig_ManForEachObj(p, pObj, i)
Definition aig.h:403
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition aig.h:393
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define l_False
Definition bmcBmcS.c:36
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
void Cnf_DataLift(Cnf_Dat_t *p, int nVarsPlus)
Definition cnfMan.c:232
Cube * p
Definition exorList.c:222
int Var
Definition exorList.c:228
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
Definition giaAig.c:408
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
void Gia_ManHashStart(Gia_Man_t *p)
Definition giaHash.c:125
void Gia_ManStopP(Gia_Man_t **p)
Definition giaMan.c:224
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:621
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
Definition giaMan.c:495
typedefABC_NAMESPACE_HEADER_START struct Int2_Man_t_ Int2_Man_t
INCLUDES ///.
Definition int2Int.h:45
void sat_solver2_delete(sat_solver2 *s)
sat_solver2 * sat_solver2_new(void)
int sat_solver2_solve(sat_solver2 *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
void sat_solver2_setnvars(sat_solver2 *s, int n)
void var_set_partA(sat_solver2 *s, int v, int partA)
Definition satSolver2.c:85
int sat_solver2_addclause(sat_solver2 *s, lit *begin, lit *end, int Id)
void Sat_Solver2PrintStats(FILE *pFile, sat_solver2 *p)
Definition satUtil.c:214
struct sat_solver2_t sat_solver2
Definition satSolver2.h:44
Gia_Man_t * Gia_ManInterTest(Gia_Man_t *p)
void Int2_ManStop(Int2_Man_t *p)
Definition satSolver2i.c:71
int Int2_ManChainStart(Int2_Man_t *p, clause *c)
int Int2_ManChainResolve(Int2_Man_t *p, clause *c, int iLit, int varA)
Int2_Man_t * Int2_ManStart(sat_solver2 *pSat, int *pGloVars, int nGloVars)
FUNCTION DEFINITIONS ///.
Definition satSolver2i.c:56
void * Int2_ManReadInterpolant(sat_solver2 *pSat)
Definition satSolver2i.c:80
int Id
Definition aig.h:85
int nVars
Definition cnf.h:59
int * pVarNums
Definition cnf.h:63
int ** pClauses
Definition cnf.h:62
int nClauses
Definition cnf.h:61
DECLARATIONS ///.
Definition int2Int.h:47
Vec_Int_t * vGloVars
Definition satSolver2i.c:36
Vec_Int_t * vVar2Glo
Definition satSolver2i.c:37
Gia_Man_t * pGia
Definition int2Int.h:51
sat_solver2 * pSat
Definition satSolver2i.c:35
unsigned lits[3]
Definition clause.h:39
unsigned size
Definition clause.h:37
Int2_Man_t * pInt2
Definition satSolver2.h:168
#define assert(ex)
Definition util_old.h:213