Commit 5351ab4b by Bruno Schmitt

xSAT is an experimental SAT Solver based on Glucose v3(see Glucose copyrights…

xSAT is an experimental SAT Solver based on Glucose v3(see Glucose copyrights below) and ABC C version of
MiniSat (bsat) developed by Niklas Sorensson and modified by Alan Mishchenko. It’s development has reached
sufficient maturity to be committed in ABC, but still in a beta state.

TODO:
* Read compressed CNF files.
* Study the use of floating point for variables and clauses activity.
* Better documentation.
* Improve verbose messages.
* Expose parameters for tuning.
parent cd92b1fe
......@@ -23,7 +23,7 @@ MODULES := \
src/opt/cut src/opt/fxu src/opt/fxch src/opt/rwr src/opt/mfs src/opt/sim \
src/opt/ret src/opt/fret src/opt/res src/opt/lpk src/opt/nwk src/opt/rwt \
src/opt/cgt src/opt/csw src/opt/dar src/opt/dau src/opt/dsc src/opt/sfm src/opt/sbd \
src/sat/bsat src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc \
src/sat/bsat src/sat/xsat src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc \
src/bool/bdc src/bool/deco src/bool/dec src/bool/kit src/bool/lucky \
src/bool/rsb src/bool/rpo \
src/proof/pdr src/proof/abs src/proof/live src/proof/ssc src/proof/int \
......
xSAT - Copyright (c) 2016, Bruno Schmitt - UC Berkeley / UFRGS (boschmitt@inf.ufrgs.br)
xSAT is based on Glucose v3(see Glucose copyrights below) and ABC C version of
MiniSat (bsat) developed by Niklas Sorensson and modified by Alan Mishchenko.
Permissions and copyrights of xSAT are exactly the same as Glucose v3/Minisat.
(see below).
---------------
Glucose -- Copyright (c) 2013, Gilles Audemard, Laurent Simon
CRIL - Univ. Artois, France
LRI - Univ. Paris Sud, France
Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions
and copyrights of Glucose are exactly the same as Minisat on which it is based
on. (see below).
---------------
Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
Copyright (c) 2007-2010, Niklas Sorensson
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*******************************************************************************/
SRC += src/sat/xsat/xsatSolver.c \
src/sat/xsat/xsatSolverAPI.c \
src/sat/xsat/xsatCnfReader.c
/**CFile****************************************************************
FileName [xsat.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [External definitions of the solver.]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
#ifndef ABC__sat__xSAT__xSAT_h
#define ABC__sat__xSAT__xSAT_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"
#include "misc/vec/vecInt.h"
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
struct xSAT_Solver_t_;
typedef struct xSAT_Solver_t_ xSAT_Solver_t;
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
/*=== xsatCnfReader.c ================================================*/
extern int xSAT_SolverParseDimacs( FILE *, xSAT_Solver_t ** );
/*=== xsatSolverAPI.c ================================================*/
extern xSAT_Solver_t * xSAT_SolverCreate();
extern void xSAT_SolverDestroy( xSAT_Solver_t * );
extern int xSAT_SolverAddClause( xSAT_Solver_t *, Vec_Int_t * );
extern int xSAT_SolverSimplify( xSAT_Solver_t * );
extern int xSAT_SolverSolve( xSAT_Solver_t * );
extern void xSAT_SolverPrintStats( xSAT_Solver_t * );
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
/**CFile****************************************************************
FileName [xsatBQueue.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [Bounded queue implementation.]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
#ifndef ABC__sat__xSAT__xsatBQueue_h
#define ABC__sat__xSAT__xsatBQueue_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct xSAT_BQueue_t_ xSAT_BQueue_t;
struct xSAT_BQueue_t_
{
int nSize;
int nCap;
int iFirst;
int iEmpty;
uint64_t nSum;
uint32_t * pData;
};
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline xSAT_BQueue_t * xSAT_BQueueNew( int nCap )
{
xSAT_BQueue_t * p = ABC_CALLOC( xSAT_BQueue_t, 1 );
p->nCap = nCap;
p->pData = ABC_CALLOC( uint32_t, nCap );
return p;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_BQueueFree( xSAT_BQueue_t * p )
{
ABC_FREE( p->pData );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_BQueuePush( xSAT_BQueue_t * p, uint32_t Value )
{
if ( p->nSize == p->nCap )
{
assert(p->iFirst == p->iEmpty);
p->nSum -= p->pData[p->iFirst];
p->iFirst = ( p->iFirst + 1 ) % p->nCap;
}
else
p->nSize++;
p->nSum += Value;
p->pData[p->iEmpty] = Value;
if ( ( ++p->iEmpty ) == p->nCap )
{
p->iEmpty = 0;
p->iFirst = 0;
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int xSAT_BQueuePop( xSAT_BQueue_t * p )
{
assert( p->nSize >= 1 );
int RetValue = p->pData[p->iFirst];
p->nSum -= RetValue;
p->iFirst = ( p->iFirst + 1 ) % p->nCap;
p->nSize--;
return RetValue;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline uint32_t xSAT_BQueueAvg( xSAT_BQueue_t * p )
{
return ( uint32_t )( p->nSum / ( ( uint64_t ) p->nSize ) );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int xSAT_BQueueIsValid( xSAT_BQueue_t * p )
{
return ( p->nCap == p->nSize );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_BQueueClean( xSAT_BQueue_t * p )
{
p->iFirst = 0;
p->iEmpty = 0;
p->nSize = 0;
p->nSum = 0;
}
ABC_NAMESPACE_HEADER_END
#endif
/**CFile****************************************************************
FileName [xsatClause.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [Clause data type definition.]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
#ifndef ABC__sat__xSAT__xsatClause_h
#define ABC__sat__xSAT__xsatClause_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct xSAT_Clause_t_ xSAT_Clause_t;
struct xSAT_Clause_t_
{
unsigned fLearnt : 1;
unsigned fMark : 1;
unsigned fReallocd : 1;
unsigned fCanBeDel : 1;
unsigned nLBD : 28;
unsigned nSize;
union {
int Lit;
unsigned Act;
} pData[0];
};
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static int xSAT_ClauseCompare( const void * p1, const void * p2 )
{
xSAT_Clause_t * pC1 = ( xSAT_Clause_t * ) p1;
xSAT_Clause_t * pC2 = ( xSAT_Clause_t * ) p2;
if ( pC1->nSize > 2 && pC2->nSize == 2 )
return 1;
if ( pC1->nSize == 2 && pC2->nSize > 2 )
return 0;
if ( pC1->nSize == 2 && pC2->nSize == 2 )
return 0;
if ( pC1->nLBD > pC2->nLBD )
return 1;
if ( pC1->nLBD < pC2->nLBD )
return 0;
return pC1->pData[pC1->nSize].Act < pC2->pData[pC2->nSize].Act;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static void xSAT_ClausePrint( xSAT_Clause_t * pCla )
{
int i;
printf("{ ");
for ( i = 0; i < pCla->nSize; i++ )
printf("%d ", pCla->pData[i].Lit );
printf("}\n");
}
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
/**CFile****************************************************************
FileName [xsatCnfReader.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [CNF DIMACS file format parser.]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include <ctype.h>
#include "misc/util/abc_global.h"
#include "misc/vec/vecInt.h"
#include "xsatSolver.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Read the file into the internal buffer.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
char * xSAT_FileRead( FILE * pFile )
{
int nFileSize;
char * pBuffer;
int RetValue;
// get the file size, in bytes
fseek( pFile, 0, SEEK_END );
nFileSize = ftell( pFile );
// move the file current reading position to the beginning
rewind( pFile );
// load the contents of the file into memory
pBuffer = ABC_ALLOC( char, nFileSize + 3 );
RetValue = fread( pBuffer, nFileSize, 1, pFile );
// terminate the string with '\0'
pBuffer[ nFileSize + 0] = '\n';
pBuffer[ nFileSize + 1] = '\0';
return pBuffer;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static void skipLine( char ** pIn )
{
while ( 1 )
{
if (**pIn == 0)
return;
if (**pIn == '\n')
{
(*pIn)++;
return;
}
(*pIn)++;
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static int xSAT_ReadInt( char ** pIn )
{
int val = 0;
int neg = 0;
for(; isspace(**pIn); (*pIn)++);
if ( **pIn == '-' )
neg = 1,
(*pIn)++;
else if ( **pIn == '+' )
(*pIn)++;
if ( !isdigit(**pIn) )
fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", **pIn),
exit(1);
while ( isdigit(**pIn) )
val = val*10 + (**pIn - '0'),
(*pIn)++;
return neg ? -val : val;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static void xSAT_ReadClause( char ** pIn, xSAT_Solver_t * p, Vec_Int_t * vLits )
{
int token, var, sign;
Vec_IntClear( vLits );
while ( 1 )
{
token = xSAT_ReadInt( pIn );
if ( token == 0 )
break;
var = abs(token) - 1;
sign = (token > 0);
Vec_IntPush( vLits, xSAT_Var2Lit( var, !sign ) );
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static int xSAT_ParseDimacs( char * pText, xSAT_Solver_t ** pS )
{
xSAT_Solver_t * p = NULL;
Vec_Int_t * vLits = NULL;
char * pIn = pText;
int nVars, nClas;
while ( 1 )
{
for(; isspace(*pIn); pIn++);
if ( *pIn == 0 )
break;
else if ( *pIn == 'c' )
skipLine( &pIn );
else if ( *pIn == 'p' )
{
pIn++;
for(; isspace(*pIn); pIn++);
for(; !isspace(*pIn); pIn++);
nVars = xSAT_ReadInt( &pIn );
nClas = xSAT_ReadInt( &pIn );
skipLine( &pIn );
/* start the solver */
p = xSAT_SolverCreate();
/* allocate the vector */
vLits = Vec_IntAlloc( nVars );
}
else
{
if ( p == NULL )
{
printf( "There is no parameter line.\n" );
exit(1);
}
xSAT_ReadClause( &pIn, p, vLits );
if ( !xSAT_SolverAddClause( p, vLits ) )
{
Vec_IntPrint(vLits);
return 0;
}
}
}
Vec_IntFree( vLits );
*pS = p;
return xSAT_SolverSimplify( p );
}
/**Function*************************************************************
Synopsis [Starts the solver and reads the DIMAC file.]
Description [Returns FALSE upon immediate conflict.]
SideEffects []
SeeAlso []
***********************************************************************/
int xSAT_SolverParseDimacs( FILE * pFile, xSAT_Solver_t ** p )
{
char * pText;
int Value;
pText = xSAT_FileRead( pFile );
Value = xSAT_ParseDimacs( pText, p );
ABC_FREE( pText );
return Value;
}
ABC_NAMESPACE_IMPL_END
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
/**CFile****************************************************************
FileName [xsatHeap.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [Heap implementation.]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
#ifndef ABC__sat__xSAT__xsatHeap_h
#define ABC__sat__xSAT__xsatHeap_h
#include "misc/util/abc_global.h"
#include "misc/vec/vecInt.h"
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct xSAT_Heap_t_ xSAT_Heap_t;
struct xSAT_Heap_t_
{
Vec_Int_t * vActivity;
Vec_Int_t * vIndices;
Vec_Int_t * vHeap;
};
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
inline int xSAT_HeapSize( xSAT_Heap_t * h )
{
return Vec_IntSize( h->vHeap );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
inline int xSAT_HeapInHeap( xSAT_Heap_t * h, int Var )
{
return ( Var < Vec_IntSize( h->vIndices ) ) && ( Vec_IntEntry( h->vIndices, Var ) >= 0 );
}
static inline int Left ( int i ) { return 2 * i + 1; }
static inline int Right ( int i ) { return ( i + 1 ) * 2; }
static inline int Parent( int i ) { return ( i - 1 ) >> 1; }
static inline int Compare( xSAT_Heap_t * p, int x, int y )
{
return ( unsigned )Vec_IntEntry( p->vActivity, x ) > ( unsigned )Vec_IntEntry( p->vActivity, y );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapPercolateUp( xSAT_Heap_t * h, int i )
{
int x = Vec_IntEntry( h->vHeap, i );
int p = Parent( i );
while ( i != 0 && Compare( h, x, Vec_IntEntry( h->vHeap, p ) ) )
{
Vec_IntWriteEntry( h->vHeap, i, Vec_IntEntry( h->vHeap, p ) );
Vec_IntWriteEntry( h->vIndices, Vec_IntEntry( h->vHeap, p ), i );
i = p;
p = Parent(p);
}
Vec_IntWriteEntry( h->vHeap, i, x );
Vec_IntWriteEntry( h->vIndices, x, i );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapPercolateDown( xSAT_Heap_t * h, int i )
{
int x = Vec_IntEntry( h->vHeap, i );
while ( Left( i ) < Vec_IntSize( h->vHeap ) )
{
int child = Right( i ) < Vec_IntSize( h->vHeap ) &&
Compare( h, Vec_IntEntry( h->vHeap, Right( i ) ), Vec_IntEntry( h->vHeap, Left( i ) ) ) ?
Right( i ) : Left( i );
if ( !Compare( h, Vec_IntEntry( h->vHeap, child ), x ) )
break;
Vec_IntWriteEntry( h->vHeap, i, Vec_IntEntry( h->vHeap, child ) );
Vec_IntWriteEntry( h->vIndices, Vec_IntEntry( h->vHeap, i ), i );
i = child;
}
Vec_IntWriteEntry( h->vHeap, i, x );
Vec_IntWriteEntry( h->vIndices, x, i );
}
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline xSAT_Heap_t * xSAT_HeapAlloc( Vec_Int_t * vActivity )
{
xSAT_Heap_t * p = ABC_ALLOC( xSAT_Heap_t, 1 );
p->vActivity = vActivity;
p->vIndices = Vec_IntAlloc( 0 );
p->vHeap = Vec_IntAlloc( 0 );
return p;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapFree( xSAT_Heap_t * p )
{
Vec_IntFree( p->vIndices );
Vec_IntFree( p->vHeap );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapIncrease( xSAT_Heap_t * h, int e )
{
assert( xSAT_HeapInHeap( h, e ) );
xSAT_HeapPercolateDown( h, Vec_IntEntry( h->vIndices, e ) );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapDecrease( xSAT_Heap_t * p, int e )
{
assert( xSAT_HeapInHeap( p, e ) );
xSAT_HeapPercolateUp( p , Vec_IntEntry( p->vIndices, e ) );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapInsert( xSAT_Heap_t * p, int n )
{
Vec_IntFillExtra( p->vIndices, n + 1, -1);
assert( !xSAT_HeapInHeap( p, n ) );
Vec_IntWriteEntry( p->vIndices, n, Vec_IntSize( p->vHeap ) );
Vec_IntPush( p->vHeap, n );
xSAT_HeapPercolateUp( p, Vec_IntEntry( p->vIndices, n ) );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapUpdate( xSAT_Heap_t * p, int i )
{
if ( !xSAT_HeapInHeap( p, i ) )
xSAT_HeapInsert( p, i );
else
{
xSAT_HeapPercolateUp( p, Vec_IntEntry( p->vIndices, i ) );
xSAT_HeapPercolateDown( p, Vec_IntEntry( p->vIndices, i ) );
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapBuild( xSAT_Heap_t * p, Vec_Int_t * Vars )
{
int i, Var;
Vec_IntForEachEntry( p->vHeap, Var, i )
Vec_IntWriteEntry( p->vIndices, Var, -1 );
Vec_IntClear( p->vHeap );
Vec_IntForEachEntry( Vars, Var, i )
{
Vec_IntWriteEntry( p->vIndices, Var, i );
Vec_IntPush( p->vHeap, Var );
}
for ( ( i = Vec_IntSize( p->vHeap ) / 2 - 1 ); i >= 0; i-- )
xSAT_HeapPercolateDown( p, i );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_HeapClear( xSAT_Heap_t * p )
{
Vec_IntFill( p->vIndices, Vec_IntSize( p->vIndices ), -1 );
Vec_IntClear( p->vHeap );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int xSAT_HeapRemoveMin( xSAT_Heap_t * p )
{
int x = Vec_IntEntry( p->vHeap, 0 );
Vec_IntWriteEntry( p->vHeap, 0, Vec_IntEntryLast( p->vHeap ) );
Vec_IntWriteEntry( p->vIndices, Vec_IntEntry( p->vHeap, 0), 0 );
Vec_IntWriteEntry( p->vIndices, x, -1 );
Vec_IntPop( p->vHeap );
if ( Vec_IntSize( p->vHeap ) > 1 )
xSAT_HeapPercolateDown( p, 0 );
return x;
}
ABC_NAMESPACE_HEADER_END
#endif
/**CFile****************************************************************
FileName [xsatMemory.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [Memory management implementation.]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
#ifndef ABC__sat__xSAT__xsatMemory_h
#define ABC__sat__xSAT__xsatMemory_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"
#include "xsatClause.h"
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct xSAT_Mem_t_ xSAT_Mem_t;
struct xSAT_Mem_t_
{
uint32_t nSize;
uint32_t nCap;
uint32_t nWasted;
uint32_t * pData;
};
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline xSAT_Clause_t * xSAT_MemClauseHand( xSAT_Mem_t * p, int h )
{
return h != UINT32_MAX ? ( xSAT_Clause_t * )( p->pData + h ) : NULL;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_MemGrow( xSAT_Mem_t * p, uint32_t nCap )
{
if ( p->nCap >= nCap )
return;
uint32_t nPrevCap = p->nCap;
while (p->nCap < nCap)
{
uint32_t delta = ((p->nCap >> 1) + (p->nCap >> 3) + 2) & ~1;
p->nCap += delta;
assert(p->nCap >= nPrevCap);
}
assert(p->nCap > 0);
p->pData = ABC_REALLOC(uint32_t, p->pData, p->nCap);
}
/**Function*************************************************************
Synopsis [Allocating vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline xSAT_Mem_t * xSAT_MemAlloc( int nCap )
{
xSAT_Mem_t * p;
p = ABC_CALLOC( xSAT_Mem_t, 1 );
if (nCap <= 0)
nCap = 1024*1024;
xSAT_MemGrow(p, nCap);
return p;
}
/**Function*************************************************************
Synopsis [Resetting vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_MemRestart( xSAT_Mem_t * p )
{
p->nSize = 0;
p->nWasted = 0;
}
/**Function*************************************************************
Synopsis [Freeing vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_MemFree( xSAT_Mem_t * p )
{
ABC_FREE( p->pData );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis [Creates new clause.]
Description [The resulting clause is fully initialized.]
SideEffects []
SeeAlso []
***********************************************************************/
static inline uint32_t xSAT_MemAppend( xSAT_Mem_t * p, int nSize )
{
assert(nSize > 0);
xSAT_MemGrow(p, p->nSize + nSize);
uint32_t nPrevSize = p->nSize;
p->nSize += nSize;
assert(p->nSize > nPrevSize);
return nPrevSize;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline uint32_t xSAT_MemCRef( xSAT_Mem_t * p, uint32_t * pC )
{
return ( uint32_t )( pC - &(p->pData[0]) );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline uint32_t xSAT_MemCap( xSAT_Mem_t * p )
{
return p->nCap;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline uint32_t xSAT_MemWastedCap( xSAT_Mem_t * p )
{
return p->nWasted;
}
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
/**CFile****************************************************************
FileName [xsatSolver.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [Internal definitions of the solver.]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
#ifndef ABC__sat__xSAT__xsatSolver_h
#define ABC__sat__xSAT__xsatSolver_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/util/abc_global.h"
#include "misc/vec/vecStr.h"
#include "xsat.h"
#include "xsatBQueue.h"
#include "xsatClause.h"
#include "xsatHeap.h"
#include "xsatMemory.h"
#include "xsatWatchList.h"
ABC_NAMESPACE_HEADER_START
#ifndef __cplusplus
#ifndef false
# define false 0
#endif
#ifndef true
# define true 1
#endif
#endif
enum
{
Var0 = 1,
Var1 = 0,
VarX = 3
};
enum
{
LBoolUndef = 0,
LBoolTrue = 1,
LBoolFalse = -1
};
enum
{
VarUndef = -1,
LitUndef = -2
};
#define CRefUndef UINT32_MAX
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct xSAT_SolverOptions_t_ xSAT_SolverOptions_t;
struct xSAT_SolverOptions_t_
{
char fVerbose;
// Limits
ABC_INT64_T nConfLimit; // external limit on the number of conflicts
ABC_INT64_T nInsLimit; // external limit on the number of implications
abctime nRuntimeLimit; // external limit on runtime
// Constants used for restart heuristic
double K; // Forces a restart
double R; // Block a restart
int nFirstBlockRestart; // Lower bound number of conflicts for start blocking restarts
int nSizeLBDQueue; // Size of the moving avarege queue for LBD (force restart)
int nSizeTrailQueue; // Size of the moving avarege queue for Trail size (block restart)
// Constants used for clause database reduction heuristic
int nConfFirstReduce; // Number of conflicts before first reduction
int nIncReduce; // Increment to reduce
int nSpecialIncReduce; // Special increment to reduce
unsigned nLBDFrozenClause;
};
typedef struct xSAT_Stats_t_ xSAT_Stats_t;
struct xSAT_Stats_t_
{
unsigned nStarts;
unsigned nReduceDB;
ABC_INT64_T nDecisions;
ABC_INT64_T nPropagations;
ABC_INT64_T nInspects;
ABC_INT64_T nConflicts;
ABC_INT64_T nClauseLits;
ABC_INT64_T nLearntLits;
};
struct xSAT_Solver_t_
{
/* Clauses Database */
xSAT_Mem_t * pMemory;
Vec_Int_t * vLearnts;
Vec_Int_t * vClauses;
xSAT_VecWatchList_t * vWatches;
xSAT_VecWatchList_t * vBinWatches;
/* Activity heuristic */
int nVarActInc; /* Amount to bump next variable with. */
int nClaActInc; /* Amount to bump next clause with. */
/* Variable Information */
Vec_Int_t * vActivity; /* A heuristic measurement of the activity of a variable. */
xSAT_Heap_t * hOrder;
Vec_Int_t * vLevels; /* Decision level of the current assignment */
Vec_Int_t * vReasons; /* Reason (clause) of the current assignment */
Vec_Str_t * vAssigns; /* Current assignment. */
Vec_Str_t * vPolarity;
Vec_Str_t * vTags;
/* Assignments */
Vec_Int_t * vTrail;
Vec_Int_t * vTrailLim; // Separator indices for different decision levels in 'trail'.
int iQhead; // Head of propagation queue (as index into the trail).
int nAssignSimplify; /* Number of top-level assignments since last
* execution of 'simplify()'. */
int64_t nPropSimplify; /* Remaining number of propagations that must be
* made before next execution of 'simplify()'. */
/* Temporary data used by Search method */
xSAT_BQueue_t * bqTrail;
xSAT_BQueue_t * bqLBD;
float nSumLBD;
int nConfBeforeReduce;
long nRC1;
int nRC2;
/* Temporary data used by Analyze */
Vec_Int_t * vLearntClause;
Vec_Str_t * vSeen;
Vec_Int_t * vTagged;
Vec_Int_t * vStack;
Vec_Int_t * vLastDLevel;
/* Misc temporary */
unsigned nStamp;
Vec_Int_t * vStamp; /* Multipurpose stamp used to calculate LBD and
* clauses minimization with binary resolution */
xSAT_SolverOptions_t Config;
xSAT_Stats_t Stats;
};
static inline int xSAT_Var2Lit( int Var, int c )
{
return Var + Var + ( c != 0 );
}
static inline int xSAT_NegLit( int Lit )
{
return Lit ^ 1;
}
static inline int xSAT_Lit2Var( int Lit )
{
return Lit >> 1;
}
static inline int xSAT_LitSign( int Lit )
{
return Lit & 1;
}
static inline int xSAT_SolverDecisionLevel( xSAT_Solver_t * s )
{
return Vec_IntSize( s->vTrailLim );
}
static inline xSAT_Clause_t * xSAT_SolverReadClause( xSAT_Solver_t * s, uint32_t h )
{
return xSAT_MemClauseHand( s->pMemory, h );
}
static inline int xSAT_SolverIsClauseSatisfied( xSAT_Solver_t * s, xSAT_Clause_t * pCla )
{
int * lits = &( pCla->pData[0].Lit );
for ( int i = 0; i < pCla->nSize; i++ )
if ( Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( lits[i] ) ) == xSAT_LitSign( ( lits[i] ) ) )
return true;
return false;
}
static inline void xSAT_SolverPrintClauses( xSAT_Solver_t * s )
{
int i;
unsigned CRef;
Vec_IntForEachEntry( s->vClauses, CRef, i )
xSAT_ClausePrint( xSAT_SolverReadClause( s, CRef ) );
}
static inline void xSAT_SolverPrintState( xSAT_Solver_t * s )
{
printf( "starts : %10d\n", s->Stats.nStarts );
printf( "conflicts : %10ld\n", s->Stats.nConflicts );
printf( "decisions : %10ld\n", s->Stats.nDecisions );
printf( "propagations : %10ld\n", s->Stats.nPropagations );
}
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
extern uint32_t xSAT_SolverClaNew( xSAT_Solver_t* s, Vec_Int_t * vLits, int fLearnt );
extern char xSAT_SolverSearch( xSAT_Solver_t * s );
extern void xSAT_SolverGarbageCollect( xSAT_Solver_t * s );
extern int xSAT_SolverEnqueue( xSAT_Solver_t* s, int Lit, uint32_t From );
extern void xSAT_SolverCancelUntil( xSAT_Solver_t* s, int Level);
extern uint32_t xSAT_SolverPropagate( xSAT_Solver_t* s );
extern void xSAT_SolverRebuildOrderHeap( xSAT_Solver_t* s );
ABC_NAMESPACE_HEADER_END
#endif
/**CFile****************************************************************
FileName [xsatUtils.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [Utility functions used in xSAT]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
#ifndef ABC__sat__xSAT__xsatUtils_h
#define ABC__sat__xSAT__xsatUtils_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"
ABC_NAMESPACE_HEADER_START
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_UtilSelectSort( void** pArray, int nSize, int(* CompFnct )( const void *, const void * ) )
{
int i, j, iBest;
void* pTmp;
for ( i = 0; i < ( nSize - 1 ); i++ )
{
iBest = i;
for ( j = i + 1; j < nSize; j++ )
{
if ( CompFnct( pArray[j], pArray[iBest] ) )
iBest = j;
}
pTmp = pArray[i];
pArray[i] = pArray[iBest];
pArray[iBest] = pTmp;
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static void xSAT_UtilSort( void** pArray, int nSize, int(* CompFnct )( const void *, const void *) )
{
if ( nSize <= 15 )
xSAT_UtilSelectSort( pArray, nSize, CompFnct );
else
{
void* pPivot = pArray[nSize / 2];
void* pTmp;
int i = -1;
int j = nSize;
for(;;)
{
do i++; while( CompFnct( pArray[i], pPivot ) );
do j--; while( CompFnct( pPivot, pArray[j] ) );
if ( i >= j )
break;
pTmp = pArray[i];
pArray[i] = pArray[j];
pArray[j] = pTmp;
}
xSAT_UtilSort( pArray, i, CompFnct );
xSAT_UtilSort( pArray + i, ( nSize - i ), CompFnct );
}
}
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
/**CFile****************************************************************
FileName [xsatWatchList.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [xSAT - A SAT solver written in C.
Read the license file for more info.]
Synopsis [Watch list and its related structures implementation]
Author [Bruno Schmitt <boschmitt@inf.ufrgs.br>]
Affiliation [UC Berkeley / UFRGS]
Date [Ver. 1.0. Started - November 10, 2016.]
Revision []
***********************************************************************/
#ifndef ABC__sat__xSAT__xsatWatchList_h
#define ABC__sat__xSAT__xsatWatchList_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct xSAT_Watcher_t_ xSAT_Watcher_t;
struct xSAT_Watcher_t_
{
uint32_t CRef;
int Blocker;
};
typedef struct xSAT_WatchList_t_ xSAT_WatchList_t;
struct xSAT_WatchList_t_
{
int nCap;
int nSize;
xSAT_Watcher_t * pArray;
};
typedef struct xSAT_VecWatchList_t_ xSAT_VecWatchList_t;
struct xSAT_VecWatchList_t_
{
int nCap;
int nSize;
xSAT_WatchList_t * pArray;
};
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_WatchListFree( xSAT_WatchList_t * v )
{
if ( v->pArray )
ABC_FREE( v->pArray );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int xSAT_WatchListSize( xSAT_WatchList_t * v )
{
return v->nSize;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_WatchListShrink( xSAT_WatchList_t * v, int k )
{
assert(k <= v->nSize);
v->nSize = k;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_WatchListPush( xSAT_WatchList_t * v, xSAT_Watcher_t e )
{
assert( v );
if (v->nSize == v->nCap)
{
int newsize = (v->nCap < 4) ? 4 : (v->nCap / 2) * 3;
v->pArray = ABC_REALLOC( xSAT_Watcher_t, v->pArray, newsize );
if ( v->pArray == NULL )
{
printf( "Failed to realloc memory from %.1f MB to %.1f MB.\n",
1.0 * v->nCap / (1<<20), 1.0 * newsize / (1<<20) );
fflush( stdout );
}
v->nCap = newsize;
}
v->pArray[v->nSize++] = e;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline xSAT_Watcher_t* xSAT_WatchListArray( xSAT_WatchList_t * v )
{
return v->pArray;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_WatchListRemove( xSAT_WatchList_t * v, uint32_t CRef )
{
xSAT_Watcher_t* ws = xSAT_WatchListArray(v);
int j = 0;
for (; ws[j].CRef != CRef; j++);
assert(j < xSAT_WatchListSize(v));
memmove(v->pArray + j, v->pArray + j + 1, (v->nSize - j - 1) * sizeof(xSAT_Watcher_t));
v->nSize -= 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline xSAT_VecWatchList_t * xSAT_VecWatchListAlloc( int nCap )
{
xSAT_VecWatchList_t * v = ABC_ALLOC( xSAT_VecWatchList_t, 1 );
v->nCap = 4;
v->nSize = 0;
v->pArray = (xSAT_WatchList_t *) ABC_CALLOC(xSAT_WatchList_t, sizeof( xSAT_WatchList_t ) * v->nCap);
return v;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_VecWatchListFree( xSAT_VecWatchList_t* v )
{
for( int i = 0; i < v->nSize; i++ )
xSAT_WatchListFree( v->pArray + i );
ABC_FREE( v->pArray );
ABC_FREE( v );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void xSAT_VecWatchListPush( xSAT_VecWatchList_t* v )
{
if ( v->nSize == v->nCap )
{
int newsize = (v->nCap < 4) ? v->nCap * 2 : (v->nCap / 2) * 3;
v->pArray = ABC_REALLOC( xSAT_WatchList_t, v->pArray, newsize );
memset( v->pArray + v->nCap, 0, sizeof(xSAT_WatchList_t) * (newsize - v->nCap) );
if ( v->pArray == NULL )
{
printf( "Failed to realloc memory from %.1f MB to %.1f MB.\n",
1.0 * v->nCap / (1<<20), 1.0 * newsize / (1<<20) );
fflush( stdout );
}
v->nCap = newsize;
}
v->nSize++;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline xSAT_WatchList_t * xSAT_VecWatchListEntry( xSAT_VecWatchList_t* v, int iEntry )
{
assert( iEntry < v->nCap );
assert( iEntry < v->nSize );
return v->pArray + iEntry;
}
ABC_NAMESPACE_HEADER_END
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment