Commit b1a913fb by Alan Mishchenko

Version abc70123

parent 2167d6c1
...@@ -12,7 +12,7 @@ MODULES := src/base/abc src/base/abci src/base/cmd src/base/io src/base/main src ...@@ -12,7 +12,7 @@ MODULES := src/base/abc src/base/abci src/base/cmd src/base/io src/base/main src
src/map/fpga src/map/mapper src/map/mio src/map/super src/map/if \ src/map/fpga src/map/mapper src/map/mio src/map/super src/map/if \
src/misc/extra src/misc/mvc src/misc/st src/misc/util src/misc/espresso src/misc/nm src/misc/vec src/misc/hash \ src/misc/extra src/misc/mvc src/misc/st src/misc/util src/misc/espresso src/misc/nm src/misc/vec src/misc/hash \
src/opt/cut src/opt/dec src/opt/fxu src/opt/rwr src/opt/sim src/opt/ret src/opt/res src/opt/kit \ src/opt/cut src/opt/dec src/opt/fxu src/opt/rwr src/opt/sim src/opt/ret src/opt/res src/opt/kit \
src/sat/asat src/sat/bsat src/sat/csat src/sat/msat src/sat/fraig src/sat/bsat src/sat/csat src/sat/msat src/sat/fraig
default: $(PROG) default: $(PROG)
......
...@@ -1145,42 +1145,6 @@ SOURCE=.\src\bdd\reo\reoUnits.c ...@@ -1145,42 +1145,6 @@ SOURCE=.\src\bdd\reo\reoUnits.c
# Begin Group "sat" # Begin Group "sat"
# PROP Default_Filter "" # PROP Default_Filter ""
# Begin Group "asat"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\src\sat\asat\added.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\asat\asatmem.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\asat\asatmem.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\asat\jfront.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\asat\satTrace.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\asat\solver.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\asat\solver.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\asat\solver_vec.h
# End Source File
# End Group
# Begin Group "msat" # Begin Group "msat"
# PROP Default_Filter "" # PROP Default_Filter ""
...@@ -1326,6 +1290,10 @@ SOURCE=.\src\sat\csat\csat_apis.h ...@@ -1326,6 +1290,10 @@ SOURCE=.\src\sat\csat\csat_apis.h
# PROP Default_Filter "" # PROP Default_Filter ""
# Begin Source File # Begin Source File
SOURCE=.\src\sat\bsat\satInter.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\bsat\satMem.c SOURCE=.\src\sat\bsat\satMem.c
# End Source File # End Source File
# Begin Source File # Begin Source File
...@@ -1342,6 +1310,18 @@ SOURCE=.\src\sat\bsat\satSolver.h ...@@ -1342,6 +1310,18 @@ SOURCE=.\src\sat\bsat\satSolver.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\src\sat\bsat\satStore.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\bsat\satStore.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\bsat\satTrace.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\bsat\satUtil.c SOURCE=.\src\sat\bsat\satUtil.c
# End Source File # End Source File
# Begin Source File # Begin Source File
......
...@@ -38,7 +38,6 @@ extern "C" { ...@@ -38,7 +38,6 @@ extern "C" {
#include "cuddInt.h" #include "cuddInt.h"
#include "hop.h" #include "hop.h"
#include "extra.h" #include "extra.h"
#include "solver.h"
#include "vec.h" #include "vec.h"
#include "stmm.h" #include "stmm.h"
#include "nm.h" #include "nm.h"
...@@ -118,6 +117,12 @@ typedef enum { ...@@ -118,6 +117,12 @@ typedef enum {
#endif #endif
#endif #endif
#ifdef _WIN32
typedef signed __int64 sint64; // compatible with MS VS 6.0
#else
typedef long long sint64;
#endif
typedef struct Abc_Lib_t_ Abc_Lib_t; typedef struct Abc_Lib_t_ Abc_Lib_t;
typedef struct Abc_Ntk_t_ Abc_Ntk_t; typedef struct Abc_Ntk_t_ Abc_Ntk_t;
typedef struct Abc_Obj_t_ Abc_Obj_t; typedef struct Abc_Obj_t_ Abc_Obj_t;
...@@ -725,8 +730,8 @@ extern int Abc_NtkRefactor( Abc_Ntk_t * pNtk, int nNodeSizeMax, i ...@@ -725,8 +730,8 @@ extern int Abc_NtkRefactor( Abc_Ntk_t * pNtk, int nNodeSizeMax, i
/*=== abcRewrite.c ==========================================================*/ /*=== abcRewrite.c ==========================================================*/
extern int Abc_NtkRewrite( Abc_Ntk_t * pNtk, int fUpdateLevel, int fUseZeros, int fVerbose, int fVeryVerbose ); extern int Abc_NtkRewrite( Abc_Ntk_t * pNtk, int fUpdateLevel, int fUseZeros, int fVerbose, int fVeryVerbose );
/*=== abcSat.c ==========================================================*/ /*=== abcSat.c ==========================================================*/
extern int Abc_NtkMiterSat( Abc_Ntk_t * pNtk, sint64 nConfLimit, sint64 nInsLimit, int fJFront, int fVerbose, sint64 * pNumConfs, sint64 * pNumInspects ); extern int Abc_NtkMiterSat( Abc_Ntk_t * pNtk, sint64 nConfLimit, sint64 nInsLimit, int fVerbose, sint64 * pNumConfs, sint64 * pNumInspects );
extern solver * Abc_NtkMiterSatCreate( Abc_Ntk_t * pNtk, int fJFront, int fAllPrimes ); extern void * Abc_NtkMiterSatCreate( Abc_Ntk_t * pNtk, int fAllPrimes );
/*=== abcSop.c ==========================================================*/ /*=== abcSop.c ==========================================================*/
extern char * Abc_SopRegister( Extra_MmFlex_t * pMan, char * pName ); extern char * Abc_SopRegister( Extra_MmFlex_t * pMan, char * pName );
extern char * Abc_SopStart( Extra_MmFlex_t * pMan, int nCubes, int nVars ); extern char * Abc_SopStart( Extra_MmFlex_t * pMan, int nCubes, int nVars );
...@@ -761,8 +766,6 @@ extern bool Abc_SopIsAndType( char * pSop ); ...@@ -761,8 +766,6 @@ extern bool Abc_SopIsAndType( char * pSop );
extern bool Abc_SopIsOrType( char * pSop ); extern bool Abc_SopIsOrType( char * pSop );
extern int Abc_SopIsExorType( char * pSop ); extern int Abc_SopIsExorType( char * pSop );
extern bool Abc_SopCheck( char * pSop, int nFanins ); extern bool Abc_SopCheck( char * pSop, int nFanins );
extern void Abc_SopWriteCnf( FILE * pFile, char * pClauses, Vec_Int_t * vVars );
extern void Abc_SopAddCnfToSolver( solver * pSat, char * pClauses, Vec_Int_t * vVars, Vec_Int_t * vTemp );
extern char * Abc_SopFromTruthBin( char * pTruth ); extern char * Abc_SopFromTruthBin( char * pTruth );
extern char * Abc_SopFromTruthHex( char * pTruth ); extern char * Abc_SopFromTruthHex( char * pTruth );
/*=== abcStrash.c ==========================================================*/ /*=== abcStrash.c ==========================================================*/
......
...@@ -799,77 +799,6 @@ bool Abc_SopCheck( char * pSop, int nFanins ) ...@@ -799,77 +799,6 @@ bool Abc_SopCheck( char * pSop, int nFanins )
return 1; return 1;
} }
/**Function*************************************************************
Synopsis [Writes the CNF of the SOP into file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_SopWriteCnf( FILE * pFile, char * pClauses, Vec_Int_t * vVars )
{
char * pChar;
int i;
// check the logic function of the node
for ( pChar = pClauses; *pChar; pChar++ )
{
// write the clause
for ( i = 0; i < vVars->nSize; i++, pChar++ )
if ( *pChar == '0' )
fprintf( pFile, "%d ", vVars->pArray[i] );
else if ( *pChar == '1' )
fprintf( pFile, "%d ", -vVars->pArray[i] );
fprintf( pFile, "0\n" );
// check that the remainig part is fine
assert( *pChar == ' ' );
pChar++;
assert( *pChar == '1' );
pChar++;
assert( *pChar == '\n' );
}
}
/**Function*************************************************************
Synopsis [Adds the clauses of for the CNF to the solver.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_SopAddCnfToSolver( solver * pSat, char * pClauses, Vec_Int_t * vVars, Vec_Int_t * vTemp )
{
char * pChar;
int i, RetValue;
// check the logic function of the node
for ( pChar = pClauses; *pChar; pChar++ )
{
// add the clause
vTemp->nSize = 0;
for ( i = 0; i < vVars->nSize; i++, pChar++ )
if ( *pChar == '0' )
Vec_IntPush( vTemp, toLit(vVars->pArray[i]) );
else if ( *pChar == '1' )
Vec_IntPush( vTemp, neg(toLit(vVars->pArray[i])) );
// add the clause to the solver
RetValue = solver_addclause( pSat, vTemp->pArray, vTemp->pArray + vTemp->nSize );
assert( RetValue != 1 );
// check that the remainig part is fine
assert( *pChar == ' ' );
pChar++;
assert( *pChar == '1' );
pChar++;
assert( *pChar == '\n' );
}
}
/**Function************************************************************* /**Function*************************************************************
......
...@@ -9206,7 +9206,6 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -9206,7 +9206,6 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Ntk_t * pNtk; Abc_Ntk_t * pNtk;
int c; int c;
int RetValue; int RetValue;
int fJFront;
int fVerbose; int fVerbose;
int nConfLimit; int nConfLimit;
int nInsLimit; int nInsLimit;
...@@ -9217,12 +9216,11 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -9217,12 +9216,11 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv )
pErr = Abc_FrameReadErr(pAbc); pErr = Abc_FrameReadErr(pAbc);
// set defaults // set defaults
fJFront = 0;
fVerbose = 0; fVerbose = 0;
nConfLimit = 100000; nConfLimit = 100000;
nInsLimit = 0; nInsLimit = 0;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "CIvjh" ) ) != EOF ) while ( ( c = Extra_UtilGetopt( argc, argv, "CIvh" ) ) != EOF )
{ {
switch ( c ) switch ( c )
{ {
...@@ -9248,9 +9246,6 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -9248,9 +9246,6 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( nInsLimit < 0 ) if ( nInsLimit < 0 )
goto usage; goto usage;
break; break;
case 'j':
fJFront ^= 1;
break;
case 'v': case 'v':
fVerbose ^= 1; fVerbose ^= 1;
break; break;
...@@ -9275,13 +9270,13 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -9275,13 +9270,13 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv )
clk = clock(); clk = clock();
if ( Abc_NtkIsStrash(pNtk) ) if ( Abc_NtkIsStrash(pNtk) )
{ {
RetValue = Abc_NtkMiterSat( pNtk, (sint64)nConfLimit, (sint64)nInsLimit, fJFront, fVerbose, NULL, NULL ); RetValue = Abc_NtkMiterSat( pNtk, (sint64)nConfLimit, (sint64)nInsLimit, fVerbose, NULL, NULL );
} }
else else
{ {
assert( Abc_NtkIsLogic(pNtk) ); assert( Abc_NtkIsLogic(pNtk) );
Abc_NtkLogicToBdd( pNtk ); Abc_NtkLogicToBdd( pNtk );
RetValue = Abc_NtkMiterSat( pNtk, (sint64)nConfLimit, (sint64)nInsLimit, fJFront, fVerbose, NULL, NULL ); RetValue = Abc_NtkMiterSat( pNtk, (sint64)nConfLimit, (sint64)nInsLimit, fVerbose, NULL, NULL );
} }
// verify that the pattern is correct // verify that the pattern is correct
...@@ -9316,12 +9311,11 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -9316,12 +9311,11 @@ int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0; return 0;
usage: usage:
fprintf( pErr, "usage: sat [-C num] [-I num] [-jvh]\n" ); fprintf( pErr, "usage: sat [-C num] [-I num] [-vh]\n" );
fprintf( pErr, "\t solves the combinational miter using SAT solver MiniSat-1.14\n" ); fprintf( pErr, "\t solves the combinational miter using SAT solver MiniSat-1.14\n" );
fprintf( pErr, "\t derives CNF from the current network and leave it unchanged\n" ); fprintf( pErr, "\t derives CNF from the current network and leave it unchanged\n" );
fprintf( pErr, "\t-C num : limit on the number of conflicts [default = %d]\n", nConfLimit ); fprintf( pErr, "\t-C num : limit on the number of conflicts [default = %d]\n", nConfLimit );
fprintf( pErr, "\t-I num : limit on the number of inspections [default = %d]\n", nInsLimit ); fprintf( pErr, "\t-I num : limit on the number of inspections [default = %d]\n", nInsLimit );
fprintf( pErr, "\t-j : toggle the use of J-frontier [default = %s]\n", fJFront? "yes": "no" );
fprintf( pErr, "\t-v : prints verbose information [default = %s]\n", fVerbose? "yes": "no" ); fprintf( pErr, "\t-v : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
fprintf( pErr, "\t-h : print the command usage\n"); fprintf( pErr, "\t-h : print the command usage\n");
return 1; return 1;
......
...@@ -491,7 +491,7 @@ int Abc_NtkIvyProve( Abc_Ntk_t ** ppNtk, void * pPars ) ...@@ -491,7 +491,7 @@ int Abc_NtkIvyProve( Abc_Ntk_t ** ppNtk, void * pPars )
} }
// if SAT only, solve without iteration // if SAT only, solve without iteration
RetValue = Abc_NtkMiterSat( pNtk, 2*(sint64)pParams->nMiteringLimitStart, (sint64)0, 0, 0, NULL, NULL ); RetValue = Abc_NtkMiterSat( pNtk, 2*(sint64)pParams->nMiteringLimitStart, (sint64)0, 0, NULL, NULL );
if ( RetValue >= 0 ) if ( RetValue >= 0 )
return RetValue; return RetValue;
......
...@@ -79,7 +79,7 @@ int Abc_NtkMiterProve( Abc_Ntk_t ** ppNtk, void * pPars ) ...@@ -79,7 +79,7 @@ int Abc_NtkMiterProve( Abc_Ntk_t ** ppNtk, void * pPars )
if ( !pParams->fUseRewriting && !pParams->fUseFraiging ) if ( !pParams->fUseRewriting && !pParams->fUseFraiging )
{ {
clk = clock(); clk = clock();
RetValue = Abc_NtkMiterSat( pNtk, (sint64)pParams->nMiteringLimitLast, (sint64)0, 0, 0, NULL, NULL ); RetValue = Abc_NtkMiterSat( pNtk, (sint64)pParams->nMiteringLimitLast, (sint64)0, 0, NULL, NULL );
Abc_NtkMiterPrint( pNtk, "SAT solving", clk, pParams->fVerbose ); Abc_NtkMiterPrint( pNtk, "SAT solving", clk, pParams->fVerbose );
*ppNtk = pNtk; *ppNtk = pNtk;
return RetValue; return RetValue;
...@@ -99,7 +99,7 @@ int Abc_NtkMiterProve( Abc_Ntk_t ** ppNtk, void * pPars ) ...@@ -99,7 +99,7 @@ int Abc_NtkMiterProve( Abc_Ntk_t ** ppNtk, void * pPars )
// try brute-force SAT // try brute-force SAT
clk = clock(); clk = clock();
nInspectLimit = pParams->nTotalInspectLimit? pParams->nTotalInspectLimit - pParams->nTotalInspectsMade : 0; nInspectLimit = pParams->nTotalInspectLimit? pParams->nTotalInspectLimit - pParams->nTotalInspectsMade : 0;
RetValue = Abc_NtkMiterSat( pNtk, (sint64)(pParams->nMiteringLimitStart * pow(pParams->nMiteringLimitMulti,nIter)), (sint64)nInspectLimit, 0, 0, &nSatConfs, &nSatInspects ); RetValue = Abc_NtkMiterSat( pNtk, (sint64)(pParams->nMiteringLimitStart * pow(pParams->nMiteringLimitMulti,nIter)), (sint64)nInspectLimit, 0, &nSatConfs, &nSatInspects );
Abc_NtkMiterPrint( pNtk, "SAT solving", clk, pParams->fVerbose ); Abc_NtkMiterPrint( pNtk, "SAT solving", clk, pParams->fVerbose );
if ( RetValue >= 0 ) if ( RetValue >= 0 )
break; break;
...@@ -213,7 +213,7 @@ int Abc_NtkMiterProve( Abc_Ntk_t ** ppNtk, void * pPars ) ...@@ -213,7 +213,7 @@ int Abc_NtkMiterProve( Abc_Ntk_t ** ppNtk, void * pPars )
} }
clk = clock(); clk = clock();
nInspectLimit = pParams->nTotalInspectLimit? pParams->nTotalInspectLimit - pParams->nTotalInspectsMade : 0; nInspectLimit = pParams->nTotalInspectLimit? pParams->nTotalInspectLimit - pParams->nTotalInspectsMade : 0;
RetValue = Abc_NtkMiterSat( pNtk, (sint64)pParams->nMiteringLimitLast, (sint64)nInspectLimit, 0, 0, NULL, NULL ); RetValue = Abc_NtkMiterSat( pNtk, (sint64)pParams->nMiteringLimitLast, (sint64)nInspectLimit, 0, NULL, NULL );
Abc_NtkMiterPrint( pNtk, "SAT solving", clk, pParams->fVerbose ); Abc_NtkMiterPrint( pNtk, "SAT solving", clk, pParams->fVerbose );
} }
......
...@@ -86,7 +86,7 @@ void Abc_NtkCecSat( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int nI ...@@ -86,7 +86,7 @@ void Abc_NtkCecSat( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int nI
} }
// solve the CNF using the SAT solver // solve the CNF using the SAT solver
RetValue = Abc_NtkMiterSat( pCnf, (sint64)nConfLimit, (sint64)nInsLimit, 0, 0, NULL, NULL ); RetValue = Abc_NtkMiterSat( pCnf, (sint64)nConfLimit, (sint64)nInsLimit, 0, NULL, NULL );
if ( RetValue == -1 ) if ( RetValue == -1 )
printf( "Networks are undecided (SAT solver timed out).\n" ); printf( "Networks are undecided (SAT solver timed out).\n" );
else if ( RetValue == 0 ) else if ( RetValue == 0 )
...@@ -268,7 +268,7 @@ void Abc_NtkSecSat( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int nI ...@@ -268,7 +268,7 @@ void Abc_NtkSecSat( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int nI
} }
// solve the CNF using the SAT solver // solve the CNF using the SAT solver
RetValue = Abc_NtkMiterSat( pCnf, (sint64)nConfLimit, (sint64)nInsLimit, 0, 0, NULL, NULL ); RetValue = Abc_NtkMiterSat( pCnf, (sint64)nConfLimit, (sint64)nInsLimit, 0, NULL, NULL );
if ( RetValue == -1 ) if ( RetValue == -1 )
printf( "Networks are undecided (SAT solver timed out).\n" ); printf( "Networks are undecided (SAT solver timed out).\n" );
else if ( RetValue == 0 ) else if ( RetValue == 0 )
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
***********************************************************************/ ***********************************************************************/
#include "io.h" #include "io.h"
#include "satSolver.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// DECLARATIONS /// /// DECLARATIONS ///
...@@ -43,7 +44,7 @@ static Abc_Ntk_t * s_pNtk = NULL; ...@@ -43,7 +44,7 @@ static Abc_Ntk_t * s_pNtk = NULL;
***********************************************************************/ ***********************************************************************/
int Io_WriteCnf( Abc_Ntk_t * pNtk, char * pFileName, int fAllPrimes ) int Io_WriteCnf( Abc_Ntk_t * pNtk, char * pFileName, int fAllPrimes )
{ {
solver * pSat; sat_solver * pSat;
if ( Abc_NtkIsStrash(pNtk) ) if ( Abc_NtkIsStrash(pNtk) )
printf( "Io_WriteCnf() warning: Generating CNF by applying heuristic AIG to CNF conversion.\n" ); printf( "Io_WriteCnf() warning: Generating CNF by applying heuristic AIG to CNF conversion.\n" );
else else
...@@ -67,7 +68,7 @@ int Io_WriteCnf( Abc_Ntk_t * pNtk, char * pFileName, int fAllPrimes ) ...@@ -67,7 +68,7 @@ int Io_WriteCnf( Abc_Ntk_t * pNtk, char * pFileName, int fAllPrimes )
if ( Abc_NtkIsLogic(pNtk) ) if ( Abc_NtkIsLogic(pNtk) )
Abc_NtkLogicToBdd( pNtk ); Abc_NtkLogicToBdd( pNtk );
// create solver with clauses // create solver with clauses
pSat = Abc_NtkMiterSatCreate( pNtk, 0, fAllPrimes ); pSat = Abc_NtkMiterSatCreate( pNtk, fAllPrimes );
if ( pSat == NULL ) if ( pSat == NULL )
{ {
fprintf( stdout, "The problem is trivially UNSAT. No CNF file is generated.\n" ); fprintf( stdout, "The problem is trivially UNSAT. No CNF file is generated.\n" );
...@@ -75,10 +76,10 @@ int Io_WriteCnf( Abc_Ntk_t * pNtk, char * pFileName, int fAllPrimes ) ...@@ -75,10 +76,10 @@ int Io_WriteCnf( Abc_Ntk_t * pNtk, char * pFileName, int fAllPrimes )
} }
// write the clauses // write the clauses
s_pNtk = pNtk; s_pNtk = pNtk;
Asat_SolverWriteDimacs( pSat, pFileName, 0, 0, 1 ); Sat_SolverWriteDimacs( pSat, pFileName, 0, 0, 1 );
s_pNtk = NULL; s_pNtk = NULL;
// free the solver // free the solver
solver_delete( pSat ); sat_solver_delete( pSat );
return 1; return 1;
} }
......
...@@ -93,9 +93,9 @@ static inline void Res_WinAddNode( Res_Win_t * p, Abc_Obj_t * pObj ) ...@@ -93,9 +93,9 @@ static inline void Res_WinAddNode( Res_Win_t * p, Abc_Obj_t * pObj )
extern void Res_WinDivisors( Res_Win_t * p, int nLevDivMax ); extern void Res_WinDivisors( Res_Win_t * p, int nLevDivMax );
extern int Res_WinVisitMffc( Res_Win_t * p ); extern int Res_WinVisitMffc( Res_Win_t * p );
/*=== resFilter.c ==========================================================*/ /*=== resFilter.c ==========================================================*/
extern Vec_Ptr_t * Res_FilterCandidates( Res_Win_t * pWin, Res_Sim_t * pSim ); extern Vec_Vec_t * Res_FilterCandidates( Res_Win_t * pWin, Res_Sim_t * pSim );
/*=== resSat.c ==========================================================*/ /*=== resSat.c ==========================================================*/
extern Hop_Obj_t * Res_SatFindFunction( Hop_Man_t * pMan, Res_Win_t * pWin, Vec_Ptr_t * vFanins, Abc_Ntk_t * pAig ); extern void * Res_SatProveUnsat( Abc_Ntk_t * pAig, Vec_Ptr_t * vFanins );
/*=== resSim.c ==========================================================*/ /*=== resSim.c ==========================================================*/
extern Res_Sim_t * Res_SimAlloc( int nWords ); extern Res_Sim_t * Res_SimAlloc( int nWords );
extern void Res_SimFree( Res_Sim_t * p ); extern void Res_SimFree( Res_Sim_t * p );
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "abc.h" #include "abc.h"
#include "res.h" #include "res.h"
#include "kit.h"
#include "satStore.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// DECLARATIONS /// /// DECLARATIONS ///
...@@ -42,15 +44,24 @@ ...@@ -42,15 +44,24 @@
***********************************************************************/ ***********************************************************************/
int Abc_NtkResynthesize( Abc_Ntk_t * pNtk, int nWindow, int nSimWords, int fVerbose, int fVeryVerbose ) int Abc_NtkResynthesize( Abc_Ntk_t * pNtk, int nWindow, int nSimWords, int fVerbose, int fVeryVerbose )
{ {
Int_Man_t * pMan;
Sto_Man_t * pCnf;
Res_Win_t * pWin; Res_Win_t * pWin;
Res_Sim_t * pSim; Res_Sim_t * pSim;
Abc_Ntk_t * pAig; Abc_Ntk_t * pAig;
Abc_Obj_t * pObj; Abc_Obj_t * pObj;
Hop_Obj_t * pFunc; Hop_Obj_t * pFunc;
Kit_Graph_t * pGraph;
Vec_Vec_t * vResubs;
Vec_Ptr_t * vFanins; Vec_Ptr_t * vFanins;
int i, nNodesOld; Vec_Int_t * vMemory;
unsigned * puTruth;
int i, k, nNodesOld, nFanins;
assert( Abc_NtkHasAig(pNtk) ); assert( Abc_NtkHasAig(pNtk) );
assert( nWindow > 0 && nWindow < 100 ); assert( nWindow > 0 && nWindow < 100 );
vMemory = Vec_IntAlloc(0);
// start the interpolation manager
pMan = Int_ManAlloc( 512 );
// start the window // start the window
pWin = Res_WinAlloc(); pWin = Res_WinAlloc();
pSim = Res_SimAlloc( nSimWords ); pSim = Res_SimAlloc( nSimWords );
...@@ -72,20 +83,44 @@ int Abc_NtkResynthesize( Abc_Ntk_t * pNtk, int nWindow, int nSimWords, int fVerb ...@@ -72,20 +83,44 @@ int Abc_NtkResynthesize( Abc_Ntk_t * pNtk, int nWindow, int nSimWords, int fVerb
// create the AIG for the window // create the AIG for the window
pAig = Res_WndStrash( pWin ); pAig = Res_WndStrash( pWin );
// prepare simulation info // prepare simulation info
if ( Res_SimPrepare( pSim, pAig ) ) if ( !Res_SimPrepare( pSim, pAig ) )
{ {
// find resub candidates for the node Abc_NtkDelete( pAig );
vFanins = Res_FilterCandidates( pWin, pSim ); continue;
// check using SAT }
pFunc = Res_SatFindFunction( pNtk->pManFunc, pWin, vFanins, pAig ); // find resub candidates for the node
// update the network vResubs = Res_FilterCandidates( pWin, pSim );
if ( pFunc == NULL ) if ( vResubs )
Res_UpdateNetwork( pObj, vFanins, pFunc, pWin->vLevels ); {
// iterate through the resubstitutions
Vec_VecForEachLevel( vResubs, vFanins, k )
{
extern Hop_Obj_t * Kit_GraphToHop( Hop_Man_t * pMan, Kit_Graph_t * pGraph );
pCnf = Res_SatProveUnsat( pAig, vFanins );
if ( pCnf == NULL )
continue;
// interplate this proof
nFanins = Int_ManInterpolate( pMan, pCnf, fVerbose, &puTruth );
assert( nFanins == Vec_PtrSize(vFanins) - 2 );
Sto_ManFree( pCnf );
// transform interpolant into the AIG
pGraph = Kit_TruthToGraph( puTruth, nFanins, vMemory );
// derive the AIG for the decomposition tree
pFunc = Kit_GraphToHop( pNtk->pManFunc, pGraph );
Kit_GraphFree( pGraph );
// update the network
if ( pFunc == NULL )
Res_UpdateNetwork( pObj, vFanins, pFunc, pWin->vLevels );
break;
}
Vec_VecFree( vResubs );
} }
Abc_NtkDelete( pAig ); Abc_NtkDelete( pAig );
} }
Res_WinFree( pWin ); Res_WinFree( pWin );
Res_SimFree( pSim ); Res_SimFree( pSim );
Int_ManFree( pMan );
Vec_IntFree( vMemory );
// check the resulting network // check the resulting network
if ( !Abc_NtkCheck( pNtk ) ) if ( !Abc_NtkCheck( pNtk ) )
{ {
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Vec_Ptr_t * Res_FilterCandidates( Res_Win_t * pWin, Res_Sim_t * pSim ) Vec_Vec_t * Res_FilterCandidates( Res_Win_t * pWin, Res_Sim_t * pSim )
{ {
unsigned * pInfo; unsigned * pInfo;
Abc_Obj_t * pFanin; Abc_Obj_t * pFanin;
......
...@@ -21,19 +21,116 @@ ...@@ -21,19 +21,116 @@
#include "abc.h" #include "abc.h"
#include "res.h" #include "res.h"
#include "hop.h" #include "hop.h"
//#include "bf.h" #include "satSolver.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// DECLARATIONS /// /// DECLARATIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
extern int Res_SatAddConst1( sat_solver * pSat, int iVar );
extern int Res_SatAddEqual( sat_solver * pSat, int iVar0, int iVar1, int fCompl );
extern int Res_SatAddAnd( sat_solver * pSat, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1 );
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS /// /// FUNCTION DEFINITIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/**Function************************************************************* /**Function*************************************************************
Synopsis [] Synopsis [Loads AIG into the SAT solver.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void * Res_SatProveUnsat( Abc_Ntk_t * pAig, Vec_Ptr_t * vFanins )
{
void * pCnf;
sat_solver * pSat;
Vec_Ptr_t * vNodes;
Abc_Obj_t * pObj;
int i, nNodes, status;
// make sure the constant node is not involved
assert( Abc_ObjFanoutNum(Abc_AigConst1(pAig)) == 0 );
// collect reachable nodes
vNodes = Abc_NtkDfsNodes( pAig, (Abc_Obj_t **)vFanins->pArray, vFanins->nSize );
// assign unique numbers to each node
nNodes = 0;
Abc_NtkForEachPi( pAig, pObj, i )
pObj->pCopy = (void *)nNodes++;
Vec_PtrForEachEntry( vNodes, pObj, i )
pObj->pCopy = (void *)nNodes++;
Vec_PtrForEachEntry( vFanins, pObj, i )
pObj->pCopy = (void *)nNodes++;
// start the solver
pSat = sat_solver_new();
sat_solver_store_alloc( pSat );
// add clause for AND gates
Vec_PtrForEachEntry( vNodes, pObj, i )
Res_SatAddAnd( pSat, (int)pObj->pCopy,
(int)Abc_ObjFanin0(pObj)->pCopy, (int)Abc_ObjFanin1(pObj)->pCopy, Abc_ObjFaninC0(pObj), Abc_ObjFaninC1(pObj) );
// add clauses for the POs
Vec_PtrForEachEntry( vFanins, pObj, i )
Res_SatAddEqual( pSat, (int)pObj->pCopy,
(int)Abc_ObjFanin0(pObj)->pCopy, Abc_ObjFaninC0(pObj) );
// add trivial clauses
pObj = Vec_PtrEntry(vFanins, 0);
Res_SatAddConst1( pSat, (int)pObj->pCopy );
pObj = Vec_PtrEntry(vFanins, 1);
Res_SatAddConst1( pSat, (int)pObj->pCopy );
// bookmark the clauses of A
sat_solver_store_mark_clauses_a( pSat );
// duplicate the clauses
pObj = Vec_PtrEntry(vFanins, 1);
Sat_SolverDoubleClauses( pSat, (int)pObj->pCopy );
// add the equality clauses
Vec_PtrForEachEntryStart( vFanins, pObj, i, 2 )
Res_SatAddEqual( pSat, (int)pObj->pCopy, ((int)pObj->pCopy) + nNodes, 0 );
// bookmark the roots
sat_solver_store_mark_roots( pSat );
Vec_PtrFree( vNodes );
// solve the problem
status = sat_solver_solve( pSat, NULL, NULL, (sint64)10000, (sint64)0, (sint64)0, (sint64)0 );
if ( status == l_False )
pCnf = sat_solver_store_release( pSat );
else if ( status == l_True )
pCnf = NULL;
else
pCnf = NULL;
sat_solver_delete( pSat );
return pCnf;
}
/**Function*************************************************************
Synopsis [Loads two-input AND-gate.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Res_SatAddConst1( sat_solver * pSat, int iVar )
{
lit Lit = lit_var(iVar);
if ( !sat_solver_addclause( pSat, &Lit, &Lit + 1 ) )
return 0;
return 1;
}
/**Function*************************************************************
Synopsis [Loads two-input AND-gate.]
Description [] Description []
...@@ -42,11 +139,56 @@ ...@@ -42,11 +139,56 @@
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Hop_Obj_t * Res_SatFindFunction( Hop_Man_t * pMan, Res_Win_t * pWin, Vec_Ptr_t * vFanins, Abc_Ntk_t * pAig ) int Res_SatAddEqual( sat_solver * pSat, int iVar0, int iVar1, int fCompl )
{ {
return NULL; lit Lits[2];
Lits[0] = toLitCond( iVar0, 0 );
Lits[1] = toLitCond( iVar1, !fCompl );
if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
return 0;
Lits[0] = toLitCond( iVar0, 1 );
Lits[1] = toLitCond( iVar1, fCompl );
if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
return 0;
return 1;
} }
/**Function*************************************************************
Synopsis [Loads two-input AND-gate.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Res_SatAddAnd( sat_solver * pSat, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1 )
{
lit Lits[3];
Lits[0] = toLitCond( iVar, 1 );
Lits[1] = toLitCond( iVar0, fCompl0 );
if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
return 0;
Lits[0] = toLitCond( iVar, 1 );
Lits[1] = toLitCond( iVar1, fCompl1 );
if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
return 0;
Lits[0] = toLitCond( iVar, 0 );
Lits[1] = toLitCond( iVar0, !fCompl0 );
Lits[2] = toLitCond( iVar1, !fCompl1 );
if ( !sat_solver_addclause( pSat, Lits, Lits + 3 ) )
return 0;
return 1;
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// END OF FILE /// /// END OF FILE ///
......
...@@ -57,7 +57,7 @@ Vec_Int_t * Abc_NtkRetimeInitialValues( Abc_Ntk_t * pNtkCone, Vec_Int_t * vValue ...@@ -57,7 +57,7 @@ Vec_Int_t * Abc_NtkRetimeInitialValues( Abc_Ntk_t * pNtkCone, Vec_Int_t * vValue
printf( "The miter for initial state computation has %d AIG nodes. ", Abc_NtkNodeNum(pNtkMiter) ); printf( "The miter for initial state computation has %d AIG nodes. ", Abc_NtkNodeNum(pNtkMiter) );
// solve the miter // solve the miter
clk = clock(); clk = clock();
RetValue = Abc_NtkMiterSat( pNtkMiter, (sint64)500000, (sint64)50000000, 0, 0, NULL, NULL ); RetValue = Abc_NtkMiterSat( pNtkMiter, (sint64)500000, (sint64)50000000, 0, NULL, NULL );
if ( fVerbose ) if ( fVerbose )
{ PRT( "SAT solving time", clock() - clk ); } { PRT( "SAT solving time", clock() - clk ); }
// analyze the result // analyze the result
......
/**CFile****************************************************************
FileName [added.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [C-language MiniSat solver.]
Synopsis [Additional SAT solver procedures.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: added.c,v 1.4 2005/09/16 22:55:03 casem Exp $]
***********************************************************************/
#include <stdio.h>
#include <assert.h>
#include "solver.h"
#include "extra.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
struct clause_t
{
int size_learnt;
lit lits[0];
};
static inline int clause_size (clause* c) { return c->size_learnt >> 1; }
static inline lit* clause_begin (clause* c) { return c->lits; }
static inline int lit_var(lit l) { return l >> 1; }
static inline int lit_sign(lit l) { return (l & 1); }
static void Asat_ClauseWriteDimacs( FILE * pFile, clause * pC, bool fIncrement );
extern void Io_WriteCnfOutputPiMapping( FILE * pFile, int incrementVars );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Write the clauses in the solver into a file in DIMACS format.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Asat_SolverWriteDimacs( solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars )
{
FILE * pFile;
void ** pClauses;
int nClauses, i;
// count the number of clauses
nClauses = p->clauses.size + p->learnts.size;
for ( i = 0; i < p->size; i++ )
if ( p->levels[i] == 0 && p->assigns[i] != l_Undef )
nClauses++;
// start the file
pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
{
printf( "Asat_SolverWriteDimacs(): Cannot open the ouput file.\n" );
return;
}
fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
// Io_WriteCnfOutputPiMapping( pFile, incrementVars );
fprintf( pFile, "p cnf %d %d\n", p->size, nClauses );
// write the original clauses
nClauses = p->clauses.size;
pClauses = p->clauses.ptr;
for ( i = 0; i < nClauses; i++ )
Asat_ClauseWriteDimacs( pFile, pClauses[i], incrementVars );
// write the learned clauses
nClauses = p->learnts.size;
pClauses = p->learnts.ptr;
for ( i = 0; i < nClauses; i++ )
Asat_ClauseWriteDimacs( pFile, pClauses[i], incrementVars );
// write zero-level assertions
for ( i = 0; i < p->size; i++ )
if ( p->levels[i] == 0 && p->assigns[i] != l_Undef )
fprintf( pFile, "%s%d%s\n",
(p->assigns[i] == l_False)? "-": "",
i + (int)(incrementVars>0),
(incrementVars) ? " 0" : "");
// write the assumptions
if (assumptionsBegin) {
for (; assumptionsBegin != assumptionsEnd; assumptionsBegin++) {
fprintf( pFile, "%s%d%s\n",
lit_sign(*assumptionsBegin)? "-": "",
lit_var(*assumptionsBegin) + (int)(incrementVars>0),
(incrementVars) ? " 0" : "");
}
}
fprintf( pFile, "\n" );
fclose( pFile );
}
/**Function*************************************************************
Synopsis [Writes the given clause in a file in DIMACS format.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Asat_ClauseWriteDimacs( FILE * pFile, clause * pC, bool fIncrement )
{
lit * pLits = clause_begin(pC);
int nLits = clause_size(pC);
int i;
for ( i = 0; i < nLits; i++ )
fprintf( pFile, "%s%d ", (lit_sign(pLits[i])? "-": ""), lit_var(pLits[i]) + (int)(fIncrement>0) );
if ( fIncrement )
fprintf( pFile, "0" );
fprintf( pFile, "\n" );
}
/**Function*************************************************************
Synopsis [Returns a counter-example.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int * solver_get_model( solver * p, int * pVars, int nVars )
{
int * pModel;
int i;
pModel = ALLOC( int, nVars );
for ( i = 0; i < nVars; i++ )
{
assert( pVars[i] >= 0 && pVars[i] < p->size );
pModel[i] = (int)(p->model.ptr[pVars[i]] == l_True);
}
return pModel;
}
/**Function*************************************************************
Synopsis [Writes the given clause in a file in DIMACS format.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Asat_SatPrintStats( FILE * pFile, solver * p )
{
printf( "Start = %4d. Conf = %6d. Dec = %6d. Prop = %7d. Insp = %8d.\n",
(int)p->solver_stats.starts,
(int)p->solver_stats.conflicts,
(int)p->solver_stats.decisions,
(int)p->solver_stats.propagations,
(int)p->solver_stats.inspects );
printf( "Total runtime = %7.2f sec. Var select = %7.2f sec. Var update = %7.2f sec.\n",
(float)(p->timeTotal)/(float)(CLOCKS_PER_SEC),
(float)(p->timeSelect)/(float)(CLOCKS_PER_SEC),
(float)(p->timeUpdate)/(float)(CLOCKS_PER_SEC) );
}
/**Function*************************************************************
Synopsis [Sets the preferred variables.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Asat_SolverSetPrefVars(solver * s, int * pPrefVars, int nPrefVars)
{
int i;
assert( s->pPrefVars == NULL );
for ( i = 0; i < nPrefVars; i++ )
assert( pPrefVars[i] < s->size );
s->pPrefVars = pPrefVars;
s->nPrefVars = nPrefVars;
}
/**Function*************************************************************
Synopsis [Sets the preferred variables.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Asat_SolverSetFactors(solver * s, float * pFactors)
{
assert( s->factors == NULL );
s->factors = pFactors;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
/**CFile****************************************************************
FileName [asatmem.h]
PackageName [SAT solver.]
Synopsis [Memory management.]
Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - January 1, 2004.]
Revision [$Id: asatmem.h,v 1.0 2004/01/01 1:00:00 alanmi Exp $]
***********************************************************************/
#ifndef __ASAT_MEM_H__
#define __ASAT_MEM_H__
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
//#include "leaks.h"
#include <stdio.h>
#include <stdlib.h>
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct Asat_MmFixed_t_ Asat_MmFixed_t;
typedef struct Asat_MmFlex_t_ Asat_MmFlex_t;
typedef struct Asat_MmStep_t_ Asat_MmStep_t;
////////////////////////////////////////////////////////////////////////
/// GLOBAL VARIABLES ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
// fixed-size-block memory manager
extern Asat_MmFixed_t * Asat_MmFixedStart( int nEntrySize );
extern void Asat_MmFixedStop( Asat_MmFixed_t * p, int fVerbose );
extern char * Asat_MmFixedEntryFetch( Asat_MmFixed_t * p );
extern void Asat_MmFixedEntryRecycle( Asat_MmFixed_t * p, char * pEntry );
extern void Asat_MmFixedRestart( Asat_MmFixed_t * p );
extern int Asat_MmFixedReadMemUsage( Asat_MmFixed_t * p );
// flexible-size-block memory manager
extern Asat_MmFlex_t * Asat_MmFlexStart();
extern void Asat_MmFlexStop( Asat_MmFlex_t * p, int fVerbose );
extern char * Asat_MmFlexEntryFetch( Asat_MmFlex_t * p, int nBytes );
extern int Asat_MmFlexReadMemUsage( Asat_MmFlex_t * p );
// hierarchical memory manager
extern Asat_MmStep_t * Asat_MmStepStart( int nSteps );
extern void Asat_MmStepStop( Asat_MmStep_t * p, int fVerbose );
extern char * Asat_MmStepEntryFetch( Asat_MmStep_t * p, int nBytes );
extern void Asat_MmStepEntryRecycle( Asat_MmStep_t * p, char * pEntry, int nBytes );
extern int Asat_MmStepReadMemUsage( Asat_MmStep_t * p );
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
/**************************************************************************************************
MiniSat -- Copyright (c) 2005, Niklas Sorensson
http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/
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.
**************************************************************************************************/
// Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko
#include "solver.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include <unistd.h>
//#include <signal.h>
//#include <zlib.h>
//#include <sys/time.h>
//#include <sys/resource.h>
//=================================================================================================
// Helpers:
// Reads an input stream to end-of-file and returns the result as a 'char*' terminated by '\0'
// (dynamic allocation in case 'in' is standard input).
//
char* readFile(FILE * in)
{
char* data = malloc(65536);
int cap = 65536;
int size = 0;
while (!feof(in)){
if (size == cap){
cap *= 2;
data = realloc(data, cap); }
size += fread(&data[size], 1, 65536, in);
}
data = realloc(data, size+1);
data[size] = '\0';
return data;
}
//static inline double cpuTime(void) {
// struct rusage ru;
// getrusage(RUSAGE_SELF, &ru);
// return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; }
//=================================================================================================
// DIMACS Parser:
static inline void skipWhitespace(char** in) {
while ((**in >= 9 && **in <= 13) || **in == 32)
(*in)++; }
static inline void skipLine(char** in) {
for (;;){
if (**in == 0) return;
if (**in == '\n') { (*in)++; return; }
(*in)++; } }
static inline int parseInt(char** in) {
int val = 0;
int _neg = 0;
skipWhitespace(in);
if (**in == '-') _neg = 1, (*in)++;
else if (**in == '+') (*in)++;
if (**in < '0' || **in > '9') fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", **in), exit(1);
while (**in >= '0' && **in <= '9')
val = val*10 + (**in - '0'),
(*in)++;
return _neg ? -val : val; }
static void readClause(char** in, solver* s, vec* lits) {
int parsed_lit, var;
vec_resize(lits,0);
for (;;){
parsed_lit = parseInt(in);
if (parsed_lit == 0) break;
var = abs(parsed_lit)-1;
vec_push(lits, (void*)(parsed_lit > 0 ? toLit(var) : neg(toLit(var))));
}
}
static lbool parse_DIMACS_main(char* in, solver* s) {
vec lits;
vec_new(&lits);
for (;;){
skipWhitespace(&in);
if (*in == 0)
break;
else if (*in == 'c' || *in == 'p')
skipLine(&in);
else{
lit* begin;
readClause(&in, s, &lits);
begin = (lit*)vec_begin(&lits);
if (solver_addclause(s, begin, begin+vec_size(&lits)) == l_False){
vec_delete(&lits);
return l_False;
}
}
}
vec_delete(&lits);
return solver_simplify(s);
}
// Inserts problem into solver. Returns FALSE upon immediate conflict.
//
static lbool parse_DIMACS(FILE * in, solver* s) {
char* text = readFile(in);
lbool ret = parse_DIMACS_main(text, s);
free(text);
return ret; }
//=================================================================================================
void printStats(stats* stats, int cpu_time)
{
double Time = (float)(cpu_time)/(float)(CLOCKS_PER_SEC);
printf("restarts : %12d\n", stats->starts);
printf("conflicts : %12.0f (%9.0f / sec )\n", (double)stats->conflicts , (double)stats->conflicts /Time);
printf("decisions : %12.0f (%9.0f / sec )\n", (double)stats->decisions , (double)stats->decisions /Time);
printf("propagations : %12.0f (%9.0f / sec )\n", (double)stats->propagations, (double)stats->propagations/Time);
printf("inspects : %12.0f (%9.0f / sec )\n", (double)stats->inspects , (double)stats->inspects /Time);
printf("conflict literals : %12.0f (%9.2f %% deleted )\n", (double)stats->tot_literals, (double)(stats->max_literals - stats->tot_literals) * 100.0 / (double)stats->max_literals);
printf("CPU time : %12.2f sec\n", Time);
}
//solver* slv;
//static void SIGINT_handler(int signum) {
// printf("\n"); printf("*** INTERRUPTED ***\n");
// printStats(&slv->stats, cpuTime());
// printf("\n"); printf("*** INTERRUPTED ***\n");
// exit(0); }
//=================================================================================================
int main(int argc, char** argv)
{
solver* s = solver_new();
lbool st;
FILE * in;
int clk = clock();
if (argc != 2)
fprintf(stderr, "ERROR! Not enough command line arguments.\n"),
exit(1);
in = fopen(argv[1], "rb");
if (in == NULL)
fprintf(stderr, "ERROR! Could not open file: %s\n", argc == 1 ? "<stdin>" : argv[1]),
exit(1);
st = parse_DIMACS(in, s);
fclose(in);
if (st == l_False){
solver_delete(s);
printf("Trivial problem\nUNSATISFIABLE\n");
exit(20);
}
s->verbosity = 1;
// slv = s;
// signal(SIGINT,SIGINT_handler);
st = solver_solve(s,0,0);
printStats(&s->stats, clock() - clk);
printf("\n");
printf(st == l_True ? "SATISFIABLE\n" : "UNSATISFIABLE\n");
solver_delete(s);
return 0;
}
SRC += src/sat/asat/added.c \
src/sat/asat/asatmem.c \
src/sat/asat/jfront.c \
src/sat/asat/solver.c
/**************************************************************************************************
MiniSat -- Copyright (c) 2005, Niklas Sorensson
http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/
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.
**************************************************************************************************/
// Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko
#ifndef solver_h
#define solver_h
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#define inline __inline // compatible with MS VS 6.0
#endif
#include "solver_vec.h"
#include "asatmem.h"
//=================================================================================================
// Simple types:
//typedef int bool;
#ifndef __cplusplus
#ifndef bool
#define bool int
#endif
#endif
typedef int lit;
typedef char lbool;
#ifdef _WIN32
typedef signed __int64 sint64; // compatible with MS VS 6.0
#else
typedef long long sint64;
#endif
static const int var_Undef = -1;
static const lit lit_Undef = -2;
static const lbool l_Undef = 0;
static const lbool l_True = 1;
static const lbool l_False = -1;
static inline lit neg (lit l) { return l ^ 1; }
static inline lit toLit (int v) { return v + v; }
static inline lit toLitCond (int v, int c) { return v + v + (int)(c != 0); }
//=================================================================================================
// Public interface:
typedef struct Asat_JMan_t_ Asat_JMan_t;
struct solver_t;
typedef struct solver_t solver;
extern solver* solver_new(void);
extern void solver_delete(solver* s);
extern bool solver_addclause(solver* s, lit* begin, lit* end);
extern bool solver_simplify(solver* s);
extern int solver_solve(solver* s, lit* begin, lit* end, sint64 nConfLimit, sint64 nInsLimit);
extern int * solver_get_model( solver * p, int * pVars, int nVars );
extern int solver_nvars(solver* s);
extern int solver_nclauses(solver* s);
// additional procedures
extern void Asat_SolverWriteDimacs( solver * pSat, char * pFileName,
lit* assumptionsBegin, lit* assumptionsEnd,
int incrementVars);
extern void Asat_SatPrintStats( FILE * pFile, solver * p );
extern void Asat_SolverSetPrefVars( solver * s, int * pPrefVars, int nPrefVars );
extern void Asat_SolverSetFactors( solver * s, float * pFactors );
// trace recording
extern void Sat_SolverTraceStart( solver * pSat, char * pName );
extern void Sat_SolverTraceStop( solver * pSat );
extern void Sat_SolverTraceWrite( solver * pSat, int * pBeg, int * pEnd, int fRoot );
// J-frontier support
extern Asat_JMan_t * Asat_JManStart( solver * pSat, void * vCircuit );
extern void Asat_JManStop( solver * pSat );
struct stats_t
{
sint64 starts, decisions, propagations, inspects, conflicts;
sint64 clauses, clauses_literals, learnts, learnts_literals, max_literals, tot_literals;
};
typedef struct stats_t stats;
//=================================================================================================
// Solver representation:
struct clause_t;
typedef struct clause_t clause;
struct solver_t
{
int size; // nof variables
int cap; // size of varmaps
int qhead; // Head index of queue.
int qtail; // Tail index of queue.
// clauses
vec clauses; // List of problem constraints. (contains: clause*)
vec learnts; // List of learnt clauses. (contains: clause*)
// activities
double var_inc; // Amount to bump next variable with.
double var_decay; // INVERSE decay factor for variable activity: stores 1/decay.
float cla_inc; // Amount to bump next clause with.
float cla_decay; // INVERSE decay factor for clause activity: stores 1/decay.
vec* wlists; //
double* activity; // A heuristic measurement of the activity of a variable.
float * factors; // the factor of variable activity
lbool* assigns; // Current values of variables.
int* orderpos; // Index in variable order.
clause** reasons; //
int* levels; //
lit* trail;
clause* binary; // A temporary binary clause
lbool* tags; //
veci tagged; // (contains: var)
veci stack; // (contains: var)
veci order; // Variable order. (heap) (contains: var)
veci trail_lim; // Separator indices for different decision levels in 'trail'. (contains: int)
veci model; // If problem is solved, this vector contains the model (contains: lbool).
int root_level; // Level of first proper decision.
int simpdb_assigns;// Number of top-level assignments at last 'simplifyDB()'.
int simpdb_props; // Number of propagations before next 'simplifyDB()'.
double random_seed;
double progress_estimate;
int verbosity; // Verbosity level. 0=silent, 1=some progress report, 2=everything
sint64 nConfLimit; // external limit on the number of conflicts
sint64 nInsLimit; // external limit on the number of implications
// the memory manager
Asat_MmStep_t * pMem;
// J-frontier
Asat_JMan_t * pJMan;
// for making decisions on some variables first
int nPrefDecNum;
int * pPrefVars;
int nPrefVars;
// solver statistics
stats solver_stats;
int timeTotal;
int timeSelect;
int timeUpdate;
// trace recording
FILE * pFile;
int nClauses;
int nRoots;
};
#ifdef __cplusplus
}
#endif
#endif
/**************************************************************************************************
MiniSat -- Copyright (c) 2005, Niklas Sorensson
http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/
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.
**************************************************************************************************/
// Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko
#ifndef vec_h
#define vec_h
#include <stdlib.h>
// vector of 32-bit intergers (added for 64-bit portability)
struct veci_t {
int size;
int cap;
int* ptr;
};
typedef struct veci_t veci;
static inline void veci_new (veci* v) {
v->size = 0;
v->cap = 4;
v->ptr = (int*)malloc(sizeof(int)*v->cap);
}
static inline void veci_delete (veci* v) { free(v->ptr); }
static inline int* veci_begin (veci* v) { return v->ptr; }
static inline int veci_size (veci* v) { return v->size; }
static inline void veci_resize (veci* v, int k) { v->size = k; } // only safe to shrink !!
static inline void veci_push (veci* v, int e)
{
if (v->size == v->cap) {
int newsize = v->cap * 2+1;
v->ptr = (int*)realloc(v->ptr,sizeof(int)*newsize);
v->cap = newsize; }
v->ptr[v->size++] = e;
}
// vector of 32- or 64-bit pointers
struct vec_t {
int size;
int cap;
void** ptr;
};
typedef struct vec_t vec;
static inline void vec_new (vec* v) {
v->size = 0;
v->cap = 4;
v->ptr = (void**)malloc(sizeof(void*)*v->cap);
}
static inline void vec_delete (vec* v) { free(v->ptr); }
static inline void** vec_begin (vec* v) { return v->ptr; }
static inline int vec_size (vec* v) { return v->size; }
static inline void vec_resize (vec* v, int k) { v->size = k; } // only safe to shrink !!
static inline void vec_push (vec* v, void* e)
{
if (v->size == v->cap) {
int newsize = v->cap * 2+1;
v->ptr = (void**)realloc(v->ptr,sizeof(void*)*newsize);
v->cap = newsize; }
v->ptr[v->size++] = e;
}
#endif
...@@ -477,6 +477,16 @@ static void sat_solver_record(sat_solver* s, veci* cls) ...@@ -477,6 +477,16 @@ static void sat_solver_record(sat_solver* s, veci* cls)
clause* c = (veci_size(cls) > 1) ? clause_new(s,begin,end,1) : (clause*)0; clause* c = (veci_size(cls) > 1) ? clause_new(s,begin,end,1) : (clause*)0;
enqueue(s,*begin,c); enqueue(s,*begin,c);
///////////////////////////////////
// add clause to internal storage
if ( s->pStore )
{
extern int Sto_ManAddClause( void * p, lit * pBeg, lit * pEnd );
int RetValue = Sto_ManAddClause( s->pStore, begin, end );
assert( RetValue );
}
///////////////////////////////////
assert(veci_size(cls) > 0); assert(veci_size(cls) > 0);
if (c != 0) { if (c != 0) {
...@@ -1022,6 +1032,7 @@ void sat_solver_delete(sat_solver* s) ...@@ -1022,6 +1032,7 @@ void sat_solver_delete(sat_solver* s)
free(s->tags ); free(s->tags );
} }
sat_solver_store_free(s);
free(s); free(s);
} }
...@@ -1046,6 +1057,7 @@ bool sat_solver_addclause(sat_solver* s, lit* begin, lit* end) ...@@ -1046,6 +1057,7 @@ bool sat_solver_addclause(sat_solver* s, lit* begin, lit* end)
*j = l; *j = l;
} }
sat_solver_setnvars(s,maxvar+1); sat_solver_setnvars(s,maxvar+1);
// sat_solver_setnvars(s, lit_var(*(end-1))+1 );
//printlits(begin,end); printf("\n"); //printlits(begin,end); printf("\n");
values = s->assigns; values = s->assigns;
...@@ -1065,7 +1077,18 @@ bool sat_solver_addclause(sat_solver* s, lit* begin, lit* end) ...@@ -1065,7 +1077,18 @@ bool sat_solver_addclause(sat_solver* s, lit* begin, lit* end)
if (j == begin) // empty clause if (j == begin) // empty clause
return false; return false;
else if (j - begin == 1) // unit clause
///////////////////////////////////
// add clause to internal storage
if ( s->pStore )
{
extern int Sto_ManAddClause( void * p, lit * pBeg, lit * pEnd );
int RetValue = Sto_ManAddClause( s->pStore, begin, j );
assert( RetValue );
}
///////////////////////////////////
if (j - begin == 1) // unit clause
return enqueue(s,*begin,(clause*)0); return enqueue(s,*begin,(clause*)0);
// create new clause // create new clause
...@@ -1198,6 +1221,15 @@ int sat_solver_solve(sat_solver* s, lit* begin, lit* end, sint64 nConfLimit, sin ...@@ -1198,6 +1221,15 @@ int sat_solver_solve(sat_solver* s, lit* begin, lit* end, sint64 nConfLimit, sin
printf("==============================================================================\n"); printf("==============================================================================\n");
sat_solver_canceluntil(s,0); sat_solver_canceluntil(s,0);
////////////////////////////////////////////////
if ( status == l_Undef && s->pStore )
{
extern int Sto_ManAddClause( void * p, lit * pBeg, lit * pEnd );
int RetValue = Sto_ManAddClause( s->pStore, NULL, NULL );
assert( RetValue );
}
////////////////////////////////////////////////
return status; return status;
} }
...@@ -1220,6 +1252,51 @@ int sat_solver_nconflicts(sat_solver* s) ...@@ -1220,6 +1252,51 @@ int sat_solver_nconflicts(sat_solver* s)
} }
//================================================================================================= //=================================================================================================
// Clause storage functions:
void sat_solver_store_alloc( sat_solver * s )
{
extern void * Sto_ManAlloc();
assert( s->pStore == NULL );
s->pStore = Sto_ManAlloc();
}
void sat_solver_store_write( sat_solver * s, char * pFileName )
{
extern void Sto_ManDumpClauses( void * p, char * pFileName );
Sto_ManDumpClauses( s->pStore, pFileName );
}
void sat_solver_store_free( sat_solver * s )
{
extern void Sto_ManFree( void * p );
if ( s->pStore ) Sto_ManFree( s->pStore );
s->pStore = NULL;
}
void sat_solver_store_mark_roots( sat_solver * s )
{
extern void Sto_ManMarkRoots( void * p );
if ( s->pStore ) Sto_ManMarkRoots( s->pStore );
}
void sat_solver_store_mark_clauses_a( sat_solver * s )
{
extern void Sto_ManMarkClausesA( void * p );
if ( s->pStore ) Sto_ManMarkClausesA( s->pStore );
}
void * sat_solver_store_release( sat_solver * s )
{
void * pTemp;
if ( s->pStore == NULL )
return NULL;
pTemp = s->pStore;
s->pStore = NULL;
return pTemp;
}
//=================================================================================================
// Sorting functions (sigh): // Sorting functions (sigh):
static inline void selectionsort(void** array, int size, int(*comp)(const void *, const void *)) static inline void selectionsort(void** array, int size, int(*comp)(const void *, const void *))
......
...@@ -33,7 +33,13 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA ...@@ -33,7 +33,13 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
// Simple types: // Simple types:
// does not work for c++ // does not work for c++
typedef int bool; //typedef int bool;
#ifndef __cplusplus
#ifndef bool
#define bool int
#endif
#endif
static const bool true = 1; static const bool true = 1;
static const bool false = 0; static const bool false = 0;
...@@ -58,6 +64,8 @@ static inline lit toLitCond(int v, int c) { return v + v + (c != 0); } ...@@ -58,6 +64,8 @@ static inline lit toLitCond(int v, int c) { return v + v + (c != 0); }
static inline lit lit_neg (lit l) { return l ^ 1; } static inline lit lit_neg (lit l) { return l ^ 1; }
static inline int lit_var (lit l) { return l >> 1; } static inline int lit_var (lit l) { return l >> 1; }
static inline int lit_sign (lit l) { return l & 1; } static inline int lit_sign (lit l) { return l & 1; }
static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
static inline lit lit_read (int s) { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }
//================================================================================================= //=================================================================================================
...@@ -88,6 +96,21 @@ typedef struct stats_t stats; ...@@ -88,6 +96,21 @@ typedef struct stats_t stats;
extern void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars ); extern void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars );
extern void Sat_SolverPrintStats( FILE * pFile, sat_solver * p ); extern void Sat_SolverPrintStats( FILE * pFile, sat_solver * p );
extern int * Sat_SolverGetModel( sat_solver * p, int * pVars, int nVars );
extern void Sat_SolverDoubleClauses( sat_solver * p, int iVar );
// trace recording
extern void Sat_SolverTraceStart( sat_solver * pSat, char * pName );
extern void Sat_SolverTraceStop( sat_solver * pSat );
extern void Sat_SolverTraceWrite( sat_solver * pSat, int * pBeg, int * pEnd, int fRoot );
// clause storage
extern void sat_solver_store_alloc( sat_solver * s );
extern void sat_solver_store_write( sat_solver * s, char * pFileName );
extern void sat_solver_store_free( sat_solver * s );
extern void sat_solver_store_mark_roots( sat_solver * s );
extern void sat_solver_store_mark_clauses_a( sat_solver * s );
extern void * sat_solver_store_release( sat_solver * s );
//================================================================================================= //=================================================================================================
// Solver representation: // Solver representation:
...@@ -146,6 +169,14 @@ struct sat_solver_t ...@@ -146,6 +169,14 @@ struct sat_solver_t
int nRestarts; // the number of local restarts int nRestarts; // the number of local restarts
Sat_MmStep_t * pMem; Sat_MmStep_t * pMem;
// clause store
void * pStore;
// trace recording
FILE * pFile;
int nClauses;
int nRoots;
}; };
#endif #endif
/**CFile****************************************************************
FileName [pr.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Proof recording.]
Synopsis [External declarations.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: pr.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef __PR_H__
#define __PR_H__
/*
The trace of SAT solving contains the original clause of the problem
along with the learned clauses derived during SAT solving.
The first line of the resulting file contains 3 numbers instead of 2:
c <num_vars> <num_all_clauses> <num_root_clauses>
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#define inline __inline // compatible with MS VS 6.0
#endif
#ifndef PRT
#define PRT(a,t) printf("%s = ", (a)); printf("%6.2f sec\n", (float)(t)/(float)(CLOCKS_PER_SEC))
#endif
#define STO_MAX(a,b) ((a) > (b) ? (a) : (b))
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////
typedef unsigned lit;
typedef struct Sto_Cls_t_ Sto_Cls_t;
struct Sto_Cls_t_
{
Sto_Cls_t * pNext; // the next clause
Sto_Cls_t * pNext0; // the next 0-watch
Sto_Cls_t * pNext1; // the next 0-watch
int Id; // the clause ID
unsigned fA : 1; // belongs to A
unsigned fRoot : 1; // original clause
unsigned fVisit : 1; // visited clause
unsigned nLits : 24; // the number of literals
lit pLits[0]; // literals of this clause
};
typedef struct Sto_Man_t_ Sto_Man_t;
struct Sto_Man_t_
{
// general data
int nVars; // the number of variables
int nRoots; // the number of root clauses
int nClauses; // the number of all clauses
int nClausesA; // the number of clauses of A
Sto_Cls_t * pHead; // the head clause
Sto_Cls_t * pTail; // the tail clause
Sto_Cls_t * pEmpty; // the empty clause
// memory management
int nChunkSize; // the number of bytes in a chunk
int nChunkUsed; // the number of bytes used in the last chunk
char * pChunkLast; // the last memory chunk
};
// variable/literal conversions (taken from MiniSat)
static inline lit toLit (int v) { return v + v; }
static inline lit toLitCond(int v, int c) { return v + v + (c != 0); }
static inline lit lit_neg (lit l) { return l ^ 1; }
static inline int lit_var (lit l) { return l >> 1; }
static inline int lit_sign (lit l) { return l & 1; }
static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
static inline lit lit_read (int s) { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }
static inline int lit_check(lit l, int n) { return l >= 0 && lit_var(l) < n; }
// iterators through the clauses
#define Sto_ManForEachClause( p, pCls ) for( pCls = p->pHead; pCls; pCls = pCls->pNext )
#define Sto_ManForEachClauseRoot( p, pCls ) for( pCls = p->pHead; pCls && pCls->fRoot; pCls = pCls->pNext )
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
/*=== satStore.c ==========================================================*/
extern Sto_Man_t * Sto_ManAlloc();
extern void Sto_ManFree( Sto_Man_t * p );
extern int Sto_ManAddClause( Sto_Man_t * p, lit * pBeg, lit * pEnd );
extern int Sto_ManMemoryReport( Sto_Man_t * p );
extern void Sto_ManMarkRoots( Sto_Man_t * p );
extern void Sto_ManMarkClausesA( Sto_Man_t * p );
/*=== satInter.c ==========================================================*/
typedef struct Int_Man_t_ Int_Man_t;
extern Int_Man_t * Int_ManAlloc( int nVarsAlloc );
extern void Int_ManFree( Int_Man_t * p );
extern int Int_ManInterpolate( Int_Man_t * p, Sto_Man_t * pCnf, int fVerbose, unsigned ** ppResult );
#ifdef __cplusplus
}
#endif
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
SystemName [ABC: Logic synthesis and verification system.] SystemName [ABC: Logic synthesis and verification system.]
PackageName [C-language MiniSat solver.] PackageName [SAT sat_solver.]
Synopsis [Records the trace of SAT solving in the CNF form.] Synopsis [Records the trace of SAT solving in the CNF form.]
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include "solver.h" #include "satSolver.h"
/* /*
The trace of SAT solving contains the original clause of the problem The trace of SAT solving contains the original clause of the problem
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
/// DECLARATIONS /// /// DECLARATIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
static inline int lit_var (lit l) { return l >> 1; }
static inline int lit_sign (lit l) { return l & 1; }
static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS /// /// FUNCTION DEFINITIONS ///
...@@ -52,7 +49,7 @@ static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : ...@@ -52,7 +49,7 @@ static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 :
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Sat_SolverTraceStart( solver * pSat, char * pName ) void Sat_SolverTraceStart( sat_solver * pSat, char * pName )
{ {
assert( pSat->pFile == NULL ); assert( pSat->pFile == NULL );
pSat->pFile = fopen( pName, "w" ); pSat->pFile = fopen( pName, "w" );
...@@ -72,12 +69,12 @@ void Sat_SolverTraceStart( solver * pSat, char * pName ) ...@@ -72,12 +69,12 @@ void Sat_SolverTraceStart( solver * pSat, char * pName )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Sat_SolverTraceStop( solver * pSat ) void Sat_SolverTraceStop( sat_solver * pSat )
{ {
if ( pSat->pFile == NULL ) if ( pSat->pFile == NULL )
return; return;
rewind( pSat->pFile ); rewind( pSat->pFile );
fprintf( pSat->pFile, "p %d %d %d", solver_nvars(pSat), pSat->nClauses, pSat->nRoots ); fprintf( pSat->pFile, "p %d %d %d", sat_solver_nvars(pSat), pSat->nClauses, pSat->nRoots );
fclose( pSat->pFile ); fclose( pSat->pFile );
pSat->pFile = NULL; pSat->pFile = NULL;
} }
...@@ -94,7 +91,7 @@ void Sat_SolverTraceStop( solver * pSat ) ...@@ -94,7 +91,7 @@ void Sat_SolverTraceStop( solver * pSat )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Sat_SolverTraceWrite( solver * pSat, int * pBeg, int * pEnd, int fRoot ) void Sat_SolverTraceWrite( sat_solver * pSat, int * pBeg, int * pEnd, int fRoot )
{ {
if ( pSat->pFile == NULL ) if ( pSat->pFile == NULL )
return; return;
......
...@@ -153,6 +153,77 @@ void Sat_SolverPrintStats( FILE * pFile, sat_solver * p ) ...@@ -153,6 +153,77 @@ void Sat_SolverPrintStats( FILE * pFile, sat_solver * p )
printf( "inspects : %d\n", (int)p->stats.inspects ); printf( "inspects : %d\n", (int)p->stats.inspects );
} }
/**Function*************************************************************
Synopsis [Returns a counter-example.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int * Sat_SolverGetModel( sat_solver * p, int * pVars, int nVars )
{
int * pModel;
int i;
pModel = ALLOC( int, nVars );
for ( i = 0; i < nVars; i++ )
{
assert( pVars[i] >= 0 && pVars[i] < p->size );
pModel[i] = (int)(p->model.ptr[pVars[i]] == l_True);
}
return pModel;
}
/**Function*************************************************************
Synopsis [Duplicates all clauses, complements unit clause of the given var.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sat_SolverDoubleClauses( sat_solver * p, int iVar )
{
clause ** pClauses;
lit Lit, * pLits;
int RetValue, nClauses, nVarsOld, nLitsOld, nLits, c, v;
// get the number of variables
nVarsOld = p->size;
nLitsOld = 2 * p->size;
// extend the solver to depend on two sets of variables
sat_solver_setnvars( p, 2 * p->size );
// duplicate implications
for ( v = 0; v < nVarsOld; v++ )
if ( p->assigns[v] != l_Undef )
{
Lit = nLitsOld + toLitCond( v, p->assigns[v]==l_False );
if ( v == iVar )
Lit = lit_neg(Lit);
RetValue = sat_solver_addclause( p, &Lit, &Lit + 1 );
assert( RetValue );
}
// duplicate clauses
nClauses = vecp_size(&p->clauses);
pClauses = (clause**)vecp_begin(&p->clauses);
for ( c = 0; c < nClauses; c++ )
{
nLits = clause_size(pClauses[c]);
pLits = clause_begin(pClauses[c]);
for ( v = 0; v < nLits; v++ )
pLits[v] += nLitsOld;
RetValue = sat_solver_addclause( p, pLits, pLits + nLits );
assert( RetValue );
for ( v = 0; v < nLits; v++ )
pLits[v] -= nLitsOld;
}
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// END OF FILE /// /// END OF FILE ///
......
...@@ -612,7 +612,7 @@ enum CSAT_StatusT ABC_Solve( ABC_Manager mng ) ...@@ -612,7 +612,7 @@ enum CSAT_StatusT ABC_Solve( ABC_Manager mng )
// try to prove the miter using a number of techniques // try to prove the miter using a number of techniques
if ( mng->mode ) if ( mng->mode )
RetValue = Abc_NtkMiterSat( mng->pTarget, (sint64)pParams->nMiteringLimitLast, (sint64)0, 0, 0, NULL, NULL ); RetValue = Abc_NtkMiterSat( mng->pTarget, (sint64)pParams->nMiteringLimitLast, (sint64)0, 0, NULL, NULL );
else else
// RetValue = Abc_NtkMiterProve( &mng->pTarget, pParams ); // old CEC engine // RetValue = Abc_NtkMiterProve( &mng->pTarget, pParams ); // old CEC engine
RetValue = Abc_NtkIvyProve( &mng->pTarget, pParams ); // new CEC engine RetValue = Abc_NtkIvyProve( &mng->pTarget, pParams ); // new CEC engine
......
...@@ -27,7 +27,11 @@ extern "C" { ...@@ -27,7 +27,11 @@ extern "C" {
/// INCLUDES /// /// INCLUDES ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
#include "solver.h" #ifdef _WIN32
typedef signed __int64 sint64; // compatible with MS VS 6.0
#else
typedef long long sint64;
#endif
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// PARAMETERS /// /// PARAMETERS ///
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
#include "vec.h" //#include "vec.h"
#include "pr.h" #include "pr.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
...@@ -150,7 +150,7 @@ Pr_Man_t * Pr_ManAlloc( int nVarsAlloc ) ...@@ -150,7 +150,7 @@ Pr_Man_t * Pr_ManAlloc( int nVarsAlloc )
// set the starting number of variables // set the starting number of variables
p->nVars = 0; p->nVars = 0;
// memory management // memory management
p->nChunkSize = (1<<18); // use 256K chunks p->nChunkSize = (1<<16); // use 64K chunks
// verification // verification
p->nResLitsAlloc = (1<<16); p->nResLitsAlloc = (1<<16);
p->pResLits = malloc( sizeof(lit) * p->nResLitsAlloc ); p->pResLits = malloc( sizeof(lit) * p->nResLitsAlloc );
...@@ -329,13 +329,6 @@ int Pr_ManAddClause( Pr_Man_t * p, lit * pBeg, lit * pEnd, int fRoot, int fClaus ...@@ -329,13 +329,6 @@ int Pr_ManAddClause( Pr_Man_t * p, lit * pBeg, lit * pEnd, int fRoot, int fClaus
printf( "More than one empty clause!\n" ); printf( "More than one empty clause!\n" );
p->pEmpty = pClause; p->pEmpty = pClause;
} }
// create watcher lists for the root clauses
if ( fRoot && pClause->nLits > 1 )
{
Pr_ManWatchClause( p, pClause, pClause->pLits[0] );
Pr_ManWatchClause( p, pClause, pClause->pLits[1] );
}
return 1; return 1;
} }
...@@ -388,6 +381,29 @@ void Pr_ManMemoryStop( Pr_Man_t * p ) ...@@ -388,6 +381,29 @@ void Pr_ManMemoryStop( Pr_Man_t * p )
/**Function************************************************************* /**Function*************************************************************
Synopsis [Reports memory usage in bytes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Pr_ManMemoryReport( Pr_Man_t * p )
{
int Total;
char * pMem, * pNext;
if ( p->pChunkLast == NULL )
return 0;
Total = p->nChunkUsed;
for ( pMem = p->pChunkLast; pNext = *(char **)pMem; pMem = pNext )
Total += p->nChunkSize;
return Total;
}
/**Function*************************************************************
Synopsis [Records the proof.] Synopsis [Records the proof.]
Description [] Description []
...@@ -688,6 +704,7 @@ int Pr_ManProofTraceOne( Pr_Man_t * p, Pr_Cls_t * pConflict, Pr_Cls_t * pFinal ) ...@@ -688,6 +704,7 @@ int Pr_ManProofTraceOne( Pr_Man_t * p, Pr_Cls_t * pConflict, Pr_Cls_t * pFinal )
Var = lit_var(p->pTrail[i]); Var = lit_var(p->pTrail[i]);
if ( !p->pSeens[Var] ) if ( !p->pSeens[Var] )
continue; continue;
p->pSeens[Var] = 0;
// skip literals of the resulting clause // skip literals of the resulting clause
pReason = p->pReasons[Var]; pReason = p->pReasons[Var];
...@@ -695,6 +712,11 @@ int Pr_ManProofTraceOne( Pr_Man_t * p, Pr_Cls_t * pConflict, Pr_Cls_t * pFinal ) ...@@ -695,6 +712,11 @@ int Pr_ManProofTraceOne( Pr_Man_t * p, Pr_Cls_t * pConflict, Pr_Cls_t * pFinal )
continue; continue;
assert( p->pTrail[i] == pReason->pLits[0] ); assert( p->pTrail[i] == pReason->pLits[0] );
// add the variables to seen
for ( v = 1; v < (int)pReason->nLits; v++ )
p->pSeens[lit_var(pReason->pLits[v])] = 1;
// record the reason clause // record the reason clause
assert( pReason->pProof > 0 ); assert( pReason->pProof > 0 );
p->Counter++; p->Counter++;
...@@ -751,16 +773,15 @@ int Pr_ManProofTraceOne( Pr_Man_t * p, Pr_Cls_t * pConflict, Pr_Cls_t * pFinal ) ...@@ -751,16 +773,15 @@ int Pr_ManProofTraceOne( Pr_Man_t * p, Pr_Cls_t * pConflict, Pr_Cls_t * pFinal )
} }
} }
// add the variables to seen
for ( v = 1; v < (int)pReason->nLits; v++ )
p->pSeens[lit_var(pReason->pLits[v])] = 1;
// Vec_PtrPush( pFinal->pAntis, pReason ); // Vec_PtrPush( pFinal->pAntis, pReason );
} }
// unmark all seen variables // unmark all seen variables
for ( i = p->nTrailSize - 1; i >= 0; i-- ) // for ( i = p->nTrailSize - 1; i >= 0; i-- )
p->pSeens[lit_var(p->pTrail[i])] = 0; // p->pSeens[lit_var(p->pTrail[i])] = 0;
// check that the literals are unmarked
// for ( i = p->nTrailSize - 1; i >= 0; i-- )
// assert( p->pSeens[lit_var(p->pTrail[i])] == 0 );
// use the resulting clause to check the correctness of resolution // use the resulting clause to check the correctness of resolution
if ( p->fProofVerif ) if ( p->fProofVerif )
...@@ -904,6 +925,12 @@ int Pr_ManProcessRoots( Pr_Man_t * p ) ...@@ -904,6 +925,12 @@ int Pr_ManProcessRoots( Pr_Man_t * p )
p->nTrailSize = 0; p->nTrailSize = 0;
Pr_ManForEachClauseRoot( p, pClause ) Pr_ManForEachClauseRoot( p, pClause )
{ {
// create watcher lists for the root clauses
if ( pClause->nLits > 1 )
{
Pr_ManWatchClause( p, pClause, pClause->pLits[0] );
Pr_ManWatchClause( p, pClause, pClause->pLits[1] );
}
// empty clause and large clauses // empty clause and large clauses
if ( pClause->nLits != 1 ) if ( pClause->nLits != 1 )
continue; continue;
...@@ -1218,9 +1245,10 @@ p->timeRead = clock() - clk; ...@@ -1218,9 +1245,10 @@ p->timeRead = clock() - clk;
1.0*(p->Counter-p->nRoots)/(p->nClauses-p->nRoots), 1.0*(p->Counter-p->nRoots)/(p->nClauses-p->nRoots),
nUsed, 1.0*nUsed/(p->nClauses-p->nRoots) ); nUsed, 1.0*nUsed/(p->nClauses-p->nRoots) );
*/ */
printf( "Vars = %d. Roots = %d. Learned = %d. Resolution steps = %d. Ave = %.2f.\n", printf( "Vars = %d. Roots = %d. Learned = %d. Resol steps = %d. Ave = %.2f. Mem = %.2f Mb\n",
p->nVars, p->nRoots, p->nClauses-p->nRoots, p->Counter, p->nVars, p->nRoots, p->nClauses-p->nRoots, p->Counter,
1.0*(p->Counter-p->nRoots)/(p->nClauses-p->nRoots) ); 1.0*(p->Counter-p->nRoots)/(p->nClauses-p->nRoots),
1.0*Pr_ManMemoryReport(p)/(1<<20) );
p->timeTotal = clock() - clkTotal; p->timeTotal = clock() - clkTotal;
Pr_ManFree( p ); Pr_ManFree( p );
......
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