abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
satSolver2i.c File Reference
#include "satSolver2.h"
#include "aig/gia/gia.h"
#include "aig/gia/giaAig.h"
#include "sat/cnf/cnf.h"

Go to the source code of this file.

Data Structures

struct  Int2_Man_t_
 DECLARATIONS ///. More...
 

Functions

Int2_Man_tInt2_ManStart (sat_solver2 *pSat, int *pGloVars, int nGloVars)
 FUNCTION DEFINITIONS ///. More...
 
void Int2_ManStop (Int2_Man_t *p)
 
void * Int2_ManReadInterpolant (sat_solver2 *pSat)
 
int Int2_ManChainStart (Int2_Man_t *p, clause *c)
 
int Int2_ManChainResolve (Int2_Man_t *p, clause *c, int iLit, int varA)
 
Gia_Man_tGia_ManInterTest (Gia_Man_t *p)
 

Function Documentation

Gia_Man_t* Gia_ManInterTest ( Gia_Man_t p)

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

Synopsis [Test for the interpolation procedure.]

Description [The input AIG can be any n-input comb circuit with one PO (not necessarily a comb miter). The interpolant depends on n+1 variables and equal to the relation f = F(x0,x1,...,xn).]

SideEffects []

SeeAlso []

Definition at line 158 of file satSolver2i.c.

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 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
Definition: giaAig.c:367
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
Definition: giaMan.c:389
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition: cnfCore.c:165
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
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
int nClauses
Definition: cnf.h:61
void sat_solver2_delete(sat_solver2 *s)
Definition: satSolver2.c:1225
int nVars
Definition: cnf.h:59
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
int * pVarNums
Definition: cnf.h:63
static int sat_solver2_add_xor(sat_solver2 *pSat, int iVarA, int iVarB, int iVarC, int fCompl, int fMark, int Id)
Definition: satSolver2.h:319
Int2_Man_t * pInt2
Definition: satSolver2.h:168
sat_solver2 * sat_solver2_new(void)
Definition: satSolver2.c:1109
void Sat_Solver2PrintStats(FILE *pFile, sat_solver2 *p)
Definition: satUtil.c:210
int sat_solver2_addclause(sat_solver2 *s, lit *begin, lit *end, int Id)
Definition: satSolver2.c:1287
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: cnf.h:56
for(p=first;p->value< newval;p=p->next)
void sat_solver2_setnvars(sat_solver2 *s, int n)
Definition: satSolver2.c:1170
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
int ** pClauses
Definition: cnf.h:62
void var_set_partA(sat_solver2 *s, int v, int partA)
Definition: satSolver2.c:85
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static lit toLitCond(int v, int c)
Definition: satVec.h:143
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
void Cnf_DataLift(Cnf_Dat_t *p, int nVarsPlus)
Definition: cnfMan.c:205
static Aig_Obj_t * Aig_ManCo(Aig_Man_t *p, int i)
Definition: aig.h:267
static int sat_solver2_add_buffer(sat_solver2 *pSat, int iVarA, int iVarB, int fCompl, int fMark, int Id)
Definition: satSolver2.h:275
Int2_Man_t * Int2_ManStart(sat_solver2 *pSat, int *pGloVars, int nGloVars)
FUNCTION DEFINITIONS ///.
Definition: satSolver2i.c:56
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
Definition: gia.h:95
static void clause2_set_partA(sat_solver2 *s, int h, int partA)
Definition: satSolver2.h:183
void * Int2_ManReadInterpolant(sat_solver2 *pSat)
Definition: satSolver2i.c:80
#define l_False
Definition: SolverTypes.h:85
int Var
Definition: SolverTypes.h:42
void Cnf_DataFree(Cnf_Dat_t *p)
Definition: cnfMan.c:180
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)
Definition: satSolver2.c:1835
#define assert(ex)
Definition: util_old.h:213
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
ABC_INT64_T abctime
Definition: abc_global.h:278
int Id
Definition: aig.h:85
static int Aig_ObjIsCo(Aig_Obj_t *pObj)
Definition: aig.h:276
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387
int Int2_ManChainResolve ( Int2_Man_t p,
clause c,
int  iLit,
int  varA 
)

Definition at line 134 of file satSolver2i.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Int2_ManChainStart(Int2_Man_t *p, clause *c)
Definition: satSolver2i.c:108
#define assert(ex)
Definition: util_old.h:213
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:611
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
int Int2_ManChainStart ( Int2_Man_t p,
clause c 
)

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

Synopsis [Computing interpolant for a clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 108 of file satSolver2i.c.

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 }
lit lits[0]
Definition: satClause.h:56
static Gia_Obj_t * Gia_ManCi(Gia_Man_t *p, int v)
Definition: gia.h:403
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
static int clause_id(clause *c)
Definition: satClause.h:144
unsigned partA
Definition: satClause.h:53
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
unsigned size
Definition: satClause.h:55
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
int Var
Definition: SolverTypes.h:42
unsigned lrn
Definition: satClause.h:51
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:611
static int * veci_begin(veci *v)
Definition: satVec.h:45
void* Int2_ManReadInterpolant ( sat_solver2 pSat)

Definition at line 80 of file satSolver2i.c.

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 }
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Int2_Man_t * pInt2
Definition: satSolver2.h:168
typedefABC_NAMESPACE_HEADER_START struct Int2_Man_t_ Int2_Man_t
INCLUDES ///.
Definition: int2Int.h:45
Definition: gia.h:95
#define assert(ex)
Definition: util_old.h:213
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition: giaScl.c:84
Int2_Man_t* Int2_ManStart ( sat_solver2 pSat,
int *  pGloVars,
int  nGloVars 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Managing interpolation manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 56 of file satSolver2i.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
static Vec_Int_t * Vec_IntInvert(Vec_Int_t *p, int Fill)
Definition: vecInt.h:1092
typedefABC_NAMESPACE_HEADER_START struct Int2_Man_t_ Int2_Man_t
INCLUDES ///.
Definition: int2Int.h:45
void Gia_ManHashStart(Gia_Man_t *p)
Definition: giaHash.c:117
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
static Vec_Int_t * Vec_IntAllocArrayCopy(int *pArray, int nSize)
Definition: vecInt.h:192
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
void Int2_ManStop ( Int2_Man_t p)

Definition at line 71 of file satSolver2i.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Gia_ManStopP(Gia_Man_t **p)
Definition: giaMan.c:177
#define ABC_FREE(obj)
Definition: abc_global.h:232
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235