mirror of https://github.com/YosysHQ/abc.git
Transforming the solver to use different clause representation.
This commit is contained in:
parent
94174d0f04
commit
7facbc3cc9
|
|
@ -22,6 +22,7 @@
|
||||||
#include "vec.h"
|
#include "vec.h"
|
||||||
#include "aig.h"
|
#include "aig.h"
|
||||||
#include "satTruth.h"
|
#include "satTruth.h"
|
||||||
|
#include "vecRec.h"
|
||||||
|
|
||||||
ABC_NAMESPACE_IMPL_START
|
ABC_NAMESPACE_IMPL_START
|
||||||
|
|
||||||
|
|
@ -36,67 +37,6 @@ ABC_NAMESPACE_IMPL_START
|
||||||
They are marked by bitshifting by 2 bits up and setting the LSB to 1
|
They are marked by bitshifting by 2 bits up and setting the LSB to 1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// data-structure to record resolvents of the proof
|
|
||||||
typedef struct Rec_Int_t_ Rec_Int_t;
|
|
||||||
struct Rec_Int_t_
|
|
||||||
{
|
|
||||||
int nShift; // log number of entries on a page
|
|
||||||
int Mask; // mask for entry number on a page
|
|
||||||
int nSize; // the total number of entries
|
|
||||||
int nLast; // the total number of entries before last append
|
|
||||||
Vec_Ptr_t * vPages; // memory pages
|
|
||||||
};
|
|
||||||
static inline Rec_Int_t * Rec_IntAlloc( int nShift )
|
|
||||||
{
|
|
||||||
Rec_Int_t * p;
|
|
||||||
p = ABC_CALLOC( Rec_Int_t, 1 );
|
|
||||||
p->nShift = nShift;
|
|
||||||
p->Mask = (1<<nShift)-1;
|
|
||||||
p->vPages = Vec_PtrAlloc( 50 );
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
static inline int Rec_IntSize( Rec_Int_t * p )
|
|
||||||
{
|
|
||||||
return p->nSize;
|
|
||||||
}
|
|
||||||
static inline int Rec_IntSizeLast( Rec_Int_t * p )
|
|
||||||
{
|
|
||||||
return p->nLast;
|
|
||||||
}
|
|
||||||
static inline void Rec_IntPush( Rec_Int_t * p, int Entry )
|
|
||||||
{
|
|
||||||
if ( (p->nSize >> p->nShift) == Vec_PtrSize(p->vPages) )
|
|
||||||
Vec_PtrPush( p->vPages, ABC_ALLOC(int, p->Mask+1) );
|
|
||||||
((int*)Vec_PtrEntry(p->vPages, p->nSize >> p->nShift))[p->nSize++ & p->Mask] = Entry;
|
|
||||||
}
|
|
||||||
static inline void Rec_IntAppend( Rec_Int_t * p, int * pArray, int nSize )
|
|
||||||
{
|
|
||||||
assert( nSize <= p->Mask );
|
|
||||||
if ( (p->nSize & p->Mask) + nSize >= p->Mask )
|
|
||||||
{
|
|
||||||
Rec_IntPush( p, 0 );
|
|
||||||
p->nSize = ((p->nSize >> p->nShift) + 1) * (p->Mask + 1);
|
|
||||||
}
|
|
||||||
if ( (p->nSize >> p->nShift) == Vec_PtrSize(p->vPages) )
|
|
||||||
Vec_PtrPush( p->vPages, ABC_ALLOC(int, p->Mask+1) );
|
|
||||||
// assert( (p->nSize >> p->nShift) + 1 == Vec_PtrSize(p->vPages) );
|
|
||||||
memmove( (int*)Vec_PtrEntry(p->vPages, p->nSize >> p->nShift) + (p->nSize & p->Mask), pArray, sizeof(int) * nSize );
|
|
||||||
p->nLast = p->nSize;
|
|
||||||
p->nSize += nSize;
|
|
||||||
}
|
|
||||||
static inline int Rec_IntEntry( Rec_Int_t * p, int i )
|
|
||||||
{
|
|
||||||
return ((int*)p->vPages->pArray[i >> p->nShift])[i & p->Mask];
|
|
||||||
}
|
|
||||||
static inline int * Rec_IntEntryP( Rec_Int_t * p, int i )
|
|
||||||
{
|
|
||||||
return (int*)p->vPages->pArray[i >> p->nShift] + (i & p->Mask);
|
|
||||||
}
|
|
||||||
static inline void Rec_IntFree( Rec_Int_t * p )
|
|
||||||
{
|
|
||||||
Vec_PtrFreeFree( p->vPages );
|
|
||||||
ABC_FREE( p );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
typedef struct satset_t satset;
|
typedef struct satset_t satset;
|
||||||
|
|
@ -118,12 +58,12 @@ struct satset_t
|
||||||
/// DECLARATIONS ///
|
/// DECLARATIONS ///
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static inline satset* Proof_NodeRead (Vec_Int_t* p, cla h ) { return satset_read( (veci*)p, h ); }
|
static inline satset* Proof_NodeRead (Vec_Int_t* p, cla h) { return satset_read( (veci*)p, h ); }
|
||||||
static inline cla Proof_NodeHandle (Vec_Int_t* p, satset* c) { return satset_handle( (veci*)p, c ); }
|
static inline cla Proof_NodeHandle (Vec_Int_t* p, satset* c) { return satset_handle( (veci*)p, c ); }
|
||||||
static inline int Proof_NodeCheck (Vec_Int_t* p, satset* c) { return satset_check( (veci*)p, c ); }
|
static inline int Proof_NodeCheck (Vec_Int_t* p, satset* c) { return satset_check( (veci*)p, c ); }
|
||||||
static inline int Proof_NodeSize (int nEnts) { return sizeof(satset)/4 + nEnts; }
|
static inline int Proof_NodeSize (int nEnts) { return sizeof(satset)/4 + nEnts; }
|
||||||
|
|
||||||
static inline satset* Proof_ResolveRead (Rec_Int_t* p, cla h ) { return (satset*)Rec_IntEntryP(p, h); }
|
static inline satset* Proof_ResolveRead (Vec_Rec_t* p, cla h) { return (satset*)Vec_RecEntryP(p, h); }
|
||||||
|
|
||||||
// iterating through nodes in the proof
|
// iterating through nodes in the proof
|
||||||
#define Proof_ForeachNode( p, pNode, h ) \
|
#define Proof_ForeachNode( p, pNode, h ) \
|
||||||
|
|
@ -418,9 +358,6 @@ void Sat_ProofReduce( sat_solver2 * s )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**Function*************************************************************
|
/**Function*************************************************************
|
||||||
|
|
||||||
Synopsis [Performs one resultion step.]
|
Synopsis [Performs one resultion step.]
|
||||||
|
|
@ -432,10 +369,10 @@ void Sat_ProofReduce( sat_solver2 * s )
|
||||||
SeeAlso []
|
SeeAlso []
|
||||||
|
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
satset * Sat_ProofCheckResolveOne( Rec_Int_t * p, satset * c1, satset * c2, Vec_Int_t * vTemp )
|
int Sat_ProofCheckResolveOne( Vec_Rec_t * p, satset * c1, satset * c2, Vec_Int_t * vTemp )
|
||||||
{
|
{
|
||||||
satset * c;
|
satset * c;
|
||||||
int i, k, Var = -1, Count = 0;
|
int h, i, k, Var = -1, Count = 0;
|
||||||
// find resolution variable
|
// find resolution variable
|
||||||
for ( i = 0; i < (int)c1->nEnts; i++ )
|
for ( i = 0; i < (int)c1->nEnts; i++ )
|
||||||
for ( k = 0; k < (int)c2->nEnts; k++ )
|
for ( k = 0; k < (int)c2->nEnts; k++ )
|
||||||
|
|
@ -447,12 +384,12 @@ satset * Sat_ProofCheckResolveOne( Rec_Int_t * p, satset * c1, satset * c2, Vec_
|
||||||
if ( Count == 0 )
|
if ( Count == 0 )
|
||||||
{
|
{
|
||||||
printf( "Cannot find resolution variable\n" );
|
printf( "Cannot find resolution variable\n" );
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( Count > 1 )
|
if ( Count > 1 )
|
||||||
{
|
{
|
||||||
printf( "Found more than 1 resolution variables\n" );
|
printf( "Found more than 1 resolution variables\n" );
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
// perform resolution
|
// perform resolution
|
||||||
Vec_IntClear( vTemp );
|
Vec_IntClear( vTemp );
|
||||||
|
|
@ -465,11 +402,11 @@ satset * Sat_ProofCheckResolveOne( Rec_Int_t * p, satset * c1, satset * c2, Vec_
|
||||||
if ( (c2->pEnts[i] >> 1) != Var )
|
if ( (c2->pEnts[i] >> 1) != Var )
|
||||||
Vec_IntPushUnique( vTemp, c2->pEnts[i] );
|
Vec_IntPushUnique( vTemp, c2->pEnts[i] );
|
||||||
// create new resolution entry
|
// create new resolution entry
|
||||||
Rec_IntAppend( p, Vec_IntArray(vTemp), Vec_IntSize(vTemp) );
|
h = Vec_RecPush( p, Vec_IntArray(vTemp), Vec_IntSize(vTemp) );
|
||||||
// return the new entry
|
// return the new entry
|
||||||
c = Proof_ResolveRead( p, Rec_IntSizeLast(p) );
|
c = Proof_ResolveRead( p, h );
|
||||||
c->nEnts = Vec_IntSize(vTemp)-2;
|
c->nEnts = Vec_IntSize(vTemp)-2;
|
||||||
return c;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Function*************************************************************
|
/**Function*************************************************************
|
||||||
|
|
@ -483,7 +420,7 @@ satset * Sat_ProofCheckResolveOne( Rec_Int_t * p, satset * c1, satset * c2, Vec_
|
||||||
SeeAlso []
|
SeeAlso []
|
||||||
|
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
satset * Sat_ProofCheckReadOne( Vec_Int_t * vClauses, Vec_Int_t * vProof, Rec_Int_t * vResolves, int iAnt )
|
satset * Sat_ProofCheckReadOne( Vec_Int_t * vClauses, Vec_Int_t * vProof, Vec_Rec_t * vResolves, int iAnt )
|
||||||
{
|
{
|
||||||
satset * pAnt;
|
satset * pAnt;
|
||||||
if ( iAnt & 1 )
|
if ( iAnt & 1 )
|
||||||
|
|
@ -511,26 +448,26 @@ void Sat_ProofCheck( sat_solver2 * s )
|
||||||
Vec_Int_t * vProof = (Vec_Int_t *)&s->proofs;
|
Vec_Int_t * vProof = (Vec_Int_t *)&s->proofs;
|
||||||
int hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
|
int hRoot = veci_begin(&s->claProofs)[satset_read(&s->learnts, s->hLearntLast>>1)->Id];
|
||||||
|
|
||||||
Rec_Int_t * vResolves;
|
Vec_Rec_t * vResolves;
|
||||||
Vec_Int_t * vUsed, * vTemp;
|
Vec_Int_t * vUsed, * vTemp;
|
||||||
satset * pSet, * pSet0, * pSet1;
|
satset * pSet, * pSet0, * pSet1;
|
||||||
int i, k, Counter = 0, clk = clock();
|
int i, k, Handle, Counter = 0, clk = clock();
|
||||||
// collect visited clauses
|
// collect visited clauses
|
||||||
vUsed = Proof_CollectUsedIter( vProof, NULL, hRoot );
|
vUsed = Proof_CollectUsedIter( vProof, NULL, hRoot );
|
||||||
Proof_CleanCollected( vProof, vUsed );
|
Proof_CleanCollected( vProof, vUsed );
|
||||||
// perform resolution steps
|
// perform resolution steps
|
||||||
vTemp = Vec_IntAlloc( 1000 );
|
vTemp = Vec_IntAlloc( 1000 );
|
||||||
vResolves = Rec_IntAlloc( 20 );
|
vResolves = Vec_RecAlloc();
|
||||||
Rec_IntPush( vResolves, -1 );
|
|
||||||
Proof_ForeachNodeVec( vUsed, vProof, pSet, i )
|
Proof_ForeachNodeVec( vUsed, vProof, pSet, i )
|
||||||
{
|
{
|
||||||
pSet0 = Sat_ProofCheckReadOne( vClauses, vProof, vResolves, pSet->pEnts[0] );
|
pSet0 = Sat_ProofCheckReadOne( vClauses, vProof, vResolves, pSet->pEnts[0] );
|
||||||
for ( k = 1; k < (int)pSet->nEnts; k++ )
|
for ( k = 1; k < (int)pSet->nEnts; k++ )
|
||||||
{
|
{
|
||||||
pSet1 = Sat_ProofCheckReadOne( vClauses, vProof, vResolves, pSet->pEnts[k] );
|
pSet1 = Sat_ProofCheckReadOne( vClauses, vProof, vResolves, pSet->pEnts[k] );
|
||||||
pSet0 = Sat_ProofCheckResolveOne( vResolves, pSet0, pSet1, vTemp );
|
Handle = Sat_ProofCheckResolveOne( vResolves, pSet0, pSet1, vTemp );
|
||||||
|
pSet0 = Proof_ResolveRead( vResolves, Handle );
|
||||||
}
|
}
|
||||||
pSet->Id = Rec_IntSizeLast( vResolves );
|
pSet->Id = Handle;
|
||||||
//printf( "Clause for proof %d: ", Vec_IntEntry(vUsed, i) );
|
//printf( "Clause for proof %d: ", Vec_IntEntry(vUsed, i) );
|
||||||
//satset_print( pSet0 );
|
//satset_print( pSet0 );
|
||||||
Counter++;
|
Counter++;
|
||||||
|
|
@ -539,17 +476,18 @@ void Sat_ProofCheck( sat_solver2 * s )
|
||||||
// clean the proof
|
// clean the proof
|
||||||
Proof_CleanCollected( vProof, vUsed );
|
Proof_CleanCollected( vProof, vUsed );
|
||||||
// compare the final clause
|
// compare the final clause
|
||||||
printf( "Used %6.2f Mb for resolvents.\n", 4.0 * Rec_IntSize(vResolves) / (1<<20) );
|
printf( "Used %6.2f Mb for resolvents.\n", 4.0 * Vec_RecSize(vResolves) / (1<<20) );
|
||||||
if ( pSet0->nEnts > 0 )
|
if ( pSet0->nEnts > 0 )
|
||||||
printf( "Derived clause with %d lits instead of the empty clause. ", pSet0->nEnts );
|
printf( "Derived clause with %d lits instead of the empty clause. ", pSet0->nEnts );
|
||||||
else
|
else
|
||||||
printf( "Proof verification successful. " );
|
printf( "Proof verification successful. " );
|
||||||
Abc_PrintTime( 1, "Time", clock() - clk );
|
Abc_PrintTime( 1, "Time", clock() - clk );
|
||||||
// cleanup
|
// cleanup
|
||||||
Rec_IntFree( vResolves );
|
Vec_RecFree( vResolves );
|
||||||
Vec_IntFree( vUsed );
|
Vec_IntFree( vUsed );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**Function*************************************************************
|
/**Function*************************************************************
|
||||||
|
|
||||||
Synopsis [Collects nodes belonging to the UNSAT core.]
|
Synopsis [Collects nodes belonging to the UNSAT core.]
|
||||||
|
|
|
||||||
|
|
@ -1317,8 +1317,8 @@ void sat_solver2_delete(sat_solver2* s)
|
||||||
veci_delete( pCore );
|
veci_delete( pCore );
|
||||||
ABC_FREE( pCore );
|
ABC_FREE( pCore );
|
||||||
*/
|
*/
|
||||||
// if ( s->fProofLogging )
|
if ( s->fProofLogging )
|
||||||
// Sat_ProofCheck( s );
|
Sat_ProofCheck( s );
|
||||||
|
|
||||||
// delete vectors
|
// delete vectors
|
||||||
veci_delete(&s->order);
|
veci_delete(&s->order);
|
||||||
|
|
|
||||||
|
|
@ -117,22 +117,6 @@ static inline void Vec_RecAlloc_( Vec_Rec_t * p )
|
||||||
// return p;
|
// return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Function*************************************************************
|
|
||||||
|
|
||||||
Synopsis []
|
|
||||||
|
|
||||||
Description []
|
|
||||||
|
|
||||||
SideEffects []
|
|
||||||
|
|
||||||
SeeAlso []
|
|
||||||
|
|
||||||
***********************************************************************/
|
|
||||||
static inline int Vec_RecEntryNum( Vec_Rec_t * p )
|
|
||||||
{
|
|
||||||
return p->nEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Function*************************************************************
|
/**Function*************************************************************
|
||||||
|
|
||||||
Synopsis []
|
Synopsis []
|
||||||
|
|
@ -165,6 +149,38 @@ static inline int Vec_RecShift( int i )
|
||||||
return i&0xFFFF;
|
return i&0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Function*************************************************************
|
||||||
|
|
||||||
|
Synopsis []
|
||||||
|
|
||||||
|
Description []
|
||||||
|
|
||||||
|
SideEffects []
|
||||||
|
|
||||||
|
SeeAlso []
|
||||||
|
|
||||||
|
***********************************************************************/
|
||||||
|
static inline int Vec_RecSize( Vec_Rec_t * p )
|
||||||
|
{
|
||||||
|
return Vec_RecChunk(p->hCurrent) * (1 << p->LogSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**Function*************************************************************
|
||||||
|
|
||||||
|
Synopsis []
|
||||||
|
|
||||||
|
Description []
|
||||||
|
|
||||||
|
SideEffects []
|
||||||
|
|
||||||
|
SeeAlso []
|
||||||
|
|
||||||
|
***********************************************************************/
|
||||||
|
static inline int Vec_RecEntryNum( Vec_Rec_t * p )
|
||||||
|
{
|
||||||
|
return p->nEntries;
|
||||||
|
}
|
||||||
|
|
||||||
/**Function*************************************************************
|
/**Function*************************************************************
|
||||||
|
|
||||||
Synopsis []
|
Synopsis []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue