summaryrefslogtreecommitdiffstats
path: root/src/sat
diff options
context:
space:
mode:
Diffstat (limited to 'src/sat')
-rw-r--r--src/sat/asat/added.c126
-rw-r--r--src/sat/asat/main.c195
-rw-r--r--src/sat/asat/module.make2
-rw-r--r--src/sat/asat/solver.h137
-rw-r--r--src/sat/bsat/module.make7
-rw-r--r--src/sat/bsat/satInter.c991
-rw-r--r--src/sat/bsat/satInterA.c970
-rw-r--r--src/sat/bsat/satMem.c527
-rw-r--r--src/sat/bsat/satMem.h80
-rw-r--r--src/sat/bsat/satSolver.c (renamed from src/sat/asat/solver.c)639
-rw-r--r--src/sat/bsat/satSolver.h210
-rw-r--r--src/sat/bsat/satStore.c437
-rw-r--r--src/sat/bsat/satStore.h146
-rw-r--r--src/sat/bsat/satTrace.c109
-rw-r--r--src/sat/bsat/satUtil.c234
-rw-r--r--src/sat/bsat/satVec.h (renamed from src/sat/asat/solver_vec.h)52
-rw-r--r--src/sat/csat/csat_apis.c386
-rw-r--r--src/sat/csat/csat_apis.h154
-rw-r--r--src/sat/fraig/fraig.h82
-rw-r--r--src/sat/fraig/fraigApi.c8
-rw-r--r--src/sat/fraig/fraigCanon.c12
-rw-r--r--src/sat/fraig/fraigChoice.c241
-rw-r--r--src/sat/fraig/fraigFanout.c2
-rw-r--r--src/sat/fraig/fraigFeed.c6
-rw-r--r--src/sat/fraig/fraigInt.h24
-rw-r--r--src/sat/fraig/fraigMan.c310
-rw-r--r--src/sat/fraig/fraigMem.c4
-rw-r--r--src/sat/fraig/fraigNode.c3
-rw-r--r--src/sat/fraig/fraigPrime.c8
-rw-r--r--src/sat/fraig/fraigSat.c461
-rw-r--r--src/sat/fraig/fraigTable.c2
-rw-r--r--src/sat/fraig/fraigUtil.c2
-rw-r--r--src/sat/fraig/fraigVec.c2
-rw-r--r--src/sat/msat/msat.h20
-rw-r--r--src/sat/msat/msatActivity.c6
-rw-r--r--src/sat/msat/msatClause.c7
-rw-r--r--src/sat/msat/msatClauseVec.c2
-rw-r--r--src/sat/msat/msatInt.h10
-rw-r--r--src/sat/msat/msatMem.c4
-rw-r--r--src/sat/msat/msatOrderH.c2
-rw-r--r--src/sat/msat/msatOrderJ.c46
-rw-r--r--src/sat/msat/msatQueue.c2
-rw-r--r--src/sat/msat/msatRead.c2
-rw-r--r--src/sat/msat/msatSolverApi.c50
-rw-r--r--src/sat/msat/msatSolverCore.c33
-rw-r--r--src/sat/msat/msatSolverIo.c2
-rw-r--r--src/sat/msat/msatSolverSearch.c10
-rw-r--r--src/sat/msat/msatSort.c2
-rw-r--r--src/sat/msat/msatVec.c2
-rw-r--r--src/sat/proof/pr.c1263
-rw-r--r--src/sat/proof/pr.h65
-rw-r--r--src/sat/proof/stats.txt66
52 files changed, 7110 insertions, 1053 deletions
diff --git a/src/sat/asat/added.c b/src/sat/asat/added.c
deleted file mode 100644
index d7f5b104..00000000
--- a/src/sat/asat/added.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/**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.00 2005/06/20 00:00:00 alanmi 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 );
-
-
-////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
-////////////////////////////////////////////////////////////////////////
-
-/**Function*************************************************************
-
- Synopsis [Write the clauses in the solver into a file in DIMACS format.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-void Asat_SolverWriteDimacs( solver * p, char * pFileName )
-{
- 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" );
- fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
- 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], 1 );
-
- // write the learned clauses
- nClauses = p->learnts.size;
- pClauses = p->learnts.ptr;
- for ( i = 0; i < nClauses; i++ )
- Asat_ClauseWriteDimacs( pFile, pClauses[i], 1 );
-
- // 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 0\n", (p->assigns[i] == l_False)? "-": "", i + 1 );
-
- 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" );
-}
-
-////////////////////////////////////////////////////////////////////////
-/// END OF FILE ///
-////////////////////////////////////////////////////////////////////////
-
-
diff --git a/src/sat/asat/main.c b/src/sat/asat/main.c
deleted file mode 100644
index cbad5ba1..00000000
--- a/src/sat/asat/main.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/**************************************************************************************************
-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;
-}
diff --git a/src/sat/asat/module.make b/src/sat/asat/module.make
deleted file mode 100644
index 882176fa..00000000
--- a/src/sat/asat/module.make
+++ /dev/null
@@ -1,2 +0,0 @@
-SRC += src/sat/asat/added.c \
- src/sat/asat/solver.c
diff --git a/src/sat/asat/solver.h b/src/sat/asat/solver.h
deleted file mode 100644
index e04d5780..00000000
--- a/src/sat/asat/solver.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/**************************************************************************************************
-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 _WIN32
-#define inline __inline // compatible with MS VS 6.0
-#endif
-
-#include "solver_vec.h"
-
-//=================================================================================================
-// Simple types:
-
-//typedef int bool;
-#ifndef bool
-#define bool int
-#endif
-
-static const bool true = 1;
-static const bool false = 0;
-
-typedef int lit;
-typedef char lbool;
-
-#ifdef _WIN32
-typedef signed __int64 uint64; // compatible with MS VS 6.0
-#else
-typedef unsigned long long uint64;
-#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; }
-
-//=================================================================================================
-// Public interface:
-
-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 bool solver_solve(solver* s, lit* begin, lit* end);
-
-extern int solver_nvars(solver* s);
-extern int solver_nclauses(solver* s);
-
-// additional procedures
-extern void Asat_SolverWriteDimacs( solver * pSat, char * pFileName );
-
-struct stats_t
-{
- uint64 starts, decisions, propagations, inspects, conflicts;
- uint64 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.
- 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; //
- vec tagged; // (contains: var)
- vec stack; // (contains: var)
-
- vec order; // Variable order. (heap) (contains: var)
- vec trail_lim; // Separator indices for different decision levels in 'trail'. (contains: int)
- vec 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
-
- stats stats;
-};
-
-#endif
diff --git a/src/sat/bsat/module.make b/src/sat/bsat/module.make
new file mode 100644
index 00000000..1e52cc0a
--- /dev/null
+++ b/src/sat/bsat/module.make
@@ -0,0 +1,7 @@
+SRC += src/sat/bsat/satMem.c \
+ src/sat/bsat/satInter.c \
+ src/sat/bsat/satInterA.c \
+ src/sat/bsat/satSolver.c \
+ src/sat/bsat/satStore.c \
+ src/sat/bsat/satTrace.c \
+ src/sat/bsat/satUtil.c
diff --git a/src/sat/bsat/satInter.c b/src/sat/bsat/satInter.c
new file mode 100644
index 00000000..8e07e9f6
--- /dev/null
+++ b/src/sat/bsat/satInter.c
@@ -0,0 +1,991 @@
+/**CFile****************************************************************
+
+ FileName [satInter.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [SAT sat_solver.]
+
+ Synopsis [Interpolation package.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: satInter.c,v 1.4 2005/09/16 22:55:03 casem Exp $]
+
+***********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <time.h>
+#include "satStore.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+// variable assignments
+static const lit LIT_UNDEF = 0xffffffff;
+
+// interpolation manager
+struct Int_Man_t_
+{
+ // clauses of the problems
+ Sto_Man_t * pCnf; // the set of CNF clauses for A and B
+ // various parameters
+ int fVerbose; // verbosiness flag
+ int fProofVerif; // verifies the proof
+ int fProofWrite; // writes the proof file
+ int nVarsAlloc; // the allocated size of var arrays
+ int nClosAlloc; // the allocated size of clause arrays
+ // internal BCP
+ int nRootSize; // the number of root level assignments
+ int nTrailSize; // the number of assignments made
+ lit * pTrail; // chronological order of assignments (size nVars)
+ lit * pAssigns; // assignments by variable (size nVars)
+ char * pSeens; // temporary mark (size nVars)
+ Sto_Cls_t ** pReasons; // reasons for each assignment (size nVars)
+ Sto_Cls_t ** pWatches; // watched clauses for each literal (size 2*nVars)
+ // interpolation data
+ int nVarsAB; // the number of global variables
+ char * pVarTypes; // variable type (size nVars) [1=A, 0=B, <0=AB]
+ unsigned * pInters; // storage for interpolants as truth tables (size nClauses)
+ int nIntersAlloc; // the allocated size of truth table array
+ int nWords; // the number of words in the truth table
+ // proof recording
+ int Counter; // counter of resolved clauses
+ int * pProofNums; // the proof numbers for each clause (size nClauses)
+ FILE * pFile; // the file for proof recording
+ // internal verification
+ lit * pResLits; // the literals of the resolvent
+ int nResLits; // the number of literals of the resolvent
+ int nResLitsAlloc;// the number of literals of the resolvent
+ // runtime stats
+ int timeBcp; // the runtime for BCP
+ int timeTrace; // the runtime of trace construction
+ int timeTotal; // the total runtime of interpolation
+};
+
+// procedure to get hold of the clauses' truth table
+static inline unsigned * Int_ManTruthRead( Int_Man_t * p, Sto_Cls_t * pCls ) { return p->pInters + pCls->Id * p->nWords; }
+static inline void Int_ManTruthClear( unsigned * p, int nWords ) { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] = 0; }
+static inline void Int_ManTruthFill( unsigned * p, int nWords ) { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] = ~0; }
+static inline void Int_ManTruthCopy( unsigned * p, unsigned * q, int nWords ) { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] = q[i]; }
+static inline void Int_ManTruthAnd( unsigned * p, unsigned * q, int nWords ) { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] &= q[i]; }
+static inline void Int_ManTruthOr( unsigned * p, unsigned * q, int nWords ) { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] |= q[i]; }
+static inline void Int_ManTruthOrNot( unsigned * p, unsigned * q, int nWords ) { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] |= ~q[i]; }
+
+// reading/writing the proof for a clause
+static inline int Int_ManProofGet( Int_Man_t * p, Sto_Cls_t * pCls ) { return p->pProofNums[pCls->Id]; }
+static inline void Int_ManProofSet( Int_Man_t * p, Sto_Cls_t * pCls, int n ) { p->pProofNums[pCls->Id] = n; }
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Allocate proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Int_Man_t * Int_ManAlloc()
+{
+ Int_Man_t * p;
+ // allocate the manager
+ p = (Int_Man_t *)malloc( sizeof(Int_Man_t) );
+ memset( p, 0, sizeof(Int_Man_t) );
+ // verification
+ p->nResLitsAlloc = (1<<16);
+ p->pResLits = malloc( sizeof(lit) * p->nResLitsAlloc );
+ // parameters
+ p->fProofWrite = 0;
+ p->fProofVerif = 1;
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Count common variables in the clauses of A and B.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Int_ManGlobalVars( Int_Man_t * p )
+{
+ Sto_Cls_t * pClause;
+ int Var, nVarsAB, v;
+
+ // mark the variable encountered in the clauses of A
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ {
+ if ( !pClause->fA )
+ break;
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ p->pVarTypes[lit_var(pClause->pLits[v])] = 1;
+ }
+
+ // check variables that appear in clauses of B
+ nVarsAB = 0;
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ {
+ if ( pClause->fA )
+ continue;
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ {
+ Var = lit_var(pClause->pLits[v]);
+ if ( p->pVarTypes[Var] == 1 ) // var of A
+ {
+ // change it into a global variable
+ nVarsAB++;
+ p->pVarTypes[Var] = -1;
+ }
+ }
+ }
+
+ // order global variables
+ nVarsAB = 0;
+ for ( v = 0; v < p->pCnf->nVars; v++ )
+ if ( p->pVarTypes[v] == -1 )
+ p->pVarTypes[v] -= nVarsAB++;
+//printf( "There are %d global variables.\n", nVarsAB );
+ return nVarsAB;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Resize proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Int_ManResize( Int_Man_t * p )
+{
+ // check if resizing is needed
+ if ( p->nVarsAlloc < p->pCnf->nVars )
+ {
+ // find the new size
+ if ( p->nVarsAlloc == 0 )
+ p->nVarsAlloc = 1;
+ while ( p->nVarsAlloc < p->pCnf->nVars )
+ p->nVarsAlloc *= 2;
+ // resize the arrays
+ p->pTrail = (lit *) realloc( p->pTrail, sizeof(lit) * p->nVarsAlloc );
+ p->pAssigns = (lit *) realloc( p->pAssigns, sizeof(lit) * p->nVarsAlloc );
+ p->pSeens = (char *) realloc( p->pSeens, sizeof(char) * p->nVarsAlloc );
+ p->pVarTypes = (char *) realloc( p->pVarTypes, sizeof(char) * p->nVarsAlloc );
+ p->pReasons = (Sto_Cls_t **)realloc( p->pReasons, sizeof(Sto_Cls_t *) * p->nVarsAlloc );
+ p->pWatches = (Sto_Cls_t **)realloc( p->pWatches, sizeof(Sto_Cls_t *) * p->nVarsAlloc*2 );
+ }
+
+ // clean the free space
+ memset( p->pAssigns , 0xff, sizeof(lit) * p->pCnf->nVars );
+ memset( p->pSeens , 0, sizeof(char) * p->pCnf->nVars );
+ memset( p->pVarTypes, 0, sizeof(char) * p->pCnf->nVars );
+ memset( p->pReasons , 0, sizeof(Sto_Cls_t *) * p->pCnf->nVars );
+ memset( p->pWatches , 0, sizeof(Sto_Cls_t *) * p->pCnf->nVars*2 );
+
+ // compute the number of common variables
+ p->nVarsAB = Int_ManGlobalVars( p );
+ // compute the number of words in the truth table
+ p->nWords = (p->nVarsAB <= 5 ? 1 : (1 << (p->nVarsAB - 5)));
+
+ // check if resizing of clauses is needed
+ if ( p->nClosAlloc < p->pCnf->nClauses )
+ {
+ // find the new size
+ if ( p->nClosAlloc == 0 )
+ p->nClosAlloc = 1;
+ while ( p->nClosAlloc < p->pCnf->nClauses )
+ p->nClosAlloc *= 2;
+ // resize the arrays
+ p->pProofNums = (int *) realloc( p->pProofNums, sizeof(int) * p->nClosAlloc );
+ }
+ memset( p->pProofNums, 0, sizeof(int) * p->pCnf->nClauses );
+
+ // check if resizing of truth tables is needed
+ if ( p->nIntersAlloc < p->nWords * p->pCnf->nClauses )
+ {
+ p->nIntersAlloc = p->nWords * p->pCnf->nClauses;
+ p->pInters = (unsigned *) realloc( p->pInters, sizeof(unsigned) * p->nIntersAlloc );
+ }
+// memset( p->pInters, 0, sizeof(unsigned) * p->nWords * p->pCnf->nClauses );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Deallocate proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Int_ManFree( Int_Man_t * p )
+{
+/*
+ printf( "Runtime stats:\n" );
+PRT( "BCP ", p->timeBcp );
+PRT( "Trace ", p->timeTrace );
+PRT( "TOTAL ", p->timeTotal );
+*/
+ free( p->pInters );
+ free( p->pProofNums );
+ free( p->pTrail );
+ free( p->pAssigns );
+ free( p->pSeens );
+ free( p->pVarTypes );
+ free( p->pReasons );
+ free( p->pWatches );
+ free( p->pResLits );
+ free( p );
+}
+
+
+
+
+/**Function*************************************************************
+
+ Synopsis [Prints the clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Int_ManPrintClause( Int_Man_t * p, Sto_Cls_t * pClause )
+{
+ int i;
+ printf( "Clause ID = %d. Proof = %d. {", pClause->Id, Int_ManProofGet(p, pClause) );
+ for ( i = 0; i < (int)pClause->nLits; i++ )
+ printf( " %d", pClause->pLits[i] );
+ printf( " }\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Prints the resolvent.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Int_ManPrintResolvent( lit * pResLits, int nResLits )
+{
+ int i;
+ printf( "Resolvent: {" );
+ for ( i = 0; i < nResLits; i++ )
+ printf( " %d", pResLits[i] );
+ printf( " }\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Extra_PrintBinary__( FILE * pFile, unsigned Sign[], int nBits )
+{
+ int Remainder, nWords;
+ int w, i;
+
+ Remainder = (nBits%(sizeof(unsigned)*8));
+ nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
+
+ for ( w = nWords-1; w >= 0; w-- )
+ for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- )
+ fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Prints the interpolant for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Int_ManPrintInterOne( Int_Man_t * p, Sto_Cls_t * pClause )
+{
+ printf( "Clause %2d : ", pClause->Id );
+ Extra_PrintBinary__( stdout, Int_ManTruthRead(p, pClause), (1 << p->nVarsAB) );
+ printf( "\n" );
+}
+
+
+
+/**Function*************************************************************
+
+ Synopsis [Adds one clause to the watcher list.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Int_ManWatchClause( Int_Man_t * p, Sto_Cls_t * pClause, lit Lit )
+{
+ assert( lit_check(Lit, p->pCnf->nVars) );
+ if ( pClause->pLits[0] == Lit )
+ pClause->pNext0 = p->pWatches[lit_neg(Lit)];
+ else
+ {
+ assert( pClause->pLits[1] == Lit );
+ pClause->pNext1 = p->pWatches[lit_neg(Lit)];
+ }
+ p->pWatches[lit_neg(Lit)] = pClause;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Records implication.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Int_ManEnqueue( Int_Man_t * p, lit Lit, Sto_Cls_t * pReason )
+{
+ int Var = lit_var(Lit);
+ if ( p->pAssigns[Var] != LIT_UNDEF )
+ return p->pAssigns[Var] == Lit;
+ p->pAssigns[Var] = Lit;
+ p->pReasons[Var] = pReason;
+ p->pTrail[p->nTrailSize++] = Lit;
+//printf( "assigning var %d value %d\n", Var, !lit_sign(Lit) );
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records implication.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Int_ManCancelUntil( Int_Man_t * p, int Level )
+{
+ lit Lit;
+ int i, Var;
+ for ( i = p->nTrailSize - 1; i >= Level; i-- )
+ {
+ Lit = p->pTrail[i];
+ Var = lit_var( Lit );
+ p->pReasons[Var] = NULL;
+ p->pAssigns[Var] = LIT_UNDEF;
+//printf( "cancelling var %d\n", Var );
+ }
+ p->nTrailSize = Level;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate one assignment.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline Sto_Cls_t * Int_ManPropagateOne( Int_Man_t * p, lit Lit )
+{
+ Sto_Cls_t ** ppPrev, * pCur, * pTemp;
+ lit LitF = lit_neg(Lit);
+ int i;
+ // iterate through the literals
+ ppPrev = p->pWatches + Lit;
+ for ( pCur = p->pWatches[Lit]; pCur; pCur = *ppPrev )
+ {
+ // make sure the false literal is in the second literal of the clause
+ if ( pCur->pLits[0] == LitF )
+ {
+ pCur->pLits[0] = pCur->pLits[1];
+ pCur->pLits[1] = LitF;
+ pTemp = pCur->pNext0;
+ pCur->pNext0 = pCur->pNext1;
+ pCur->pNext1 = pTemp;
+ }
+ assert( pCur->pLits[1] == LitF );
+
+ // if the first literal is true, the clause is satisfied
+ if ( pCur->pLits[0] == p->pAssigns[lit_var(pCur->pLits[0])] )
+ {
+ ppPrev = &pCur->pNext1;
+ continue;
+ }
+
+ // look for a new literal to watch
+ for ( i = 2; i < (int)pCur->nLits; i++ )
+ {
+ // skip the case when the literal is false
+ if ( lit_neg(pCur->pLits[i]) == p->pAssigns[lit_var(pCur->pLits[i])] )
+ continue;
+ // the literal is either true or unassigned - watch it
+ pCur->pLits[1] = pCur->pLits[i];
+ pCur->pLits[i] = LitF;
+ // remove this clause from the watch list of Lit
+ *ppPrev = pCur->pNext1;
+ // add this clause to the watch list of pCur->pLits[i] (now it is pCur->pLits[1])
+ Int_ManWatchClause( p, pCur, pCur->pLits[1] );
+ break;
+ }
+ if ( i < (int)pCur->nLits ) // found new watch
+ continue;
+
+ // clause is unit - enqueue new implication
+ if ( Int_ManEnqueue(p, pCur->pLits[0], pCur) )
+ {
+ ppPrev = &pCur->pNext1;
+ continue;
+ }
+
+ // conflict detected - return the conflict clause
+ return pCur;
+ }
+ return NULL;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate the current assignments.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Sto_Cls_t * Int_ManPropagate( Int_Man_t * p, int Start )
+{
+ Sto_Cls_t * pClause;
+ int i;
+ int clk = clock();
+ for ( i = Start; i < p->nTrailSize; i++ )
+ {
+ pClause = Int_ManPropagateOne( p, p->pTrail[i] );
+ if ( pClause )
+ {
+p->timeBcp += clock() - clk;
+ return pClause;
+ }
+ }
+p->timeBcp += clock() - clk;
+ return NULL;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Writes one root clause into a file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Int_ManProofWriteOne( Int_Man_t * p, Sto_Cls_t * pClause )
+{
+ Int_ManProofSet( p, pClause, ++p->Counter );
+
+ if ( p->fProofWrite )
+ {
+ int v;
+ fprintf( p->pFile, "%d", Int_ManProofGet(p, pClause) );
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ fprintf( p->pFile, " %d", lit_print(pClause->pLits[v]) );
+ fprintf( p->pFile, " 0 0\n" );
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Traces the proof for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Int_ManProofTraceOne( Int_Man_t * p, Sto_Cls_t * pConflict, Sto_Cls_t * pFinal )
+{
+ Sto_Cls_t * pReason;
+ int i, v, Var, PrevId;
+ int fPrint = 0;
+ int clk = clock();
+
+ // collect resolvent literals
+ if ( p->fProofVerif )
+ {
+ assert( (int)pConflict->nLits <= p->nResLitsAlloc );
+ memcpy( p->pResLits, pConflict->pLits, sizeof(lit) * pConflict->nLits );
+ p->nResLits = pConflict->nLits;
+ }
+
+ // mark all the variables in the conflict as seen
+ for ( v = 0; v < (int)pConflict->nLits; v++ )
+ p->pSeens[lit_var(pConflict->pLits[v])] = 1;
+
+ // start the anticedents
+// pFinal->pAntis = Vec_PtrAlloc( 32 );
+// Vec_PtrPush( pFinal->pAntis, pConflict );
+
+ if ( p->pCnf->nClausesA )
+ Int_ManTruthCopy( Int_ManTruthRead(p, pFinal), Int_ManTruthRead(p, pConflict), p->nWords );
+
+ // follow the trail backwards
+ PrevId = Int_ManProofGet(p, pConflict);
+ for ( i = p->nTrailSize - 1; i >= 0; i-- )
+ {
+ // skip literals that are not involved
+ Var = lit_var(p->pTrail[i]);
+ if ( !p->pSeens[Var] )
+ continue;
+ p->pSeens[Var] = 0;
+
+ // skip literals of the resulting clause
+ pReason = p->pReasons[Var];
+ if ( pReason == NULL )
+ continue;
+ 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
+ assert( Int_ManProofGet(p, pReason) > 0 );
+ p->Counter++;
+ if ( p->fProofWrite )
+ fprintf( p->pFile, "%d * %d %d 0\n", p->Counter, PrevId, Int_ManProofGet(p, pReason) );
+ PrevId = p->Counter;
+
+ if ( p->pCnf->nClausesA )
+ {
+ if ( p->pVarTypes[Var] == 1 ) // var of A
+ Int_ManTruthOr( Int_ManTruthRead(p, pFinal), Int_ManTruthRead(p, pReason), p->nWords );
+ else
+ Int_ManTruthAnd( Int_ManTruthRead(p, pFinal), Int_ManTruthRead(p, pReason), p->nWords );
+ }
+
+ // resolve the temporary resolvent with the reason clause
+ if ( p->fProofVerif )
+ {
+ int v1, v2;
+ if ( fPrint )
+ Int_ManPrintResolvent( p->pResLits, p->nResLits );
+ // check that the var is present in the resolvent
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ if ( lit_var(p->pResLits[v1]) == Var )
+ break;
+ if ( v1 == p->nResLits )
+ printf( "Recording clause %d: Cannot find variable %d in the temporary resolvent.\n", pFinal->Id, Var );
+ if ( p->pResLits[v1] != lit_neg(pReason->pLits[0]) )
+ printf( "Recording clause %d: The resolved variable %d is in the wrong polarity.\n", pFinal->Id, Var );
+ // remove this variable from the resolvent
+ assert( lit_var(p->pResLits[v1]) == Var );
+ p->nResLits--;
+ for ( ; v1 < p->nResLits; v1++ )
+ p->pResLits[v1] = p->pResLits[v1+1];
+ // add variables of the reason clause
+ for ( v2 = 1; v2 < (int)pReason->nLits; v2++ )
+ {
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ if ( lit_var(p->pResLits[v1]) == lit_var(pReason->pLits[v2]) )
+ break;
+ // if it is a new variable, add it to the resolvent
+ if ( v1 == p->nResLits )
+ {
+ if ( p->nResLits == p->nResLitsAlloc )
+ printf( "Recording clause %d: Ran out of space for intermediate resolvent.\n", pFinal->Id );
+ p->pResLits[ p->nResLits++ ] = pReason->pLits[v2];
+ continue;
+ }
+ // if the variable is the same, the literal should be the same too
+ if ( p->pResLits[v1] == pReason->pLits[v2] )
+ continue;
+ // the literal is different
+ printf( "Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->Id );
+ }
+ }
+
+// Vec_PtrPush( pFinal->pAntis, pReason );
+ }
+
+ // unmark all seen variables
+// for ( i = p->nTrailSize - 1; i >= 0; i-- )
+// 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
+ if ( p->fProofVerif )
+ {
+ int v1, v2;
+ if ( fPrint )
+ Int_ManPrintResolvent( p->pResLits, p->nResLits );
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ {
+ for ( v2 = 0; v2 < (int)pFinal->nLits; v2++ )
+ if ( pFinal->pLits[v2] == p->pResLits[v1] )
+ break;
+ if ( v2 < (int)pFinal->nLits )
+ continue;
+ break;
+ }
+ if ( v1 < p->nResLits )
+ {
+ printf( "Recording clause %d: The final resolvent is wrong.\n", pFinal->Id );
+ Int_ManPrintClause( p, pConflict );
+ Int_ManPrintResolvent( p->pResLits, p->nResLits );
+ Int_ManPrintClause( p, pFinal );
+ }
+ }
+p->timeTrace += clock() - clk;
+
+ // return the proof pointer
+ if ( p->pCnf->nClausesA )
+ {
+// Int_ManPrintInterOne( p, pFinal );
+ }
+ Int_ManProofSet( p, pFinal, p->Counter );
+ return p->Counter;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Int_ManProofRecordOne( Int_Man_t * p, Sto_Cls_t * pClause )
+{
+ Sto_Cls_t * pConflict;
+ int i;
+
+ // empty clause never ends up there
+ assert( pClause->nLits > 0 );
+ if ( pClause->nLits == 0 )
+ printf( "Error: Empty clause is attempted.\n" );
+
+ // add assumptions to the trail
+ assert( !pClause->fRoot );
+ assert( p->nTrailSize == p->nRootSize );
+ for ( i = 0; i < (int)pClause->nLits; i++ )
+ if ( !Int_ManEnqueue( p, lit_neg(pClause->pLits[i]), NULL ) )
+ {
+ assert( 0 ); // impossible
+ return 0;
+ }
+
+ // propagate the assumptions
+ pConflict = Int_ManPropagate( p, p->nRootSize );
+ if ( pConflict == NULL )
+ {
+ assert( 0 ); // cannot prove
+ return 0;
+ }
+
+ // construct the proof
+ Int_ManProofTraceOne( p, pConflict, pClause );
+
+ // undo to the root level
+ Int_ManCancelUntil( p, p->nRootSize );
+
+ // add large clauses to the watched lists
+ if ( pClause->nLits > 1 )
+ {
+ Int_ManWatchClause( p, pClause, pClause->pLits[0] );
+ Int_ManWatchClause( p, pClause, pClause->pLits[1] );
+ return 1;
+ }
+ assert( pClause->nLits == 1 );
+
+ // if the clause proved is unit, add it and propagate
+ if ( !Int_ManEnqueue( p, pClause->pLits[0], pClause ) )
+ {
+ assert( 0 ); // impossible
+ return 0;
+ }
+
+ // propagate the assumption
+ pConflict = Int_ManPropagate( p, p->nRootSize );
+ if ( pConflict )
+ {
+ // construct the proof
+ Int_ManProofTraceOne( p, pConflict, p->pCnf->pEmpty );
+ if ( p->fVerbose )
+ printf( "Found last conflict after adding unit clause number %d!\n", pClause->Id );
+ return 0;
+ }
+
+ // update the root level
+ p->nRootSize = p->nTrailSize;
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate the root clauses.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Int_ManProcessRoots( Int_Man_t * p )
+{
+ Sto_Cls_t * pClause;
+ int Counter;
+
+ // make sure the root clauses are preceeding the learnt clauses
+ Counter = 0;
+ Sto_ManForEachClause( p->pCnf, pClause )
+ {
+ assert( (int)pClause->fA == (Counter < (int)p->pCnf->nClausesA) );
+ assert( (int)pClause->fRoot == (Counter < (int)p->pCnf->nRoots) );
+ Counter++;
+ }
+ assert( p->pCnf->nClauses == Counter );
+
+ // make sure the last clause if empty
+ assert( p->pCnf->pTail->nLits == 0 );
+
+ // go through the root unit clauses
+ p->nTrailSize = 0;
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ {
+ // create watcher lists for the root clauses
+ if ( pClause->nLits > 1 )
+ {
+ Int_ManWatchClause( p, pClause, pClause->pLits[0] );
+ Int_ManWatchClause( p, pClause, pClause->pLits[1] );
+ }
+ // empty clause and large clauses
+ if ( pClause->nLits != 1 )
+ continue;
+ // unit clause
+ assert( lit_check(pClause->pLits[0], p->pCnf->nVars) );
+ if ( !Int_ManEnqueue( p, pClause->pLits[0], pClause ) )
+ {
+ // detected root level conflict
+ printf( "Error in Int_ManProcessRoots(): Detected a root-level conflict too early!\n" );
+ assert( 0 );
+ return 0;
+ }
+ }
+
+ // propagate the root unit clauses
+ pClause = Int_ManPropagate( p, 0 );
+ if ( pClause )
+ {
+ // detected root level conflict
+ Int_ManProofTraceOne( p, pClause, p->pCnf->pEmpty );
+ if ( p->fVerbose )
+ printf( "Found root level conflict!\n" );
+ return 0;
+ }
+
+ // set the root level
+ p->nRootSize = p->nTrailSize;
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Int_ManPrepareInter( Int_Man_t * p )
+{
+ // elementary truth tables
+ unsigned uTruths[8][8] = {
+ { 0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA },
+ { 0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC },
+ { 0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0 },
+ { 0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00 },
+ { 0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000 },
+ { 0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF },
+ { 0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF },
+ { 0x00000000,0x00000000,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF }
+ };
+ Sto_Cls_t * pClause;
+ int Var, VarAB, v;
+ assert( p->nVarsAB <= 8 );
+
+ // set interpolants for root clauses
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ {
+ if ( !pClause->fA ) // clause of B
+ {
+ Int_ManTruthFill( Int_ManTruthRead(p, pClause), p->nWords );
+// Int_ManPrintInterOne( p, pClause );
+ continue;
+ }
+ // clause of A
+ Int_ManTruthClear( Int_ManTruthRead(p, pClause), p->nWords );
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ {
+ Var = lit_var(pClause->pLits[v]);
+ if ( p->pVarTypes[Var] < 0 ) // global var
+ {
+ VarAB = -p->pVarTypes[Var]-1;
+ assert( VarAB >= 0 && VarAB < p->nVarsAB );
+ if ( lit_sign(pClause->pLits[v]) ) // negative var
+ Int_ManTruthOrNot( Int_ManTruthRead(p, pClause), uTruths[VarAB], p->nWords );
+ else
+ Int_ManTruthOr( Int_ManTruthRead(p, pClause), uTruths[VarAB], p->nWords );
+ }
+ }
+// Int_ManPrintInterOne( p, pClause );
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Computes interpolant for the given CNF.]
+
+ Description [Returns the number of common variable found and interpolant.
+ Returns 0, if something did not work.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Int_ManInterpolate( Int_Man_t * p, Sto_Man_t * pCnf, int fVerbose, unsigned ** ppResult )
+{
+ Sto_Cls_t * pClause;
+ int RetValue = 1;
+ int clkTotal = clock();
+
+ // check that the CNF makes sense
+ assert( pCnf->nVars > 0 && pCnf->nClauses > 0 );
+ p->pCnf = pCnf;
+ p->fVerbose = fVerbose;
+ *ppResult = NULL;
+
+ // adjust the manager
+ Int_ManResize( p );
+
+ // prepare the interpolant computation
+ Int_ManPrepareInter( p );
+
+ // construct proof for each clause
+ // start the proof
+ if ( p->fProofWrite )
+ {
+ p->pFile = fopen( "proof.cnf_", "w" );
+ p->Counter = 0;
+ }
+
+ // write the root clauses
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ Int_ManProofWriteOne( p, pClause );
+
+ // propagate root level assignments
+ if ( Int_ManProcessRoots( p ) )
+ {
+ // if there is no conflict, consider learned clauses
+ Sto_ManForEachClause( p->pCnf, pClause )
+ {
+ if ( pClause->fRoot )
+ continue;
+ if ( !Int_ManProofRecordOne( p, pClause ) )
+ {
+ RetValue = 0;
+ break;
+ }
+ }
+ }
+
+ // stop the proof
+ if ( p->fProofWrite )
+ {
+ fclose( p->pFile );
+ p->pFile = NULL;
+ }
+
+ if ( fVerbose )
+ {
+ printf( "Vars = %d. Roots = %d. Learned = %d. Resol steps = %d. Ave = %.2f. Mem = %.2f Mb\n",
+ p->pCnf->nVars, p->pCnf->nRoots, p->pCnf->nClauses-p->pCnf->nRoots, p->Counter,
+ 1.0*(p->Counter-p->pCnf->nRoots)/(p->pCnf->nClauses-p->pCnf->nRoots),
+ 1.0*Sto_ManMemoryReport(p->pCnf)/(1<<20) );
+p->timeTotal += clock() - clkTotal;
+ }
+
+ *ppResult = Int_ManTruthRead( p, p->pCnf->pTail );
+ return p->nVarsAB;
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/sat/bsat/satInterA.c b/src/sat/bsat/satInterA.c
new file mode 100644
index 00000000..513a9044
--- /dev/null
+++ b/src/sat/bsat/satInterA.c
@@ -0,0 +1,970 @@
+/**CFile****************************************************************
+
+ FileName [satInter.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [SAT sat_solver.]
+
+ Synopsis [Interpolation package.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: satInter.c,v 1.4 2005/09/16 22:55:03 casem Exp $]
+
+***********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <time.h>
+#include "satStore.h"
+#include "aig.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+// variable assignments
+static const lit LIT_UNDEF = 0xffffffff;
+
+// interpolation manager
+struct Inta_Man_t_
+{
+ // clauses of the problems
+ Sto_Man_t * pCnf; // the set of CNF clauses for A and B
+ Vec_Int_t * vVarsAB; // the array of global variables
+ // various parameters
+ int fVerbose; // verbosiness flag
+ int fProofVerif; // verifies the proof
+ int fProofWrite; // writes the proof file
+ int nVarsAlloc; // the allocated size of var arrays
+ int nClosAlloc; // the allocated size of clause arrays
+ // internal BCP
+ int nRootSize; // the number of root level assignments
+ int nTrailSize; // the number of assignments made
+ lit * pTrail; // chronological order of assignments (size nVars)
+ lit * pAssigns; // assignments by variable (size nVars)
+ char * pSeens; // temporary mark (size nVars)
+ Sto_Cls_t ** pReasons; // reasons for each assignment (size nVars)
+ Sto_Cls_t ** pWatches; // watched clauses for each literal (size 2*nVars)
+ // interpolation data
+ Aig_Man_t * pAig; // the AIG manager for recording the interpolant
+ int * pVarTypes; // variable type (size nVars) [1=A, 0=B, <0=AB]
+ Aig_Obj_t ** pInters; // storage for interpolants as truth tables (size nClauses)
+ int nIntersAlloc; // the allocated size of truth table array
+ // proof recording
+ int Counter; // counter of resolved clauses
+ int * pProofNums; // the proof numbers for each clause (size nClauses)
+ FILE * pFile; // the file for proof recording
+ // internal verification
+ lit * pResLits; // the literals of the resolvent
+ int nResLits; // the number of literals of the resolvent
+ int nResLitsAlloc;// the number of literals of the resolvent
+ // runtime stats
+ int timeBcp; // the runtime for BCP
+ int timeTrace; // the runtime of trace construction
+ int timeTotal; // the total runtime of interpolation
+};
+
+// procedure to get hold of the clauses' truth table
+static inline Aig_Obj_t ** Inta_ManAigRead( Inta_Man_t * pMan, Sto_Cls_t * pCls ) { return pMan->pInters + pCls->Id; }
+static inline void Inta_ManAigClear( Inta_Man_t * pMan, Aig_Obj_t ** p ) { *p = Aig_ManConst0(pMan->pAig); }
+static inline void Inta_ManAigFill( Inta_Man_t * pMan, Aig_Obj_t ** p ) { *p = Aig_ManConst1(pMan->pAig); }
+static inline void Inta_ManAigCopy( Inta_Man_t * pMan, Aig_Obj_t ** p, Aig_Obj_t ** q ) { *p = *q; }
+static inline void Inta_ManAigAnd( Inta_Man_t * pMan, Aig_Obj_t ** p, Aig_Obj_t ** q ) { *p = Aig_And(pMan->pAig, *p, *q); }
+static inline void Inta_ManAigOr( Inta_Man_t * pMan, Aig_Obj_t ** p, Aig_Obj_t ** q ) { *p = Aig_Or(pMan->pAig, *p, *q); }
+static inline void Inta_ManAigOrNot( Inta_Man_t * pMan, Aig_Obj_t ** p, Aig_Obj_t ** q ) { *p = Aig_Or(pMan->pAig, *p, Aig_Not(*q)); }
+static inline void Inta_ManAigOrVar( Inta_Man_t * pMan, Aig_Obj_t ** p, int v ) { *p = Aig_Or(pMan->pAig, *p, Aig_IthVar(pMan->pAig, v)); }
+static inline void Inta_ManAigOrNotVar( Inta_Man_t * pMan, Aig_Obj_t ** p, int v ) { *p = Aig_Or(pMan->pAig, *p, Aig_Not(Aig_IthVar(pMan->pAig, v))); }
+
+// reading/writing the proof for a clause
+static inline int Inta_ManProofGet( Inta_Man_t * p, Sto_Cls_t * pCls ) { return p->pProofNums[pCls->Id]; }
+static inline void Inta_ManProofSet( Inta_Man_t * p, Sto_Cls_t * pCls, int n ) { p->pProofNums[pCls->Id] = n; }
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Allocate proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Inta_Man_t * Inta_ManAlloc()
+{
+ Inta_Man_t * p;
+ // allocate the manager
+ p = (Inta_Man_t *)malloc( sizeof(Inta_Man_t) );
+ memset( p, 0, sizeof(Inta_Man_t) );
+ // verification
+ p->nResLitsAlloc = (1<<16);
+ p->pResLits = malloc( sizeof(lit) * p->nResLitsAlloc );
+ // parameters
+ p->fProofWrite = 0;
+ p->fProofVerif = 1;
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Count common variables in the clauses of A and B.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Inta_ManGlobalVars( Inta_Man_t * p )
+{
+ Sto_Cls_t * pClause;
+ int LargeNum = -100000000;
+ int Var, nVarsAB, v;
+
+ // mark the variable encountered in the clauses of A
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ {
+ if ( !pClause->fA )
+ break;
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ p->pVarTypes[lit_var(pClause->pLits[v])] = 1;
+ }
+
+ // check variables that appear in clauses of B
+ nVarsAB = 0;
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ {
+ if ( pClause->fA )
+ continue;
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ {
+ Var = lit_var(pClause->pLits[v]);
+ if ( p->pVarTypes[Var] == 1 ) // var of A
+ {
+ // change it into a global variable
+ nVarsAB++;
+ p->pVarTypes[Var] = LargeNum;
+ }
+ }
+ }
+ assert( nVarsAB <= Vec_IntSize(p->vVarsAB) );
+
+ // order global variables
+ nVarsAB = 0;
+ Vec_IntForEachEntry( p->vVarsAB, Var, v )
+ p->pVarTypes[Var] = -(1+nVarsAB++);
+
+ // check that there is no extra global variables
+ for ( v = 0; v < p->pCnf->nVars; v++ )
+ assert( p->pVarTypes[v] != LargeNum );
+ return nVarsAB;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Resize proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Inta_ManResize( Inta_Man_t * p )
+{
+ // check if resizing is needed
+ if ( p->nVarsAlloc < p->pCnf->nVars )
+ {
+ // find the new size
+ if ( p->nVarsAlloc == 0 )
+ p->nVarsAlloc = 1;
+ while ( p->nVarsAlloc < p->pCnf->nVars )
+ p->nVarsAlloc *= 2;
+ // resize the arrays
+ p->pTrail = (lit *) realloc( p->pTrail, sizeof(lit) * p->nVarsAlloc );
+ p->pAssigns = (lit *) realloc( p->pAssigns, sizeof(lit) * p->nVarsAlloc );
+ p->pSeens = (char *) realloc( p->pSeens, sizeof(char) * p->nVarsAlloc );
+ p->pVarTypes = (int *) realloc( p->pVarTypes, sizeof(int) * p->nVarsAlloc );
+ p->pReasons = (Sto_Cls_t **)realloc( p->pReasons, sizeof(Sto_Cls_t *) * p->nVarsAlloc );
+ p->pWatches = (Sto_Cls_t **)realloc( p->pWatches, sizeof(Sto_Cls_t *) * p->nVarsAlloc*2 );
+ }
+
+ // clean the free space
+ memset( p->pAssigns , 0xff, sizeof(lit) * p->pCnf->nVars );
+ memset( p->pSeens , 0, sizeof(char) * p->pCnf->nVars );
+ memset( p->pVarTypes, 0, sizeof(int) * p->pCnf->nVars );
+ memset( p->pReasons , 0, sizeof(Sto_Cls_t *) * p->pCnf->nVars );
+ memset( p->pWatches , 0, sizeof(Sto_Cls_t *) * p->pCnf->nVars*2 );
+
+ // compute the number of common variables
+ Inta_ManGlobalVars( p );
+
+ // check if resizing of clauses is needed
+ if ( p->nClosAlloc < p->pCnf->nClauses )
+ {
+ // find the new size
+ if ( p->nClosAlloc == 0 )
+ p->nClosAlloc = 1;
+ while ( p->nClosAlloc < p->pCnf->nClauses )
+ p->nClosAlloc *= 2;
+ // resize the arrays
+ p->pProofNums = (int *) realloc( p->pProofNums, sizeof(int) * p->nClosAlloc );
+ }
+ memset( p->pProofNums, 0, sizeof(int) * p->pCnf->nClauses );
+
+ // check if resizing of truth tables is needed
+ if ( p->nIntersAlloc < p->pCnf->nClauses )
+ {
+ p->nIntersAlloc = p->pCnf->nClauses;
+ p->pInters = (Aig_Obj_t **) realloc( p->pInters, sizeof(Aig_Obj_t *) * p->nIntersAlloc );
+ }
+ memset( p->pInters, 0, sizeof(Aig_Obj_t *) * p->pCnf->nClauses );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Deallocate proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Inta_ManFree( Inta_Man_t * p )
+{
+/*
+ printf( "Runtime stats:\n" );
+PRT( "BCP ", p->timeBcp );
+PRT( "Trace ", p->timeTrace );
+PRT( "TOTAL ", p->timeTotal );
+*/
+ free( p->pInters );
+ free( p->pProofNums );
+ free( p->pTrail );
+ free( p->pAssigns );
+ free( p->pSeens );
+ free( p->pVarTypes );
+ free( p->pReasons );
+ free( p->pWatches );
+ free( p->pResLits );
+ free( p );
+}
+
+
+
+
+/**Function*************************************************************
+
+ Synopsis [Prints the clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Inta_ManPrintClause( Inta_Man_t * p, Sto_Cls_t * pClause )
+{
+ int i;
+ printf( "Clause ID = %d. Proof = %d. {", pClause->Id, Inta_ManProofGet(p, pClause) );
+ for ( i = 0; i < (int)pClause->nLits; i++ )
+ printf( " %d", pClause->pLits[i] );
+ printf( " }\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Prints the resolvent.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Inta_ManPrintResolvent( lit * pResLits, int nResLits )
+{
+ int i;
+ printf( "Resolvent: {" );
+ for ( i = 0; i < nResLits; i++ )
+ printf( " %d", pResLits[i] );
+ printf( " }\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Prints the interpolant for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Inta_ManPrintInterOne( Inta_Man_t * p, Sto_Cls_t * pClause )
+{
+ printf( "Clause %2d : ", pClause->Id );
+// Extra_PrintBinary___( stdout, Inta_ManAigRead(p, pClause), (1 << p->nVarsAB) );
+ printf( "\n" );
+}
+
+
+
+/**Function*************************************************************
+
+ Synopsis [Adds one clause to the watcher list.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Inta_ManWatchClause( Inta_Man_t * p, Sto_Cls_t * pClause, lit Lit )
+{
+ assert( lit_check(Lit, p->pCnf->nVars) );
+ if ( pClause->pLits[0] == Lit )
+ pClause->pNext0 = p->pWatches[lit_neg(Lit)];
+ else
+ {
+ assert( pClause->pLits[1] == Lit );
+ pClause->pNext1 = p->pWatches[lit_neg(Lit)];
+ }
+ p->pWatches[lit_neg(Lit)] = pClause;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Records implication.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Inta_ManEnqueue( Inta_Man_t * p, lit Lit, Sto_Cls_t * pReason )
+{
+ int Var = lit_var(Lit);
+ if ( p->pAssigns[Var] != LIT_UNDEF )
+ return p->pAssigns[Var] == Lit;
+ p->pAssigns[Var] = Lit;
+ p->pReasons[Var] = pReason;
+ p->pTrail[p->nTrailSize++] = Lit;
+//printf( "assigning var %d value %d\n", Var, !lit_sign(Lit) );
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records implication.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Inta_ManCancelUntil( Inta_Man_t * p, int Level )
+{
+ lit Lit;
+ int i, Var;
+ for ( i = p->nTrailSize - 1; i >= Level; i-- )
+ {
+ Lit = p->pTrail[i];
+ Var = lit_var( Lit );
+ p->pReasons[Var] = NULL;
+ p->pAssigns[Var] = LIT_UNDEF;
+//printf( "cancelling var %d\n", Var );
+ }
+ p->nTrailSize = Level;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate one assignment.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline Sto_Cls_t * Inta_ManPropagateOne( Inta_Man_t * p, lit Lit )
+{
+ Sto_Cls_t ** ppPrev, * pCur, * pTemp;
+ lit LitF = lit_neg(Lit);
+ int i;
+ // iterate through the literals
+ ppPrev = p->pWatches + Lit;
+ for ( pCur = p->pWatches[Lit]; pCur; pCur = *ppPrev )
+ {
+ // make sure the false literal is in the second literal of the clause
+ if ( pCur->pLits[0] == LitF )
+ {
+ pCur->pLits[0] = pCur->pLits[1];
+ pCur->pLits[1] = LitF;
+ pTemp = pCur->pNext0;
+ pCur->pNext0 = pCur->pNext1;
+ pCur->pNext1 = pTemp;
+ }
+ assert( pCur->pLits[1] == LitF );
+
+ // if the first literal is true, the clause is satisfied
+ if ( pCur->pLits[0] == p->pAssigns[lit_var(pCur->pLits[0])] )
+ {
+ ppPrev = &pCur->pNext1;
+ continue;
+ }
+
+ // look for a new literal to watch
+ for ( i = 2; i < (int)pCur->nLits; i++ )
+ {
+ // skip the case when the literal is false
+ if ( lit_neg(pCur->pLits[i]) == p->pAssigns[lit_var(pCur->pLits[i])] )
+ continue;
+ // the literal is either true or unassigned - watch it
+ pCur->pLits[1] = pCur->pLits[i];
+ pCur->pLits[i] = LitF;
+ // remove this clause from the watch list of Lit
+ *ppPrev = pCur->pNext1;
+ // add this clause to the watch list of pCur->pLits[i] (now it is pCur->pLits[1])
+ Inta_ManWatchClause( p, pCur, pCur->pLits[1] );
+ break;
+ }
+ if ( i < (int)pCur->nLits ) // found new watch
+ continue;
+
+ // clause is unit - enqueue new implication
+ if ( Inta_ManEnqueue(p, pCur->pLits[0], pCur) )
+ {
+ ppPrev = &pCur->pNext1;
+ continue;
+ }
+
+ // conflict detected - return the conflict clause
+ return pCur;
+ }
+ return NULL;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate the current assignments.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Sto_Cls_t * Inta_ManPropagate( Inta_Man_t * p, int Start )
+{
+ Sto_Cls_t * pClause;
+ int i;
+ int clk = clock();
+ for ( i = Start; i < p->nTrailSize; i++ )
+ {
+ pClause = Inta_ManPropagateOne( p, p->pTrail[i] );
+ if ( pClause )
+ {
+p->timeBcp += clock() - clk;
+ return pClause;
+ }
+ }
+p->timeBcp += clock() - clk;
+ return NULL;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Writes one root clause into a file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Inta_ManProofWriteOne( Inta_Man_t * p, Sto_Cls_t * pClause )
+{
+ Inta_ManProofSet( p, pClause, ++p->Counter );
+
+ if ( p->fProofWrite )
+ {
+ int v;
+ fprintf( p->pFile, "%d", Inta_ManProofGet(p, pClause) );
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ fprintf( p->pFile, " %d", lit_print(pClause->pLits[v]) );
+ fprintf( p->pFile, " 0 0\n" );
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Traces the proof for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Inta_ManProofTraceOne( Inta_Man_t * p, Sto_Cls_t * pConflict, Sto_Cls_t * pFinal )
+{
+ Sto_Cls_t * pReason;
+ int i, v, Var, PrevId;
+ int fPrint = 0;
+ int clk = clock();
+
+ // collect resolvent literals
+ if ( p->fProofVerif )
+ {
+ assert( (int)pConflict->nLits <= p->nResLitsAlloc );
+ memcpy( p->pResLits, pConflict->pLits, sizeof(lit) * pConflict->nLits );
+ p->nResLits = pConflict->nLits;
+ }
+
+ // mark all the variables in the conflict as seen
+ for ( v = 0; v < (int)pConflict->nLits; v++ )
+ p->pSeens[lit_var(pConflict->pLits[v])] = 1;
+
+ // start the anticedents
+// pFinal->pAntis = Vec_PtrAlloc( 32 );
+// Vec_PtrPush( pFinal->pAntis, pConflict );
+
+ if ( p->pCnf->nClausesA )
+ Inta_ManAigCopy( p, Inta_ManAigRead(p, pFinal), Inta_ManAigRead(p, pConflict) );
+
+ // follow the trail backwards
+ PrevId = Inta_ManProofGet(p, pConflict);
+ for ( i = p->nTrailSize - 1; i >= 0; i-- )
+ {
+ // skip literals that are not involved
+ Var = lit_var(p->pTrail[i]);
+ if ( !p->pSeens[Var] )
+ continue;
+ p->pSeens[Var] = 0;
+
+ // skip literals of the resulting clause
+ pReason = p->pReasons[Var];
+ if ( pReason == NULL )
+ continue;
+ 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
+ assert( Inta_ManProofGet(p, pReason) > 0 );
+ p->Counter++;
+ if ( p->fProofWrite )
+ fprintf( p->pFile, "%d * %d %d 0\n", p->Counter, PrevId, Inta_ManProofGet(p, pReason) );
+ PrevId = p->Counter;
+
+ if ( p->pCnf->nClausesA )
+ {
+ if ( p->pVarTypes[Var] == 1 ) // var of A
+ Inta_ManAigOr( p, Inta_ManAigRead(p, pFinal), Inta_ManAigRead(p, pReason) );
+ else
+ Inta_ManAigAnd( p, Inta_ManAigRead(p, pFinal), Inta_ManAigRead(p, pReason) );
+ }
+
+ // resolve the temporary resolvent with the reason clause
+ if ( p->fProofVerif )
+ {
+ int v1, v2;
+ if ( fPrint )
+ Inta_ManPrintResolvent( p->pResLits, p->nResLits );
+ // check that the var is present in the resolvent
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ if ( lit_var(p->pResLits[v1]) == Var )
+ break;
+ if ( v1 == p->nResLits )
+ printf( "Recording clause %d: Cannot find variable %d in the temporary resolvent.\n", pFinal->Id, Var );
+ if ( p->pResLits[v1] != lit_neg(pReason->pLits[0]) )
+ printf( "Recording clause %d: The resolved variable %d is in the wrong polarity.\n", pFinal->Id, Var );
+ // remove this variable from the resolvent
+ assert( lit_var(p->pResLits[v1]) == Var );
+ p->nResLits--;
+ for ( ; v1 < p->nResLits; v1++ )
+ p->pResLits[v1] = p->pResLits[v1+1];
+ // add variables of the reason clause
+ for ( v2 = 1; v2 < (int)pReason->nLits; v2++ )
+ {
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ if ( lit_var(p->pResLits[v1]) == lit_var(pReason->pLits[v2]) )
+ break;
+ // if it is a new variable, add it to the resolvent
+ if ( v1 == p->nResLits )
+ {
+ if ( p->nResLits == p->nResLitsAlloc )
+ printf( "Recording clause %d: Ran out of space for intermediate resolvent.\n", pFinal->Id );
+ p->pResLits[ p->nResLits++ ] = pReason->pLits[v2];
+ continue;
+ }
+ // if the variable is the same, the literal should be the same too
+ if ( p->pResLits[v1] == pReason->pLits[v2] )
+ continue;
+ // the literal is different
+ printf( "Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->Id );
+ }
+ }
+
+// Vec_PtrPush( pFinal->pAntis, pReason );
+ }
+
+ // unmark all seen variables
+// for ( i = p->nTrailSize - 1; i >= 0; i-- )
+// 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
+ if ( p->fProofVerif )
+ {
+ int v1, v2;
+ if ( fPrint )
+ Inta_ManPrintResolvent( p->pResLits, p->nResLits );
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ {
+ for ( v2 = 0; v2 < (int)pFinal->nLits; v2++ )
+ if ( pFinal->pLits[v2] == p->pResLits[v1] )
+ break;
+ if ( v2 < (int)pFinal->nLits )
+ continue;
+ break;
+ }
+ if ( v1 < p->nResLits )
+ {
+ printf( "Recording clause %d: The final resolvent is wrong.\n", pFinal->Id );
+ Inta_ManPrintClause( p, pConflict );
+ Inta_ManPrintResolvent( p->pResLits, p->nResLits );
+ Inta_ManPrintClause( p, pFinal );
+ }
+ }
+p->timeTrace += clock() - clk;
+
+ // return the proof pointer
+ if ( p->pCnf->nClausesA )
+ {
+// Inta_ManPrintInterOne( p, pFinal );
+ }
+ Inta_ManProofSet( p, pFinal, p->Counter );
+ return p->Counter;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Inta_ManProofRecordOne( Inta_Man_t * p, Sto_Cls_t * pClause )
+{
+ Sto_Cls_t * pConflict;
+ int i;
+
+ // empty clause never ends up there
+ assert( pClause->nLits > 0 );
+ if ( pClause->nLits == 0 )
+ printf( "Error: Empty clause is attempted.\n" );
+
+ // add assumptions to the trail
+ assert( !pClause->fRoot );
+ assert( p->nTrailSize == p->nRootSize );
+ for ( i = 0; i < (int)pClause->nLits; i++ )
+ if ( !Inta_ManEnqueue( p, lit_neg(pClause->pLits[i]), NULL ) )
+ {
+ assert( 0 ); // impossible
+ return 0;
+ }
+
+ // propagate the assumptions
+ pConflict = Inta_ManPropagate( p, p->nRootSize );
+ if ( pConflict == NULL )
+ {
+ assert( 0 ); // cannot prove
+ return 0;
+ }
+
+ // construct the proof
+ Inta_ManProofTraceOne( p, pConflict, pClause );
+
+ // undo to the root level
+ Inta_ManCancelUntil( p, p->nRootSize );
+
+ // add large clauses to the watched lists
+ if ( pClause->nLits > 1 )
+ {
+ Inta_ManWatchClause( p, pClause, pClause->pLits[0] );
+ Inta_ManWatchClause( p, pClause, pClause->pLits[1] );
+ return 1;
+ }
+ assert( pClause->nLits == 1 );
+
+ // if the clause proved is unit, add it and propagate
+ if ( !Inta_ManEnqueue( p, pClause->pLits[0], pClause ) )
+ {
+ assert( 0 ); // impossible
+ return 0;
+ }
+
+ // propagate the assumption
+ pConflict = Inta_ManPropagate( p, p->nRootSize );
+ if ( pConflict )
+ {
+ // construct the proof
+ Inta_ManProofTraceOne( p, pConflict, p->pCnf->pEmpty );
+// if ( p->fVerbose )
+// printf( "Found last conflict after adding unit clause number %d!\n", pClause->Id );
+ return 0;
+ }
+
+ // update the root level
+ p->nRootSize = p->nTrailSize;
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate the root clauses.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Inta_ManProcessRoots( Inta_Man_t * p )
+{
+ Sto_Cls_t * pClause;
+ int Counter;
+
+ // make sure the root clauses are preceeding the learnt clauses
+ Counter = 0;
+ Sto_ManForEachClause( p->pCnf, pClause )
+ {
+ assert( (int)pClause->fA == (Counter < (int)p->pCnf->nClausesA) );
+ assert( (int)pClause->fRoot == (Counter < (int)p->pCnf->nRoots) );
+ Counter++;
+ }
+ assert( p->pCnf->nClauses == Counter );
+
+ // make sure the last clause if empty
+ assert( p->pCnf->pTail->nLits == 0 );
+
+ // go through the root unit clauses
+ p->nTrailSize = 0;
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ {
+ // create watcher lists for the root clauses
+ if ( pClause->nLits > 1 )
+ {
+ Inta_ManWatchClause( p, pClause, pClause->pLits[0] );
+ Inta_ManWatchClause( p, pClause, pClause->pLits[1] );
+ }
+ // empty clause and large clauses
+ if ( pClause->nLits != 1 )
+ continue;
+ // unit clause
+ assert( lit_check(pClause->pLits[0], p->pCnf->nVars) );
+ if ( !Inta_ManEnqueue( p, pClause->pLits[0], pClause ) )
+ {
+ // detected root level conflict
+ printf( "Error in Inta_ManProcessRoots(): Detected a root-level conflict too early!\n" );
+ assert( 0 );
+ return 0;
+ }
+ }
+
+ // propagate the root unit clauses
+ pClause = Inta_ManPropagate( p, 0 );
+ if ( pClause )
+ {
+ // detected root level conflict
+ Inta_ManProofTraceOne( p, pClause, p->pCnf->pEmpty );
+ if ( p->fVerbose )
+ printf( "Found root level conflict!\n" );
+ return 0;
+ }
+
+ // set the root level
+ p->nRootSize = p->nTrailSize;
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Inta_ManPrepareInter( Inta_Man_t * p )
+{
+ Sto_Cls_t * pClause;
+ int Var, VarAB, v;
+
+ // set interpolants for root clauses
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ {
+ if ( !pClause->fA ) // clause of B
+ {
+ Inta_ManAigFill( p, Inta_ManAigRead(p, pClause) );
+// Inta_ManPrintInterOne( p, pClause );
+ continue;
+ }
+ // clause of A
+ Inta_ManAigClear( p, Inta_ManAigRead(p, pClause) );
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ {
+ Var = lit_var(pClause->pLits[v]);
+ if ( p->pVarTypes[Var] < 0 ) // global var
+ {
+ VarAB = -p->pVarTypes[Var]-1;
+ assert( VarAB >= 0 && VarAB < Vec_IntSize(p->vVarsAB) );
+ if ( lit_sign(pClause->pLits[v]) ) // negative var
+ Inta_ManAigOrNotVar( p, Inta_ManAigRead(p, pClause), VarAB );
+ else
+ Inta_ManAigOrVar( p, Inta_ManAigRead(p, pClause), VarAB );
+ }
+ }
+// Inta_ManPrintInterOne( p, pClause );
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Computes interpolant for the given CNF.]
+
+ Description [Takes the interpolation manager, the CNF deriving by the SAT
+ solver, which includes ClausesA, ClausesB, and learned clauses. Additional
+ arguments are the vector of variables common to AB and the verbosiness flag.
+ Returns the AIG manager with a single output, containing the interpolant.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void * Inta_ManInterpolate( Inta_Man_t * p, Sto_Man_t * pCnf, void * vVarsAB, int fVerbose )
+{
+ Aig_Man_t * pRes;
+ Sto_Cls_t * pClause;
+ int RetValue = 1;
+ int clkTotal = clock();
+
+ // check that the CNF makes sense
+ assert( pCnf->nVars > 0 && pCnf->nClauses > 0 );
+ p->pCnf = pCnf;
+ p->fVerbose = fVerbose;
+ p->vVarsAB = vVarsAB;
+ p->pAig = pRes = Aig_ManStart( 10000 );
+ Aig_IthVar( p->pAig, Vec_IntSize(p->vVarsAB) - 1 );
+
+ // adjust the manager
+ Inta_ManResize( p );
+
+ // prepare the interpolant computation
+ Inta_ManPrepareInter( p );
+
+ // construct proof for each clause
+ // start the proof
+ if ( p->fProofWrite )
+ {
+ p->pFile = fopen( "proof.cnf_", "w" );
+ p->Counter = 0;
+ }
+
+ // write the root clauses
+ Sto_ManForEachClauseRoot( p->pCnf, pClause )
+ Inta_ManProofWriteOne( p, pClause );
+
+ // propagate root level assignments
+ if ( Inta_ManProcessRoots( p ) )
+ {
+ // if there is no conflict, consider learned clauses
+ Sto_ManForEachClause( p->pCnf, pClause )
+ {
+ if ( pClause->fRoot )
+ continue;
+ if ( !Inta_ManProofRecordOne( p, pClause ) )
+ {
+ RetValue = 0;
+ break;
+ }
+ }
+ }
+
+ // stop the proof
+ if ( p->fProofWrite )
+ {
+ fclose( p->pFile );
+ p->pFile = NULL;
+ }
+
+ if ( fVerbose )
+ {
+ PRT( "Interpo", clock() - clkTotal );
+ printf( "Vars = %d. Roots = %d. Learned = %d. Resol steps = %d. Ave = %.2f. Mem = %.2f Mb\n",
+ p->pCnf->nVars, p->pCnf->nRoots, p->pCnf->nClauses-p->pCnf->nRoots, p->Counter,
+ 1.0*(p->Counter-p->pCnf->nRoots)/(p->pCnf->nClauses-p->pCnf->nRoots),
+ 1.0*Sto_ManMemoryReport(p->pCnf)/(1<<20) );
+p->timeTotal += clock() - clkTotal;
+ }
+
+ Aig_ObjCreatePo( pRes, *Inta_ManAigRead( p, p->pCnf->pTail ) );
+ Aig_ManCleanup( pRes );
+
+ p->pAig = NULL;
+ return pRes;
+
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/sat/bsat/satMem.c b/src/sat/bsat/satMem.c
new file mode 100644
index 00000000..7fa1a824
--- /dev/null
+++ b/src/sat/bsat/satMem.c
@@ -0,0 +1,527 @@
+/**CFile****************************************************************
+
+ FileName [satMem.c]
+
+ 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: satMem.c,v 1.0 2004/01/01 1:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "satMem.h"
+#include "vec.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+struct Sat_MmFixed_t_
+{
+ // information about individual entries
+ int nEntrySize; // the size of one entry
+ int nEntriesAlloc; // the total number of entries allocated
+ int nEntriesUsed; // the number of entries in use
+ int nEntriesMax; // the max number of entries in use
+ char * pEntriesFree; // the linked list of free entries
+
+ // this is where the memory is stored
+ int nChunkSize; // the size of one chunk
+ int nChunksAlloc; // the maximum number of memory chunks
+ int nChunks; // the current number of memory chunks
+ char ** pChunks; // the allocated memory
+
+ // statistics
+ int nMemoryUsed; // memory used in the allocated entries
+ int nMemoryAlloc; // memory allocated
+};
+
+struct Sat_MmFlex_t_
+{
+ // information about individual entries
+ int nEntriesUsed; // the number of entries allocated
+ char * pCurrent; // the current pointer to free memory
+ char * pEnd; // the first entry outside the free memory
+
+ // this is where the memory is stored
+ int nChunkSize; // the size of one chunk
+ int nChunksAlloc; // the maximum number of memory chunks
+ int nChunks; // the current number of memory chunks
+ char ** pChunks; // the allocated memory
+
+ // statistics
+ int nMemoryUsed; // memory used in the allocated entries
+ int nMemoryAlloc; // memory allocated
+};
+
+struct Sat_MmStep_t_
+{
+ int nMems; // the number of fixed memory managers employed
+ Sat_MmFixed_t ** pMems; // memory managers: 2^1 words, 2^2 words, etc
+ int nMapSize; // the size of the memory array
+ Sat_MmFixed_t ** pMap; // maps the number of bytes into its memory manager
+};
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Allocates memory pieces of fixed size.]
+
+ Description [The size of the chunk is computed as the minimum of
+ 1024 entries and 64K. Can only work with entry size at least 4 byte long.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Sat_MmFixed_t * Sat_MmFixedStart( int nEntrySize )
+{
+ Sat_MmFixed_t * p;
+
+ p = ALLOC( Sat_MmFixed_t, 1 );
+ memset( p, 0, sizeof(Sat_MmFixed_t) );
+
+ p->nEntrySize = nEntrySize;
+ p->nEntriesAlloc = 0;
+ p->nEntriesUsed = 0;
+ p->pEntriesFree = NULL;
+
+ if ( nEntrySize * (1 << 10) < (1<<16) )
+ p->nChunkSize = (1 << 10);
+ else
+ p->nChunkSize = (1<<16) / nEntrySize;
+ if ( p->nChunkSize < 8 )
+ p->nChunkSize = 8;
+
+ p->nChunksAlloc = 64;
+ p->nChunks = 0;
+ p->pChunks = ALLOC( char *, p->nChunksAlloc );
+
+ p->nMemoryUsed = 0;
+ p->nMemoryAlloc = 0;
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_MmFixedStop( Sat_MmFixed_t * p, int fVerbose )
+{
+ int i;
+ if ( p == NULL )
+ return;
+ if ( fVerbose )
+ {
+ printf( "Fixed memory manager: Entry = %5d. Chunk = %5d. Chunks used = %5d.\n",
+ p->nEntrySize, p->nChunkSize, p->nChunks );
+ printf( " Entries used = %8d. Entries peak = %8d. Memory used = %8d. Memory alloc = %8d.\n",
+ p->nEntriesUsed, p->nEntriesMax, p->nEntrySize * p->nEntriesUsed, p->nMemoryAlloc );
+ }
+ for ( i = 0; i < p->nChunks; i++ )
+ free( p->pChunks[i] );
+ free( p->pChunks );
+ free( p );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Sat_MmFixedEntryFetch( Sat_MmFixed_t * p )
+{
+ char * pTemp;
+ int i;
+
+ // check if there are still free entries
+ if ( p->nEntriesUsed == p->nEntriesAlloc )
+ { // need to allocate more entries
+ assert( p->pEntriesFree == NULL );
+ if ( p->nChunks == p->nChunksAlloc )
+ {
+ p->nChunksAlloc *= 2;
+ p->pChunks = REALLOC( char *, p->pChunks, p->nChunksAlloc );
+ }
+ p->pEntriesFree = ALLOC( char, p->nEntrySize * p->nChunkSize );
+ p->nMemoryAlloc += p->nEntrySize * p->nChunkSize;
+ // transform these entries into a linked list
+ pTemp = p->pEntriesFree;
+ for ( i = 1; i < p->nChunkSize; i++ )
+ {
+ *((char **)pTemp) = pTemp + p->nEntrySize;
+ pTemp += p->nEntrySize;
+ }
+ // set the last link
+ *((char **)pTemp) = NULL;
+ // add the chunk to the chunk storage
+ p->pChunks[ p->nChunks++ ] = p->pEntriesFree;
+ // add to the number of entries allocated
+ p->nEntriesAlloc += p->nChunkSize;
+ }
+ // incrememt the counter of used entries
+ p->nEntriesUsed++;
+ if ( p->nEntriesMax < p->nEntriesUsed )
+ p->nEntriesMax = p->nEntriesUsed;
+ // return the first entry in the free entry list
+ pTemp = p->pEntriesFree;
+ p->pEntriesFree = *((char **)pTemp);
+ return pTemp;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_MmFixedEntryRecycle( Sat_MmFixed_t * p, char * pEntry )
+{
+ // decrement the counter of used entries
+ p->nEntriesUsed--;
+ // add the entry to the linked list of free entries
+ *((char **)pEntry) = p->pEntriesFree;
+ p->pEntriesFree = pEntry;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description [Relocates all the memory except the first chunk.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_MmFixedRestart( Sat_MmFixed_t * p )
+{
+ int i;
+ char * pTemp;
+
+ // deallocate all chunks except the first one
+ for ( i = 1; i < p->nChunks; i++ )
+ free( p->pChunks[i] );
+ p->nChunks = 1;
+ // transform these entries into a linked list
+ pTemp = p->pChunks[0];
+ for ( i = 1; i < p->nChunkSize; i++ )
+ {
+ *((char **)pTemp) = pTemp + p->nEntrySize;
+ pTemp += p->nEntrySize;
+ }
+ // set the last link
+ *((char **)pTemp) = NULL;
+ // set the free entry list
+ p->pEntriesFree = p->pChunks[0];
+ // set the correct statistics
+ p->nMemoryAlloc = p->nEntrySize * p->nChunkSize;
+ p->nMemoryUsed = 0;
+ p->nEntriesAlloc = p->nChunkSize;
+ p->nEntriesUsed = 0;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Sat_MmFixedReadMemUsage( Sat_MmFixed_t * p )
+{
+ return p->nMemoryAlloc;
+}
+
+
+
+/**Function*************************************************************
+
+ Synopsis [Allocates entries of flexible size.]
+
+ Description [Can only work with entry size at least 4 byte long.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Sat_MmFlex_t * Sat_MmFlexStart()
+{
+ Sat_MmFlex_t * p;
+
+ p = ALLOC( Sat_MmFlex_t, 1 );
+ memset( p, 0, sizeof(Sat_MmFlex_t) );
+
+ p->nEntriesUsed = 0;
+ p->pCurrent = NULL;
+ p->pEnd = NULL;
+
+ p->nChunkSize = (1 << 12);
+ p->nChunksAlloc = 64;
+ p->nChunks = 0;
+ p->pChunks = ALLOC( char *, p->nChunksAlloc );
+
+ p->nMemoryUsed = 0;
+ p->nMemoryAlloc = 0;
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_MmFlexStop( Sat_MmFlex_t * p, int fVerbose )
+{
+ int i;
+ if ( p == NULL )
+ return;
+ if ( fVerbose )
+ {
+ printf( "Flexible memory manager: Chunk size = %d. Chunks used = %d.\n",
+ p->nChunkSize, p->nChunks );
+ printf( " Entries used = %d. Memory used = %d. Memory alloc = %d.\n",
+ p->nEntriesUsed, p->nMemoryUsed, p->nMemoryAlloc );
+ }
+ for ( i = 0; i < p->nChunks; i++ )
+ free( p->pChunks[i] );
+ free( p->pChunks );
+ free( p );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Sat_MmFlexEntryFetch( Sat_MmFlex_t * p, int nBytes )
+{
+ char * pTemp;
+ // check if there are still free entries
+ if ( p->pCurrent == NULL || p->pCurrent + nBytes > p->pEnd )
+ { // need to allocate more entries
+ if ( p->nChunks == p->nChunksAlloc )
+ {
+ p->nChunksAlloc *= 2;
+ p->pChunks = REALLOC( char *, p->pChunks, p->nChunksAlloc );
+ }
+ if ( nBytes > p->nChunkSize )
+ {
+ // resize the chunk size if more memory is requested than it can give
+ // (ideally, this should never happen)
+ p->nChunkSize = 2 * nBytes;
+ }
+ p->pCurrent = ALLOC( char, p->nChunkSize );
+ p->pEnd = p->pCurrent + p->nChunkSize;
+ p->nMemoryAlloc += p->nChunkSize;
+ // add the chunk to the chunk storage
+ p->pChunks[ p->nChunks++ ] = p->pCurrent;
+ }
+ assert( p->pCurrent + nBytes <= p->pEnd );
+ // increment the counter of used entries
+ p->nEntriesUsed++;
+ // keep track of the memory used
+ p->nMemoryUsed += nBytes;
+ // return the next entry
+ pTemp = p->pCurrent;
+ p->pCurrent += nBytes;
+ return pTemp;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Sat_MmFlexReadMemUsage( Sat_MmFlex_t * p )
+{
+ return p->nMemoryAlloc;
+}
+
+
+
+
+
+/**Function*************************************************************
+
+ Synopsis [Starts the hierarchical memory manager.]
+
+ Description [This manager can allocate entries of any size.
+ Iternally they are mapped into the entries with the number of bytes
+ equal to the power of 2. The smallest entry size is 8 bytes. The
+ next one is 16 bytes etc. So, if the user requests 6 bytes, he gets
+ 8 byte entry. If we asks for 25 bytes, he gets 32 byte entry etc.
+ The input parameters "nSteps" says how many fixed memory managers
+ are employed internally. Calling this procedure with nSteps equal
+ to 10 results in 10 hierarchically arranged internal memory managers,
+ which can allocate up to 4096 (1Kb) entries. Requests for larger
+ entries are handed over to malloc() and then free()ed.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Sat_MmStep_t * Sat_MmStepStart( int nSteps )
+{
+ Sat_MmStep_t * p;
+ int i, k;
+ p = ALLOC( Sat_MmStep_t, 1 );
+ p->nMems = nSteps;
+ // start the fixed memory managers
+ p->pMems = ALLOC( Sat_MmFixed_t *, p->nMems );
+ for ( i = 0; i < p->nMems; i++ )
+ p->pMems[i] = Sat_MmFixedStart( (8<<i) );
+ // set up the mapping of the required memory size into the corresponding manager
+ p->nMapSize = (4<<p->nMems);
+ p->pMap = ALLOC( Sat_MmFixed_t *, p->nMapSize+1 );
+ p->pMap[0] = NULL;
+ for ( k = 1; k <= 4; k++ )
+ p->pMap[k] = p->pMems[0];
+ for ( i = 0; i < p->nMems; i++ )
+ for ( k = (4<<i)+1; k <= (8<<i); k++ )
+ p->pMap[k] = p->pMems[i];
+//for ( i = 1; i < 100; i ++ )
+//printf( "%10d: size = %10d\n", i, p->pMap[i]->nEntrySize );
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Stops the memory manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_MmStepStop( Sat_MmStep_t * p, int fVerbose )
+{
+ int i;
+ for ( i = 0; i < p->nMems; i++ )
+ Sat_MmFixedStop( p->pMems[i], fVerbose );
+ free( p->pMems );
+ free( p->pMap );
+ free( p );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Creates the entry.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Sat_MmStepEntryFetch( Sat_MmStep_t * p, int nBytes )
+{
+ if ( nBytes == 0 )
+ return NULL;
+ if ( nBytes > p->nMapSize )
+ {
+// printf( "Allocating %d bytes.\n", nBytes );
+ return ALLOC( char, nBytes );
+ }
+ return Sat_MmFixedEntryFetch( p->pMap[nBytes] );
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Recycles the entry.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_MmStepEntryRecycle( Sat_MmStep_t * p, char * pEntry, int nBytes )
+{
+ if ( nBytes == 0 )
+ return;
+ if ( nBytes > p->nMapSize )
+ {
+ free( pEntry );
+ return;
+ }
+ Sat_MmFixedEntryRecycle( p->pMap[nBytes], pEntry );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Sat_MmStepReadMemUsage( Sat_MmStep_t * p )
+{
+ int i, nMemTotal = 0;
+ for ( i = 0; i < p->nMems; i++ )
+ nMemTotal += p->pMems[i]->nMemoryAlloc;
+ return nMemTotal;
+}
diff --git a/src/sat/bsat/satMem.h b/src/sat/bsat/satMem.h
new file mode 100644
index 00000000..22b7a87c
--- /dev/null
+++ b/src/sat/bsat/satMem.h
@@ -0,0 +1,80 @@
+/**CFile****************************************************************
+
+ FileName [satMem.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: satMem.h,v 1.0 2004/01/01 1:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#ifndef __SAT_MEM_H__
+#define __SAT_MEM_H__
+
+////////////////////////////////////////////////////////////////////////
+/// INCLUDES ///
+////////////////////////////////////////////////////////////////////////
+
+//#include "leaks.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+////////////////////////////////////////////////////////////////////////
+/// PARAMETERS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// STRUCTURE DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+typedef struct Sat_MmFixed_t_ Sat_MmFixed_t;
+typedef struct Sat_MmFlex_t_ Sat_MmFlex_t;
+typedef struct Sat_MmStep_t_ Sat_MmStep_t;
+
+////////////////////////////////////////////////////////////////////////
+/// GLOBAL VARIABLES ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// MACRO DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+// fixed-size-block memory manager
+extern Sat_MmFixed_t * Sat_MmFixedStart( int nEntrySize );
+extern void Sat_MmFixedStop( Sat_MmFixed_t * p, int fVerbose );
+extern char * Sat_MmFixedEntryFetch( Sat_MmFixed_t * p );
+extern void Sat_MmFixedEntryRecycle( Sat_MmFixed_t * p, char * pEntry );
+extern void Sat_MmFixedRestart( Sat_MmFixed_t * p );
+extern int Sat_MmFixedReadMemUsage( Sat_MmFixed_t * p );
+// flexible-size-block memory manager
+extern Sat_MmFlex_t * Sat_MmFlexStart();
+extern void Sat_MmFlexStop( Sat_MmFlex_t * p, int fVerbose );
+extern char * Sat_MmFlexEntryFetch( Sat_MmFlex_t * p, int nBytes );
+extern int Sat_MmFlexReadMemUsage( Sat_MmFlex_t * p );
+// hierarchical memory manager
+extern Sat_MmStep_t * Sat_MmStepStart( int nSteps );
+extern void Sat_MmStepStop( Sat_MmStep_t * p, int fVerbose );
+extern char * Sat_MmStepEntryFetch( Sat_MmStep_t * p, int nBytes );
+extern void Sat_MmStepEntryRecycle( Sat_MmStep_t * p, char * pEntry, int nBytes );
+extern int Sat_MmStepReadMemUsage( Sat_MmStep_t * p );
+
+#endif
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
diff --git a/src/sat/asat/solver.c b/src/sat/bsat/satSolver.c
index c9dadcb4..fbc9874d 100644
--- a/src/sat/asat/solver.c
+++ b/src/sat/bsat/satSolver.c
@@ -21,15 +21,12 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
#include <stdio.h>
#include <assert.h>
+#include <string.h>
#include <math.h>
-#include "solver.h"
+#include "satSolver.h"
-//=================================================================================================
-// Simple (var/literal) helpers:
-
-static inline int lit_var(lit l) { return l >> 1; }
-static inline int lit_sign(lit l) { return (l & 1); }
+//#define SAT_USE_SYSTEM_MEMORY_MANAGEMENT
//=================================================================================================
// Debug:
@@ -38,7 +35,7 @@ static inline int lit_sign(lit l) { return (l & 1); }
// For derivation output (verbosity level 2)
#define L_IND "%-*d"
-#define L_ind solver_dlevel(s)*3+3,solver_dlevel(s)
+#define L_ind sat_solver_dlevel(s)*3+3,sat_solver_dlevel(s)
#define L_LIT "%sx%d"
#define L_lit(p) lit_sign(p)?"~":"", (lit_var(p))
@@ -73,7 +70,7 @@ static inline int irand(double* seed, int size) {
//=================================================================================================
// Predeclarations:
-void sort(void** array, int size, int(*comp)(const void *, const void *));
+static void sat_solver_sort(void** array, int size, int(*comp)(const void *, const void *));
//=================================================================================================
// Clause datatype + minor functions:
@@ -93,34 +90,33 @@ static inline void clause_setactivity(clause* c, float a) { *((float*)&c->lits[
//=================================================================================================
// Encode literals in clause pointers:
-clause* clause_from_lit (lit l) { return (clause*)(l + l + 1); }
-bool clause_is_lit (clause* c) { return ((unsigned int)c & 1); }
-lit clause_read_lit (clause* c) { return (lit)((unsigned int)c >> 1); }
+static inline clause* clause_from_lit (lit l) { return (clause*)((unsigned long)l + (unsigned long)l + 1); }
+static inline bool clause_is_lit (clause* c) { return ((unsigned long)c & 1); }
+static inline lit clause_read_lit (clause* c) { return (lit)((unsigned long)c >> 1); }
//=================================================================================================
// Simple helpers:
-static inline int solver_dlevel(solver* s) { return vec_size(&s->trail_lim); }
-static inline vec* solver_read_wlist (solver* s, lit l){ return &s->wlists[l]; }
-static inline void vec_remove(vec* v, void* e)
+static inline int sat_solver_dlevel(sat_solver* s) { return veci_size(&s->trail_lim); }
+static inline vecp* sat_solver_read_wlist(sat_solver* s, lit l) { return &s->wlists[l]; }
+static inline void vecp_remove(vecp* v, void* e)
{
- void** ws = vec_begin(v);
+ void** ws = vecp_begin(v);
int j = 0;
-
for (; ws[j] != e ; j++);
- assert(j < vec_size(v));
- for (; j < vec_size(v)-1; j++) ws[j] = ws[j+1];
- vec_resize(v,vec_size(v)-1);
+ assert(j < vecp_size(v));
+ for (; j < vecp_size(v)-1; j++) ws[j] = ws[j+1];
+ vecp_resize(v,vecp_size(v)-1);
}
//=================================================================================================
// Variable order functions:
-static inline void order_update(solver* s, int v) // updateorder
+static inline void order_update(sat_solver* s, int v) // updateorder
{
int* orderpos = s->orderpos;
double* activity = s->activity;
- int* heap = (int*)vec_begin(&s->order);
+ int* heap = veci_begin(&s->order);
int i = orderpos[v];
int x = heap[i];
int parent = (i - 1) / 2;
@@ -137,21 +133,22 @@ static inline void order_update(solver* s, int v) // updateorder
orderpos[x] = i;
}
-static inline void order_assigned(solver* s, int v)
+static inline void order_assigned(sat_solver* s, int v)
{
}
-static inline void order_unassigned(solver* s, int v) // undoorder
+static inline void order_unassigned(sat_solver* s, int v) // undoorder
{
int* orderpos = s->orderpos;
if (orderpos[v] == -1){
- orderpos[v] = vec_size(&s->order);
- vec_push(&s->order,(void*)v);
+ orderpos[v] = veci_size(&s->order);
+ veci_push(&s->order,v);
order_update(s,v);
+//printf( "+%d ", v );
}
}
-static int order_select(solver* s, float random_var_freq) // selectvar
+static inline int order_select(sat_solver* s, float random_var_freq) // selectvar
{
int* heap;
double* activity;
@@ -169,17 +166,17 @@ static int order_select(solver* s, float random_var_freq) // selectvar
// Activity based decision:
- heap = (int*)vec_begin(&s->order);
+ heap = veci_begin(&s->order);
activity = s->activity;
orderpos = s->orderpos;
- while (vec_size(&s->order) > 0){
+ while (veci_size(&s->order) > 0){
int next = heap[0];
- int size = vec_size(&s->order)-1;
+ int size = veci_size(&s->order)-1;
int x = heap[size];
- vec_resize(&s->order,size);
+ veci_resize(&s->order,size);
orderpos[next] = -1;
@@ -208,6 +205,7 @@ static int order_select(solver* s, float random_var_freq) // selectvar
orderpos[heap[i]] = i;
}
+//printf( "-%d ", next );
if (values[next] == l_Undef)
return next;
}
@@ -218,7 +216,7 @@ static int order_select(solver* s, float random_var_freq) // selectvar
//=================================================================================================
// Activity functions:
-static inline void act_var_rescale(solver* s) {
+static inline void act_var_rescale(sat_solver* s) {
double* activity = s->activity;
int i;
for (i = 0; i < s->size; i++)
@@ -226,24 +224,30 @@ static inline void act_var_rescale(solver* s) {
s->var_inc *= 1e-100;
}
-static inline void act_var_bump(solver* s, int v) {
- double* activity = s->activity;
- if ((activity[v] += s->var_inc) > 1e100)
+static inline void act_var_bump(sat_solver* s, int v) {
+ s->activity[v] += s->var_inc;
+ if (s->activity[v] > 1e100)
act_var_rescale(s);
-
//printf("bump %d %f\n", v-1, activity[v]);
-
if (s->orderpos[v] != -1)
order_update(s,v);
+}
+static inline void act_var_bump_factor(sat_solver* s, int v) {
+ s->activity[v] += (s->var_inc * s->factors[v]);
+ if (s->activity[v] > 1e100)
+ act_var_rescale(s);
+ //printf("bump %d %f\n", v-1, activity[v]);
+ if (s->orderpos[v] != -1)
+ order_update(s,v);
}
-static inline void act_var_decay(solver* s) { s->var_inc *= s->var_decay; }
+static inline void act_var_decay(sat_solver* s) { s->var_inc *= s->var_decay; }
-static inline void act_clause_rescale(solver* s) {
- clause** cs = (clause**)vec_begin(&s->learnts);
+static inline void act_clause_rescale(sat_solver* s) {
+ clause** cs = (clause**)vecp_begin(&s->learnts);
int i;
- for (i = 0; i < vec_size(&s->learnts); i++){
+ for (i = 0; i < vecp_size(&s->learnts); i++){
float a = clause_activity(cs[i]);
clause_setactivity(cs[i], a * (float)1e-20);
}
@@ -251,21 +255,20 @@ static inline void act_clause_rescale(solver* s) {
}
-static inline void act_clause_bump(solver* s, clause *c) {
+static inline void act_clause_bump(sat_solver* s, clause *c) {
float a = clause_activity(c) + s->cla_inc;
clause_setactivity(c,a);
if (a > 1e20) act_clause_rescale(s);
}
-static inline void act_clause_decay(solver* s) { s->cla_inc *= s->cla_decay; }
-
+static inline void act_clause_decay(sat_solver* s) { s->cla_inc *= s->cla_decay; }
//=================================================================================================
// Clause functions:
/* pre: size > 1 && no variable occurs twice
*/
-static clause* clause_new(solver* s, lit* begin, lit* end, int learnt)
+static clause* clause_new(sat_solver* s, lit* begin, lit* end, int learnt)
{
int size;
clause* c;
@@ -274,9 +277,15 @@ static clause* clause_new(solver* s, lit* begin, lit* end, int learnt)
assert(end - begin > 1);
assert(learnt >= 0 && learnt < 2);
size = end - begin;
- c = (clause*)malloc(sizeof(clause) + sizeof(lit) * size + learnt * sizeof(float));
+// c = (clause*)malloc(sizeof(clause) + sizeof(lit) * size + learnt * sizeof(float));
+#ifdef SAT_USE_SYSTEM_MEMORY_MANAGEMENT
+ c = (clause*)malloc(sizeof(clause) + sizeof(lit) * size + learnt * sizeof(float));
+#else
+ c = (clause*)Sat_MmStepEntryFetch( s->pMem, sizeof(clause) + sizeof(lit) * size + learnt * sizeof(float) );
+#endif
+
c->size_learnt = (size << 1) | learnt;
- assert(((unsigned int)c & 1) == 0);
+ assert(((unsigned long)c & 1) == 0);
for (i = 0; i < size; i++)
c->lits[i] = begin[i];
@@ -289,31 +298,31 @@ static clause* clause_new(solver* s, lit* begin, lit* end, int learnt)
assert(begin[1] >= 0);
assert(begin[1] < s->size*2);
- assert(neg(begin[0]) < s->size*2);
- assert(neg(begin[1]) < s->size*2);
+ assert(lit_neg(begin[0]) < s->size*2);
+ assert(lit_neg(begin[1]) < s->size*2);
- //vec_push(solver_read_wlist(s,neg(begin[0])),(void*)c);
- //vec_push(solver_read_wlist(s,neg(begin[1])),(void*)c);
+ //vecp_push(sat_solver_read_wlist(s,lit_neg(begin[0])),(void*)c);
+ //vecp_push(sat_solver_read_wlist(s,lit_neg(begin[1])),(void*)c);
- vec_push(solver_read_wlist(s,neg(begin[0])),(void*)(size > 2 ? c : clause_from_lit(begin[1])));
- vec_push(solver_read_wlist(s,neg(begin[1])),(void*)(size > 2 ? c : clause_from_lit(begin[0])));
+ vecp_push(sat_solver_read_wlist(s,lit_neg(begin[0])),(void*)(size > 2 ? c : clause_from_lit(begin[1])));
+ vecp_push(sat_solver_read_wlist(s,lit_neg(begin[1])),(void*)(size > 2 ? c : clause_from_lit(begin[0])));
return c;
}
-static void clause_remove(solver* s, clause* c)
+static void clause_remove(sat_solver* s, clause* c)
{
lit* lits = clause_begin(c);
- assert(neg(lits[0]) < s->size*2);
- assert(neg(lits[1]) < s->size*2);
+ assert(lit_neg(lits[0]) < s->size*2);
+ assert(lit_neg(lits[1]) < s->size*2);
- //vec_remove(solver_read_wlist(s,neg(lits[0])),(void*)c);
- //vec_remove(solver_read_wlist(s,neg(lits[1])),(void*)c);
+ //vecp_remove(sat_solver_read_wlist(s,lit_neg(lits[0])),(void*)c);
+ //vecp_remove(sat_solver_read_wlist(s,lit_neg(lits[1])),(void*)c);
assert(lits[0] < s->size*2);
- vec_remove(solver_read_wlist(s,neg(lits[0])),(void*)(clause_size(c) > 2 ? c : clause_from_lit(lits[1])));
- vec_remove(solver_read_wlist(s,neg(lits[1])),(void*)(clause_size(c) > 2 ? c : clause_from_lit(lits[0])));
+ vecp_remove(sat_solver_read_wlist(s,lit_neg(lits[0])),(void*)(clause_size(c) > 2 ? c : clause_from_lit(lits[1])));
+ vecp_remove(sat_solver_read_wlist(s,lit_neg(lits[1])),(void*)(clause_size(c) > 2 ? c : clause_from_lit(lits[0])));
if (clause_learnt(c)){
s->stats.learnts--;
@@ -323,17 +332,21 @@ static void clause_remove(solver* s, clause* c)
s->stats.clauses_literals -= clause_size(c);
}
+#ifdef SAT_USE_SYSTEM_MEMORY_MANAGEMENT
free(c);
+#else
+ Sat_MmStepEntryRecycle( s->pMem, (char *)c, sizeof(clause) + sizeof(lit) * clause_size(c) + clause_learnt(c) * sizeof(float) );
+#endif
}
-static lbool clause_simplify(solver* s, clause* c)
+static lbool clause_simplify(sat_solver* s, clause* c)
{
lit* lits = clause_begin(c);
lbool* values = s->assigns;
int i;
- assert(solver_dlevel(s) == 0);
+ assert(sat_solver_dlevel(s) == 0);
for (i = 0; i < clause_size(c); i++){
lbool sig = !lit_sign(lits[i]); sig += sig - 1;
@@ -346,15 +359,17 @@ static lbool clause_simplify(solver* s, clause* c)
//=================================================================================================
// Minor (solver) functions:
-static void solver_setnvars(solver* s,int n)
+void sat_solver_setnvars(sat_solver* s,int n)
{
int var;
+
if (s->cap < n){
while (s->cap < n) s->cap = s->cap*2+1;
- s->wlists = (vec*) realloc(s->wlists, sizeof(vec)*s->cap*2);
+ s->wlists = (vecp*) realloc(s->wlists, sizeof(vecp)*s->cap*2);
s->activity = (double*) realloc(s->activity, sizeof(double)*s->cap);
+ s->factors = (double*) realloc(s->factors, sizeof(double)*s->cap);
s->assigns = (lbool*) realloc(s->assigns, sizeof(lbool)*s->cap);
s->orderpos = (int*) realloc(s->orderpos, sizeof(int)*s->cap);
s->reasons = (clause**)realloc(s->reasons, sizeof(clause*)*s->cap);
@@ -364,25 +379,28 @@ static void solver_setnvars(solver* s,int n)
}
for (var = s->size; var < n; var++){
- vec_new(&s->wlists[2*var]);
- vec_new(&s->wlists[2*var+1]);
+ vecp_new(&s->wlists[2*var]);
+ vecp_new(&s->wlists[2*var+1]);
s->activity [var] = 0;
+ s->factors [var] = 0;
s->assigns [var] = l_Undef;
- s->orderpos [var] = var;
+ s->orderpos [var] = veci_size(&s->order);
s->reasons [var] = (clause*)0;
s->levels [var] = 0;
s->tags [var] = l_Undef;
-
- assert(vec_size(&s->order) == var);
- vec_push(&s->order,(void*)var);
- order_update(s,var);
+
+ /* does not hold because variables enqueued at top level will not be reinserted in the heap
+ assert(veci_size(&s->order) == var);
+ */
+ veci_push(&s->order,var);
+ order_update(s, var);
}
s->size = n > s->size ? n : s->size;
}
-static inline bool enqueue(solver* s, lit l, clause* from)
+static inline bool enqueue(sat_solver* s, lit l, clause* from)
{
lbool* values = s->assigns;
int v = lit_var(l);
@@ -403,7 +421,7 @@ static inline bool enqueue(solver* s, lit l, clause* from)
clause** reasons = s->reasons;
values [v] = sig;
- levels [v] = solver_dlevel(s);
+ levels [v] = sat_solver_dlevel(s);
reasons[v] = from;
s->trail[s->qtail++] = l;
@@ -413,31 +431,37 @@ static inline bool enqueue(solver* s, lit l, clause* from)
}
-static inline void assume(solver* s, lit l){
+static inline void assume(sat_solver* s, lit l){
assert(s->qtail == s->qhead);
assert(s->assigns[lit_var(l)] == l_Undef);
#ifdef VERBOSEDEBUG
printf(L_IND"assume("L_LIT")\n", L_ind, L_lit(l));
#endif
- vec_push(&s->trail_lim,(void*)s->qtail);
+ veci_push(&s->trail_lim,s->qtail);
enqueue(s,l,(clause*)0);
}
-static inline void solver_canceluntil(solver* s, int level) {
+static void sat_solver_canceluntil(sat_solver* s, int level) {
lit* trail;
lbool* values;
clause** reasons;
int bound;
int c;
- if (solver_dlevel(s) <= level)
+ if (sat_solver_dlevel(s) <= level)
return;
trail = s->trail;
values = s->assigns;
reasons = s->reasons;
- bound = ((int*)vec_begin(&s->trail_lim))[level];
+ bound = (veci_begin(&s->trail_lim))[level];
+
+ ////////////////////////////////////////
+ // added to cancel all assignments
+// if ( level == -1 )
+// bound = 0;
+ ////////////////////////////////////////
for (c = s->qtail-1; c >= bound; c--) {
int x = lit_var(trail[c]);
@@ -449,28 +473,38 @@ static inline void solver_canceluntil(solver* s, int level) {
order_unassigned(s,lit_var(trail[c]));
s->qhead = s->qtail = bound;
- vec_resize(&s->trail_lim,level);
+ veci_resize(&s->trail_lim,level);
}
-static void solver_record(solver* s, vec* cls)
+static void sat_solver_record(sat_solver* s, veci* cls)
{
- lit* begin = (lit*)vec_begin(cls);
- lit* end = begin + vec_size(cls);
- clause* c = (vec_size(cls) > 1) ? clause_new(s,begin,end,1) : (clause*)0;
+ lit* begin = veci_begin(cls);
+ lit* end = begin + veci_size(cls);
+ clause* c = (veci_size(cls) > 1) ? clause_new(s,begin,end,1) : (clause*)0;
enqueue(s,*begin,c);
- assert(vec_size(cls) > 0);
+ ///////////////////////////////////
+ // 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);
if (c != 0) {
- vec_push(&s->learnts,(void*)c);
+ vecp_push(&s->learnts,c);
act_clause_bump(s,c);
s->stats.learnts++;
- s->stats.learnts_literals += vec_size(cls);
+ s->stats.learnts_literals += veci_size(cls);
}
}
-static double solver_progress(solver* s)
+static double sat_solver_progress(sat_solver* s)
{
lbool* values = s->assigns;
int* levels = s->levels;
@@ -487,23 +521,23 @@ static double solver_progress(solver* s)
//=================================================================================================
// Major methods:
-static bool solver_lit_removable(solver* s, lit l, int minl)
+static bool sat_solver_lit_removable(sat_solver* s, lit l, int minl)
{
lbool* tags = s->tags;
clause** reasons = s->reasons;
int* levels = s->levels;
- int top = vec_size(&s->tagged);
+ int top = veci_size(&s->tagged);
assert(lit_var(l) >= 0 && lit_var(l) < s->size);
assert(reasons[lit_var(l)] != 0);
- vec_resize(&s->stack,0);
- vec_push(&s->stack,(void*)lit_var(l));
+ veci_resize(&s->stack,0);
+ veci_push(&s->stack,lit_var(l));
- while (vec_size(&s->stack) > 0){
+ while (veci_size(&s->stack) > 0){
clause* c;
- int v = (int)vec_begin(&s->stack)[vec_size(&s->stack)-1];
+ int v = veci_begin(&s->stack)[veci_size(&s->stack)-1];
assert(v >= 0 && v < s->size);
- vec_resize(&s->stack,vec_size(&s->stack)-1);
+ veci_resize(&s->stack,veci_size(&s->stack)-1);
assert(reasons[v] != 0);
c = reasons[v];
@@ -511,15 +545,15 @@ static bool solver_lit_removable(solver* s, lit l, int minl)
int v = lit_var(clause_read_lit(c));
if (tags[v] == l_Undef && levels[v] != 0){
if (reasons[v] != 0 && ((1 << (levels[v] & 31)) & minl)){
- vec_push(&s->stack,(void*)v);
+ veci_push(&s->stack,v);
tags[v] = l_True;
- vec_push(&s->tagged,(void*)v);
+ veci_push(&s->tagged,v);
}else{
- int* tagged = (int*)vec_begin(&s->tagged);
+ int* tagged = veci_begin(&s->tagged);
int j;
- for (j = top; j < vec_size(&s->tagged); j++)
+ for (j = top; j < veci_size(&s->tagged); j++)
tags[tagged[j]] = l_Undef;
- vec_resize(&s->tagged,top);
+ veci_resize(&s->tagged,top);
return false;
}
}
@@ -532,14 +566,14 @@ static bool solver_lit_removable(solver* s, lit l, int minl)
if (tags[v] == l_Undef && levels[v] != 0){
if (reasons[v] != 0 && ((1 << (levels[v] & 31)) & minl)){
- vec_push(&s->stack,(void*)lit_var(lits[i]));
+ veci_push(&s->stack,lit_var(lits[i]));
tags[v] = l_True;
- vec_push(&s->tagged,(void*)v);
+ veci_push(&s->tagged,v);
}else{
- int* tagged = (int*)vec_begin(&s->tagged);
- for (j = top; j < vec_size(&s->tagged); j++)
+ int* tagged = veci_begin(&s->tagged);
+ for (j = top; j < veci_size(&s->tagged); j++)
tags[tagged[j]] = l_Undef;
- vec_resize(&s->tagged,top);
+ veci_resize(&s->tagged,top);
return false;
}
}
@@ -550,7 +584,7 @@ static bool solver_lit_removable(solver* s, lit l, int minl)
return true;
}
-static void solver_analyze(solver* s, clause* c, vec* learnt)
+static void sat_solver_analyze(sat_solver* s, clause* c, veci* learnt)
{
lit* trail = s->trail;
lbool* tags = s->tags;
@@ -563,7 +597,7 @@ static void solver_analyze(solver* s, clause* c, vec* learnt)
int i, j, minl;
int* tagged;
- vec_push(learnt,(void*)lit_Undef);
+ veci_push(learnt,lit_Undef);
do{
assert(c != 0);
@@ -573,12 +607,12 @@ static void solver_analyze(solver* s, clause* c, vec* learnt)
assert(lit_var(q) >= 0 && lit_var(q) < s->size);
if (tags[lit_var(q)] == l_Undef && levels[lit_var(q)] > 0){
tags[lit_var(q)] = l_True;
- vec_push(&s->tagged,(void*)lit_var(q));
+ veci_push(&s->tagged,lit_var(q));
act_var_bump(s,lit_var(q));
- if (levels[lit_var(q)] == solver_dlevel(s))
+ if (levels[lit_var(q)] == sat_solver_dlevel(s))
cnt++;
else
- vec_push(learnt,(void*)q);
+ veci_push(learnt,q);
}
}else{
@@ -592,12 +626,12 @@ static void solver_analyze(solver* s, clause* c, vec* learnt)
assert(lit_var(q) >= 0 && lit_var(q) < s->size);
if (tags[lit_var(q)] == l_Undef && levels[lit_var(q)] > 0){
tags[lit_var(q)] = l_True;
- vec_push(&s->tagged,(void*)lit_var(q));
+ veci_push(&s->tagged,lit_var(q));
act_var_bump(s,lit_var(q));
- if (levels[lit_var(q)] == solver_dlevel(s))
+ if (levels[lit_var(q)] == sat_solver_dlevel(s))
cnt++;
else
- vec_push(learnt,(void*)q);
+ veci_push(learnt,q);
}
}
}
@@ -610,31 +644,31 @@ static void solver_analyze(solver* s, clause* c, vec* learnt)
}while (cnt > 0);
- *(lit*)vec_begin(learnt) = neg(p);
+ *veci_begin(learnt) = lit_neg(p);
- lits = (lit*)vec_begin(learnt);
+ lits = veci_begin(learnt);
minl = 0;
- for (i = 1; i < vec_size(learnt); i++){
+ for (i = 1; i < veci_size(learnt); i++){
int lev = levels[lit_var(lits[i])];
minl |= 1 << (lev & 31);
}
// simplify (full)
- for (i = j = 1; i < vec_size(learnt); i++){
- if (reasons[lit_var(lits[i])] == 0 || !solver_lit_removable(s,lits[i],minl))
+ for (i = j = 1; i < veci_size(learnt); i++){
+ if (reasons[lit_var(lits[i])] == 0 || !sat_solver_lit_removable(s,lits[i],minl))
lits[j++] = lits[i];
}
// update size of learnt + statistics
- s->stats.max_literals += vec_size(learnt);
- vec_resize(learnt,j);
+ s->stats.max_literals += veci_size(learnt);
+ veci_resize(learnt,j);
s->stats.tot_literals += j;
// clear tags
- tagged = (int*)vec_begin(&s->tagged);
- for (i = 0; i < vec_size(&s->tagged); i++)
+ tagged = veci_begin(&s->tagged);
+ for (i = 0; i < veci_size(&s->tagged); i++)
tags[tagged[i]] = l_Undef;
- vec_resize(&s->tagged,0);
+ veci_resize(&s->tagged,0);
#ifdef DEBUG
for (i = 0; i < s->size; i++)
@@ -643,14 +677,14 @@ static void solver_analyze(solver* s, clause* c, vec* learnt)
#ifdef VERBOSEDEBUG
printf(L_IND"Learnt {", L_ind);
- for (i = 0; i < vec_size(learnt); i++) printf(" "L_LIT, L_lit(lits[i]));
+ for (i = 0; i < veci_size(learnt); i++) printf(" "L_LIT, L_lit(lits[i]));
#endif
- if (vec_size(learnt) > 1){
+ if (veci_size(learnt) > 1){
int max_i = 1;
int max = levels[lit_var(lits[1])];
lit tmp;
- for (i = 2; i < vec_size(learnt); i++)
+ for (i = 2; i < veci_size(learnt); i++)
if (levels[lit_var(lits[i])] > max){
max = levels[lit_var(lits[i])];
max_i = i;
@@ -662,40 +696,41 @@ static void solver_analyze(solver* s, clause* c, vec* learnt)
}
#ifdef VERBOSEDEBUG
{
- int lev = vec_size(learnt) > 1 ? levels[lit_var(lits[1])] : 0;
+ int lev = veci_size(learnt) > 1 ? levels[lit_var(lits[1])] : 0;
printf(" } at level %d\n", lev);
}
#endif
}
-clause* solver_propagate(solver* s)
+clause* sat_solver_propagate(sat_solver* s)
{
lbool* values = s->assigns;
clause* confl = (clause*)0;
lit* lits;
- //printf("solver_propagate\n");
+ //printf("sat_solver_propagate\n");
while (confl == 0 && s->qtail - s->qhead > 0){
lit p = s->trail[s->qhead++];
- vec* ws = solver_read_wlist(s,p);
- clause **begin = (clause**)vec_begin(ws);
- clause **end = begin + vec_size(ws);
+ vecp* ws = sat_solver_read_wlist(s,p);
+ clause **begin = (clause**)vecp_begin(ws);
+ clause **end = begin + vecp_size(ws);
clause **i, **j;
s->stats.propagations++;
s->simpdb_props--;
- //printf("checking lit %d: "L_LIT"\n", vec_size(ws), L_lit(p));
+ //printf("checking lit %d: "L_LIT"\n", veci_size(ws), L_lit(p));
for (i = j = begin; i < end; ){
if (clause_is_lit(*i)){
+// s->stats.inspects2++;
*j++ = *i;
if (!enqueue(s,clause_read_lit(*i),clause_from_lit(p))){
confl = s->binary;
- (clause_begin(confl))[1] = neg(p);
+ (clause_begin(confl))[1] = lit_neg(p);
(clause_begin(confl))[0] = clause_read_lit(*i++);
-
// Copy the remaining watches:
+// s->stats.inspects2 += end - i;
while (i < end)
*j++ = *i++;
}
@@ -706,7 +741,7 @@ clause* solver_propagate(solver* s)
lits = clause_begin(*i);
// Make sure the false literal is data[1]:
- false_lit = neg(p);
+ false_lit = lit_neg(p);
if (lits[0] == false_lit){
lits[0] = lits[1];
lits[1] = false_lit;
@@ -727,7 +762,7 @@ clause* solver_propagate(solver* s)
if (values[lit_var(*k)] != sig){
lits[1] = *k;
*k = false_lit;
- vec_push(solver_read_wlist(s,neg(lits[1])),*i);
+ vecp_push(sat_solver_read_wlist(s,lit_neg(lits[1])),*i);
goto next; }
}
@@ -736,6 +771,7 @@ clause* solver_propagate(solver* s)
if (!enqueue(s,lits[0], *i)){
confl = *i++;
// Copy the remaining watches:
+// s->stats.inspects2 += end - i;
while (i < end)
*j++ = *i++;
}
@@ -745,8 +781,8 @@ clause* solver_propagate(solver* s)
i++;
}
- s->stats.inspects += j - (clause**)vec_begin(ws);
- vec_resize(ws,j - (clause**)vec_begin(ws));
+ s->stats.inspects += j - (clause**)vecp_begin(ws);
+ vecp_resize(ws,j - (clause**)vecp_begin(ws));
}
return confl;
@@ -755,54 +791,61 @@ clause* solver_propagate(solver* s)
static inline int clause_cmp (const void* x, const void* y) {
return clause_size((clause*)x) > 2 && (clause_size((clause*)y) == 2 || clause_activity((clause*)x) < clause_activity((clause*)y)) ? -1 : 1; }
-void solver_reducedb(solver* s)
+void sat_solver_reducedb(sat_solver* s)
{
int i, j;
- double extra_lim = s->cla_inc / vec_size(&s->learnts); // Remove any clause below this activity
- clause** learnts = (clause**)vec_begin(&s->learnts);
+ double extra_lim = s->cla_inc / vecp_size(&s->learnts); // Remove any clause below this activity
+ clause** learnts = (clause**)vecp_begin(&s->learnts);
clause** reasons = s->reasons;
- sort(vec_begin(&s->learnts), vec_size(&s->learnts), &clause_cmp);
+ sat_solver_sort(vecp_begin(&s->learnts), vecp_size(&s->learnts), &clause_cmp);
- for (i = j = 0; i < vec_size(&s->learnts) / 2; i++){
+ for (i = j = 0; i < vecp_size(&s->learnts) / 2; i++){
if (clause_size(learnts[i]) > 2 && reasons[lit_var(*clause_begin(learnts[i]))] != learnts[i])
clause_remove(s,learnts[i]);
else
learnts[j++] = learnts[i];
}
- for (; i < vec_size(&s->learnts); i++){
+ for (; i < vecp_size(&s->learnts); i++){
if (clause_size(learnts[i]) > 2 && reasons[lit_var(*clause_begin(learnts[i]))] != learnts[i] && clause_activity(learnts[i]) < extra_lim)
clause_remove(s,learnts[i]);
else
learnts[j++] = learnts[i];
}
- //printf("reducedb deleted %d\n", vec_size(&s->learnts) - j);
+ //printf("reducedb deleted %d\n", vecp_size(&s->learnts) - j);
- vec_resize(&s->learnts,j);
+ vecp_resize(&s->learnts,j);
}
-static lbool solver_search(solver* s, int nof_conflicts, int nof_learnts)
+static lbool sat_solver_search(sat_solver* s, sint64 nof_conflicts, sint64 nof_learnts)
{
int* levels = s->levels;
double var_decay = 0.95;
double clause_decay = 0.999;
double random_var_freq = 0.02;
- int conflictC = 0;
- vec learnt_clause;
+ sint64 conflictC = 0;
+ veci learnt_clause;
+ int i;
- assert(s->root_level == solver_dlevel(s));
+ assert(s->root_level == sat_solver_dlevel(s));
+ s->nRestarts++;
s->stats.starts++;
s->var_decay = (float)(1 / var_decay );
s->cla_decay = (float)(1 / clause_decay);
- vec_resize(&s->model,0);
- vec_new(&learnt_clause);
+ veci_resize(&s->model,0);
+ veci_new(&learnt_clause);
+
+ // use activity factors in every even restart
+ if ( (s->nRestarts & 1) && veci_size(&s->act_vars) > 0 )
+ for ( i = 0; i < s->act_vars.size; i++ )
+ act_var_bump_factor(s, s->act_vars.ptr[i]);
for (;;){
- clause* confl = solver_propagate(s);
+ clause* confl = sat_solver_propagate(s);
if (confl != 0){
// CONFLICT
int blevel;
@@ -811,16 +854,17 @@ static lbool solver_search(solver* s, int nof_conflicts, int nof_learnts)
printf(L_IND"**CONFLICT**\n", L_ind);
#endif
s->stats.conflicts++; conflictC++;
- if (solver_dlevel(s) == s->root_level){
- vec_delete(&learnt_clause);
+ if (sat_solver_dlevel(s) == s->root_level){
+ veci_delete(&learnt_clause);
return l_False;
}
- vec_resize(&learnt_clause,0);
- solver_analyze(s, confl, &learnt_clause);
- blevel = vec_size(&learnt_clause) > 1 ? levels[lit_var(((lit*)vec_begin(&learnt_clause))[1])] : s->root_level;
- solver_canceluntil(s,blevel);
- solver_record(s,&learnt_clause);
+ veci_resize(&learnt_clause,0);
+ sat_solver_analyze(s, confl, &learnt_clause);
+ blevel = veci_size(&learnt_clause) > 1 ? levels[lit_var(veci_begin(&learnt_clause)[1])] : s->root_level;
+ blevel = s->root_level > blevel ? s->root_level : blevel;
+ sat_solver_canceluntil(s,blevel);
+ sat_solver_record(s,&learnt_clause);
act_var_decay(s);
act_clause_decay(s);
@@ -830,18 +874,28 @@ static lbool solver_search(solver* s, int nof_conflicts, int nof_learnts)
if (nof_conflicts >= 0 && conflictC >= nof_conflicts){
// Reached bound on number of conflicts:
- s->progress_estimate = solver_progress(s);
- solver_canceluntil(s,s->root_level);
- vec_delete(&learnt_clause);
+ s->progress_estimate = sat_solver_progress(s);
+ sat_solver_canceluntil(s,s->root_level);
+ veci_delete(&learnt_clause);
return l_Undef; }
- if (solver_dlevel(s) == 0)
+ if ( (s->nConfLimit && s->stats.conflicts > s->nConfLimit) ||
+ (s->nInsLimit && s->stats.inspects > s->nInsLimit) )
+ {
+ // Reached bound on number of conflicts:
+ s->progress_estimate = sat_solver_progress(s);
+ sat_solver_canceluntil(s,s->root_level);
+ veci_delete(&learnt_clause);
+ return l_Undef;
+ }
+
+ if (sat_solver_dlevel(s) == 0 && !s->fSkipSimplify)
// Simplify the set of problem clauses:
- solver_simplify(s);
+ sat_solver_simplify(s);
- if (nof_learnts >= 0 && vec_size(&s->learnts) - s->qtail >= nof_learnts)
+ if (nof_learnts >= 0 && vecp_size(&s->learnts) - s->qtail >= nof_learnts)
// Reduce the set of learnt clauses:
- solver_reducedb(s);
+ sat_solver_reducedb(s);
// New variable decision:
s->stats.decisions++;
@@ -851,13 +905,24 @@ static lbool solver_search(solver* s, int nof_conflicts, int nof_learnts)
// Model found:
lbool* values = s->assigns;
int i;
- for (i = 0; i < s->size; i++) vec_push(&s->model,(void*)((int)values[i]));
- solver_canceluntil(s,s->root_level);
- vec_delete(&learnt_clause);
+ veci_resize(&s->model, 0);
+ for (i = 0; i < s->size; i++)
+ veci_push(&s->model,(int)values[i]);
+ sat_solver_canceluntil(s,s->root_level);
+ veci_delete(&learnt_clause);
+
+ /*
+ veci apa; veci_new(&apa);
+ for (i = 0; i < s->size; i++)
+ veci_push(&apa,(int)(s->model.ptr[i] == l_True ? toLit(i) : lit_neg(toLit(i))));
+ printf("model: "); printlits((lit*)apa.ptr, (lit*)apa.ptr + veci_size(&apa)); printf("\n");
+ veci_delete(&apa);
+ */
+
return l_True;
}
- assume(s,neg(toLit(next)));
+ assume(s,lit_neg(toLit(next)));
}
}
@@ -867,22 +932,25 @@ static lbool solver_search(solver* s, int nof_conflicts, int nof_learnts)
//=================================================================================================
// External solver functions:
-solver* solver_new(void)
+sat_solver* sat_solver_new(void)
{
- solver* s = (solver*)malloc(sizeof(solver));
+ sat_solver* s = (sat_solver*)malloc(sizeof(sat_solver));
+ memset( s, 0, sizeof(sat_solver) );
// initialize vectors
- vec_new(&s->clauses);
- vec_new(&s->learnts);
- vec_new(&s->order);
- vec_new(&s->trail_lim);
- vec_new(&s->tagged);
- vec_new(&s->stack);
- vec_new(&s->model);
+ vecp_new(&s->clauses);
+ vecp_new(&s->learnts);
+ veci_new(&s->order);
+ veci_new(&s->trail_lim);
+ veci_new(&s->tagged);
+ veci_new(&s->stack);
+ veci_new(&s->model);
+ veci_new(&s->act_vars);
// initialize arrays
s->wlists = 0;
s->activity = 0;
+ s->factors = 0;
s->assigns = 0;
s->orderpos = 0;
s->reasons = 0;
@@ -921,38 +989,49 @@ solver* solver_new(void)
s->stats.max_literals = 0;
s->stats.tot_literals = 0;
+#ifdef SAT_USE_SYSTEM_MEMORY_MANAGEMENT
+ s->pMem = NULL;
+#else
+ s->pMem = Sat_MmStepStart( 10 );
+#endif
return s;
}
-void solver_delete(solver* s)
+void sat_solver_delete(sat_solver* s)
{
- int i;
- for (i = 0; i < vec_size(&s->clauses); i++)
- free(vec_begin(&s->clauses)[i]);
- for (i = 0; i < vec_size(&s->learnts); i++)
- free(vec_begin(&s->learnts)[i]);
+#ifdef SAT_USE_SYSTEM_MEMORY_MANAGEMENT
+ int i;
+ for (i = 0; i < vecp_size(&s->clauses); i++)
+ free(vecp_begin(&s->clauses)[i]);
+ for (i = 0; i < vecp_size(&s->learnts); i++)
+ free(vecp_begin(&s->learnts)[i]);
+#else
+ Sat_MmStepStop( s->pMem, 0 );
+#endif
// delete vectors
- vec_delete(&s->clauses);
- vec_delete(&s->learnts);
- vec_delete(&s->order);
- vec_delete(&s->trail_lim);
- vec_delete(&s->tagged);
- vec_delete(&s->stack);
- vec_delete(&s->model);
+ vecp_delete(&s->clauses);
+ vecp_delete(&s->learnts);
+ veci_delete(&s->order);
+ veci_delete(&s->trail_lim);
+ veci_delete(&s->tagged);
+ veci_delete(&s->stack);
+ veci_delete(&s->model);
+ veci_delete(&s->act_vars);
free(s->binary);
// delete arrays
if (s->wlists != 0){
int i;
for (i = 0; i < s->size*2; i++)
- vec_delete(&s->wlists[i]);
+ vecp_delete(&s->wlists[i]);
// if one is different from null, all are
- free(s->wlists);
+ free(s->wlists );
free(s->activity );
+ free(s->factors );
free(s->assigns );
free(s->orderpos );
free(s->reasons );
@@ -961,11 +1040,12 @@ void solver_delete(solver* s)
free(s->tags );
}
+ sat_solver_store_free(s);
free(s);
}
-bool solver_addclause(solver* s, lit* begin, lit* end)
+bool sat_solver_addclause(sat_solver* s, lit* begin, lit* end)
{
lit *i,*j;
int maxvar;
@@ -984,7 +1064,8 @@ bool solver_addclause(solver* s, lit* begin, lit* end)
*j = *(j-1);
*j = l;
}
- 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");
values = s->assigns;
@@ -994,7 +1075,7 @@ bool solver_addclause(solver* s, lit* begin, lit* end)
for (i = j = begin; i < end; i++){
//printf("lit: "L_LIT", value = %d\n", L_lit(*i), (lit_sign(*i) ? -values[lit_var(*i)] : values[lit_var(*i)]));
lbool sig = !lit_sign(*i); sig += sig - 1;
- if (*i == neg(last) || sig == values[lit_var(*i)])
+ if (*i == lit_neg(last) || sig == values[lit_var(*i)])
return true; // tautology
else if (*i != last && values[lit_var(*i)] == l_Undef)
last = *j++ = *i;
@@ -1004,11 +1085,22 @@ bool solver_addclause(solver* s, lit* begin, lit* end)
if (j == begin) // empty clause
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);
// create new clause
- vec_push(&s->clauses,clause_new(s,begin,j,0));
+ vecp_push(&s->clauses,clause_new(s,begin,j,0));
s->stats.clauses++;
@@ -1018,14 +1110,14 @@ bool solver_addclause(solver* s, lit* begin, lit* end)
}
-bool solver_simplify(solver* s)
+bool sat_solver_simplify(sat_solver* s)
{
clause** reasons;
int type;
- assert(solver_dlevel(s) == 0);
+ assert(sat_solver_dlevel(s) == 0);
- if (solver_propagate(s) != 0)
+ if (sat_solver_propagate(s) != 0)
return false;
if (s->qhead == s->simpdb_assigns || s->simpdb_props > 0)
@@ -1033,18 +1125,18 @@ bool solver_simplify(solver* s)
reasons = s->reasons;
for (type = 0; type < 2; type++){
- vec* cs = type ? &s->learnts : &s->clauses;
- clause** cls = (clause**)vec_begin(cs);
+ vecp* cs = type ? &s->learnts : &s->clauses;
+ clause** cls = (clause**)vecp_begin(cs);
int i, j;
- for (j = i = 0; i < vec_size(cs); i++){
+ for (j = i = 0; i < vecp_size(cs); i++){
if (reasons[lit_var(*clause_begin(cls[i]))] != cls[i] &&
clause_simplify(s,cls[i]) == l_True)
clause_remove(s,cls[i]);
else
cls[j++] = cls[i];
}
- vec_resize(cs,j);
+ vecp_resize(cs,j);
}
s->simpdb_assigns = s->qhead;
@@ -1055,20 +1147,46 @@ bool solver_simplify(solver* s)
}
-bool solver_solve(solver* s, lit* begin, lit* end)
+int sat_solver_solve(sat_solver* s, lit* begin, lit* end, sint64 nConfLimit, sint64 nInsLimit, sint64 nConfLimitGlobal, sint64 nInsLimitGlobal)
{
- double nof_conflicts = 100;
- double nof_learnts = solver_nclauses(s) / 3;
+ sint64 nof_conflicts = 100;
+ sint64 nof_learnts = sat_solver_nclauses(s) / 3;
lbool status = l_Undef;
lbool* values = s->assigns;
lit* i;
- for (i = begin; i < end; i++)
- if ((lit_sign(*i) ? -values[lit_var(*i)] : values[lit_var(*i)]) == l_False || (assume(s,*i), solver_propagate(s) != 0)){
- solver_canceluntil(s,0);
- return false; }
+ // set the external limits
+ s->nCalls++;
+ s->nRestarts = 0;
+ s->nConfLimit = 0;
+ s->nInsLimit = 0;
+ if ( nConfLimit )
+ s->nConfLimit = s->stats.conflicts + nConfLimit;
+ if ( nInsLimit )
+ s->nInsLimit = s->stats.inspects + nInsLimit;
+ if ( nConfLimitGlobal && (s->nConfLimit == 0 || s->nConfLimit > nConfLimitGlobal) )
+ s->nConfLimit = nConfLimitGlobal;
+ if ( nInsLimitGlobal && (s->nInsLimit == 0 || s->nInsLimit > nInsLimitGlobal) )
+ s->nInsLimit = nInsLimitGlobal;
+
+ //printf("solve: "); printlits(begin, end); printf("\n");
+ for (i = begin; i < end; i++){
+ switch (lit_sign(*i) ? -values[lit_var(*i)] : values[lit_var(*i)]){
+ case 1: /* l_True: */
+ break;
+ case 0: /* l_Undef */
+ assume(s, *i);
+ if (sat_solver_propagate(s) == NULL)
+ break;
+ // fallthrough
+ case -1: /* l_False */
+ sat_solver_canceluntil(s, 0);
+ return l_False;
+ }
+ }
+ s->nCalls2++;
- s->root_level = solver_dlevel(s);
+ s->root_level = sat_solver_dlevel(s);
if (s->verbosity >= 1){
printf("==================================[MINISAT]===================================\n");
@@ -1081,7 +1199,8 @@ bool solver_solve(solver* s, lit* begin, lit* end)
double Ratio = (s->stats.learnts == 0)? 0.0 :
s->stats.learnts_literals / (double)s->stats.learnts;
- if (s->verbosity >= 1){
+ if (s->verbosity >= 1)
+ {
printf("| %9.0f | %7.0f %8.0f | %7.0f %7.0f %8.0f %7.1f | %6.3f %% |\n",
(double)s->stats.conflicts,
(double)s->stats.clauses,
@@ -1093,27 +1212,99 @@ bool solver_solve(solver* s, lit* begin, lit* end)
s->progress_estimate*100);
fflush(stdout);
}
- status = solver_search(s,(int)nof_conflicts, (int)nof_learnts);
- nof_conflicts *= 1.5;
- nof_learnts *= 1.1;
+ status = sat_solver_search(s, nof_conflicts, nof_learnts);
+ nof_conflicts = nof_conflicts * 3 / 2; //*= 1.5;
+ nof_learnts = nof_learnts * 11 / 10; //*= 1.1;
+
+ // quit the loop if reached an external limit
+ if ( s->nConfLimit && s->stats.conflicts > s->nConfLimit )
+ {
+// printf( "Reached the limit on the number of conflicts (%d).\n", s->nConfLimit );
+ break;
+ }
+ if ( s->nInsLimit && s->stats.inspects > s->nInsLimit )
+ {
+// printf( "Reached the limit on the number of implications (%d).\n", s->nInsLimit );
+ break;
+ }
}
if (s->verbosity >= 1)
printf("==============================================================================\n");
- solver_canceluntil(s,0);
- return status != l_False;
+ sat_solver_canceluntil(s,0);
+
+ ////////////////////////////////////////////////
+ if ( status == l_False && s->pStore )
+ {
+ extern int Sto_ManAddClause( void * p, lit * pBeg, lit * pEnd );
+ int RetValue = Sto_ManAddClause( s->pStore, NULL, NULL );
+ assert( RetValue );
+ }
+ ////////////////////////////////////////////////
+ return status;
}
-int solver_nvars(solver* s)
+int sat_solver_nvars(sat_solver* s)
{
return s->size;
}
-int solver_nclauses(solver* s)
+int sat_solver_nclauses(sat_solver* s)
+{
+ return vecp_size(&s->clauses);
+}
+
+
+int sat_solver_nconflicts(sat_solver* s)
+{
+ return (int)s->stats.conflicts;
+}
+
+//=================================================================================================
+// 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 );
+ if ( s->pStore ) 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 )
{
- return vec_size(&s->clauses);
+ void * pTemp;
+ if ( s->pStore == NULL )
+ return NULL;
+ pTemp = s->pStore;
+ s->pStore = NULL;
+ return pTemp;
}
//=================================================================================================
@@ -1160,7 +1351,7 @@ static void sortrnd(void** array, int size, int(*comp)(const void *, const void
}
}
-void sort(void** array, int size, int(*comp)(const void *, const void *))
+void sat_solver_sort(void** array, int size, int(*comp)(const void *, const void *))
{
double seed = 91648253;
sortrnd(array,size,comp,&seed);
diff --git a/src/sat/bsat/satSolver.h b/src/sat/bsat/satSolver.h
new file mode 100644
index 00000000..c1bf32a7
--- /dev/null
+++ b/src/sat/bsat/satSolver.h
@@ -0,0 +1,210 @@
+/**************************************************************************************************
+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 satSolver_h
+#define satSolver_h
+
+#ifdef _WIN32
+#define inline __inline // compatible with MS VS 6.0
+#endif
+
+#include "satVec.h"
+#include "satMem.h"
+
+//=================================================================================================
+// Simple types:
+
+// does not work for c++
+//typedef int bool;
+#ifndef __cplusplus
+#ifndef bool
+#define bool int
+#endif
+#endif
+
+static const bool true = 1;
+static const bool false = 0;
+
+typedef int lit;
+typedef char lbool;
+
+#ifndef SINT64
+#define SINT64
+
+#ifdef _WIN32
+typedef signed __int64 sint64; // compatible with MS VS 6.0
+#else
+typedef long long sint64;
+#endif
+
+#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 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; }
+
+
+//=================================================================================================
+// Public interface:
+
+struct sat_solver_t;
+typedef struct sat_solver_t sat_solver;
+
+extern sat_solver* sat_solver_new(void);
+extern void sat_solver_delete(sat_solver* s);
+
+extern bool sat_solver_addclause(sat_solver* s, lit* begin, lit* end);
+extern bool sat_solver_simplify(sat_solver* s);
+extern int sat_solver_solve(sat_solver* s, lit* begin, lit* end, sint64 nConfLimit, sint64 nInsLimit, sint64 nConfLimitGlobal, sint64 nInsLimitGlobal);
+
+extern int sat_solver_nvars(sat_solver* s);
+extern int sat_solver_nclauses(sat_solver* s);
+extern int sat_solver_nconflicts(sat_solver* s);
+
+extern void sat_solver_setnvars(sat_solver* s,int n);
+
+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;
+
+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 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:
+
+struct clause_t;
+typedef struct clause_t clause;
+
+struct sat_solver_t
+{
+ int size; // nof variables
+ int cap; // size of varmaps
+ int qhead; // Head index of queue.
+ int qtail; // Tail index of queue.
+
+ // clauses
+ vecp clauses; // List of problem constraints. (contains: clause*)
+ vecp 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.
+
+ vecp* wlists; //
+ double* activity; // A heuristic measurement of the activity of a variable.
+ 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
+
+ stats stats;
+
+ sint64 nConfLimit; // external limit on the number of conflicts
+ sint64 nInsLimit; // external limit on the number of implications
+
+ veci act_vars; // variables whose activity has changed
+ double* factors; // the activity factors
+ int nRestarts; // the number of local restarts
+ int nCalls; // the number of local restarts
+ int nCalls2; // the number of local restarts
+
+ Sat_MmStep_t * pMem;
+
+ int fSkipSimplify; // set to one to skip simplification of the clause database
+
+ // clause store
+ void * pStore;
+
+ // trace recording
+ FILE * pFile;
+ int nClauses;
+ int nRoots;
+};
+
+static int sat_solver_var_value( sat_solver* s, int v )
+{
+ assert( s->model.ptr != NULL && v < s->size );
+ return (int)(s->model.ptr[v] == l_True);
+}
+static int sat_solver_var_literal( sat_solver* s, int v )
+{
+ assert( s->model.ptr != NULL && v < s->size );
+ return toLitCond( v, s->model.ptr[v] != l_True );
+}
+static void sat_solver_act_var_clear(sat_solver* s)
+{
+ int i;
+ for (i = 0; i < s->size; i++)
+ s->activity[i] = 0.0;
+ s->var_inc = 1.0;
+}
+
+#endif
diff --git a/src/sat/bsat/satStore.c b/src/sat/bsat/satStore.c
new file mode 100644
index 00000000..f968162e
--- /dev/null
+++ b/src/sat/bsat/satStore.c
@@ -0,0 +1,437 @@
+/**CFile****************************************************************
+
+ FileName [satStore.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [SAT solver.]
+
+ Synopsis [Records the trace of SAT solving in the CNF form.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: satStore.c,v 1.4 2005/09/16 22:55:03 casem Exp $]
+
+***********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <time.h>
+#include "satStore.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Fetches memory.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Sto_ManMemoryFetch( Sto_Man_t * p, int nBytes )
+{
+ char * pMem;
+ if ( p->pChunkLast == NULL || nBytes > p->nChunkSize - p->nChunkUsed )
+ {
+ pMem = (char *)malloc( p->nChunkSize );
+ *(char **)pMem = p->pChunkLast;
+ p->pChunkLast = pMem;
+ p->nChunkUsed = sizeof(char *);
+ }
+ pMem = p->pChunkLast + p->nChunkUsed;
+ p->nChunkUsed += nBytes;
+ return pMem;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Frees memory manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sto_ManMemoryStop( Sto_Man_t * p )
+{
+ char * pMem, * pNext;
+ if ( p->pChunkLast == NULL )
+ return;
+ for ( pMem = p->pChunkLast; (pNext = *(char **)pMem); pMem = pNext )
+ free( pMem );
+ free( pMem );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Reports memory usage in bytes.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Sto_ManMemoryReport( Sto_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 [Allocate proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Sto_Man_t * Sto_ManAlloc()
+{
+ Sto_Man_t * p;
+ // allocate the manager
+ p = (Sto_Man_t *)malloc( sizeof(Sto_Man_t) );
+ memset( p, 0, sizeof(Sto_Man_t) );
+ // memory management
+ p->nChunkSize = (1<<16); // use 64K chunks
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Deallocate proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sto_ManFree( Sto_Man_t * p )
+{
+ Sto_ManMemoryStop( p );
+ free( p );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Adds one clause to the manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Sto_ManAddClause( Sto_Man_t * p, lit * pBeg, lit * pEnd )
+{
+ Sto_Cls_t * pClause;
+ lit Lit, * i, * j;
+ int nSize;
+
+ // process the literals
+ if ( pBeg < pEnd )
+ {
+ // insertion sort
+ for ( i = pBeg + 1; i < pEnd; i++ )
+ {
+ Lit = *i;
+ for ( j = i; j > pBeg && *(j-1) > Lit; j-- )
+ *j = *(j-1);
+ *j = Lit;
+ }
+ // make sure there is no duplicated variables
+ for ( i = pBeg + 1; i < pEnd; i++ )
+ if ( lit_var(*(i-1)) == lit_var(*i) )
+ {
+ printf( "The clause contains two literals of the same variable: %d and %d.\n", *(i-1), *i );
+ return 0;
+ }
+ // check the largest var size
+ p->nVars = STO_MAX( p->nVars, lit_var(*(pEnd-1)) + 1 );
+ }
+
+ // get memory for the clause
+ nSize = sizeof(Sto_Cls_t) + sizeof(lit) * (pEnd - pBeg);
+ pClause = (Sto_Cls_t *)Sto_ManMemoryFetch( p, nSize );
+ memset( pClause, 0, sizeof(Sto_Cls_t) );
+
+ // assign the clause
+ pClause->Id = p->nClauses++;
+ pClause->nLits = pEnd - pBeg;
+ memcpy( pClause->pLits, pBeg, sizeof(lit) * (pEnd - pBeg) );
+
+ // add the clause to the list
+ if ( p->pHead == NULL )
+ p->pHead = pClause;
+ if ( p->pTail == NULL )
+ p->pTail = pClause;
+ else
+ {
+ p->pTail->pNext = pClause;
+ p->pTail = pClause;
+ }
+
+ // add the empty clause
+ if ( pClause->nLits == 0 )
+ {
+ if ( p->pEmpty )
+ {
+ printf( "More than one empty clause!\n" );
+ return 0;
+ }
+ p->pEmpty = pClause;
+ }
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Mark all clauses added so far as root clauses.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sto_ManMarkRoots( Sto_Man_t * p )
+{
+ Sto_Cls_t * pClause;
+ p->nRoots = 0;
+ Sto_ManForEachClause( p, pClause )
+ {
+ pClause->fRoot = 1;
+ p->nRoots++;
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Mark all clauses added so far as clause of A.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sto_ManMarkClausesA( Sto_Man_t * p )
+{
+ Sto_Cls_t * pClause;
+ p->nClausesA = 0;
+ Sto_ManForEachClause( p, pClause )
+ {
+ pClause->fA = 1;
+ p->nClausesA++;
+ }
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Writes the stored clauses into a file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sto_ManDumpClauses( Sto_Man_t * p, char * pFileName )
+{
+ FILE * pFile;
+ Sto_Cls_t * pClause;
+ int i;
+ // start the file
+ pFile = fopen( pFileName, "w" );
+ if ( pFile == NULL )
+ {
+ printf( "Error: Cannot open output file (%s).\n", pFileName );
+ return;
+ }
+ // write the data
+ fprintf( pFile, "p %d %d %d %d\n", p->nVars, p->nClauses, p->nRoots, p->nClausesA );
+ Sto_ManForEachClause( p, pClause )
+ {
+ for ( i = 0; i < (int)pClause->nLits; i++ )
+ fprintf( pFile, " %d", lit_print(pClause->pLits[i]) );
+ fprintf( pFile, "\n" );
+ }
+ fprintf( pFile, " 0\n" );
+ fclose( pFile );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Reads one literal from file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Sto_ManLoadNumber( FILE * pFile, int * pNumber )
+{
+ int Char, Number = 0, Sign = 0;
+ // skip space-like chars
+ do {
+ Char = fgetc( pFile );
+ if ( Char == EOF )
+ return 0;
+ } while ( Char == ' ' || Char == '\t' || Char == '\r' || Char == '\n' );
+ // read the literal
+ while ( 1 )
+ {
+ // get the next character
+ Char = fgetc( pFile );
+ if ( Char == ' ' || Char == '\t' || Char == '\r' || Char == '\n' )
+ break;
+ // check that the char is a digit
+ if ( (Char < '0' || Char > '9') && Char != '-' )
+ {
+ printf( "Error: Wrong char (%c) in the input file.\n", Char );
+ return 0;
+ }
+ // check if this is a minus
+ if ( Char == '-' )
+ Sign = 1;
+ else
+ Number = 10 * Number + Char;
+ }
+ // return the number
+ *pNumber = Sign? -Number : Number;
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Reads CNF from file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Sto_Man_t * Sto_ManLoadClauses( char * pFileName )
+{
+ FILE * pFile;
+ Sto_Man_t * p;
+ Sto_Cls_t * pClause;
+ char pBuffer[1024];
+ int nLits, nLitsAlloc, Counter, Number;
+ lit * pLits;
+
+ // start the file
+ pFile = fopen( pFileName, "r" );
+ if ( pFile == NULL )
+ {
+ printf( "Error: Cannot open input file (%s).\n", pFileName );
+ return NULL;
+ }
+
+ // create the manager
+ p = Sto_ManAlloc();
+
+ // alloc the array of literals
+ nLitsAlloc = 1024;
+ pLits = (lit *)malloc( sizeof(lit) * nLitsAlloc );
+
+ // read file header
+ p->nVars = p->nClauses = p->nRoots = p->nClausesA = 0;
+ while ( fgets( pBuffer, 1024, pFile ) )
+ {
+ if ( pBuffer[0] == 'c' )
+ continue;
+ if ( pBuffer[0] == 'p' )
+ {
+ sscanf( pBuffer + 1, "%d %d %d %d", &p->nVars, &p->nClauses, &p->nRoots, &p->nClausesA );
+ break;
+ }
+ printf( "Warning: Skipping line: \"%s\"\n", pBuffer );
+ }
+
+ // read the clauses
+ nLits = 0;
+ while ( Sto_ManLoadNumber(pFile, &Number) )
+ {
+ if ( Number == 0 )
+ {
+ int RetValue;
+ RetValue = Sto_ManAddClause( p, pLits, pLits + nLits );
+ assert( RetValue );
+ nLits = 0;
+ continue;
+ }
+ if ( nLits == nLitsAlloc )
+ {
+ nLitsAlloc *= 2;
+ pLits = (lit *)realloc( pLits, sizeof(lit) * nLitsAlloc );
+ }
+ pLits[ nLits++ ] = lit_read(Number);
+ }
+ if ( nLits > 0 )
+ printf( "Error: The last clause was not saved.\n" );
+
+ // count clauses
+ Counter = 0;
+ Sto_ManForEachClause( p, pClause )
+ Counter++;
+
+ // check the number of clauses
+ if ( p->nClauses != Counter )
+ {
+ printf( "Error: The actual number of clauses (%d) is different than declared (%d).\n", Counter, p->nClauses );
+ Sto_ManFree( p );
+ return NULL;
+ }
+
+ free( pLits );
+ fclose( pFile );
+ return p;
+}
+
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/sat/bsat/satStore.h b/src/sat/bsat/satStore.h
new file mode 100644
index 00000000..b66abc8f
--- /dev/null
+++ b/src/sat/bsat/satStore.h
@@ -0,0 +1,146 @@
+/**CFile****************************************************************
+
+ FileName [satStore.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 __SAT_STORE_H__
+#define __SAT_STORE_H__
+
+#include "satSolver.h"
+
+/*
+ The trace of SAT solving contains the original clauses 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;
+// 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; }
+*/
+
+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
+};
+
+// 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 );
+extern void Sto_ManDumpClauses( Sto_Man_t * p, char * pFileName );
+extern Sto_Man_t * Sto_ManLoadClauses( char * pFileName );
+
+/*=== satInter.c ==========================================================*/
+typedef struct Int_Man_t_ Int_Man_t;
+extern Int_Man_t * Int_ManAlloc();
+extern void Int_ManFree( Int_Man_t * p );
+extern int Int_ManInterpolate( Int_Man_t * p, Sto_Man_t * pCnf, int fVerbose, unsigned ** ppResult );
+
+/*=== satInterA.c ==========================================================*/
+typedef struct Inta_Man_t_ Inta_Man_t;
+extern Inta_Man_t * Inta_ManAlloc();
+extern void Inta_ManFree( Inta_Man_t * p );
+extern void * Inta_ManInterpolate( Inta_Man_t * p, Sto_Man_t * pCnf, void * vVarsAB, int fVerbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
diff --git a/src/sat/bsat/satTrace.c b/src/sat/bsat/satTrace.c
new file mode 100644
index 00000000..111e8dfb
--- /dev/null
+++ b/src/sat/bsat/satTrace.c
@@ -0,0 +1,109 @@
+/**CFile****************************************************************
+
+ FileName [satTrace.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [SAT sat_solver.]
+
+ Synopsis [Records the trace of SAT solving in the CNF form.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: satTrace.c,v 1.4 2005/09/16 22:55:03 casem Exp $]
+
+***********************************************************************/
+
+#include <stdio.h>
+#include <assert.h>
+#include "satSolver.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>
+*/
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Start the trace recording.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_SolverTraceStart( sat_solver * pSat, char * pName )
+{
+ assert( pSat->pFile == NULL );
+ pSat->pFile = fopen( pName, "w" );
+ fprintf( pSat->pFile, " \n" );
+ pSat->nClauses = 0;
+ pSat->nRoots = 0;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Stops the trace recording.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_SolverTraceStop( sat_solver * pSat )
+{
+ if ( pSat->pFile == NULL )
+ return;
+ rewind( pSat->pFile );
+ fprintf( pSat->pFile, "p %d %d %d", sat_solver_nvars(pSat), pSat->nClauses, pSat->nRoots );
+ fclose( pSat->pFile );
+ pSat->pFile = NULL;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Writes one clause into the trace file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_SolverTraceWrite( sat_solver * pSat, int * pBeg, int * pEnd, int fRoot )
+{
+ if ( pSat->pFile == NULL )
+ return;
+ pSat->nClauses++;
+ pSat->nRoots += fRoot;
+ for ( ; pBeg < pEnd ; pBeg++ )
+ fprintf( pSat->pFile, " %d", lit_print(*pBeg) );
+ fprintf( pSat->pFile, " 0\n" );
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/sat/bsat/satUtil.c b/src/sat/bsat/satUtil.c
new file mode 100644
index 00000000..3961cf7e
--- /dev/null
+++ b/src/sat/bsat/satUtil.c
@@ -0,0 +1,234 @@
+/**CFile****************************************************************
+
+ FileName [satUtil.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: satUtil.c,v 1.4 2005/09/16 22:55:03 casem Exp $]
+
+***********************************************************************/
+
+#include <stdio.h>
+#include <assert.h>
+#include "satSolver.h"
+#include "vec.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 void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, bool fIncrement );
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Write the clauses in the solver into a file in DIMACS format.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_SolverWriteDimacs( sat_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( "Sat_SolverWriteDimacs(): Cannot open the ouput file.\n" );
+ return;
+ }
+// fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
+ 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++ )
+ Sat_SolverClauseWriteDimacs( pFile, pClauses[i], incrementVars );
+
+ // write the learned clauses
+ nClauses = p->learnts.size;
+ pClauses = p->learnts.ptr;
+ for ( i = 0; i < nClauses; i++ )
+ Sat_SolverClauseWriteDimacs( 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 Sat_SolverClauseWriteDimacs( 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 [Writes the given clause in a file in DIMACS format.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Sat_SolverPrintStats( FILE * pFile, sat_solver * p )
+{
+// printf( "calls : %8d (%d)\n", (int)p->nCalls, (int)p->nCalls2 );
+ printf( "starts : %8d\n", (int)p->stats.starts );
+ printf( "conflicts : %8d\n", (int)p->stats.conflicts );
+ printf( "decisions : %8d\n", (int)p->stats.decisions );
+ printf( "propagations : %8d\n", (int)p->stats.propagations );
+ printf( "inspects : %8d\n", (int)p->stats.inspects );
+// printf( "inspects2 : %8d\n", (int)p->stats.inspects2 );
+}
+
+/**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 * pClause;
+ 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);
+ for ( c = 0; c < nClauses; c++ )
+ {
+ pClause = p->clauses.ptr[c];
+ nLits = clause_size(pClause);
+ pLits = clause_begin(pClause);
+ 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 ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/sat/asat/solver_vec.h b/src/sat/bsat/satVec.h
index fae313d0..d7fce5c0 100644
--- a/src/sat/asat/solver_vec.h
+++ b/src/sat/bsat/satVec.h
@@ -19,35 +19,65 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
**************************************************************************************************/
// Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko
-#ifndef vec_h
-#define vec_h
+#ifndef satVec_h
+#define satVec_h
#include <stdlib.h>
-struct vec_t {
+// 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 vecp_t {
int size;
int cap;
void** ptr;
};
-typedef struct vec_t vec;
+typedef struct vecp_t vecp;
-static inline void vec_new (vec* v) {
+static inline void vecp_new (vecp* 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)
+static inline void vecp_delete (vecp* v) { free(v->ptr); }
+static inline void** vecp_begin (vecp* v) { return v->ptr; }
+static inline int vecp_size (vecp* v) { return v->size; }
+static inline void vecp_resize (vecp* v, int k) { v->size = k; } // only safe to shrink !!
+static inline void vecp_push (vecp* v, void* e)
{
if (v->size == v->cap) {
- int newsize = v->cap * 2+1;
+ int newsize = v->cap * 2;//+1;
v->ptr = (void**)realloc(v->ptr,sizeof(void*)*newsize);
v->cap = newsize; }
v->ptr[v->size++] = e;
}
+
#endif
diff --git a/src/sat/csat/csat_apis.c b/src/sat/csat/csat_apis.c
index b030caef..5872f5bc 100644
--- a/src/sat/csat/csat_apis.c
+++ b/src/sat/csat/csat_apis.c
@@ -24,7 +24,11 @@
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
-struct CSAT_ManagerStruct_t
+#define ABC_DEFAULT_CONF_LIMIT 0 // limit on conflicts
+#define ABC_DEFAULT_IMP_LIMIT 0 // limit on implications
+
+
+struct ABC_ManagerStruct_t
{
// information about the problem
stmm_table * tName2Node; // the hash table mapping names to nodes
@@ -32,9 +36,10 @@ struct CSAT_ManagerStruct_t
Abc_Ntk_t * pNtk; // the starting ABC network
Abc_Ntk_t * pTarget; // the AIG representing the target
char * pDumpFileName; // the name of the file to dump the target network
+ Extra_MmFlex_t * pMmNames; // memory manager for signal names
// solving parameters
- int mode; // 0 = baseline; 1 = resource-aware fraiging
- Fraig_Params_t Params; // the set of parameters to call FRAIG package
+ int mode; // 0 = resource-aware integration; 1 = brute-force SAT
+ Prove_Params_t Params; // integrated CEC parameters
// information about the target
int nog; // the numbers of gates in the target
Vec_Ptr_t * vNodes; // the gates in the target
@@ -43,16 +48,18 @@ struct CSAT_ManagerStruct_t
CSAT_Target_ResultT * pResult; // the result of solving the target
};
-static CSAT_Target_ResultT * CSAT_TargetResAlloc( int nVars );
-static void CSAT_TargetResFree( CSAT_Target_ResultT * p );
-static char * CSAT_GetNodeName( CSAT_Manager mng, Abc_Obj_t * pNode );
+static CSAT_Target_ResultT * ABC_TargetResAlloc( int nVars );
+static char * ABC_GetNodeName( ABC_Manager mng, Abc_Obj_t * pNode );
+
+// procedures to start and stop the ABC framework
+extern void Abc_Start();
+extern void Abc_Stop();
// some external procedures
-extern Fraig_Man_t * Abc_NtkToFraig( Abc_Ntk_t * pNtk, Fraig_Params_t * pParams, int fAllNodes );
extern int Io_WriteBench( Abc_Ntk_t * pNtk, char * FileName );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -66,17 +73,24 @@ extern int Io_WriteBench( Abc_Ntk_t * pNtk, char * FileName );
SeeAlso []
***********************************************************************/
-CSAT_Manager CSAT_InitManager()
+ABC_Manager ABC_InitManager()
{
- CSAT_Manager_t * mng;
- mng = ALLOC( CSAT_Manager_t, 1 );
- memset( mng, 0, sizeof(CSAT_Manager_t) );
- mng->pNtk = Abc_NtkAlloc( ABC_TYPE_LOGIC, ABC_FUNC_SOP );
- mng->pNtk->pName = util_strsav("csat_network");
+ ABC_Manager_t * mng;
+ Abc_Start();
+ mng = ALLOC( ABC_Manager_t, 1 );
+ memset( mng, 0, sizeof(ABC_Manager_t) );
+ mng->pNtk = Abc_NtkAlloc( ABC_NTK_LOGIC, ABC_FUNC_SOP, 1 );
+ mng->pNtk->pName = Extra_UtilStrsav("csat_network");
mng->tName2Node = stmm_init_table(strcmp, stmm_strhash);
mng->tNode2Name = stmm_init_table(stmm_ptrcmp, stmm_ptrhash);
+ mng->pMmNames = Extra_MmFlexStart();
mng->vNodes = Vec_PtrAlloc( 100 );
mng->vValues = Vec_IntAlloc( 100 );
+ mng->mode = 0; // set "resource-aware integration" as the default mode
+ // set default parameters for CEC
+ Prove_ParamsSetDefault( &mng->Params );
+ // set infinite resource limit for the final mitering
+// mng->Params.nMiteringLimitLast = ABC_INFINITY;
return mng;
}
@@ -91,40 +105,52 @@ CSAT_Manager CSAT_InitManager()
SeeAlso []
***********************************************************************/
-void CSAT_QuitManager( CSAT_Manager mng )
+void ABC_ReleaseManager( ABC_Manager mng )
{
+ CSAT_Target_ResultT * p_res = ABC_Get_Target_Result( mng,0 );
+ ABC_TargetResFree(p_res);
if ( mng->tNode2Name ) stmm_free_table( mng->tNode2Name );
if ( mng->tName2Node ) stmm_free_table( mng->tName2Node );
+ if ( mng->pMmNames ) Extra_MmFlexStop( mng->pMmNames );
if ( mng->pNtk ) Abc_NtkDelete( mng->pNtk );
if ( mng->pTarget ) Abc_NtkDelete( mng->pTarget );
if ( mng->vNodes ) Vec_PtrFree( mng->vNodes );
if ( mng->vValues ) Vec_IntFree( mng->vValues );
FREE( mng->pDumpFileName );
free( mng );
+ Abc_Stop();
}
/**Function*************************************************************
Synopsis [Sets solver options for learning.]
- Description [0 = baseline; 1 = resource-aware solving.]
+ Description []
SideEffects []
SeeAlso []
***********************************************************************/
-void CSAT_SetSolveOption( CSAT_Manager mng, enum CSAT_OptionT option )
+void ABC_SetSolveOption( ABC_Manager mng, enum CSAT_OptionT option )
{
- mng->mode = option;
- if ( option == 0 )
- printf( "CSAT_SetSolveOption: Setting baseline solving mode.\n" );
- else if ( option == 1 )
- printf( "CSAT_SetSolveOption: Setting resource-aware solving mode.\n" );
- else
- printf( "CSAT_SetSolveOption: Unknown option.\n" );
}
+/**Function*************************************************************
+
+ Synopsis [Sets solving mode by brute-force SAT.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void ABC_UseOnlyCoreSatSolver( ABC_Manager mng )
+{
+ mng->mode = 1; // switch to "brute-force SAT" as the solving option
+}
/**Function*************************************************************
@@ -141,18 +167,24 @@ void CSAT_SetSolveOption( CSAT_Manager mng, enum CSAT_OptionT option )
SeeAlso []
***********************************************************************/
-int CSAT_AddGate( CSAT_Manager mng, enum GateType type, char * name, int nofi, char ** fanins, int dc_attr )
+int ABC_AddGate( ABC_Manager mng, enum GateType type, char * name, int nofi, char ** fanins, int dc_attr )
{
Abc_Obj_t * pObj, * pFanin;
- char * pSop;
+ char * pSop, * pNewName;
int i;
+ // save the name in the local memory manager
+ pNewName = Extra_MmFlexEntryFetch( mng->pMmNames, strlen(name) + 1 );
+ strcpy( pNewName, name );
+ name = pNewName;
+
+ // consider different cases, create the node, and map the node into the name
switch( type )
{
case CSAT_BPI:
case CSAT_BPPI:
if ( nofi != 0 )
- { printf( "CSAT_AddGate: The PI/PPI gate \"%s\" has fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The PI/PPI gate \"%s\" has fanins.\n", name ); return 0; }
// create the PI
pObj = Abc_NtkCreatePi( mng->pNtk );
stmm_insert( mng->tNode2Name, (char *)pObj, name );
@@ -172,7 +204,7 @@ int CSAT_AddGate( CSAT_Manager mng, enum GateType type, char * name, int nofi, c
for ( i = 0; i < nofi; i++ )
{
if ( !stmm_lookup( mng->tName2Node, fanins[i], (char **)&pFanin ) )
- { printf( "CSAT_AddGate: The fanin gate \"%s\" is not in the network.\n", fanins[i] ); return 0; }
+ { printf( "ABC_AddGate: The fanin gate \"%s\" is not in the network.\n", fanins[i] ); return 0; }
Abc_ObjAddFanin( pObj, pFanin );
}
// create the node function
@@ -180,51 +212,51 @@ int CSAT_AddGate( CSAT_Manager mng, enum GateType type, char * name, int nofi, c
{
case CSAT_CONST:
if ( nofi != 0 )
- { printf( "CSAT_AddGate: The constant gate \"%s\" has fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The constant gate \"%s\" has fanins.\n", name ); return 0; }
pSop = Abc_SopCreateConst1( mng->pNtk->pManFunc );
break;
case CSAT_BAND:
if ( nofi < 1 )
- { printf( "CSAT_AddGate: The AND gate \"%s\" no fanins.\n", name ); return 0; }
- pSop = Abc_SopCreateAnd( mng->pNtk->pManFunc, nofi );
+ { printf( "ABC_AddGate: The AND gate \"%s\" no fanins.\n", name ); return 0; }
+ pSop = Abc_SopCreateAnd( mng->pNtk->pManFunc, nofi, NULL );
break;
case CSAT_BNAND:
if ( nofi < 1 )
- { printf( "CSAT_AddGate: The NAND gate \"%s\" no fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The NAND gate \"%s\" no fanins.\n", name ); return 0; }
pSop = Abc_SopCreateNand( mng->pNtk->pManFunc, nofi );
break;
case CSAT_BOR:
if ( nofi < 1 )
- { printf( "CSAT_AddGate: The OR gate \"%s\" no fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The OR gate \"%s\" no fanins.\n", name ); return 0; }
pSop = Abc_SopCreateOr( mng->pNtk->pManFunc, nofi, NULL );
break;
case CSAT_BNOR:
if ( nofi < 1 )
- { printf( "CSAT_AddGate: The NOR gate \"%s\" no fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The NOR gate \"%s\" no fanins.\n", name ); return 0; }
pSop = Abc_SopCreateNor( mng->pNtk->pManFunc, nofi );
break;
case CSAT_BXOR:
if ( nofi < 1 )
- { printf( "CSAT_AddGate: The XOR gate \"%s\" no fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The XOR gate \"%s\" no fanins.\n", name ); return 0; }
if ( nofi > 2 )
- { printf( "CSAT_AddGate: The XOR gate \"%s\" has more than two fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The XOR gate \"%s\" has more than two fanins.\n", name ); return 0; }
pSop = Abc_SopCreateXor( mng->pNtk->pManFunc, nofi );
break;
case CSAT_BXNOR:
if ( nofi < 1 )
- { printf( "CSAT_AddGate: The XNOR gate \"%s\" no fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The XNOR gate \"%s\" no fanins.\n", name ); return 0; }
if ( nofi > 2 )
- { printf( "CSAT_AddGate: The XNOR gate \"%s\" has more than two fanins.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The XNOR gate \"%s\" has more than two fanins.\n", name ); return 0; }
pSop = Abc_SopCreateNxor( mng->pNtk->pManFunc, nofi );
break;
case CSAT_BINV:
if ( nofi != 1 )
- { printf( "CSAT_AddGate: The inverter gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The inverter gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
pSop = Abc_SopCreateInv( mng->pNtk->pManFunc );
break;
case CSAT_BBUF:
if ( nofi != 1 )
- { printf( "CSAT_AddGate: The buffer gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The buffer gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
pSop = Abc_SopCreateBuf( mng->pNtk->pManFunc );
break;
default :
@@ -235,66 +267,85 @@ int CSAT_AddGate( CSAT_Manager mng, enum GateType type, char * name, int nofi, c
case CSAT_BPPO:
case CSAT_BPO:
if ( nofi != 1 )
- { printf( "CSAT_AddGate: The PO/PPO gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The PO/PPO gate \"%s\" does not have exactly one fanin.\n", name ); return 0; }
// create the PO
pObj = Abc_NtkCreatePo( mng->pNtk );
stmm_insert( mng->tNode2Name, (char *)pObj, name );
// connect to the PO fanin
if ( !stmm_lookup( mng->tName2Node, fanins[0], (char **)&pFanin ) )
- { printf( "CSAT_AddGate: The fanin gate \"%s\" is not in the network.\n", fanins[0] ); return 0; }
+ { printf( "ABC_AddGate: The fanin gate \"%s\" is not in the network.\n", fanins[0] ); return 0; }
Abc_ObjAddFanin( pObj, pFanin );
break;
default:
- printf( "CSAT_AddGate: Unknown gate type.\n" );
+ printf( "ABC_AddGate: Unknown gate type.\n" );
break;
}
+
+ // map the name into the node
if ( stmm_insert( mng->tName2Node, name, (char *)pObj ) )
- { printf( "CSAT_AddGate: The same gate \"%s\" is added twice.\n", name ); return 0; }
+ { printf( "ABC_AddGate: The same gate \"%s\" is added twice.\n", name ); return 0; }
return 1;
}
/**Function*************************************************************
- Synopsis [Checks integraty of the manager.]
+ Synopsis [This procedure also finalizes construction of the ABC network.]
- Description [Checks if there are gates that are not used by any primary output.
- If no such gates exist, return 1 else return 0.]
+ Description []
SideEffects []
SeeAlso []
***********************************************************************/
-int CSAT_Check_Integrity( CSAT_Manager mng )
+void ABC_Network_Finalize( ABC_Manager mng )
{
Abc_Ntk_t * pNtk = mng->pNtk;
Abc_Obj_t * pObj;
int i;
-
- // this procedure also finalizes construction of the ABC network
- Abc_NtkFixNonDrivenNets( pNtk );
Abc_NtkForEachPi( pNtk, pObj, i )
- Abc_NtkLogicStoreName( pObj, CSAT_GetNodeName(mng, pObj) );
+ Abc_ObjAssignName( pObj, ABC_GetNodeName(mng, pObj), NULL );
Abc_NtkForEachPo( pNtk, pObj, i )
- Abc_NtkLogicStoreName( pObj, CSAT_GetNodeName(mng, pObj) );
+ Abc_ObjAssignName( pObj, ABC_GetNodeName(mng, pObj), NULL );
assert( Abc_NtkLatchNum(pNtk) == 0 );
+}
- // make sure everything is okay with the network structure
- if ( !Abc_NtkCheckRead( pNtk ) )
- {
- printf( "CSAT_Check_Integrity: The internal network check has failed.\n" );
- return 0;
- }
+/**Function*************************************************************
+
+ Synopsis [Checks integraty of the manager.]
+
+ Description [Checks if there are gates that are not used by any primary output.
+ If no such gates exist, return 1 else return 0.]
+
+ SideEffects []
- // check that there is no dangling nodes
+ SeeAlso []
+
+***********************************************************************/
+int ABC_Check_Integrity( ABC_Manager mng )
+{
+ Abc_Ntk_t * pNtk = mng->pNtk;
+ Abc_Obj_t * pObj;
+ int i;
+
+ // check that there are no dangling nodes
Abc_NtkForEachNode( pNtk, pObj, i )
{
+ if ( i == 0 )
+ continue;
if ( Abc_ObjFanoutNum(pObj) == 0 )
{
- printf( "CSAT_Check_Integrity: The network has dangling nodes.\n" );
+// printf( "ABC_Check_Integrity: The network has dangling nodes.\n" );
return 0;
}
}
+
+ // make sure everything is okay with the network structure
+ if ( !Abc_NtkDoCheck( pNtk ) )
+ {
+ printf( "ABC_Check_Integrity: The internal network check has failed.\n" );
+ return 0;
+ }
return 1;
}
@@ -309,9 +360,9 @@ int CSAT_Check_Integrity( CSAT_Manager mng )
SeeAlso []
***********************************************************************/
-void CSAT_SetTimeLimit( CSAT_Manager mng, int runtime )
+void ABC_SetTimeLimit( ABC_Manager mng, int runtime )
{
- printf( "CSAT_SetTimeLimit: The resource limit is not implemented (warning).\n" );
+// printf( "ABC_SetTimeLimit: The resource limit is not implemented (warning).\n" );
}
/**Function*************************************************************
@@ -325,9 +376,9 @@ void CSAT_SetTimeLimit( CSAT_Manager mng, int runtime )
SeeAlso []
***********************************************************************/
-void CSAT_SetLearnLimit( CSAT_Manager mng, int num )
+void ABC_SetLearnLimit( ABC_Manager mng, int num )
{
- printf( "CSAT_SetLearnLimit: The resource limit is not implemented (warning).\n" );
+// printf( "ABC_SetLearnLimit: The resource limit is not implemented (warning).\n" );
}
/**Function*************************************************************
@@ -341,9 +392,9 @@ void CSAT_SetLearnLimit( CSAT_Manager mng, int num )
SeeAlso []
***********************************************************************/
-void CSAT_SetSolveBacktrackLimit( CSAT_Manager mng, int num )
+void ABC_SetLearnBacktrackLimit( ABC_Manager mng, int num )
{
- printf( "CSAT_SetSolveBacktrackLimit: The resource limit is not implemented (warning).\n" );
+// printf( "ABC_SetLearnBacktrackLimit: The resource limit is not implemented (warning).\n" );
}
/**Function*************************************************************
@@ -357,9 +408,88 @@ void CSAT_SetSolveBacktrackLimit( CSAT_Manager mng, int num )
SeeAlso []
***********************************************************************/
-void CSAT_SetLearnBacktrackLimit( CSAT_Manager mng, int num )
+void ABC_SetSolveBacktrackLimit( ABC_Manager mng, int num )
{
- printf( "CSAT_SetLearnBacktrackLimit: The resource limit is not implemented (warning).\n" );
+ mng->Params.nMiteringLimitLast = num;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void ABC_SetSolveImplicationLimit( ABC_Manager mng, int num )
+{
+// printf( "ABC_SetSolveImplicationLimit: The resource limit is not implemented (warning).\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void ABC_SetTotalBacktrackLimit( ABC_Manager mng, uint64 num )
+{
+ mng->Params.nTotalBacktrackLimit = num;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void ABC_SetTotalInspectLimit( ABC_Manager mng, uint64 num )
+{
+ mng->Params.nTotalInspectLimit = num;
+}
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+uint64 ABC_GetTotalBacktracksMade( ABC_Manager mng )
+{
+ return mng->Params.nTotalBacktracksMade;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+uint64 ABC_GetTotalInspectsMade( ABC_Manager mng )
+{
+ return mng->Params.nTotalInspectsMade;
}
/**Function*************************************************************
@@ -373,10 +503,10 @@ void CSAT_SetLearnBacktrackLimit( CSAT_Manager mng, int num )
SeeAlso []
***********************************************************************/
-void CSAT_EnableDump( CSAT_Manager mng, char * dump_file )
+void ABC_EnableDump( ABC_Manager mng, char * dump_file )
{
FREE( mng->pDumpFileName );
- mng->pDumpFileName = util_strsav( dump_file );
+ mng->pDumpFileName = Extra_UtilStrsav( dump_file );
}
/**Function*************************************************************
@@ -394,12 +524,12 @@ void CSAT_EnableDump( CSAT_Manager mng, char * dump_file )
SeeAlso []
***********************************************************************/
-int CSAT_AddTarget( CSAT_Manager mng, int nog, char ** names, int * values )
+int ABC_AddTarget( ABC_Manager mng, int nog, char ** names, int * values )
{
Abc_Obj_t * pObj;
int i;
if ( nog < 1 )
- { printf( "CSAT_AddTarget: The target has no gates.\n" ); return 0; }
+ { printf( "ABC_AddTarget: The target has no gates.\n" ); return 0; }
// clear storage for the target
mng->nog = 0;
Vec_PtrClear( mng->vNodes );
@@ -408,10 +538,10 @@ int CSAT_AddTarget( CSAT_Manager mng, int nog, char ** names, int * values )
for ( i = 0; i < nog; i++ )
{
if ( !stmm_lookup( mng->tName2Node, names[i], (char **)&pObj ) )
- { printf( "CSAT_AddTarget: The target gate \"%s\" is not in the network.\n", names[i] ); return 0; }
+ { printf( "ABC_AddTarget: The target gate \"%s\" is not in the network.\n", names[i] ); return 0; }
Vec_PtrPush( mng->vNodes, pObj );
if ( values[i] < 0 || values[i] > 1 )
- { printf( "CSAT_AddTarget: The value of gate \"%s\" is not 0 or 1.\n", names[i] ); return 0; }
+ { printf( "ABC_AddTarget: The value of gate \"%s\" is not 0 or 1.\n", names[i] ); return 0; }
Vec_IntPush( mng->vValues, values[i] );
}
mng->nog = nog;
@@ -423,50 +553,26 @@ int CSAT_AddTarget( CSAT_Manager mng, int nog, char ** names, int * values )
Synopsis [Initialize the solver internal data structure.]
Description [Prepares the solver to work on one specific target
- set by calling CSAT_AddTarget before.]
+ set by calling ABC_AddTarget before.]
SideEffects []
SeeAlso []
***********************************************************************/
-void CSAT_SolveInit( CSAT_Manager mng )
+void ABC_SolveInit( ABC_Manager mng )
{
- Fraig_Params_t * pParams = &mng->Params;
- int nWords1, nWords2, nWordsMin;
-
// check if the target is available
assert( mng->nog == Vec_PtrSize(mng->vNodes) );
if ( mng->nog == 0 )
- { printf( "CSAT_SolveInit: Target is not specified by CSAT_AddTarget().\n" ); return; }
+ { printf( "ABC_SolveInit: Target is not specified by ABC_AddTarget().\n" ); return; }
// free the previous target network if present
if ( mng->pTarget ) Abc_NtkDelete( mng->pTarget );
// set the new target network
- mng->pTarget = Abc_NtkCreateCone( mng->pNtk, mng->vNodes, mng->vValues );
-
- // to determine the number of simulation patterns
- // use the following strategy
- // at least 64 words (32 words random and 32 words dynamic)
- // no more than 256M for one circuit (128M + 128M)
- nWords1 = 32;
- nWords2 = (1<<27) / (Abc_NtkNodeNum(mng->pTarget) + Abc_NtkCiNum(mng->pTarget));
- nWordsMin = ABC_MIN( nWords1, nWords2 );
-
- // set parameters for fraiging
- memset( pParams, 0, sizeof(Fraig_Params_t) );
- pParams->nPatsRand = nWordsMin * 32; // the number of words of random simulation info
- pParams->nPatsDyna = nWordsMin * 32; // the number of words of dynamic simulation info
- pParams->nBTLimit = 99; // the max number of backtracks to perform at a node
- pParams->fFuncRed = mng->mode; // performs only one level hashing
- pParams->fFeedBack = 1; // enables solver feedback
- pParams->fDist1Pats = 1; // enables distance-1 patterns
- pParams->fDoSparse = 0; // performs equiv tests for sparse functions
- pParams->fChoicing = 0; // enables recording structural choices
- pParams->fTryProve = 1; // tries to solve the final miter
- pParams->fVerbose = 0; // the verbosiness flag
- pParams->fVerboseP = 0; // the verbosiness flag for proof reporting
+// mng->pTarget = Abc_NtkCreateTarget( mng->pNtk, mng->vNodes, mng->vValues );
+ mng->pTarget = Abc_NtkStrash( mng->pNtk, 0, 1, 0 );
}
/**Function*************************************************************
@@ -480,13 +586,13 @@ void CSAT_SolveInit( CSAT_Manager mng )
SeeAlso []
***********************************************************************/
-void CSAT_AnalyzeTargets( CSAT_Manager mng )
+void ABC_AnalyzeTargets( ABC_Manager mng )
{
}
/**Function*************************************************************
- Synopsis [Solves the targets added by CSAT_AddTarget().]
+ Synopsis [Solves the targets added by ABC_AddTarget().]
Description []
@@ -495,23 +601,24 @@ void CSAT_AnalyzeTargets( CSAT_Manager mng )
SeeAlso []
***********************************************************************/
-enum CSAT_StatusT CSAT_Solve( CSAT_Manager mng )
+enum CSAT_StatusT ABC_Solve( ABC_Manager mng )
{
- Fraig_Man_t * pMan;
- int * pModel;
+ Prove_Params_t * pParams = &mng->Params;
int RetValue, i;
// check if the target network is available
if ( mng->pTarget == NULL )
- { printf( "CSAT_Solve: Target network is not derived by CSAT_SolveInit().\n" ); return UNDETERMINED; }
+ { printf( "ABC_Solve: Target network is not derived by ABC_SolveInit().\n" ); return UNDETERMINED; }
- // transform the target into a fraig
- pMan = Abc_NtkToFraig( mng->pTarget, &mng->Params, 0 );
- Fraig_ManProveMiter( pMan );
+ // try to prove the miter using a number of techniques
+ if ( mng->mode )
+ RetValue = Abc_NtkMiterSat( mng->pTarget, (sint64)pParams->nMiteringLimitLast, (sint64)0, 0, NULL, NULL );
+ else
+// RetValue = Abc_NtkMiterProve( &mng->pTarget, pParams ); // old CEC engine
+ RetValue = Abc_NtkIvyProve( &mng->pTarget, pParams ); // new CEC engine
// analyze the result
- mng->pResult = CSAT_TargetResAlloc( Abc_NtkCiNum(mng->pTarget) );
- RetValue = Fraig_ManCheckMiter( pMan );
+ mng->pResult = ABC_TargetResAlloc( Abc_NtkCiNum(mng->pTarget) );
if ( RetValue == -1 )
mng->pResult->status = UNDETERMINED;
else if ( RetValue == 1 )
@@ -519,20 +626,16 @@ enum CSAT_StatusT CSAT_Solve( CSAT_Manager mng )
else if ( RetValue == 0 )
{
mng->pResult->status = SATISFIABLE;
- pModel = Fraig_ManReadModel( pMan );
- assert( pModel != NULL );
// create the array of PI names and values
for ( i = 0; i < mng->pResult->no_sig; i++ )
{
- mng->pResult->names[i] = CSAT_GetNodeName(mng, Abc_NtkCi(mng->pNtk, i)); // returns the same string that was given
- mng->pResult->values[i] = pModel[i];
+ mng->pResult->names[i] = Extra_UtilStrsav( ABC_GetNodeName(mng, Abc_NtkCi(mng->pNtk, i)) );
+ mng->pResult->values[i] = mng->pTarget->pModel[i];
}
+ FREE( mng->pTarget->pModel );
}
- else
- assert( 0 );
+ else assert( 0 );
- // delete the fraig manager
- Fraig_ManFree( pMan );
// delete the target
Abc_NtkDelete( mng->pTarget );
mng->pTarget = NULL;
@@ -544,38 +647,40 @@ enum CSAT_StatusT CSAT_Solve( CSAT_Manager mng )
Synopsis [Gets the solve status of a target.]
- Description [TargetID: the target id returned by CSAT_AddTarget().]
+ Description [TargetID: the target id returned by ABC_AddTarget().]
SideEffects []
SeeAlso []
***********************************************************************/
-CSAT_Target_ResultT * CSAT_Get_Target_Result( CSAT_Manager mng, int TargetID )
+CSAT_Target_ResultT * ABC_Get_Target_Result( ABC_Manager mng, int TargetID )
{
return mng->pResult;
}
/**Function*************************************************************
- Synopsis [Dumps the target AIG into the BENCH file.]
+ Synopsis [Dumps the original network into the BENCH file.]
- Description []
+ Description [This procedure should be modified to dump the target.]
SideEffects []
- SeeAlso []
+ SeeAlso []
***********************************************************************/
-void CSAT_Dump_Bench_File( CSAT_Manager mng )
+void ABC_Dump_Bench_File( ABC_Manager mng )
{
- Abc_Ntk_t * pNtkTemp;
+ Abc_Ntk_t * pNtkTemp, * pNtkAig;
char * pFileName;
-
+
// derive the netlist
- pNtkTemp = Abc_NtkLogicToNetlistBench( mng->pTarget );
+ pNtkAig = Abc_NtkStrash( mng->pNtk, 0, 0, 0 );
+ pNtkTemp = Abc_NtkToNetlistBench( pNtkAig );
+ Abc_NtkDelete( pNtkAig );
if ( pNtkTemp == NULL )
- { printf( "CSAT_Dump_Bench_File: Dumping BENCH has failed.\n" ); return; }
+ { printf( "ABC_Dump_Bench_File: Dumping BENCH has failed.\n" ); return; }
pFileName = mng->pDumpFileName? mng->pDumpFileName: "abc_test.bench";
Io_WriteBench( pNtkTemp, pFileName );
Abc_NtkDelete( pNtkTemp );
@@ -594,7 +699,7 @@ void CSAT_Dump_Bench_File( CSAT_Manager mng )
SeeAlso []
***********************************************************************/
-CSAT_Target_ResultT * CSAT_TargetResAlloc( int nVars )
+CSAT_Target_ResultT * ABC_TargetResAlloc( int nVars )
{
CSAT_Target_ResultT * p;
p = ALLOC( CSAT_Target_ResultT, 1 );
@@ -618,10 +723,18 @@ CSAT_Target_ResultT * CSAT_TargetResAlloc( int nVars )
SeeAlso []
***********************************************************************/
-void CSAT_TargetResFree( CSAT_Target_ResultT * p )
+void ABC_TargetResFree( CSAT_Target_ResultT * p )
{
if ( p == NULL )
return;
+ if( p->names )
+ {
+ int i = 0;
+ for ( i = 0; i < p->no_sig; i++ )
+ {
+ FREE(p->names[i]);
+ }
+ }
FREE( p->names );
FREE( p->values );
free( p );
@@ -638,7 +751,7 @@ void CSAT_TargetResFree( CSAT_Target_ResultT * p )
SeeAlso []
***********************************************************************/
-char * CSAT_GetNodeName( CSAT_Manager mng, Abc_Obj_t * pNode )
+char * ABC_GetNodeName( ABC_Manager mng, Abc_Obj_t * pNode )
{
char * pName = NULL;
if ( !stmm_lookup( mng->tNode2Name, (char *)pNode, (char **)&pName ) )
@@ -648,6 +761,7 @@ char * CSAT_GetNodeName( CSAT_Manager mng, Abc_Obj_t * pNode )
return pName;
}
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
diff --git a/src/sat/csat/csat_apis.h b/src/sat/csat/csat_apis.h
index 124ca266..b80eddbf 100644
--- a/src/sat/csat/csat_apis.h
+++ b/src/sat/csat/csat_apis.h
@@ -12,12 +12,16 @@
Date [Ver. 1.0. Started - August 28, 2005]
- Revision [$Id: csat_apis.h,v 1.00 2005/08/28 00:00:00 alanmi Exp $]
+ Revision [$Id: csat_apis.h,v 1.5 2005/12/30 10:54:40 rmukherj Exp $]
***********************************************************************/
-#ifndef __CSAT_APIS_H__
-#define __CSAT_APIS_H__
+#ifndef __ABC_APIS_H__
+#define __ABC_APIS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
@@ -32,36 +36,44 @@
////////////////////////////////////////////////////////////////////////
-typedef struct CSAT_ManagerStruct_t CSAT_Manager_t;
-typedef struct CSAT_ManagerStruct_t * CSAT_Manager;
+typedef struct ABC_ManagerStruct_t ABC_Manager_t;
+typedef struct ABC_ManagerStruct_t * ABC_Manager;
// GateType defines the gate type that can be added to circuit by
-// CSAT_AddGate();
-#ifndef _CSAT_GATE_TYPE_
-#define _CSAT_GATE_TYPE_
+// ABC_AddGate();
+#ifndef _ABC_GATE_TYPE_
+#define _ABC_GATE_TYPE_
enum GateType
{
CSAT_CONST = 0, // constant gate
- CSAT_BPI, // boolean PI
- CSAT_BPPI, // bit level PSEUDO PRIMARY INPUT
- CSAT_BAND, // bit level AND
- CSAT_BNAND, // bit level NAND
- CSAT_BOR, // bit level OR
- CSAT_BNOR, // bit level NOR
- CSAT_BXOR, // bit level XOR
- CSAT_BXNOR, // bit level XNOR
- CSAT_BINV, // bit level INVERTER
- CSAT_BBUF, // bit level BUFFER
- CSAT_BPPO, // bit level PSEUDO PRIMARY OUTPUT
- CSAT_BPO // boolean PO
+ CSAT_BPI, // boolean PI
+ CSAT_BPPI, // bit level PSEUDO PRIMARY INPUT
+ CSAT_BAND, // bit level AND
+ CSAT_BNAND, // bit level NAND
+ CSAT_BOR, // bit level OR
+ CSAT_BNOR, // bit level NOR
+ CSAT_BXOR, // bit level XOR
+ CSAT_BXNOR, // bit level XNOR
+ CSAT_BINV, // bit level INVERTER
+ CSAT_BBUF, // bit level BUFFER
+ CSAT_BMUX, // bit level MUX --not supported
+ CSAT_BDFF, // bit level D-type FF
+ CSAT_BSDFF, // bit level scan FF --not supported
+ CSAT_BTRIH, // bit level TRISTATE gate with active high control --not supported
+ CSAT_BTRIL, // bit level TRISTATE gate with active low control --not supported
+ CSAT_BBUS, // bit level BUS --not supported
+ CSAT_BPPO, // bit level PSEUDO PRIMARY OUTPUT
+ CSAT_BPO, // boolean PO
+ CSAT_BCNF, // boolean constraint
+ CSAT_BDC, // boolean don't care gate (2 input)
};
#endif
-//CSAT_StatusT defines the return value by CSAT_Solve();
-#ifndef _CSAT_STATUS_
-#define _CSAT_STATUS_
+//CSAT_StatusT defines the return value by ABC_Solve();
+#ifndef _ABC_STATUS_
+#define _ABC_STATUS_
enum CSAT_StatusT
{
UNDETERMINED = 0,
@@ -76,10 +88,22 @@ enum CSAT_StatusT
#endif
+// to identify who called the CSAT solver
+#ifndef _ABC_CALLER_
+#define _ABC_CALLER_
+enum CSAT_CallerT
+{
+ BLS = 0,
+ SATORI,
+ NONE
+};
+#endif
+
+
// CSAT_OptionT defines the solver option about learning
-// which is used by CSAT_SetSolveOption();
-#ifndef _CSAT_OPTION_
-#define _CSAT_OPTION_
+// which is used by ABC_SetSolveOption();
+#ifndef _ABC_OPTION_
+#define _ABC_OPTION_
enum CSAT_OptionT
{
BASE_LINE = 0,
@@ -89,8 +113,8 @@ enum CSAT_OptionT
#endif
-#ifndef _CSAT_Target_Result
-#define _CSAT_Target_Result
+#ifndef _ABC_Target_Result
+#define _ABC_Target_Result
typedef struct _CSAT_Target_ResultT CSAT_Target_ResultT;
struct _CSAT_Target_ResultT
{
@@ -114,14 +138,21 @@ struct _CSAT_Target_ResultT
#endif
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
// create a new manager
-extern CSAT_Manager CSAT_InitManager(void);
+extern ABC_Manager ABC_InitManager(void);
+
+// release a manager
+extern void ABC_ReleaseManager(ABC_Manager mng);
// set solver options for learning
-extern void CSAT_SetSolveOption(CSAT_Manager mng, enum CSAT_OptionT option);
+extern void ABC_SetSolveOption(ABC_Manager mng, enum CSAT_OptionT option);
+
+// enable checking by brute-force SAT solver (MiniSat-1.14)
+extern void ABC_UseOnlyCoreSatSolver(ABC_Manager mng);
+
// add a gate to the circuit
// the meaning of the parameters are:
@@ -129,46 +160,63 @@ extern void CSAT_SetSolveOption(CSAT_Manager mng, enum CSAT_Opt
// name: the name of the gate to be added, name should be unique in a circuit.
// nofi: number of fanins of the gate to be added;
// fanins: the name array of fanins of the gate to be added
-extern int CSAT_AddGate(CSAT_Manager mng,
- enum GateType type,
- char* name,
- int nofi,
- char** fanins,
- int dc_attr);
+extern int ABC_AddGate(ABC_Manager mng,
+ enum GateType type,
+ char* name,
+ int nofi,
+ char** fanins,
+ int dc_attr);
// check if there are gates that are not used by any primary ouput.
// if no such gates exist, return 1 else return 0;
-extern int CSAT_Check_Integrity(CSAT_Manager mng);
+extern int ABC_Check_Integrity(ABC_Manager mng);
+
+// THIS PROCEDURE SHOULD BE CALLED AFTER THE NETWORK IS CONSTRUCTED!!!
+extern void ABC_Network_Finalize( ABC_Manager mng );
// set time limit for solving a target.
// runtime: time limit (in second).
-extern void CSAT_SetTimeLimit(CSAT_Manager mng, int runtime);
-extern void CSAT_SetLearnLimit(CSAT_Manager mng, int num);
-extern void CSAT_SetSolveBacktrackLimit(CSAT_Manager mng, int num);
-extern void CSAT_SetLearnBacktrackLimit(CSAT_Manager mng, int num);
-extern void CSAT_EnableDump(CSAT_Manager mng, char* dump_file);
+extern void ABC_SetTimeLimit(ABC_Manager mng, int runtime);
+extern void ABC_SetLearnLimit(ABC_Manager mng, int num);
+extern void ABC_SetSolveBacktrackLimit(ABC_Manager mng, int num);
+extern void ABC_SetLearnBacktrackLimit(ABC_Manager mng, int num);
+extern void ABC_EnableDump(ABC_Manager mng, char* dump_file);
+
+extern void ABC_SetTotalBacktrackLimit( ABC_Manager mng, uint64 num );
+extern void ABC_SetTotalInspectLimit( ABC_Manager mng, uint64 num );
+extern uint64 ABC_GetTotalBacktracksMade( ABC_Manager mng );
+extern uint64 ABC_GetTotalInspectsMade( ABC_Manager mng );
// the meaning of the parameters are:
// nog: number of gates that are in the targets
// names: name array of gates
// values: value array of the corresponding gates given in "names" to be
// solved. the relation of them is AND.
-extern int CSAT_AddTarget(CSAT_Manager mng, int nog, char**names, int* values);
+extern int ABC_AddTarget(ABC_Manager mng, int nog, char**names, int* values);
// initialize the solver internal data structure.
-extern void CSAT_SolveInit(CSAT_Manager mng);
-extern void CSAT_AnalyzeTargets(CSAT_Manager mng);
+extern void ABC_SolveInit(ABC_Manager mng);
+extern void ABC_AnalyzeTargets(ABC_Manager mng);
-// solve the targets added by CSAT_AddTarget()
-extern enum CSAT_StatusT CSAT_Solve(CSAT_Manager mng);
+// solve the targets added by ABC_AddTarget()
+extern enum CSAT_StatusT ABC_Solve(ABC_Manager mng);
// get the solve status of a target
-// TargetID: the target id returned by CSAT_AddTarget().
-extern CSAT_Target_ResultT * CSAT_Get_Target_Result(CSAT_Manager mng, int TargetID);
-extern void CSAT_Dump_Bench_File(CSAT_Manager mng);
+// TargetID: the target id returned by ABC_AddTarget().
+extern CSAT_Target_ResultT * ABC_Get_Target_Result(ABC_Manager mng, int TargetID);
+extern void ABC_Dump_Bench_File(ABC_Manager mng);
+
+// ADDED PROCEDURES:
+extern void ABC_TargetResFree( CSAT_Target_ResultT * p );
+
+extern void CSAT_SetCaller(ABC_Manager mng, enum CSAT_CallerT caller);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-
-#endif
diff --git a/src/sat/fraig/fraig.h b/src/sat/fraig/fraig.h
index 901bbac9..1dad21e2 100644
--- a/src/sat/fraig/fraig.h
+++ b/src/sat/fraig/fraig.h
@@ -18,11 +18,26 @@
#ifndef __FRAIG_H__
#define __FRAIG_H__
-
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
+#ifndef SINT64
+#define SINT64
+
+#ifdef _WIN32
+typedef signed __int64 sint64; // compatible with MS VS 6.0
+#else
+typedef long long sint64;
+#endif
+
+#endif
+
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
@@ -37,12 +52,14 @@ typedef struct Fraig_NodeVecStruct_t_ Fraig_NodeVec_t;
typedef struct Fraig_HashTableStruct_t_ Fraig_HashTable_t;
typedef struct Fraig_ParamsStruct_t_ Fraig_Params_t;
typedef struct Fraig_PatternsStruct_t_ Fraig_Patterns_t;
+typedef struct Prove_ParamsStruct_t_ Prove_Params_t;
struct Fraig_ParamsStruct_t_
{
int nPatsRand; // the number of words of random simulation info
int nPatsDyna; // the number of words of dynamic simulation info
int nBTLimit; // the max number of backtracks to perform
+ int nSeconds; // the timeout for the final proof
int fFuncRed; // performs only one level hashing
int fFeedBack; // enables solver feedback
int fDist1Pats; // enables distance-1 patterns
@@ -52,6 +69,39 @@ struct Fraig_ParamsStruct_t_
int fVerbose; // the verbosiness flag
int fVerboseP; // the verbosiness flag (for proof reporting)
int fInternal; // is set to 1 for internal fraig calls
+ int nConfLimit; // the limit on the number of conflicts
+ sint64 nInspLimit; // the limit on the number of inspections
+};
+
+struct Prove_ParamsStruct_t_
+{
+ // general parameters
+ int fUseFraiging; // enables fraiging
+ int fUseRewriting; // enables rewriting
+ int fUseBdds; // enables BDD construction when other methods fail
+ int fVerbose; // prints verbose stats
+ // iterations
+ int nItersMax; // the number of iterations
+ // mitering
+ int nMiteringLimitStart; // starting mitering limit
+ float nMiteringLimitMulti; // multiplicative coefficient to increase the limit in each iteration
+ // rewriting
+ int nRewritingLimitStart; // the number of rewriting iterations
+ float nRewritingLimitMulti; // multiplicative coefficient to increase the limit in each iteration
+ // fraiging
+ int nFraigingLimitStart; // starting backtrack(conflict) limit
+ float nFraigingLimitMulti; // multiplicative coefficient to increase the limit in each iteration
+ // last-gasp BDD construction
+ int nBddSizeLimit; // the number of BDD nodes when construction is aborted
+ int fBddReorder; // enables dynamic BDD variable reordering
+ // last-gasp mitering
+ int nMiteringLimitLast; // final mitering limit
+ // global SAT solver limits
+ sint64 nTotalBacktrackLimit; // global limit on the number of backtracks
+ sint64 nTotalInspectLimit; // global limit on the number of clause inspects
+ // global resources applied
+ sint64 nTotalBacktracksMade; // the total number of backtracks made
+ sint64 nTotalInspectsMade; // the total number of inspects made
};
////////////////////////////////////////////////////////////////////////
@@ -59,14 +109,14 @@ struct Fraig_ParamsStruct_t_
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// MACRO DEFITIONS ///
+/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
// macros working with complemented attributes of the nodes
-#define Fraig_IsComplement(p) (((int)((long) (p) & 01)))
-#define Fraig_Regular(p) ((Fraig_Node_t *)((unsigned)(p) & ~01))
-#define Fraig_Not(p) ((Fraig_Node_t *)((long)(p) ^ 01))
-#define Fraig_NotCond(p,c) ((Fraig_Node_t *)((long)(p) ^ (c)))
+#define Fraig_IsComplement(p) (((int)((unsigned long) (p) & 01)))
+#define Fraig_Regular(p) ((Fraig_Node_t *)((unsigned long)(p) & ~01))
+#define Fraig_Not(p) ((Fraig_Node_t *)((unsigned long)(p) ^ 01))
+#define Fraig_NotCond(p,c) ((Fraig_Node_t *)((unsigned long)(p) ^ (c)))
// these are currently not used
#define Fraig_Ref(p)
@@ -74,7 +124,7 @@ struct Fraig_ParamsStruct_t_
#define Fraig_RecursiveDeref(p,c)
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/*=== fraigApi.c =============================================================*/
@@ -103,6 +153,9 @@ extern int * Fraig_ManReadModel( Fraig_Man_t * p );
extern int Fraig_ManReadPatternNumRandom( Fraig_Man_t * p );
extern int Fraig_ManReadPatternNumDynamic( Fraig_Man_t * p );
extern int Fraig_ManReadPatternNumDynamicFiltered( Fraig_Man_t * p );
+extern int Fraig_ManReadSatFails( Fraig_Man_t * p );
+extern int Fraig_ManReadConflicts( Fraig_Man_t * p );
+extern int Fraig_ManReadInspects( Fraig_Man_t * p );
extern void Fraig_ManSetFuncRed( Fraig_Man_t * p, int fFuncRed );
extern void Fraig_ManSetFeedBack( Fraig_Man_t * p, int fFeedBack );
@@ -147,10 +200,15 @@ extern Fraig_Node_t * Fraig_NodeMux( Fraig_Man_t * p, Fraig_Node_t * pNode,
extern void Fraig_NodeSetChoice( Fraig_Man_t * pMan, Fraig_Node_t * pNodeOld, Fraig_Node_t * pNodeNew );
/*=== fraigMan.c =============================================================*/
+extern void Prove_ParamsSetDefault( Prove_Params_t * pParams );
extern void Fraig_ParamsSetDefault( Fraig_Params_t * pParams );
+extern void Fraig_ParamsSetDefaultFull( Fraig_Params_t * pParams );
extern Fraig_Man_t * Fraig_ManCreate( Fraig_Params_t * pParams );
extern void Fraig_ManFree( Fraig_Man_t * pMan );
extern void Fraig_ManPrintStats( Fraig_Man_t * p );
+extern Fraig_NodeVec_t * Fraig_ManGetSimInfo( Fraig_Man_t * p );
+extern int Fraig_ManCheckClauseUsingSimInfo( Fraig_Man_t * p, Fraig_Node_t * pNode1, Fraig_Node_t * pNode2 );
+extern void Fraig_ManAddClause( Fraig_Man_t * p, Fraig_Node_t ** ppNodes, int nNodes );
/*=== fraigDfs.c =============================================================*/
extern Fraig_NodeVec_t * Fraig_Dfs( Fraig_Man_t * pMan, int fEquiv );
@@ -162,10 +220,11 @@ extern int Fraig_CheckTfi( Fraig_Man_t * pMan, Fraig_Node_t * pO
extern int Fraig_CountLevels( Fraig_Man_t * pMan );
/*=== fraigSat.c =============================================================*/
-extern int Fraig_NodesAreEqual( Fraig_Man_t * p, Fraig_Node_t * pNode1, Fraig_Node_t * pNode2, int nBTLimit );
-extern int Fraig_NodeIsEquivalent( Fraig_Man_t * p, Fraig_Node_t * pOld, Fraig_Node_t * pNew, int nBTLimit );
+extern int Fraig_NodesAreEqual( Fraig_Man_t * p, Fraig_Node_t * pNode1, Fraig_Node_t * pNode2, int nBTLimit, int nTimeLimit );
+extern int Fraig_NodeIsEquivalent( Fraig_Man_t * p, Fraig_Node_t * pOld, Fraig_Node_t * pNew, int nBTLimit, int nTimeLimit );
extern void Fraig_ManProveMiter( Fraig_Man_t * p );
extern int Fraig_ManCheckMiter( Fraig_Man_t * p );
+extern int Fraig_ManCheckClauseUsingSat( Fraig_Man_t * p, Fraig_Node_t * pNode1, Fraig_Node_t * pNode2, int nBTLimit );
/*=== fraigVec.c ===============================================================*/
extern Fraig_NodeVec_t * Fraig_NodeVecAlloc( int nCap );
@@ -200,4 +259,9 @@ extern Fraig_NodeVec_t * Fraig_CollectSupergate( Fraig_Node_t * pNode, int fSt
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
+
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/src/sat/fraig/fraigApi.c b/src/sat/fraig/fraigApi.c
index b92f6afd..79a7c224 100644
--- a/src/sat/fraig/fraigApi.c
+++ b/src/sat/fraig/fraigApi.c
@@ -23,7 +23,7 @@
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -64,6 +64,12 @@ int Fraig_ManReadPatternNumRandom( Fraig_Man_t * p ) {
int Fraig_ManReadPatternNumDynamic( Fraig_Man_t * p ) { return p->iWordStart * 32; }
// returns the number of dynamic patterns proved useful to distinquish some FRAIG nodes (this number is more than 0 after the first garbage collection of patterns)
int Fraig_ManReadPatternNumDynamicFiltered( Fraig_Man_t * p ) { return p->iPatsPerm; }
+// returns the number of times FRAIG package timed out
+int Fraig_ManReadSatFails( Fraig_Man_t * p ) { return p->nSatFailsReal; }
+// returns the number of conflicts in the SAT solver
+int Fraig_ManReadConflicts( Fraig_Man_t * p ) { return p->pSat? Msat_SolverReadBackTracks(p->pSat) : 0; }
+// returns the number of inspections in the SAT solver
+int Fraig_ManReadInspects( Fraig_Man_t * p ) { return p->pSat? Msat_SolverReadInspects(p->pSat) : 0; }
/**Function*************************************************************
diff --git a/src/sat/fraig/fraigCanon.c b/src/sat/fraig/fraigCanon.c
index 5a7d0563..89bc924f 100644
--- a/src/sat/fraig/fraigCanon.c
+++ b/src/sat/fraig/fraigCanon.c
@@ -24,7 +24,7 @@
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -49,7 +49,8 @@
Fraig_Node_t * Fraig_NodeAndCanon( Fraig_Man_t * pMan, Fraig_Node_t * p1, Fraig_Node_t * p2 )
{
Fraig_Node_t * pNodeNew, * pNodeOld, * pNodeRepr;
- int RetValue;
+ int fUseSatCheck;
+// int RetValue;
// check for trivial cases
if ( p1 == p2 )
@@ -68,7 +69,7 @@ Fraig_Node_t * Fraig_NodeAndCanon( Fraig_Man_t * pMan, Fraig_Node_t * p1, Fraig_
return p1;
return Fraig_Not(pMan->pConst1);
}
-
+/*
// check for less trivial cases
if ( Fraig_IsComplement(p1) )
{
@@ -125,7 +126,7 @@ Fraig_Node_t * Fraig_NodeAndCanon( Fraig_Man_t * pMan, Fraig_Node_t * p1, Fraig_
return Fraig_Not(pMan->pConst1);
}
}
-
+*/
// perform level-one structural hashing
if ( Fraig_HashTableLookupS( pMan, p1, p2, &pNodeNew ) ) // the node with these children is found
{
@@ -167,7 +168,8 @@ Fraig_Node_t * Fraig_NodeAndCanon( Fraig_Man_t * pMan, Fraig_Node_t * p1, Fraig_
// there is another node which looks the same according to simulation
// use SAT to resolve the ambiguity
- if ( Fraig_NodeIsEquivalent( pMan, pNodeOld, pNodeNew, pMan->nBTLimit ) )
+ fUseSatCheck = (pMan->nInspLimit == 0 || Fraig_ManReadInspects(pMan) < pMan->nInspLimit);
+ if ( fUseSatCheck && Fraig_NodeIsEquivalent( pMan, pNodeOld, pNodeNew, pMan->nBTLimit, 1000000 ) )
{
// set the node to be equivalent with this node
// to prevent loops, only set if the old node is not in the TFI of the new node
diff --git a/src/sat/fraig/fraigChoice.c b/src/sat/fraig/fraigChoice.c
new file mode 100644
index 00000000..896e5d2d
--- /dev/null
+++ b/src/sat/fraig/fraigChoice.c
@@ -0,0 +1,241 @@
+/**CFile****************************************************************
+
+ FileName [fraigTrans.c]
+
+ PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
+
+ Synopsis [Adds the additive and distributive choices to the AIG.]
+
+ Author [MVSIS Group]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - February 1, 2003.]
+
+ Revision [$Id: fraigTrans.c,v 1.1 2005/02/28 05:34:34 alanmi Exp $]
+
+***********************************************************************/
+
+#include "fraigInt.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Adds choice nodes based on associativity.]
+
+ Description [Make nLimit big AND gates and add all decompositions
+ to the Fraig.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Fraig_ManAddChoices( Fraig_Man_t * pMan, int fVerbose, int nLimit )
+{
+// ProgressBar * pProgress;
+ char Buffer[100];
+ int clkTotal = clock();
+ int i, nNodesBefore, nNodesAfter, nInputs, nMaxNodes;
+ int /*nMaxLevel,*/ nDistributive;
+ Fraig_Node_t *pNode, *pRepr;
+ Fraig_Node_t *pX, *pA, *pB, *pC, /* *pD,*/ *pN, /* *pQ, *pR,*/ *pT;
+ int fShortCut = 0;
+
+ nDistributive = 0;
+
+// Fraig_ManSetApprox( pMan, 1 );
+
+ // NO functional reduction
+ if (fShortCut) Fraig_ManSetFuncRed( pMan, 0 );
+
+ // First we mark critical functions i.e. compute those
+ // nodes which lie on the critical path. Note that this
+ // doesn't update the required times on any choice nodes
+ // which are not the representatives
+/*
+ nMaxLevel = Fraig_GetMaxLevel( pMan );
+ for ( i = 0; i < pMan->nOutputs; i++ )
+ {
+ Fraig_SetNodeRequired( pMan, pMan->pOutputs[i], nMaxLevel );
+ }
+*/
+ nNodesBefore = Fraig_ManReadNodeNum( pMan );
+ nInputs = Fraig_ManReadInputNum( pMan );
+ nMaxNodes = nInputs + nLimit * ( nNodesBefore - nInputs );
+
+ printf ("Limit = %d, Before = %d\n", nMaxNodes, nNodesBefore );
+
+ if (0)
+ {
+ char buffer[128];
+ sprintf (buffer, "test" );
+// Fraig_MappingShow( pMan, buffer );
+ }
+
+// pProgress = Extra_ProgressBarStart( stdout, nMaxNodes );
+Fraig_ManCheckConsistency( pMan );
+
+ for ( i = nInputs+1; (i < Fraig_ManReadNodeNum( pMan ))
+ && (nMaxNodes > Fraig_ManReadNodeNum( pMan )); ++i )
+ {
+// if ( i == nNodesBefore )
+// break;
+
+ pNode = Fraig_ManReadIthNode( pMan, i );
+ assert ( pNode );
+
+ pRepr = pNode->pRepr ? pNode->pRepr : pNode;
+ //printf ("Slack: %d\n", Fraig_NodeReadSlack( pRepr ));
+
+ // All the new associative choices we add will have huge slack
+ // since we do not redo timing, and timing doesnt handle choices
+ // well anyway. However every newly added node is a choice of an
+ // existing critical node, so they are considered critical.
+// if ( (Fraig_NodeReadSlack( pRepr ) > 3) && (i < nNodesBefore) )
+// continue;
+
+// if ( pNode->pRepr )
+// continue;
+
+ // Try ((ab)c), x = ab -> (a(bc)) and (b(ac))
+ pX = Fraig_NodeReadOne(pNode);
+ pC = Fraig_NodeReadTwo(pNode);
+ if (Fraig_NodeIsAnd(pX) && !Fraig_IsComplement(pX))
+ {
+ pA = Fraig_NodeReadOne(Fraig_Regular(pX));
+ pB = Fraig_NodeReadTwo(Fraig_Regular(pX));
+
+// pA = Fraig_NodeGetRepr( pA );
+// pB = Fraig_NodeGetRepr( pB );
+// pC = Fraig_NodeGetRepr( pC );
+
+ if (fShortCut)
+ {
+ pT = Fraig_NodeAnd(pMan, pB, pC);
+ if ( !pT->pRepr )
+ {
+ pN = Fraig_NodeAnd(pMan, pA, pT);
+// Fraig_NodeAddChoice( pMan, pNode, pN );
+ }
+ }
+ else
+ pN = Fraig_NodeAnd(pMan, pA, Fraig_NodeAnd(pMan, pB, pC));
+ // assert ( Fraig_NodesEqual(pN, pNode) );
+
+
+ if (fShortCut)
+ {
+ pT = Fraig_NodeAnd(pMan, pA, pC);
+ if ( !pT->pRepr )
+ {
+ pN = Fraig_NodeAnd(pMan, pB, pT);
+// Fraig_NodeAddChoice( pMan, pNode, pN );
+ }
+ }
+ else
+ pN = Fraig_NodeAnd(pMan, pB, Fraig_NodeAnd(pMan, pA, pC));
+ // assert ( Fraig_NodesEqual(pN, pNode) );
+ }
+
+
+ // Try (a(bc)), x = bc -> ((ab)c) and ((ac)b)
+ pA = Fraig_NodeReadOne(pNode);
+ pX = Fraig_NodeReadTwo(pNode);
+ if (Fraig_NodeIsAnd(pX) && !Fraig_IsComplement(pX))
+ {
+ pB = Fraig_NodeReadOne(Fraig_Regular(pX));
+ pC = Fraig_NodeReadTwo(Fraig_Regular(pX));
+
+// pA = Fraig_NodeGetRepr( pA );
+// pB = Fraig_NodeGetRepr( pB );
+// pC = Fraig_NodeGetRepr( pC );
+
+ if (fShortCut)
+ {
+ pT = Fraig_NodeAnd(pMan, pA, pB);
+ if ( !pT->pRepr )
+ {
+ pN = Fraig_NodeAnd(pMan, pC, pT);
+// Fraig_NodeAddChoice( pMan, pNode, pN );
+ }
+ }
+ else
+ pN = Fraig_NodeAnd(pMan, Fraig_NodeAnd(pMan, pA, pB), pC);
+ // assert ( Fraig_NodesEqual(pN, pNode) );
+
+ if (fShortCut)
+ {
+ pT = Fraig_NodeAnd(pMan, pA, pC);
+ if ( !pT->pRepr )
+ {
+ pN = Fraig_NodeAnd(pMan, pB, pT);
+// Fraig_NodeAddChoice( pMan, pNode, pN );
+ }
+ }
+ else
+ pN = Fraig_NodeAnd(pMan, Fraig_NodeAnd(pMan, pA, pC), pB);
+ // assert ( Fraig_NodesEqual(pN, pNode) );
+ }
+
+
+/*
+ // Try distributive transform
+ pQ = Fraig_NodeReadOne(pNode);
+ pR = Fraig_NodeReadTwo(pNode);
+ if ( (Fraig_IsComplement(pQ) && Fraig_NodeIsAnd(pQ))
+ && (Fraig_IsComplement(pR) && Fraig_NodeIsAnd(pR)) )
+ {
+ pA = Fraig_NodeReadOne(Fraig_Regular(pQ));
+ pB = Fraig_NodeReadTwo(Fraig_Regular(pQ));
+ pC = Fraig_NodeReadOne(Fraig_Regular(pR));
+ pD = Fraig_NodeReadTwo(Fraig_Regular(pR));
+
+ // Now detect the !(xy + xz) pattern, store
+ // x in pA, y in pB and z in pC and set pD = 0 to indicate
+ // pattern was found
+ assert (pD != 0);
+ if (pA == pC) { pC = pD; pD = 0; }
+ if (pA == pD) { pD = 0; }
+ if (pB == pC) { pB = pA; pA = pC; pC = pD; pD = 0; }
+ if (pB == pD) { pB = pA; pA = pD; pD = 0; }
+ if (pD == 0)
+ {
+ nDistributive++;
+ pN = Fraig_Not(Fraig_NodeAnd(pMan, pA,
+ Fraig_NodeOr(pMan, pB, pC)));
+ if (fShortCut) Fraig_NodeAddChoice( pMan, pNode, pN );
+ // assert ( Fraig_NodesEqual(pN, pNode) );
+ }
+ }
+*/
+ if ( i % 1000 == 0 )
+ {
+ sprintf( Buffer, "Adding choice %6d...", i - nNodesBefore );
+// Extra_ProgressBarUpdate( pProgress, i, Buffer );
+ }
+ }
+
+// Extra_ProgressBarStop( pProgress );
+
+Fraig_ManCheckConsistency( pMan );
+
+ nNodesAfter = Fraig_ManReadNodeNum( pMan );
+ printf ( "Nodes before = %6d. Nodes with associative choices = %6d. Increase = %4.2f %%.\n",
+ nNodesBefore, nNodesAfter, ((float)(nNodesAfter - nNodesBefore)) * 100.0/(nNodesBefore - nInputs) );
+ printf ( "Distributive = %d\n", nDistributive );
+
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/sat/fraig/fraigFanout.c b/src/sat/fraig/fraigFanout.c
index b44bacd7..789bffca 100644
--- a/src/sat/fraig/fraigFanout.c
+++ b/src/sat/fraig/fraigFanout.c
@@ -25,7 +25,7 @@
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/fraig/fraigFeed.c b/src/sat/fraig/fraigFeed.c
index 73640387..8a3cc6c7 100644
--- a/src/sat/fraig/fraigFeed.c
+++ b/src/sat/fraig/fraigFeed.c
@@ -37,7 +37,7 @@ static void Fraig_ReallocateSimulationInfo( Fraig_Man_t * p );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -463,6 +463,10 @@ Fraig_NodeVec_t * Fraig_FeedBackCoveringStart( Fraig_Man_t * p )
Fraig_NodeVecPush( p->vCones, pEntD );
if ( p->vCones->nSize == 1 )
continue;
+ //////////////////////////////// bug fix by alanmi, September 14, 2006
+ if ( p->vCones->nSize > 20 )
+ continue;
+ ////////////////////////////////
for ( k = 0; k < p->vCones->nSize; k++ )
for ( m = k+1; m < p->vCones->nSize; m++ )
diff --git a/src/sat/fraig/fraigInt.h b/src/sat/fraig/fraigInt.h
index 131b750c..9c6e0d47 100644
--- a/src/sat/fraig/fraigInt.h
+++ b/src/sat/fraig/fraigInt.h
@@ -47,7 +47,7 @@
*/
////////////////////////////////////////////////////////////////////////
-/// MACRO DEFITIONS ///
+/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
// enable this macro to support the fanouts
@@ -66,7 +66,7 @@
// the bit masks
#define FRAIG_MASK(n) ((~((unsigned)0)) >> (32-(n)))
#define FRAIG_FULL (~((unsigned)0))
-#define FRAIG_NUM_WORDS(n) ((n)/32 + (((n)%32) > 0))
+#define FRAIG_NUM_WORDS(n) (((n)>>5) + (((n)&31) > 0))
// maximum/minimum operators
#define FRAIG_MIN(a,b) (((a) < (b))? (a) : (b))
@@ -143,6 +143,7 @@ struct Fraig_ManStruct_t_
int nWordsRand; // the number of words of random simulation info
int nWordsDyna; // the number of words of dynamic simulation info
int nBTLimit; // the max number of backtracks to perform
+ int nSeconds; // the runtime limit for the miter proof
int fFuncRed; // performs only one level hashing
int fFeedBack; // enables solver feedback
int fDist1Pats; // enables solver feedback
@@ -151,6 +152,7 @@ struct Fraig_ManStruct_t_
int fTryProve; // tries to solve the final miter
int fVerbose; // the verbosiness flag
int fVerboseP; // the verbosiness flag
+ sint64 nInspLimit; // the inspection limit
int nTravIds; // the traversal counter
int nTravIds2; // the traversal counter
@@ -188,7 +190,8 @@ struct Fraig_ManStruct_t_
int nSatCalls; // the number of times equivalence checking was called
int nSatProof; // the number of times a proof was found
int nSatCounter; // the number of times a counter example was found
- int nSatFails; // the number of times the SAT solver failed to complete
+ int nSatFails; // the number of times the SAT solver failed to complete due to resource limit or prediction
+ int nSatFailsReal; // the number of times the SAT solver failed to complete due to resource limit
int nSatCallsImp; // the number of times equivalence checking was called
int nSatProofImp; // the number of times a proof was found
@@ -242,8 +245,9 @@ struct Fraig_NodeStruct_t_
unsigned fMark3 : 1; // the mark used for traversals
unsigned fFeedUse : 1; // the presence of the variable in the feedback
unsigned fFeedVal : 1; // the value of the variable in the feedback
+ unsigned fFailTfo : 1; // the node is in the TFO of the failed SAT run
unsigned nFanouts : 2; // the indicator of fanouts (none, one, or many)
- unsigned nOnes : 21; // the number of 1's in the random sim info
+ unsigned nOnes : 20; // the number of 1's in the random sim info
// the children of the node
Fraig_Node_t * p1; // the first child
@@ -279,9 +283,9 @@ struct Fraig_NodeStruct_t_
// the vector of nodes
struct Fraig_NodeVecStruct_t_
{
- Fraig_Node_t ** pArray; // the array of nodes
- int nSize; // the number of entries in the array
int nCap; // the number of allocated entries
+ int nSize; // the number of entries in the array
+ Fraig_Node_t ** pArray; // the array of nodes
};
// the hash table
@@ -364,7 +368,7 @@ struct Fraig_HashTableStruct_t_
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/*=== fraigCanon.c =============================================================*/
@@ -380,6 +384,8 @@ extern void Fraig_FeedBackTest( Fraig_Man_t * p );
extern int Fraig_FeedBackCompress( Fraig_Man_t * p );
extern int * Fraig_ManAllocCounterExample( Fraig_Man_t * p );
extern int * Fraig_ManSaveCounterExample( Fraig_Man_t * p, Fraig_Node_t * pNode );
+/*=== fraigMan.c =============================================================*/
+extern void Fraig_ManCreateSolver( Fraig_Man_t * p );
/*=== fraigMem.c =============================================================*/
extern Fraig_MemFixed_t * Fraig_MemFixedStart( int nEntrySize );
extern void Fraig_MemFixedStop( Fraig_MemFixed_t * p, int fVerbose );
@@ -438,8 +444,8 @@ extern int Fraig_NodeIsTravIdPrevious( Fraig_Man_t * pMan, Fraig
/*=== fraigVec.c ===============================================================*/
extern void Fraig_NodeVecSortByRefCount( Fraig_NodeVec_t * p );
+#endif
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-
-#endif
diff --git a/src/sat/fraig/fraigMan.c b/src/sat/fraig/fraigMan.c
index e5979c93..7fd937d5 100644
--- a/src/sat/fraig/fraigMan.c
+++ b/src/sat/fraig/fraigMan.c
@@ -26,7 +26,7 @@ int timeSelect;
int timeAssign;
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -40,12 +40,89 @@ int timeAssign;
SeeAlso []
***********************************************************************/
+void Prove_ParamsSetDefault( Prove_Params_t * pParams )
+{
+ // clean the parameter structure
+ memset( pParams, 0, sizeof(Prove_Params_t) );
+ // general parameters
+ pParams->fUseFraiging = 1; // enables fraiging
+ pParams->fUseRewriting = 1; // enables rewriting
+ pParams->fUseBdds = 0; // enables BDD construction when other methods fail
+ pParams->fVerbose = 0; // prints verbose stats
+ // iterations
+ pParams->nItersMax = 6; // the number of iterations
+ // mitering
+ pParams->nMiteringLimitStart = 300; // starting mitering limit
+ pParams->nMiteringLimitMulti = 2.0; // multiplicative coefficient to increase the limit in each iteration
+ // rewriting (currently not used)
+ pParams->nRewritingLimitStart = 3; // the number of rewriting iterations
+ pParams->nRewritingLimitMulti = 1.0; // multiplicative coefficient to increase the limit in each iteration
+ // fraiging
+ pParams->nFraigingLimitStart = 2; // starting backtrack(conflict) limit
+ pParams->nFraigingLimitMulti = 8.0; // multiplicative coefficient to increase the limit in each iteration
+ // last-gasp BDD construction
+ pParams->nBddSizeLimit = 1000000; // the number of BDD nodes when construction is aborted
+ pParams->fBddReorder = 1; // enables dynamic BDD variable reordering
+ // last-gasp mitering
+// pParams->nMiteringLimitLast = 1000000; // final mitering limit
+ pParams->nMiteringLimitLast = 0; // final mitering limit
+ // global SAT solver limits
+ pParams->nTotalBacktrackLimit = 0; // global limit on the number of backtracks
+ pParams->nTotalInspectLimit = 0; // global limit on the number of clause inspects
+// pParams->nTotalInspectLimit = 100000000; // global limit on the number of clause inspects
+}
+
+/**Function*************************************************************
+
+ Synopsis [Prints out the current values of CEC engine parameters.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Prove_ParamsPrint( Prove_Params_t * pParams )
+{
+ printf( "CEC enging parameters:\n" );
+ printf( "Fraiging enabled: %s\n", pParams->fUseFraiging? "yes":"no" );
+ printf( "Rewriting enabled: %s\n", pParams->fUseRewriting? "yes":"no" );
+ printf( "BDD construction enabled: %s\n", pParams->fUseBdds? "yes":"no" );
+ printf( "Verbose output enabled: %s\n", pParams->fVerbose? "yes":"no" );
+ printf( "Solver iterations: %d\n", pParams->nItersMax );
+ printf( "Starting mitering limit: %d\n", pParams->nMiteringLimitStart );
+ printf( "Multiplicative coeficient for mitering: %.2f\n", pParams->nMiteringLimitMulti );
+ printf( "Starting number of rewriting iterations: %d\n", pParams->nRewritingLimitStart );
+ printf( "Multiplicative coeficient for rewriting: %.2f\n", pParams->nRewritingLimitMulti );
+ printf( "Starting number of conflicts in fraiging: %d\n", pParams->nFraigingLimitMulti );
+ printf( "Multiplicative coeficient for fraiging: %.2f\n", pParams->nRewritingLimitMulti );
+ printf( "BDD size limit for bailing out: %.2f\n", pParams->nBddSizeLimit );
+ printf( "BDD reordering enabled: %s\n", pParams->fBddReorder? "yes":"no" );
+ printf( "Last-gasp mitering limit: %d\n", pParams->nMiteringLimitLast );
+ printf( "Total conflict limit: %d\n", pParams->nTotalBacktrackLimit );
+ printf( "Total inspection limit: %d\n", pParams->nTotalInspectLimit );
+ printf( "Parameter dump complete.\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Sets the default parameters of the package.]
+
+ Description [This set of parameters is tuned for equivalence checking.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
void Fraig_ParamsSetDefault( Fraig_Params_t * pParams )
{
memset( pParams, 0, sizeof(Fraig_Params_t) );
pParams->nPatsRand = FRAIG_PATTERNS_RANDOM; // the number of words of random simulation info
pParams->nPatsDyna = FRAIG_PATTERNS_DYNAMIC; // the number of words of dynamic simulation info
pParams->nBTLimit = 99; // the max number of backtracks to perform
+ pParams->nSeconds = 20; // the max number of seconds to solve the miter
pParams->fFuncRed = 1; // performs only one level hashing
pParams->fFeedBack = 1; // enables solver feedback
pParams->fDist1Pats = 1; // enables distance-1 patterns
@@ -55,6 +132,39 @@ void Fraig_ParamsSetDefault( Fraig_Params_t * pParams )
pParams->fVerbose = 0; // the verbosiness flag
pParams->fVerboseP = 0; // the verbose flag for reporting the proof
pParams->fInternal = 0; // the flag indicates the internal run
+ pParams->nConfLimit = 0; // the limit on the number of conflicts
+ pParams->nInspLimit = 0; // the limit on the number of inspections
+}
+
+/**Function*************************************************************
+
+ Synopsis [Sets the default parameters of the package.]
+
+ Description [This set of parameters is tuned for complete FRAIGing.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Fraig_ParamsSetDefaultFull( Fraig_Params_t * pParams )
+{
+ memset( pParams, 0, sizeof(Fraig_Params_t) );
+ pParams->nPatsRand = FRAIG_PATTERNS_RANDOM; // the number of words of random simulation info
+ pParams->nPatsDyna = FRAIG_PATTERNS_DYNAMIC; // the number of words of dynamic simulation info
+ pParams->nBTLimit = -1; // the max number of backtracks to perform
+ pParams->nSeconds = 20; // the max number of seconds to solve the miter
+ pParams->fFuncRed = 1; // performs only one level hashing
+ pParams->fFeedBack = 1; // enables solver feedback
+ pParams->fDist1Pats = 1; // enables distance-1 patterns
+ pParams->fDoSparse = 1; // performs equiv tests for sparse functions
+ pParams->fChoicing = 0; // enables recording structural choices
+ pParams->fTryProve = 0; // tries to solve the final miter
+ pParams->fVerbose = 0; // the verbosiness flag
+ pParams->fVerboseP = 0; // the verbose flag for reporting the proof
+ pParams->fInternal = 0; // the flag indicates the internal run
+ pParams->nConfLimit = 0; // the limit on the number of conflicts
+ pParams->nInspLimit = 0; // the limit on the number of inspections
}
/**Function*************************************************************
@@ -74,7 +184,8 @@ Fraig_Man_t * Fraig_ManCreate( Fraig_Params_t * pParams )
Fraig_Man_t * p;
// set the random seed for simulation
- srand( 0xFEEDDEAF );
+// srand( 0xFEEDDEAF );
+ srand( 0xDEADCAFE );
// set parameters for equivalence checking
if ( pParams == NULL )
@@ -100,6 +211,7 @@ Fraig_Man_t * Fraig_ManCreate( Fraig_Params_t * pParams )
p->nWordsRand = FRAIG_NUM_WORDS( pParams->nPatsRand ); // the number of words of random simulation info
p->nWordsDyna = FRAIG_NUM_WORDS( pParams->nPatsDyna ); // the number of patterns for dynamic simulation info
p->nBTLimit = pParams->nBTLimit; // -1 means infinite backtrack limit
+ p->nSeconds = pParams->nSeconds; // the timeout for the final miter
p->fFuncRed = pParams->fFuncRed; // enables functional reduction (otherwise, only one-level hashing is performed)
p->fFeedBack = pParams->fFeedBack; // enables solver feedback (the use of counter-examples in simulation)
p->fDist1Pats = pParams->fDist1Pats; // enables solver feedback (the use of counter-examples in simulation)
@@ -108,6 +220,7 @@ Fraig_Man_t * Fraig_ManCreate( Fraig_Params_t * pParams )
p->fTryProve = pParams->fTryProve; // disable accumulation of structural choices (keeps only the first choice)
p->fVerbose = pParams->fVerbose; // disable verbose output
p->fVerboseP = pParams->fVerboseP; // disable verbose output
+ p->nInspLimit = pParams->nInspLimit; // the limit on the number of inspections
// start memory managers
p->mmNodes = Fraig_MemFixedStart( sizeof(Fraig_Node_t) );
@@ -153,7 +266,7 @@ void Fraig_ManFree( Fraig_Man_t * p )
// Fraig_TablePrintStatsF( p );
// Fraig_TablePrintStatsF0( p );
}
-
+
for ( i = 0; i < p->vNodes->nSize; i++ )
if ( p->vNodes->pArray[i]->vFanins )
{
@@ -194,6 +307,31 @@ void Fraig_ManFree( Fraig_Man_t * p )
FREE( p );
}
+/**Function*************************************************************
+
+ Synopsis [Prepares the SAT solver to run on the two nodes.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Fraig_ManCreateSolver( Fraig_Man_t * p )
+{
+ extern int timeSelect;
+ extern int timeAssign;
+ assert( p->pSat == NULL );
+ // allocate data for SAT solving
+ p->pSat = Msat_SolverAlloc( 500, 1, 1, 1, 1, 0 );
+ p->vVarsInt = Msat_SolverReadConeVars( p->pSat );
+ p->vAdjacents = Msat_SolverReadAdjacents( p->pSat );
+ p->vVarsUsed = Msat_SolverReadVarsUsed( p->pSat );
+ timeSelect = 0;
+ timeAssign = 0;
+}
+
/**Function*************************************************************
@@ -214,8 +352,8 @@ void Fraig_ManPrintStats( Fraig_Man_t * p )
(sizeof(Fraig_Node_t) + sizeof(unsigned)*(p->nWordsRand + p->nWordsDyna) /*+ p->nSuppWords*sizeof(unsigned)*/))/(1<<20);
printf( "Words: Random = %d. Dynamic = %d. Used = %d. Memory = %0.2f Mb.\n",
p->nWordsRand, p->nWordsDyna, p->iWordPerm, nMemory );
- printf( "Proof = %d. Counter-example = %d. Fail = %d. Zero = %d.\n",
- p->nSatProof, p->nSatCounter, p->nSatFails, p->nSatZeros );
+ printf( "Proof = %d. Counter-example = %d. Fail = %d. FailReal = %d. Zero = %d.\n",
+ p->nSatProof, p->nSatCounter, p->nSatFails, p->nSatFailsReal, p->nSatZeros );
printf( "Nodes: Final = %d. Total = %d. Mux = %d. (Exor = %d.) ClaVars = %d.\n",
Fraig_CountNodes(p,0), p->vNodes->nSize, Fraig_ManCountMuxes(p), Fraig_ManCountExors(p), p->nVarsClauses );
if ( p->pSat ) Msat_SolverPrintStats( p->pSat );
@@ -233,6 +371,168 @@ void Fraig_ManPrintStats( Fraig_Man_t * p )
// PRT( "Assignment", timeAssign );
}
+/**Function*************************************************************
+
+ Synopsis [Allocates simulation information for all nodes.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Fraig_NodeVec_t * Fraig_UtilInfoAlloc( int nSize, int nWords, bool fClean )
+{
+ Fraig_NodeVec_t * vInfo;
+ unsigned * pUnsigned;
+ int i;
+ assert( nSize > 0 && nWords > 0 );
+ vInfo = Fraig_NodeVecAlloc( nSize );
+ pUnsigned = ALLOC( unsigned, nSize * nWords );
+ vInfo->pArray[0] = (Fraig_Node_t *)pUnsigned;
+ if ( fClean )
+ memset( pUnsigned, 0, sizeof(unsigned) * nSize * nWords );
+ for ( i = 1; i < nSize; i++ )
+ vInfo->pArray[i] = (Fraig_Node_t *)(((unsigned *)vInfo->pArray[i-1]) + nWords);
+ vInfo->nSize = nSize;
+ return vInfo;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Returns simulation info of all nodes.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Fraig_NodeVec_t * Fraig_ManGetSimInfo( Fraig_Man_t * p )
+{
+ Fraig_NodeVec_t * vInfo;
+ Fraig_Node_t * pNode;
+ unsigned * pUnsigned;
+ int nRandom, nDynamic;
+ int i, k, nWords;
+
+ nRandom = Fraig_ManReadPatternNumRandom( p );
+ nDynamic = Fraig_ManReadPatternNumDynamic( p );
+ nWords = nRandom / 32 + nDynamic / 32;
+
+ vInfo = Fraig_UtilInfoAlloc( p->vNodes->nSize, nWords, 0 );
+ for ( i = 0; i < p->vNodes->nSize; i++ )
+ {
+ pNode = p->vNodes->pArray[i];
+ assert( i == pNode->Num );
+ pUnsigned = (unsigned *)vInfo->pArray[i];
+ for ( k = 0; k < nRandom / 32; k++ )
+ pUnsigned[k] = pNode->puSimR[k];
+ for ( k = 0; k < nDynamic / 32; k++ )
+ pUnsigned[nRandom / 32 + k] = pNode->puSimD[k];
+ }
+ return vInfo;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Returns 1 if A v B is always true based on the siminfo.]
+
+ Description [A v B is always true iff A' * B' is always false.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Fraig_ManCheckClauseUsingSimInfo( Fraig_Man_t * p, Fraig_Node_t * pNode1, Fraig_Node_t * pNode2 )
+{
+ int fCompl1, fCompl2, i;
+
+ fCompl1 = 1 ^ Fraig_IsComplement(pNode1) ^ Fraig_Regular(pNode1)->fInv;
+ fCompl2 = 1 ^ Fraig_IsComplement(pNode2) ^ Fraig_Regular(pNode2)->fInv;
+
+ pNode1 = Fraig_Regular(pNode1);
+ pNode2 = Fraig_Regular(pNode2);
+ assert( pNode1 != pNode2 );
+
+ // check the simulation info
+ if ( fCompl1 && fCompl2 )
+ {
+ for ( i = 0; i < p->nWordsRand; i++ )
+ if ( ~pNode1->puSimR[i] & ~pNode2->puSimR[i] )
+ return 0;
+ for ( i = 0; i < p->iWordStart; i++ )
+ if ( ~pNode1->puSimD[i] & ~pNode2->puSimD[i] )
+ return 0;
+ return 1;
+ }
+ if ( !fCompl1 && fCompl2 )
+ {
+ for ( i = 0; i < p->nWordsRand; i++ )
+ if ( pNode1->puSimR[i] & ~pNode2->puSimR[i] )
+ return 0;
+ for ( i = 0; i < p->iWordStart; i++ )
+ if ( pNode1->puSimD[i] & ~pNode2->puSimD[i] )
+ return 0;
+ return 1;
+ }
+ if ( fCompl1 && !fCompl2 )
+ {
+ for ( i = 0; i < p->nWordsRand; i++ )
+ if ( ~pNode1->puSimR[i] & pNode2->puSimR[i] )
+ return 0;
+ for ( i = 0; i < p->iWordStart; i++ )
+ if ( ~pNode1->puSimD[i] & pNode2->puSimD[i] )
+ return 0;
+ return 1;
+ }
+// if ( fCompl1 && fCompl2 )
+ {
+ for ( i = 0; i < p->nWordsRand; i++ )
+ if ( pNode1->puSimR[i] & pNode2->puSimR[i] )
+ return 0;
+ for ( i = 0; i < p->iWordStart; i++ )
+ if ( pNode1->puSimD[i] & pNode2->puSimD[i] )
+ return 0;
+ return 1;
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Adds clauses to the solver.]
+
+ Description [This procedure is used to add external clauses to the solver.
+ The clauses are given by sets of nodes. Each node stands for one literal.
+ If the node is complemented, the literal is negated.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Fraig_ManAddClause( Fraig_Man_t * p, Fraig_Node_t ** ppNodes, int nNodes )
+{
+ Fraig_Node_t * pNode;
+ int i, fComp, RetValue;
+ if ( p->pSat == NULL )
+ Fraig_ManCreateSolver( p );
+ // create four clauses
+ Msat_IntVecClear( p->vProj );
+ for ( i = 0; i < nNodes; i++ )
+ {
+ pNode = Fraig_Regular(ppNodes[i]);
+ fComp = Fraig_IsComplement(ppNodes[i]);
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNode->Num, fComp) );
+// printf( "%d(%d) ", pNode->Num, fComp );
+ }
+// printf( "\n" );
+ RetValue = Msat_SolverAddClause( p->pSat, p->vProj );
+ assert( RetValue );
+}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
diff --git a/src/sat/fraig/fraigMem.c b/src/sat/fraig/fraigMem.c
index dbf42da4..500431c6 100644
--- a/src/sat/fraig/fraigMem.c
+++ b/src/sat/fraig/fraigMem.c
@@ -43,7 +43,7 @@ struct Fraig_MemFixed_t_
};
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -201,7 +201,7 @@ void Fraig_MemFixedRestart( Fraig_MemFixed_t * p )
int i;
char * pTemp;
- // delocate all chunks except the first one
+ // deallocate all chunks except the first one
for ( i = 1; i < p->nChunks; i++ )
free( p->pChunks[i] );
p->nChunks = 1;
diff --git a/src/sat/fraig/fraigNode.c b/src/sat/fraig/fraigNode.c
index a6c1d5a6..6e3d3c7d 100644
--- a/src/sat/fraig/fraigNode.c
+++ b/src/sat/fraig/fraigNode.c
@@ -26,7 +26,7 @@
#define Fraig_NodeIsSimComplement(p) (Fraig_IsComplement(p)? !(Fraig_Regular(p)->fInv) : (p)->fInv)
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -176,6 +176,7 @@ Fraig_Node_t * Fraig_NodeCreate( Fraig_Man_t * p, Fraig_Node_t * p1, Fraig_Node_
// compute the level of this node
pNode->Level = 1 + FRAIG_MAX(Fraig_Regular(p1)->Level, Fraig_Regular(p2)->Level);
pNode->fInv = Fraig_NodeIsSimComplement(p1) & Fraig_NodeIsSimComplement(p2);
+ pNode->fFailTfo = Fraig_Regular(p1)->fFailTfo | Fraig_Regular(p2)->fFailTfo;
// derive the simulation info
clk = clock();
diff --git a/src/sat/fraig/fraigPrime.c b/src/sat/fraig/fraigPrime.c
index 0f37a586..127ad478 100644
--- a/src/sat/fraig/fraigPrime.c
+++ b/src/sat/fraig/fraigPrime.c
@@ -22,7 +22,7 @@
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
-// The 1,000 smallest prime numbers used to compute the hash value
+// The 1,024 smallest prime numbers used to compute the hash value
// http://www.math.utah.edu/~alfeld/math/primelist.html
int s_FraigPrimes[FRAIG_MAX_PRIMES] = { 2, 3, 5,
7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
@@ -93,10 +93,12 @@ int s_FraigPrimes[FRAIG_MAX_PRIMES] = { 2, 3, 5,
7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603,
7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723,
7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873,
-7877, 7879, 7883, 7901, 7907, 7919 };
+7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009,
+8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123,
+8147, 8161 };
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function********************************************************************
diff --git a/src/sat/fraig/fraigSat.c b/src/sat/fraig/fraigSat.c
index 17201e58..53057fc3 100644
--- a/src/sat/fraig/fraigSat.c
+++ b/src/sat/fraig/fraigSat.c
@@ -17,6 +17,7 @@
***********************************************************************/
#include "fraigInt.h"
+#include "math.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
@@ -33,6 +34,7 @@ static void Fraig_SupergateAddClausesExor( Fraig_Man_t * pMan, Fraig_Node_t * pN
static void Fraig_SupergateAddClausesMux( Fraig_Man_t * pMan, Fraig_Node_t * pNode );
//static void Fraig_DetectFanoutFreeCone( Fraig_Man_t * pMan, Fraig_Node_t * pNode );
static void Fraig_DetectFanoutFreeConeMux( Fraig_Man_t * pMan, Fraig_Node_t * pNode );
+static void Fraig_SetActivity( Fraig_Man_t * pMan, Fraig_Node_t * pOld, Fraig_Node_t * pNew );
extern void * Msat_ClauseVecReadEntry( void * p, int i );
@@ -41,8 +43,10 @@ extern void * Msat_ClauseVecReadEntry( void * p, int i );
// The best way seems to be fanins followed by fanouts. Slight changes to this order
// leads to big degradation in quality.
+static int nMuxes;
+
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -56,13 +60,13 @@ extern void * Msat_ClauseVecReadEntry( void * p, int i );
SeeAlso []
***********************************************************************/
-int Fraig_NodesAreEqual( Fraig_Man_t * p, Fraig_Node_t * pNode1, Fraig_Node_t * pNode2, int nBTLimit )
+int Fraig_NodesAreEqual( Fraig_Man_t * p, Fraig_Node_t * pNode1, Fraig_Node_t * pNode2, int nBTLimit, int nTimeLimit )
{
if ( pNode1 == pNode2 )
return 1;
if ( pNode1 == Fraig_Not(pNode2) )
return 0;
- return Fraig_NodeIsEquivalent( p, Fraig_Regular(pNode1), Fraig_Regular(pNode2), nBTLimit );
+ return Fraig_NodeIsEquivalent( p, Fraig_Regular(pNode1), Fraig_Regular(pNode2), nBTLimit, nTimeLimit );
}
/**Function*************************************************************
@@ -95,9 +99,9 @@ void Fraig_ManProveMiter( Fraig_Man_t * p )
// skip nodes that are different according to simulation
if ( !Fraig_CompareSimInfo( pNode, p->pConst1, p->nWordsRand, 1 ) )
continue;
- if ( Fraig_NodeIsEquivalent( p, p->pConst1, pNode, -1 ) )
+ if ( Fraig_NodeIsEquivalent( p, p->pConst1, pNode, -1, p->nSeconds ) )
{
- if ( Fraig_IsComplement(p->vOutputs->pArray[i]) )
+ if ( Fraig_IsComplement(p->vOutputs->pArray[i]) ^ Fraig_NodeComparePhase(p->pConst1, pNode) )
p->vOutputs->pArray[i] = Fraig_Not(p->pConst1);
else
p->vOutputs->pArray[i] = p->pConst1;
@@ -105,7 +109,7 @@ void Fraig_ManProveMiter( Fraig_Man_t * p )
}
if ( p->fVerboseP )
{
- PRT( "Final miter proof time", clock() - clk );
+// PRT( "Final miter proof time", clock() - clk );
}
}
@@ -123,26 +127,158 @@ void Fraig_ManProveMiter( Fraig_Man_t * p )
int Fraig_ManCheckMiter( Fraig_Man_t * p )
{
Fraig_Node_t * pNode;
+ int i;
FREE( p->pModel );
- // get the output node (it can be complemented!)
- pNode = p->vOutputs->pArray[0];
- // if the miter is constant 0, the problem is UNSAT
- if ( pNode == Fraig_Not(p->pConst1) )
+ for ( i = 0; i < p->vOutputs->nSize; i++ )
+ {
+ // get the output node (it can be complemented!)
+ pNode = p->vOutputs->pArray[i];
+ // if the miter is constant 0, the problem is UNSAT
+ if ( pNode == Fraig_Not(p->pConst1) )
+ continue;
+ // consider the special case when the miter is constant 1
+ if ( pNode == p->pConst1 )
+ {
+ // in this case, any counter example will do to distinquish it from constant 0
+ // here we pick the counter example composed of all zeros
+ p->pModel = Fraig_ManAllocCounterExample( p );
+ return 0;
+ }
+ // save the counter example
+ p->pModel = Fraig_ManSaveCounterExample( p, pNode );
+ // if the model is not found, return undecided
+ if ( p->pModel == NULL )
+ return -1;
+ else
+ return 0;
+ }
+ return 1;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Returns 1 if pOld is in the TFI of pNew.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Fraig_MarkTfi_rec( Fraig_Man_t * pMan, Fraig_Node_t * pNode )
+{
+ // skip the visited node
+ if ( pNode->TravId == pMan->nTravIds )
+ return 0;
+ pNode->TravId = pMan->nTravIds;
+ // skip the PI node
+ if ( pNode->NumPi >= 0 )
+ return 1;
+ // check the children
+ return Fraig_MarkTfi_rec( pMan, Fraig_Regular(pNode->p1) ) +
+ Fraig_MarkTfi_rec( pMan, Fraig_Regular(pNode->p2) );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Returns 1 if pOld is in the TFI of pNew.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Fraig_MarkTfi2_rec( Fraig_Man_t * pMan, Fraig_Node_t * pNode )
+{
+ // skip the visited node
+ if ( pNode->TravId == pMan->nTravIds )
+ return 0;
+ // skip the boundary node
+ if ( pNode->TravId == pMan->nTravIds-1 )
+ {
+ pNode->TravId = pMan->nTravIds;
+ return 1;
+ }
+ pNode->TravId = pMan->nTravIds;
+ // skip the PI node
+ if ( pNode->NumPi >= 0 )
+ return 1;
+ // check the children
+ return Fraig_MarkTfi2_rec( pMan, Fraig_Regular(pNode->p1) ) +
+ Fraig_MarkTfi2_rec( pMan, Fraig_Regular(pNode->p2) );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Returns 1 if pOld is in the TFI of pNew.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Fraig_MarkTfi3_rec( Fraig_Man_t * pMan, Fraig_Node_t * pNode )
+{
+ // skip the visited node
+ if ( pNode->TravId == pMan->nTravIds )
return 1;
- // consider the special case when the miter is constant 1
- if ( pNode == p->pConst1 )
+ // skip the boundary node
+ if ( pNode->TravId == pMan->nTravIds-1 )
{
- // in this case, any counter example will do to distinquish it from constant 0
- // here we pick the counter example composed of all zeros
- p->pModel = Fraig_ManAllocCounterExample( p );
+ pNode->TravId = pMan->nTravIds;
+ return 1;
+ }
+ pNode->TravId = pMan->nTravIds;
+ // skip the PI node
+ if ( pNode->NumPi >= 0 )
return 0;
+ // check the children
+ return Fraig_MarkTfi3_rec( pMan, Fraig_Regular(pNode->p1) ) *
+ Fraig_MarkTfi3_rec( pMan, Fraig_Regular(pNode->p2) );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Fraig_VarsStudy( Fraig_Man_t * p, Fraig_Node_t * pOld, Fraig_Node_t * pNew )
+{
+ int NumPis, NumCut, fContain;
+
+ // mark the TFI of pNew
+ p->nTravIds++;
+ NumPis = Fraig_MarkTfi_rec( p, pNew );
+ printf( "(%d)(%d,%d):", NumPis, pOld->Level, pNew->Level );
+
+ // check if the old is in the TFI
+ if ( pOld->TravId == p->nTravIds )
+ {
+ printf( "* " );
+ return;
}
- // save the counter example
- p->pModel = Fraig_ManSaveCounterExample( p, pNode );
- // if the model is not found, return undecided
- if ( p->pModel == NULL )
- return -1;
- return 0;
+
+ // count the boundary of nodes in pOld
+ p->nTravIds++;
+ NumCut = Fraig_MarkTfi2_rec( p, pOld );
+ printf( "%d", NumCut );
+
+ // check if the new is contained in the old's support
+ p->nTravIds++;
+ fContain = Fraig_MarkTfi3_rec( p, pNew );
+ printf( "%c ", fContain? '+':'-' );
}
@@ -160,34 +296,40 @@ int Fraig_ManCheckMiter( Fraig_Man_t * p )
SeeAlso []
***********************************************************************/
-int Fraig_NodeIsEquivalent( Fraig_Man_t * p, Fraig_Node_t * pOld, Fraig_Node_t * pNew, int nBTLimit )
+int Fraig_NodeIsEquivalent( Fraig_Man_t * p, Fraig_Node_t * pOld, Fraig_Node_t * pNew, int nBTLimit, int nTimeLimit )
{
int RetValue, RetValue1, i, fComp, clk;
int fVerbose = 0;
+ int fSwitch = 0;
// make sure the nodes are not complemented
assert( !Fraig_IsComplement(pNew) );
assert( !Fraig_IsComplement(pOld) );
assert( pNew != pOld );
+ // if at least one of the nodes is a failed node, perform adjustments:
+ // if the backtrack limit is small, simply skip this node
+ // if the backtrack limit is > 10, take the quare root of the limit
+ if ( nBTLimit > 0 && (pOld->fFailTfo || pNew->fFailTfo) )
+ {
+ p->nSatFails++;
+// return 0;
+// if ( nBTLimit > 10 )
+// nBTLimit /= 10;
+ if ( nBTLimit <= 10 )
+ return 0;
+ nBTLimit = (int)sqrt(nBTLimit);
+// fSwitch = 1;
+ }
+
p->nSatCalls++;
// make sure the solver is allocated and has enough variables
if ( p->pSat == NULL )
- {
- extern int timeSelect;
- extern int timeAssign;
- // allocate data for SAT solving
- p->pSat = Msat_SolverAlloc( 500, 1, 1, 1, 1, 0 );
- p->vVarsInt = Msat_SolverReadConeVars( p->pSat );
- p->vAdjacents = Msat_SolverReadAdjacents( p->pSat );
- p->vVarsUsed = Msat_SolverReadVarsUsed( p->pSat );
- timeSelect = 0;
- timeAssign = 0;
- }
+ Fraig_ManCreateSolver( p );
// make sure the SAT solver has enough variables
for ( i = Msat_SolverReadVarNum(p->pSat); i < p->vNodes->nSize; i++ )
- Msat_SolverAddVar( p->pSat );
+ Msat_SolverAddVar( p->pSat, p->vNodes->pArray[i]->Level );
@@ -199,17 +341,26 @@ int Fraig_NodeIsEquivalent( Fraig_Man_t * p, Fraig_Node_t * pOld, Fraig_Node_t *
}
*/
+ nMuxes = 0;
+
// get the logic cone
clk = clock();
+// Fraig_VarsStudy( p, pOld, pNew );
Fraig_OrderVariables( p, pOld, pNew );
// Fraig_PrepareCones( p, pOld, pNew );
p->timeTrav += clock() - clk;
+// printf( "The number of MUXes detected = %d (%5.2f %% of logic). ", nMuxes, 300.0*nMuxes/(p->vNodes->nSize - p->vInputs->nSize) );
+// PRT( "Time", clock() - clk );
+
if ( fVerbose )
printf( "%d(%d) - ", Fraig_CountPis(p,p->vVarsInt), Msat_IntVecReadSize(p->vVarsInt) );
+ // prepare variable activity
+ Fraig_SetActivity( p, pOld, pNew );
+
// get the complemented attribute
fComp = Fraig_NodeComparePhase( pOld, pNew );
//Msat_SolverPrintClauses( p->pSat );
@@ -220,14 +371,18 @@ if ( fVerbose )
Msat_SolverPrepare( p->pSat, p->vVarsInt );
//p->time3 += clock() - clk;
+
// solve under assumptions
// A = 1; B = 0 OR A = 1; B = 1
Msat_IntVecClear( p->vProj );
Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pOld->Num, 0) );
Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNew->Num, !fComp) );
+
+//Msat_SolverWriteDimacs( p->pSat, "temp_fraig.cnf" );
+
// run the solver
clk = clock();
- RetValue1 = Msat_SolverSolve( p->pSat, p->vProj, nBTLimit );
+ RetValue1 = Msat_SolverSolve( p->pSat, p->vProj, nBTLimit, nTimeLimit );
p->timeSat += clock() - clk;
if ( RetValue1 == MSAT_FALSE )
@@ -260,13 +415,31 @@ PRT( "time", clock() - clk );
// record the counter example
Fraig_FeedBack( p, Msat_SolverReadModelArray(p->pSat), p->vVarsInt, pOld, pNew );
+
+// if ( pOld->fFailTfo || pNew->fFailTfo )
+// printf( "*" );
+// printf( "s(%d)", pNew->Level );
+ if ( fSwitch )
+ printf( "s(%d)", pNew->Level );
p->nSatCounter++;
return 0;
}
else // if ( RetValue1 == MSAT_UNKNOWN )
{
p->time3 += clock() - clk;
- p->nSatFails++;
+
+// if ( pOld->fFailTfo || pNew->fFailTfo )
+// printf( "*" );
+// printf( "T(%d)", pNew->Level );
+
+ // mark the node as the failed node
+ if ( pOld != p->pConst1 )
+ pOld->fFailTfo = 1;
+ pNew->fFailTfo = 1;
+// p->nSatFails++;
+ if ( fSwitch )
+ printf( "T(%d)", pNew->Level );
+ p->nSatFailsReal++;
return 0;
}
@@ -286,8 +459,9 @@ p->time3 += clock() - clk;
Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNew->Num, fComp) );
// run the solver
clk = clock();
- RetValue1 = Msat_SolverSolve( p->pSat, p->vProj, nBTLimit );
+ RetValue1 = Msat_SolverSolve( p->pSat, p->vProj, nBTLimit, nTimeLimit );
p->timeSat += clock() - clk;
+
if ( RetValue1 == MSAT_FALSE )
{
//p->time1 += clock() - clk;
@@ -319,17 +493,42 @@ PRT( "time", clock() - clk );
// record the counter example
Fraig_FeedBack( p, Msat_SolverReadModelArray(p->pSat), p->vVarsInt, pOld, pNew );
p->nSatCounter++;
+
+// if ( pOld->fFailTfo || pNew->fFailTfo )
+// printf( "*" );
+// printf( "s(%d)", pNew->Level );
+ if ( fSwitch )
+ printf( "s(%d)", pNew->Level );
return 0;
}
else // if ( RetValue1 == MSAT_UNKNOWN )
{
p->time3 += clock() - clk;
- p->nSatFails++;
+
+// if ( pOld->fFailTfo || pNew->fFailTfo )
+// printf( "*" );
+// printf( "T(%d)", pNew->Level );
+ if ( fSwitch )
+ printf( "T(%d)", pNew->Level );
+
+ // mark the node as the failed node
+ pOld->fFailTfo = 1;
+ pNew->fFailTfo = 1;
+// p->nSatFails++;
+ p->nSatFailsReal++;
return 0;
}
// return SAT proof
p->nSatProof++;
+
+// if ( pOld->fFailTfo || pNew->fFailTfo )
+// printf( "*" );
+// printf( "u(%d)", pNew->Level );
+
+ if ( fSwitch )
+ printf( "u(%d)", pNew->Level );
+
return 1;
}
@@ -359,32 +558,12 @@ int Fraig_NodeIsImplication( Fraig_Man_t * p, Fraig_Node_t * pOld, Fraig_Node_t
// make sure the solver is allocated and has enough variables
if ( p->pSat == NULL )
- {
- extern int timeSelect;
- extern int timeAssign;
- // allocate data for SAT solving
- p->pSat = Msat_SolverAlloc( 500, 1, 1, 1, 1, 0 );
- p->vVarsInt = Msat_SolverReadConeVars( p->pSat );
- p->vAdjacents = Msat_SolverReadAdjacents( p->pSat );
- p->vVarsUsed = Msat_SolverReadVarsUsed( p->pSat );
- timeSelect = 0;
- timeAssign = 0;
- }
+ Fraig_ManCreateSolver( p );
// make sure the SAT solver has enough variables
for ( i = Msat_SolverReadVarNum(p->pSat); i < p->vNodes->nSize; i++ )
- Msat_SolverAddVar( p->pSat );
-
+ Msat_SolverAddVar( p->pSat, p->vNodes->pArray[i]->Level );
-/*
- {
- Fraig_Node_t * ppNodes[2] = { pOld, pNew };
- extern void Fraig_MappingShowNodes( Fraig_Man_t * pMan, Fraig_Node_t ** ppRoots, int nRoots, char * pFileName );
- Fraig_MappingShowNodes( p, ppNodes, 2, "temp_aig" );
- }
-*/
-
-
- // get the logic cone
+ // get the logic cone
clk = clock();
Fraig_OrderVariables( p, pOld, pNew );
// Fraig_PrepareCones( p, pOld, pNew );
@@ -411,7 +590,7 @@ if ( fVerbose )
Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNew->Num, !fComp) );
// run the solver
clk = clock();
- RetValue1 = Msat_SolverSolve( p->pSat, p->vProj, nBTLimit );
+ RetValue1 = Msat_SolverSolve( p->pSat, p->vProj, nBTLimit, 1000000 );
p->timeSat += clock() - clk;
if ( RetValue1 == MSAT_FALSE )
@@ -443,8 +622,8 @@ if ( fVerbose )
PRT( "time", clock() - clk );
}
// record the counter example
-// Fraig_FeedBack( p, Msat_SolverReadModelArray(p->pSat), p->vVarsInt, pOld, pNew );
-// p->nSatCounterImp++;
+ Fraig_FeedBack( p, Msat_SolverReadModelArray(p->pSat), p->vVarsInt, pOld, pNew );
+ p->nSatCounterImp++;
return 0;
}
else // if ( RetValue1 == MSAT_UNKNOWN )
@@ -455,6 +634,96 @@ p->time3 += clock() - clk;
}
}
+/**Function*************************************************************
+
+ Synopsis [Prepares the SAT solver to run on the two nodes.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Fraig_ManCheckClauseUsingSat( Fraig_Man_t * p, Fraig_Node_t * pNode1, Fraig_Node_t * pNode2, int nBTLimit )
+{
+ Fraig_Node_t * pNode1R, * pNode2R;
+ int RetValue, RetValue1, i, clk;
+ int fVerbose = 0;
+
+ pNode1R = Fraig_Regular(pNode1);
+ pNode2R = Fraig_Regular(pNode2);
+ assert( pNode1R != pNode2R );
+
+ // make sure the solver is allocated and has enough variables
+ if ( p->pSat == NULL )
+ Fraig_ManCreateSolver( p );
+ // make sure the SAT solver has enough variables
+ for ( i = Msat_SolverReadVarNum(p->pSat); i < p->vNodes->nSize; i++ )
+ Msat_SolverAddVar( p->pSat, p->vNodes->pArray[i]->Level );
+
+ // get the logic cone
+clk = clock();
+ Fraig_OrderVariables( p, pNode1R, pNode2R );
+// Fraig_PrepareCones( p, pNode1R, pNode2R );
+p->timeTrav += clock() - clk;
+
+ ////////////////////////////////////////////
+ // prepare the solver to run incrementally on these variables
+//clk = clock();
+ Msat_SolverPrepare( p->pSat, p->vVarsInt );
+//p->time3 += clock() - clk;
+
+ // solve under assumptions
+ // A = 1; B = 0 OR A = 1; B = 1
+ Msat_IntVecClear( p->vProj );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNode1R->Num, !Fraig_IsComplement(pNode1)) );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNode2R->Num, !Fraig_IsComplement(pNode2)) );
+ // run the solver
+clk = clock();
+ RetValue1 = Msat_SolverSolve( p->pSat, p->vProj, nBTLimit, 1000000 );
+p->timeSat += clock() - clk;
+
+ if ( RetValue1 == MSAT_FALSE )
+ {
+//p->time1 += clock() - clk;
+
+if ( fVerbose )
+{
+ printf( "unsat %d ", Msat_SolverReadBackTracks(p->pSat) );
+PRT( "time", clock() - clk );
+}
+
+ // add the clause
+ Msat_IntVecClear( p->vProj );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNode1R->Num, Fraig_IsComplement(pNode1)) );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNode2R->Num, Fraig_IsComplement(pNode2)) );
+ RetValue = Msat_SolverAddClause( p->pSat, p->vProj );
+ assert( RetValue );
+// p->nSatProofImp++;
+ return 1;
+ }
+ else if ( RetValue1 == MSAT_TRUE )
+ {
+//p->time2 += clock() - clk;
+
+if ( fVerbose )
+{
+ printf( "sat %d ", Msat_SolverReadBackTracks(p->pSat) );
+PRT( "time", clock() - clk );
+}
+ // record the counter example
+// Fraig_FeedBack( p, Msat_SolverReadModelArray(p->pSat), p->vVarsInt, pNode1R, pNode2R );
+ p->nSatCounterImp++;
+ return 0;
+ }
+ else // if ( RetValue1 == MSAT_UNKNOWN )
+ {
+p->time3 += clock() - clk;
+ p->nSatFailsImp++;
+ return 0;
+ }
+}
/**Function*************************************************************
@@ -486,6 +755,7 @@ void Fraig_PrepareCones( Fraig_Man_t * pMan, Fraig_Node_t * pOld, Fraig_Node_t *
Fraig_PrepareCones_rec( pMan, pNew );
Fraig_PrepareCones_rec( pMan, pOld );
+
/*
nVars = Msat_IntVecReadSize( pMan->vVarsInt );
pVars = Msat_IntVecReadArray( pMan->vVarsInt );
@@ -649,6 +919,8 @@ void Fraig_OrderVariables( Fraig_Man_t * pMan, Fraig_Node_t * pOld, Fraig_Node_t
Fraig_NodeVecPushUnique( pNode->vFanins, Fraig_Regular(Fraig_Regular(pNode->p2)->p2) );
Fraig_SupergateAddClausesMux( pMan, pNode );
// Fraig_DetectFanoutFreeConeMux( pMan, pNode );
+
+ nMuxes++;
}
else
{
@@ -983,6 +1255,33 @@ void Fraig_SupergateAddClausesMux( Fraig_Man_t * p, Fraig_Node_t * pNode )
Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(VarF, 1) );
RetValue = Msat_SolverAddClause( p->pSat, p->vProj );
assert( RetValue );
+
+ // two additional clauses
+ // t' & e' -> f'
+ // t & e -> f
+
+ // t + e + f'
+ // t' + e' + f
+
+ if ( VarT == VarE )
+ {
+// assert( fCompT == !fCompE );
+ return;
+ }
+
+ Msat_IntVecClear( p->vProj );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(VarT, 0^fCompT) );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(VarE, 0^fCompE) );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(VarF, 1) );
+ RetValue = Msat_SolverAddClause( p->pSat, p->vProj );
+ assert( RetValue );
+ Msat_IntVecClear( p->vProj );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(VarT, 1^fCompT) );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(VarE, 1^fCompE) );
+ Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(VarF, 0) );
+ RetValue = Msat_SolverAddClause( p->pSat, p->vProj );
+ assert( RetValue );
+
}
@@ -1115,6 +1414,40 @@ printf( "%d(%d)", vFanins->nSize, nCubes );
}
+
+/**Function*************************************************************
+
+ Synopsis [Collect variables using their proximity from the nodes.]
+
+ Description [This procedure creates a variable order based on collecting
+ first the nodes that are the closest to the given two target nodes.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Fraig_SetActivity( Fraig_Man_t * pMan, Fraig_Node_t * pOld, Fraig_Node_t * pNew )
+{
+ Fraig_Node_t * pNode;
+ int i, Number, MaxLevel;
+ float * pFactors = Msat_SolverReadFactors(pMan->pSat);
+ if ( pFactors == NULL )
+ return;
+ MaxLevel = FRAIG_MAX( pOld->Level, pNew->Level );
+ // create the variable order
+ for ( i = 0; i < Msat_IntVecReadSize(pMan->vVarsInt); i++ )
+ {
+ // get the new node on the frontier
+ Number = Msat_IntVecReadEntry(pMan->vVarsInt, i);
+ pNode = pMan->vNodes->pArray[Number];
+ pFactors[pNode->Num] = (float)pow( 0.97, MaxLevel - pNode->Level );
+// if ( pNode->Num % 50 == 0 )
+// printf( "(%d) %.2f ", MaxLevel - pNode->Level, pFactors[pNode->Num] );
+ }
+// printf( "\n" );
+}
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
diff --git a/src/sat/fraig/fraigTable.c b/src/sat/fraig/fraigTable.c
index d0f22acd..b68bbe0e 100644
--- a/src/sat/fraig/fraigTable.c
+++ b/src/sat/fraig/fraigTable.c
@@ -26,7 +26,7 @@ static void Fraig_TableResizeS( Fraig_HashTable_t * p );
static void Fraig_TableResizeF( Fraig_HashTable_t * p, int fUseSimR );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/fraig/fraigUtil.c b/src/sat/fraig/fraigUtil.c
index 2155c4a3..342a7111 100644
--- a/src/sat/fraig/fraigUtil.c
+++ b/src/sat/fraig/fraigUtil.c
@@ -38,7 +38,7 @@ static void Fraig_Dfs_rec( Fraig_Man_t * pMan, Fraig_Node_t * pNode, Fraig_NodeV
static int Fraig_CheckTfi_rec( Fraig_Man_t * pMan, Fraig_Node_t * pNode, Fraig_Node_t * pOld );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/fraig/fraigVec.c b/src/sat/fraig/fraigVec.c
index 2e2603b0..ba3feecd 100644
--- a/src/sat/fraig/fraigVec.c
+++ b/src/sat/fraig/fraigVec.c
@@ -23,7 +23,7 @@
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/msat/msat.h b/src/sat/msat/msat.h
index 21ddcb81..53353ba6 100644
--- a/src/sat/msat/msat.h
+++ b/src/sat/msat/msat.h
@@ -21,6 +21,10 @@
#ifndef __MSAT_H__
#define __MSAT_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
@@ -65,7 +69,7 @@ typedef enum { MSAT_FALSE = -1, MSAT_UNKNOWN = 0, MSAT_TRUE = 1 } Msat_Type_t;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// MACRO DEFITIONS ///
+/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
@@ -76,10 +80,10 @@ typedef enum { MSAT_FALSE = -1, MSAT_UNKNOWN = 0, MSAT_TRUE = 1 } Msat_Type_t;
extern bool Msat_SolverParseDimacs( FILE * pFile, Msat_Solver_t ** p, int fVerbose );
/*=== satSolver.c ===========================================================*/
// adding vars, clauses, simplifying the database, and solving
-extern bool Msat_SolverAddVar( Msat_Solver_t * p );
+extern bool Msat_SolverAddVar( Msat_Solver_t * p, int Level );
extern bool Msat_SolverAddClause( Msat_Solver_t * p, Msat_IntVec_t * pLits );
extern bool Msat_SolverSimplifyDB( Msat_Solver_t * p );
-extern bool Msat_SolverSolve( Msat_Solver_t * p, Msat_IntVec_t * pVecAssumps, int nBackTrackLimit );
+extern bool Msat_SolverSolve( Msat_Solver_t * p, Msat_IntVec_t * pVecAssumps, int nBackTrackLimit, int nTimeLimit );
// printing stats, assignments, and clauses
extern void Msat_SolverPrintStats( Msat_Solver_t * p );
extern void Msat_SolverPrintAssignment( Msat_Solver_t * p );
@@ -87,17 +91,20 @@ extern void Msat_SolverPrintClauses( Msat_Solver_t * p );
extern void Msat_SolverWriteDimacs( Msat_Solver_t * p, char * pFileName );
// access to the solver internal data
extern int Msat_SolverReadVarNum( Msat_Solver_t * p );
+extern int Msat_SolverReadClauseNum( Msat_Solver_t * p );
extern int Msat_SolverReadVarAllocNum( Msat_Solver_t * p );
extern int * Msat_SolverReadAssignsArray( Msat_Solver_t * p );
extern int * Msat_SolverReadModelArray( Msat_Solver_t * p );
extern unsigned Msat_SolverReadTruth( Msat_Solver_t * p );
extern int Msat_SolverReadBackTracks( Msat_Solver_t * p );
+extern int Msat_SolverReadInspects( Msat_Solver_t * p );
extern void Msat_SolverSetVerbosity( Msat_Solver_t * p, int fVerbose );
extern void Msat_SolverSetProofWriting( Msat_Solver_t * p, int fProof );
extern void Msat_SolverSetVarTypeA( Msat_Solver_t * p, int Var );
extern void Msat_SolverSetVarMap( Msat_Solver_t * p, Msat_IntVec_t * vVarMap );
extern void Msat_SolverMarkLastClauseTypeA( Msat_Solver_t * p );
extern void Msat_SolverMarkClausesStart( Msat_Solver_t * p );
+extern float * Msat_SolverReadFactors( Msat_Solver_t * p );
// returns the solution after incremental solving
extern int Msat_SolverReadSolutions( Msat_Solver_t * p );
extern int * Msat_SolverReadSolutionsArray( Msat_Solver_t * p );
@@ -153,8 +160,13 @@ extern double Msat_VarHeapReadMaxWeight( Msat_VarHeap_t * p );
extern int Msat_VarHeapCountNodes( Msat_VarHeap_t * p, double WeightLimit );
extern int Msat_VarHeapReadMax( Msat_VarHeap_t * p );
extern int Msat_VarHeapGetMax( Msat_VarHeap_t * p );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-#endif
diff --git a/src/sat/msat/msatActivity.c b/src/sat/msat/msatActivity.c
index c9a518ce..1cd795bd 100644
--- a/src/sat/msat/msatActivity.c
+++ b/src/sat/msat/msatActivity.c
@@ -25,7 +25,7 @@
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -45,7 +45,9 @@ void Msat_SolverVarBumpActivity( Msat_Solver_t * p, Msat_Lit_t Lit )
if ( p->dVarDecay < 0 ) // (negative decay means static variable order -- don't bump)
return;
Var = MSAT_LIT2VAR(Lit);
- if ( (p->pdActivity[Var] += p->dVarInc) > 1e100 )
+ p->pdActivity[Var] += p->dVarInc;
+// p->pdActivity[Var] += p->dVarInc * p->pFactors[Var];
+ if ( p->pdActivity[Var] > 1e100 )
Msat_SolverVarRescaleActivity( p );
Msat_OrderUpdate( p->pOrder, Var );
}
diff --git a/src/sat/msat/msatClause.c b/src/sat/msat/msatClause.c
index dc39bee6..2ba8cd32 100644
--- a/src/sat/msat/msatClause.c
+++ b/src/sat/msat/msatClause.c
@@ -36,7 +36,7 @@ struct Msat_Clause_t_
};
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -82,6 +82,10 @@ bool Msat_ClauseCreate( Msat_Solver_t * p, Msat_IntVec_t * vLits, bool fLearned,
// nSeenId - 1 stands for negative
// nSeenId stands for positive
// Remove false literals
+
+ // there is a bug here!!!!
+ // when the same var in opposite polarities is given, it drops one polarity!!!
+
for ( i = j = 0; i < nLits; i++ ) {
// get the corresponding variable
Var = MSAT_LIT2VAR(pLits[i]);
@@ -190,6 +194,7 @@ bool Msat_ClauseCreate( Msat_Solver_t * p, Msat_IntVec_t * vLits, bool fLearned,
{
Msat_SolverVarBumpActivity( p, pLits[i] );
// Msat_SolverVarBumpActivity( p, pLits[i] );
+// p->pFreq[ MSAT_LIT2VAR(pLits[i]) ]++;
}
}
diff --git a/src/sat/msat/msatClauseVec.c b/src/sat/msat/msatClauseVec.c
index 7c24619f..04691cf2 100644
--- a/src/sat/msat/msatClauseVec.c
+++ b/src/sat/msat/msatClauseVec.c
@@ -25,7 +25,7 @@
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/msat/msatInt.h b/src/sat/msat/msatInt.h
index 037616f6..03903abe 100644
--- a/src/sat/msat/msatInt.h
+++ b/src/sat/msat/msatInt.h
@@ -56,10 +56,10 @@ typedef long long int64;
#define ALLOC(type, num) \
((type *) malloc(sizeof(type) * (num)))
#define REALLOC(type, obj, num) \
- (obj) ? ((type *) realloc((char *) obj, sizeof(type) * (num))) : \
- ((type *) malloc(sizeof(type) * (num)))
+ ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \
+ ((type *) malloc(sizeof(type) * (num))))
#define FREE(obj) \
- ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
+ ((obj) ? (free((char *)(obj)), (obj) = 0) : 0)
// By default, custom memory management is used
// which guarantees constant time allocation/deallocation
@@ -119,6 +119,7 @@ struct Msat_Solver_t_
double dClaDecay; // INVERSE decay factor for clause activity: stores 1/decay.
double * pdActivity; // A heuristic measurement of the activity of a variable.
+ float * pFactors; // the multiplicative factors of variable activity
double dVarInc; // Amount to bump next variable with.
double dVarDecay; // INVERSE decay factor for variable activity: stores 1/decay. Use negative value for static variable order.
Msat_Order_t * pOrder; // Keeps track of the decision variable order.
@@ -151,6 +152,7 @@ struct Msat_Solver_t_
int nSeenId; // the id of current seeing
Msat_IntVec_t * vReason; // the temporary array of literals
Msat_IntVec_t * vTemp; // the temporary array of literals
+ int * pFreq; // the number of times each var participated in conflicts
// the memory manager
Msat_MmStep_t * pMem;
@@ -184,7 +186,7 @@ struct Msat_IntVec_t_
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// MACRO DEFITIONS ///
+/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
diff --git a/src/sat/msat/msatMem.c b/src/sat/msat/msatMem.c
index 2d178094..30bf4a96 100644
--- a/src/sat/msat/msatMem.c
+++ b/src/sat/msat/msatMem.c
@@ -72,7 +72,7 @@ struct Msat_MmStep_t_
};
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -231,7 +231,7 @@ void Msat_MmFixedRestart( Msat_MmFixed_t * p )
int i;
char * pTemp;
- // delocate all chunks except the first one
+ // deallocate all chunks except the first one
for ( i = 1; i < p->nChunks; i++ )
free( p->pChunks[i] );
p->nChunks = 1;
diff --git a/src/sat/msat/msatOrderH.c b/src/sat/msat/msatOrderH.c
index ca034233..956e7fc6 100644
--- a/src/sat/msat/msatOrderH.c
+++ b/src/sat/msat/msatOrderH.c
@@ -58,7 +58,7 @@ static void Msat_HeapPercolateDown( Msat_Order_t * p, int i );
extern int timeSelect;
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/msat/msatOrderJ.c b/src/sat/msat/msatOrderJ.c
index 6067b40f..4db7ff7b 100644
--- a/src/sat/msat/msatOrderJ.c
+++ b/src/sat/msat/msatOrderJ.c
@@ -38,7 +38,7 @@ struct Msat_OrderVar_t_
{
Msat_OrderVar_t * pNext;
Msat_OrderVar_t * pPrev;
- int Num;
+ int Num;
};
// the ring of variables data structure (J-boundary)
@@ -82,7 +82,7 @@ extern int timeSelect;
extern int timeAssign;
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -170,7 +170,8 @@ int Msat_OrderCheck( Msat_Order_t * p )
Msat_OrderVar_t * pVar, * pNext;
Msat_IntVec_t * vRound;
int * pRound, nRound;
- int * pVars, nVars, i;
+ int * pVars, nVars, i, k;
+ int Counter = 0;
// go through all the variables in the boundary
Msat_OrderRingForEachEntry( p->rVars.pRoot, pVar, pNext )
@@ -188,10 +189,14 @@ int Msat_OrderCheck( Msat_Order_t * p )
if ( Msat_OrderVarIsAssigned(p, pRound[i]) )
break;
}
- assert( i != nRound );
- if ( i != nRound )
- return 0;
+// assert( i != nRound );
+// if ( i == nRound )
+// return 0;
+ if ( i == nRound )
+ Counter++;
}
+ if ( Counter > 0 )
+ printf( "%d(%d) ", Counter, p->rVars.nItems );
// we may also check other unassigned variables in the cone
// to make sure that if they are not in J-boundary,
@@ -209,16 +214,16 @@ int Msat_OrderCheck( Msat_Order_t * p )
vRound = (Msat_IntVec_t *)Msat_ClauseVecReadEntry( p->pSat->vAdjacents, pVars[i] );
nRound = Msat_IntVecReadSize( vRound );
pRound = Msat_IntVecReadArray( vRound );
- for ( i = 0; i < nRound; i++ )
+ for ( k = 0; k < nRound; k++ )
{
- if ( !Msat_OrderVarIsUsedInCone(p, pRound[i]) )
+ if ( !Msat_OrderVarIsUsedInCone(p, pRound[k]) )
continue;
- if ( Msat_OrderVarIsAssigned(p, pRound[i]) )
+ if ( Msat_OrderVarIsAssigned(p, pRound[k]) )
break;
}
- assert( i == nRound );
- if ( i == nRound )
- return 0;
+// assert( k == nRound );
+// if ( k != nRound )
+// return 0;
}
return 1;
}
@@ -256,7 +261,7 @@ int Msat_OrderVarSelect( Msat_Order_t * p )
Msat_OrderVar_t * pVar, * pNext, * pVarBest;
double * pdActs = p->pSat->pdActivity;
double dfActBest;
- int clk = clock();
+// int clk = clock();
pVarBest = NULL;
dfActBest = -1.0;
@@ -268,12 +273,13 @@ int Msat_OrderVarSelect( Msat_Order_t * p )
pVarBest = pVar;
}
}
-timeSelect += clock() - clk;
-timeAssign += clock() - clk;
+//timeSelect += clock() - clk;
+//timeAssign += clock() - clk;
//if ( pVarBest && pVarBest->Num % 1000 == 0 )
//printf( "%d ", p->rVars.nItems );
+// Msat_OrderCheck( p );
if ( pVarBest )
{
assert( Msat_OrderVarIsUsedInCone(p, pVarBest->Num) );
@@ -296,7 +302,7 @@ timeAssign += clock() - clk;
void Msat_OrderVarAssigned( Msat_Order_t * p, int Var )
{
Msat_IntVec_t * vRound;
- int i, clk = clock();
+ int i;//, clk = clock();
// make sure the variable is in the boundary
assert( Var < p->nVarsAlloc );
@@ -316,7 +322,7 @@ void Msat_OrderVarAssigned( Msat_Order_t * p, int Var )
continue;
Msat_OrderRingAddLast( &p->rVars, &p->pVars[vRound->pArray[i]] );
}
-timeSelect += clock() - clk;
+//timeSelect += clock() - clk;
// Msat_OrderCheck( p );
}
@@ -334,7 +340,7 @@ timeSelect += clock() - clk;
void Msat_OrderVarUnassigned( Msat_Order_t * p, int Var )
{
Msat_IntVec_t * vRound, * vRound2;
- int i, k, clk = clock();
+ int i, k;//, clk = clock();
// make sure the variable is not in the boundary
assert( Var < p->nVarsAlloc );
@@ -363,7 +369,7 @@ void Msat_OrderVarUnassigned( Msat_Order_t * p, int Var )
if ( k == vRound2->nSize ) // there is no assigned vars, delete this one
Msat_OrderRingRemove( &p->rVars, &p->pVars[vRound->pArray[i]] );
}
-timeSelect += clock() - clk;
+//timeSelect += clock() - clk;
// Msat_OrderCheck( p );
}
@@ -450,7 +456,7 @@ void Msat_OrderRingRemove( Msat_OrderRing_t * pRing, Msat_OrderVar_t * pVar )
pRing->pRoot = pVar->pNext;
// move the root to the next entry after pVar
// this way all the additions to the list will be traversed first
-// pRing->pRoot = pVar->pNext;
+// pRing->pRoot = pVar->pPrev;
// delete the node
pVar->pPrev->pNext = pVar->pNext;
pVar->pNext->pPrev = pVar->pPrev;
diff --git a/src/sat/msat/msatQueue.c b/src/sat/msat/msatQueue.c
index c12cc75d..5938e042 100644
--- a/src/sat/msat/msatQueue.c
+++ b/src/sat/msat/msatQueue.c
@@ -33,7 +33,7 @@ struct Msat_Queue_t_
};
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/msat/msatRead.c b/src/sat/msat/msatRead.c
index b8e585a4..738562ef 100644
--- a/src/sat/msat/msatRead.c
+++ b/src/sat/msat/msatRead.c
@@ -27,7 +27,7 @@
static char * Msat_FileRead( FILE * pFile );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/msat/msatSolverApi.c b/src/sat/msat/msatSolverApi.c
index ba506993..ee3507a6 100644
--- a/src/sat/msat/msatSolverApi.c
+++ b/src/sat/msat/msatSolverApi.c
@@ -27,7 +27,7 @@
static void Msat_SolverSetupTruthTables( unsigned uTruths[][2] );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -41,27 +41,30 @@ static void Msat_SolverSetupTruthTables( unsigned uTruths[][2] );
SeeAlso []
***********************************************************************/
-int Msat_SolverReadVarNum( Msat_Solver_t * p ) { return p->nVars; }
-int Msat_SolverReadVarAllocNum( Msat_Solver_t * p ) { return p->nVarsAlloc;}
+int Msat_SolverReadVarNum( Msat_Solver_t * p ) { return p->nVars; }
+int Msat_SolverReadClauseNum( Msat_Solver_t * p ) { return p->nClauses; }
+int Msat_SolverReadVarAllocNum( Msat_Solver_t * p ) { return p->nVarsAlloc; }
int Msat_SolverReadDecisionLevel( Msat_Solver_t * p ) { return Msat_IntVecReadSize(p->vTrailLim); }
-int * Msat_SolverReadDecisionLevelArray( Msat_Solver_t * p ) { return p->pLevel; }
-Msat_Clause_t ** Msat_SolverReadReasonArray( Msat_Solver_t * p ) { return p->pReasons; }
+int * Msat_SolverReadDecisionLevelArray( Msat_Solver_t * p ) { return p->pLevel; }
+Msat_Clause_t ** Msat_SolverReadReasonArray( Msat_Solver_t * p ) { return p->pReasons; }
Msat_Lit_t Msat_SolverReadVarValue( Msat_Solver_t * p, Msat_Var_t Var ) { return p->pAssigns[Var]; }
-Msat_ClauseVec_t * Msat_SolverReadLearned( Msat_Solver_t * p ) { return p->vLearned; }
-Msat_ClauseVec_t ** Msat_SolverReadWatchedArray( Msat_Solver_t * p ) { return p->pvWatched; }
-int * Msat_SolverReadAssignsArray( Msat_Solver_t * p ) { return p->pAssigns; }
-int * Msat_SolverReadModelArray( Msat_Solver_t * p ) { return p->pModel; }
-int Msat_SolverReadBackTracks( Msat_Solver_t * p ) { return p->nBackTracks; }
-Msat_MmStep_t * Msat_SolverReadMem( Msat_Solver_t * p ) { return p->pMem; }
-int * Msat_SolverReadSeenArray( Msat_Solver_t * p ) { return p->pSeen; }
-int Msat_SolverIncrementSeenId( Msat_Solver_t * p ) { return ++p->nSeenId; }
+Msat_ClauseVec_t * Msat_SolverReadLearned( Msat_Solver_t * p ) { return p->vLearned; }
+Msat_ClauseVec_t ** Msat_SolverReadWatchedArray( Msat_Solver_t * p ) { return p->pvWatched; }
+int * Msat_SolverReadAssignsArray( Msat_Solver_t * p ) { return p->pAssigns; }
+int * Msat_SolverReadModelArray( Msat_Solver_t * p ) { return p->pModel; }
+int Msat_SolverReadBackTracks( Msat_Solver_t * p ) { return (int)p->Stats.nConflicts; }
+int Msat_SolverReadInspects( Msat_Solver_t * p ) { return (int)p->Stats.nInspects; }
+Msat_MmStep_t * Msat_SolverReadMem( Msat_Solver_t * p ) { return p->pMem; }
+int * Msat_SolverReadSeenArray( Msat_Solver_t * p ) { return p->pSeen; }
+int Msat_SolverIncrementSeenId( Msat_Solver_t * p ) { return ++p->nSeenId; }
void Msat_SolverSetVerbosity( Msat_Solver_t * p, int fVerbose ) { p->fVerbose = fVerbose; }
-void Msat_SolverClausesIncrement( Msat_Solver_t * p ) { p->nClausesAlloc++; }
-void Msat_SolverClausesDecrement( Msat_Solver_t * p ) { p->nClausesAlloc--; }
-void Msat_SolverClausesIncrementL( Msat_Solver_t * p ) { p->nClausesAllocL++; }
-void Msat_SolverClausesDecrementL( Msat_Solver_t * p ) { p->nClausesAllocL--; }
+void Msat_SolverClausesIncrement( Msat_Solver_t * p ) { p->nClausesAlloc++; }
+void Msat_SolverClausesDecrement( Msat_Solver_t * p ) { p->nClausesAlloc--; }
+void Msat_SolverClausesIncrementL( Msat_Solver_t * p ) { p->nClausesAllocL++; }
+void Msat_SolverClausesDecrementL( Msat_Solver_t * p ) { p->nClausesAllocL--; }
void Msat_SolverMarkLastClauseTypeA( Msat_Solver_t * p ) { Msat_ClauseSetTypeA( Msat_ClauseVecReadEntry( p->vClauses, Msat_ClauseVecReadSize(p->vClauses)-1 ), 1 ); }
void Msat_SolverMarkClausesStart( Msat_Solver_t * p ) { p->nClausesStart = Msat_ClauseVecReadSize(p->vClauses); }
+float * Msat_SolverReadFactors( Msat_Solver_t * p ) { return p->pFactors; }
/**Function*************************************************************
@@ -172,8 +175,12 @@ Msat_Solver_t * Msat_SolverAlloc( int nVarsAlloc,
p->dVarDecay = dVarDecay;
p->pdActivity = ALLOC( double, p->nVarsAlloc );
+ p->pFactors = ALLOC( float, p->nVarsAlloc );
for ( i = 0; i < p->nVarsAlloc; i++ )
- p->pdActivity[i] = 0;
+ {
+ p->pdActivity[i] = 0.0;
+ p->pFactors[i] = 1.0;
+ }
p->pAssigns = ALLOC( int, p->nVarsAlloc );
p->pModel = ALLOC( int, p->nVarsAlloc );
@@ -237,8 +244,12 @@ void Msat_SolverResize( Msat_Solver_t * p, int nVarsAlloc )
p->nVarsAlloc = nVarsAlloc;
p->pdActivity = REALLOC( double, p->pdActivity, p->nVarsAlloc );
+ p->pFactors = REALLOC( float, p->pFactors, p->nVarsAlloc );
for ( i = nVarsAllocOld; i < p->nVarsAlloc; i++ )
- p->pdActivity[i] = 0;
+ {
+ p->pdActivity[i] = 0.0;
+ p->pFactors[i] = 1.0;
+ }
p->pAssigns = REALLOC( int, p->pAssigns, p->nVarsAlloc );
p->pModel = REALLOC( int, p->pModel, p->nVarsAlloc );
@@ -392,6 +403,7 @@ void Msat_SolverFree( Msat_Solver_t * p )
Msat_ClauseVecFree( p->vLearned );
FREE( p->pdActivity );
+ FREE( p->pFactors );
Msat_OrderFree( p->pOrder );
for ( i = 0; i < 2 * p->nVarsAlloc; i++ )
diff --git a/src/sat/msat/msatSolverCore.c b/src/sat/msat/msatSolverCore.c
index b8d9f328..f9fee73c 100644
--- a/src/sat/msat/msatSolverCore.c
+++ b/src/sat/msat/msatSolverCore.c
@@ -25,7 +25,7 @@
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -39,10 +39,11 @@
SeeAlso []
***********************************************************************/
-bool Msat_SolverAddVar( Msat_Solver_t * p )
+bool Msat_SolverAddVar( Msat_Solver_t * p, int Level )
{
if ( p->nVars == p->nVarsAlloc )
Msat_SolverResize( p, 2 * p->nVarsAlloc );
+ p->pLevel[p->nVars] = Level;
p->nVars++;
return 1;
}
@@ -131,14 +132,18 @@ void Msat_SolverPrintStats( Msat_Solver_t * p )
SeeAlso []
***********************************************************************/
-bool Msat_SolverSolve( Msat_Solver_t * p, Msat_IntVec_t * vAssumps, int nBackTrackLimit )
+bool Msat_SolverSolve( Msat_Solver_t * p, Msat_IntVec_t * vAssumps, int nBackTrackLimit, int nTimeLimit )
{
Msat_SearchParams_t Params = { 0.95, 0.999 };
double nConflictsLimit, nLearnedLimit;
Msat_Type_t Status;
+ int timeStart = clock();
int64 nConflictsOld = p->Stats.nConflicts;
int64 nDecisionsOld = p->Stats.nDecisions;
+// p->pFreq = ALLOC( int, p->nVarsAlloc );
+// memset( p->pFreq, 0, sizeof(int) * p->nVarsAlloc );
+
if ( vAssumps )
{
int * pAssumps, nAssumps, i;
@@ -172,11 +177,31 @@ bool Msat_SolverSolve( Msat_Solver_t * p, Msat_IntVec_t * vAssumps, int nBackTra
nConflictsLimit *= 1.5;
nLearnedLimit *= 1.1;
// if the limit on the number of backtracks is given, quit the restart loop
- if ( nBackTrackLimit > 0 )
+ if ( nBackTrackLimit > 0 && (int)p->Stats.nConflicts - p->nBackTracks > nBackTrackLimit )
+ break;
+ // if the runtime limit is exceeded, quit the restart loop
+ if ( nTimeLimit > 0 && clock() - timeStart >= nTimeLimit * CLOCKS_PER_SEC )
break;
}
Msat_SolverCancelUntil( p, 0 );
p->nBackTracks = (int)p->Stats.nConflicts - p->nBackTracks;
+/*
+ PRT( "True solver runtime", clock() - timeStart );
+ // print the statistics
+ {
+ int i, Counter = 0;
+ for ( i = 0; i < p->nVars; i++ )
+ if ( p->pFreq[i] > 0 )
+ {
+ printf( "%d ", p->pFreq[i] );
+ Counter++;
+ }
+ if ( Counter )
+ printf( "\n" );
+ printf( "Total = %d. Used = %d. Decisions = %d. Imps = %d. Conflicts = %d. ", p->nVars, Counter, (int)p->Stats.nDecisions, (int)p->Stats.nPropagations, (int)p->Stats.nConflicts );
+ PRT( "Time", clock() - timeStart );
+ }
+*/
return Status;
}
diff --git a/src/sat/msat/msatSolverIo.c b/src/sat/msat/msatSolverIo.c
index f17595a7..05b7f6a9 100644
--- a/src/sat/msat/msatSolverIo.c
+++ b/src/sat/msat/msatSolverIo.c
@@ -27,7 +27,7 @@
static char * Msat_TimeStamp();
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/msat/msatSolverSearch.c b/src/sat/msat/msatSolverSearch.c
index 13a0c403..11a6540c 100644
--- a/src/sat/msat/msatSolverSearch.c
+++ b/src/sat/msat/msatSolverSearch.c
@@ -31,7 +31,7 @@ static void Msat_SolverAnalyze( Msat_Solver_t * p, Msat_Clause_t * pC
static void Msat_SolverReduceDB( Msat_Solver_t * p );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -534,12 +534,18 @@ Msat_Type_t Msat_SolverSearch( Msat_Solver_t * p, int nConfLimit, int nLearnedLi
Msat_Clause_t * pConf;
Msat_Var_t Var;
int nLevelBack, nConfs, nAssigns, Value;
+ int i;
assert( Msat_SolverReadDecisionLevel(p) == p->nLevelRoot );
p->Stats.nStarts++;
p->dVarDecay = 1 / pPars->dVarDecay;
p->dClaDecay = 1 / pPars->dClaDecay;
+ // reset the activities
+ for ( i = 0; i < p->nVars; i++ )
+ p->pdActivity[i] = (double)p->pFactors[i];
+// p->pdActivity[i] = 0.0;
+
nConfs = 0;
while ( 1 )
{
@@ -599,7 +605,7 @@ Msat_Type_t Msat_SolverSearch( Msat_Solver_t * p, int nConfLimit, int nLearnedLi
Msat_SolverCancelUntil( p, p->nLevelRoot );
return MSAT_UNKNOWN;
}
- else if ( nBackTrackLimit > 0 && nConfs > nBackTrackLimit ) {
+ else if ( nBackTrackLimit > 0 && (int)p->Stats.nConflicts - p->nBackTracks > nBackTrackLimit ) {
// Reached bound on number of conflicts:
Msat_QueueClear( p->pQueue );
Msat_SolverCancelUntil( p, p->nLevelRoot );
diff --git a/src/sat/msat/msatSort.c b/src/sat/msat/msatSort.c
index 2198d303..3b89d102 100644
--- a/src/sat/msat/msatSort.c
+++ b/src/sat/msat/msatSort.c
@@ -41,7 +41,7 @@ static int irand(double seed, int size) {
static void Msat_SolverSort( Msat_Clause_t ** array, int size, double seed );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/msat/msatVec.c b/src/sat/msat/msatVec.c
index 951969cf..75f53047 100644
--- a/src/sat/msat/msatVec.c
+++ b/src/sat/msat/msatVec.c
@@ -28,7 +28,7 @@ static int Msat_IntVecSortCompare1( int * pp1, int * pp2 );
static int Msat_IntVecSortCompare2( int * pp1, int * pp2 );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
diff --git a/src/sat/proof/pr.c b/src/sat/proof/pr.c
new file mode 100644
index 00000000..2d1ab2d1
--- /dev/null
+++ b/src/sat/proof/pr.c
@@ -0,0 +1,1263 @@
+/**CFile****************************************************************
+
+ FileName [pr.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [Proof recording.]
+
+ Synopsis [Core procedures of the package.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: pr.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <time.h>
+//#include "vec.h"
+#include "pr.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+typedef unsigned lit;
+
+typedef struct Pr_Cls_t_ Pr_Cls_t;
+struct Pr_Cls_t_
+{
+ unsigned uTruth; // interpolant
+ void * pProof; // the proof node
+// void * pAntis; // the anticedents
+ Pr_Cls_t * pNext; // the next clause
+ Pr_Cls_t * pNext0; // the next 0-watch
+ Pr_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
+};
+
+struct Pr_Man_t_
+{
+ // general data
+ int fProofWrite; // writes the proof file
+ int fProofVerif; // verifies the proof
+ int nVars; // the number of variables
+ int nVarsAB; // the number of global variables
+ int nRoots; // the number of root clauses
+ int nClauses; // the number of all clauses
+ int nClausesA; // the number of clauses of A
+ Pr_Cls_t * pHead; // the head clause
+ Pr_Cls_t * pTail; // the tail clause
+ Pr_Cls_t * pLearnt; // the tail clause
+ Pr_Cls_t * pEmpty; // the empty clause
+ // internal BCP
+ int nRootSize; // the number of root level assignments
+ int nTrailSize; // the number of assignments made
+ lit * pTrail; // chronological order of assignments (size nVars)
+ lit * pAssigns; // assignments by variable (size nVars)
+ char * pSeens; // temporary mark (size nVars)
+ char * pVarTypes; // variable type (size nVars) [1=A, 0=B, <0=AB]
+ Pr_Cls_t ** pReasons; // reasons for each assignment (size nVars)
+ Pr_Cls_t ** pWatches; // watched clauses for each literal (size 2*nVars)
+ int nVarsAlloc; // the allocated size of arrays
+ // proof recording
+ void * pManProof; // proof manager
+ int Counter; // counter of resolved clauses
+ // 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
+ // internal verification
+ lit * pResLits; // the literals of the resolvent
+ int nResLits; // the number of literals of the resolvent
+ int nResLitsAlloc;// the number of literals of the resolvent
+ // runtime stats
+ int timeBcp;
+ int timeTrace;
+ int timeRead;
+ int timeTotal;
+};
+
+#ifndef PRT
+#define PRT(a,t) printf("%s = ", (a)); printf("%6.2f sec\n", (float)(t)/(float)(CLOCKS_PER_SEC))
+#endif
+
+// variable assignments
+static const lit LIT_UNDEF = 0xffffffff;
+
+// 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 Pr_ManForEachClause( p, pCls ) for( pCls = p->pHead; pCls; pCls = pCls->pNext )
+#define Pr_ManForEachClauseRoot( p, pCls ) for( pCls = p->pHead; pCls != p->pLearnt; pCls = pCls->pNext )
+#define Pr_ManForEachClauseLearnt( p, pCls ) for( pCls = p->pLearnt; pCls; pCls = pCls->pNext )
+
+// static procedures
+static char * Pr_ManMemoryFetch( Pr_Man_t * p, int nBytes );
+static void Pr_ManMemoryStop( Pr_Man_t * p );
+static void Pr_ManResize( Pr_Man_t * p, int nVarsNew );
+
+// exported procedures
+extern Pr_Man_t * Pr_ManAlloc( int nVarsAlloc );
+extern void Pr_ManFree( Pr_Man_t * p );
+extern int Pr_ManAddClause( Pr_Man_t * p, lit * pBeg, lit * pEnd, int fRoot, int fClauseA );
+extern int Pr_ManProofWrite( Pr_Man_t * p );
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis [Allocate proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Pr_Man_t * Pr_ManAlloc( int nVarsAlloc )
+{
+ Pr_Man_t * p;
+ // allocate the manager
+ p = (Pr_Man_t *)malloc( sizeof(Pr_Man_t) );
+ memset( p, 0, sizeof(Pr_Man_t) );
+ // allocate internal arrays
+ Pr_ManResize( p, nVarsAlloc? nVarsAlloc : 256 );
+ // set the starting number of variables
+ p->nVars = 0;
+ // memory management
+ p->nChunkSize = (1<<16); // use 64K chunks
+ // verification
+ p->nResLitsAlloc = (1<<16);
+ p->pResLits = malloc( sizeof(lit) * p->nResLitsAlloc );
+ // parameters
+ p->fProofWrite = 0;
+ p->fProofVerif = 0;
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Resize proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Pr_ManResize( Pr_Man_t * p, int nVarsNew )
+{
+ // check if resizing is needed
+ if ( p->nVarsAlloc < nVarsNew )
+ {
+ int nVarsAllocOld = p->nVarsAlloc;
+ // find the new size
+ if ( p->nVarsAlloc == 0 )
+ p->nVarsAlloc = 1;
+ while ( p->nVarsAlloc < nVarsNew )
+ p->nVarsAlloc *= 2;
+ // resize the arrays
+ p->pTrail = (lit *) realloc( p->pTrail, sizeof(lit) * p->nVarsAlloc );
+ p->pAssigns = (lit *) realloc( p->pAssigns, sizeof(lit) * p->nVarsAlloc );
+ p->pSeens = (char *) realloc( p->pSeens, sizeof(char) * p->nVarsAlloc );
+ p->pVarTypes = (char *) realloc( p->pVarTypes, sizeof(char) * p->nVarsAlloc );
+ p->pReasons = (Pr_Cls_t **)realloc( p->pReasons, sizeof(Pr_Cls_t *) * p->nVarsAlloc );
+ p->pWatches = (Pr_Cls_t **)realloc( p->pWatches, sizeof(Pr_Cls_t *) * p->nVarsAlloc*2 );
+ // clean the free space
+ memset( p->pAssigns + nVarsAllocOld, 0xff, sizeof(lit) * (p->nVarsAlloc - nVarsAllocOld) );
+ memset( p->pSeens + nVarsAllocOld, 0, sizeof(char) * (p->nVarsAlloc - nVarsAllocOld) );
+ memset( p->pVarTypes + nVarsAllocOld, 0, sizeof(char) * (p->nVarsAlloc - nVarsAllocOld) );
+ memset( p->pReasons + nVarsAllocOld, 0, sizeof(Pr_Cls_t *) * (p->nVarsAlloc - nVarsAllocOld) );
+ memset( p->pWatches + nVarsAllocOld, 0, sizeof(Pr_Cls_t *) * (p->nVarsAlloc - nVarsAllocOld)*2 );
+ }
+ // adjust the number of variables
+ if ( p->nVars < nVarsNew )
+ p->nVars = nVarsNew;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Deallocate proof manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Pr_ManFree( Pr_Man_t * p )
+{
+ printf( "Runtime stats:\n" );
+PRT( "Reading ", p->timeRead );
+PRT( "BCP ", p->timeBcp );
+PRT( "Trace ", p->timeTrace );
+PRT( "TOTAL ", p->timeTotal );
+
+ Pr_ManMemoryStop( p );
+ free( p->pTrail );
+ free( p->pAssigns );
+ free( p->pSeens );
+ free( p->pVarTypes );
+ free( p->pReasons );
+ free( p->pWatches );
+ free( p->pResLits );
+ free( p );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Adds one clause to the watcher list.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Pr_ManWatchClause( Pr_Man_t * p, Pr_Cls_t * pClause, lit Lit )
+{
+ assert( lit_check(Lit, p->nVars) );
+ if ( pClause->pLits[0] == Lit )
+ pClause->pNext0 = p->pWatches[lit_neg(Lit)];
+ else
+ {
+ assert( pClause->pLits[1] == Lit );
+ pClause->pNext1 = p->pWatches[lit_neg(Lit)];
+ }
+ p->pWatches[lit_neg(Lit)] = pClause;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Adds one clause to the manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Pr_ManAddClause( Pr_Man_t * p, lit * pBeg, lit * pEnd, int fRoot, int fClauseA )
+{
+ Pr_Cls_t * pClause;
+ lit Lit, * i, * j;
+ int nSize, VarMax;
+
+ // process the literals
+ if ( pBeg < pEnd )
+ {
+ // insertion sort
+ VarMax = lit_var( *pBeg );
+ for ( i = pBeg + 1; i < pEnd; i++ )
+ {
+ Lit = *i;
+ VarMax = lit_var(Lit) > VarMax ? lit_var(Lit) : VarMax;
+ for ( j = i; j > pBeg && *(j-1) > Lit; j-- )
+ *j = *(j-1);
+ *j = Lit;
+ }
+ // make sure there is no duplicated variables
+ for ( i = pBeg + 1; i < pEnd; i++ )
+ assert( lit_var(*(i-1)) != lit_var(*i) );
+ // resize the manager
+ Pr_ManResize( p, VarMax+1 );
+ }
+
+ // get memory for the clause
+ nSize = sizeof(Pr_Cls_t) + sizeof(lit) * (pEnd - pBeg);
+ pClause = (Pr_Cls_t *)Pr_ManMemoryFetch( p, nSize );
+ memset( pClause, 0, sizeof(Pr_Cls_t) );
+
+ // assign the clause
+ assert( !fClauseA || fRoot ); // clause of A is always a root clause
+ p->nRoots += fRoot;
+ p->nClausesA += fClauseA;
+ pClause->Id = p->nClauses++;
+ pClause->fA = fClauseA;
+ pClause->fRoot = fRoot;
+ pClause->nLits = pEnd - pBeg;
+ memcpy( pClause->pLits, pBeg, sizeof(lit) * (pEnd - pBeg) );
+
+ // add the clause to the list
+ if ( p->pHead == NULL )
+ p->pHead = pClause;
+ if ( p->pTail == NULL )
+ p->pTail = pClause;
+ else
+ {
+ p->pTail->pNext = pClause;
+ p->pTail = pClause;
+ }
+
+ // mark the first learnt clause
+ if ( p->pLearnt == NULL && !pClause->fRoot )
+ p->pLearnt = pClause;
+
+ // add the empty clause
+ if ( pClause->nLits == 0 )
+ {
+ if ( p->pEmpty )
+ printf( "More than one empty clause!\n" );
+ p->pEmpty = pClause;
+ }
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Fetches memory.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+char * Pr_ManMemoryFetch( Pr_Man_t * p, int nBytes )
+{
+ char * pMem;
+ if ( p->pChunkLast == NULL || nBytes > p->nChunkSize - p->nChunkUsed )
+ {
+ pMem = (char *)malloc( p->nChunkSize );
+ *(char **)pMem = p->pChunkLast;
+ p->pChunkLast = pMem;
+ p->nChunkUsed = sizeof(char *);
+ }
+ pMem = p->pChunkLast + p->nChunkUsed;
+ p->nChunkUsed += nBytes;
+ return pMem;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Frees memory manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Pr_ManMemoryStop( Pr_Man_t * p )
+{
+ char * pMem, * pNext;
+ if ( p->pChunkLast == NULL )
+ return;
+ for ( pMem = p->pChunkLast; pNext = *(char **)pMem; pMem = pNext )
+ free( pMem );
+ free( pMem );
+}
+
+/**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.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Extra_PrintBinary_( FILE * pFile, unsigned Sign[], int nBits )
+{
+ int Remainder, nWords;
+ int w, i;
+
+ Remainder = (nBits%(sizeof(unsigned)*8));
+ nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
+
+ for ( w = nWords-1; w >= 0; w-- )
+ for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- )
+ fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Prints the interpolant for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Pr_ManPrintInterOne( Pr_Man_t * p, Pr_Cls_t * pClause )
+{
+ printf( "Clause %2d : ", pClause->Id );
+ Extra_PrintBinary_( stdout, &pClause->uTruth, (1 << p->nVarsAB) );
+ printf( "\n" );
+}
+
+
+
+/**Function*************************************************************
+
+ Synopsis [Records implication.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Pr_ManEnqueue( Pr_Man_t * p, lit Lit, Pr_Cls_t * pReason )
+{
+ int Var = lit_var(Lit);
+ if ( p->pAssigns[Var] != LIT_UNDEF )
+ return p->pAssigns[Var] == Lit;
+ p->pAssigns[Var] = Lit;
+ p->pReasons[Var] = pReason;
+ p->pTrail[p->nTrailSize++] = Lit;
+//printf( "assigning var %d value %d\n", Var, !lit_sign(Lit) );
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records implication.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline void Pr_ManCancelUntil( Pr_Man_t * p, int Level )
+{
+ lit Lit;
+ int i, Var;
+ for ( i = p->nTrailSize - 1; i >= Level; i-- )
+ {
+ Lit = p->pTrail[i];
+ Var = lit_var( Lit );
+ p->pReasons[Var] = NULL;
+ p->pAssigns[Var] = LIT_UNDEF;
+//printf( "cancelling var %d\n", Var );
+ }
+ p->nTrailSize = Level;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate one assignment.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline Pr_Cls_t * Pr_ManPropagateOne( Pr_Man_t * p, lit Lit )
+{
+ Pr_Cls_t ** ppPrev, * pCur, * pTemp;
+ lit LitF = lit_neg(Lit);
+ int i;
+ // iterate through the literals
+ ppPrev = p->pWatches + Lit;
+ for ( pCur = p->pWatches[Lit]; pCur; pCur = *ppPrev )
+ {
+ // make sure the false literal is in the second literal of the clause
+ if ( pCur->pLits[0] == LitF )
+ {
+ pCur->pLits[0] = pCur->pLits[1];
+ pCur->pLits[1] = LitF;
+ pTemp = pCur->pNext0;
+ pCur->pNext0 = pCur->pNext1;
+ pCur->pNext1 = pTemp;
+ }
+ assert( pCur->pLits[1] == LitF );
+
+ // if the first literal is true, the clause is satisfied
+ if ( pCur->pLits[0] == p->pAssigns[lit_var(pCur->pLits[0])] )
+ {
+ ppPrev = &pCur->pNext1;
+ continue;
+ }
+
+ // look for a new literal to watch
+ for ( i = 2; i < (int)pCur->nLits; i++ )
+ {
+ // skip the case when the literal is false
+ if ( lit_neg(pCur->pLits[i]) == p->pAssigns[lit_var(pCur->pLits[i])] )
+ continue;
+ // the literal is either true or unassigned - watch it
+ pCur->pLits[1] = pCur->pLits[i];
+ pCur->pLits[i] = LitF;
+ // remove this clause from the watch list of Lit
+ *ppPrev = pCur->pNext1;
+ // add this clause to the watch list of pCur->pLits[i] (now it is pCur->pLits[1])
+ Pr_ManWatchClause( p, pCur, pCur->pLits[1] );
+ break;
+ }
+ if ( i < (int)pCur->nLits ) // found new watch
+ continue;
+
+ // clause is unit - enqueue new implication
+ if ( Pr_ManEnqueue(p, pCur->pLits[0], pCur) )
+ {
+ ppPrev = &pCur->pNext1;
+ continue;
+ }
+
+ // conflict detected - return the conflict clause
+ return pCur;
+ }
+ return NULL;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate the current assignments.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Pr_Cls_t * Pr_ManPropagate( Pr_Man_t * p, int Start )
+{
+ Pr_Cls_t * pClause;
+ int i;
+ int clk = clock();
+ for ( i = Start; i < p->nTrailSize; i++ )
+ {
+ pClause = Pr_ManPropagateOne( p, p->pTrail[i] );
+ if ( pClause )
+ {
+p->timeBcp += clock() - clk;
+ return pClause;
+ }
+ }
+p->timeBcp += clock() - clk;
+ return NULL;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Prints the clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Pr_ManPrintClause( Pr_Cls_t * pClause )
+{
+ int i;
+ printf( "Clause ID = %d. Proof = %d. {", pClause->Id, (int)pClause->pProof );
+ for ( i = 0; i < (int)pClause->nLits; i++ )
+ printf( " %d", pClause->pLits[i] );
+ printf( " }\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Prints the resolvent.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Pr_ManPrintResolvent( lit * pResLits, int nResLits )
+{
+ int i;
+ printf( "Resolvent: {" );
+ for ( i = 0; i < nResLits; i++ )
+ printf( " %d", pResLits[i] );
+ printf( " }\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Writes one root clause into a file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Pr_ManProofWriteOne( Pr_Man_t * p, Pr_Cls_t * pClause )
+{
+ pClause->pProof = (void *)++p->Counter;
+
+ if ( p->fProofWrite )
+ {
+ int v;
+ fprintf( p->pManProof, "%d", (int)pClause->pProof );
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ fprintf( p->pManProof, " %d", lit_print(pClause->pLits[v]) );
+ fprintf( p->pManProof, " 0 0\n" );
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Traces the proof for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Pr_ManProofTraceOne( Pr_Man_t * p, Pr_Cls_t * pConflict, Pr_Cls_t * pFinal )
+{
+ Pr_Cls_t * pReason;
+ int i, v, Var, PrevId;
+ int fPrint = 0;
+ int clk = clock();
+
+ // collect resolvent literals
+ if ( p->fProofVerif )
+ {
+ assert( (int)pConflict->nLits <= p->nResLitsAlloc );
+ memcpy( p->pResLits, pConflict->pLits, sizeof(lit) * pConflict->nLits );
+ p->nResLits = pConflict->nLits;
+ }
+
+ // mark all the variables in the conflict as seen
+ for ( v = 0; v < (int)pConflict->nLits; v++ )
+ p->pSeens[lit_var(pConflict->pLits[v])] = 1;
+
+ // start the anticedents
+// pFinal->pAntis = Vec_PtrAlloc( 32 );
+// Vec_PtrPush( pFinal->pAntis, pConflict );
+
+ if ( p->nClausesA )
+ pFinal->uTruth = pConflict->uTruth;
+
+ // follow the trail backwards
+ PrevId = (int)pConflict->pProof;
+ for ( i = p->nTrailSize - 1; i >= 0; i-- )
+ {
+ // skip literals that are not involved
+ Var = lit_var(p->pTrail[i]);
+ if ( !p->pSeens[Var] )
+ continue;
+ p->pSeens[Var] = 0;
+
+ // skip literals of the resulting clause
+ pReason = p->pReasons[Var];
+ if ( pReason == NULL )
+ continue;
+ 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
+ assert( pReason->pProof > 0 );
+ p->Counter++;
+ if ( p->fProofWrite )
+ fprintf( p->pManProof, "%d * %d %d 0\n", p->Counter, PrevId, (int)pReason->pProof );
+ PrevId = p->Counter;
+
+ if ( p->nClausesA )
+ {
+ if ( p->pVarTypes[Var] == 1 ) // var of A
+ pFinal->uTruth |= pReason->uTruth;
+ else
+ pFinal->uTruth &= pReason->uTruth;
+ }
+
+ // resolve the temporary resolvent with the reason clause
+ if ( p->fProofVerif )
+ {
+ int v1, v2;
+ if ( fPrint )
+ Pr_ManPrintResolvent( p->pResLits, p->nResLits );
+ // check that the var is present in the resolvent
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ if ( lit_var(p->pResLits[v1]) == Var )
+ break;
+ if ( v1 == p->nResLits )
+ printf( "Recording clause %d: Cannot find variable %d in the temporary resolvent.\n", pFinal->Id, Var );
+ if ( p->pResLits[v1] != lit_neg(pReason->pLits[0]) )
+ printf( "Recording clause %d: The resolved variable %d is in the wrong polarity.\n", pFinal->Id, Var );
+ // remove this variable from the resolvent
+ assert( lit_var(p->pResLits[v1]) == Var );
+ p->nResLits--;
+ for ( ; v1 < p->nResLits; v1++ )
+ p->pResLits[v1] = p->pResLits[v1+1];
+ // add variables of the reason clause
+ for ( v2 = 1; v2 < (int)pReason->nLits; v2++ )
+ {
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ if ( lit_var(p->pResLits[v1]) == lit_var(pReason->pLits[v2]) )
+ break;
+ // if it is a new variable, add it to the resolvent
+ if ( v1 == p->nResLits )
+ {
+ if ( p->nResLits == p->nResLitsAlloc )
+ printf( "Recording clause %d: Ran out of space for intermediate resolvent.\n, pFinal->Id" );
+ p->pResLits[ p->nResLits++ ] = pReason->pLits[v2];
+ continue;
+ }
+ // if the variable is the same, the literal should be the same too
+ if ( p->pResLits[v1] == pReason->pLits[v2] )
+ continue;
+ // the literal is different
+ printf( "Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->Id );
+ }
+ }
+
+// Vec_PtrPush( pFinal->pAntis, pReason );
+ }
+
+ // unmark all seen variables
+// for ( i = p->nTrailSize - 1; i >= 0; i-- )
+// 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
+ if ( p->fProofVerif )
+ {
+ int v1, v2;
+ if ( fPrint )
+ Pr_ManPrintResolvent( p->pResLits, p->nResLits );
+ for ( v1 = 0; v1 < p->nResLits; v1++ )
+ {
+ for ( v2 = 0; v2 < (int)pFinal->nLits; v2++ )
+ if ( pFinal->pLits[v2] == p->pResLits[v1] )
+ break;
+ if ( v2 < (int)pFinal->nLits )
+ continue;
+ break;
+ }
+ if ( v1 < p->nResLits )
+ {
+ printf( "Recording clause %d: The final resolvent is wrong.\n", pFinal->Id );
+ Pr_ManPrintClause( pConflict );
+ Pr_ManPrintResolvent( p->pResLits, p->nResLits );
+ Pr_ManPrintClause( pFinal );
+ }
+ }
+p->timeTrace += clock() - clk;
+
+ // return the proof pointer
+ if ( p->nClausesA )
+ {
+ Pr_ManPrintInterOne( p, pFinal );
+ }
+ return p->Counter;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof for one clause.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Pr_ManProofRecordOne( Pr_Man_t * p, Pr_Cls_t * pClause )
+{
+ Pr_Cls_t * pConflict;
+ int i;
+
+ // empty clause never ends up there
+ assert( pClause->nLits > 0 );
+ if ( pClause->nLits == 0 )
+ printf( "Error: Empty clause is attempted.\n" );
+
+ // add assumptions to the trail
+ assert( !pClause->fRoot );
+ assert( p->nTrailSize == p->nRootSize );
+ for ( i = 0; i < (int)pClause->nLits; i++ )
+ if ( !Pr_ManEnqueue( p, lit_neg(pClause->pLits[i]), NULL ) )
+ {
+ assert( 0 ); // impossible
+ return 0;
+ }
+
+ // propagate the assumptions
+ pConflict = Pr_ManPropagate( p, p->nRootSize );
+ if ( pConflict == NULL )
+ {
+ assert( 0 ); // cannot prove
+ return 0;
+ }
+
+ // construct the proof
+ pClause->pProof = (void *)Pr_ManProofTraceOne( p, pConflict, pClause );
+
+ // undo to the root level
+ Pr_ManCancelUntil( p, p->nRootSize );
+
+ // add large clauses to the watched lists
+ if ( pClause->nLits > 1 )
+ {
+ Pr_ManWatchClause( p, pClause, pClause->pLits[0] );
+ Pr_ManWatchClause( p, pClause, pClause->pLits[1] );
+ return 1;
+ }
+ assert( pClause->nLits == 1 );
+
+ // if the clause proved is unit, add it and propagate
+ if ( !Pr_ManEnqueue( p, pClause->pLits[0], pClause ) )
+ {
+ assert( 0 ); // impossible
+ return 0;
+ }
+
+ // propagate the assumption
+ pConflict = Pr_ManPropagate( p, p->nRootSize );
+ if ( pConflict )
+ {
+ // construct the proof
+ p->pEmpty->pProof = (void *)Pr_ManProofTraceOne( p, pConflict, p->pEmpty );
+ printf( "Found last conflict after adding unit clause number %d!\n", pClause->Id );
+ return 0;
+ }
+
+ // update the root level
+ p->nRootSize = p->nTrailSize;
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Propagate the root clauses.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Pr_ManProcessRoots( Pr_Man_t * p )
+{
+ Pr_Cls_t * pClause;
+ int Counter;
+
+ // make sure the root clauses are preceeding the learnt clauses
+ Counter = 0;
+ Pr_ManForEachClause( p, pClause )
+ {
+ assert( (int)pClause->fA == (Counter < (int)p->nClausesA) );
+ assert( (int)pClause->fRoot == (Counter < (int)p->nRoots) );
+ Counter++;
+ }
+ assert( p->nClauses == Counter );
+
+ // make sure the last clause if empty
+ assert( p->pTail->nLits == 0 );
+
+ // go through the root unit clauses
+ p->nTrailSize = 0;
+ 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
+ if ( pClause->nLits != 1 )
+ continue;
+ // unit clause
+ assert( lit_check(pClause->pLits[0], p->nVars) );
+ if ( !Pr_ManEnqueue( p, pClause->pLits[0], pClause ) )
+ {
+ // detected root level conflict
+ printf( "Pr_ManProcessRoots(): Detected a root-level conflict\n" );
+ assert( 0 );
+ return 0;
+ }
+ }
+
+ // propagate the root unit clauses
+ pClause = Pr_ManPropagate( p, 0 );
+ if ( pClause )
+ {
+ // detected root level conflict
+ printf( "Pr_ManProcessRoots(): Detected a root-level conflict\n" );
+ assert( 0 );
+ return 0;
+ }
+
+ // set the root level
+ p->nRootSize = p->nTrailSize;
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Pr_ManPrepareInter( Pr_Man_t * p )
+{
+ unsigned uTruths[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
+ Pr_Cls_t * pClause;
+ int Var, v;
+
+ // mark the variable encountered in the clauses of A
+ Pr_ManForEachClauseRoot( p, pClause )
+ {
+ if ( !pClause->fA )
+ break;
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ p->pVarTypes[lit_var(pClause->pLits[v])] = 1;
+ }
+
+ // check variables that appear in clauses of B
+ p->nVarsAB = 0;
+ Pr_ManForEachClauseRoot( p, pClause )
+ {
+ if ( pClause->fA )
+ continue;
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ {
+ Var = lit_var(pClause->pLits[v]);
+ if ( p->pVarTypes[Var] == 1 ) // var of A
+ {
+ // change it into a global variable
+ p->nVarsAB++;
+ p->pVarTypes[Var] = -1;
+ }
+ }
+ }
+
+ // order global variables
+ p->nVarsAB = 0;
+ for ( v = 0; v < p->nVars; v++ )
+ if ( p->pVarTypes[v] == -1 )
+ p->pVarTypes[v] -= p->nVarsAB++;
+printf( "There are %d global variables.\n", p->nVarsAB );
+
+ // set interpolants for root clauses
+ Pr_ManForEachClauseRoot( p, pClause )
+ {
+ if ( !pClause->fA ) // clause of B
+ {
+ pClause->uTruth = ~0;
+ Pr_ManPrintInterOne( p, pClause );
+ continue;
+ }
+ // clause of A
+ pClause->uTruth = 0;
+ for ( v = 0; v < (int)pClause->nLits; v++ )
+ {
+ Var = lit_var(pClause->pLits[v]);
+ if ( p->pVarTypes[Var] < 0 ) // global var
+ {
+ if ( lit_sign(pClause->pLits[v]) ) // negative var
+ pClause->uTruth |= ~uTruths[ -p->pVarTypes[Var]-1 ];
+ else
+ pClause->uTruth |= uTruths[ -p->pVarTypes[Var]-1 ];
+ }
+ }
+ Pr_ManPrintInterOne( p, pClause );
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Pr_ManProofWrite( Pr_Man_t * p )
+{
+ Pr_Cls_t * pClause;
+ int RetValue = 1;
+
+ // propagate root level assignments
+ Pr_ManProcessRoots( p );
+
+ // prepare the interpolant computation
+ if ( p->nClausesA )
+ Pr_ManPrepareInter( p );
+
+ // construct proof for each clause
+ // start the proof
+ if ( p->fProofWrite )
+ p->pManProof = fopen( "proof.cnf_", "w" );
+ p->Counter = 0;
+
+ // write the root clauses
+ Pr_ManForEachClauseRoot( p, pClause )
+ Pr_ManProofWriteOne( p, pClause );
+
+ // consider each learned clause
+ Pr_ManForEachClauseLearnt( p, pClause )
+ {
+ if ( !Pr_ManProofRecordOne( p, pClause ) )
+ {
+ RetValue = 0;
+ break;
+ }
+ }
+
+ if ( p->nClausesA )
+ {
+ printf( "Interpolant: " );
+ }
+
+
+ // stop the proof
+ if ( p->fProofWrite )
+ {
+ fclose( p->pManProof );
+ p->pManProof = NULL;
+ }
+ return RetValue;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Reads clauses from file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Pr_Man_t * Pr_ManProofRead( char * pFileName )
+{
+ Pr_Man_t * p = NULL;
+ char * pCur, * pBuffer = NULL;
+ int * pArray = NULL;
+ FILE * pFile;
+ int RetValue, Counter, nNumbers, Temp;
+ int nClauses, nClausesA, nRoots, nVars;
+
+ // open the file
+ pFile = fopen( pFileName, "r" );
+ if ( pFile == NULL )
+ {
+ printf( "Count not open input file \"%s\".\n", pFileName );
+ return NULL;
+ }
+
+ // read the file
+ pBuffer = (char *)malloc( (1<<16) );
+ for ( Counter = 0; fgets( pBuffer, (1<<16), pFile ); )
+ {
+ if ( pBuffer[0] == 'c' )
+ continue;
+ if ( pBuffer[0] == 'p' )
+ {
+ assert( p == NULL );
+ nClausesA = 0;
+ RetValue = sscanf( pBuffer + 1, "%d %d %d %d", &nVars, &nClauses, &nRoots, &nClausesA );
+ if ( RetValue != 3 && RetValue != 4 )
+ {
+ printf( "Wrong input file format.\n" );
+ }
+ p = Pr_ManAlloc( nVars );
+ pArray = (int *)malloc( sizeof(int) * (nVars + 10) );
+ continue;
+ }
+ // skip empty lines
+ for ( pCur = pBuffer; *pCur; pCur++ )
+ if ( !(*pCur == ' ' || *pCur == '\t' || *pCur == '\r' || *pCur == '\n') )
+ break;
+ if ( *pCur == 0 )
+ continue;
+ // scan the numbers from file
+ nNumbers = 0;
+ pCur = pBuffer;
+ while ( *pCur )
+ {
+ // skip spaces
+ for ( ; *pCur && *pCur == ' '; pCur++ );
+ // read next number
+ Temp = 0;
+ sscanf( pCur, "%d", &Temp );
+ if ( Temp == 0 )
+ break;
+ pArray[ nNumbers++ ] = lit_read( Temp );
+ // skip non-spaces
+ for ( ; *pCur && *pCur != ' '; pCur++ );
+ }
+ // add the clause
+ if ( !Pr_ManAddClause( p, pArray, pArray + nNumbers, Counter < nRoots, Counter < nClausesA ) )
+ {
+ printf( "Bad clause number %d.\n", Counter );
+ return NULL;
+ }
+ // count the clauses
+ Counter++;
+ }
+ // check the number of clauses
+ if ( Counter != nClauses )
+ printf( "Expected %d clauses but read %d.\n", nClauses, Counter );
+
+ // finish
+ if ( pArray ) free( pArray );
+ if ( pBuffer ) free( pBuffer );
+ fclose( pFile );
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+/*
+int Pr_ManProofCount_rec( Pr_Cls_t * pClause )
+{
+ Pr_Cls_t * pNext;
+ int i, Counter;
+ if ( pClause->fRoot )
+ return 0;
+ if ( pClause->fVisit )
+ return 0;
+ pClause->fVisit = 1;
+ // count the number of visited clauses
+ Counter = 1;
+ Vec_PtrForEachEntry( pClause->pAntis, pNext, i )
+ Counter += Pr_ManProofCount_rec( pNext );
+ return Counter;
+}
+*/
+
+/**Function*************************************************************
+
+ Synopsis [Records the proof.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Pr_ManProofTest( char * pFileName )
+{
+ Pr_Man_t * p;
+ int clk, clkTotal = clock();
+
+clk = clock();
+ p = Pr_ManProofRead( pFileName );
+p->timeRead = clock() - clk;
+ if ( p == NULL )
+ return 0;
+
+ Pr_ManProofWrite( p );
+
+ // print stats
+/*
+ nUsed = Pr_ManProofCount_rec( p->pEmpty );
+ printf( "Roots = %d. Learned = %d. Total = %d. Steps = %d. Ave = %.2f. Used = %d. Ratio = %.2f. \n",
+ p->nRoots, p->nClauses-p->nRoots, p->nClauses, p->Counter,
+ 1.0*(p->Counter-p->nRoots)/(p->nClauses-p->nRoots),
+ nUsed, 1.0*nUsed/(p->nClauses-p->nRoots) );
+*/
+ 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,
+ 1.0*(p->Counter-p->nRoots)/(p->nClauses-p->nRoots),
+ 1.0*Pr_ManMemoryReport(p)/(1<<20) );
+
+p->timeTotal = clock() - clkTotal;
+ Pr_ManFree( p );
+ return 1;
+}
+
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/sat/proof/pr.h b/src/sat/proof/pr.h
new file mode 100644
index 00000000..1e71a2d3
--- /dev/null
+++ b/src/sat/proof/pr.h
@@ -0,0 +1,65 @@
+/**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__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef _WIN32
+#define inline __inline // compatible with MS VS 6.0
+#endif
+
+////////////////////////////////////////////////////////////////////////
+/// INCLUDES ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// PARAMETERS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// BASIC TYPES ///
+////////////////////////////////////////////////////////////////////////
+
+typedef struct Pr_Man_t_ Pr_Man_t;
+
+////////////////////////////////////////////////////////////////////////
+/// MACRO DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/*=== pr.c ==========================================================*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
diff --git a/src/sat/proof/stats.txt b/src/sat/proof/stats.txt
new file mode 100644
index 00000000..470b1630
--- /dev/null
+++ b/src/sat/proof/stats.txt
@@ -0,0 +1,66 @@
+UC Berkeley, ABC 1.01 (compiled Jan 20 2007 16:47:34)
+abc.rc: No such file or directory
+Loaded "abc.rc" from the parent directory.
+abc 01> test
+Found last conflict after adding unit clause number 10229!
+Roots = 7184. Learned = 3047. Total = 10231. Steps = 196361. Ave = 62.09. Used = 2224. Ratio = 0.73.
+Runtime stats:
+Reading = 0.03 sec
+BCP = 0.32 sec
+Trace = 0.06 sec
+TOTAL = 0.43 sec
+abc 01> test
+Found last conflict after adding unit clause number 7676!
+Roots = 6605. Learned = 1073. Total = 7678. Steps = 52402. Ave = 42.68. Used = 1011. Ratio = 0.94.
+Runtime stats:
+Reading = 0.01 sec
+BCP = 0.02 sec
+Trace = 0.02 sec
+TOTAL = 0.06 sec
+abc 01> test
+Found last conflict after adding unit clause number 37868!
+Roots = 15443. Learned = 22427. Total = 37870. Steps = 2365472. Ave = 104.79. Used = 19763. Ratio = 0.88.
+Runtime stats:
+Reading = 0.20 sec
+BCP = 14.67 sec
+Trace = 0.56 sec
+TOTAL = 15.74 sec
+abc 01>
+
+
+abc 05> wb ibm_bmc/len25u_renc.blif
+abc 05> ps
+(no name) : i/o = 348/ 1 lat = 0 nd = 3648 bdd = 15522 lev = 246
+abc 05> sat -v
+==================================[MINISAT]===================================
+| Conflicts | ORIGINAL | LEARNT | Progress |
+| | Clauses Literals | Limit Clauses Literals Lit/Cl | |
+==============================================================================
+| 0 | 17413 54996 | 5804 0 0 0.0 | 0.000 % |
+| 100 | 17413 54996 | 6384 100 606 6.1 | 0.417 % |
+| 250 | 17413 54996 | 7023 250 1586 6.3 | 0.417 % |
+| 476 | 17413 54996 | 7725 476 3288 6.9 | 0.417 % |
+| 813 | 17413 54996 | 8498 813 7586 9.3 | 0.417 % |
+| 1319 | 17403 54970 | 9347 1318 14848 11.3 | 0.442 % |
+| 2078 | 17403 54970 | 10282 2076 40186 19.4 | 0.466 % |
+| 3217 | 17397 54948 | 11310 3208 99402 31.0 | 0.466 % |
+| 4926 | 17392 54930 | 12441 4911 131848 26.8 | 0.491 % |
+| 7489 | 17392 54930 | 13686 7474 204217 27.3 | 0.491 % |
+| 11336 | 17357 54829 | 15054 11310 332863 29.4 | 0.638 % |
+| 17103 | 17346 54794 | 16559 9130 203029 22.2 | 0.687 % |
+| 25752 | 17288 54606 | 18215 9083 176982 19.5 | 0.834 % |
+| 38727 | 17266 54536 | 20037 12674 278949 22.0 | 0.883 % |
+| 58188 | 17240 54453 | 22041 11905 255255 21.4 | 0.957 % |
+==============================================================================
+Start = 15. Conf = 79435. Dec = 130967. Prop = 24083434. Insp = 136774586.
+Total runtime = 18.66 sec. Var select = 0.00 sec. Var update = 0.00 sec.
+UNSATISFIABLE Time = 18.69 sec
+abc 05>
+abc 05> test
+Found last conflict after adding unit clause number 96902!
+Roots = 17469. Learned = 79435. Total = 96904. Steps = 9700042. Ave = 121.89. Used = 57072. Ratio = 0.72.
+Runtime stats:
+Reading = 1.26 sec
+BCP = 204.99 sec
+Trace = 2.85 sec
+TOTAL = 209.85 sec \ No newline at end of file