diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2017-09-06 17:57:44 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2017-09-06 17:57:44 -0700 |
commit | f68bd519c69dabfe0c507810d84d3289e082947e (patch) | |
tree | 8475dee53e0bb4cb66db9eccc9f316c304f2a6ba /src/sat/glucose | |
parent | 8063887ffe8528bb5100b3ede7400956eefa4d53 (diff) | |
download | abc-f68bd519c69dabfe0c507810d84d3289e082947e.tar.gz abc-f68bd519c69dabfe0c507810d84d3289e082947e.tar.bz2 abc-f68bd519c69dabfe0c507810d84d3289e082947e.zip |
Integrating Glucose into &bmcs -g.
Diffstat (limited to 'src/sat/glucose')
-rw-r--r-- | src/sat/glucose/AbcGlucose.cpp | 92 | ||||
-rw-r--r-- | src/sat/glucose/AbcGlucose.h | 37 | ||||
-rw-r--r-- | src/sat/glucose/AbcGlucoseCmd.cpp | 13 | ||||
-rw-r--r-- | src/sat/glucose/Glucose.cpp | 14 |
4 files changed, 119 insertions, 37 deletions
diff --git a/src/sat/glucose/AbcGlucose.cpp b/src/sat/glucose/AbcGlucose.cpp index 7601ac39..b5c6b592 100644 --- a/src/sat/glucose/AbcGlucose.cpp +++ b/src/sat/glucose/AbcGlucose.cpp @@ -81,12 +81,11 @@ int glucose_solver_addclause(Glucose::Solver* S, int * plits, int nlits) return S->addClause(lits); // returns 0 if the problem is UNSAT } -int glucose_solver_setcallback(Glucose::Solver* S, void * pman, int(*pfunc)(void*, int, int*)) +void glucose_solver_setcallback(Glucose::Solver* S, void * pman, int(*pfunc)(void*, int, int*)) { S->pCnfMan = pman; S->pCnfFunc = pfunc; S->nCallConfl = 1000; - return 0; } int glucose_solver_solve(Glucose::Solver* S, int * plits, int nlits) @@ -141,6 +140,73 @@ void glucose_print_stats(Solver& s, abctime clk) /**Function************************************************************* + Synopsis [Wrapper APIs to calling from ABC.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +bmcg_sat_solver * bmcg_sat_solver_start() +{ + return (bmcg_sat_solver *)glucose_solver_start(); +} +void bmcg_sat_solver_stop(bmcg_sat_solver* s) +{ + glucose_solver_stop((Glucose::Solver*)s); +} + +int bmcg_sat_solver_addclause(bmcg_sat_solver* s, int * plits, int nlits) +{ + return glucose_solver_addclause((Glucose::Solver*)s,plits,nlits); +} + +void bmcg_sat_solver_setcallback(bmcg_sat_solver* s, void * pman, int(*pfunc)(void*, int, int*)) +{ + glucose_solver_setcallback((Glucose::Solver*)s,pman,pfunc); +} + +int bmcg_sat_solver_solve(bmcg_sat_solver* s, int * plits, int nlits) +{ + return glucose_solver_solve((Glucose::Solver*)s,plits,nlits); +} + +int bmcg_sat_solver_addvar(bmcg_sat_solver* s) +{ + return glucose_solver_addvar((Glucose::Solver*)s); +} + +int bmcg_sat_solver_read_cex_varvalue(bmcg_sat_solver* s, int ivar) +{ + return glucose_solver_read_cex_varvalue((Glucose::Solver*)s, ivar); +} + +void bmcg_sat_solver_setstop(bmcg_sat_solver* s, int * pstop) +{ + glucose_solver_setstop((Glucose::Solver*)s, pstop); +} + +int bmcg_sat_solver_varnum(bmcg_sat_solver* s) +{ + return ((Glucose::Solver*)s)->nVars(); +} +int bmcg_sat_solver_clausenum(bmcg_sat_solver* s) +{ + return ((Glucose::Solver*)s)->nClauses(); +} +int bmcg_sat_solver_learntnum(bmcg_sat_solver* s) +{ + return ((Glucose::Solver*)s)->nLearnts(); +} +int bmcg_sat_solver_conflictnum(bmcg_sat_solver* s) +{ + return ((Glucose::Solver*)s)->conflicts; +} + +/**Function************************************************************* + Synopsis [] Description [] @@ -150,9 +216,10 @@ void glucose_print_stats(Solver& s, abctime clk) SeeAlso [] ***********************************************************************/ -void Glucose_SolveCnf( char * pFilename, ExtSat_Pars * pPars ) +void Glucose_SolveCnf( char * pFilename, Glucose_Pars * pPars ) { abctime clk = Abc_Clock(); + SimpSolver S; S.verbosity = pPars->verb; S.setConfBudget( pPars->nConfls > 0 ? (int64_t)pPars->nConfls : -1 ); @@ -161,10 +228,13 @@ void Glucose_SolveCnf( char * pFilename, ExtSat_Pars * pPars ) parse_DIMACS(in, S); gzclose(in); - printf("c ============================[ Problem Statistics ]=============================\n"); - printf("c | |\n"); - printf("c | Number of variables: %12d |\n", S.nVars()); - printf("c | Number of clauses: %12d |\n", S.nClauses()); + if ( pPars->verb ) + { + printf("c ============================[ Problem Statistics ]=============================\n"); + printf("c | |\n"); + printf("c | Number of variables: %12d |\n", S.nVars()); + printf("c | Number of clauses: %12d |\n", S.nClauses()); + } if ( pPars->pre ) S.eliminate(true); @@ -172,7 +242,7 @@ void Glucose_SolveCnf( char * pFilename, ExtSat_Pars * pPars ) lbool ret = S.solveLimited(dummy); if ( pPars->verb ) glucose_print_stats(S, Abc_Clock() - clk); printf(ret == l_True ? "SATISFIABLE" : ret == l_False ? "UNSATISFIABLE" : "INDETERMINATE"); - Abc_PrintTime( 1, " Time", Abc_Clock() - clk ); + Abc_PrintTime( 1, " Time", Abc_Clock() - clk ); } /**Function************************************************************* @@ -188,7 +258,7 @@ void Glucose_SolveCnf( char * pFilename, ExtSat_Pars * pPars ) ***********************************************************************/ Vec_Int_t * Glucose_SolverFromAig( Gia_Man_t * p, SimpSolver& S ) { - abctime clk = Abc_Clock(); + //abctime clk = Abc_Clock(); int * pLit, * pStop, i; Cnf_Dat_t * pCnf = (Cnf_Dat_t *)Mf_ManGenerateCnf( p, 8 /*nLutSize*/, 0 /*fCnfObjIds*/, 1/*fAddOrCla*/, 0, 0/*verbose*/ ); for ( i = 0; i < pCnf->nClauses; i++ ) @@ -211,7 +281,7 @@ Vec_Int_t * Glucose_SolverFromAig( Gia_Man_t * p, SimpSolver& S ) return vCnfIds; } -int Glucose_SolveAig(Gia_Man_t * p, ExtSat_Pars * pPars) +int Glucose_SolveAig(Gia_Man_t * p, Glucose_Pars * pPars) { abctime clk = Abc_Clock(); @@ -241,7 +311,7 @@ int Glucose_SolveAig(Gia_Man_t * p, ExtSat_Pars * pPars) if ( pPars->verb ) glucose_print_stats(S, Abc_Clock() - clk); printf(ret == l_True ? "SATISFIABLE" : ret == l_False ? "UNSATISFIABLE" : "INDETERMINATE"); - Abc_PrintTime( 1, " Time", Abc_Clock() - clk ); + Abc_PrintTime( 1, " Time", Abc_Clock() - clk ); // port counterexample if (ret == l_True) diff --git a/src/sat/glucose/AbcGlucose.h b/src/sat/glucose/AbcGlucose.h index 68f793dd..92a6594e 100644 --- a/src/sat/glucose/AbcGlucose.h +++ b/src/sat/glucose/AbcGlucose.h @@ -18,8 +18,8 @@ ***********************************************************************/ -#ifndef SRC_EXTSAT_GLUCOSE_ABC_H_ -#define SRC_EXTSAT_GLUCOSE_ABC_H_ +#ifndef ABC_SAT_GLUCOSE_H_ +#define ABC_SAT_GLUCOSE_H_ //////////////////////////////////////////////////////////////////////// /// INCLUDES /// @@ -37,24 +37,26 @@ ABC_NAMESPACE_HEADER_START /// BASIC TYPES /// //////////////////////////////////////////////////////////////////////// -typedef struct ExtSat_Pars_ ExtSat_Pars; -struct ExtSat_Pars_ { +typedef struct Glucose_Pars_ Glucose_Pars; +struct Glucose_Pars_ { int pre; // preprocessing int verb; // verbosity int cust; // customizable int nConfls; // conflict limit (0 = no limit) }; -static inline ExtSat_Pars ExtSat_CreatePars(int p, int v, int c, int nConfls) +static inline Glucose_Pars Glucose_CreatePars(int p, int v, int c, int nConfls) { - ExtSat_Pars pars; - pars.pre = p; - pars.verb = v; - pars.cust = c; + Glucose_Pars pars; + pars.pre = p; + pars.verb = v; + pars.cust = c; pars.nConfls = nConfls; return pars; } +typedef void bmcg_sat_solver; + //////////////////////////////////////////////////////////////////////// /// MACRO DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -63,8 +65,21 @@ static inline ExtSat_Pars ExtSat_CreatePars(int p, int v, int c, int nConfls) /// FUNCTION DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -extern void Glucose_SolveCnf( char * pFilename, ExtSat_Pars * pPars ); -extern int Glucose_SolveAig( Gia_Man_t * p, ExtSat_Pars * pPars ); +extern bmcg_sat_solver * bmcg_sat_solver_start(); +extern void bmcg_sat_solver_stop( bmcg_sat_solver* s ); +extern int bmcg_sat_solver_addclause( bmcg_sat_solver* s, int * plits, int nlits ); +extern void bmcg_sat_solver_setcallback( bmcg_sat_solver* s, void * pman, int(*pfunc)(void*, int, int*) ); +extern int bmcg_sat_solver_solve( bmcg_sat_solver* s, int * plits, int nlits ); +extern int bmcg_sat_solver_addvar( bmcg_sat_solver* s ); +extern int bmcg_sat_solver_read_cex_varvalue( bmcg_sat_solver* s, int ); +extern void bmcg_sat_solver_setstop( bmcg_sat_solver* s, int * ); +extern int bmcg_sat_solver_varnum(bmcg_sat_solver* s); +extern int bmcg_sat_solver_clausenum(bmcg_sat_solver* s); +extern int bmcg_sat_solver_learntnum(bmcg_sat_solver* s); +extern int bmcg_sat_solver_conflictnum(bmcg_sat_solver* s); + +extern void Glucose_SolveCnf( char * pFilename, Glucose_Pars * pPars ); +extern int Glucose_SolveAig( Gia_Man_t * p, Glucose_Pars * pPars ); ABC_NAMESPACE_HEADER_END diff --git a/src/sat/glucose/AbcGlucoseCmd.cpp b/src/sat/glucose/AbcGlucoseCmd.cpp index 80fdb77f..8dbe3790 100644 --- a/src/sat/glucose/AbcGlucoseCmd.cpp +++ b/src/sat/glucose/AbcGlucoseCmd.cpp @@ -72,15 +72,12 @@ void Glucose_End( Abc_Frame_t * pAbc ) ***********************************************************************/ int Abc_CommandGlucose( Abc_Frame_t * pAbc, int argc, char ** argv ) { - extern void Glucose_SolveCnf( char * pFilename, ExtSat_Pars * pPars ); - extern int Glucose_SolveAig( Gia_Man_t * p, ExtSat_Pars * pPars ); - - int c = 0; - int pre = 1; - int verb = 0; + int c = 0; + int pre = 1; + int verb = 0; int nConfls = 0; - ExtSat_Pars pPars; + Glucose_Pars pPars; Extra_UtilGetoptReset(); while ( ( c = Extra_UtilGetopt( argc, argv, "Cpvh" ) ) != EOF ) { @@ -110,7 +107,7 @@ int Abc_CommandGlucose( Abc_Frame_t * pAbc, int argc, char ** argv ) } } - pPars = ExtSat_CreatePars(pre,verb,0,nConfls); + pPars = Glucose_CreatePars(pre,verb,0,nConfls); if ( argc == globalUtilOptind + 1 ) { diff --git a/src/sat/glucose/Glucose.cpp b/src/sat/glucose/Glucose.cpp index 05f2945d..ac849584 100644 --- a/src/sat/glucose/Glucose.cpp +++ b/src/sat/glucose/Glucose.cpp @@ -1156,7 +1156,7 @@ lbool Solver::search(int nof_conflicts) next = pickBranchLit(); if (next == lit_Undef){ - printf("c last restart ## conflicts : %d %d \n",conflictC,decisionLevel()); + //printf("c last restart ## conflicts : %d %d \n",conflictC,decisionLevel()); // Model found: return l_True; } @@ -1189,17 +1189,17 @@ void Solver::printIncrementalStats() { printf("c---------- Glucose Stats -------------------------\n"); printf("c restarts : %lld\n", starts); printf("c nb ReduceDB : %lld\n", nbReduceDB); - printf("c nb removed Clauses : %lld\n",nbRemovedClauses); + printf("c nb removed Clauses : %lld\n", nbRemovedClauses); printf("c nb learnts DL2 : %lld\n", nbDL2); printf("c nb learnts size 2 : %lld\n", nbBin); printf("c nb learnts size 1 : %lld\n", nbUn); - printf("c conflicts : %lld \n",conflicts); - printf("c decisions : %lld\n",decisions); - printf("c propagations : %lld\n",propagations); + printf("c conflicts : %lld\n", conflicts); + printf("c decisions : %lld\n", decisions); + printf("c propagations : %lld\n", propagations); - printf("c SAT Calls : %d in %g seconds\n",nbSatCalls,totalTime4Sat); - printf("c UNSAT Calls : %d in %g seconds\n",nbUnsatCalls,totalTime4Unsat); + printf("c SAT Calls : %d in %g seconds\n", nbSatCalls, totalTime4Sat); + printf("c UNSAT Calls : %d in %g seconds\n", nbUnsatCalls, totalTime4Unsat); printf("c--------------------------------------------------\n"); |