summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-01-20 17:55:34 -0800
committerAlan Mishchenko <alanmi@berkeley.edu>2012-01-20 17:55:34 -0800
commit719b06f91295cc0dd811241b7bc30707546241bd (patch)
treea3abeb11e3ccd73adefd81023451d48568adfeab
parentb9163754b759ad5406509d042b873f973db7ab4c (diff)
downloadabc-719b06f91295cc0dd811241b7bc30707546241bd.tar.gz
abc-719b06f91295cc0dd811241b7bc30707546241bd.tar.bz2
abc-719b06f91295cc0dd811241b7bc30707546241bd.zip
Variable timeframe abstraction.
-rw-r--r--src/aig/gia/giaAbsVta.c388
-rw-r--r--src/aig/gia/giaFrames.c9
-rw-r--r--src/aig/gia/giaMan.c8
-rw-r--r--src/sat/bsat/satProof.c29
-rw-r--r--src/sat/bsat/satSolver.h6
-rw-r--r--src/sat/bsat/satSolver2.c28
-rw-r--r--src/sat/bsat/satSolver2.h6
7 files changed, 266 insertions, 208 deletions
diff --git a/src/aig/gia/giaAbsVta.c b/src/aig/gia/giaAbsVta.c
index 50ae53e2..c3574e26 100644
--- a/src/aig/gia/giaAbsVta.c
+++ b/src/aig/gia/giaAbsVta.c
@@ -98,7 +98,7 @@ static inline int Vta_ObjId( Vta_Man_t * p, Vta_Obj_t * pObj ) { assert
// - the following entries give the object IDs
// invariant: assert( vec[vec[0]+2] == size(vec) );
-extern void Vga_ManAddClausesOne( Vta_Man_t * p, Vta_Obj_t * pThis );
+extern void Vga_ManAddClausesOne( Vta_Man_t * p, int iObj, int iFrame );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
@@ -342,6 +342,7 @@ static inline Vta_Obj_t * Vga_ManFindOrAdd( Vta_Man_t * p, int iObj, int iFrame
{
Vta_Obj_t * pThis;
int * pPlace;
+ assert( iObj >= 0 && iFrame >= -1 );
if ( p->nObjs == p->nObjsAlloc )
{
p->pObjs = ABC_REALLOC( Vta_Obj_t, p->pObjs, 2 * p->nObjsAlloc );
@@ -370,78 +371,6 @@ static inline void Vga_ManDelete( Vta_Man_t * p, int iObj, int iFrame )
/**Function*************************************************************
- Synopsis [Finds the set of clauses involved in the UNSAT core.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-Vec_Int_t * Vta_ManUnsatCore( Vec_Int_t * vCla2Var, sat_solver2 * pSat, int nConfMax, int fVerbose, int * piRetValue )
-{
- Vec_Int_t * vPres;
- Vec_Int_t * vCore;
- int k, i, Entry, RetValue, clk = clock();
- if ( piRetValue )
- *piRetValue = -1;
- // solve the problem
- RetValue = sat_solver2_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfMax, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
- if ( RetValue == l_Undef )
- {
-// if ( fVerbose )
- printf( "Conflict limit is reached.\n" );
- return NULL;
- }
- if ( RetValue == l_True )
- {
-// if ( fVerbose )
- printf( "The BMC problem is SAT.\n" );
- if ( piRetValue )
- *piRetValue = 0;
- return NULL;
- }
- if ( fVerbose )
- {
- printf( "UNSAT after %7d conflicts. ", pSat->stats.conflicts );
- Abc_PrintTime( 1, "Time", clock() - clk );
- }
- assert( RetValue == l_False );
-
- // derive the UNSAT core
- clk = clock();
- vCore = (Vec_Int_t *)Sat_ProofCore( pSat );
- if ( fVerbose )
- {
- printf( "Core is %8d clauses (out of %8d). ", Vec_IntSize(vCore), sat_solver2_nclauses(pSat) );
- Abc_PrintTime( 1, "Time", clock() - clk );
- }
-
- // remap core into variables
- clk = clock();
- vPres = Vec_IntStart( sat_solver2_nvars(pSat) );
- k = 0;
- Vec_IntForEachEntry( vCore, Entry, i )
- {
- Entry = Vec_IntEntry(vCla2Var, Entry);
- if ( Vec_IntEntry(vPres, Entry) )
- continue;
- Vec_IntWriteEntry( vPres, Entry, 1 );
- Vec_IntWriteEntry( vCore, k++, Entry );
- }
- Vec_IntShrink( vCore, k );
- Vec_IntFree( vPres );
- if ( fVerbose )
- {
- printf( "Core is %8d vars (out of %8d). ", Vec_IntSize(vCore), sat_solver2_nvars(pSat) );
- Abc_PrintTime( 1, "Time", clock() - clk );
- }
- return vCore;
-}
-
-/**Function*************************************************************
-
Synopsis [Remaps core into frame/node pairs.]
Description []
@@ -460,7 +389,9 @@ void Vta_ManUnsatCoreRemap( Vta_Man_t * p, Vec_Int_t * vCore )
pThis = Vta_ManObj( p, Entry );
Entry = (pThis->iFrame << p->nObjBits) | pThis->iObj;
Vec_IntWriteEntry( vCore, i, Entry );
+//printf( "%d^%d ", pThis->iObj, pThis->iFrame );
}
+//printf( "\n" );
}
/**Function*************************************************************
@@ -804,7 +735,7 @@ Abc_Cex_t * Vta_ManRefineAbstraction( Vta_Man_t * p )
}
// add clauses
Vec_PtrForEachEntry( Vta_Obj_t *, vTermsUsed, pThis, i )
- Vga_ManAddClausesOne( p, pThis );
+ Vga_ManAddClausesOne( p, pThis->iObj, pThis->iFrame );
}
Vec_PtrFree( vTermsUsed );
@@ -827,38 +758,43 @@ Vta_Man_t * Vga_ManStart( Gia_Man_t * pGia, Gia_ParVta_t * pPars )
{
Vta_Man_t * p;
p = ABC_CALLOC( Vta_Man_t, 1 );
- p->pGia = pGia;
- p->pPars = pPars;
+ p->pGia = pGia;
+ p->pPars = pPars;
// internal data
- p->nObjsAlloc = (1 << 20);
- p->pObjs = ABC_CALLOC( Vta_Obj_t, p->nObjsAlloc );
- p->nObjs = 1;
- p->nBins = Abc_PrimeCudd( p->nObjsAlloc/2 );
- p->pBins = ABC_CALLOC( int, p->nBins );
- p->vOrder = Vec_IntAlloc( 1013 );
+ p->nObjsAlloc = (1 << 20);
+ p->pObjs = ABC_CALLOC( Vta_Obj_t, p->nObjsAlloc );
+ p->nObjs = 1;
+ p->nBins = Abc_PrimeCudd( p->nObjsAlloc/2 );
+ p->pBins = ABC_CALLOC( int, p->nBins );
+ p->vOrder = Vec_IntAlloc( 1013 );
// abstraction
- p->nObjBits = Gia_Base2Log( Gia_ManObjNum(pGia) );
- p->nObjMask = (1 << p->nObjBits) - 1;
+ p->nObjBits = Gia_Base2Log( Gia_ManObjNum(pGia) );
+ p->nObjMask = (1 << p->nObjBits) - 1;
assert( Gia_ManObjNum(pGia) <= (int)p->nObjMask );
- p->nWords = 1;
- p->vSeens = Vec_IntStart( Gia_ManObjNum(pGia) * p->nWords );
+ p->nWords = 1;
+ p->vSeens = Vec_IntStart( Gia_ManObjNum(pGia) * p->nWords );
// start the abstraction
if ( pGia->vObjClasses == NULL )
- p->vFrames = Gia_ManUnrollAbs( pGia, pPars->nFramesStart );
+ p->vFrames = Gia_ManUnrollAbs( pGia, pPars->nFramesStart );
else
{
- p->vFrames = Gia_VtaAbsToFrames( pGia->vObjClasses );
+ p->vFrames = Gia_VtaAbsToFrames( pGia->vObjClasses );
// update parameters
if ( pPars->nFramesStart != Vec_PtrSize(p->vFrames) )
- printf( "Starting frame count is set in accordance with abstraction (%d).\n", Vec_PtrSize(p->vFrames) );
- pPars->nFramesStart = Vec_PtrSize(p->vFrames);
- if ( pPars->nFramesMax )
+ {
+ printf( "Starting frame count is changed to match the abstraction (from %d to %d).\n", pPars->nFramesStart, Vec_PtrSize(p->vFrames) );
+ pPars->nFramesStart = Vec_PtrSize(p->vFrames);
+ }
+ if ( pPars->nFramesMax && pPars->nFramesMax < pPars->nFramesStart )
+ {
+ printf( "Maximum frame count is changed to match the starting frames (from %d to %d).\n", pPars->nFramesMax, pPars->nFramesStart );
pPars->nFramesMax = Abc_MaxInt( pPars->nFramesMax, pPars->nFramesStart );
+ }
}
// other data
- p->vCla2Var = Vec_IntAlloc( 1000 );
- p->vCores = Vec_PtrAlloc( 100 );
- p->pSat = sat_solver2_new();
+ p->vCla2Var = Vec_IntAlloc( 1000 );
+ p->vCores = Vec_PtrAlloc( 100 );
+ p->pSat = sat_solver2_new();
return p;
}
@@ -888,6 +824,82 @@ void Vga_ManStop( Vta_Man_t * p )
/**Function*************************************************************
+ Synopsis [Finds the set of clauses involved in the UNSAT core.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Vec_Int_t * Vta_ManUnsatCore( int iLit, Vec_Int_t * vCla2Var, sat_solver2 * pSat, int nConfMax, int fVerbose, int * piRetValue )
+{
+ Vec_Int_t * vPres;
+ Vec_Int_t * vCore;
+ int k, i, Entry, RetValue, clk = clock();
+ int nConfPrev = pSat->stats.conflicts;
+ if ( piRetValue )
+ *piRetValue = 1;
+ // solve the problem
+ RetValue = sat_solver2_solve( pSat, &iLit, &iLit+1, (ABC_INT64_T)nConfMax, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
+ if ( RetValue == l_Undef )
+ {
+// if ( fVerbose )
+ printf( "Conflict limit is reached.\n" );
+ if ( piRetValue )
+ *piRetValue = -1;
+ return NULL;
+ }
+ if ( RetValue == l_True )
+ {
+// if ( fVerbose )
+ printf( "The BMC problem is SAT.\n" );
+ if ( piRetValue )
+ *piRetValue = 0;
+ return NULL;
+ }
+ if ( fVerbose )
+ {
+ printf( "%6d", (int)pSat->stats.conflicts - nConfPrev );
+// printf( "UNSAT after %7d conflicts. ", pSat->stats.conflicts );
+// Abc_PrintTime( 1, "Time", clock() - clk );
+ }
+ assert( RetValue == l_False );
+
+ // derive the UNSAT core
+ clk = clock();
+ vCore = (Vec_Int_t *)Sat_ProofCore( pSat );
+ if ( fVerbose )
+ {
+// printf( "Core is %8d clauses (out of %8d). ", Vec_IntSize(vCore), sat_solver2_nclauses(pSat) );
+// Abc_PrintTime( 1, "Time", clock() - clk );
+ }
+
+ // remap core into variables
+ clk = clock();
+ vPres = Vec_IntStart( sat_solver2_nvars(pSat) );
+ k = 0;
+ Vec_IntForEachEntry( vCore, Entry, i )
+ {
+ Entry = Vec_IntEntry(vCla2Var, Entry);
+ if ( Vec_IntEntry(vPres, Entry) )
+ continue;
+ Vec_IntWriteEntry( vPres, Entry, 1 );
+ Vec_IntWriteEntry( vCore, k++, Entry );
+ }
+ Vec_IntShrink( vCore, k );
+ Vec_IntFree( vPres );
+ if ( fVerbose )
+ {
+// printf( "Core is %8d vars (out of %8d). ", Vec_IntSize(vCore), sat_solver2_nvars(pSat) );
+// Abc_PrintTime( 1, "Time", clock() - clk );
+ }
+ return vCore;
+}
+
+/**Function*************************************************************
+
Synopsis []
Description []
@@ -918,12 +930,13 @@ void Vta_ManAbsPrintFrame( Vta_Man_t * p, Vec_Int_t * vCore, int nFrames )
}
pCountAll[iFrame+1]++;
pCountAll[0]++;
-
- printf( "%5d%5d ", pCountAll[0], pCountUni[0] );
- for ( k = 0; k < nFrames; k++ )
- printf( "%5d%5d ", pCountAll[k+1], pCountUni[k+1] );
- printf( "\n" );
}
+// printf( "%5d%5d", pCountAll[0], pCountUni[0] );
+ printf( "%7d", pCountAll[0] );
+ for ( k = 0; k < nFrames; k++ )
+// printf( "%5d%5d ", pCountAll[k+1], pCountUni[k+1] );
+ printf( "%4d", pCountAll[k+1] );
+ printf( "\n" );
ABC_FREE( pCountAll );
ABC_FREE( pCountUni );
}
@@ -939,59 +952,56 @@ void Vta_ManAbsPrintFrame( Vta_Man_t * p, Vec_Int_t * vCore, int nFrames )
SeeAlso []
***********************************************************************/
-void Vga_ManAddClausesOne( Vta_Man_t * p, Vta_Obj_t * pThis )
+void Vga_ManAddClausesOne( Vta_Man_t * p, int iObj, int iFrame )
{
Vta_Obj_t * pThis0, * pThis1;
- Gia_Obj_t * pObj;
- int i = Vta_ObjId( p, pThis );
- assert( !pThis->fAdded && !pThis->fNew );
- pObj = Gia_ManObj( p->pGia, pThis->iObj );
+ Gia_Obj_t * pObj = Gia_ManObj( p->pGia, iObj );
+ Vta_Obj_t * pThis = Vga_ManFindOrAdd( p, iObj, iFrame );
+ int iMainVar = Vta_ObjId(p, pThis);
+ assert( pThis->iObj == iObj && pThis->iFrame == iFrame );
+ assert( pThis->fAdded == 0 );
+ pThis->fAdded = 1;
if ( Gia_ObjIsAnd(pObj) )
{
- pThis0 = Vga_ManFind( p, Gia_ObjFaninId0p(p->pGia, pObj), pThis->iFrame );
- pThis1 = Vga_ManFind( p, Gia_ObjFaninId1p(p->pGia, pObj), pThis->iFrame );
- if ( pThis0 && pThis1 )
- {
- pThis->fAdded = 1;
- sat_solver2_add_and( p->pSat,
- Vta_ObjId(p, pThis), Vta_ObjId(p, pThis0), Vta_ObjId(p, pThis1),
- Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj), 0 );
- Vec_IntPush( p->vCla2Var, i );
- Vec_IntPush( p->vCla2Var, i );
- Vec_IntPush( p->vCla2Var, i );
- }
+ pThis0 = Vga_ManFindOrAdd( p, Gia_ObjFaninId0p(p->pGia, pObj), iFrame );
+ pThis1 = Vga_ManFindOrAdd( p, Gia_ObjFaninId1p(p->pGia, pObj), iFrame );
+ sat_solver2_add_and( p->pSat, iMainVar, Vta_ObjId(p, pThis0), Vta_ObjId(p, pThis1),
+ Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj), 0 );
+ Vec_IntPush( p->vCla2Var, iMainVar );
+ Vec_IntPush( p->vCla2Var, iMainVar );
+ Vec_IntPush( p->vCla2Var, iMainVar );
+//printf( "Adding node %d (var %d)\n", iObj, iMainVar );
}
else if ( Gia_ObjIsRo(p->pGia, pObj) )
{
- if ( pThis->iFrame == 0 )
+//printf( "Adding flop %d (var %d)\n", iObj, iMainVar );
+ if ( iFrame == 0 )
{
- pThis->fAdded = 1;
- sat_solver2_add_constraint( p->pSat, pThis->iObj, 1, 0 );
- Vec_IntPush( p->vCla2Var, i );
- Vec_IntPush( p->vCla2Var, i );
+ /*
+ pThis0 = Vga_ManFindOrAdd( p, iObj, -1 );
+ sat_solver2_add_constraint( p->pSat, iMainVar, Vta_ObjId(p, pThis0), 1, 0 );
+ Vec_IntPush( p->vCla2Var, iMainVar );
+ Vec_IntPush( p->vCla2Var, iMainVar );
+ */
+ sat_solver2_add_const( p->pSat, iMainVar, 1, 0 );
+ Vec_IntPush( p->vCla2Var, iMainVar );
}
else
{
pObj = Gia_ObjRoToRi( p->pGia, pObj );
- pThis0 = Vga_ManFind( p, Gia_ObjFaninId0p(p->pGia, pObj), pThis->iFrame-1 );
- if ( pThis0 )
- {
- pThis->fAdded = 1;
- sat_solver2_add_buffer( p->pSat,
- Vta_ObjId(p, pThis), Vta_ObjId(p, pThis0),
- Gia_ObjFaninC0(pObj), 0 );
- Vec_IntPush( p->vCla2Var, i );
- Vec_IntPush( p->vCla2Var, i );
- }
+ pThis0 = Vga_ManFindOrAdd( p, Gia_ObjFaninId0p(p->pGia, pObj), pThis->iFrame-1 );
+ sat_solver2_add_buffer( p->pSat, iMainVar, Vta_ObjId(p, pThis0), Gia_ObjFaninC0(pObj), 0 );
+ Vec_IntPush( p->vCla2Var, iMainVar );
+ Vec_IntPush( p->vCla2Var, iMainVar );
}
}
else if ( Gia_ObjIsConst0(pObj) )
{
- pThis->fAdded = 1;
- sat_solver2_add_const( p->pSat, Vta_ObjId(p, pThis), 1, 0 );
- Vec_IntPush( p->vCla2Var, i );
+//printf( "Adding const %d (var %d)\n", iObj, iMainVar );
+ sat_solver2_add_const( p->pSat, iMainVar, 1, 0 );
+ Vec_IntPush( p->vCla2Var, iMainVar );
}
- else if ( !Gia_ObjIsPi(p->pGia, pObj) )
+ else //if ( !Gia_ObjIsPi(p->pGia, pObj) )
assert( 0 );
}
@@ -1008,25 +1018,28 @@ void Vga_ManAddClausesOne( Vta_Man_t * p, Vta_Obj_t * pThis )
***********************************************************************/
void Vga_ManLoadSlice( Vta_Man_t * p, Vec_Int_t * vOne, int Lift )
{
- Gia_Obj_t * pObj;
- Vta_Obj_t * pThis;
- int i, Entry, iObjPrev = p->nObjs;
+ int i, Entry;
Vec_IntForEachEntry( vOne, Entry, i )
- {
- pObj = Gia_ManObj( p->pGia, Entry & p->nObjMask );
- if ( Gia_ObjIsPi(p->pGia, pObj) )
- continue;
- pThis = Vga_ManFindOrAdd( p, Entry & p->nObjMask, (Entry >> p->nObjBits) + Lift );
- pThis->fNew = 0;
- // add constraint variable
- if ( Gia_ObjIsRo(p->pGia, pObj) && (Entry >> p->nObjBits) + Lift == 0 )
- {
- pThis = Vga_ManFindOrAdd( p, Entry & p->nObjMask, (Entry >> p->nObjBits) + Lift );
- pThis->fNew = 0;
- }
- }
- for ( i = iObjPrev; i < p->nObjs; i++ )
- Vga_ManAddClausesOne( p, Vta_ManObj(p, i) );
+ Vga_ManAddClausesOne( p, Entry & p->nObjMask, (Entry >> p->nObjBits) + Lift );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Returns the output literal.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Vga_ManGetOutLit( Vta_Man_t * p, int f )
+{
+ Gia_Obj_t * pObj = Gia_ManPo(p->pGia, 0);
+ Vta_Obj_t * pThis = Vga_ManFind( p, Gia_ObjFaninId0p(p->pGia, pObj), f );
+ assert( pThis != NULL && pThis->fAdded );
+ return Gia_Var2Lit( Vta_ObjId(p, pThis), Gia_ObjFaninC0(pObj) );
}
/**Function*************************************************************
@@ -1043,19 +1056,24 @@ void Vga_ManLoadSlice( Vta_Man_t * p, Vec_Int_t * vOne, int Lift )
int Gia_VtaPerform( Gia_Man_t * pAig, Gia_ParVta_t * pPars )
{
Vta_Man_t * p;
+ Vta_Obj_t * pThis;
Vec_Int_t * vCore;
Abc_Cex_t * pCex = NULL;
- int f, i, Limit, Status, RetValue = -1;
+ Gia_Obj_t * pObj;
+ int i, f, Status, RetValue = -1;
// preconditions
assert( Gia_ManPoNum(pAig) == 1 );
assert( pPars->nFramesMax == 0 || pPars->nFramesStart <= pPars->nFramesMax );
// start the manager
p = Vga_ManStart( pAig, pPars );
// perform initial abstraction
+ if ( p->pPars->fVerbose )
+ printf( "Frame Confl All F0 F1 F2 F3 ...\n" );
for ( f = 0; !p->pPars->nFramesMax || f < p->pPars->nFramesMax; f++ )
{
if ( p->pPars->fVerbose )
- printf( "Frame %4d : ", f );
+ printf( "%3d :", f );
+//printf( "\n" );
p->pPars->iFrame = f;
// realloc storage for abstraction marks
if ( f == p->nWords * 32 )
@@ -1065,43 +1083,54 @@ int Gia_VtaPerform( Gia_Man_t * pAig, Gia_ParVta_t * pPars )
{
// load this timeframe
Vga_ManLoadSlice( p, Vec_PtrEntry(p->vFrames, f), 0 );
+// Vga_ManAddClausesOne( p, 0, f );
// run SAT solver
- vCore = Vta_ManUnsatCore( p->vCla2Var, p->pSat, pPars->nConfLimit, p->pPars->fVerbose, &Status );
- if ( vCore == NULL && Status == 0 )
+ vCore = Vta_ManUnsatCore( Vga_ManGetOutLit(p, f), p->vCla2Var, p->pSat, pPars->nConfLimit, p->pPars->fVerbose, &Status );
+ assert( (vCore != NULL) == (Status == 1) );
+ if ( Status == -1 )
+ break;
+ if ( Status == 0 )
{
// make sure, there was no initial abstraction (otherwise, it was invalid)
assert( pAig->vObjClasses == NULL );
// derive counter-example
- pCex = NULL;
+ pCex = Abc_CexAlloc( Gia_ManRegNum(p->pGia), Gia_ManPiNum(p->pGia), p->pPars->iFrame+1 );
+ pCex->iPo = 0;
+ pCex->iFrame = p->pPars->iFrame;
+ Vta_ManForEachObj( p, pThis, i )
+ {
+ pObj = Gia_ManObj( p->pGia, pThis->iObj );
+ if ( Gia_ObjIsPi(p->pGia, pObj) && sat_solver2_var_value(p->pSat, Vta_ObjId(p, pThis)) )
+ Gia_InfoSetBit( pCex->pData, pCex->nRegs + pThis->iFrame * pCex->nPis + Gia_ObjCioId(pObj) );
+ }
}
}
else
{
- break;
-
+/*
// load the time frame
- Limit = Abc_MinInt(3, p->pPars->nFramesStart);
+ int Limit = Abc_MinInt(3, p->pPars->nFramesStart);
for ( i = 1; i <= Limit; i++ )
Vga_ManLoadSlice( p, Vec_PtrEntry(p->vCores, f-i), i );
+// Vga_ManAddClausesOne( p, 0, f );
// iterate as long as there are counter-examples
- while ( 1 )
- {
- vCore = Vta_ManUnsatCore( p->vCla2Var, p->pSat, pPars->nConfLimit, pPars->fVerbose, &RetValue );
- if ( RetValue ) // resource limit is reached
- {
- assert( vCore == NULL );
+ do {
+ vCore = Vta_ManUnsatCore( Vga_ManGetOutLit(p, f), p->vCla2Var, p->pSat, pPars->nConfLimit, pPars->fVerbose, &Status );
+ assert( (vCore != NULL) == (Status == 1) );
+ if ( Status == -1 ) // resource limit is reached
break;
- }
if ( vCore != NULL )
{
- // unroll the solver, add the core
+ // rollback and add the core
// return and double check
break;
}
pCex = Vta_ManRefineAbstraction( p );
- if ( pCex != NULL )
- break;
- }
+ }
+ while ( pCex == NULL );
+ if ( Status == -1 ) // resource limit is reached
+ break;
+*/
}
if ( pCex != NULL )
{
@@ -1121,7 +1150,11 @@ int Gia_VtaPerform( Gia_Man_t * pAig, Gia_ParVta_t * pPars )
// print the result
if ( p->pPars->fVerbose )
Vta_ManAbsPrintFrame( p, vCore, f+1 );
+
+ if ( f == p->pPars->nFramesStart-1 )
+ break;
}
+ // analize the results
if ( pCex == NULL )
{
assert( Vec_PtrSize(p->vCores) > 0 );
@@ -1129,6 +1162,17 @@ int Gia_VtaPerform( Gia_Man_t * pAig, Gia_ParVta_t * pPars )
printf( "Replacing the old abstraction by a new one.\n" );
Vec_IntFreeP( &pAig->vObjClasses );
pAig->vObjClasses = Gia_VtaFramesToAbs( (Vec_Vec_t *)p->vCores );
+ if ( Status == -1 )
+ printf( "SAT solver ran out of resources at %d conflicts in frame %d.\n", pPars->nConfLimit, f );
+ else
+ printf( "SAT solver completed %d frames and produced an abstraction.\n", f+1 );
+ }
+ else
+ {
+ ABC_FREE( p->pGia->pCexSeq );
+ p->pGia->pCexSeq = pCex;
+ if ( !Gia_ManVerifyCex( p->pGia, pCex, 0 ) )
+ printf( "Gia_VtaPerform(): CEX verification has failed!\n" );
}
Vga_ManStop( p );
return RetValue;
diff --git a/src/aig/gia/giaFrames.c b/src/aig/gia/giaFrames.c
index bee181c3..480326bd 100644
--- a/src/aig/gia/giaFrames.c
+++ b/src/aig/gia/giaFrames.c
@@ -189,11 +189,12 @@ Vec_Ptr_t * Gia_ManUnrollAbs( Gia_Man_t * p, int nFrames )
iStop = (f+1 < Vec_IntSize(vLimit)) ? Vec_IntEntry(vLimit, f+1) : 0;
for ( k = iStop - 1; k >= iStart; k-- )
{
- pObj = Gia_ManObj(pNew, k);
- if ( Gia_ObjIsCo(pObj) )
+ assert( Gia_ManObj(pNew, k)->Value > 0 );
+ pObj = Gia_ManObj(p, Gia_ManObj(pNew, k)->Value);
+ if ( Gia_ObjIsCo(pObj) || Gia_ObjIsPi(p, pObj) )
continue;
- assert( Gia_ObjIsCi(pObj) || Gia_ObjIsAnd(pObj) );
- Entry = ((fMax-f) << nObjBits) | pObj->Value;
+ assert( Gia_ObjIsRo(p, pObj) || Gia_ObjIsAnd(pObj) );
+ Entry = ((fMax-f) << nObjBits) | Gia_ObjId(p, pObj);
Vec_IntPush( vOne, Entry );
// printf( "%d ", Gia_ManObj(pNew, k)->Value );
}
diff --git a/src/aig/gia/giaMan.c b/src/aig/gia/giaMan.c
index b787f713..769006c2 100644
--- a/src/aig/gia/giaMan.c
+++ b/src/aig/gia/giaMan.c
@@ -277,6 +277,7 @@ void Gia_ManPrintObjClasses( Gia_Man_t * p )
nObjMask = (1 << nObjBits) - 1;
assert( Gia_ManObjNum(p) <= nObjMask );
// print info about frames
+ printf( "Frame All F0 F1 F2 F3 ...\n" );
for ( i = 0; i < nFrames; i++ )
{
iStart = Vec_IntEntry( vAbs, i+1 );
@@ -298,10 +299,13 @@ void Gia_ManPrintObjClasses( Gia_Man_t * p )
pCountAll[0]++;
}
assert( pCountAll[0] == (unsigned)(iStop - iStart) );
- printf( "%5d%5d ", pCountAll[0], pCountUni[0] );
+// printf( "%5d%5d ", pCountAll[0], pCountUni[0] );
+ printf( "%3d :", i );
+ printf( "%6d", pCountAll[0] );
for ( k = 0; k < nFrames; k++ )
if ( k <= i )
- printf( "%5d%5d ", pCountAll[k+1], pCountUni[k+1] );
+// printf( "%5d%5d ", pCountAll[k+1], pCountUni[k+1] );
+ printf( "%4d", pCountAll[k+1] );
printf( "\n" );
}
assert( iStop == Vec_IntSize(vAbs) );
diff --git a/src/sat/bsat/satProof.c b/src/sat/bsat/satProof.c
index 27fd698c..79179952 100644
--- a/src/sat/bsat/satProof.c
+++ b/src/sat/bsat/satProof.c
@@ -443,12 +443,13 @@ void Sat_ProofCheck( sat_solver2 * s )
{
Vec_Int_t * vClauses = (Vec_Int_t *)&s->clauses;
Vec_Int_t * vProof = (Vec_Int_t *)&s->proofs;
- int hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
-
Vec_Rec_t * vResolves;
Vec_Int_t * vUsed, * vTemp;
satset * pSet, * pSet0, * pSet1;
- int i, k, Handle, Counter = 0, clk = clock();
+ int i, k, hRoot, Handle, Counter = 0, clk = clock();
+ if ( s->hLearntLast < 0 )
+ return;
+ hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
// collect visited clauses
vUsed = Proof_CollectUsedIter( vProof, NULL, hRoot );
Proof_CleanCollected( vProof, vUsed );
@@ -509,7 +510,7 @@ Vec_Int_t * Sat_ProofCollectCore( Vec_Int_t * vClauses, Vec_Int_t * vProof, Vec_
if ( pFanin && !pFanin->mark )
{
pFanin->mark = 1;
- Vec_IntPush( vCore, pNode->pEnts[i] >> 2 );
+ Vec_IntPush( vCore, pNode->pEnts[k] >> 2 );
}
}
// clean core clauses and reexpress core in terms of clause IDs
@@ -586,13 +587,14 @@ void * Sat_ProofInterpolant( sat_solver2 * s, void * pGloVars )
Vec_Int_t * vClauses = (Vec_Int_t *)&s->clauses;
Vec_Int_t * vProof = (Vec_Int_t *)&s->proofs;
Vec_Int_t * vGlobVars = (Vec_Int_t *)pGloVars;
- int hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
-
Vec_Int_t * vUsed, * vCore, * vCoreNums, * vVarMap;
satset * pNode, * pFanin;
Aig_Man_t * pAig;
Aig_Obj_t * pObj;
- int i, k, iVar, Lit, Entry;
+ int i, k, iVar, Lit, Entry, hRoot;
+ if ( s->hLearntLast < 0 )
+ return NULL;
+ hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
Sat_ProofInterpolantCheckVars( s, vGlobVars );
@@ -683,16 +685,17 @@ word * Sat_ProofInterpolantTruth( sat_solver2 * s, void * pGloVars )
Vec_Int_t * vClauses = (Vec_Int_t *)&s->clauses;
Vec_Int_t * vProof = (Vec_Int_t *)&s->proofs;
Vec_Int_t * vGlobVars = (Vec_Int_t *)pGloVars;
- int hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
-
Vec_Int_t * vUsed, * vCore, * vCoreNums, * vVarMap;
satset * pNode, * pFanin;
Tru_Man_t * pTru;
int nVars = Vec_IntSize(vGlobVars);
int nWords = (nVars < 6) ? 1 : (1 << (nVars-6));
word * pRes = ABC_ALLOC( word, nWords );
- int i, k, iVar, Lit, Entry;
+ int i, k, iVar, Lit, Entry, hRoot;
assert( nVars > 0 && nVars <= 16 );
+ if ( s->hLearntLast < 0 )
+ return NULL;
+ hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
Sat_ProofInterpolantCheckVars( s, vGlobVars );
@@ -789,9 +792,11 @@ void * Sat_ProofCore( sat_solver2 * s )
{
Vec_Int_t * vClauses = (Vec_Int_t *)&s->clauses;
Vec_Int_t * vProof = (Vec_Int_t *)&s->proofs;
- int hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
-
Vec_Int_t * vCore, * vUsed;
+ int hRoot;
+ if ( s->hLearntLast < 0 )
+ return NULL;
+ hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
// collect visited clauses
vUsed = Proof_CollectUsedIter( vProof, NULL, hRoot );
// collect core clauses
diff --git a/src/sat/bsat/satSolver.h b/src/sat/bsat/satSolver.h
index 1437f5c1..0ca934ed 100644
--- a/src/sat/bsat/satSolver.h
+++ b/src/sat/bsat/satSolver.h
@@ -292,19 +292,19 @@ static inline int sat_solver_add_xor( sat_solver * pSat, int iVarA, int iVarB, i
assert( Cid );
return 4;
}
-static inline int sat_solver_add_constraint( sat_solver * pSat, int iVar, int fCompl )
+static inline int sat_solver_add_constraint( sat_solver * pSat, int iVar, int iVar2, int fCompl )
{
lit Lits[2];
int Cid;
assert( iVar >= 0 );
Lits[0] = toLitCond( iVar, fCompl );
- Lits[1] = toLitCond( iVar+1, 0 );
+ Lits[1] = toLitCond( iVar2, 0 );
Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
assert( Cid );
Lits[0] = toLitCond( iVar, fCompl );
- Lits[1] = toLitCond( iVar+1, 1 );
+ Lits[1] = toLitCond( iVar2, 1 );
Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
assert( Cid );
return 2;
diff --git a/src/sat/bsat/satSolver2.c b/src/sat/bsat/satSolver2.c
index f4625d51..f2215fea 100644
--- a/src/sat/bsat/satSolver2.c
+++ b/src/sat/bsat/satSolver2.c
@@ -150,7 +150,8 @@ static inline int clause_is_used(sat_solver2* s, cla h) { return (h & 1
static inline int var_reason (sat_solver2* s, int v) { return s->reasons[v]; }
static inline int lit_reason (sat_solver2* s, int l) { return s->reasons[lit_var(l)]; }
static inline satset* var_unit_clause(sat_solver2* s, int v) { return clause_read(s, s->units[v]); }
-static inline void var_set_unit_clause(sat_solver2* s, int v, cla i){ assert(v >= 0 && v < s->size && !s->units[v]); s->units[v] = i; s->nUnits++; }
+//static inline void var_set_unit_clause(sat_solver2* s, int v, cla i){ assert(v >= 0 && v < s->size && !s->units[v]); s->units[v] = i; s->nUnits++; }
+static inline void var_set_unit_clause(sat_solver2* s, int v, cla i){ assert(v >= 0 && v < s->size); s->units[v] = i; s->nUnits++; }
// these two only work after creating a clause before the solver is called
int clause_is_partA (sat_solver2* s, int h) { return clause_read(s, h)->partA; }
@@ -1102,7 +1103,8 @@ static lbool solver2_search(sat_solver2* s, ABC_INT64_T nof_conflicts)
if (solver2_dlevel(s) <= s->root_level){
#ifdef SAT_USE_ANALYZE_FINAL
proof_id = solver2_analyze_final(s, confl, 0);
- if ( proof_id > 0 )
+ assert( proof_id > 0 );
+// if ( proof_id > 0 )
solver2_record(s,&s->conf_final, proof_id);
#endif
veci_delete(&learnt_clause);
@@ -1307,11 +1309,11 @@ void sat_solver2_setnvars(sat_solver2* s,int n)
void sat_solver2_delete(sat_solver2* s)
{
- veci * pCore;
+// veci * pCore;
// report statistics
printf( "Used %6.2f Mb for proof-logging. Unit clauses = %d.\n", 2.0 * veci_size(&s->proofs) / (1<<20), s->nUnits );
-
+/*
pCore = Sat_ProofCore( s );
printf( "UNSAT core contains %d clauses (%6.2f %%).\n", veci_size(pCore), 100.0*veci_size(pCore)/veci_size(&s->clauses) );
veci_delete( pCore );
@@ -1319,7 +1321,7 @@ void sat_solver2_delete(sat_solver2* s)
if ( s->fProofLogging )
Sat_ProofCheck( s );
-
+*/
// delete vectors
veci_delete(&s->order);
veci_delete(&s->trail_lim);
@@ -1392,7 +1394,7 @@ int sat_solver2_addclause__(sat_solver2* s, lit* begin, lit* end)
// delete duplicates
last = lit_Undef;
for (i = j = begin; i < end; i++){
- //printf("lit: "L_LIT", value = %d\n", L_lit(*i), (lit_sign(*i) ? -values[lit_var(*i)] : values[lit_var(*i)]));
+ //printf("lit: "L_LIT", value = %d\n", L_lit(*i), (lit_sign(*i) ? -var_value(s, lit_var(*i)) : var_value(s, lit_var(*i))));
if (*i == lit_neg(last) || var_value(s, lit_var(*i)) == lit_sign(*i))
return true; // tautology
else if (*i != last && var_value(s, lit_var(*i)) == varX)
@@ -1634,9 +1636,9 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
int restart_iter = 0;
ABC_INT64_T nof_conflicts;
ABC_INT64_T nof_learnts = sat_solver2_nclauses(s) / 3;
- lbool status = l_Undef;
-// lbool* values = s->assigns;
- lit* i;
+ lbool status = l_Undef;
+ int proof_id;
+ lit * i;
s->hLearntLast = -1;
@@ -1659,7 +1661,6 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
//printf("solve: "); printlits(begin, end); printf("\n");
for (i = begin; i < end; i++){
-// switch (lit_sign(*i) ? -values[lit_var(*i)] : values[lit_var(*i)]){
switch (var_value(s, *i)) {
case var1: // l_True:
break;
@@ -1723,17 +1724,19 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
if (r != NULL)
{
satset* confl = r;
- solver2_analyze_final(s, confl, 1);
+ proof_id = solver2_analyze_final(s, confl, 1);
veci_push(&s->conf_final, lit_neg(p));
}
else
{
+ proof_id = -1; // the only case when ProofId is not assigned (conflicting assumptions)
veci_resize(&s->conf_final,0);
veci_push(&s->conf_final, lit_neg(p));
// the two lines below are a bug fix by Siert Wieringa
if (var_level(s, lit_var(p)) > 0)
veci_push(&s->conf_final, p);
}
+ solver2_record(s, &s->conf_final, proof_id);
solver2_canceluntil(s, 0);
return l_False;
}
@@ -1741,9 +1744,10 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
{
satset* confl = solver2_propagate(s);
if (confl != NULL){
- solver2_analyze_final(s, confl, 0);
+ proof_id = solver2_analyze_final(s, confl, 0);
assert(s->conf_final.size > 0);
solver2_canceluntil(s, 0);
+ solver2_record(s,&s->conf_final, proof_id);
return l_False;
}
}
diff --git a/src/sat/bsat/satSolver2.h b/src/sat/bsat/satSolver2.h
index 4b26f55f..baccf68d 100644
--- a/src/sat/bsat/satSolver2.h
+++ b/src/sat/bsat/satSolver2.h
@@ -355,20 +355,20 @@ static inline int sat_solver2_add_xor( sat_solver2 * pSat, int iVarA, int iVarB,
clause_set_partA( pSat, Cid, 1 );
return 4;
}
-static inline int sat_solver2_add_constraint( sat_solver2 * pSat, int iVar, int fCompl, int fMark )
+static inline int sat_solver2_add_constraint( sat_solver2 * pSat, int iVar, int iVar2, int fCompl, int fMark )
{
lit Lits[2];
int Cid;
assert( iVar >= 0 );
Lits[0] = toLitCond( iVar, fCompl );
- Lits[1] = toLitCond( iVar+1, 0 );
+ Lits[1] = toLitCond( iVar2, 0 );
Cid = sat_solver2_addclause( pSat, Lits, Lits + 2 );
if ( fMark )
clause_set_partA( pSat, Cid, 1 );
Lits[0] = toLitCond( iVar, fCompl );
- Lits[1] = toLitCond( iVar+1, 1 );
+ Lits[1] = toLitCond( iVar2, 1 );
Cid = sat_solver2_addclause( pSat, Lits, Lits + 2 );
if ( fMark )
clause_set_partA( pSat, Cid, 1 );