summaryrefslogtreecommitdiffstats
path: root/src/sat
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2021-11-12 12:31:29 +0100
committerMiodrag Milanovic <mmicko@gmail.com>2021-11-12 12:31:29 +0100
commitd2d6bbd9f86f61fc9b5cc7d703e1386bbd6ad6a2 (patch)
tree071fb2118c158c748ff9969ef250affe7b9a3561 /src/sat
parent4f5f73d18b137930fb3048c0b385c82fa078db38 (diff)
parent9b245d9f6910c048e9bbcf95ee5dee46f2f24f2c (diff)
downloadabc-d2d6bbd9f86f61fc9b5cc7d703e1386bbd6ad6a2.tar.gz
abc-d2d6bbd9f86f61fc9b5cc7d703e1386bbd6ad6a2.tar.bz2
abc-d2d6bbd9f86f61fc9b5cc7d703e1386bbd6ad6a2.zip
Merge remote-tracking branch 'upstream/master' into yosys-experimental
Diffstat (limited to 'src/sat')
-rw-r--r--src/sat/bsat/satSolver.h18
-rw-r--r--src/sat/glucose/AbcGlucose.cpp170
-rw-r--r--src/sat/glucose/AbcGlucose.h8
-rw-r--r--src/sat/glucose/Glucose.cpp2
-rw-r--r--src/sat/glucose/Solver.h12
-rw-r--r--src/sat/glucose/SolverTypes.h12
-rw-r--r--src/sat/glucose/Vec.h3
-rw-r--r--src/sat/glucose/stdint.h1628
-rw-r--r--src/sat/glucose2/AbcGlucose2.cpp1543
-rw-r--r--src/sat/glucose2/AbcGlucose2.h118
-rw-r--r--src/sat/glucose2/AbcGlucoseCmd2.cpp149
-rw-r--r--src/sat/glucose2/Alg.h88
-rw-r--r--src/sat/glucose2/Alloc.h136
-rw-r--r--src/sat/glucose2/BoundedQueue.h114
-rw-r--r--src/sat/glucose2/CGlucose.h7
-rw-r--r--src/sat/glucose2/CGlucoseCore.h620
-rw-r--r--src/sat/glucose2/Constants.h33
-rw-r--r--src/sat/glucose2/Dimacs.h93
-rw-r--r--src/sat/glucose2/Glucose2.cpp1749
-rw-r--r--src/sat/glucose2/Heap.h163
-rw-r--r--src/sat/glucose2/Heap2.h169
-rw-r--r--src/sat/glucose2/IntTypes.h49
-rw-r--r--src/sat/glucose2/Map.h197
-rw-r--r--src/sat/glucose2/Options.h392
-rw-r--r--src/sat/glucose2/Options2.cpp95
-rw-r--r--src/sat/glucose2/ParseUtils.h155
-rw-r--r--src/sat/glucose2/Queue.h73
-rw-r--r--src/sat/glucose2/SimpSolver.h230
-rw-r--r--src/sat/glucose2/SimpSolver2.cpp781
-rw-r--r--src/sat/glucose2/Solver.h653
-rw-r--r--src/sat/glucose2/SolverTypes.h450
-rw-r--r--src/sat/glucose2/Sort.h101
-rw-r--r--src/sat/glucose2/System.h73
-rw-r--r--src/sat/glucose2/System2.cpp116
-rw-r--r--src/sat/glucose2/Vec.h152
-rw-r--r--src/sat/glucose2/XAlloc.h53
-rw-r--r--src/sat/glucose2/license32
-rw-r--r--src/sat/glucose2/module.make6
-rw-r--r--src/sat/glucose2/pstdint.h919
-rw-r--r--src/sat/satoko/utils/sdbl.h4
40 files changed, 9729 insertions, 1637 deletions
diff --git a/src/sat/bsat/satSolver.h b/src/sat/bsat/satSolver.h
index f4126567..53f3ebe2 100644
--- a/src/sat/bsat/satSolver.h
+++ b/src/sat/bsat/satSolver.h
@@ -292,6 +292,24 @@ static inline int sat_solver_final(sat_solver* s, int ** ppArray)
return s->conf_final.size;
}
+static inline void sat_solver_randomize( sat_solver * pSat, int iVar, int nVars )
+{
+ int i, nPols = 0, * pVars = ABC_ALLOC( int, nVars );
+ for ( i = 0; i < nVars; i++ )
+ if ( Abc_Random(0) & 1 )
+ pVars[nPols++] = iVar + i;
+ sat_solver_set_polarity( pSat, pVars, nPols );
+ for ( i = 0; i < nVars; i++ )
+ pVars[i] = iVar + i;
+ for ( i = 0; i < nVars; i++ )
+ {
+ int j = Abc_Random(0) % nVars;
+ ABC_SWAP( int, pVars[i], pVars[j] );
+ }
+ sat_solver_set_var_activity( pSat, pVars, nVars );
+ ABC_FREE( pVars );
+}
+
static inline abctime sat_solver_set_runtime_limit(sat_solver* s, abctime Limit)
{
abctime nRuntimeLimit = s->nRuntimeLimit;
diff --git a/src/sat/glucose/AbcGlucose.cpp b/src/sat/glucose/AbcGlucose.cpp
index 247bc89a..ad595ab9 100644
--- a/src/sat/glucose/AbcGlucose.cpp
+++ b/src/sat/glucose/AbcGlucose.cpp
@@ -58,7 +58,7 @@ using namespace Gluco;
SeeAlso []
***********************************************************************/
-Gluco::SimpSolver * glucose_solver_start()
+SimpSolver * glucose_solver_start()
{
SimpSolver * S = new SimpSolver;
S->setIncrementalMode();
@@ -116,6 +116,11 @@ int glucose_solver_addvar(Gluco::SimpSolver* S)
return S->nVars() - 1;
}
+int * glucose_solver_read_cex(Gluco::SimpSolver* S )
+{
+ return S->getCex();
+}
+
int glucose_solver_read_cex_varvalue(Gluco::SimpSolver* S, int ivar)
{
return S->model[ivar] == l_True;
@@ -208,6 +213,10 @@ int bmcg_sat_solver_elim_varnum(bmcg_sat_solver* s)
return ((Gluco::SimpSolver*)s)->eliminated_vars;
}
+int * bmcg_sat_solver_read_cex(bmcg_sat_solver* s)
+{
+ return glucose_solver_read_cex((Gluco::SimpSolver*)s);
+}
int bmcg_sat_solver_read_cex_varvalue(bmcg_sat_solver* s, int ivar)
{
return glucose_solver_read_cex_varvalue((Gluco::SimpSolver*)s, ivar);
@@ -317,6 +326,64 @@ int bmcg_sat_solver_add_and( bmcg_sat_solver * s, int iVar, int iVar0, int iVar1
return 1;
}
+int bmcg_solver_add_xor( bmcg_sat_solver * pSat, int iVarA, int iVarB, int iVarC, int fCompl )
+{
+ int Lits[3];
+ int Cid;
+ assert( iVarA >= 0 && iVarB >= 0 && iVarC >= 0 );
+
+ Lits[0] = Abc_Var2Lit( iVarA, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 1 );
+ Lits[2] = Abc_Var2Lit( iVarC, 1 );
+ Cid = bmcg_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 0 );
+ Lits[2] = Abc_Var2Lit( iVarC, 0 );
+ Cid = bmcg_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 1 );
+ Lits[2] = Abc_Var2Lit( iVarC, 0 );
+ Cid = bmcg_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 0 );
+ Lits[2] = Abc_Var2Lit( iVarC, 1 );
+ Cid = bmcg_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+ return 4;
+}
+
+int bmcg_sat_solver_jftr(bmcg_sat_solver* s)
+{
+ return ((Gluco::SimpSolver*)s)->jftr;
+}
+
+void bmcg_sat_solver_set_jftr(bmcg_sat_solver* s, int jftr)
+{
+ ((Gluco::SimpSolver*)s)->jftr = jftr;
+}
+
+void bmcg_sat_solver_set_var_fanin_lit(bmcg_sat_solver* s, int var, int lit0, int lit1)
+{
+ ((Gluco::SimpSolver*)s)->sat_solver_set_var_fanin_lit(var, lit0, lit1);
+}
+
+void bmcg_sat_solver_start_new_round(bmcg_sat_solver* s)
+{
+ ((Gluco::SimpSolver*)s)->sat_solver_start_new_round();
+}
+
+void bmcg_sat_solver_mark_cone(bmcg_sat_solver* s, int var)
+{
+ ((Gluco::SimpSolver*)s)->sat_solver_mark_cone(var);
+}
+
+
#else
/**Function*************************************************************
@@ -330,7 +397,7 @@ int bmcg_sat_solver_add_and( bmcg_sat_solver * s, int iVar, int iVar0, int iVar1
SeeAlso []
***********************************************************************/
-Gluco::Solver * glucose_solver_start()
+Solver * glucose_solver_start()
{
Solver * S = new Solver;
S->setIncrementalMode();
@@ -342,6 +409,11 @@ void glucose_solver_stop(Gluco::Solver* S)
delete S;
}
+void glucose_solver_reset(Gluco::Solver* S)
+{
+ S->reset();
+}
+
int glucose_solver_addclause(Gluco::Solver* S, int * plits, int nlits)
{
vec<Lit> lits;
@@ -383,6 +455,11 @@ int glucose_solver_addvar(Gluco::Solver* S)
return S->nVars() - 1;
}
+int * glucose_solver_read_cex(Gluco::Solver* S )
+{
+ return S->getCex();
+}
+
int glucose_solver_read_cex_varvalue(Gluco::Solver* S, int ivar)
{
return S->model[ivar] == l_True;
@@ -413,6 +490,10 @@ void bmcg_sat_solver_stop(bmcg_sat_solver* s)
{
glucose_solver_stop((Gluco::Solver*)s);
}
+void bmcg_sat_solver_reset(bmcg_sat_solver* s)
+{
+ glucose_solver_reset((Gluco::Solver*)s);
+}
int bmcg_sat_solver_addclause(bmcg_sat_solver* s, int * plits, int nlits)
{
@@ -470,6 +551,11 @@ int bmcg_sat_solver_elim_varnum(bmcg_sat_solver* s)
// return ((Gluco::SimpSolver*)s)->eliminated_vars;
}
+int * bmcg_sat_solver_read_cex(bmcg_sat_solver* s)
+{
+ return glucose_solver_read_cex((Gluco::Solver*)s);
+}
+
int bmcg_sat_solver_read_cex_varvalue(bmcg_sat_solver* s, int ivar)
{
return glucose_solver_read_cex_varvalue((Gluco::Solver*)s, ivar);
@@ -556,6 +642,86 @@ int bmcg_sat_solver_minimize_assumptions( bmcg_sat_solver * s, int * plits, int
return nresL + nresR;
}
+int bmcg_sat_solver_add_and( bmcg_sat_solver * s, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl )
+{
+ int Lits[3];
+
+ Lits[0] = Abc_Var2Lit( iVar, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVar0, fCompl0 );
+ if ( !bmcg_sat_solver_addclause( s, Lits, 2 ) )
+ return 0;
+
+ Lits[0] = Abc_Var2Lit( iVar, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVar1, fCompl1 );
+ if ( !bmcg_sat_solver_addclause( s, Lits, 2 ) )
+ return 0;
+
+ Lits[0] = Abc_Var2Lit( iVar, fCompl );
+ Lits[1] = Abc_Var2Lit( iVar0, !fCompl0 );
+ Lits[2] = Abc_Var2Lit( iVar1, !fCompl1 );
+ if ( !bmcg_sat_solver_addclause( s, Lits, 3 ) )
+ return 0;
+
+ return 1;
+}
+
+int bmcg_solver_add_xor( bmcg_sat_solver * pSat, int iVarA, int iVarB, int iVarC, int fCompl )
+{
+ int Lits[3];
+ int Cid;
+ assert( iVarA >= 0 && iVarB >= 0 && iVarC >= 0 );
+
+ Lits[0] = Abc_Var2Lit( iVarA, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 1 );
+ Lits[2] = Abc_Var2Lit( iVarC, 1 );
+ Cid = bmcg_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 0 );
+ Lits[2] = Abc_Var2Lit( iVarC, 0 );
+ Cid = bmcg_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 1 );
+ Lits[2] = Abc_Var2Lit( iVarC, 0 );
+ Cid = bmcg_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 0 );
+ Lits[2] = Abc_Var2Lit( iVarC, 1 );
+ Cid = bmcg_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+ return 4;
+}
+
+int bmcg_sat_solver_jftr(bmcg_sat_solver* s)
+{
+ return ((Gluco::Solver*)s)->jftr;
+}
+
+void bmcg_sat_solver_set_jftr(bmcg_sat_solver* s, int jftr)
+{
+ ((Gluco::Solver*)s)->jftr = jftr;
+}
+
+void bmcg_sat_solver_set_var_fanin_lit(bmcg_sat_solver* s, int var, int lit0, int lit1)
+{
+ ((Gluco::Solver*)s)->sat_solver_set_var_fanin_lit(var, lit0, lit1);
+}
+
+void bmcg_sat_solver_start_new_round(bmcg_sat_solver* s)
+{
+ ((Gluco::Solver*)s)->sat_solver_start_new_round();
+}
+
+void bmcg_sat_solver_mark_cone(bmcg_sat_solver* s, int var)
+{
+ ((Gluco::Solver*)s)->sat_solver_mark_cone(var);
+}
+
#endif
diff --git a/src/sat/glucose/AbcGlucose.h b/src/sat/glucose/AbcGlucose.h
index 4489adc7..89a3652f 100644
--- a/src/sat/glucose/AbcGlucose.h
+++ b/src/sat/glucose/AbcGlucose.h
@@ -83,6 +83,7 @@ extern int bmcg_sat_solver_eliminate( bmcg_sat_solver* s, int turn
extern int bmcg_sat_solver_var_is_elim( bmcg_sat_solver* s, int v );
extern void bmcg_sat_solver_var_set_frozen( bmcg_sat_solver* s, int v, int freeze );
extern int bmcg_sat_solver_elim_varnum(bmcg_sat_solver* s);
+extern int * bmcg_sat_solver_read_cex( bmcg_sat_solver* s );
extern int bmcg_sat_solver_read_cex_varvalue( bmcg_sat_solver* s, int );
extern void bmcg_sat_solver_set_stop( bmcg_sat_solver* s, int * pstop );
extern abctime bmcg_sat_solver_set_runtime_limit( bmcg_sat_solver* s, abctime Limit );
@@ -93,9 +94,16 @@ extern int bmcg_sat_solver_learntnum( bmcg_sat_solver* s );
extern int bmcg_sat_solver_conflictnum( bmcg_sat_solver* s );
extern int bmcg_sat_solver_minimize_assumptions( bmcg_sat_solver * s, int * plits, int nlits, int pivot );
extern int bmcg_sat_solver_add_and( bmcg_sat_solver * s, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl );
+extern int bmcg_sat_solver_add_xor( bmcg_sat_solver * s, int iVarA, int iVarB, int iVarC, int fCompl );
extern int bmcg_sat_solver_quantify( bmcg_sat_solver * s[], Gia_Man_t * p, int iLit, int fHash, int(*pFuncCiToKeep)(void *, int), void * pData, Vec_Int_t * vDLits );
extern int bmcg_sat_solver_equiv_overlap_check( bmcg_sat_solver * s, Gia_Man_t * p, int iLit0, int iLit1, int fEquiv );
extern Vec_Str_t * bmcg_sat_solver_sop( Gia_Man_t * p, int CubeLimit );
+extern int bmcg_sat_solver_jftr( bmcg_sat_solver * s );
+extern void bmcg_sat_solver_set_jftr( bmcg_sat_solver * s, int jftr );
+extern void bmcg_sat_solver_set_var_fanin_lit( bmcg_sat_solver * s, int var, int lit0, int lit1 );
+extern void bmcg_sat_solver_start_new_round( bmcg_sat_solver * s );
+extern void bmcg_sat_solver_mark_cone( bmcg_sat_solver * s, int var );
+
extern void Glucose_SolveCnf( char * pFilename, Glucose_Pars * pPars );
extern int Glucose_SolveAig( Gia_Man_t * p, Glucose_Pars * pPars );
diff --git a/src/sat/glucose/Glucose.cpp b/src/sat/glucose/Glucose.cpp
index 0f2d2fce..c975c6ca 100644
--- a/src/sat/glucose/Glucose.cpp
+++ b/src/sat/glucose/Glucose.cpp
@@ -609,7 +609,7 @@ void Solver::analyze(CRef confl, vec<Lit>& out_learnt,vec<Lit>&selectors, int& o
for(i = 0;i<selectors.size();i++)
out_learnt.push(selectors[i]);
- out_learnt.copyTo(analyze_toclear);
+ out_learnt.copyTo_(analyze_toclear);
if (ccmin_mode == 2){
uint32_t abstract_level = 0;
for (i = 1; i < out_learnt.size(); i++)
diff --git a/src/sat/glucose/Solver.h b/src/sat/glucose/Solver.h
index df72660a..3d7d26ea 100644
--- a/src/sat/glucose/Solver.h
+++ b/src/sat/glucose/Solver.h
@@ -64,6 +64,12 @@ public:
vec<int> user_vec;
vec<Lit> user_lits;
+ // circuit-based solving
+ int jftr;
+ void sat_solver_set_var_fanin_lit(int, int, int);
+ void sat_solver_start_new_round();
+ void sat_solver_mark_cone(int);
+
// Problem specification:
//
Var newVar (bool polarity = true, bool dvar = true); // Add a new variable with parameters specifying variable mode.
@@ -116,6 +122,7 @@ public:
int nLearnts () const; // The current number of learnt clauses.
int nVars () const; // The current number of variables.
int nFreeVars () const;
+ int * getCex () const;
// Incremental mode
void setIncrementalMode();
@@ -418,6 +425,7 @@ inline int Solver::nClauses () const { return clauses.size(); }
inline int Solver::nLearnts () const { return learnts.size(); }
inline int Solver::nVars () const { return vardata.size(); }
inline int Solver::nFreeVars () const { return (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]); }
+inline int * Solver::getCex () const { return NULL; }
inline void Solver::setPolarity (Var v, bool b) { polarity[v] = b; }
inline void Solver::setDecisionVar(Var v, bool b)
{
@@ -455,6 +463,10 @@ inline void Solver::toDimacs (const char* file, Lit p, Lit q, Lit r){ v
inline void Solver::addVar(Var v) { while (v >= nVars()) newVar(); }
+inline void Solver::sat_solver_set_var_fanin_lit(int var, int lit0, int lit1) {}
+inline void Solver::sat_solver_start_new_round() {}
+inline void Solver::sat_solver_mark_cone(int var) {}
+
//=================================================================================================
// Debug etc:
diff --git a/src/sat/glucose/SolverTypes.h b/src/sat/glucose/SolverTypes.h
index 4f2670a7..b29699fa 100644
--- a/src/sat/glucose/SolverTypes.h
+++ b/src/sat/glucose/SolverTypes.h
@@ -306,9 +306,15 @@ class OccLists
}
void clear(bool free = true){
- occs .clear(free);
- dirty .clear(free);
- dirties.clear(free);
+ if(free){
+ occs .clear(free);
+ dirty .clear(free);
+ dirties.clear(free);
+ } else {
+ occs .shrink_(occs .size());
+ dirty .shrink_(dirty .size());
+ dirties.shrink_(dirties.size());
+ }
}
};
diff --git a/src/sat/glucose/Vec.h b/src/sat/glucose/Vec.h
index da87af35..dd1bc20a 100644
--- a/src/sat/glucose/Vec.h
+++ b/src/sat/glucose/Vec.h
@@ -89,7 +89,8 @@ public:
T& operator [] (int index) { return data[index]; }
// Duplicatation (preferred instead):
- void copyTo(vec<T>& copy) const { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
+ void copyTo (vec<T>& copy) const { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
+ void copyTo_(vec<T>& copy) const { copy.shrink_(copy.size()); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
void moveTo(vec<T>& dest) { dest.clear(true); dest.data = data; dest.sz = sz; dest.cap = cap; data = NULL; sz = 0; cap = 0; }
};
diff --git a/src/sat/glucose/stdint.h b/src/sat/glucose/stdint.h
deleted file mode 100644
index e36a136d..00000000
--- a/src/sat/glucose/stdint.h
+++ /dev/null
@@ -1,1628 +0,0 @@
-
-
-
-
-
-
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="utf-8">
- <link rel="dns-prefetch" href="https://assets-cdn.github.com">
- <link rel="dns-prefetch" href="https://avatars0.githubusercontent.com">
- <link rel="dns-prefetch" href="https://avatars1.githubusercontent.com">
- <link rel="dns-prefetch" href="https://avatars2.githubusercontent.com">
- <link rel="dns-prefetch" href="https://avatars3.githubusercontent.com">
- <link rel="dns-prefetch" href="https://github-cloud.s3.amazonaws.com">
- <link rel="dns-prefetch" href="https://user-images.githubusercontent.com/">
-
-
-
- <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/frameworks-7db951ed87f8f6cbd3a9e89c294e300cf23c1a83ad7ae64c70b8f99b21031340.css" integrity="sha256-fblR7Yf49svTqeicKU4wDPI8GoOteuZMcLj5myEDE0A=" media="all" rel="stylesheet" />
- <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/github-4b2158409cc56f58dafd534ae676475b1bfe7cb057c415e2c5984e3c13b041e5.css" integrity="sha256-SyFYQJzFb1ja/VNK5nZHWxv+fLBXxBXixZhOPBOwQeU=" media="all" rel="stylesheet" />
-
-
- <link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/site-955690c4e09b2eeb3627ae6048471522eb98b42054150bd855ad4183db364816.css" integrity="sha256-lVaQxOCbLus2J65gSEcVIuuYtCBUFQvYVa1Bg9s2SBY=" media="all" rel="stylesheet" />
-
-
- <meta name="viewport" content="width=device-width">
-
- <title>gntp-send/stdint.h at master · mattn/gntp-send · GitHub</title>
- <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub">
- <link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub">
- <meta property="fb:app_id" content="1401488693436528">
-
-
- <meta content="https://avatars1.githubusercontent.com/u/10111?v=4&amp;s=400" property="og:image" /><meta content="GitHub" property="og:site_name" /><meta content="object" property="og:type" /><meta content="mattn/gntp-send" property="og:title" /><meta content="https://github.com/mattn/gntp-send" property="og:url" /><meta content="gntp-send - command line program that send to growl using GNTP protocol." property="og:description" />
-
- <link rel="assets" href="https://assets-cdn.github.com/">
-
- <meta name="pjax-timeout" content="1000">
-
- <meta name="request-id" content="C6BC:2817D:56F2228:8688546:59B04B65" data-pjax-transient>
-
-
- <meta name="selected-link" value="repo_source" data-pjax-transient>
-
- <meta name="google-site-verification" content="KT5gs8h0wvaagLKAVWq8bbeNwnZZK1r1XQysX3xurLU">
-<meta name="google-site-verification" content="ZzhVyEFwb7w3e0-uOTltm8Jsck2F5StVihD0exw2fsA">
- <meta name="google-analytics" content="UA-3769691-2">
-
-<meta content="collector.githubapp.com" name="octolytics-host" /><meta content="github" name="octolytics-app-id" /><meta content="https://collector.githubapp.com/github-external/browser_event" name="octolytics-event-url" /><meta content="C6BC:2817D:56F2228:8688546:59B04B65" name="octolytics-dimension-request_id" /><meta content="sea" name="octolytics-dimension-region_edge" /><meta content="iad" name="octolytics-dimension-region_render" />
-<meta content="/&lt;user-name&gt;/&lt;repo-name&gt;/blob/show" data-pjax-transient="true" name="analytics-location" />
-
-
-
-
- <meta class="js-ga-set" name="dimension1" content="Logged Out">
-
-
-
-
- <meta name="hostname" content="github.com">
- <meta name="user-login" content="">
-
- <meta name="expected-hostname" content="github.com">
- <meta name="js-proxy-site-detection-payload" content="YmNhNTY5Y2Y4MjdmNjMyMzc4ODViZmFkM2JmYmE5MDA4YWFkMWRmZWU5YzNjMGZmMmU3M2U2YTc1YWE0ZTEzYXx7InJlbW90ZV9hZGRyZXNzIjoiNzMuMjUyLjEzOC45MyIsInJlcXVlc3RfaWQiOiJDNkJDOjI4MTdEOjU2RjIyMjg6ODY4ODU0Njo1OUIwNEI2NSIsInRpbWVzdGFtcCI6MTUwNDcyNTg2NiwiaG9zdCI6ImdpdGh1Yi5jb20ifQ==">
-
-
- <meta name="html-safe-nonce" content="c7ac7dad53ebbb213745963c771e009cd0ec2414">
-
- <meta http-equiv="x-pjax-version" content="ef2b97c5ce9b111269ce538c13af797b">
-
-
- <link href="https://github.com/mattn/gntp-send/commits/master.atom" rel="alternate" title="Recent Commits to gntp-send:master" type="application/atom+xml">
-
- <meta name="description" content="gntp-send - command line program that send to growl using GNTP protocol.">
- <meta name="go-import" content="github.com/mattn/gntp-send git https://github.com/mattn/gntp-send.git">
-
- <meta content="10111" name="octolytics-dimension-user_id" /><meta content="mattn" name="octolytics-dimension-user_login" /><meta content="160637" name="octolytics-dimension-repository_id" /><meta content="mattn/gntp-send" name="octolytics-dimension-repository_nwo" /><meta content="true" name="octolytics-dimension-repository_public" /><meta content="false" name="octolytics-dimension-repository_is_fork" /><meta content="160637" name="octolytics-dimension-repository_network_root_id" /><meta content="mattn/gntp-send" name="octolytics-dimension-repository_network_root_nwo" /><meta content="false" name="octolytics-dimension-repository_explore_github_marketplace_ci_cta_shown" />
-
-
- <link rel="canonical" href="https://github.com/mattn/gntp-send/blob/master/include/msinttypes/stdint.h" data-pjax-transient>
-
-
- <meta name="browser-stats-url" content="https://api.github.com/_private/browser/stats">
-
- <meta name="browser-errors-url" content="https://api.github.com/_private/browser/errors">
-
- <link rel="mask-icon" href="https://assets-cdn.github.com/pinned-octocat.svg" color="#000000">
- <link rel="icon" type="image/x-icon" href="https://assets-cdn.github.com/favicon.ico">
-
-<meta name="theme-color" content="#1e2327">
-
-
-
- </head>
-
- <body class="logged-out env-production page-blob">
-
-
- <div class="position-relative js-header-wrapper ">
- <a href="#start-of-content" tabindex="1" class="px-2 py-4 show-on-focus js-skip-to-content">Skip to content</a>
- <div id="js-pjax-loader-bar" class="pjax-loader-bar"><div class="progress"></div></div>
-
-
-
-
-
-
-
- <header class="Header header-logged-out position-relative f4 py-3" role="banner">
- <div class="container-lg d-flex px-3">
- <div class="d-flex flex-justify-between flex-items-center">
- <a class="header-logo-invertocat my-0" href="https://github.com/" aria-label="Homepage" data-ga-click="(Logged out) Header, go to homepage, icon:logo-wordmark">
- <svg aria-hidden="true" class="octicon octicon-mark-github" height="32" version="1.1" viewBox="0 0 16 16" width="32"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
- </a>
-
- </div>
-
- <div class="HeaderMenu HeaderMenu--bright d-flex flex-justify-between flex-auto">
- <nav class="mt-0">
- <ul class="d-flex list-style-none">
- <li class="ml-2">
- <a href="/features" class="js-selected-navigation-item HeaderNavlink px-0 py-2 m-0" data-ga-click="Header, click, Nav menu - item:features" data-selected-links="/features /features/project-management /features/code-review /features/project-management /features/integrations /features">
- Features
-</a> </li>
- <li class="ml-4">
- <a href="/business" class="js-selected-navigation-item HeaderNavlink px-0 py-2 m-0" data-ga-click="Header, click, Nav menu - item:business" data-selected-links="/business /business/security /business/customers /business">
- Business
-</a> </li>
-
- <li class="ml-4">
- <a href="/explore" class="js-selected-navigation-item HeaderNavlink px-0 py-2 m-0" data-ga-click="Header, click, Nav menu - item:explore" data-selected-links="/explore /trending /trending/developers /integrations /integrations/feature/code /integrations/feature/collaborate /integrations/feature/ship showcases showcases_search showcases_landing /explore">
- Explore
-</a> </li>
-
- <li class="ml-4">
- <a href="/marketplace" class="js-selected-navigation-item HeaderNavlink px-0 py-2 m-0" data-ga-click="Header, click, Nav menu - item:marketplace" data-selected-links=" /marketplace">
- Marketplace
-</a> </li>
- <li class="ml-4">
- <a href="/pricing" class="js-selected-navigation-item HeaderNavlink px-0 py-2 m-0" data-ga-click="Header, click, Nav menu - item:pricing" data-selected-links="/pricing /pricing/developer /pricing/team /pricing/business-hosted /pricing/business-enterprise /pricing">
- Pricing
-</a> </li>
- </ul>
- </nav>
-
- <div class="d-flex">
- <div class="d-lg-flex flex-items-center mr-3">
- <div class="header-search scoped-search site-scoped-search js-site-search" role="search">
- <!-- '"` --><!-- </textarea></xmp> --></option></form><form accept-charset="UTF-8" action="/mattn/gntp-send/search" class="js-site-search-form" data-scoped-search-url="/mattn/gntp-send/search" data-unscoped-search-url="/search" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
- <label class="form-control header-search-wrapper js-chromeless-input-container">
- <a href="/mattn/gntp-send/blob/master/include/msinttypes/stdint.h" class="header-search-scope no-underline">This repository</a>
- <input type="text"
- class="form-control header-search-input js-site-search-focus js-site-search-field is-clearable"
- data-hotkey="s"
- name="q"
- value=""
- placeholder="Search"
- aria-label="Search this repository"
- data-unscoped-placeholder="Search GitHub"
- data-scoped-placeholder="Search"
- autocapitalize="off">
- <input type="hidden" class="js-site-search-type-field" name="type" >
- </label>
-</form></div>
-
- </div>
-
- <span class="d-inline-block">
- <div class="HeaderNavlink px-0 py-2 m-0">
- <a class="text-bold text-white no-underline" href="/login?return_to=%2Fmattn%2Fgntp-send%2Fblob%2Fmaster%2Finclude%2Fmsinttypes%2Fstdint.h" data-ga-click="(Logged out) Header, clicked Sign in, text:sign-in">Sign in</a>
- <span class="text-gray">or</span>
- <a class="text-bold text-white no-underline" href="/join?source=header-repo" data-ga-click="(Logged out) Header, clicked Sign up, text:sign-up">Sign up</a>
- </div>
- </span>
- </div>
- </div>
- </div>
-</header>
-
-
- </div>
-
- <div id="start-of-content" class="show-on-focus"></div>
-
- <div id="js-flash-container">
-</div>
-
-
-
- <div role="main">
- <div itemscope itemtype="http://schema.org/SoftwareSourceCode">
- <div id="js-repo-pjax-container" data-pjax-container>
-
-
-
-
-
-
- <div class="pagehead repohead instapaper_ignore readability-menu experiment-repo-nav">
- <div class="container repohead-details-container">
-
- <ul class="pagehead-actions">
- <li>
- <a href="/login?return_to=%2Fmattn%2Fgntp-send"
- class="btn btn-sm btn-with-count tooltipped tooltipped-n"
- aria-label="You must be signed in to watch a repository" rel="nofollow">
- <svg aria-hidden="true" class="octicon octicon-eye" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"/></svg>
- Watch
- </a>
- <a class="social-count" href="/mattn/gntp-send/watchers"
- aria-label="7 users are watching this repository">
- 7
- </a>
-
- </li>
-
- <li>
- <a href="/login?return_to=%2Fmattn%2Fgntp-send"
- class="btn btn-sm btn-with-count tooltipped tooltipped-n"
- aria-label="You must be signed in to star a repository" rel="nofollow">
- <svg aria-hidden="true" class="octicon octicon-star" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M14 6l-4.9-.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74z"/></svg>
- Star
- </a>
-
- <a class="social-count js-social-count" href="/mattn/gntp-send/stargazers"
- aria-label="44 users starred this repository">
- 44
- </a>
-
- </li>
-
- <li>
- <a href="/login?return_to=%2Fmattn%2Fgntp-send"
- class="btn btn-sm btn-with-count tooltipped tooltipped-n"
- aria-label="You must be signed in to fork a repository" rel="nofollow">
- <svg aria-hidden="true" class="octicon octicon-repo-forked" height="16" version="1.1" viewBox="0 0 10 16" width="10"><path fill-rule="evenodd" d="M8 1a1.993 1.993 0 0 0-1 3.72V6L5 8 3 6V4.72A1.993 1.993 0 0 0 2 1a1.993 1.993 0 0 0-1 3.72V6.5l3 3v1.78A1.993 1.993 0 0 0 5 15a1.993 1.993 0 0 0 1-3.72V9.5l3-3V4.72A1.993 1.993 0 0 0 8 1zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3 10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3-10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"/></svg>
- Fork
- </a>
-
- <a href="/mattn/gntp-send/network" class="social-count"
- aria-label="45 users forked this repository">
- 45
- </a>
- </li>
-</ul>
-
- <h1 class="public ">
- <svg aria-hidden="true" class="octicon octicon-repo" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M4 9H3V8h1v1zm0-3H3v1h1V6zm0-2H3v1h1V4zm0-2H3v1h1V2zm8-1v12c0 .55-.45 1-1 1H6v2l-1.5-1.5L3 16v-2H1c-.55 0-1-.45-1-1V1c0-.55.45-1 1-1h10c.55 0 1 .45 1 1zm-1 10H1v2h2v-1h3v1h5v-2zm0-10H2v9h9V1z"/></svg>
- <span class="author" itemprop="author"><a href="/mattn" class="url fn" rel="author">mattn</a></span><!--
---><span class="path-divider">/</span><!--
---><strong itemprop="name"><a href="/mattn/gntp-send" data-pjax="#js-repo-pjax-container">gntp-send</a></strong>
-
-</h1>
-
- </div>
- <div class="container">
-
-<nav class="reponav js-repo-nav js-sidenav-container-pjax"
- itemscope
- itemtype="http://schema.org/BreadcrumbList"
- role="navigation"
- data-pjax="#js-repo-pjax-container">
-
- <span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
- <a href="/mattn/gntp-send" class="js-selected-navigation-item selected reponav-item" data-hotkey="g c" data-selected-links="repo_source repo_downloads repo_commits repo_releases repo_tags repo_branches /mattn/gntp-send" itemprop="url">
- <svg aria-hidden="true" class="octicon octicon-code" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M9.5 3L8 4.5 11.5 8 8 11.5 9.5 13 14 8 9.5 3zm-5 0L0 8l4.5 5L6 11.5 2.5 8 6 4.5 4.5 3z"/></svg>
- <span itemprop="name">Code</span>
- <meta itemprop="position" content="1">
-</a> </span>
-
- <span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
- <a href="/mattn/gntp-send/issues" class="js-selected-navigation-item reponav-item" data-hotkey="g i" data-selected-links="repo_issues repo_labels repo_milestones /mattn/gntp-send/issues" itemprop="url">
- <svg aria-hidden="true" class="octicon octicon-issue-opened" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"/></svg>
- <span itemprop="name">Issues</span>
- <span class="Counter">1</span>
- <meta itemprop="position" content="2">
-</a> </span>
-
- <span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
- <a href="/mattn/gntp-send/pulls" class="js-selected-navigation-item reponav-item" data-hotkey="g p" data-selected-links="repo_pulls /mattn/gntp-send/pulls" itemprop="url">
- <svg aria-hidden="true" class="octicon octicon-git-pull-request" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"/></svg>
- <span itemprop="name">Pull requests</span>
- <span class="Counter">0</span>
- <meta itemprop="position" content="3">
-</a> </span>
-
- <a href="/mattn/gntp-send/projects" class="js-selected-navigation-item reponav-item" data-selected-links="repo_projects new_repo_project repo_project /mattn/gntp-send/projects">
- <svg aria-hidden="true" class="octicon octicon-project" height="16" version="1.1" viewBox="0 0 15 16" width="15"><path fill-rule="evenodd" d="M10 12h3V2h-3v10zm-4-2h3V2H6v8zm-4 4h3V2H2v12zm-1 1h13V1H1v14zM14 0H1a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h13a1 1 0 0 0 1-1V1a1 1 0 0 0-1-1z"/></svg>
- Projects
- <span class="Counter" >0</span>
-</a>
- <a href="/mattn/gntp-send/wiki" class="js-selected-navigation-item reponav-item" data-hotkey="g w" data-selected-links="repo_wiki /mattn/gntp-send/wiki">
- <svg aria-hidden="true" class="octicon octicon-book" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M3 5h4v1H3V5zm0 3h4V7H3v1zm0 2h4V9H3v1zm11-5h-4v1h4V5zm0 2h-4v1h4V7zm0 2h-4v1h4V9zm2-6v9c0 .55-.45 1-1 1H9.5l-1 1-1-1H2c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h5.5l1 1 1-1H15c.55 0 1 .45 1 1zm-8 .5L7.5 3H2v9h6V3.5zm7-.5H9.5l-.5.5V12h6V3z"/></svg>
- Wiki
-</a>
-
- <div class="reponav-dropdown js-menu-container">
- <button type="button" class="btn-link reponav-item reponav-dropdown js-menu-target " data-no-toggle aria-expanded="false" aria-haspopup="true">
- Insights
- <svg aria-hidden="true" class="octicon octicon-triangle-down v-align-middle text-gray" height="11" version="1.1" viewBox="0 0 12 16" width="8"><path fill-rule="evenodd" d="M0 5l6 6 6-6z"/></svg>
- </button>
- <div class="dropdown-menu-content js-menu-content">
- <div class="dropdown-menu dropdown-menu-sw">
- <a class="dropdown-item" href="/mattn/gntp-send/pulse" data-skip-pjax>
- <svg aria-hidden="true" class="octicon octicon-pulse" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M11.5 8L8.8 5.4 6.6 8.5 5.5 1.6 2.38 8H0v2h3.6l.9-1.8.9 5.4L9 8.5l1.6 1.5H14V8z"/></svg>
- Pulse
- </a>
- <a class="dropdown-item" href="/mattn/gntp-send/graphs" data-skip-pjax>
- <svg aria-hidden="true" class="octicon octicon-graph" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M16 14v1H0V0h1v14h15zM5 13H3V8h2v5zm4 0H7V3h2v10zm4 0h-2V6h2v7z"/></svg>
- Graphs
- </a>
- </div>
- </div>
- </div>
-</nav>
-
- </div>
- </div>
-
-<div class="container new-discussion-timeline experiment-repo-nav">
- <div class="repository-content">
-
-
- <a href="/mattn/gntp-send/blob/090b1276fb4a30601113551bed88c58329646818/include/msinttypes/stdint.h" class="d-none js-permalink-shortcut" data-hotkey="y">Permalink</a>
-
- <!-- blob contrib key: blob_contributors:v21:1fdd18f08c206edbaba4a5b47a34cc57 -->
-
- <div class="file-navigation js-zeroclipboard-container">
-
-<div class="select-menu branch-select-menu js-menu-container js-select-menu float-left">
- <button class=" btn btn-sm select-menu-button js-menu-target css-truncate" data-hotkey="w"
-
- type="button" aria-label="Switch branches or tags" aria-expanded="false" aria-haspopup="true">
- <i>Branch:</i>
- <span class="js-select-button css-truncate-target">master</span>
- </button>
-
- <div class="select-menu-modal-holder js-menu-content js-navigation-container" data-pjax>
-
- <div class="select-menu-modal">
- <div class="select-menu-header">
- <svg aria-label="Close" class="octicon octicon-x js-menu-close" height="16" role="img" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"/></svg>
- <span class="select-menu-title">Switch branches/tags</span>
- </div>
-
- <div class="select-menu-filters">
- <div class="select-menu-text-filter">
- <input type="text" aria-label="Filter branches/tags" id="context-commitish-filter-field" class="form-control js-filterable-field js-navigation-enable" placeholder="Filter branches/tags">
- </div>
- <div class="select-menu-tabs">
- <ul>
- <li class="select-menu-tab">
- <a href="#" data-tab-filter="branches" data-filter-placeholder="Filter branches/tags" class="js-select-menu-tab" role="tab">Branches</a>
- </li>
- <li class="select-menu-tab">
- <a href="#" data-tab-filter="tags" data-filter-placeholder="Find a tag…" class="js-select-menu-tab" role="tab">Tags</a>
- </li>
- </ul>
- </div>
- </div>
-
- <div class="select-menu-list select-menu-tab-bucket js-select-menu-tab-bucket" data-tab-filter="branches" role="menu">
-
- <div data-filterable-for="context-commitish-filter-field" data-filterable-type="substring">
-
-
- <a class="select-menu-item js-navigation-item js-navigation-open selected"
- href="/mattn/gntp-send/blob/master/include/msinttypes/stdint.h"
- data-name="master"
- data-skip-pjax="true"
- rel="nofollow">
- <svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"/></svg>
- <span class="select-menu-item-text css-truncate-target js-select-menu-filter-text">
- master
- </span>
- </a>
- </div>
-
- <div class="select-menu-no-results">Nothing to show</div>
- </div>
-
- <div class="select-menu-list select-menu-tab-bucket js-select-menu-tab-bucket" data-tab-filter="tags">
- <div data-filterable-for="context-commitish-filter-field" data-filterable-type="substring">
-
-
- <a class="select-menu-item js-navigation-item js-navigation-open "
- href="/mattn/gntp-send/tree/0.3.4/include/msinttypes/stdint.h"
- data-name="0.3.4"
- data-skip-pjax="true"
- rel="nofollow">
- <svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"/></svg>
- <span class="select-menu-item-text css-truncate-target" title="0.3.4">
- 0.3.4
- </span>
- </a>
- </div>
-
- <div class="select-menu-no-results">Nothing to show</div>
- </div>
-
- </div>
- </div>
-</div>
-
- <div class="BtnGroup float-right">
- <a href="/mattn/gntp-send/find/master"
- class="js-pjax-capture-input btn btn-sm BtnGroup-item"
- data-pjax
- data-hotkey="t">
- Find file
- </a>
- <button aria-label="Copy file path to clipboard" class="js-zeroclipboard btn btn-sm BtnGroup-item tooltipped tooltipped-s" data-copied-hint="Copied!" type="button">Copy path</button>
- </div>
- <div class="breadcrumb js-zeroclipboard-target">
- <span class="repo-root js-repo-root"><span class="js-path-segment"><a href="/mattn/gntp-send"><span>gntp-send</span></a></span></span><span class="separator">/</span><span class="js-path-segment"><a href="/mattn/gntp-send/tree/master/include"><span>include</span></a></span><span class="separator">/</span><span class="js-path-segment"><a href="/mattn/gntp-send/tree/master/include/msinttypes"><span>msinttypes</span></a></span><span class="separator">/</span><strong class="final-path">stdint.h</strong>
- </div>
- </div>
-
-
-
- <div class="commit-tease">
- <span class="float-right">
- <a class="commit-tease-sha" href="/mattn/gntp-send/commit/700f4a2d844001a6197d68440a9123f197be6096" data-pjax>
- 700f4a2
- </a>
- <relative-time datetime="2011-10-06T00:28:08Z">Oct 6, 2011</relative-time>
- </span>
- <div>
- <img alt="@mattn" class="avatar" height="20" src="https://avatars1.githubusercontent.com/u/10111?v=4&amp;s=40" width="20" />
- <a href="/mattn" class="user-mention" rel="author">mattn</a>
- <a href="/mattn/gntp-send/commit/700f4a2d844001a6197d68440a9123f197be6096" class="message" data-pjax="true" title="perfer include/src name.">perfer include/src name.</a>
- </div>
-
- <div class="commit-tease-contributors">
- <button type="button" class="btn-link muted-link contributors-toggle" data-facebox="#blob_contributors_box">
- <strong>1</strong>
- contributor
- </button>
-
- </div>
-
- <div id="blob_contributors_box" style="display:none">
- <h2 class="facebox-header" data-facebox-id="facebox-header">Users who have contributed to this file</h2>
- <ul class="facebox-user-list" data-facebox-id="facebox-description">
- <li class="facebox-user-list-item">
- <img alt="@mattn" height="24" src="https://avatars3.githubusercontent.com/u/10111?v=4&amp;s=48" width="24" />
- <a href="/mattn">mattn</a>
- </li>
- </ul>
- </div>
- </div>
-
-
- <div class="file">
- <div class="file-header">
- <div class="file-actions">
-
- <div class="BtnGroup">
- <a href="/mattn/gntp-send/raw/master/include/msinttypes/stdint.h" class="btn btn-sm BtnGroup-item" id="raw-url">Raw</a>
- <a href="/mattn/gntp-send/blame/master/include/msinttypes/stdint.h" class="btn btn-sm js-update-url-with-hash BtnGroup-item" data-hotkey="b">Blame</a>
- <a href="/mattn/gntp-send/commits/master/include/msinttypes/stdint.h" class="btn btn-sm BtnGroup-item" rel="nofollow">History</a>
- </div>
-
- <a class="btn-octicon tooltipped tooltipped-nw"
- href="https://desktop.github.com"
- aria-label="Open this file in GitHub Desktop"
- data-ga-click="Repository, open with desktop, type:windows">
- <svg aria-hidden="true" class="octicon octicon-device-desktop" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M15 2H1c-.55 0-1 .45-1 1v9c0 .55.45 1 1 1h5.34c-.25.61-.86 1.39-2.34 2h8c-1.48-.61-2.09-1.39-2.34-2H15c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm0 9H1V3h14v8z"/></svg>
- </a>
-
- <button type="button" class="btn-octicon disabled tooltipped tooltipped-nw"
- aria-label="You must be signed in to make or propose changes">
- <svg aria-hidden="true" class="octicon octicon-pencil" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path fill-rule="evenodd" d="M0 12v3h3l8-8-3-3-8 8zm3 2H1v-2h1v1h1v1zm10.3-9.3L12 6 9 3l1.3-1.3a.996.996 0 0 1 1.41 0l1.59 1.59c.39.39.39 1.02 0 1.41z"/></svg>
- </button>
- <button type="button" class="btn-octicon btn-octicon-danger disabled tooltipped tooltipped-nw"
- aria-label="You must be signed in to make or propose changes">
- <svg aria-hidden="true" class="octicon octicon-trashcan" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"/></svg>
- </button>
- </div>
-
- <div class="file-info">
- 248 lines (207 sloc)
- <span class="file-info-divider"></span>
- 7.55 KB
- </div>
-</div>
-
-
-
- <div itemprop="text" class="blob-wrapper data type-c">
- <table class="highlight tab-size js-file-line-container" data-tab-size="8">
- <tr>
- <td id="L1" class="blob-num js-line-number" data-line-number="1"></td>
- <td id="LC1" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> ISO C9x compliant stdint.h for Microsoft Visual Studio</span></td>
- </tr>
- <tr>
- <td id="L2" class="blob-num js-line-number" data-line-number="2"></td>
- <td id="LC2" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 </span></td>
- </tr>
- <tr>
- <td id="L3" class="blob-num js-line-number" data-line-number="3"></td>
- <td id="LC3" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> </span></td>
- </tr>
- <tr>
- <td id="L4" class="blob-num js-line-number" data-line-number="4"></td>
- <td id="LC4" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> Copyright (c) 2006-2008 Alexander Chemeris</span></td>
- </tr>
- <tr>
- <td id="L5" class="blob-num js-line-number" data-line-number="5"></td>
- <td id="LC5" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> </span></td>
- </tr>
- <tr>
- <td id="L6" class="blob-num js-line-number" data-line-number="6"></td>
- <td id="LC6" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> Redistribution and use in source and binary forms, with or without</span></td>
- </tr>
- <tr>
- <td id="L7" class="blob-num js-line-number" data-line-number="7"></td>
- <td id="LC7" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> modification, are permitted provided that the following conditions are met:</span></td>
- </tr>
- <tr>
- <td id="L8" class="blob-num js-line-number" data-line-number="8"></td>
- <td id="LC8" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> </span></td>
- </tr>
- <tr>
- <td id="L9" class="blob-num js-line-number" data-line-number="9"></td>
- <td id="LC9" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 1. Redistributions of source code must retain the above copyright notice,</span></td>
- </tr>
- <tr>
- <td id="L10" class="blob-num js-line-number" data-line-number="10"></td>
- <td id="LC10" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> this list of conditions and the following disclaimer.</span></td>
- </tr>
- <tr>
- <td id="L11" class="blob-num js-line-number" data-line-number="11"></td>
- <td id="LC11" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> </span></td>
- </tr>
- <tr>
- <td id="L12" class="blob-num js-line-number" data-line-number="12"></td>
- <td id="LC12" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 2. Redistributions in binary form must reproduce the above copyright</span></td>
- </tr>
- <tr>
- <td id="L13" class="blob-num js-line-number" data-line-number="13"></td>
- <td id="LC13" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> notice, this list of conditions and the following disclaimer in the</span></td>
- </tr>
- <tr>
- <td id="L14" class="blob-num js-line-number" data-line-number="14"></td>
- <td id="LC14" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> documentation and/or other materials provided with the distribution.</span></td>
- </tr>
- <tr>
- <td id="L15" class="blob-num js-line-number" data-line-number="15"></td>
- <td id="LC15" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> </span></td>
- </tr>
- <tr>
- <td id="L16" class="blob-num js-line-number" data-line-number="16"></td>
- <td id="LC16" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 3. The name of the author may be used to endorse or promote products</span></td>
- </tr>
- <tr>
- <td id="L17" class="blob-num js-line-number" data-line-number="17"></td>
- <td id="LC17" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> derived from this software without specific prior written permission.</span></td>
- </tr>
- <tr>
- <td id="L18" class="blob-num js-line-number" data-line-number="18"></td>
- <td id="LC18" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> </span></td>
- </tr>
- <tr>
- <td id="L19" class="blob-num js-line-number" data-line-number="19"></td>
- <td id="LC19" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS&#39;&#39; AND ANY EXPRESS OR IMPLIED</span></td>
- </tr>
- <tr>
- <td id="L20" class="blob-num js-line-number" data-line-number="20"></td>
- <td id="LC20" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span></td>
- </tr>
- <tr>
- <td id="L21" class="blob-num js-line-number" data-line-number="21"></td>
- <td id="LC21" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO</span></td>
- </tr>
- <tr>
- <td id="L22" class="blob-num js-line-number" data-line-number="22"></td>
- <td id="LC22" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span></td>
- </tr>
- <tr>
- <td id="L23" class="blob-num js-line-number" data-line-number="23"></td>
- <td id="LC23" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,</span></td>
- </tr>
- <tr>
- <td id="L24" class="blob-num js-line-number" data-line-number="24"></td>
- <td id="LC24" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;</span></td>
- </tr>
- <tr>
- <td id="L25" class="blob-num js-line-number" data-line-number="25"></td>
- <td id="LC25" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span></td>
- </tr>
- <tr>
- <td id="L26" class="blob-num js-line-number" data-line-number="26"></td>
- <td id="LC26" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR</span></td>
- </tr>
- <tr>
- <td id="L27" class="blob-num js-line-number" data-line-number="27"></td>
- <td id="LC27" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF</span></td>
- </tr>
- <tr>
- <td id="L28" class="blob-num js-line-number" data-line-number="28"></td>
- <td id="LC28" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span></td>
- </tr>
- <tr>
- <td id="L29" class="blob-num js-line-number" data-line-number="29"></td>
- <td id="LC29" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> </span></td>
- </tr>
- <tr>
- <td id="L30" class="blob-num js-line-number" data-line-number="30"></td>
- <td id="LC30" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span>/////////////////////////////////////////////////////////////////////////////</span></td>
- </tr>
- <tr>
- <td id="L31" class="blob-num js-line-number" data-line-number="31"></td>
- <td id="LC31" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L32" class="blob-num js-line-number" data-line-number="32"></td>
- <td id="LC32" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifndef</span> _MSC_VER <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L33" class="blob-num js-line-number" data-line-number="33"></td>
- <td id="LC33" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">error</span> &quot;Use this header only with Microsoft Visual C++ compilers!&quot;</td>
- </tr>
- <tr>
- <td id="L34" class="blob-num js-line-number" data-line-number="34"></td>
- <td id="LC34" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> _MSC_VER ]</span></td>
- </tr>
- <tr>
- <td id="L35" class="blob-num js-line-number" data-line-number="35"></td>
- <td id="LC35" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L36" class="blob-num js-line-number" data-line-number="36"></td>
- <td id="LC36" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifndef</span> _MSC_STDINT_H_ <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L37" class="blob-num js-line-number" data-line-number="37"></td>
- <td id="LC37" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">_MSC_STDINT_H_</span></td>
- </tr>
- <tr>
- <td id="L38" class="blob-num js-line-number" data-line-number="38"></td>
- <td id="LC38" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L39" class="blob-num js-line-number" data-line-number="39"></td>
- <td id="LC39" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">if</span> _MSC_VER &gt; 1000</td>
- </tr>
- <tr>
- <td id="L40" class="blob-num js-line-number" data-line-number="40"></td>
- <td id="LC40" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">pragma</span> once</td>
- </tr>
- <tr>
- <td id="L41" class="blob-num js-line-number" data-line-number="41"></td>
- <td id="LC41" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span></td>
- </tr>
- <tr>
- <td id="L42" class="blob-num js-line-number" data-line-number="42"></td>
- <td id="LC42" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L43" class="blob-num js-line-number" data-line-number="43"></td>
- <td id="LC43" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>limits.h<span class="pl-pds">&gt;</span></span></td>
- </tr>
- <tr>
- <td id="L44" class="blob-num js-line-number" data-line-number="44"></td>
- <td id="LC44" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L45" class="blob-num js-line-number" data-line-number="45"></td>
- <td id="LC45" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> For Visual Studio 6 in C++ mode and for many Visual Studio versions when</span></td>
- </tr>
- <tr>
- <td id="L46" class="blob-num js-line-number" data-line-number="46"></td>
- <td id="LC46" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> compiling for ARM we should wrap &lt;wchar.h&gt; include with &#39;extern &quot;C++&quot; {}&#39;</span></td>
- </tr>
- <tr>
- <td id="L47" class="blob-num js-line-number" data-line-number="47"></td>
- <td id="LC47" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> or compiler give many errors like this:</span></td>
- </tr>
- <tr>
- <td id="L48" class="blob-num js-line-number" data-line-number="48"></td>
- <td id="LC48" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> error C2733: second C linkage of overloaded function &#39;wmemchr&#39; not allowed</span></td>
- </tr>
- <tr>
- <td id="L49" class="blob-num js-line-number" data-line-number="49"></td>
- <td id="LC49" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifdef</span> __cplusplus</td>
- </tr>
- <tr>
- <td id="L50" class="blob-num js-line-number" data-line-number="50"></td>
- <td id="LC50" class="blob-code blob-code-inner js-file-line"><span class="pl-k">extern</span> <span class="pl-s"><span class="pl-pds">&quot;</span>C<span class="pl-pds">&quot;</span></span> {</td>
- </tr>
- <tr>
- <td id="L51" class="blob-num js-line-number" data-line-number="51"></td>
- <td id="LC51" class="blob-code blob-code-inner js-file-line">#endif</td>
- </tr>
- <tr>
- <td id="L52" class="blob-num js-line-number" data-line-number="52"></td>
- <td id="LC52" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>wchar.h<span class="pl-pds">&gt;</span></span></td>
- </tr>
- <tr>
- <td id="L53" class="blob-num js-line-number" data-line-number="53"></td>
- <td id="LC53" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifdef</span> __cplusplus</td>
- </tr>
- <tr>
- <td id="L54" class="blob-num js-line-number" data-line-number="54"></td>
- <td id="LC54" class="blob-code blob-code-inner js-file-line">}</td>
- </tr>
- <tr>
- <td id="L55" class="blob-num js-line-number" data-line-number="55"></td>
- <td id="LC55" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span></td>
- </tr>
- <tr>
- <td id="L56" class="blob-num js-line-number" data-line-number="56"></td>
- <td id="LC56" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L57" class="blob-num js-line-number" data-line-number="57"></td>
- <td id="LC57" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> Define _W64 macros to mark types changing their size, like intptr_t.</span></td>
- </tr>
- <tr>
- <td id="L58" class="blob-num js-line-number" data-line-number="58"></td>
- <td id="LC58" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifndef</span> _W64</td>
- </tr>
- <tr>
- <td id="L59" class="blob-num js-line-number" data-line-number="59"></td>
- <td id="LC59" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">if</span> !defined(__midl) &amp;&amp; (defined(_X86_) || defined(_M_IX86)) &amp;&amp; _MSC_VER &gt;= 1300</td>
- </tr>
- <tr>
- <td id="L60" class="blob-num js-line-number" data-line-number="60"></td>
- <td id="LC60" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">_W64</span> __w64</td>
- </tr>
- <tr>
- <td id="L61" class="blob-num js-line-number" data-line-number="61"></td>
- <td id="LC61" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">else</span></td>
- </tr>
- <tr>
- <td id="L62" class="blob-num js-line-number" data-line-number="62"></td>
- <td id="LC62" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">_W64</span></td>
- </tr>
- <tr>
- <td id="L63" class="blob-num js-line-number" data-line-number="63"></td>
- <td id="LC63" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">endif</span></td>
- </tr>
- <tr>
- <td id="L64" class="blob-num js-line-number" data-line-number="64"></td>
- <td id="LC64" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span></td>
- </tr>
- <tr>
- <td id="L65" class="blob-num js-line-number" data-line-number="65"></td>
- <td id="LC65" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L66" class="blob-num js-line-number" data-line-number="66"></td>
- <td id="LC66" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L67" class="blob-num js-line-number" data-line-number="67"></td>
- <td id="LC67" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.1 Integer types</span></td>
- </tr>
- <tr>
- <td id="L68" class="blob-num js-line-number" data-line-number="68"></td>
- <td id="LC68" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L69" class="blob-num js-line-number" data-line-number="69"></td>
- <td id="LC69" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.1.1 Exact-width integer types</span></td>
- </tr>
- <tr>
- <td id="L70" class="blob-num js-line-number" data-line-number="70"></td>
- <td id="LC70" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L71" class="blob-num js-line-number" data-line-number="71"></td>
- <td id="LC71" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> Visual Studio 6 and Embedded Visual C++ 4 doesn&#39;t</span></td>
- </tr>
- <tr>
- <td id="L72" class="blob-num js-line-number" data-line-number="72"></td>
- <td id="LC72" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> realize that, e.g. char has the same size as __int8</span></td>
- </tr>
- <tr>
- <td id="L73" class="blob-num js-line-number" data-line-number="73"></td>
- <td id="LC73" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> so we give up on __intX for them.</span></td>
- </tr>
- <tr>
- <td id="L74" class="blob-num js-line-number" data-line-number="74"></td>
- <td id="LC74" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">if</span> (_MSC_VER &lt; 1300)</td>
- </tr>
- <tr>
- <td id="L75" class="blob-num js-line-number" data-line-number="75"></td>
- <td id="LC75" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">signed</span> <span class="pl-k">char</span> <span class="pl-c1">int8_t</span>;</td>
- </tr>
- <tr>
- <td id="L76" class="blob-num js-line-number" data-line-number="76"></td>
- <td id="LC76" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">signed</span> <span class="pl-k">short</span> <span class="pl-c1">int16_t</span>;</td>
- </tr>
- <tr>
- <td id="L77" class="blob-num js-line-number" data-line-number="77"></td>
- <td id="LC77" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">signed</span> <span class="pl-k">int</span> <span class="pl-c1">int32_t</span>;</td>
- </tr>
- <tr>
- <td id="L78" class="blob-num js-line-number" data-line-number="78"></td>
- <td id="LC78" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">unsigned</span> <span class="pl-k">char</span> <span class="pl-c1">uint8_t</span>;</td>
- </tr>
- <tr>
- <td id="L79" class="blob-num js-line-number" data-line-number="79"></td>
- <td id="LC79" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">unsigned</span> <span class="pl-k">short</span> <span class="pl-c1">uint16_t</span>;</td>
- </tr>
- <tr>
- <td id="L80" class="blob-num js-line-number" data-line-number="80"></td>
- <td id="LC80" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">unsigned</span> <span class="pl-k">int</span> <span class="pl-c1">uint32_t</span>;</td>
- </tr>
- <tr>
- <td id="L81" class="blob-num js-line-number" data-line-number="81"></td>
- <td id="LC81" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">else</span></td>
- </tr>
- <tr>
- <td id="L82" class="blob-num js-line-number" data-line-number="82"></td>
- <td id="LC82" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">signed</span> __int8 <span class="pl-c1">int8_t</span>;</td>
- </tr>
- <tr>
- <td id="L83" class="blob-num js-line-number" data-line-number="83"></td>
- <td id="LC83" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">signed</span> __int16 <span class="pl-c1">int16_t</span>;</td>
- </tr>
- <tr>
- <td id="L84" class="blob-num js-line-number" data-line-number="84"></td>
- <td id="LC84" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">signed</span> __int32 <span class="pl-c1">int32_t</span>;</td>
- </tr>
- <tr>
- <td id="L85" class="blob-num js-line-number" data-line-number="85"></td>
- <td id="LC85" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">unsigned</span> __int8 <span class="pl-c1">uint8_t</span>;</td>
- </tr>
- <tr>
- <td id="L86" class="blob-num js-line-number" data-line-number="86"></td>
- <td id="LC86" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">unsigned</span> __int16 <span class="pl-c1">uint16_t</span>;</td>
- </tr>
- <tr>
- <td id="L87" class="blob-num js-line-number" data-line-number="87"></td>
- <td id="LC87" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">unsigned</span> __int32 <span class="pl-c1">uint32_t</span>;</td>
- </tr>
- <tr>
- <td id="L88" class="blob-num js-line-number" data-line-number="88"></td>
- <td id="LC88" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span></td>
- </tr>
- <tr>
- <td id="L89" class="blob-num js-line-number" data-line-number="89"></td>
- <td id="LC89" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-k">signed</span> __int64 <span class="pl-c1">int64_t</span>;</td>
- </tr>
- <tr>
- <td id="L90" class="blob-num js-line-number" data-line-number="90"></td>
- <td id="LC90" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-k">unsigned</span> __int64 <span class="pl-c1">uint64_t</span>;</td>
- </tr>
- <tr>
- <td id="L91" class="blob-num js-line-number" data-line-number="91"></td>
- <td id="LC91" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L92" class="blob-num js-line-number" data-line-number="92"></td>
- <td id="LC92" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L93" class="blob-num js-line-number" data-line-number="93"></td>
- <td id="LC93" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.1.2 Minimum-width integer types</span></td>
- </tr>
- <tr>
- <td id="L94" class="blob-num js-line-number" data-line-number="94"></td>
- <td id="LC94" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int8_t</span> <span class="pl-c1">int_least8_t</span>;</td>
- </tr>
- <tr>
- <td id="L95" class="blob-num js-line-number" data-line-number="95"></td>
- <td id="LC95" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int16_t</span> <span class="pl-c1">int_least16_t</span>;</td>
- </tr>
- <tr>
- <td id="L96" class="blob-num js-line-number" data-line-number="96"></td>
- <td id="LC96" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int32_t</span> <span class="pl-c1">int_least32_t</span>;</td>
- </tr>
- <tr>
- <td id="L97" class="blob-num js-line-number" data-line-number="97"></td>
- <td id="LC97" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int64_t</span> <span class="pl-c1">int_least64_t</span>;</td>
- </tr>
- <tr>
- <td id="L98" class="blob-num js-line-number" data-line-number="98"></td>
- <td id="LC98" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint8_t</span> <span class="pl-c1">uint_least8_t</span>;</td>
- </tr>
- <tr>
- <td id="L99" class="blob-num js-line-number" data-line-number="99"></td>
- <td id="LC99" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint16_t</span> <span class="pl-c1">uint_least16_t</span>;</td>
- </tr>
- <tr>
- <td id="L100" class="blob-num js-line-number" data-line-number="100"></td>
- <td id="LC100" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint32_t</span> <span class="pl-c1">uint_least32_t</span>;</td>
- </tr>
- <tr>
- <td id="L101" class="blob-num js-line-number" data-line-number="101"></td>
- <td id="LC101" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint64_t</span> <span class="pl-c1">uint_least64_t</span>;</td>
- </tr>
- <tr>
- <td id="L102" class="blob-num js-line-number" data-line-number="102"></td>
- <td id="LC102" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L103" class="blob-num js-line-number" data-line-number="103"></td>
- <td id="LC103" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.1.3 Fastest minimum-width integer types</span></td>
- </tr>
- <tr>
- <td id="L104" class="blob-num js-line-number" data-line-number="104"></td>
- <td id="LC104" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int8_t</span> <span class="pl-c1">int_fast8_t</span>;</td>
- </tr>
- <tr>
- <td id="L105" class="blob-num js-line-number" data-line-number="105"></td>
- <td id="LC105" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int16_t</span> <span class="pl-c1">int_fast16_t</span>;</td>
- </tr>
- <tr>
- <td id="L106" class="blob-num js-line-number" data-line-number="106"></td>
- <td id="LC106" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int32_t</span> <span class="pl-c1">int_fast32_t</span>;</td>
- </tr>
- <tr>
- <td id="L107" class="blob-num js-line-number" data-line-number="107"></td>
- <td id="LC107" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int64_t</span> <span class="pl-c1">int_fast64_t</span>;</td>
- </tr>
- <tr>
- <td id="L108" class="blob-num js-line-number" data-line-number="108"></td>
- <td id="LC108" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint8_t</span> <span class="pl-c1">uint_fast8_t</span>;</td>
- </tr>
- <tr>
- <td id="L109" class="blob-num js-line-number" data-line-number="109"></td>
- <td id="LC109" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint16_t</span> <span class="pl-c1">uint_fast16_t</span>;</td>
- </tr>
- <tr>
- <td id="L110" class="blob-num js-line-number" data-line-number="110"></td>
- <td id="LC110" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint32_t</span> <span class="pl-c1">uint_fast32_t</span>;</td>
- </tr>
- <tr>
- <td id="L111" class="blob-num js-line-number" data-line-number="111"></td>
- <td id="LC111" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint64_t</span> <span class="pl-c1">uint_fast64_t</span>;</td>
- </tr>
- <tr>
- <td id="L112" class="blob-num js-line-number" data-line-number="112"></td>
- <td id="LC112" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L113" class="blob-num js-line-number" data-line-number="113"></td>
- <td id="LC113" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.1.4 Integer types capable of holding object pointers</span></td>
- </tr>
- <tr>
- <td id="L114" class="blob-num js-line-number" data-line-number="114"></td>
- <td id="LC114" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifdef</span> _WIN64 <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L115" class="blob-num js-line-number" data-line-number="115"></td>
- <td id="LC115" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">signed</span> __int64 <span class="pl-c1">intptr_t</span>;</td>
- </tr>
- <tr>
- <td id="L116" class="blob-num js-line-number" data-line-number="116"></td>
- <td id="LC116" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> <span class="pl-k">unsigned</span> __int64 <span class="pl-c1">uintptr_t</span>;</td>
- </tr>
- <tr>
- <td id="L117" class="blob-num js-line-number" data-line-number="117"></td>
- <td id="LC117" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">else</span> <span class="pl-c"><span class="pl-c">//</span> _WIN64 ][</span></td>
- </tr>
- <tr>
- <td id="L118" class="blob-num js-line-number" data-line-number="118"></td>
- <td id="LC118" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> _W64 <span class="pl-k">signed</span> <span class="pl-k">int</span> <span class="pl-c1">intptr_t</span>;</td>
- </tr>
- <tr>
- <td id="L119" class="blob-num js-line-number" data-line-number="119"></td>
- <td id="LC119" class="blob-code blob-code-inner js-file-line"> <span class="pl-k">typedef</span> _W64 <span class="pl-k">unsigned</span> <span class="pl-k">int</span> <span class="pl-c1">uintptr_t</span>;</td>
- </tr>
- <tr>
- <td id="L120" class="blob-num js-line-number" data-line-number="120"></td>
- <td id="LC120" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> _WIN64 ]</span></td>
- </tr>
- <tr>
- <td id="L121" class="blob-num js-line-number" data-line-number="121"></td>
- <td id="LC121" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L122" class="blob-num js-line-number" data-line-number="122"></td>
- <td id="LC122" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.1.5 Greatest-width integer types</span></td>
- </tr>
- <tr>
- <td id="L123" class="blob-num js-line-number" data-line-number="123"></td>
- <td id="LC123" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">int64_t</span> <span class="pl-c1">intmax_t</span>;</td>
- </tr>
- <tr>
- <td id="L124" class="blob-num js-line-number" data-line-number="124"></td>
- <td id="LC124" class="blob-code blob-code-inner js-file-line"><span class="pl-k">typedef</span> <span class="pl-c1">uint64_t</span> <span class="pl-c1">uintmax_t</span>;</td>
- </tr>
- <tr>
- <td id="L125" class="blob-num js-line-number" data-line-number="125"></td>
- <td id="LC125" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L126" class="blob-num js-line-number" data-line-number="126"></td>
- <td id="LC126" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L127" class="blob-num js-line-number" data-line-number="127"></td>
- <td id="LC127" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.2 Limits of specified-width integer types</span></td>
- </tr>
- <tr>
- <td id="L128" class="blob-num js-line-number" data-line-number="128"></td>
- <td id="LC128" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L129" class="blob-num js-line-number" data-line-number="129"></td>
- <td id="LC129" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">if</span> !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) <span class="pl-c"><span class="pl-c">//</span> [ See footnote 220 at page 257 and footnote 221 at page 259</span></td>
- </tr>
- <tr>
- <td id="L130" class="blob-num js-line-number" data-line-number="130"></td>
- <td id="LC130" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L131" class="blob-num js-line-number" data-line-number="131"></td>
- <td id="LC131" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.2.1 Limits of exact-width integer types</span></td>
- </tr>
- <tr>
- <td id="L132" class="blob-num js-line-number" data-line-number="132"></td>
- <td id="LC132" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT8_MIN</span> ((<span class="pl-c1">int8_t</span>)_I8_MIN)</td>
- </tr>
- <tr>
- <td id="L133" class="blob-num js-line-number" data-line-number="133"></td>
- <td id="LC133" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT8_MAX</span> _I8_MAX</td>
- </tr>
- <tr>
- <td id="L134" class="blob-num js-line-number" data-line-number="134"></td>
- <td id="LC134" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT16_MIN</span> ((<span class="pl-c1">int16_t</span>)_I16_MIN)</td>
- </tr>
- <tr>
- <td id="L135" class="blob-num js-line-number" data-line-number="135"></td>
- <td id="LC135" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT16_MAX</span> _I16_MAX</td>
- </tr>
- <tr>
- <td id="L136" class="blob-num js-line-number" data-line-number="136"></td>
- <td id="LC136" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT32_MIN</span> ((<span class="pl-c1">int32_t</span>)_I32_MIN)</td>
- </tr>
- <tr>
- <td id="L137" class="blob-num js-line-number" data-line-number="137"></td>
- <td id="LC137" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT32_MAX</span> _I32_MAX</td>
- </tr>
- <tr>
- <td id="L138" class="blob-num js-line-number" data-line-number="138"></td>
- <td id="LC138" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT64_MIN</span> ((<span class="pl-c1">int64_t</span>)_I64_MIN)</td>
- </tr>
- <tr>
- <td id="L139" class="blob-num js-line-number" data-line-number="139"></td>
- <td id="LC139" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT64_MAX</span> _I64_MAX</td>
- </tr>
- <tr>
- <td id="L140" class="blob-num js-line-number" data-line-number="140"></td>
- <td id="LC140" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT8_MAX</span> _UI8_MAX</td>
- </tr>
- <tr>
- <td id="L141" class="blob-num js-line-number" data-line-number="141"></td>
- <td id="LC141" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT16_MAX</span> _UI16_MAX</td>
- </tr>
- <tr>
- <td id="L142" class="blob-num js-line-number" data-line-number="142"></td>
- <td id="LC142" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT32_MAX</span> _UI32_MAX</td>
- </tr>
- <tr>
- <td id="L143" class="blob-num js-line-number" data-line-number="143"></td>
- <td id="LC143" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT64_MAX</span> _UI64_MAX</td>
- </tr>
- <tr>
- <td id="L144" class="blob-num js-line-number" data-line-number="144"></td>
- <td id="LC144" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L145" class="blob-num js-line-number" data-line-number="145"></td>
- <td id="LC145" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.2.2 Limits of minimum-width integer types</span></td>
- </tr>
- <tr>
- <td id="L146" class="blob-num js-line-number" data-line-number="146"></td>
- <td id="LC146" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_LEAST8_MIN</span> INT8_MIN</td>
- </tr>
- <tr>
- <td id="L147" class="blob-num js-line-number" data-line-number="147"></td>
- <td id="LC147" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_LEAST8_MAX</span> INT8_MAX</td>
- </tr>
- <tr>
- <td id="L148" class="blob-num js-line-number" data-line-number="148"></td>
- <td id="LC148" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_LEAST16_MIN</span> INT16_MIN</td>
- </tr>
- <tr>
- <td id="L149" class="blob-num js-line-number" data-line-number="149"></td>
- <td id="LC149" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_LEAST16_MAX</span> INT16_MAX</td>
- </tr>
- <tr>
- <td id="L150" class="blob-num js-line-number" data-line-number="150"></td>
- <td id="LC150" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_LEAST32_MIN</span> INT32_MIN</td>
- </tr>
- <tr>
- <td id="L151" class="blob-num js-line-number" data-line-number="151"></td>
- <td id="LC151" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_LEAST32_MAX</span> INT32_MAX</td>
- </tr>
- <tr>
- <td id="L152" class="blob-num js-line-number" data-line-number="152"></td>
- <td id="LC152" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_LEAST64_MIN</span> INT64_MIN</td>
- </tr>
- <tr>
- <td id="L153" class="blob-num js-line-number" data-line-number="153"></td>
- <td id="LC153" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_LEAST64_MAX</span> INT64_MAX</td>
- </tr>
- <tr>
- <td id="L154" class="blob-num js-line-number" data-line-number="154"></td>
- <td id="LC154" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT_LEAST8_MAX</span> UINT8_MAX</td>
- </tr>
- <tr>
- <td id="L155" class="blob-num js-line-number" data-line-number="155"></td>
- <td id="LC155" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT_LEAST16_MAX</span> UINT16_MAX</td>
- </tr>
- <tr>
- <td id="L156" class="blob-num js-line-number" data-line-number="156"></td>
- <td id="LC156" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT_LEAST32_MAX</span> UINT32_MAX</td>
- </tr>
- <tr>
- <td id="L157" class="blob-num js-line-number" data-line-number="157"></td>
- <td id="LC157" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT_LEAST64_MAX</span> UINT64_MAX</td>
- </tr>
- <tr>
- <td id="L158" class="blob-num js-line-number" data-line-number="158"></td>
- <td id="LC158" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L159" class="blob-num js-line-number" data-line-number="159"></td>
- <td id="LC159" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.2.3 Limits of fastest minimum-width integer types</span></td>
- </tr>
- <tr>
- <td id="L160" class="blob-num js-line-number" data-line-number="160"></td>
- <td id="LC160" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_FAST8_MIN</span> INT8_MIN</td>
- </tr>
- <tr>
- <td id="L161" class="blob-num js-line-number" data-line-number="161"></td>
- <td id="LC161" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_FAST8_MAX</span> INT8_MAX</td>
- </tr>
- <tr>
- <td id="L162" class="blob-num js-line-number" data-line-number="162"></td>
- <td id="LC162" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_FAST16_MIN</span> INT16_MIN</td>
- </tr>
- <tr>
- <td id="L163" class="blob-num js-line-number" data-line-number="163"></td>
- <td id="LC163" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_FAST16_MAX</span> INT16_MAX</td>
- </tr>
- <tr>
- <td id="L164" class="blob-num js-line-number" data-line-number="164"></td>
- <td id="LC164" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_FAST32_MIN</span> INT32_MIN</td>
- </tr>
- <tr>
- <td id="L165" class="blob-num js-line-number" data-line-number="165"></td>
- <td id="LC165" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_FAST32_MAX</span> INT32_MAX</td>
- </tr>
- <tr>
- <td id="L166" class="blob-num js-line-number" data-line-number="166"></td>
- <td id="LC166" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_FAST64_MIN</span> INT64_MIN</td>
- </tr>
- <tr>
- <td id="L167" class="blob-num js-line-number" data-line-number="167"></td>
- <td id="LC167" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT_FAST64_MAX</span> INT64_MAX</td>
- </tr>
- <tr>
- <td id="L168" class="blob-num js-line-number" data-line-number="168"></td>
- <td id="LC168" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT_FAST8_MAX</span> UINT8_MAX</td>
- </tr>
- <tr>
- <td id="L169" class="blob-num js-line-number" data-line-number="169"></td>
- <td id="LC169" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT_FAST16_MAX</span> UINT16_MAX</td>
- </tr>
- <tr>
- <td id="L170" class="blob-num js-line-number" data-line-number="170"></td>
- <td id="LC170" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT_FAST32_MAX</span> UINT32_MAX</td>
- </tr>
- <tr>
- <td id="L171" class="blob-num js-line-number" data-line-number="171"></td>
- <td id="LC171" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT_FAST64_MAX</span> UINT64_MAX</td>
- </tr>
- <tr>
- <td id="L172" class="blob-num js-line-number" data-line-number="172"></td>
- <td id="LC172" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L173" class="blob-num js-line-number" data-line-number="173"></td>
- <td id="LC173" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.2.4 Limits of integer types capable of holding object pointers</span></td>
- </tr>
- <tr>
- <td id="L174" class="blob-num js-line-number" data-line-number="174"></td>
- <td id="LC174" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifdef</span> _WIN64 <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L175" class="blob-num js-line-number" data-line-number="175"></td>
- <td id="LC175" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">INTPTR_MIN</span> INT64_MIN</td>
- </tr>
- <tr>
- <td id="L176" class="blob-num js-line-number" data-line-number="176"></td>
- <td id="LC176" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">INTPTR_MAX</span> INT64_MAX</td>
- </tr>
- <tr>
- <td id="L177" class="blob-num js-line-number" data-line-number="177"></td>
- <td id="LC177" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">UINTPTR_MAX</span> UINT64_MAX</td>
- </tr>
- <tr>
- <td id="L178" class="blob-num js-line-number" data-line-number="178"></td>
- <td id="LC178" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">else</span> <span class="pl-c"><span class="pl-c">//</span> _WIN64 ][</span></td>
- </tr>
- <tr>
- <td id="L179" class="blob-num js-line-number" data-line-number="179"></td>
- <td id="LC179" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">INTPTR_MIN</span> INT32_MIN</td>
- </tr>
- <tr>
- <td id="L180" class="blob-num js-line-number" data-line-number="180"></td>
- <td id="LC180" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">INTPTR_MAX</span> INT32_MAX</td>
- </tr>
- <tr>
- <td id="L181" class="blob-num js-line-number" data-line-number="181"></td>
- <td id="LC181" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">UINTPTR_MAX</span> UINT32_MAX</td>
- </tr>
- <tr>
- <td id="L182" class="blob-num js-line-number" data-line-number="182"></td>
- <td id="LC182" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> _WIN64 ]</span></td>
- </tr>
- <tr>
- <td id="L183" class="blob-num js-line-number" data-line-number="183"></td>
- <td id="LC183" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L184" class="blob-num js-line-number" data-line-number="184"></td>
- <td id="LC184" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.2.5 Limits of greatest-width integer types</span></td>
- </tr>
- <tr>
- <td id="L185" class="blob-num js-line-number" data-line-number="185"></td>
- <td id="LC185" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INTMAX_MIN</span> INT64_MIN</td>
- </tr>
- <tr>
- <td id="L186" class="blob-num js-line-number" data-line-number="186"></td>
- <td id="LC186" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INTMAX_MAX</span> INT64_MAX</td>
- </tr>
- <tr>
- <td id="L187" class="blob-num js-line-number" data-line-number="187"></td>
- <td id="LC187" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINTMAX_MAX</span> UINT64_MAX</td>
- </tr>
- <tr>
- <td id="L188" class="blob-num js-line-number" data-line-number="188"></td>
- <td id="LC188" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L189" class="blob-num js-line-number" data-line-number="189"></td>
- <td id="LC189" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.3 Limits of other integer types</span></td>
- </tr>
- <tr>
- <td id="L190" class="blob-num js-line-number" data-line-number="190"></td>
- <td id="LC190" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L191" class="blob-num js-line-number" data-line-number="191"></td>
- <td id="LC191" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifdef</span> _WIN64 <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L192" class="blob-num js-line-number" data-line-number="192"></td>
- <td id="LC192" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">PTRDIFF_MIN</span> _I64_MIN</td>
- </tr>
- <tr>
- <td id="L193" class="blob-num js-line-number" data-line-number="193"></td>
- <td id="LC193" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">PTRDIFF_MAX</span> _I64_MAX</td>
- </tr>
- <tr>
- <td id="L194" class="blob-num js-line-number" data-line-number="194"></td>
- <td id="LC194" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">else</span> <span class="pl-c"><span class="pl-c">//</span> _WIN64 ][</span></td>
- </tr>
- <tr>
- <td id="L195" class="blob-num js-line-number" data-line-number="195"></td>
- <td id="LC195" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">PTRDIFF_MIN</span> _I32_MIN</td>
- </tr>
- <tr>
- <td id="L196" class="blob-num js-line-number" data-line-number="196"></td>
- <td id="LC196" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">PTRDIFF_MAX</span> _I32_MAX</td>
- </tr>
- <tr>
- <td id="L197" class="blob-num js-line-number" data-line-number="197"></td>
- <td id="LC197" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> _WIN64 ]</span></td>
- </tr>
- <tr>
- <td id="L198" class="blob-num js-line-number" data-line-number="198"></td>
- <td id="LC198" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L199" class="blob-num js-line-number" data-line-number="199"></td>
- <td id="LC199" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">SIG_ATOMIC_MIN</span> INT_MIN</td>
- </tr>
- <tr>
- <td id="L200" class="blob-num js-line-number" data-line-number="200"></td>
- <td id="LC200" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">SIG_ATOMIC_MAX</span> INT_MAX</td>
- </tr>
- <tr>
- <td id="L201" class="blob-num js-line-number" data-line-number="201"></td>
- <td id="LC201" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L202" class="blob-num js-line-number" data-line-number="202"></td>
- <td id="LC202" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifndef</span> SIZE_MAX <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L203" class="blob-num js-line-number" data-line-number="203"></td>
- <td id="LC203" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">ifdef</span> _WIN64 <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L204" class="blob-num js-line-number" data-line-number="204"></td>
- <td id="LC204" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">SIZE_MAX</span> _UI64_MAX</td>
- </tr>
- <tr>
- <td id="L205" class="blob-num js-line-number" data-line-number="205"></td>
- <td id="LC205" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">else</span> <span class="pl-c"><span class="pl-c">//</span> _WIN64 ][</span></td>
- </tr>
- <tr>
- <td id="L206" class="blob-num js-line-number" data-line-number="206"></td>
- <td id="LC206" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">SIZE_MAX</span> _UI32_MAX</td>
- </tr>
- <tr>
- <td id="L207" class="blob-num js-line-number" data-line-number="207"></td>
- <td id="LC207" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> _WIN64 ]</span></td>
- </tr>
- <tr>
- <td id="L208" class="blob-num js-line-number" data-line-number="208"></td>
- <td id="LC208" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> SIZE_MAX ]</span></td>
- </tr>
- <tr>
- <td id="L209" class="blob-num js-line-number" data-line-number="209"></td>
- <td id="LC209" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L210" class="blob-num js-line-number" data-line-number="210"></td>
- <td id="LC210" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> WCHAR_MIN and WCHAR_MAX are also defined in &lt;wchar.h&gt;</span></td>
- </tr>
- <tr>
- <td id="L211" class="blob-num js-line-number" data-line-number="211"></td>
- <td id="LC211" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifndef</span> WCHAR_MIN <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L212" class="blob-num js-line-number" data-line-number="212"></td>
- <td id="LC212" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">WCHAR_MIN</span> <span class="pl-c1">0</span></td>
- </tr>
- <tr>
- <td id="L213" class="blob-num js-line-number" data-line-number="213"></td>
- <td id="LC213" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> WCHAR_MIN ]</span></td>
- </tr>
- <tr>
- <td id="L214" class="blob-num js-line-number" data-line-number="214"></td>
- <td id="LC214" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">ifndef</span> WCHAR_MAX <span class="pl-c"><span class="pl-c">//</span> [</span></td>
- </tr>
- <tr>
- <td id="L215" class="blob-num js-line-number" data-line-number="215"></td>
- <td id="LC215" class="blob-code blob-code-inner js-file-line"># <span class="pl-k">define</span> <span class="pl-en">WCHAR_MAX</span> _UI16_MAX</td>
- </tr>
- <tr>
- <td id="L216" class="blob-num js-line-number" data-line-number="216"></td>
- <td id="LC216" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> WCHAR_MAX ]</span></td>
- </tr>
- <tr>
- <td id="L217" class="blob-num js-line-number" data-line-number="217"></td>
- <td id="LC217" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L218" class="blob-num js-line-number" data-line-number="218"></td>
- <td id="LC218" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">WINT_MIN</span> <span class="pl-c1">0</span></td>
- </tr>
- <tr>
- <td id="L219" class="blob-num js-line-number" data-line-number="219"></td>
- <td id="LC219" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">WINT_MAX</span> _UI16_MAX</td>
- </tr>
- <tr>
- <td id="L220" class="blob-num js-line-number" data-line-number="220"></td>
- <td id="LC220" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L221" class="blob-num js-line-number" data-line-number="221"></td>
- <td id="LC221" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> __STDC_LIMIT_MACROS ]</span></td>
- </tr>
- <tr>
- <td id="L222" class="blob-num js-line-number" data-line-number="222"></td>
- <td id="LC222" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L223" class="blob-num js-line-number" data-line-number="223"></td>
- <td id="LC223" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L224" class="blob-num js-line-number" data-line-number="224"></td>
- <td id="LC224" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.4 Limits of other integer types</span></td>
- </tr>
- <tr>
- <td id="L225" class="blob-num js-line-number" data-line-number="225"></td>
- <td id="LC225" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L226" class="blob-num js-line-number" data-line-number="226"></td>
- <td id="LC226" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">if</span> !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) <span class="pl-c"><span class="pl-c">//</span> [ See footnote 224 at page 260</span></td>
- </tr>
- <tr>
- <td id="L227" class="blob-num js-line-number" data-line-number="227"></td>
- <td id="LC227" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L228" class="blob-num js-line-number" data-line-number="228"></td>
- <td id="LC228" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.4.1 Macros for minimum-width integer constants</span></td>
- </tr>
- <tr>
- <td id="L229" class="blob-num js-line-number" data-line-number="229"></td>
- <td id="LC229" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L230" class="blob-num js-line-number" data-line-number="230"></td>
- <td id="LC230" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT8_C</span>(<span class="pl-v">val</span>) val##i8</td>
- </tr>
- <tr>
- <td id="L231" class="blob-num js-line-number" data-line-number="231"></td>
- <td id="LC231" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT16_C</span>(<span class="pl-v">val</span>) val##i16</td>
- </tr>
- <tr>
- <td id="L232" class="blob-num js-line-number" data-line-number="232"></td>
- <td id="LC232" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT32_C</span>(<span class="pl-v">val</span>) val##i32</td>
- </tr>
- <tr>
- <td id="L233" class="blob-num js-line-number" data-line-number="233"></td>
- <td id="LC233" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INT64_C</span>(<span class="pl-v">val</span>) val##i64</td>
- </tr>
- <tr>
- <td id="L234" class="blob-num js-line-number" data-line-number="234"></td>
- <td id="LC234" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L235" class="blob-num js-line-number" data-line-number="235"></td>
- <td id="LC235" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT8_C</span>(<span class="pl-v">val</span>) val##ui8</td>
- </tr>
- <tr>
- <td id="L236" class="blob-num js-line-number" data-line-number="236"></td>
- <td id="LC236" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT16_C</span>(<span class="pl-v">val</span>) val##ui16</td>
- </tr>
- <tr>
- <td id="L237" class="blob-num js-line-number" data-line-number="237"></td>
- <td id="LC237" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT32_C</span>(<span class="pl-v">val</span>) val##ui32</td>
- </tr>
- <tr>
- <td id="L238" class="blob-num js-line-number" data-line-number="238"></td>
- <td id="LC238" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINT64_C</span>(<span class="pl-v">val</span>) val##ui64</td>
- </tr>
- <tr>
- <td id="L239" class="blob-num js-line-number" data-line-number="239"></td>
- <td id="LC239" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L240" class="blob-num js-line-number" data-line-number="240"></td>
- <td id="LC240" class="blob-code blob-code-inner js-file-line"><span class="pl-c"><span class="pl-c">//</span> 7.18.4.2 Macros for greatest-width integer constants</span></td>
- </tr>
- <tr>
- <td id="L241" class="blob-num js-line-number" data-line-number="241"></td>
- <td id="LC241" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">INTMAX_C</span> INT64_C</td>
- </tr>
- <tr>
- <td id="L242" class="blob-num js-line-number" data-line-number="242"></td>
- <td id="LC242" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">UINTMAX_C</span> UINT64_C</td>
- </tr>
- <tr>
- <td id="L243" class="blob-num js-line-number" data-line-number="243"></td>
- <td id="LC243" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L244" class="blob-num js-line-number" data-line-number="244"></td>
- <td id="LC244" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">endif</span> <span class="pl-c"><span class="pl-c">//</span> __STDC_CONSTANT_MACROS ]</span></td>
- </tr>
- <tr>
- <td id="L245" class="blob-num js-line-number" data-line-number="245"></td>
- <td id="LC245" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L246" class="blob-num js-line-number" data-line-number="246"></td>
- <td id="LC246" class="blob-code blob-code-inner js-file-line">
-</td>
- </tr>
- <tr>
- <td id="L247" class="blob-num js-line-number" data-line-number="247"></td>
- <td id="LC247" class="blob-code blob-code-inner js-file-line">#endif <span class="pl-c"><span class="pl-c">//</span> _MSC_STDINT_H_ ]</span></td>
- </tr>
-</table>
-
- <div class="BlobToolbar position-absolute js-file-line-actions dropdown js-menu-container js-select-menu d-none" aria-hidden="true">
- <button class="btn-octicon ml-0 px-2 p-0 bg-white border border-gray-dark rounded-1 dropdown-toggle js-menu-target" id="js-file-line-action-button" type="button" aria-expanded="false" aria-haspopup="true" aria-label="Inline file action toolbar" aria-controls="inline-file-actions">
- <svg aria-hidden="true" class="octicon" height="16" version="1.1" viewBox="0 0 13 4" width="14">
- <g stroke="none" stroke-width="1" fill-rule="evenodd">
- <g transform="translate(-1.000000, -6.000000)">
- <path d="M2.5,9.5 C1.67157288,9.5 1,8.82842712 1,8 C1,7.17157288 1.67157288,6.5 2.5,6.5 C3.32842712,6.5 4,7.17157288 4,8 C4,8.82842712 3.32842712,9.5 2.5,9.5 Z M7.5,9.5 C6.67157288,9.5 6,8.82842712 6,8 C6,7.17157288 6.67157288,6.5 7.5,6.5 C8.32842712,6.5 9,7.17157288 9,8 C9,8.82842712 8.32842712,9.5 7.5,9.5 Z M12.5,9.5 C11.6715729,9.5 11,8.82842712 11,8 C11,7.17157288 11.6715729,6.5 12.5,6.5 C13.3284271,6.5 14,7.17157288 14,8 C14,8.82842712 13.3284271,9.5 12.5,9.5 Z"></path>
- </g>
- </g>
- </svg>
- </button>
- <div class="dropdown-menu-content js-menu-content" id="inline-file-actions">
- <ul class="BlobToolbar-dropdown dropdown-menu dropdown-menu-se mt-2">
- <li><a class="js-zeroclipboard dropdown-item" style="cursor:pointer;" id="js-copy-lines" data-original-text="Copy lines">Copy lines</a></li>
- <li><a class="js-zeroclipboard dropdown-item" id= "js-copy-permalink" style="cursor:pointer;" data-original-text="Copy permalink">Copy permalink</a></li>
- <li><a href="/mattn/gntp-send/blame/090b1276fb4a30601113551bed88c58329646818/include/msinttypes/stdint.h" class="dropdown-item js-update-url-with-hash" id="js-view-git-blame">View git blame</a></li>
- <li><a href="/mattn/gntp-send/issues/new" class="dropdown-item" id="js-new-issue">Open new issue</a></li>
- </ul>
- </div>
- </div>
-
- </div>
-
- </div>
-
- <button type="button" data-facebox="#jump-to-line" data-facebox-class="linejump" data-hotkey="l" class="d-none">Jump to Line</button>
- <div id="jump-to-line" style="display:none">
- <!-- '"` --><!-- </textarea></xmp> --></option></form><form accept-charset="UTF-8" action="" class="js-jump-to-line-form" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
- <input class="form-control linejump-input js-jump-to-line-field" type="text" placeholder="Jump to line&hellip;" aria-label="Jump to line" autofocus>
- <button type="submit" class="btn">Go</button>
-</form> </div>
-
- </div>
- <div class="modal-backdrop js-touch-events"></div>
-</div>
-
- </div>
- </div>
-
- </div>
-
-
-<div class="footer container-lg px-3" role="contentinfo">
- <div class="position-relative d-flex flex-justify-between py-6 mt-6 f6 text-gray border-top border-gray-light ">
- <ul class="list-style-none d-flex flex-wrap ">
- <li class="mr-3">&copy; 2017 <span title="0.12140s from unicorn-1420858540-p0bxs">GitHub</span>, Inc.</li>
- <li class="mr-3"><a href="https://github.com/site/terms" data-ga-click="Footer, go to terms, text:terms">Terms</a></li>
- <li class="mr-3"><a href="https://github.com/site/privacy" data-ga-click="Footer, go to privacy, text:privacy">Privacy</a></li>
- <li class="mr-3"><a href="https://github.com/security" data-ga-click="Footer, go to security, text:security">Security</a></li>
- <li class="mr-3"><a href="https://status.github.com/" data-ga-click="Footer, go to status, text:status">Status</a></li>
- <li><a href="https://help.github.com" data-ga-click="Footer, go to help, text:help">Help</a></li>
- </ul>
-
- <a href="https://github.com" aria-label="Homepage" class="footer-octicon" title="GitHub">
- <svg aria-hidden="true" class="octicon octicon-mark-github" height="24" version="1.1" viewBox="0 0 16 16" width="24"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
-</a>
- <ul class="list-style-none d-flex flex-wrap ">
- <li class="mr-3"><a href="https://github.com/contact" data-ga-click="Footer, go to contact, text:contact">Contact GitHub</a></li>
- <li class="mr-3"><a href="https://developer.github.com" data-ga-click="Footer, go to api, text:api">API</a></li>
- <li class="mr-3"><a href="https://training.github.com" data-ga-click="Footer, go to training, text:training">Training</a></li>
- <li class="mr-3"><a href="https://shop.github.com" data-ga-click="Footer, go to shop, text:shop">Shop</a></li>
- <li class="mr-3"><a href="https://github.com/blog" data-ga-click="Footer, go to blog, text:blog">Blog</a></li>
- <li><a href="https://github.com/about" data-ga-click="Footer, go to about, text:about">About</a></li>
-
- </ul>
- </div>
-</div>
-
-
-
- <div id="ajax-error-message" class="ajax-error-message flash flash-error">
- <svg aria-hidden="true" class="octicon octicon-alert" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.865 1.52c-.18-.31-.51-.5-.87-.5s-.69.19-.87.5L.275 13.5c-.18.31-.18.69 0 1 .19.31.52.5.87.5h13.7c.36 0 .69-.19.86-.5.17-.31.18-.69.01-1L8.865 1.52zM8.995 13h-2v-2h2v2zm0-3h-2V6h2v4z"/></svg>
- <button type="button" class="flash-close js-flash-close js-ajax-error-dismiss" aria-label="Dismiss error">
- <svg aria-hidden="true" class="octicon octicon-x" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"/></svg>
- </button>
- You can't perform that action at this time.
- </div>
-
-
-
- <script crossorigin="anonymous" integrity="sha256-Sxs+Reu4luxVVaYLalcHLGmPG0uGt2qgtP4QZ/RAsfM=" src="https://assets-cdn.github.com/assets/frameworks-4b1b3e45ebb896ec5555a60b6a57072c698f1b4b86b76aa0b4fe1067f440b1f3.js"></script>
-
- <script async="async" crossorigin="anonymous" integrity="sha256-rhTSU9vJG0Aq7OSJ05kyOeUQ/RwV/IBUApQ7VS8xXXM=" src="https://assets-cdn.github.com/assets/github-ae14d253dbc91b402aece489d3993239e510fd1c15fc805402943b552f315d73.js"></script>
-
-
-
-
- <div class="js-stale-session-flash stale-session-flash flash flash-warn flash-banner d-none">
- <svg aria-hidden="true" class="octicon octicon-alert" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M8.865 1.52c-.18-.31-.51-.5-.87-.5s-.69.19-.87.5L.275 13.5c-.18.31-.18.69 0 1 .19.31.52.5.87.5h13.7c.36 0 .69-.19.86-.5.17-.31.18-.69.01-1L8.865 1.52zM8.995 13h-2v-2h2v2zm0-3h-2V6h2v4z"/></svg>
- <span class="signed-in-tab-flash">You signed in with another tab or window. <a href="">Reload</a> to refresh your session.</span>
- <span class="signed-out-tab-flash">You signed out in another tab or window. <a href="">Reload</a> to refresh your session.</span>
- </div>
- <div class="facebox" id="facebox" style="display:none;">
- <div class="facebox-popup">
- <div class="facebox-content" role="dialog" aria-labelledby="facebox-header" aria-describedby="facebox-description">
- </div>
- <button type="button" class="facebox-close js-facebox-close" aria-label="Close modal">
- <svg aria-hidden="true" class="octicon octicon-x" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path fill-rule="evenodd" d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"/></svg>
- </button>
- </div>
-</div>
-
-
- </body>
-</html>
-
diff --git a/src/sat/glucose2/AbcGlucose2.cpp b/src/sat/glucose2/AbcGlucose2.cpp
new file mode 100644
index 00000000..9a8b97eb
--- /dev/null
+++ b/src/sat/glucose2/AbcGlucose2.cpp
@@ -0,0 +1,1543 @@
+/**CFile****************************************************************
+
+ FileName [AbcGlucose.cpp]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [SAT solver Glucose 3.0 by Gilles Audemard and Laurent Simon.]
+
+ Synopsis [Interface to Glucose.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - September 6, 2017.]
+
+ Revision [$Id: AbcGlucose.cpp,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "sat/glucose2/System.h"
+#include "sat/glucose2/ParseUtils.h"
+#include "sat/glucose2/Options.h"
+#include "sat/glucose2/Dimacs.h"
+#include "sat/glucose2/SimpSolver.h"
+
+#include "sat/glucose2/AbcGlucose2.h"
+
+#include "base/abc/abc.h"
+#include "aig/gia/gia.h"
+#include "sat/cnf/cnf.h"
+#include "misc/extra/extra.h"
+
+ABC_NAMESPACE_IMPL_START
+
+using namespace Gluco2;
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+#define USE_SIMP_SOLVER 1
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+#ifdef USE_SIMP_SOLVER
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+SimpSolver * glucose2_solver_start()
+{
+ SimpSolver * S = new SimpSolver;
+ S->setIncrementalMode();
+ return S;
+}
+
+void glucose2_solver_stop(Gluco2::SimpSolver* S)
+{
+ delete S;
+}
+
+void glucose2_solver_reset(Gluco2::SimpSolver* S)
+{
+ S->reset();
+}
+
+int glucose2_solver_addclause(Gluco2::SimpSolver* S, int * plits, int nlits)
+{
+ vec<Lit> lits;
+ for ( int i = 0; i < nlits; i++,plits++)
+ {
+ // note: Glucose uses the same var->lit conventiaon as ABC
+ while ((*plits)/2 >= S->nVars()) S->newVar();
+ assert((*plits)/2 < S->nVars()); // NOTE: since we explicitely use new function bmc_add_var
+ Lit p;
+ p.x = *plits;
+ lits.push(p);
+ }
+ return S->addClause(lits); // returns 0 if the problem is UNSAT
+}
+
+void glucose2_solver_setcallback(Gluco2::SimpSolver* S, void * pman, int(*pfunc)(void*, int, int*))
+{
+ S->pCnfMan = pman;
+ S->pCnfFunc = pfunc;
+ S->nCallConfl = 1000;
+}
+
+int glucose2_solver_solve(Gluco2::SimpSolver* S, int * plits, int nlits)
+{
+// vec<Lit> lits;
+// for (int i=0;i<nlits;i++,plits++)
+// {
+// Lit p;
+// p.x = *plits;
+// lits.push(p);
+// }
+// Gluco2::lbool res = S->solveLimited(lits, 0);
+// return (res == l_True ? 1 : res == l_False ? -1 : 0);
+ return S->solveLimited(plits, nlits, 0);
+}
+
+int glucose2_solver_addvar(Gluco2::SimpSolver* S)
+{
+ S->newVar();
+ return S->nVars() - 1;
+}
+
+int * glucose2_solver_read_cex(Gluco2::SimpSolver* S )
+{
+ return S->getCex();
+}
+
+int glucose2_solver_read_cex_varvalue(Gluco2::SimpSolver* S, int ivar)
+{
+ return S->model[ivar] == l_True;
+}
+
+void glucose2_solver_setstop(Gluco2::SimpSolver* S, int * pstop)
+{
+ S->pstop = pstop;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Wrapper APIs to calling from ABC.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+bmcg2_sat_solver * bmcg2_sat_solver_start()
+{
+ return (bmcg2_sat_solver *)glucose2_solver_start();
+}
+void bmcg2_sat_solver_stop(bmcg2_sat_solver* s)
+{
+ glucose2_solver_stop((Gluco2::SimpSolver*)s);
+}
+void bmcg2_sat_solver_reset(bmcg2_sat_solver* s)
+{
+ glucose2_solver_reset((Gluco2::SimpSolver*)s);
+}
+
+
+int bmcg2_sat_solver_addclause(bmcg2_sat_solver* s, int * plits, int nlits)
+{
+ return glucose2_solver_addclause((Gluco2::SimpSolver*)s,plits,nlits);
+}
+
+void bmcg2_sat_solver_setcallback(bmcg2_sat_solver* s, void * pman, int(*pfunc)(void*, int, int*))
+{
+ glucose2_solver_setcallback((Gluco2::SimpSolver*)s,pman,pfunc);
+}
+
+int bmcg2_sat_solver_solve(bmcg2_sat_solver* s, int * plits, int nlits)
+{
+ return glucose2_solver_solve((Gluco2::SimpSolver*)s,plits,nlits);
+}
+
+int bmcg2_sat_solver_final(bmcg2_sat_solver* s, int ** ppArray)
+{
+ *ppArray = (int *)(Lit *)((Gluco2::SimpSolver*)s)->conflict;
+ return ((Gluco2::SimpSolver*)s)->conflict.size();
+}
+
+int bmcg2_sat_solver_addvar(bmcg2_sat_solver* s)
+{
+ return glucose2_solver_addvar((Gluco2::SimpSolver*)s);
+}
+
+void bmcg2_sat_solver_set_nvars( bmcg2_sat_solver* s, int nvars )
+{
+ int i;
+ for ( i = bmcg2_sat_solver_varnum(s); i < nvars; i++ )
+ bmcg2_sat_solver_addvar(s);
+}
+
+int bmcg2_sat_solver_eliminate( bmcg2_sat_solver* s, int turn_off_elim )
+{
+// return 1;
+ return ((Gluco2::SimpSolver*)s)->eliminate(turn_off_elim != 0);
+}
+
+int bmcg2_sat_solver_var_is_elim( bmcg2_sat_solver* s, int v )
+{
+// return 0;
+ return ((Gluco2::SimpSolver*)s)->isEliminated(v);
+}
+
+void bmcg2_sat_solver_var_set_frozen( bmcg2_sat_solver* s, int v, int freeze )
+{
+ ((Gluco2::SimpSolver*)s)->setFrozen(v, freeze != 0);
+}
+
+int bmcg2_sat_solver_elim_varnum(bmcg2_sat_solver* s)
+{
+// return 0;
+ return ((Gluco2::SimpSolver*)s)->eliminated_vars;
+}
+
+int * bmcg2_sat_solver_read_cex(bmcg2_sat_solver* s)
+{
+ return glucose2_solver_read_cex((Gluco2::SimpSolver*)s);
+}
+int bmcg2_sat_solver_read_cex_varvalue(bmcg2_sat_solver* s, int ivar)
+{
+ return glucose2_solver_read_cex_varvalue((Gluco2::SimpSolver*)s, ivar);
+}
+
+void bmcg2_sat_solver_set_stop(bmcg2_sat_solver* s, int * pstop)
+{
+ glucose2_solver_setstop((Gluco2::SimpSolver*)s, pstop);
+}
+
+abctime bmcg2_sat_solver_set_runtime_limit(bmcg2_sat_solver* s, abctime Limit)
+{
+ abctime nRuntimeLimit = ((Gluco2::SimpSolver*)s)->nRuntimeLimit;
+ ((Gluco2::SimpSolver*)s)->nRuntimeLimit = Limit;
+ return nRuntimeLimit;
+}
+
+void bmcg2_sat_solver_set_conflict_budget(bmcg2_sat_solver* s, int Limit)
+{
+ if ( Limit > 0 )
+ ((Gluco2::SimpSolver*)s)->setConfBudget( (int64_t)Limit );
+ else
+ ((Gluco2::SimpSolver*)s)->budgetOff();
+}
+
+int bmcg2_sat_solver_varnum(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::SimpSolver*)s)->nVars();
+}
+int bmcg2_sat_solver_clausenum(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::SimpSolver*)s)->nClauses();
+}
+int bmcg2_sat_solver_learntnum(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::SimpSolver*)s)->nLearnts();
+}
+int bmcg2_sat_solver_conflictnum(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::SimpSolver*)s)->conflicts;
+}
+
+int bmcg2_sat_solver_minimize_assumptions( bmcg2_sat_solver * s, int * plits, int nlits, int pivot )
+{
+ vec<int>*array = &((Gluco2::SimpSolver*)s)->user_vec;
+ int i, nlitsL, nlitsR, nresL, nresR, status;
+ assert( pivot >= 0 );
+// assert( nlits - pivot >= 2 );
+ assert( nlits - pivot >= 1 );
+ if ( nlits - pivot == 1 )
+ {
+ // since the problem is UNSAT, we try to solve it without assuming the last literal
+ // if the result is UNSAT, the last literal can be dropped; otherwise, it is needed
+ status = bmcg2_sat_solver_solve( s, plits, pivot );
+ return status != GLUCOSE_UNSAT; // return 1 if the problem is not UNSAT
+ }
+ assert( nlits - pivot >= 2 );
+ nlitsL = (nlits - pivot) / 2;
+ nlitsR = (nlits - pivot) - nlitsL;
+ assert( nlitsL + nlitsR == nlits - pivot );
+ // solve with these assumptions
+ status = bmcg2_sat_solver_solve( s, plits, pivot + nlitsL );
+ if ( status == GLUCOSE_UNSAT ) // these are enough
+ return bmcg2_sat_solver_minimize_assumptions( s, plits, pivot + nlitsL, pivot );
+ // these are not enough
+ // solve for the right lits
+// nResL = nLitsR == 1 ? 1 : sat_solver_minimize_assumptions( s, pLits + nLitsL, nLitsR, nConfLimit );
+ nresL = nlitsR == 1 ? 1 : bmcg2_sat_solver_minimize_assumptions( s, plits, nlits, pivot + nlitsL );
+ // swap literals
+ array->clear();
+ for ( i = 0; i < nlitsL; i++ )
+ array->push(plits[pivot + i]);
+ for ( i = 0; i < nresL; i++ )
+ plits[pivot + i] = plits[pivot + nlitsL + i];
+ for ( i = 0; i < nlitsL; i++ )
+ plits[pivot + nresL + i] = (*array)[i];
+ // solve with these assumptions
+ status = bmcg2_sat_solver_solve( s, plits, pivot + nresL );
+ if ( status == GLUCOSE_UNSAT ) // these are enough
+ return nresL;
+ // solve for the left lits
+// nResR = nLitsL == 1 ? 1 : sat_solver_minimize_assumptions( s, pLits + nResL, nLitsL, nConfLimit );
+ nresR = nlitsL == 1 ? 1 : bmcg2_sat_solver_minimize_assumptions( s, plits, pivot + nresL + nlitsL, pivot + nresL );
+ return nresL + nresR;
+}
+
+int bmcg2_sat_solver_add_and( bmcg2_sat_solver * s, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl )
+{
+ int Lits[3];
+
+ Lits[0] = Abc_Var2Lit( iVar, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVar0, fCompl0 );
+ if ( !bmcg2_sat_solver_addclause( s, Lits, 2 ) )
+ return 0;
+
+ Lits[0] = Abc_Var2Lit( iVar, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVar1, fCompl1 );
+ if ( !bmcg2_sat_solver_addclause( s, Lits, 2 ) )
+ return 0;
+
+ Lits[0] = Abc_Var2Lit( iVar, fCompl );
+ Lits[1] = Abc_Var2Lit( iVar0, !fCompl0 );
+ Lits[2] = Abc_Var2Lit( iVar1, !fCompl1 );
+ if ( !bmcg2_sat_solver_addclause( s, Lits, 3 ) )
+ return 0;
+
+ return 1;
+}
+
+int bmcg2_sat_solver_add_xor( bmcg2_sat_solver * pSat, int iVarA, int iVarB, int iVarC, int fCompl )
+{
+ int Lits[3];
+ int Cid;
+ assert( iVarA >= 0 && iVarB >= 0 && iVarC >= 0 );
+
+ Lits[0] = Abc_Var2Lit( iVarA, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 1 );
+ Lits[2] = Abc_Var2Lit( iVarC, 1 );
+ Cid = bmcg2_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 0 );
+ Lits[2] = Abc_Var2Lit( iVarC, 0 );
+ Cid = bmcg2_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 1 );
+ Lits[2] = Abc_Var2Lit( iVarC, 0 );
+ Cid = bmcg2_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 0 );
+ Lits[2] = Abc_Var2Lit( iVarC, 1 );
+ Cid = bmcg2_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+ return 4;
+}
+
+int bmcg2_sat_solver_jftr(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::SimpSolver*)s)->jftr;
+}
+
+void bmcg2_sat_solver_set_jftr(bmcg2_sat_solver* s, int jftr)
+{
+ ((Gluco2::SimpSolver*)s)->jftr = jftr;
+}
+
+void bmcg2_sat_solver_set_var_fanin_lit(bmcg2_sat_solver* s, int var, int lit0, int lit1)
+{
+ ((Gluco2::SimpSolver*)s)->sat_solver_set_var_fanin_lit(var, lit0, lit1);
+}
+
+void bmcg2_sat_solver_start_new_round(bmcg2_sat_solver* s)
+{
+ ((Gluco2::SimpSolver*)s)->sat_solver_start_new_round();
+}
+
+void bmcg2_sat_solver_mark_cone(bmcg2_sat_solver* s, int var)
+{
+ ((Gluco2::SimpSolver*)s)->sat_solver_mark_cone(var);
+}
+
+void bmcg2_sat_solver_prelocate( bmcg2_sat_solver * s, int var_num ){
+ ((Gluco2::SimpSolver*)s)->prelocate(var_num);
+}
+
+#else
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Solver * glucose2_solver_start()
+{
+ Solver * S = new Solver;
+ S->setIncrementalMode();
+ return S;
+}
+
+void glucose2_solver_stop(Gluco2::Solver* S)
+{
+ delete S;
+}
+
+void glucose2_solver_reset(Gluco2::Solver* S)
+{
+ S->reset();
+}
+
+int glucose2_solver_addclause(Gluco2::Solver* S, int * plits, int nlits)
+{
+ vec<Lit> lits;
+ for ( int i = 0; i < nlits; i++,plits++)
+ {
+ // note: Glucose uses the same var->lit conventiaon as ABC
+ while ((*plits)/2 >= S->nVars()) S->newVar();
+ assert((*plits)/2 < S->nVars()); // NOTE: since we explicitely use new function bmc_add_var
+ Lit p;
+ p.x = *plits;
+ lits.push(p);
+ }
+ return S->addClause(lits); // returns 0 if the problem is UNSAT
+}
+
+void glucose2_solver_setcallback(Gluco2::Solver* S, void * pman, int(*pfunc)(void*, int, int*))
+{
+ S->pCnfMan = pman;
+ S->pCnfFunc = pfunc;
+ S->nCallConfl = 1000;
+}
+
+int glucose2_solver_solve(Gluco2::Solver* S, int * plits, int nlits)
+{
+ vec<Lit> lits;
+ for (int i=0;i<nlits;i++,plits++)
+ {
+ Lit p;
+ p.x = *plits;
+ lits.push(p);
+ }
+ Gluco2::lbool res = S->solveLimited(lits);
+ return (res == l_True ? 1 : res == l_False ? -1 : 0);
+}
+
+int glucose2_solver_addvar(Gluco2::Solver* S)
+{
+ S->newVar();
+ return S->nVars() - 1;
+}
+
+int * glucose2_solver_read_cex(Gluco2::Solver* S )
+{
+ return S->getCex();
+}
+
+int glucose2_solver_read_cex_varvalue(Gluco2::Solver* S, int ivar)
+{
+ return S->model[ivar] == l_True;
+}
+
+void glucose2_solver_setstop(Gluco2::Solver* S, int * pstop)
+{
+ S->pstop = pstop;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Wrapper APIs to calling from ABC.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+bmcg2_sat_solver * bmcg2_sat_solver_start()
+{
+ return (bmcg2_sat_solver *)glucose2_solver_start();
+}
+void bmcg2_sat_solver_stop(bmcg2_sat_solver* s)
+{
+ glucose2_solver_stop((Gluco2::Solver*)s);
+}
+void bmcg2_sat_solver_reset(bmcg2_sat_solver* s)
+{
+ glucose2_solver_reset((Gluco2::Solver*)s);
+}
+
+int bmcg2_sat_solver_addclause(bmcg2_sat_solver* s, int * plits, int nlits)
+{
+ return glucose2_solver_addclause((Gluco2::Solver*)s,plits,nlits);
+}
+
+void bmcg2_sat_solver_setcallback(bmcg2_sat_solver* s, void * pman, int(*pfunc)(void*, int, int*))
+{
+ glucose2_solver_setcallback((Gluco2::Solver*)s,pman,pfunc);
+}
+
+int bmcg2_sat_solver_solve(bmcg2_sat_solver* s, int * plits, int nlits)
+{
+ return glucose2_solver_solve((Gluco2::Solver*)s,plits,nlits);
+}
+
+int bmcg2_sat_solver_final(bmcg2_sat_solver* s, int ** ppArray)
+{
+ *ppArray = (int *)(Lit *)((Gluco2::Solver*)s)->conflict;
+ return ((Gluco2::Solver*)s)->conflict.size();
+}
+
+int bmcg2_sat_solver_addvar(bmcg2_sat_solver* s)
+{
+ return glucose2_solver_addvar((Gluco2::Solver*)s);
+}
+
+void bmcg2_sat_solver_set_nvars( bmcg2_sat_solver* s, int nvars )
+{
+ int i;
+ for ( i = bmcg2_sat_solver_varnum(s); i < nvars; i++ )
+ bmcg2_sat_solver_addvar(s);
+}
+
+int bmcg2_sat_solver_eliminate( bmcg2_sat_solver* s, int turn_off_elim )
+{
+ return 1;
+// return ((Gluco2::SimpSolver*)s)->eliminate(turn_off_elim != 0);
+}
+
+int bmcg2_sat_solver_var_is_elim( bmcg2_sat_solver* s, int v )
+{
+ return 0;
+// return ((Gluco2::SimpSolver*)s)->isEliminated(v);
+}
+
+void bmcg2_sat_solver_var_set_frozen( bmcg2_sat_solver* s, int v, int freeze )
+{
+// ((Gluco2::SimpSolver*)s)->setFrozen(v, freeze);
+}
+
+int bmcg2_sat_solver_elim_varnum(bmcg2_sat_solver* s)
+{
+ return 0;
+// return ((Gluco2::SimpSolver*)s)->eliminated_vars;
+}
+
+int * bmcg2_sat_solver_read_cex(bmcg2_sat_solver* s)
+{
+ return glucose2_solver_read_cex((Gluco2::Solver*)s);
+}
+
+int bmcg2_sat_solver_read_cex_varvalue(bmcg2_sat_solver* s, int ivar)
+{
+ return glucose2_solver_read_cex_varvalue((Gluco2::Solver*)s, ivar);
+}
+
+void bmcg2_sat_solver_set_stop(bmcg2_sat_solver* s, int * pstop)
+{
+ glucose2_solver_setstop((Gluco2::Solver*)s, pstop);
+}
+
+abctime bmcg2_sat_solver_set_runtime_limit(bmcg2_sat_solver* s, abctime Limit)
+{
+ abctime nRuntimeLimit = ((Gluco2::Solver*)s)->nRuntimeLimit;
+ ((Gluco2::Solver*)s)->nRuntimeLimit = Limit;
+ return nRuntimeLimit;
+}
+
+void bmcg2_sat_solver_set_conflict_budget(bmcg2_sat_solver* s, int Limit)
+{
+ if ( Limit > 0 )
+ ((Gluco2::Solver*)s)->setConfBudget( (int64_t)Limit );
+ else
+ ((Gluco2::Solver*)s)->budgetOff();
+}
+
+int bmcg2_sat_solver_varnum(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::Solver*)s)->nVars();
+}
+int bmcg2_sat_solver_clausenum(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::Solver*)s)->nClauses();
+}
+int bmcg2_sat_solver_learntnum(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::Solver*)s)->nLearnts();
+}
+int bmcg2_sat_solver_conflictnum(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::Solver*)s)->conflicts;
+}
+
+int bmcg2_sat_solver_minimize_assumptions( bmcg2_sat_solver * s, int * plits, int nlits, int pivot )
+{
+ vec<int>*array = &((Gluco2::Solver*)s)->user_vec;
+ int i, nlitsL, nlitsR, nresL, nresR, status;
+ assert( pivot >= 0 );
+// assert( nlits - pivot >= 2 );
+ assert( nlits - pivot >= 1 );
+ if ( nlits - pivot == 1 )
+ {
+ // since the problem is UNSAT, we try to solve it without assuming the last literal
+ // if the result is UNSAT, the last literal can be dropped; otherwise, it is needed
+ status = bmcg2_sat_solver_solve( s, plits, pivot );
+ return status != GLUCOSE_UNSAT; // return 1 if the problem is not UNSAT
+ }
+ assert( nlits - pivot >= 2 );
+ nlitsL = (nlits - pivot) / 2;
+ nlitsR = (nlits - pivot) - nlitsL;
+ assert( nlitsL + nlitsR == nlits - pivot );
+ // solve with these assumptions
+ status = bmcg2_sat_solver_solve( s, plits, pivot + nlitsL );
+ if ( status == GLUCOSE_UNSAT ) // these are enough
+ return bmcg2_sat_solver_minimize_assumptions( s, plits, pivot + nlitsL, pivot );
+ // these are not enough
+ // solve for the right lits
+// nResL = nLitsR == 1 ? 1 : sat_solver_minimize_assumptions( s, pLits + nLitsL, nLitsR, nConfLimit );
+ nresL = nlitsR == 1 ? 1 : bmcg2_sat_solver_minimize_assumptions( s, plits, nlits, pivot + nlitsL );
+ // swap literals
+ array->clear();
+ for ( i = 0; i < nlitsL; i++ )
+ array->push(plits[pivot + i]);
+ for ( i = 0; i < nresL; i++ )
+ plits[pivot + i] = plits[pivot + nlitsL + i];
+ for ( i = 0; i < nlitsL; i++ )
+ plits[pivot + nresL + i] = (*array)[i];
+ // solve with these assumptions
+ status = bmcg2_sat_solver_solve( s, plits, pivot + nresL );
+ if ( status == GLUCOSE_UNSAT ) // these are enough
+ return nresL;
+ // solve for the left lits
+// nResR = nLitsL == 1 ? 1 : sat_solver_minimize_assumptions( s, pLits + nResL, nLitsL, nConfLimit );
+ nresR = nlitsL == 1 ? 1 : bmcg2_sat_solver_minimize_assumptions( s, plits, pivot + nresL + nlitsL, pivot + nresL );
+ return nresL + nresR;
+}
+
+int bmcg2_sat_solver_add_and( bmcg2_sat_solver * s, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl )
+{
+ int Lits[3];
+
+ Lits[0] = Abc_Var2Lit( iVar, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVar0, fCompl0 );
+ if ( !bmcg2_sat_solver_addclause( s, Lits, 2 ) )
+ return 0;
+
+ Lits[0] = Abc_Var2Lit( iVar, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVar1, fCompl1 );
+ if ( !bmcg2_sat_solver_addclause( s, Lits, 2 ) )
+ return 0;
+
+ Lits[0] = Abc_Var2Lit( iVar, fCompl );
+ Lits[1] = Abc_Var2Lit( iVar0, !fCompl0 );
+ Lits[2] = Abc_Var2Lit( iVar1, !fCompl1 );
+ if ( !bmcg2_sat_solver_addclause( s, Lits, 3 ) )
+ return 0;
+
+ return 1;
+}
+
+int bmcg2_solver_add_xor( bmcg2_sat_solver * pSat, int iVarA, int iVarB, int iVarC, int fCompl )
+{
+ int Lits[3];
+ int Cid;
+ assert( iVarA >= 0 && iVarB >= 0 && iVarC >= 0 );
+
+ Lits[0] = Abc_Var2Lit( iVarA, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 1 );
+ Lits[2] = Abc_Var2Lit( iVarC, 1 );
+ Cid = bmcg2_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, !fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 0 );
+ Lits[2] = Abc_Var2Lit( iVarC, 0 );
+ Cid = bmcg2_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 1 );
+ Lits[2] = Abc_Var2Lit( iVarC, 0 );
+ Cid = bmcg2_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+
+ Lits[0] = Abc_Var2Lit( iVarA, fCompl );
+ Lits[1] = Abc_Var2Lit( iVarB, 0 );
+ Lits[2] = Abc_Var2Lit( iVarC, 1 );
+ Cid = bmcg2_sat_solver_addclause( pSat, Lits, 3 );
+ assert( Cid );
+ return 4;
+}
+
+int bmcg2_sat_solver_jftr(bmcg2_sat_solver* s)
+{
+ return ((Gluco2::Solver*)s)->jftr;
+}
+
+void bmcg2_sat_solver_set_jftr(bmcg2_sat_solver* s, int jftr)
+{
+ ((Gluco2::Solver*)s)->jftr = jftr;
+}
+
+void bmcg2_sat_solver_set_var_fanin_lit(bmcg2_sat_solver* s, int var, int lit0, int lit1)
+{
+ ((Gluco2::Solver*)s)->sat_solver_set_var_fanin_lit(var, lit0, lit1);
+}
+
+void bmcg2_sat_solver_start_new_round(bmcg2_sat_solver* s)
+{
+ ((Gluco2::Solver*)s)->sat_solver_start_new_round();
+}
+
+void bmcg2_sat_solver_mark_cone(bmcg2_sat_solver* s, int var)
+{
+ ((Gluco2::Solver*)s)->sat_solver_mark_cone(var);
+}
+
+void bmcg2_sat_solver_prelocate( bmcg2_sat_solver * s, int var_num ){
+ ((Gluco2::Solver*)s)->prelocate(var_num);
+}
+
+#endif
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void glucose2_print_stats(SimpSolver& s, abctime clk)
+{
+ double cpu_time = (double)(unsigned)clk / CLOCKS_PER_SEC;
+ double mem_used = memUsed();
+ printf("c restarts : %d (%d conflicts on average)\n", (int)s.starts, s.starts > 0 ? (int)(s.conflicts/s.starts) : 0);
+ printf("c blocked restarts : %d (multiple: %d) \n", (int)s.nbstopsrestarts, (int)s.nbstopsrestartssame);
+ printf("c last block at restart : %d\n", (int)s.lastblockatrestart);
+ printf("c nb ReduceDB : %-12d\n", (int)s.nbReduceDB);
+ printf("c nb removed Clauses : %-12d\n", (int)s.nbRemovedClauses);
+ printf("c nb learnts DL2 : %-12d\n", (int)s.nbDL2);
+ printf("c nb learnts size 2 : %-12d\n", (int)s.nbBin);
+ printf("c nb learnts size 1 : %-12d\n", (int)s.nbUn);
+ printf("c conflicts : %-12d (%.0f /sec)\n", (int)s.conflicts, s.conflicts /cpu_time);
+ printf("c decisions : %-12d (%4.2f %% random) (%.0f /sec)\n", (int)s.decisions, (float)s.rnd_decisions*100 / (float)s.decisions, s.decisions /cpu_time);
+ printf("c propagations : %-12d (%.0f /sec)\n", (int)s.propagations, s.propagations/cpu_time);
+ printf("c conflict literals : %-12d (%4.2f %% deleted)\n", (int)s.tot_literals, (s.max_literals - s.tot_literals)*100 / (double)s.max_literals);
+ printf("c nb reduced Clauses : %-12d\n", (int)s.nbReducedClauses);
+ if (mem_used != 0) printf("Memory used : %.2f MB\n", mem_used);
+ //printf("c CPU time : %.2f sec\n", cpu_time);
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Glucose_ReadDimacs( char * pFileName, SimpSolver& s )
+{
+ vec<Lit> * lits = &s.user_lits;
+ char * pBuffer = Extra_FileReadContents( pFileName );
+ char * pTemp; int fComp, Var, VarMax = 0;
+ lits->clear();
+ for ( pTemp = pBuffer; *pTemp; pTemp++ )
+ {
+ if ( *pTemp == 'c' || *pTemp == 'p' ) {
+ while ( *pTemp != '\n' )
+ pTemp++;
+ continue;
+ }
+ while ( *pTemp == ' ' || *pTemp == '\t' || *pTemp == '\r' || *pTemp == '\n' )
+ pTemp++;
+ fComp = 0;
+ if ( *pTemp == '-' )
+ fComp = 1, pTemp++;
+ if ( *pTemp == '+' )
+ pTemp++;
+ Var = atoi( pTemp );
+ if ( Var == 0 ) {
+ if ( lits->size() > 0 ) {
+ s.addVar( VarMax );
+ s.addClause(*lits);
+ lits->clear();
+ }
+ }
+ else {
+ Var--;
+ VarMax = Abc_MaxInt( VarMax, Var );
+ lits->push( toLit(Abc_Var2Lit(Var, fComp)) );
+ }
+ while ( *pTemp >= '0' && *pTemp <= '9' )
+ pTemp++;
+ }
+ ABC_FREE( pBuffer );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Glucose2_SolveCnf( char * pFileName, Glucose2_Pars * pPars )
+{
+ abctime clk = Abc_Clock();
+
+ SimpSolver S;
+ S.verbosity = pPars->verb;
+ S.setConfBudget( pPars->nConfls > 0 ? (int64_t)pPars->nConfls : -1 );
+
+// gzFile in = gzopen(pFilename, "rb");
+// parse_DIMACS(in, S);
+// gzclose(in);
+ Glucose_ReadDimacs( pFileName, S );
+
+ if ( pPars->verb )
+ {
+ printf("c ============================[ Problem Statistics ]=============================\n");
+ printf("c | |\n");
+ printf("c | Number of variables: %12d |\n", S.nVars());
+ printf("c | Number of clauses: %12d |\n", S.nClauses());
+ }
+
+ if ( pPars->pre )
+ {
+ S.eliminate(true);
+ printf( "c Simplication removed %d variables and %d clauses. ", S.eliminated_vars, S.eliminated_clauses );
+ Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
+ }
+
+ vec<Lit> dummy;
+ lbool ret = S.solveLimited(dummy, 0);
+ if ( pPars->verb ) glucose2_print_stats(S, Abc_Clock() - clk);
+ printf(ret == l_True ? "SATISFIABLE" : ret == l_False ? "UNSATISFIABLE" : "INDETERMINATE");
+ Abc_PrintTime( 1, " Time", Abc_Clock() - clk );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Vec_Int_t * Glucose_SolverFromAig( Gia_Man_t * p, SimpSolver& s )
+{
+ abctime clk = Abc_Clock();
+ vec<Lit> * lits = &s.user_lits;
+ Cnf_Dat_t * pCnf = (Cnf_Dat_t *)Mf_ManGenerateCnf( p, 8 /*nLutSize*/, 0 /*fCnfObjIds*/, 1/*fAddOrCla*/, 0, 0/*verbose*/ );
+ for ( int i = 0; i < pCnf->nClauses; i++ )
+ {
+ lits->clear();
+ for ( int * pLit = pCnf->pClauses[i]; pLit < pCnf->pClauses[i+1]; pLit++ )
+ lits->push( toLit(*pLit) ), s.addVar( *pLit >> 1 );
+ s.addClause(*lits);
+ }
+ Vec_Int_t * vCnfIds = Vec_IntAllocArrayCopy(pCnf->pVarNums,pCnf->nVars);
+ printf( "CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
+ Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
+ Cnf_DataFree(pCnf);
+ return vCnfIds;
+}
+
+// procedure below does not work because glucose2_solver_addclause() expects Solver
+Vec_Int_t * Glucose_SolverFromAig2( Gia_Man_t * p, SimpSolver& S )
+{
+ Cnf_Dat_t * pCnf = (Cnf_Dat_t *)Mf_ManGenerateCnf( p, 8 /*nLutSize*/, 0 /*fCnfObjIds*/, 1/*fAddOrCla*/, 0, 0/*verbose*/ );
+ for ( int i = 0; i < pCnf->nClauses; i++ )
+ if ( !glucose2_solver_addclause( &S, pCnf->pClauses[i], pCnf->pClauses[i+1]-pCnf->pClauses[i] ) )
+ assert( 0 );
+ Vec_Int_t * vCnfIds = Vec_IntAllocArrayCopy(pCnf->pVarNums,pCnf->nVars);
+ //printf( "CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
+ //Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
+ Cnf_DataFree(pCnf);
+ return vCnfIds;
+}
+
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Vec_Str_t * Glucose2_GenerateCubes( bmcg2_sat_solver * pSat[2], Vec_Int_t * vCiSatVars, Vec_Int_t * vVar2Index, int CubeLimit )
+{
+ int fCreatePrime = 1;
+ int nCubes, nSupp = Vec_IntSize(vCiSatVars);
+ Vec_Str_t * vSop = Vec_StrAlloc( 1000 );
+ Vec_Int_t * vLits = Vec_IntAlloc( nSupp );
+ Vec_Str_t * vCube = Vec_StrAlloc( nSupp + 4 );
+ Vec_StrFill( vCube, nSupp, '-' );
+ Vec_StrPrintF( vCube, " 1\n\0" );
+ for ( nCubes = 0; !CubeLimit || nCubes < CubeLimit; nCubes++ )
+ {
+ int * pFinal, nFinal, iVar, i, k = 0;
+ // generate onset minterm
+ int status = bmcg2_sat_solver_solve( pSat[1], NULL, 0 );
+ if ( status == GLUCOSE_UNSAT )
+ break;
+ assert( status == GLUCOSE_SAT );
+ Vec_IntClear( vLits );
+ Vec_IntForEachEntry( vCiSatVars, iVar, i )
+ Vec_IntPush( vLits, Abc_Var2Lit(iVar, !bmcg2_sat_solver_read_cex_varvalue(pSat[1], iVar)) );
+ // expand against offset
+ if ( fCreatePrime )
+ {
+ nFinal = bmcg2_sat_solver_minimize_assumptions( pSat[0], Vec_IntArray(vLits), Vec_IntSize(vLits), 0 );
+ Vec_IntShrink( vLits, nFinal );
+ pFinal = Vec_IntArray( vLits );
+ for ( i = 0; i < nFinal; i++ )
+ pFinal[i] = Abc_LitNot(pFinal[i]);
+ }
+ else
+ {
+ status = bmcg2_sat_solver_solve( pSat[0], Vec_IntArray(vLits), Vec_IntSize(vLits) );
+ assert( status == GLUCOSE_UNSAT );
+ nFinal = bmcg2_sat_solver_final( pSat[0], &pFinal );
+ }
+ // print cube
+ Vec_StrFill( vCube, nSupp, '-' );
+ for ( i = 0; i < nFinal; i++ )
+ {
+ int Index = Vec_IntEntry(vVar2Index, Abc_Lit2Var(pFinal[i]));
+ if ( Index == -1 )
+ continue;
+ pFinal[k++] = pFinal[i];
+ assert( Index >= 0 && Index < nSupp );
+ Vec_StrWriteEntry( vCube, Index, (char)('0' + Abc_LitIsCompl(pFinal[i])) );
+ }
+ nFinal = k;
+ Vec_StrAppend( vSop, Vec_StrArray(vCube) );
+ //printf( "%s\n", Vec_StrArray(vCube) );
+ // add blocking clause
+ if ( !bmcg2_sat_solver_addclause( pSat[1], pFinal, nFinal ) )
+ break;
+ }
+ Vec_IntFree( vLits );
+ Vec_StrFree( vCube );
+ Vec_StrPush( vSop, '\0' );
+ return vSop;
+}
+Vec_Str_t * bmcg2_sat_solver_sop( Gia_Man_t * p, int CubeLimit )
+{
+ bmcg2_sat_solver * pSat[2] = { bmcg2_sat_solver_start(), bmcg2_sat_solver_start() };
+
+ // generate CNF for the on-set and off-set
+ Cnf_Dat_t * pCnf = (Cnf_Dat_t *)Mf_ManGenerateCnf( p, 8 /*nLutSize*/, 0 /*fCnfObjIds*/, 0/*fAddOrCla*/, 0, 0/*verbose*/ );
+ int i, n, nVars = Gia_ManCiNum(p), Lit;//, Count = 0;
+ int iFirstVar = pCnf->nVars - nVars;
+ assert( Gia_ManCoNum(p) == 1 );
+ for ( n = 0; n < 2; n++ )
+ {
+ bmcg2_sat_solver_set_nvars( pSat[n], pCnf->nVars );
+ Lit = Abc_Var2Lit( 1, !n ); // output variable is 1
+ for ( i = 0; i < pCnf->nClauses; i++ )
+ if ( !bmcg2_sat_solver_addclause( pSat[n], pCnf->pClauses[i], pCnf->pClauses[i+1]-pCnf->pClauses[i] ) )
+ assert( 0 );
+ if ( !bmcg2_sat_solver_addclause( pSat[n], &Lit, 1 ) )
+ {
+ Vec_Str_t * vSop = Vec_StrAlloc( 10 );
+ Vec_StrPrintF( vSop, " %d\n\0", !n );
+ Cnf_DataFree( pCnf );
+ return vSop;
+ }
+ }
+ Cnf_DataFree( pCnf );
+
+ // collect cube vars and map SAT vars into them
+ Vec_Int_t * vVars = Vec_IntAlloc( 100 );
+ Vec_Int_t * vVarMap = Vec_IntStartFull( iFirstVar + nVars );
+ for ( i = 0; i < nVars; i++ )
+ {
+ Vec_IntPush( vVars, iFirstVar+i );
+ Vec_IntWriteEntry( vVarMap, iFirstVar+i, i );
+ }
+
+ Vec_Str_t * vSop = Glucose2_GenerateCubes( pSat, vVars, vVarMap, CubeLimit );
+ Vec_IntFree( vVarMap );
+ Vec_IntFree( vVars );
+
+ bmcg2_sat_solver_stop( pSat[0] );
+ bmcg2_sat_solver_stop( pSat[1] );
+ return vSop;
+}
+void bmcg2_sat_solver_print_sop( Gia_Man_t * p )
+{
+ Vec_Str_t * vSop = bmcg2_sat_solver_sop( p, 0 );
+ printf( "%s", Vec_StrArray(vSop) );
+ Vec_StrFree( vSop );
+}
+void bmcg2_sat_solver_print_sop_lit( Gia_Man_t * p, int Lit )
+{
+ Vec_Int_t * vCisUsed = Vec_IntAlloc( 100 );
+ int i, ObjId, iNode = Abc_Lit2Var( Lit );
+ Gia_ManCollectCis( p, &iNode, 1, vCisUsed );
+ Vec_IntSort( vCisUsed, 0 );
+ Vec_IntForEachEntry( vCisUsed, ObjId, i )
+ Vec_IntWriteEntry( vCisUsed, i, Gia_ManIdToCioId(p, ObjId) );
+ Vec_IntPrint( vCisUsed );
+ Gia_Man_t * pNew = Gia_ManDupConeSupp( p, Lit, vCisUsed );
+ Vec_IntFree( vCisUsed );
+ bmcg2_sat_solver_print_sop( pNew );
+ Gia_ManStop( pNew );
+ printf( "\n" );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Computing d-literals.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+#define Gia_CubeForEachVar( pCube, Value, i ) \
+ for ( i = 0; (pCube[i] != ' ') && (Value = pCube[i]); i++ )
+#define Gia_SopForEachCube( pSop, nFanins, pCube ) \
+ for ( pCube = (pSop); *pCube; pCube += (nFanins) + 3 )
+
+void bmcg2_sat_generate_dvars( Vec_Int_t * vCiVars, Vec_Str_t * vSop, Vec_Int_t * vDLits )
+{
+ int i, Lit, Counter, nCubes = 0;
+ char Value, * pCube, * pSop = Vec_StrArray( vSop );
+ Vec_Int_t * vCounts = Vec_IntStart( 2*Vec_IntSize(vCiVars) );
+ Vec_IntClear( vDLits );
+ Gia_SopForEachCube( pSop, Vec_IntSize(vCiVars), pCube )
+ {
+ nCubes++;
+ Gia_CubeForEachVar( pCube, Value, i )
+ {
+ if ( Value == '1' )
+ Vec_IntAddToEntry( vCounts, 2*i, 1 );
+ else if ( Value == '0' )
+ Vec_IntAddToEntry( vCounts, 2*i+1, 1 );
+ }
+ }
+ Vec_IntForEachEntry( vCounts, Counter, Lit )
+ if ( Counter == nCubes )
+ Vec_IntPush( vDLits, Abc_Var2Lit(Vec_IntEntry(vCiVars, Abc_Lit2Var(Lit)), Abc_LitIsCompl(Lit)) );
+ Vec_IntSort( vDLits, 0 );
+ Vec_IntFree( vCounts );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Performs SAT-based quantification.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int bmcg2_sat_solver_quantify2( Gia_Man_t * p, int iLit, int fHash, int(*pFuncCiToKeep)(void *, int), void * pData, Vec_Int_t * vDLits )
+{
+ int fSynthesize = 0;
+ extern Gia_Man_t * Abc_SopSynthesizeOne( char * pSop, int fClp );
+ Gia_Man_t * pMan, * pNew, * pTemp; Vec_Str_t * vSop;
+ int i, CiId, ObjId, Res, nCubes = 0, nNodes, Count = 0, iNode = Abc_Lit2Var(iLit);
+ Vec_Int_t * vCisUsed = Vec_IntAlloc( 100 );
+ Gia_ManCollectCis( p, &iNode, 1, vCisUsed );
+ Vec_IntSort( vCisUsed, 0 );
+ if ( vDLits ) Vec_IntClear( vDLits );
+ if ( iLit < 2 )
+ return iLit;
+ // remap into CI Ids
+ Vec_IntForEachEntry( vCisUsed, ObjId, i )
+ Vec_IntWriteEntry( vCisUsed, i, Gia_ManIdToCioId(p, ObjId) );
+ // duplicate cone
+ pNew = Gia_ManDupConeSupp( p, iLit, vCisUsed );
+ assert( Gia_ManCiNum(pNew) == Vec_IntSize(vCisUsed) );
+ nNodes = Gia_ManAndNum(pNew);
+
+ // perform quantification one CI at a time
+ assert( pFuncCiToKeep );
+ Vec_IntForEachEntry( vCisUsed, CiId, i )
+ if ( !pFuncCiToKeep( pData, CiId ) )
+ {
+ //printf( "Quantifying %d.\n", CiId );
+ pNew = Gia_ManDupExist( pTemp = pNew, i );
+ Gia_ManStop( pTemp );
+ Count++;
+ }
+ if ( Gia_ManPoIsConst(pNew, 0) )
+ {
+ int RetValue = Gia_ManPoIsConst1(pNew, 0);
+ Vec_IntFree( vCisUsed );
+ Gia_ManStop( pNew );
+ return RetValue;
+ }
+
+ if ( fSynthesize )
+ {
+ vSop = bmcg2_sat_solver_sop( pNew, 0 );
+ Gia_ManStop( pNew );
+ pMan = Abc_SopSynthesizeOne( Vec_StrArray(vSop), 1 );
+ nCubes = Vec_StrCountEntry(vSop, '\n');
+ if ( vDLits )
+ {
+ // convert into object IDs
+ Vec_Int_t * vCisObjs = Vec_IntAlloc( Vec_IntSize(vCisUsed) );
+ Vec_IntForEachEntry( vCisUsed, CiId, i )
+ Vec_IntPush( vCisObjs, CiId + 1 );
+ bmcg2_sat_generate_dvars( vCisObjs, vSop, vDLits );
+ Vec_IntFree( vCisObjs );
+ }
+ Vec_StrFree( vSop );
+
+ if ( Gia_ManPoIsConst(pMan, 0) )
+ {
+ int RetValue = Gia_ManPoIsConst1(pMan, 0);
+ Vec_IntFree( vCisUsed );
+ Gia_ManStop( pMan );
+ return RetValue;
+ }
+ }
+ else
+ {
+ pMan = pNew;
+ }
+
+ Res = Gia_ManDupConeBack( p, pMan, vCisUsed );
+
+ // report the result
+ //printf( "Performed quantification with %5d nodes, %3d keep-vars, %3d quant-vars, resulting in %5d cubes and %5d nodes. ",
+ // nNodes, Vec_IntSize(vCisUsed) - Count, Count, nCubes, Gia_ManAndNum(pMan) );
+ //Abc_PrintTime( 1, "Time", Abc_Clock() - clkAll );
+
+ Vec_IntFree( vCisUsed );
+ Gia_ManStop( pMan );
+ return Res;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Performs SAT-based quantification.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Gia_ManSatAndCollect2_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vObjsUsed, Vec_Int_t * vCiVars )
+{
+ Gia_Obj_t * pObj; int iVar;
+ if ( (iVar = Gia_ObjCopyArray(p, iObj)) >= 0 )
+ return iVar;
+ pObj = Gia_ManObj( p, iObj );
+ assert( Gia_ObjIsCand(pObj) );
+ if ( Gia_ObjIsAnd(pObj) )
+ {
+ Gia_ManSatAndCollect2_rec( p, Gia_ObjFaninId0(pObj, iObj), vObjsUsed, vCiVars );
+ Gia_ManSatAndCollect2_rec( p, Gia_ObjFaninId1(pObj, iObj), vObjsUsed, vCiVars );
+ }
+ iVar = Vec_IntSize( vObjsUsed );
+ Vec_IntPush( vObjsUsed, iObj );
+ Gia_ObjSetCopyArray( p, iObj, iVar );
+ if ( vCiVars && Gia_ObjIsCi(pObj) )
+ Vec_IntPush( vCiVars, iVar );
+ return iVar;
+}
+void Gia_ManQuantLoadCnf2( Gia_Man_t * p, Vec_Int_t * vObjsUsed, bmcg2_sat_solver * pSats[] )
+{
+ Gia_Obj_t * pObj; int i;
+ bmcg2_sat_solver_reset( pSats[0] );
+ if ( pSats[1] )
+ bmcg2_sat_solver_reset( pSats[1] );
+ bmcg2_sat_solver_set_nvars( pSats[0], Vec_IntSize(vObjsUsed) );
+ if ( pSats[1] )
+ bmcg2_sat_solver_set_nvars( pSats[1], Vec_IntSize(vObjsUsed) );
+ Gia_ManForEachObjVec( vObjsUsed, p, pObj, i )
+ if ( Gia_ObjIsAnd(pObj) )
+ {
+ int iObj = Gia_ObjId( p, pObj );
+ int iVar = Gia_ObjCopyArray(p, iObj);
+ int iVar0 = Gia_ObjCopyArray(p, Gia_ObjFaninId0(pObj, iObj));
+ int iVar1 = Gia_ObjCopyArray(p, Gia_ObjFaninId1(pObj, iObj));
+ bmcg2_sat_solver_add_and( pSats[0], iVar, iVar0, iVar1, Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj), 0 );
+ if ( pSats[1] )
+ bmcg2_sat_solver_add_and( pSats[1], iVar, iVar0, iVar1, Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj), 0 );
+ }
+ else if ( Gia_ObjIsConst0(pObj) )
+ {
+ int Lit = Abc_Var2Lit( Gia_ObjCopyArray(p, 0), 1 );
+ int RetValue = bmcg2_sat_solver_addclause( pSats[0], &Lit, 1 );
+ assert( RetValue );
+ if ( pSats[1] )
+ bmcg2_sat_solver_addclause( pSats[1], &Lit, 1 );
+ assert( Lit == 1 );
+ }
+}
+int Gia_ManFactorSop2( Gia_Man_t * p, Vec_Int_t * vCiObjIds, Vec_Str_t * vSop, int fHash )
+{
+ extern Gia_Man_t * Abc_SopSynthesizeOne( char * pSop, int fClp );
+ Gia_Man_t * pMan = Abc_SopSynthesizeOne( Vec_StrArray(vSop), 1 );
+ Gia_Obj_t * pObj; int i, Result;
+ assert( Gia_ManPiNum(pMan) == Vec_IntSize(vCiObjIds) );
+ Gia_ManConst0(pMan)->Value = 0;
+ Gia_ManForEachPi( pMan, pObj, i )
+ pObj->Value = Abc_Var2Lit( Vec_IntEntry(vCiObjIds, i), 0 );
+ Gia_ManForEachAnd( pMan, pObj, i )
+ if ( fHash )
+ pObj->Value = Gia_ManHashAnd( p, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
+ else
+ pObj->Value = Gia_ManAppendAnd( p, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
+ pObj = Gia_ManPo(pMan, 0);
+ Result = Gia_ObjFanin0Copy(pObj);
+ Gia_ManStop( pMan );
+ return Result;
+}
+int bmcg2_sat_solver_quantify( bmcg2_sat_solver * pSats[], Gia_Man_t * p, int iLit, int fHash, int(*pFuncCiToKeep)(void *, int), void * pData, Vec_Int_t * vDLits )
+{
+ Vec_Int_t * vObjsUsed = Vec_IntAlloc( 100 ); // GIA objs
+ Vec_Int_t * vCiVars = Vec_IntAlloc( 100 ); // CI SAT vars
+ Vec_Int_t * vVarMap = NULL; Vec_Str_t * vSop = NULL;
+ int i, iVar, iVarLast, Lit, RetValue, Count = 0, Result = -1;
+ if ( vDLits ) Vec_IntClear( vDLits );
+ if ( iLit < 2 )
+ return iLit;
+ if ( Vec_IntSize(&p->vCopies) < Gia_ManObjNum(p) )
+ Vec_IntFillExtra( &p->vCopies, Gia_ManObjNum(p), -1 );
+ // assign variable number 0 to const0 node
+ iVar = Vec_IntSize(vObjsUsed);
+ Vec_IntPush( vObjsUsed, 0 );
+ Gia_ObjSetCopyArray( p, 0, iVar );
+ assert( iVar == 0 );
+
+ // collect other variables
+ iVarLast = Gia_ManSatAndCollect2_rec( p, Abc_Lit2Var(iLit), vObjsUsed, vCiVars );
+ Gia_ManQuantLoadCnf2( p, vObjsUsed, pSats );
+
+ // check constants
+ Lit = Abc_Var2Lit( iVarLast, !Abc_LitIsCompl(iLit) );
+ RetValue = bmcg2_sat_solver_addclause( pSats[0], &Lit, 1 ); // offset
+ if ( !RetValue || bmcg2_sat_solver_solve(pSats[0], NULL, 0) == GLUCOSE_UNSAT )
+ {
+ Result = 1;
+ goto cleanup;
+ }
+ Lit = Abc_Var2Lit( iVarLast, Abc_LitIsCompl(iLit) );
+ RetValue = bmcg2_sat_solver_addclause( pSats[1], &Lit, 1 ); // onset
+ if ( !RetValue || bmcg2_sat_solver_solve(pSats[1], NULL, 0) == GLUCOSE_UNSAT )
+ {
+ Result = 0;
+ goto cleanup;
+ }
+/*
+ // reorder CI SAT variables to have keep-vars first
+ Vec_Int_t * vCiVars2 = Vec_IntAlloc( 100 ); // CI SAT vars
+ Vec_IntForEachEntry( vCiVars, iVar, i )
+ {
+ Gia_Obj_t * pObj = Gia_ManObj( p, Vec_IntEntry(vObjsUsed, iVar) );
+ assert( Gia_ObjIsCi(pObj) );
+ if ( pFuncCiToKeep(pData, Gia_ObjCioId(pObj)) )
+ Vec_IntPush( vCiVars2, iVar );
+ }
+ Vec_IntForEachEntry( vCiVars, iVar, i )
+ {
+ Gia_Obj_t * pObj = Gia_ManObj( p, Vec_IntEntry(vObjsUsed, iVar) );
+ assert( Gia_ObjIsCi(pObj) );
+ if ( !pFuncCiToKeep(pData, Gia_ObjCioId(pObj)) )
+ Vec_IntPush( vCiVars2, iVar );
+ }
+ ABC_SWAP( Vec_Int_t *, vCiVars2, vCiVars );
+ Vec_IntFree( vCiVars2 );
+*/
+ // map CI SAT variables into their indexes used in the cubes
+ vVarMap = Vec_IntStartFull( Vec_IntSize(vObjsUsed) );
+ Vec_IntForEachEntry( vCiVars, iVar, i )
+ {
+ Gia_Obj_t * pObj = Gia_ManObj( p, Vec_IntEntry(vObjsUsed, iVar) );
+ assert( Gia_ObjIsCi(pObj) );
+ if ( pFuncCiToKeep(pData, Gia_ObjCioId(pObj)) )
+ Vec_IntWriteEntry( vVarMap, iVar, i ), Count++;
+ }
+ if ( Count == 0 || Count == Vec_IntSize(vCiVars) )
+ {
+ Result = Count == 0 ? 1 : iLit;
+ goto cleanup;
+ }
+ // generate cubes
+ vSop = Glucose2_GenerateCubes( pSats, vCiVars, vVarMap, 0 );
+ //printf( "%s", Vec_StrArray(vSop) );
+ // convert into object IDs
+ Vec_IntForEachEntry( vCiVars, iVar, i )
+ Vec_IntWriteEntry( vCiVars, i, Vec_IntEntry(vObjsUsed, iVar) );
+ // generate unate variables
+ if ( vDLits )
+ bmcg2_sat_generate_dvars( vCiVars, vSop, vDLits );
+ // convert into an AIG
+ RetValue = Gia_ManAndNum(p);
+ Result = Gia_ManFactorSop2( p, vCiVars, vSop, fHash );
+
+ // report the result
+// printf( "Performed quantification with %5d nodes, %3d keep-vars, %3d quant-vars, resulting in %5d cubes and %5d nodes. ",
+// Vec_IntSize(vObjsUsed), Count, Vec_IntSize(vCiVars) - Count, Vec_StrCountEntry(vSop, '\n'), Gia_ManAndNum(p)-RetValue );
+// Abc_PrintTime( 1, "Time", Abc_Clock() - clkAll );
+
+cleanup:
+ Vec_IntForEachEntry( vObjsUsed, iVar, i )
+ Gia_ObjSetCopyArray( p, iVar, -1 );
+ Vec_IntFree( vObjsUsed );
+ Vec_IntFree( vCiVars );
+ Vec_IntFreeP( &vVarMap );
+ Vec_StrFreeP( &vSop );
+ return Result;
+}
+int Gia_ManCiIsToKeep2( void * pData, int i )
+{
+ return i % 5 != 0;
+}
+void Glucose2_QuantifyAigTest( Gia_Man_t * p )
+{
+ bmcg2_sat_solver * pSats[3] = { bmcg2_sat_solver_start(), bmcg2_sat_solver_start(), bmcg2_sat_solver_start() };
+
+ abctime clk1 = Abc_Clock();
+ int iRes1 = bmcg2_sat_solver_quantify( pSats, p, Gia_ObjFaninLit0p(p, Gia_ManPo(p, 0)), 0, Gia_ManCiIsToKeep2, NULL, NULL );
+ abctime clk1d = Abc_Clock()-clk1;
+
+ abctime clk2 = Abc_Clock();
+ int iRes2 = bmcg2_sat_solver_quantify2( p, Gia_ObjFaninLit0p(p, Gia_ManPo(p, 0)), 0, Gia_ManCiIsToKeep2, NULL, NULL );
+ abctime clk2d = Abc_Clock()-clk2;
+
+ Abc_PrintTime( 1, "Time1", clk1d );
+ Abc_PrintTime( 1, "Time2", clk2d );
+
+ if ( bmcg2_sat_solver_equiv_overlap_check( pSats[2], p, iRes1, iRes2, 1 ) )
+ printf( "Verification passed.\n" );
+ else
+ printf( "Verification FAILED.\n" );
+
+ Gia_ManAppendCo( p, iRes1 );
+ Gia_ManAppendCo( p, iRes2 );
+
+ bmcg2_sat_solver_stop( pSats[0] );
+ bmcg2_sat_solver_stop( pSats[1] );
+ bmcg2_sat_solver_stop( pSats[2] );
+}
+int bmcg2_sat_solver_quantify_test( bmcg2_sat_solver * pSats[], Gia_Man_t * p, int iLit, int fHash, int(*pFuncCiToKeep)(void *, int), void * pData, Vec_Int_t * vDLits )
+{
+ extern int Gia_ManQuantExist( Gia_Man_t * p, int iLit, int(*pFuncCiToKeep)(void *, int), void * pData );
+ int Res1 = Gia_ManQuantExist( p, iLit, pFuncCiToKeep, pData );
+ int Res2 = bmcg2_sat_solver_quantify2( p, iLit, 1, pFuncCiToKeep, pData, NULL );
+
+ bmcg2_sat_solver * pSat = bmcg2_sat_solver_start();
+ if ( bmcg2_sat_solver_equiv_overlap_check( pSat, p, Res1, Res2, 1 ) )
+ printf( "Verification passed.\n" );
+ else
+ {
+ printf( "Verification FAILED.\n" );
+ bmcg2_sat_solver_print_sop_lit( p, Res1 );
+ bmcg2_sat_solver_print_sop_lit( p, Res2 );
+ printf( "\n" );
+ }
+ return Res1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Checks equivalence or intersection of two nodes.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int bmcg2_sat_solver_equiv_overlap_check( bmcg2_sat_solver * pSat, Gia_Man_t * p, int iLit0, int iLit1, int fEquiv )
+{
+ bmcg2_sat_solver * pSats[2] = { pSat, NULL };
+ Vec_Int_t * vObjsUsed = Vec_IntAlloc( 100 );
+ int i, iVar, iSatVar[2], iSatLit[2], Lits[2], status;
+ if ( Vec_IntSize(&p->vCopies) < Gia_ManObjNum(p) )
+ Vec_IntFillExtra( &p->vCopies, Gia_ManObjNum(p), -1 );
+
+ // assign const0 variable number 0
+ iVar = Vec_IntSize(vObjsUsed);
+ Vec_IntPush( vObjsUsed, 0 );
+ Gia_ObjSetCopyArray( p, 0, iVar );
+ assert( iVar == 0 );
+
+ iSatVar[0] = Gia_ManSatAndCollect2_rec( p, Abc_Lit2Var(iLit0), vObjsUsed, NULL );
+ iSatVar[1] = Gia_ManSatAndCollect2_rec( p, Abc_Lit2Var(iLit1), vObjsUsed, NULL );
+
+ iSatLit[0] = Abc_Var2Lit( iSatVar[0], Abc_LitIsCompl(iLit0) );
+ iSatLit[1] = Abc_Var2Lit( iSatVar[1], Abc_LitIsCompl(iLit1) );
+ Gia_ManQuantLoadCnf2( p, vObjsUsed, pSats );
+ Vec_IntForEachEntry( vObjsUsed, iVar, i )
+ Gia_ObjSetCopyArray( p, iVar, -1 );
+ Vec_IntFree( vObjsUsed );
+
+ if ( fEquiv )
+ {
+ Lits[0] = iSatLit[0];
+ Lits[1] = Abc_LitNot(iSatLit[1]);
+ status = bmcg2_sat_solver_solve( pSats[0], Lits, 2 );
+ if ( status == GLUCOSE_UNSAT )
+ {
+ Lits[0] = Abc_LitNot(iSatLit[0]);
+ Lits[1] = iSatLit[1];
+ status = bmcg2_sat_solver_solve( pSats[0], Lits, 2 );
+ }
+ return status == GLUCOSE_UNSAT;
+ }
+ else
+ {
+ Lits[0] = iSatLit[0];
+ Lits[1] = iSatLit[1];
+ status = bmcg2_sat_solver_solve( pSats[0], Lits, 2 );
+ return status == GLUCOSE_SAT;
+ }
+}
+void Glucose2_CheckTwoNodesTest( Gia_Man_t * p )
+{
+ int n, Res;
+ bmcg2_sat_solver * pSat = bmcg2_sat_solver_start();
+ for ( n = 0; n < 2; n++ )
+ {
+ Res = bmcg2_sat_solver_equiv_overlap_check(
+ pSat, p,
+ Gia_ObjFaninLit0p(p, Gia_ManPo(p, 0)),
+ Gia_ObjFaninLit0p(p, Gia_ManPo(p, 1)),
+ n );
+ bmcg2_sat_solver_reset( pSat );
+ printf( "%s %s.\n", n ? "Equivalence" : "Overlap", Res ? "holds" : "fails" );
+ }
+ bmcg2_sat_solver_stop( pSat );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Glucose2_SolveAig(Gia_Man_t * p, Glucose2_Pars * pPars)
+{
+ abctime clk = Abc_Clock();
+
+ SimpSolver S;
+ S.verbosity = pPars->verb;
+ S.verbEveryConflicts = 50000;
+ S.showModel = false;
+ //S.verbosity = 2;
+ S.setConfBudget( pPars->nConfls > 0 ? (int64_t)pPars->nConfls : -1 );
+
+ S.parsing = 1;
+ Vec_Int_t * vCnfIds = Glucose_SolverFromAig(p,S);
+ S.parsing = 0;
+
+ if (pPars->verb)
+ {
+ printf("c ============================[ Problem Statistics ]=============================\n");
+ printf("c | |\n");
+ printf("c | Number of variables: %12d |\n", S.nVars());
+ printf("c | Number of clauses: %12d |\n", S.nClauses());
+ }
+
+ if (pPars->pre)
+ {
+ S.eliminate(true);
+ printf( "c Simplication removed %d variables and %d clauses. ", S.eliminated_vars, S.eliminated_clauses );
+ Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
+ }
+
+ vec<Lit> dummy;
+ lbool ret = S.solveLimited(dummy, 0);
+
+ if ( pPars->verb ) glucose2_print_stats(S, Abc_Clock() - clk);
+ printf(ret == l_True ? "SATISFIABLE" : ret == l_False ? "UNSATISFIABLE" : "INDETERMINATE");
+ Abc_PrintTime( 1, " Time", Abc_Clock() - clk );
+
+ // port counterexample
+ if (ret == l_True)
+ {
+ Gia_Obj_t * pObj; int i;
+ p->pCexComb = Abc_CexAlloc(0,Gia_ManCiNum(p),1);
+ Gia_ManForEachCi( p, pObj, i )
+ {
+ assert(Vec_IntEntry(vCnfIds,Gia_ObjId(p, pObj))!=-1);
+ if (S.model[Vec_IntEntry(vCnfIds,Gia_ObjId(p, pObj))] == l_True)
+ Abc_InfoSetBit( p->pCexComb->pData, i);
+ }
+ }
+ Vec_IntFree(vCnfIds);
+ return (ret == l_True ? 10 : ret == l_False ? 20 : 0);
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+ABC_NAMESPACE_IMPL_END
diff --git a/src/sat/glucose2/AbcGlucose2.h b/src/sat/glucose2/AbcGlucose2.h
new file mode 100644
index 00000000..9299d290
--- /dev/null
+++ b/src/sat/glucose2/AbcGlucose2.h
@@ -0,0 +1,118 @@
+/**CFile****************************************************************
+
+ FileName [AbcGlucose.h]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [SAT solver Glucose 3.0 by Gilles Audemard and Laurent Simon.]
+
+ Synopsis [Interface to Glucose.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - September 6, 2017.]
+
+ Revision [$Id: AbcGlucose.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#ifndef ABC_SAT_GLUCOSE_H_
+#define ABC_SAT_GLUCOSE_H_
+
+////////////////////////////////////////////////////////////////////////
+/// INCLUDES ///
+////////////////////////////////////////////////////////////////////////
+
+#include "aig/gia/gia.h"
+
+////////////////////////////////////////////////////////////////////////
+/// PARAMETERS ///
+////////////////////////////////////////////////////////////////////////
+
+#define GLUCOSE_UNSAT -1
+#define GLUCOSE_SAT 1
+#define GLUCOSE_UNDEC 0
+
+
+ABC_NAMESPACE_HEADER_START
+
+////////////////////////////////////////////////////////////////////////
+/// BASIC TYPES ///
+////////////////////////////////////////////////////////////////////////
+
+typedef struct Glucose2_Pars_ Glucose2_Pars;
+struct Glucose2_Pars_ {
+ int pre; // preprocessing
+ int verb; // verbosity
+ int cust; // customizable
+ int nConfls; // conflict limit (0 = no limit)
+};
+
+static inline Glucose2_Pars Glucose_CreatePars(int p, int v, int c, int nConfls)
+{
+ Glucose2_Pars pars;
+ pars.pre = p;
+ pars.verb = v;
+ pars.cust = c;
+ pars.nConfls = nConfls;
+ return pars;
+}
+
+typedef void bmcg2_sat_solver;
+
+////////////////////////////////////////////////////////////////////////
+/// MACRO DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+extern bmcg2_sat_solver * bmcg2_sat_solver_start();
+extern void bmcg2_sat_solver_stop( bmcg2_sat_solver* s );
+extern void bmcg2_sat_solver_reset( bmcg2_sat_solver* s );
+extern int bmcg2_sat_solver_addclause( bmcg2_sat_solver* s, int * plits, int nlits );
+extern void bmcg2_sat_solver_setcallback( bmcg2_sat_solver* s, void * pman, int(*pfunc)(void*, int, int*) );
+extern int bmcg2_sat_solver_solve( bmcg2_sat_solver* s, int * plits, int nlits );
+extern int bmcg2_sat_solver_final( bmcg2_sat_solver* s, int ** ppArray );
+extern int bmcg2_sat_solver_addvar( bmcg2_sat_solver* s );
+extern void bmcg2_sat_solver_set_nvars( bmcg2_sat_solver* s, int nvars );
+extern int bmcg2_sat_solver_eliminate( bmcg2_sat_solver* s, int turn_off_elim );
+extern int bmcg2_sat_solver_var_is_elim( bmcg2_sat_solver* s, int v );
+extern void bmcg2_sat_solver_var_set_frozen( bmcg2_sat_solver* s, int v, int freeze );
+extern int bmcg2_sat_solver_elim_varnum(bmcg2_sat_solver* s);
+extern int * bmcg2_sat_solver_read_cex( bmcg2_sat_solver* s );
+extern int bmcg2_sat_solver_read_cex_varvalue( bmcg2_sat_solver* s, int );
+extern void bmcg2_sat_solver_set_stop( bmcg2_sat_solver* s, int * pstop );
+extern abctime bmcg2_sat_solver_set_runtime_limit( bmcg2_sat_solver* s, abctime Limit );
+extern void bmcg2_sat_solver_set_conflict_budget( bmcg2_sat_solver* s, int Limit );
+extern int bmcg2_sat_solver_varnum( bmcg2_sat_solver* s );
+extern int bmcg2_sat_solver_clausenum( bmcg2_sat_solver* s );
+extern int bmcg2_sat_solver_learntnum( bmcg2_sat_solver* s );
+extern int bmcg2_sat_solver_conflictnum( bmcg2_sat_solver* s );
+extern int bmcg2_sat_solver_minimize_assumptions( bmcg2_sat_solver * s, int * plits, int nlits, int pivot );
+extern int bmcg2_sat_solver_add_and( bmcg2_sat_solver * s, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl );
+extern int bmcg2_sat_solver_add_xor( bmcg2_sat_solver * s, int iVarA, int iVarB, int iVarC, int fCompl );
+extern int bmcg2_sat_solver_quantify( bmcg2_sat_solver * s[], Gia_Man_t * p, int iLit, int fHash, int(*pFuncCiToKeep)(void *, int), void * pData, Vec_Int_t * vDLits );
+extern int bmcg2_sat_solver_equiv_overlap_check( bmcg2_sat_solver * s, Gia_Man_t * p, int iLit0, int iLit1, int fEquiv );
+extern Vec_Str_t * bmcg2_sat_solver_sop( Gia_Man_t * p, int CubeLimit );
+extern int bmcg2_sat_solver_jftr( bmcg2_sat_solver * s );
+extern void bmcg2_sat_solver_set_jftr( bmcg2_sat_solver * s, int jftr );
+extern void bmcg2_sat_solver_set_var_fanin_lit( bmcg2_sat_solver * s, int var, int lit0, int lit1 );
+extern void bmcg2_sat_solver_start_new_round( bmcg2_sat_solver * s );
+extern void bmcg2_sat_solver_mark_cone( bmcg2_sat_solver * s, int var );
+extern void bmcg2_sat_solver_prelocate( bmcg2_sat_solver * s, int var_num );
+
+extern void Glucose2_SolveCnf( char * pFilename, Glucose2_Pars * pPars );
+extern int Glucose2_SolveAig( Gia_Man_t * p, Glucose2_Pars * pPars );
+
+ABC_NAMESPACE_HEADER_END
+
+#endif
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
diff --git a/src/sat/glucose2/AbcGlucoseCmd2.cpp b/src/sat/glucose2/AbcGlucoseCmd2.cpp
new file mode 100644
index 00000000..54bae608
--- /dev/null
+++ b/src/sat/glucose2/AbcGlucoseCmd2.cpp
@@ -0,0 +1,149 @@
+/**CFile****************************************************************
+
+ FileName [AbcGlucoseCmd.cpp]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [SAT solver Glucose 3.0 by Gilles Audemard and Laurent Simon.]
+
+ Synopsis [Interface to Glucose.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - September 6, 2017.]
+
+ Revision [$Id: AbcGlucoseCmd.cpp,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "aig/gia/gia.h"
+#include "base/main/mainInt.h"
+
+#include "sat/glucose2/AbcGlucose2.h"
+
+
+ABC_NAMESPACE_HEADER_START
+
+extern void Glucose2_Init( Abc_Frame_t *pAbc );
+extern void Glucose2_End( Abc_Frame_t * pAbc );
+
+ABC_NAMESPACE_HEADER_END
+
+ABC_NAMESPACE_IMPL_START
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+static int Abc_CommandGlucose( Abc_Frame_t * pAbc, int argc, char ** argv );
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+
+void Glucose2_Init(Abc_Frame_t *pAbc)
+{
+ Cmd_CommandAdd( pAbc, "ABC9", "&glucose2", Abc_CommandGlucose, 0 );
+}
+
+void Glucose2_End( Abc_Frame_t * pAbc )
+{
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Abc_CommandGlucose( Abc_Frame_t * pAbc, int argc, char ** argv )
+{
+ int c = 0;
+ int pre = 1;
+ int verb = 0;
+ int nConfls = 0;
+
+ Glucose2_Pars pPars;
+ Extra_UtilGetoptReset();
+ while ( ( c = Extra_UtilGetopt( argc, argv, "Cpvh" ) ) != EOF )
+ {
+ switch ( c )
+ {
+ case 'C':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
+ goto usage;
+ }
+ nConfls = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( nConfls < 0 )
+ goto usage;
+ break;
+ case 'p':
+ pre ^= 1;
+ break;
+ case 'v':
+ verb ^= 1;
+ break;
+ case 'h':
+ goto usage;
+ default:
+ goto usage;
+ }
+ }
+
+ pPars = Glucose_CreatePars(pre,verb,0,nConfls);
+
+ if ( argc == globalUtilOptind + 1 )
+ {
+ Glucose2_SolveCnf( argv[globalUtilOptind], &pPars );
+ return 0;
+ }
+
+ if ( pAbc->pGia == NULL )
+ {
+ Abc_Print( -1, "Abc_CommandGlucose(): There is no AIG.\n" );
+ return 1;
+ }
+
+ if ( Glucose2_SolveAig( pAbc->pGia, &pPars ) == 10 )
+ Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexComb );
+
+ return 0;
+
+usage:
+ Abc_Print( -2, "usage: &glucose2 [-C num] [-pvh] <file.cnf>\n" );
+ Abc_Print( -2, "\t run Glucose 3.0 by Gilles Audemard and Laurent Simon\n" );
+ Abc_Print( -2, "\t-C num : conflict limit [default = %d]\n", nConfls );
+ Abc_Print( -2, "\t-p : enable preprocessing [default = %d]\n",pre);
+ Abc_Print( -2, "\t-v : verbosity [default = %d]\n",verb);
+ Abc_Print( -2, "\t-h : print the command usage\n");
+ Abc_Print( -2, "\t<file.cnf> : (optional) CNF file to solve\n");
+ return 1;
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+ABC_NAMESPACE_IMPL_END
diff --git a/src/sat/glucose2/Alg.h b/src/sat/glucose2/Alg.h
new file mode 100644
index 00000000..96f6ab70
--- /dev/null
+++ b/src/sat/glucose2/Alg.h
@@ -0,0 +1,88 @@
+/*******************************************************************************************[Alg.h]
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Alg_h
+#define Glucose_Alg_h
+
+#include "sat/glucose2/Vec.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// Useful functions on vector-like types:
+
+//=================================================================================================
+// Removing and searching for elements:
+//
+
+template<class V, class T>
+static inline void remove(V& ts, const T& t)
+{
+ int j = 0;
+ for (; j < ts.size() && ts[j] != t; j++);
+ assert(j < ts.size());
+ for (; j < ts.size()-1; j++) ts[j] = ts[j+1];
+ ts.pop();
+}
+
+
+template<class V, class T>
+static inline bool find(V& ts, const T& t)
+{
+ int j = 0;
+ for (; j < ts.size() && ts[j] != t; j++);
+ return j < ts.size();
+}
+
+
+//=================================================================================================
+// Copying vectors with support for nested vector types:
+//
+
+// Base case:
+template<class T>
+static inline void copy(const T& from, T& to)
+{
+ to = from;
+}
+
+// Recursive case:
+template<class T>
+static inline void copy(const vec<T>& from, vec<T>& to, bool append = false)
+{
+ if (!append)
+ to.clear();
+ for (int i = 0; i < from.size(); i++){
+ to.push();
+ copy(from[i], to.last());
+ }
+}
+
+template<class T>
+static inline void append(const vec<T>& from, vec<T>& to){ copy(from, to, true); }
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/Alloc.h b/src/sat/glucose2/Alloc.h
new file mode 100644
index 00000000..b7bebaca
--- /dev/null
+++ b/src/sat/glucose2/Alloc.h
@@ -0,0 +1,136 @@
+/*****************************************************************************************[Alloc.h]
+Copyright (c) 2008-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+
+#ifndef Glucose_Alloc_h
+#define Glucose_Alloc_h
+
+#include "sat/glucose2/XAlloc.h"
+#include "sat/glucose2/Vec.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// Simple Region-based memory allocator:
+
+template<class T>
+class RegionAllocator
+{
+ T* memory;
+ uint32_t sz;
+ uint32_t cap;
+ uint32_t wasted_;
+
+ void capacity(uint32_t min_cap);
+
+ public:
+ // TODO: make this a class for better type-checking?
+ typedef uint32_t Ref;
+ enum { Ref_Undef = UINT32_MAX };
+ enum { Unit_Size = sizeof(uint32_t) };
+
+ explicit RegionAllocator(uint32_t start_cap = 1024*1024) : memory(NULL), sz(0), cap(0), wasted_(0){ capacity(start_cap); }
+ ~RegionAllocator()
+ {
+ if (memory != NULL)
+ ::free(memory);
+ }
+
+
+ uint32_t size () const { return sz; }
+ uint32_t wasted () const { return wasted_; }
+
+ Ref alloc (int size);
+ void free_ (int size) { wasted_ += size; }
+ void clear () { sz = 0; wasted_=0; }
+
+ // Deref, Load Effective Address (LEA), Inverse of LEA (AEL):
+ T& operator[](Ref r) { assert(r >= 0 && r < sz); return memory[r]; }
+ const T& operator[](Ref r) const { assert(r >= 0 && r < sz); return memory[r]; }
+
+ T* lea (Ref r) { assert(r >= 0 && r < sz); return &memory[r]; }
+ const T* lea (Ref r) const { assert(r >= 0 && r < sz); return &memory[r]; }
+ Ref ael (const T* t) { assert((void*)t >= (void*)&memory[0] && (void*)t < (void*)&memory[sz-1]);
+ return (Ref)(t - &memory[0]); }
+
+ void moveTo(RegionAllocator& to) {
+ if (to.memory != NULL) ::free(to.memory);
+ to.memory = memory;
+ to.sz = sz;
+ to.cap = cap;
+ to.wasted_ = wasted_;
+
+ memory = NULL;
+ sz = cap = wasted_ = 0;
+ }
+
+
+};
+
+template<class T>
+void RegionAllocator<T>::capacity(uint32_t min_cap)
+{
+ if (cap >= min_cap) return;
+
+ uint32_t prev_cap = cap;
+ while (cap < min_cap){
+ // NOTE: Multiply by a factor (13/8) without causing overflow, then add 2 and make the
+ // result even by clearing the least significant bit. The resulting sequence of capacities
+ // is carefully chosen to hit a maximum capacity that is close to the '2^32-1' limit when
+ // using 'uint32_t' as indices so that as much as possible of this space can be used.
+ uint32_t delta = ((cap >> 1) + (cap >> 3) + 2) & ~1;
+ cap += delta;
+
+ if (cap <= prev_cap)
+ throw OutOfMemoryException();
+ }
+ //printf(" .. (%p) cap = %u\n", this, cap);
+
+ assert(cap > 0);
+ memory = (T*)xrealloc(memory, sizeof(T)*cap);
+}
+
+
+template<class T>
+typename RegionAllocator<T>::Ref
+RegionAllocator<T>::alloc(int size)
+{
+ //printf("ALLOC called (this = %p, size = %d)\n", this, size); fflush(stdout);
+ assert(size > 0);
+ capacity(sz + size);
+
+ uint32_t prev_sz = sz;
+ sz += size;
+
+ // Handle overflow:
+ if (sz < prev_sz)
+ throw OutOfMemoryException();
+
+ return prev_sz;
+}
+
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/BoundedQueue.h b/src/sat/glucose2/BoundedQueue.h
new file mode 100644
index 00000000..1a0d2148
--- /dev/null
+++ b/src/sat/glucose2/BoundedQueue.h
@@ -0,0 +1,114 @@
+/***********************************************************************************[BoundedQueue.h]
+ Glucose -- Copyright (c) 2009, Gilles Audemard, Laurent Simon
+ CRIL - Univ. Artois, France
+ LRI - Univ. Paris Sud, France
+
+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.
+**************************************************************************************************/
+
+
+#ifndef BoundedQueue_h
+#define BoundedQueue_h
+
+#include "sat/glucose2/Vec.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+//=================================================================================================
+
+namespace Gluco2 {
+
+template <class T>
+class bqueue {
+ vec<T> elems;
+ int first;
+ int last;
+ uint64_t sumofqueue;
+ int maxsize;
+ int queuesize; // Number of current elements (must be < maxsize !)
+ bool expComputed;
+ double exp,value;
+public:
+ bqueue(void) : first(0), last(0), sumofqueue(0), maxsize(0), queuesize(0),expComputed(false) { }
+
+ void initSize(int size) {growTo(size);exp = 2.0/(size+1);} // Init size of bounded size queue
+
+ void push(T x) {
+ expComputed = false;
+ if (queuesize==maxsize) {
+ assert(last==first); // The queue is full, next value to enter will replace oldest one
+ sumofqueue -= elems[last];
+ if ((++last) == maxsize) last = 0;
+ } else
+ queuesize++;
+ sumofqueue += x;
+ elems[first] = x;
+ if ((++first) == maxsize) {first = 0;last = 0;}
+ }
+
+ T peek() { assert(queuesize>0); return elems[last]; }
+ void pop() {sumofqueue-=elems[last]; queuesize--; if ((++last) == maxsize) last = 0;}
+
+ uint64_t getsum() const {return sumofqueue;}
+ unsigned int getavg() const {return (unsigned int)(sumofqueue/((uint64_t)queuesize));}
+ int maxSize() const {return maxsize;}
+ double getavgDouble() const {
+ double tmp = 0;
+ for(int i=0;i<elems.size();i++) {
+ tmp+=elems[i];
+ }
+ return tmp/elems.size();
+ }
+ int isvalid() const {return (queuesize==maxsize);}
+
+ void growTo(int size) {
+ elems.growTo(size);
+ first=0; maxsize=size; queuesize = 0;last = 0;
+ for(int i=0;i<size;i++) elems[i]=0;
+ }
+
+ double getAvgExp() {
+ if(expComputed) return value;
+ double a=exp;
+ value = elems[first];
+ for(int i = first;i<maxsize;i++) {
+ value+=a*((double)elems[i]);
+ a=a*exp;
+ }
+ for(int i = 0;i<last;i++) {
+ value+=a*((double)elems[i]);
+ a=a*exp;
+ }
+ value = value*(1-exp)/(1-a);
+ expComputed = true;
+ return value;
+
+
+ }
+ void fastclear() {first = 0; last = 0; queuesize=0; sumofqueue=0;} // to be called after restarts... Discard the queue
+
+ int size(void) { return queuesize; }
+
+ void clear(bool dealloc = false) { elems.clear(dealloc); first = 0; maxsize=0; queuesize=0;sumofqueue=0;}
+
+
+};
+}
+//=================================================================================================
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/CGlucose.h b/src/sat/glucose2/CGlucose.h
new file mode 100644
index 00000000..7fbf8f83
--- /dev/null
+++ b/src/sat/glucose2/CGlucose.h
@@ -0,0 +1,7 @@
+#ifndef Glucose_CGlucose_h
+#define Glucose_CGlucose_h
+
+#define CGLUCOSE_EXP 1
+#include "sat/glucose2/Heap2.h"
+
+#endif \ No newline at end of file
diff --git a/src/sat/glucose2/CGlucoseCore.h b/src/sat/glucose2/CGlucoseCore.h
new file mode 100644
index 00000000..c0f96fc4
--- /dev/null
+++ b/src/sat/glucose2/CGlucoseCore.h
@@ -0,0 +1,620 @@
+// The code in this file was developed by He-Teng Zhang (National Taiwan University)
+
+#ifndef Glucose_CGlucoseCore_h
+#define Glucose_CGlucoseCore_h
+
+/*
+ * justification for glucose
+ */
+
+#include "sat/glucose2/Options.h"
+#include "sat/glucose2/Solver.h"
+
+ABC_NAMESPACE_IMPL_START
+
+namespace Gluco2 {
+inline int Solver::justUsage() const { return jftr; }
+
+inline Lit Solver::gateJustFanin(Var v) const {
+ assert(v < nVars());
+ assert(isJReason(v));
+
+
+ lbool val0, val1;
+ val0 = value(getFaninLit0(v));
+ val1 = value(getFaninLit1(v));
+
+ if(isAND(v)){
+ // should be handled by conflict analysis before entering here
+ assert( value(v) != l_False || l_True != val0 || l_True != val1 );
+
+ if(val0 == l_False || val1 == l_False)
+ return lit_Undef;
+
+ // branch
+ if(val0 == l_True)
+ return ~getFaninLit1(v);
+ if(val1 == l_True)
+ return ~getFaninLit0(v);
+
+ //assert( jdata[v].act_fanin == activity[getFaninVar0(v)] || jdata[v].act_fanin == activity[getFaninVar1(v)] );
+ //assert( jdata[v].act_fanin == (jdata[v].adir? activity[getFaninVar1(v)]: activity[getFaninVar0(v)]) );
+ return maxActiveLit( ~getFaninLit0(v), ~getFaninLit1(v) );
+ //return jdata[v].adir? ~getFaninLit1(v): ~getFaninLit0(v);
+ } else { // xor scope
+ // should be handled by conflict analysis before entering here
+ assert( value(v) == l_Undef || value(v) != l_False || val0 == val1 );
+
+ // both are assigned
+ if( l_Undef != val0 && l_Undef != val1 )
+ return lit_Undef;
+
+ // should be handled by propagation before entering here
+ assert( l_Undef == val0 && l_Undef == val1 );
+ return maxActiveLit( getFaninPlt0(v), getFaninPlt1(v) );
+ }
+}
+
+
+// a var should at most be enqueued one time
+inline void Solver::pushJustQueue(Var v, int index){
+ assert(v < nVars());
+ assert(isJReason(v));
+
+ if( ! isRoundWatch(v) )\
+ return;
+
+ var2NodeData[v].now = true;
+
+
+ if( activity[getFaninVar1(v)] > activity[getFaninVar0(v)] )
+ jheap.update( JustKey( activity[getFaninVar1(v)], v, index ) );
+ else
+ jheap.update( JustKey( activity[getFaninVar0(v)], v, index ) );
+}
+
+inline void Solver::uncheckedEnqueue2(Lit p, CRef from)
+{
+ //assert( isRoundWatch(var(p)) ); // inplace sorting guarantee this
+ assert(value(p) == l_Undef);
+ assigns[var(p)] = lbool(!sign(p));
+ vardata[var(p)] = mkVarData(from, decisionLevel());
+ trail.push_(p);
+}
+
+inline void Solver::ResetJustData(bool fCleanMemory){
+ jhead = 0;
+ jheap .clear_( fCleanMemory );
+}
+
+inline Lit Solver::pickJustLit( int& index ){
+ Var next = var_Undef;
+ Lit jlit = lit_Undef;
+
+ for( ; jhead < trail.size() ; jhead++ ){
+ Var x = var(trail[jhead]);
+ if( !decisionLevel() && !isRoundWatch(x) ) continue;
+ if( isJReason(x) && l_Undef == value( getFaninVar0(x) ) && l_Undef == value( getFaninVar1(x) ) )
+ pushJustQueue(x,jhead);
+ }
+
+ while( ! jheap.empty() ){
+ next = jheap.removeMin(index);
+ if( ! var2NodeData[next].now )
+ continue;
+
+ assert(isJReason(next));
+ if( lit_Undef != (jlit = gateJustFanin(next)) ){
+ //assert( jheap.prev.key() == activity[getFaninVar0(next)] || jheap.prev.key() == activity[getFaninVar1(next)] );
+ break;
+ }
+ gateAddJwatch(next,index);
+ }
+
+ return jlit;
+}
+
+
+inline void Solver::gateAddJwatch(Var v,int index){
+ assert(v < nVars());
+ assert(isJReason(v));
+
+ lbool val0, val1;
+ Var var0, var1;
+ var0 = getFaninVar0(v);
+ var1 = getFaninVar1(v);
+ val0 = value(getFaninLit0(v));
+ val1 = value(getFaninLit1(v));
+
+ assert( !isAND(v) || l_False == val0 || l_False == val1 );
+ assert( isAND(v) || (l_Undef != val0 && l_Undef != val1) );
+
+ if( (val0 == l_False && val1 == l_False) || !isAND(v) ){
+ addJwatch(vardata[var0].level < vardata[var1].level? var0: var1, v, index);
+ return;
+ }
+
+ addJwatch(l_False == val0? var0: var1, v, index);
+
+ return;
+}
+
+inline void Solver::updateJustActivity( Var v ){
+ if( ! var2NodeData[v].sort )
+ inplace_sort(v);
+
+ int nFanout = 0;
+ for(Lit lfo = var2Fanout0[ v ]; nFanout < var2NodeData[v].sort; lfo = var2FanoutN[ toInt(lfo) ], nFanout ++ ){
+ Var x = var(lfo);
+ if( var2NodeData[x].now && jheap.inHeap(x) ){
+ if( activity[getFaninVar1(x)] > activity[getFaninVar0(x)] )
+ jheap.update( JustKey( activity[getFaninVar1(x)], x, jheap.data_attr(x) ) );
+ else
+ jheap.update( JustKey( activity[getFaninVar0(x)], x, jheap.data_attr(x) ) );
+ }
+ }
+}
+
+
+inline void Solver::addJwatch( Var host, Var member, int index ){
+ assert(level(host) >= level(member));
+ jnext[index] = jlevel[level(host)];
+ jlevel[level(host)] = index;
+}
+
+/*
+ * circuit propagation
+ */
+
+inline void Solver::justCheck(){
+ Lit lit;
+ int i, nJustFail = 0;
+ for(i=0; i<trail.size(); i++){
+ Var x = var(trail[i]);
+ if( ! isRoundWatch(x) )
+ continue;
+ if( !isJReason(x) )
+ continue;
+ if( lit_Undef != (lit = gateJustFanin(x)) ){
+ printf("\t%8d is not justified (value=%d, level=%3d)\n", x, l_True == value(x)? 1: 0, vardata[x].level), nJustFail ++ ;
+
+ assert(false);
+ }
+ }
+ if( nJustFail )
+ printf("%d just-fails\n", nJustFail);
+}
+/**
+inline void Solver::delVarFaninLits( Var v ){
+ if( toLit(~0) != getFaninLit0(v) ){
+ if( toLit(~0) == var2FanoutP[ (v<<1) + 0 ] ){
+ // head of linked-list
+ Lit root = mkLit(getFaninVar0(v));
+ Lit next = var2FanoutN[ (v<<1) + 0 ];
+ if( toLit(~0) != next ){
+ assert( var2Fanout0[ toInt(root) ] == toLit((v<<1) + 0) );
+ assert( var2FanoutP[ toInt(next) ] == toLit((v<<1) + 0) );
+ var2Fanout0[ getFaninVar0(v) ] = next;
+ var2FanoutP[ toInt(next) ] = toLit(~0);
+ }
+ } else {
+ Lit prev = var2FanoutP[ (v<<1) + 0 ];
+ Lit next = var2FanoutN[ (v<<1) + 0 ];
+ if( toLit(~0) != next ){
+ assert( var2FanoutN[ toInt(prev) ] == toLit((v<<1) + 0) );
+ assert( var2FanoutP[ toInt(next) ] == toLit((v<<1) + 0) );
+ var2FanoutN[ toInt(prev) ] = next;
+ var2FanoutP[ toInt(next) ] = prev;
+ }
+ }
+ }
+
+
+ if( toLit(~0) != getFaninLit1(v) ){
+ if( toLit(~0) == var2FanoutP[ (v<<1) + 1 ] ){
+ // head of linked-list
+ Lit root = mkLit(getFaninVar1(v));
+ Lit next = var2FanoutN[ (v<<1) + 1 ];
+ if( toLit(~0) != next ){
+ assert( var2Fanout0[ toInt(root) ] == toLit((v<<1) + 1) );
+ assert( var2FanoutP[ toInt(next) ] == toLit((v<<1) + 1) );
+ var2Fanout0[ getFaninVar1(v) ] = next;
+ var2FanoutP[ toInt(next) ] = toLit(~0);
+ }
+ } else {
+ Lit prev = var2FanoutP[ (v<<1) + 1 ];
+ Lit next = var2FanoutN[ (v<<1) + 1 ];
+ if( toLit(~0) != next ){
+ assert( var2FanoutN[ toInt(prev) ] == toLit((v<<1) + 1) );
+ assert( var2FanoutP[ toInt(next) ] == toLit((v<<1) + 1) );
+ var2FanoutN[ toInt(prev) ] = next;
+ var2FanoutP[ toInt(next) ] = prev;
+ }
+ }
+ }
+
+ var2FanoutP [ (v<<1) + 0 ] = toLit(~0);
+ var2FanoutP [ (v<<1) + 1 ] = toLit(~0);
+ var2FanoutN [ (v<<1) + 0 ] = toLit(~0);
+ var2FanoutN [ (v<<1) + 1 ] = toLit(~0);
+ var2FaninLits[ (v<<1) + 0 ] = toLit(~0);
+ var2FaninLits[ (v<<1) + 1 ] = toLit(~0);
+}
+**/
+inline void Solver::setVarFaninLits( Var v, Lit lit1, Lit lit2 ){
+ assert( var(lit1) != var(lit2) );
+ int mincap = var(lit1) < var(lit2)? var(lit2): var(lit1);
+ mincap = (v < mincap? mincap: v) + 1;
+
+ var2NodeData[ v ].lit0 = lit1;
+ var2NodeData[ v ].lit1 = lit2;
+
+
+ assert( toLit(~0) != lit1 && toLit(~0) != lit2 );
+
+ var2FanoutN[ (v<<1) + 0 ] = var2Fanout0[ var(lit1) ];
+ var2FanoutN[ (v<<1) + 1 ] = var2Fanout0[ var(lit2) ];
+ var2Fanout0[ var(lit1) ] = toLit( (v<<1) + 0 );
+ var2Fanout0[ var(lit2) ] = toLit( (v<<1) + 1 );
+
+ //if( toLit(~0) != var2FanoutN[ (v<<1) + 0 ] )
+ // var2FanoutP[ toInt(var2FanoutN[ (v<<1) + 0 ]) ] = toLit((v<<1) + 0);
+
+ //if( toLit(~0) != var2FanoutN[ (v<<1) + 1 ] )
+ // var2FanoutP[ toInt(var2FanoutN[ (v<<1) + 1 ]) ] = toLit((v<<1) + 1);
+}
+
+
+inline bool Solver::isTwoFanin( Var v ) const {
+ Lit lit0 = var2NodeData[ v ].lit0;
+ Lit lit1 = var2NodeData[ v ].lit1;
+ assert( toLit(~0) == lit0 || var(lit0) < nVars() );
+ assert( toLit(~0) == lit1 || var(lit1) < nVars() );
+ lit0.x = lit1.x = 0; // suppress the warning - alanmi
+ return toLit(~0) != var2NodeData[ v ].lit0 && toLit(~0) != var2NodeData[ v ].lit1;
+}
+
+// this implementation return the last conflict encountered
+// which follows minisat concept
+inline CRef Solver::gatePropagate( Lit p ){
+ CRef confl = CRef_Undef, stats;
+ if( justUsage() < 2 )
+ return CRef_Undef;
+
+ if( ! isRoundWatch(var(p)) )
+ return CRef_Undef;
+
+ if( ! isTwoFanin( var(p) ) )
+ goto check_fanout;
+
+
+ // check fanin consistency
+ if( CRef_Undef != (stats = gatePropagateCheckThis( var(p) )) ){
+ confl = stats;
+ if( l_True == value(var(p)) )
+ return confl;
+ }
+
+ // check fanout consistency
+check_fanout:
+ assert( var(p) < var2Fanout0.size() );
+
+ if( ! var2NodeData[var(p)].sort )
+ inplace_sort(var(p));
+
+ int nFanout = 0;
+ for( Lit lfo = var2Fanout0[ var(p) ]; nFanout < var2NodeData[var(p)].sort; lfo = var2FanoutN[ toInt(lfo) ], nFanout ++ )
+ {
+ if( CRef_Undef != (stats = gatePropagateCheckFanout( var(p), lfo )) ){
+ confl = stats;
+ if( l_True == value(var(lfo)) )
+ return confl;
+ }
+ }
+
+ return confl;
+}
+
+inline CRef Solver::gatePropagateCheckFanout( Var v, Lit lfo ){
+ Lit faninLit = sign(lfo)? getFaninLit1(var(lfo)): getFaninLit0(var(lfo));
+ assert( var(faninLit) == v );
+ if( isAND(var(lfo)) ){
+ if( l_False == value(faninLit) )
+ {
+ if( l_False == value(var(lfo)) )
+ return CRef_Undef;
+
+ if( l_True == value(var(lfo)) )
+ return Var2CRef(var(lfo));
+
+ var2NodeData[var(lfo)].dir = sign(lfo);
+ uncheckedEnqueue2(~mkLit(var(lfo)), Var2CRef( var(lfo) ) );
+ } else {
+ assert( l_True == value(faninLit) );
+
+ if( l_True == value(var(lfo)) )
+ return CRef_Undef;
+
+ // check value of the other fanin
+ Lit faninLitP = sign(lfo)? getFaninLit0(var(lfo)): getFaninLit1(var(lfo));
+ if( l_False == value(var(lfo)) ){
+
+ if( l_False == value(faninLitP) )
+ return CRef_Undef;
+
+ if( l_True == value(faninLitP) )
+ return Var2CRef(var(lfo));
+
+ uncheckedEnqueue2( ~faninLitP, Var2CRef( var(lfo) ) );
+ }
+ else
+ if( l_True == value(faninLitP) )
+ uncheckedEnqueue2( mkLit(var(lfo)), Var2CRef( var(lfo) ) );
+ }
+ } else { // xor scope
+ // check value of the other fanin
+ Lit faninLitP = sign(lfo)? getFaninLit0(var(lfo)): getFaninLit1(var(lfo));
+
+ lbool val0, val1, valo;
+ val0 = value(faninLit );
+ val1 = value(faninLitP);
+ valo = value(var(lfo));
+
+ if( l_Undef == val1 && l_Undef == valo )
+ return CRef_Undef;
+ else
+ if( l_Undef == val1 )
+ uncheckedEnqueue2( ~faninLitP ^ ( (l_True == val0) ^ (l_True == valo) ), Var2CRef( var(lfo) ) );
+ else
+ if( l_Undef == valo )
+ uncheckedEnqueue2( ~mkLit( var(lfo), (l_True == val0) ^ (l_True == val1) ), Var2CRef( var(lfo) ) );
+ else
+ if( l_False == (valo ^ (val0 == val1)) )
+ return Var2CRef(var(lfo));
+
+ }
+
+ return CRef_Undef;
+}
+
+inline CRef Solver::gatePropagateCheckThis( Var v ){
+ CRef confl = CRef_Undef;
+ if( isAND(v) ){
+ if( l_False == value(v) ){
+ if( l_True == value(getFaninLit0(v)) && l_True == value(getFaninLit1(v)) )
+ return Var2CRef(v);
+
+ if( l_False == value(getFaninLit0(v)) || l_False == value(getFaninLit1(v)) )
+ return CRef_Undef;
+
+ if( l_True == value(getFaninLit0(v)) )
+ uncheckedEnqueue2(~getFaninLit1( v ), Var2CRef( v ) );
+ if( l_True == value(getFaninLit1(v)) )
+ uncheckedEnqueue2(~getFaninLit0( v ), Var2CRef( v ) );
+ } else {
+ assert( l_True == value(v) );
+ if( l_False == value(getFaninLit0(v)) || l_False == value(getFaninLit1(v)) )
+ confl = Var2CRef(v);
+
+ if( l_Undef == value( getFaninLit0( v )) )
+ uncheckedEnqueue2( getFaninLit0( v ), Var2CRef( v ) );
+
+ if( l_Undef == value( getFaninLit1( v )) )
+ uncheckedEnqueue2( getFaninLit1( v ), Var2CRef( v ) );
+
+ }
+ } else { // xor scope
+ lbool val0, val1, valo;
+ val0 = value(getFaninLit0(v));
+ val1 = value(getFaninLit1(v));
+ valo = value(v);
+ if( l_Undef == val0 && l_Undef == val1 )
+ return CRef_Undef;
+ if( l_Undef == val0 )
+ uncheckedEnqueue2(~getFaninLit0( v ) ^ ( (l_True == val1) ^ (l_True == valo) ), Var2CRef( v ) );
+ else
+ if( l_Undef == val1 )
+ uncheckedEnqueue2(~getFaninLit1( v ) ^ ( (l_True == val0) ^ (l_True == valo) ), Var2CRef( v ) );
+ else
+ if( l_False == (valo ^ (val0 == val1)) )
+ return Var2CRef(v);
+ }
+
+ return confl;
+}
+
+inline CRef Solver::getConfClause( CRef r ){
+ if( !isGateCRef(r) )
+ return r;
+ Var v = CRef2Var(r);
+ assert( isTwoFanin(v) );
+
+ if(isAND(v)){
+ if( l_False == value(v) ){
+ setItpcSize(3);
+ Clause& c = ca[itpc];
+ c[0] = mkLit(v);
+ c[1] = ~getFaninLit0( v );
+ c[2] = ~getFaninLit1( v );
+ } else {
+ setItpcSize(2);
+ Clause& c = ca[itpc];
+ c[0] = ~mkLit(v);
+
+ lbool val0 = value(getFaninLit0(v));
+ lbool val1 = value(getFaninLit1(v));
+
+ if( l_False == val0 && l_False == val1 )
+ c[1] = level(getFaninVar0(v)) < level(getFaninVar1(v))? getFaninLit0( v ): getFaninLit1( v );
+ else
+ if( l_False == val0 )
+ c[1] = getFaninLit0( v );
+ else
+ c[1] = getFaninLit1( v );
+ }
+ } else { // xor scope
+ setItpcSize(3);
+ Clause& c = ca[itpc];
+ c[0] = mkLit(v, l_True == value(v));
+ c[1] = mkLit(getFaninVar0(v), l_True == value(getFaninVar0(v)));
+ c[2] = mkLit(getFaninVar1(v), l_True == value(getFaninVar1(v)));
+ }
+
+
+ return itpc;
+}
+
+inline void Solver::setItpcSize( int sz ){
+ assert( 3 >= sz );
+ assert( CRef_Undef != itpc );
+ ca[itpc].header.size = sz;
+}
+
+inline CRef Solver::interpret( Var v, Var t )
+{ // get gate-clause on implication graph
+ assert( isTwoFanin(v) );
+
+ lbool val0, val1, valo;
+ Var var0, var1;
+ var0 = getFaninVar0( v );
+ var1 = getFaninVar1( v );
+ val0 = value(var0);
+ val1 = value(var1);
+ valo = value( v );
+
+ // phased values
+ if(l_Undef != val0) val0 = val0 ^ getFaninC0( v );
+ if(l_Undef != val1) val1 = val1 ^ getFaninC1( v );
+
+
+ if( isAND(v) ){
+ if( v == t ){ // tracing output
+ if( l_False == valo ){
+ setItpcSize(2);
+ Clause& c = ca[itpc];
+ c[0] = ~mkLit(v);
+
+ c[1] = var2NodeData[v].dir ? getFaninLit1( v ): getFaninLit0( v );
+ } else {
+ setItpcSize(3);
+ Clause& c = ca[itpc];
+ c[0] = mkLit(v);
+ c[1] = ~getFaninLit0( v );
+ c[2] = ~getFaninLit1( v );
+ }
+ } else {
+ assert( t == var0 || t == var1 );
+ if( l_False == valo ){
+ setItpcSize(3);
+ Clause& c = ca[itpc];
+ c[0] = ~getFaninLit0( v );
+ c[1] = ~getFaninLit1( v );
+ c[2] = mkLit(v);
+ if( t == var1 )
+ c[1].x ^= c[0].x, c[0].x ^= c[1].x, c[1].x ^= c[0].x;
+ } else {
+ setItpcSize(2);
+ Clause& c = ca[itpc];
+ c[0] = t == var0? getFaninLit0( v ): getFaninLit1( v );
+ c[1] = ~mkLit(v);
+ }
+ }
+ } else { // xor scope
+ setItpcSize(3);
+ Clause& c = ca[itpc];
+ if( v == t ){
+ c[0] = mkLit(v, l_False == value(v));
+ c[1] = mkLit(var0, l_True == value(var0));
+ c[2] = mkLit(var1, l_True == value(var1));
+ } else {
+ if( t == var0)
+ c[0] = mkLit(var0, l_False == value(var0)), c[1] = mkLit(var1, l_True == value(var1));
+ else
+ c[1] = mkLit(var0, l_True == value(var0)), c[0] = mkLit(var1, l_False == value(var1));
+ c[2] = mkLit(v, l_True == value(v));
+ }
+ }
+
+ return itpc;
+}
+
+inline CRef Solver::castCRef( Lit p ){
+ CRef cr = reason( var(p) );
+ if( CRef_Undef == cr )
+ return cr;
+ if( ! isGateCRef(cr) )
+ return cr;
+ Var v = CRef2Var(cr);
+ return interpret(v,var(p));
+}
+
+inline void Solver::markCone( Var v ){
+ if( var2TravId[v] >= travId )
+ return;
+ var2TravId[v] = travId;
+ var2NodeData[v].sort = 0;
+ Var var0, var1;
+ var0 = getFaninVar0(v);
+ var1 = getFaninVar1(v);
+ if( !isTwoFanin(v) )
+ return;
+ markCone( var0 );
+ markCone( var1 );
+}
+
+inline void Solver::inplace_sort( Var v ){
+ Lit w, next, prev;
+ prev= var2Fanout0[v];
+
+ if( toLit(~0) == prev ) return;
+
+ if( isRoundWatch(var(prev)) )
+ var2NodeData[v].sort ++ ;
+
+ if( toLit(~0) == (w = var2FanoutN[toInt(prev)]) )
+ return;
+
+ while( toLit(~0) != w ){
+ next = var2FanoutN[toInt(w)];
+ if( isRoundWatch(var(w)) )
+ var2NodeData[v].sort ++ ;
+ if( isRoundWatch(var(w)) && !isRoundWatch(var(prev)) ){
+ var2FanoutN[toInt(w)] = var2Fanout0[v];
+ var2Fanout0[v] = w;
+ var2FanoutN[toInt(prev)] = next;
+ } else
+ prev = w;
+ w = next;
+ }
+}
+
+inline void Solver::prelocate( int base_var_num ){
+ if( justUsage() ){
+ var2FanoutN .prelocate( base_var_num << 1 );
+ var2Fanout0 .prelocate( base_var_num );
+ var2NodeData.prelocate( base_var_num );
+ var2TravId .prelocate( base_var_num );
+ jheap .prelocate( base_var_num );
+ jlevel .prelocate( base_var_num );
+ jnext .prelocate( base_var_num );
+ }
+ watches .prelocate( base_var_num << 1 );
+ watchesBin .prelocate( base_var_num << 1 );
+
+ decision .prelocate( base_var_num );
+ trail .prelocate( base_var_num );
+ assigns .prelocate( base_var_num );
+ vardata .prelocate( base_var_num );
+ activity .prelocate( base_var_num );
+
+
+ seen .prelocate( base_var_num );
+ permDiff .prelocate( base_var_num );
+ polarity .prelocate( base_var_num );
+}
+
+};
+
+ABC_NAMESPACE_IMPL_END
+
+#endif
diff --git a/src/sat/glucose2/Constants.h b/src/sat/glucose2/Constants.h
new file mode 100644
index 00000000..4cccad24
--- /dev/null
+++ b/src/sat/glucose2/Constants.h
@@ -0,0 +1,33 @@
+/************************************************************************************[Constants.h]
+ Glucose -- Copyright (c) 2009, Gilles Audemard, Laurent Simon
+ CRIL - Univ. Artois, France
+ LRI - Univ. Paris Sud, France
+
+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.
+**************************************************************************************************/
+
+#define DYNAMICNBLEVEL
+#define CONSTANTREMOVECLAUSE
+#define UPDATEVARACTIVITY
+
+// Constants for clauses reductions
+#define RATIOREMOVECLAUSES 2
+
+
+
+// Constants for restarts
+#define LOWER_BOUND_FOR_BLOCKING_RESTART 10000
+
diff --git a/src/sat/glucose2/Dimacs.h b/src/sat/glucose2/Dimacs.h
new file mode 100644
index 00000000..1d6a0bed
--- /dev/null
+++ b/src/sat/glucose2/Dimacs.h
@@ -0,0 +1,93 @@
+/****************************************************************************************[Dimacs.h]
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Dimacs_h
+#define Glucose_Dimacs_h
+
+#include <stdio.h>
+
+#include "sat/glucose2/ParseUtils.h"
+#include "sat/glucose2/SolverTypes.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// DIMACS Parser:
+
+template<class B, class Solver>
+static void readClause(B& in, Solver& S, vec<Lit>& lits) {
+ int parsed_lit, var;
+ lits.clear();
+ for (;;){
+ parsed_lit = parseInt(in);
+ if (parsed_lit == 0) break;
+ var = abs(parsed_lit)-1;
+ while (var >= S.nVars()) S.newVar();
+ lits.push( (parsed_lit > 0) ? mkLit(var) : ~mkLit(var) );
+ }
+}
+
+template<class B, class Solver>
+static void parse_DIMACS_main(B& in, Solver& S) {
+ vec<Lit> lits;
+ int vars = 0;
+ int clauses = 0;
+ int cnt = 0;
+ for (;;){
+ skipWhitespace(in);
+ if (*in == EOF) break;
+ else if (*in == 'p'){
+ if (eagerMatch(in, "p cnf")){
+ vars = parseInt(in);
+ clauses = parseInt(in);
+ // SATRACE'06 hack
+ // if (clauses > 4000000)
+ // S.eliminate(true);
+ }else{
+ printf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3);
+ }
+ } else if (*in == 'c' || *in == 'p')
+ skipLine(in);
+ else{
+ cnt++;
+ readClause(in, S, lits);
+ S.addClause_(lits); }
+ }
+ if (vars != S.nVars())
+ fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of variables.\n");
+ if (cnt != clauses)
+ fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of clauses.\n");
+}
+
+// Inserts problem into solver.
+//
+template<class Solver>
+static void parse_DIMACS(gzFile input_stream, Solver& S) {
+ StreamBuffer in(input_stream);
+ parse_DIMACS_main(in, S); }
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/Glucose2.cpp b/src/sat/glucose2/Glucose2.cpp
new file mode 100644
index 00000000..7a8b265b
--- /dev/null
+++ b/src/sat/glucose2/Glucose2.cpp
@@ -0,0 +1,1749 @@
+/***************************************************************************************[Solver.cc]
+ Glucose -- Copyright (c) 2013, Gilles Audemard, Laurent Simon
+ CRIL - Univ. Artois, France
+ LRI - Univ. Paris Sud, France
+
+Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of
+Glucose are exactly the same as Minisat on which it is based on. (see below).
+
+---------------
+
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+#include <math.h>
+
+#include "sat/glucose2/Sort.h"
+#include "sat/glucose2/Constants.h"
+#include "sat/glucose2/System.h"
+#include "sat/glucose2/Solver.h"
+
+#include "sat/glucose2/CGlucose.h"
+
+ABC_NAMESPACE_IMPL_START
+
+using namespace Gluco2;
+
+//=================================================================================================
+// Options:
+namespace Gluco2 {
+static const char* _cat = "CORE";
+static const char* _cr = "CORE -- RESTART";
+static const char* _cred = "CORE -- REDUCE";
+static const char* _cm = "CORE -- MINIMIZE";
+static const char* _certified = "CORE -- CERTIFIED UNSAT";
+
+
+
+
+static BoolOption opt_incremental (_cat,"incremental", "Use incremental SAT solving", false);
+static DoubleOption opt_K (_cr, "K", "The constant used to force restart", 0.8, DoubleRange(0, false, 1, false));
+static DoubleOption opt_R (_cr, "R", "The constant used to block restart", 1.4, DoubleRange(1, false, 5, false));
+static IntOption opt_size_lbd_queue (_cr, "szLBDQueue", "The size of moving average for LBD (restarts)", 50, IntRange(10, INT32_MAX));
+static IntOption opt_size_trail_queue (_cr, "szTrailQueue", "The size of moving average for trail (block restarts)", 5000, IntRange(10, INT32_MAX));
+
+static IntOption opt_first_reduce_db (_cred, "firstReduceDB", "The number of conflicts before the first reduce DB", 2000, IntRange(0, INT32_MAX));
+static IntOption opt_inc_reduce_db (_cred, "incReduceDB", "Increment for reduce DB", 300, IntRange(0, INT32_MAX));
+static IntOption opt_spec_inc_reduce_db (_cred, "specialIncReduceDB", "Special increment for reduce DB", 1000, IntRange(0, INT32_MAX));
+static IntOption opt_lb_lbd_frozen_clause (_cred, "minLBDFrozenClause", "Protect clauses if their LBD decrease and is lower than (for one turn)", 30, IntRange(0, INT32_MAX));
+
+static IntOption opt_lb_size_minimzing_clause (_cm, "minSizeMinimizingClause", "The min size required to minimize clause", 30, IntRange(3, INT32_MAX));
+static IntOption opt_lb_lbd_minimzing_clause (_cm, "minLBDMinimizingClause", "The min LBD required to minimize clause", 6, IntRange(3, INT32_MAX));
+
+
+static DoubleOption opt_var_decay (_cat, "var-decay", "The variable activity decay factor", 0.8, DoubleRange(0, false, 1, false));
+static DoubleOption opt_clause_decay (_cat, "cla-decay", "The clause activity decay factor", 0.999, DoubleRange(0, false, 1, false));
+static DoubleOption opt_random_var_freq (_cat, "rnd-freq", "The frequency with which the decision heuristic tries to choose a random variable", 0, DoubleRange(0, true, 1, true));
+static DoubleOption opt_random_seed (_cat, "rnd-seed", "Used by the random variable selection", 91648253, DoubleRange(0, false, HUGE_VAL, false));
+static IntOption opt_ccmin_mode (_cat, "ccmin-mode", "Controls conflict clause minimization (0=none, 1=basic, 2=deep)", 2, IntRange(0, 2));
+static IntOption opt_phase_saving (_cat, "phase-saving", "Controls the level of phase saving (0=none, 1=limited, 2=full)", 2, IntRange(0, 2));
+static BoolOption opt_rnd_init_act (_cat, "rnd-init", "Randomize the initial activity", false);
+/*
+static IntOption opt_restart_first (_cat, "rfirst", "The base restart interval", 100, IntRange(1, INT32_MAX));
+static DoubleOption opt_restart_inc (_cat, "rinc", "Restart interval increase factor", 2, DoubleRange(1, false, HUGE_VAL, false));
+*/
+static DoubleOption opt_garbage_frac (_cat, "gc-frac", "The fraction of wasted memory allowed before a garbage collection is triggered", 0.20, DoubleRange(0, false, HUGE_VAL, false));
+
+
+BoolOption opt_certified_ (_certified, "certified", "Certified UNSAT using DRUP format", false );
+StringOption opt_certified_file_ (_certified, "certified-output", "Certified UNSAT output file", "NULL");
+};
+
+//=================================================================================================
+// Constructor/Destructor:
+
+
+Solver::Solver() :
+
+ // Parameters (user settable):
+ //
+ SolverType(0)
+ , pCnfFunc(NULL)
+ , nCallConfl(1000)
+ , terminate_search_early(false)
+ , pstop(NULL)
+ , nRuntimeLimit(0)
+
+ , verbosity (0)
+ , verbEveryConflicts(10000)
+ , showModel (0)
+ , K (opt_K)
+ , R (opt_R)
+ , sizeLBDQueue (opt_size_lbd_queue)
+ , sizeTrailQueue (opt_size_trail_queue)
+ , firstReduceDB (opt_first_reduce_db)
+ , incReduceDB (opt_inc_reduce_db)
+ , specialIncReduceDB (opt_spec_inc_reduce_db)
+ , lbLBDFrozenClause (opt_lb_lbd_frozen_clause)
+ , lbSizeMinimizingClause (opt_lb_size_minimzing_clause)
+ , lbLBDMinimizingClause (opt_lb_lbd_minimzing_clause)
+ , var_decay (opt_var_decay)
+ , clause_decay (opt_clause_decay)
+ , random_var_freq (opt_random_var_freq)
+ , random_seed (opt_random_seed)
+ , ccmin_mode (opt_ccmin_mode)
+ , phase_saving (opt_phase_saving)
+ , rnd_pol (false)
+ , rnd_init_act (opt_rnd_init_act)
+ , garbage_frac (opt_garbage_frac)
+ , certifiedOutput (NULL)
+ , certifiedUNSAT (opt_certified_)
+ // Statistics: (formerly in 'SolverStats')
+ //
+ , nbRemovedClauses(0),nbReducedClauses(0), nbDL2(0),nbBin(0),nbUn(0) , nbReduceDB(0)
+ , solves(0), starts(0), decisions(0), rnd_decisions(0), propagations(0),conflicts(0),conflictsRestarts(0),nbstopsrestarts(0),nbstopsrestartssame(0),lastblockatrestart(0)
+ , dec_vars(0), clauses_literals(0), learnts_literals(0), max_literals(0), tot_literals(0)
+ , curRestart(1)
+
+ , ok (true)
+ , cla_inc (1)
+ , var_inc (1)
+ , watches (WatcherDeleted(ca))
+ , watchesBin (WatcherDeleted(ca))
+ , qhead (0)
+ , simpDB_assigns (-1)
+ , simpDB_props (0)
+ , order_heap (VarOrderLt(activity))
+ , progress_estimate (0)
+ , remove_satisfied (true)
+
+ // Resource constraints:
+ //
+ , conflict_budget (-1)
+ , propagation_budget (-1)
+ , asynch_interrupt (false)
+ , incremental(opt_incremental)
+ , nbVarsInitialFormula(INT32_MAX)
+
+ #ifdef CGLUCOSE_EXP
+ //, jheap (JustOrderLt(this))
+ , jheap (JustOrderLt2(this))
+ #endif
+{
+ MYFLAG=0;
+
+ // Initialize only first time. Useful for incremental solving, useless otherwise
+ lbdQueue.initSize(sizeLBDQueue);
+ trailQueue.initSize(sizeTrailQueue);
+ sumLBD = 0;
+ nbclausesbeforereduce = firstReduceDB;
+ totalTime4Sat=0;totalTime4Unsat=0;
+ nbSatCalls=0;nbUnsatCalls=0;
+
+
+ if(certifiedUNSAT) {
+ if(!strcmp(opt_certified_file_,"NULL")) {
+ certifiedOutput = fopen("/dev/stdout", "wb");
+ } else {
+ certifiedOutput = fopen(opt_certified_file_, "wb");
+ }
+ // fprintf(certifiedOutput,"o proof DRUP\n");
+ }
+
+ #ifdef CGLUCOSE_EXP
+ jhead= 0;
+ jftr = 0;
+ travId = 0;
+ travId_prev = 0;
+
+ // allocate space for clause interpretation
+ vec<Lit> tmp; tmp.growTo(3);
+ itpc = ca.alloc(tmp);
+ ca[itpc].shrink( ca[itpc].size() );
+
+ #endif
+}
+
+
+Solver::~Solver()
+{
+}
+
+
+/****************************************************************
+ Set the incremental mode
+****************************************************************/
+
+// This function set the incremental mode to true.
+// You can add special code for this mode here.
+
+void Solver::setIncrementalMode() {
+ incremental = true;
+}
+
+// Number of variables without selectors
+void Solver::initNbInitialVars(int nb) {
+ nbVarsInitialFormula = nb;
+}
+
+
+//=================================================================================================
+// Minor methods:
+
+
+// Creates a new SAT variable in the solver. If 'decision' is cleared, variable will not be
+// used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result).
+//
+Var Solver::newVar(bool sign, bool dvar)
+{
+ int v = nVars();
+ watches .init(mkLit(v, false));
+ watches .init(mkLit(v, true ));
+ watchesBin .init(mkLit(v, false));
+ watchesBin .init(mkLit(v, true ));
+ assigns .push(l_Undef);
+ vardata .push(mkVarData(CRef_Undef, 0));
+ //activity .push(0);
+ activity .push(rnd_init_act ? drand(random_seed) * 0.00001 : 0);
+ seen .push(0);
+ permDiff .push(0);
+ polarity .push(sign);
+ decision .push();
+ trail .capacity(v+1);
+
+
+ #ifdef CGLUCOSE_EXP
+ //jreason .capacity(v+1);
+ if( justUsage() ){
+ //jdata .push(mkJustData(false));
+ //jwatch .push(mkJustWatch());
+
+ jlevel .push(-1);
+ jnext .push(-1);
+
+ var2FanoutN.growTo( nVars()<<1, toLit(~0));
+ //var2FanoutP.growTo( nVars()<<1, toLit(~0));
+ var2Fanout0.growTo( nVars(), toLit(~0));
+ var2NodeData.growTo( nVars(), mkNodeData());
+ var2TravId .growTo( nVars(), 0);
+
+ setDecisionVar(v, dvar, false);
+ } else
+ setDecisionVar(v, dvar);
+ #else
+ setDecisionVar(v, dvar);
+ #endif
+
+ return v;
+}
+
+
+
+bool Solver::addClause_(vec<Lit>& ps)
+{
+ assert(decisionLevel() == 0);
+ if (!ok) return false;
+
+ if ( 0 ) {
+ for ( int i = 0; i < ps.size(); i++ )
+ printf( "%s%d ", (toInt(ps[i]) & 1) ? "-":"", toInt(ps[i]) >> 1 );
+ printf( "\n" );
+ }
+
+ // Check if clause is satisfied and remove false/duplicate literals:
+ sort(ps);
+
+ vec<Lit> oc;
+ oc.clear();
+
+ Lit p; int i, j, flag = 0;
+ if(certifiedUNSAT) {
+ for (i = j = 0, p = lit_Undef; i < ps.size(); i++) {
+ oc.push(ps[i]);
+ if (value(ps[i]) == l_True || ps[i] == ~p || value(ps[i]) == l_False)
+ flag = 1;
+ }
+ }
+
+ for (i = j = 0, p = lit_Undef; i < ps.size(); i++)
+ if (value(ps[i]) == l_True || ps[i] == ~p)
+ return true;
+ else if (value(ps[i]) != l_False && ps[i] != p)
+ ps[j++] = p = ps[i];
+ ps.shrink_(i - j);
+
+ if ( 0 ) {
+ for ( int i = 0; i < ps.size(); i++ )
+ printf( "%s%d ", (toInt(ps[i]) & 1) ? "-":"", toInt(ps[i]) >> 1 );
+ printf( "\n" );
+ }
+
+ if (flag && (certifiedUNSAT)) {
+ for (i = j = 0, p = lit_Undef; i < ps.size(); i++)
+ fprintf(certifiedOutput, "%i ", (var(ps[i]) + 1) * (-2 * sign(ps[i]) + 1));
+ fprintf(certifiedOutput, "0\n");
+
+ fprintf(certifiedOutput, "d ");
+ for (i = j = 0, p = lit_Undef; i < oc.size(); i++)
+ fprintf(certifiedOutput, "%i ", (var(oc[i]) + 1) * (-2 * sign(oc[i]) + 1));
+ fprintf(certifiedOutput, "0\n");
+ }
+
+ if (ps.size() == 0)
+ return ok = false;
+ else if (ps.size() == 1){
+ uncheckedEnqueue(ps[0]);
+ return ok = (propagate() == CRef_Undef);
+ }else{
+ CRef cr = ca.alloc(ps, false);
+ clauses.push(cr);
+ attachClause(cr);
+ }
+
+ return true;
+}
+
+
+void Solver::attachClause(CRef cr) {
+ const Clause& c = ca[cr];
+
+ assert(c.size() > 1);
+ if(c.size()==2) {
+ watchesBin[~c[0]].push(Watcher(cr, c[1]));
+ watchesBin[~c[1]].push(Watcher(cr, c[0]));
+ } else {
+ watches[~c[0]].push(Watcher(cr, c[1]));
+ watches[~c[1]].push(Watcher(cr, c[0]));
+ }
+ if (c.learnt()) learnts_literals += c.size();
+ else clauses_literals += c.size(); }
+
+
+
+
+void Solver::detachClause(CRef cr, bool strict) {
+ const Clause& c = ca[cr];
+
+ assert(c.size() > 1);
+ if(c.size()==2) {
+ if (strict){
+ remove(watchesBin[~c[0]], Watcher(cr, c[1]));
+ remove(watchesBin[~c[1]], Watcher(cr, c[0]));
+ }else{
+ // Lazy detaching: (NOTE! Must clean all watcher lists before garbage collecting this clause)
+ watchesBin.smudge(~c[0]);
+ watchesBin.smudge(~c[1]);
+ }
+ } else {
+ if (strict){
+ remove(watches[~c[0]], Watcher(cr, c[1]));
+ remove(watches[~c[1]], Watcher(cr, c[0]));
+ }else{
+ // Lazy detaching: (NOTE! Must clean all watcher lists before garbage collecting this clause)
+ watches.smudge(~c[0]);
+ watches.smudge(~c[1]);
+ }
+ }
+ if (c.learnt()) learnts_literals -= c.size();
+ else clauses_literals -= c.size(); }
+
+
+void Solver::removeClause(CRef cr) {
+
+ Clause& c = ca[cr];
+
+ if (certifiedUNSAT) {
+ fprintf(certifiedOutput, "d ");
+ for (int i = 0; i < c.size(); i++)
+ fprintf(certifiedOutput, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1));
+ fprintf(certifiedOutput, "0\n");
+ }
+
+ detachClause(cr);
+ // Don't leave pointers to free'd memory!
+ if (locked(c)) vardata[var(c[0])].reason = CRef_Undef;
+ c.mark(1);
+ ca.free_(cr);
+}
+
+
+bool Solver::satisfied(const Clause& c) const {
+ if(incremental) // Check clauses with many selectors is too time consuming
+ return (value(c[0]) == l_True) || (value(c[1]) == l_True);
+
+ // Default mode.
+ for (int i = 0; i < c.size(); i++)
+ if (value(c[i]) == l_True)
+ return true;
+ return false;
+}
+
+/************************************************************
+ * Compute LBD functions
+ *************************************************************/
+
+inline unsigned int Solver::computeLBD(const vec<Lit> & lits,int end) {
+ int nblevels = 0;
+ MYFLAG++;
+
+ if(incremental) { // ----------------- INCREMENTAL MODE
+ if(end==-1) end = lits.size();
+ unsigned int nbDone = 0;
+ for(int i=0;i<lits.size();i++) {
+ if(nbDone>=end) break;
+ if(isSelector(var(lits[i]))) continue;
+ nbDone++;
+ int l = level(var(lits[i]));
+ if (permDiff[l] != MYFLAG) {
+ permDiff[l] = MYFLAG;
+ nblevels++;
+ }
+ }
+ } else { // -------- DEFAULT MODE. NOT A LOT OF DIFFERENCES... BUT EASIER TO READ
+ for(int i=0;i<lits.size();i++) {
+ int l = level(var(lits[i]));
+ if (permDiff[l] != MYFLAG) {
+ permDiff[l] = MYFLAG;
+ nblevels++;
+ }
+ }
+ }
+
+ return nblevels;
+}
+
+inline unsigned int Solver::computeLBD(const Clause &c) {
+ int nblevels = 0;
+ MYFLAG++;
+
+ if(incremental) { // ----------------- INCREMENTAL MODE
+ int nbDone = 0;
+ for(int i=0;i<c.size();i++) {
+ if(nbDone>=c.sizeWithoutSelectors()) break;
+ if(isSelector(var(c[i]))) continue;
+ nbDone++;
+ int l = level(var(c[i]));
+ if (permDiff[l] != MYFLAG) {
+ permDiff[l] = MYFLAG;
+ nblevels++;
+ }
+ }
+ } else { // -------- DEFAULT MODE. NOT A LOT OF DIFFERENCES... BUT EASIER TO READ
+ for(int i=0;i<c.size();i++) {
+ int l = level(var(c[i]));
+ if (permDiff[l] != MYFLAG) {
+ permDiff[l] = MYFLAG;
+ nblevels++;
+ }
+ }
+ }
+ return nblevels;
+}
+
+
+/******************************************************************
+ * Minimisation with binary reolution
+ ******************************************************************/
+void Solver::minimisationWithBinaryResolution(vec<Lit> &out_learnt) {
+
+ // Find the LBD measure
+ unsigned int lbd = computeLBD(out_learnt);
+ Lit p = ~out_learnt[0];
+
+ if(lbd<=lbLBDMinimizingClause){
+ MYFLAG++;
+
+ for(int i = 1;i<out_learnt.size();i++) {
+ permDiff[var(out_learnt[i])] = MYFLAG;
+ }
+
+ vec<Watcher>& wbin = watchesBin[p];
+ int nb = 0;
+ for(int k = 0;k<wbin.size();k++) {
+ Lit imp = wbin[k].blocker;
+ if(permDiff[var(imp)]==MYFLAG && value(imp)==l_True) {
+ nb++;
+ permDiff[var(imp)]= MYFLAG-1;
+ }
+ }
+ int l = out_learnt.size()-1;
+ if(nb>0) {
+ nbReducedClauses++;
+ for(int i = 1;i<out_learnt.size()-nb;i++) {
+ if(permDiff[var(out_learnt[i])]!=MYFLAG) {
+ Lit p = out_learnt[l];
+ out_learnt[l] = out_learnt[i];
+ out_learnt[i] = p;
+ l--;i--;
+ }
+ }
+
+ out_learnt.shrink_(nb);
+
+ }
+ }
+}
+
+// Revert to the state at given level (keeping all assignment at 'level' but not beyond).
+//
+void Solver::cancelUntil(int level) {
+ if (decisionLevel() > level){
+
+ #ifdef CGLUCOSE_EXP
+ if( 0 < justUsage() ){
+
+ for (int c = trail.size()-1; c >= trail_lim[level]; c--){
+ Var x = var(trail[c]);
+ assigns [x] = l_Undef;
+ if (phase_saving > 1 || ((phase_saving == 1) && c > trail_lim.last()))
+ polarity[x] = sign(trail[c]);
+ //gateClearJwatch(x, level);
+
+ var2NodeData[x].now = false;
+ }
+ for (int l = decisionLevel(); l > level; l -- ){
+ int q = jlevel[l], k;
+ jlevel[l] = -1;
+ while( -1 != q ){
+ k = jnext[q];
+ jnext[q] = -1;
+ Var v = var(trail[q]);
+ if( Solver::level(v) <= level ){
+ pushJustQueue(v,q);
+ }
+ q = k;
+ }
+ }
+ } else
+ #endif
+ for (int c = trail.size()-1; c >= trail_lim[level]; c--){
+ Var x = var(trail[c]);
+ assigns [x] = l_Undef;
+ if (phase_saving > 1 || ((phase_saving == 1) && c > trail_lim.last()))
+ polarity[x] = sign(trail[c]);
+ insertVarOrder(x);
+ }
+
+ jhead = qhead = trail_lim[level];
+
+ trail.shrink_(trail.size() - trail_lim[level]);
+ trail_lim.shrink_(trail_lim.size() - level);
+ }
+}
+
+
+//=================================================================================================
+// Major methods:
+
+
+Lit Solver::pickBranchLit()
+{
+ Var next = var_Undef;
+
+ // Random decision:
+ if (drand(random_seed) < random_var_freq && !order_heap.empty()){
+ next = order_heap[irand(random_seed,order_heap.size())];
+ if (value(next) == l_Undef && decision[next])
+ rnd_decisions++; }
+
+ // Activity based decision:
+ while (next == var_Undef || value(next) != l_Undef || !decision[next])
+ if (order_heap.empty()){
+ next = var_Undef;
+ break;
+ }else
+ next = order_heap.removeMin();
+
+ return next == var_Undef ? lit_Undef : mkLit(next, rnd_pol ? drand(random_seed) < 0.5 : (polarity[next] != 0));
+}
+
+
+/*_________________________________________________________________________________________________
+|
+| analyze : (confl : Clause*) (out_learnt : vec<Lit>&) (out_btlevel : int&) -> [void]
+|
+| Description:
+| Analyze conflict and produce a reason clause.
+|
+| Pre-conditions:
+| * 'out_learnt' is assumed to be cleared.
+| * Current decision level must be greater than root level.
+|
+| Post-conditions:
+| * 'out_learnt[0]' is the asserting literal at level 'out_btlevel'.
+| * If out_learnt.size() > 1 then 'out_learnt[1]' has the greatest decision level of the
+| rest of literals. There may be others from the same level though.
+|
+|________________________________________________________________________________________________@*/
+void Solver::analyze(CRef confl, vec<Lit>& out_learnt,vec<Lit>&selectors, int& out_btlevel,unsigned int &lbd,unsigned int &szWithoutSelectors)
+{
+ //double clk = Abc_Clock();
+ heap_rescale = 0;
+
+ int pathC = 0;
+ Lit p = lit_Undef;
+
+ // Generate conflict clause:
+ //
+ out_learnt.push(); // (leave room for the asserting literal)
+ int index = trail.size() - 1;
+
+ analyze_toclear.shrink_( analyze_toclear.size() );
+ do{
+ assert(confl != CRef_Undef); // (otherwise should be UIP)
+
+ #ifdef CGLUCOSE_EXP
+ Clause& c = ca[ lit_Undef != p ? castCRef(p): getConfClause(confl) ];
+ #else
+ Clause& c = ca[confl];
+ #endif
+
+ // Special case for binary clauses
+ // The first one has to be SAT
+ if( p != lit_Undef && c.size()==2 && value(c[0])==l_False) {
+
+ assert(value(c[1])==l_True);
+ Lit tmp = c[0];
+ c[0] = c[1], c[1] = tmp;
+ }
+
+ if (c.learnt())
+ claBumpActivity(c);
+
+#ifdef DYNAMICNBLEVEL
+ // DYNAMIC NBLEVEL trick (see competition'09 companion paper)
+ if(c.learnt() && c.lbd()>2) {
+ unsigned int nblevels = computeLBD(c);
+ if(nblevels+1<c.lbd() ) { // improve the LBD
+ if(c.lbd()<=lbLBDFrozenClause) {
+ c.setCanBeDel(false);
+ }
+ // seems to be interesting : keep it for the next round
+ c.setLBD(nblevels); // Update it
+ }
+ }
+#endif
+
+
+ for (int j = (p == lit_Undef) ? 0 : 1; j < c.size(); j++){
+ Lit q = c[j];
+ bool fBump = 0;
+
+ if (!seen[var(q)] && level(var(q)) > 0){
+ if(!isSelector(var(q))){
+ fBump = 1;
+ varBumpActivity(var(q));
+ }
+ seen[var(q)] = 1;
+ if (level(var(q)) >= decisionLevel()) {
+ if( fBump )
+ analyze_toclear.push(q);
+ pathC++;
+ #ifdef UPDATEVARACTIVITY
+ // UPDATEVARACTIVITY trick (see competition'09 companion paper)
+ #ifdef CGLUCOSE_EXP
+ if(!isSelector(var(q)) && (reason(var(q))!= CRef_Undef)
+ && ! isGateCRef(reason(var(q))) && ca[reason(var(q))].learnt())
+ lastDecisionLevel.push(q);
+ #else
+ if(!isSelector(var(q)) && (reason(var(q))!= CRef_Undef) && ca[reason(var(q))].learnt())
+ lastDecisionLevel.push(q);
+ #endif
+ #endif
+
+ } else {
+ if(isSelector(var(q))) {
+ assert(value(q) == l_False);
+ selectors.push(q);
+ } else
+ out_learnt.push(q);
+ }
+ }
+ }
+
+ // Select next clause to look at:
+ while (!seen[var(trail[index--])]);
+ p = trail[index+1];
+ confl = reason(var(p));
+ seen[var(p)] = 0;
+ pathC--;
+
+ }while (pathC > 0);
+ out_learnt[0] = ~p;
+
+ // Simplify conflict clause:
+ //
+ int i, j;
+
+ for(i = 0;i<selectors.size();i++) out_learnt.push(selectors[i]);
+
+
+ #ifdef CGLUCOSE_EXP
+ for(i = 0;i<out_learnt.size();i++)
+ analyze_toclear.push(out_learnt[i]);
+ #else
+ out_learnt.copyTo_(analyze_toclear);
+ #endif
+ if (ccmin_mode == 2){
+ uint32_t abstract_level = 0;
+ for (i = 1; i < out_learnt.size(); i++)
+ abstract_level |= abstractLevel(var(out_learnt[i])); // (maintain an abstraction of levels involved in conflict)
+
+ for (i = j = 1; i < out_learnt.size(); i++)
+ if (reason(var(out_learnt[i])) == CRef_Undef || !litRedundant(out_learnt[i], abstract_level))
+ out_learnt[j++] = out_learnt[i];
+
+ }else if (ccmin_mode == 1){
+ for (i = j = 1; i < out_learnt.size(); i++){
+ Var x = var(out_learnt[i]);
+
+ if (reason(x) == CRef_Undef)
+ out_learnt[j++] = out_learnt[i];
+ else{
+ #ifdef CGLUCOSE_EXP
+ Clause& c = ca[castCRef(out_learnt[i])];
+ #else
+ Clause& c = ca[reason(var(out_learnt[i]))];
+ #endif
+ // Thanks to Siert Wieringa for this bug fix!
+ for (int k = ((c.size()==2) ? 0:1); k < c.size(); k++)
+ if (!seen[var(c[k])] && level(var(c[k])) > 0){
+ out_learnt[j++] = out_learnt[i];
+ break; }
+ }
+ }
+ }else
+ i = j = out_learnt.size();
+
+ max_literals += out_learnt.size();
+ out_learnt.shrink_(i - j);
+ tot_literals += out_learnt.size();
+
+
+ /* ***************************************
+ Minimisation with binary clauses of the asserting clause
+ First of all : we look for small clauses
+ Then, we reduce clauses with small LBD.
+ Otherwise, this can be useless
+ */
+ if(!incremental && out_learnt.size()<=lbSizeMinimizingClause) {
+ minimisationWithBinaryResolution(out_learnt);
+ }
+ // Find correct backtrack level:
+ //
+ if (out_learnt.size() == 1)
+ out_btlevel = 0;
+ else{
+ int max_i = 1;
+ // Find the first literal assigned at the next-highest level:
+ for (int i = 2; i < out_learnt.size(); i++)
+ if (level(var(out_learnt[i])) > level(var(out_learnt[max_i])))
+ max_i = i;
+ // Swap-in this literal at index 1:
+ Lit p = out_learnt[max_i];
+ out_learnt[max_i] = out_learnt[1];
+ out_learnt[1] = p;
+ out_btlevel = level(var(p));
+ }
+
+
+ // Compute the size of the clause without selectors (incremental mode)
+ if(incremental) {
+ szWithoutSelectors = 0;
+ for(int i=0;i<out_learnt.size();i++) {
+ if(!isSelector(var((out_learnt[i])))) szWithoutSelectors++;
+ else if(i>0) break;
+ }
+ } else
+ szWithoutSelectors = out_learnt.size();
+
+ // Compute LBD
+ lbd = computeLBD(out_learnt,out_learnt.size()-selectors.size());
+
+
+#ifdef UPDATEVARACTIVITY
+ // UPDATEVARACTIVITY trick (see competition'09 companion paper)
+ if(lastDecisionLevel.size()>0) {
+ for(int i = 0;i<lastDecisionLevel.size();i++) {
+ Lit t = lastDecisionLevel[i];
+ //assert( ca[reason(var(t))].learnt() );
+ if(ca[reason(var(t))].lbd()<lbd)
+ varBumpActivity(var(t));
+ }
+ lastDecisionLevel.shrink_( lastDecisionLevel.size() );
+ }
+#endif
+
+
+ if( justUsage() ){
+ if( heap_rescale )
+ {
+ for (j = 0; j < analyze_toclear.size(); j++) seen[var(analyze_toclear[j])] = 0;
+
+ analyze_toclear.shrink_( analyze_toclear.size() );
+ for (j = 0; j < jheap.size(); j++){
+ Var x = jheap[j];
+ if( var2NodeData[x].now )
+ analyze_toclear.push(mkLit(x));
+ }
+ for (j = 0; j < analyze_toclear.size(); j++){
+ Var x = var(analyze_toclear[j]);
+// jdata[x].act_fanin = activity[getFaninVar0(x)] > activity[getFaninVar1(x)]? activity[getFaninVar0(x)]: activity[getFaninVar1(x)];
+// jheap.update(x);
+ if( activity[getFaninVar1(x)] > activity[getFaninVar0(x)] )
+ jheap.update( JustKey( activity[getFaninVar1(x)], x, jheap.data_attr(x) ) );
+ else
+ jheap.update( JustKey( activity[getFaninVar0(x)], x, jheap.data_attr(x) ) );
+ }
+
+ } else {
+
+ for (j = 0; j < analyze_toclear.size(); j++)
+ {
+ seen[var(analyze_toclear[j])] = 0;
+ updateJustActivity(var(analyze_toclear[j]));
+ }
+ }
+ } else
+ for (j = 0; j < analyze_toclear.size(); j++) seen[var(analyze_toclear[j])] = 0; // ('seen[]' is now cleared)
+ for(j = 0 ; j<selectors.size() ; j++) seen[var(selectors[j])] = 0;
+}
+
+
+// Check if 'p' can be removed. 'abstract_levels' is used to abort early if the algorithm is
+// visiting literals at levels that cannot be removed later.
+bool Solver::litRedundant(Lit p, uint32_t abstract_levels)
+{
+ analyze_stack.shrink_( analyze_stack.size() ); analyze_stack.push(p);
+ int top = analyze_toclear.size();
+ while (analyze_stack.size() > 0){
+ assert(reason(var(analyze_stack.last())) != CRef_Undef);
+ #ifdef CGLUCOSE_EXP
+ Clause& c = ca[castCRef(analyze_stack.last())]; analyze_stack.pop();
+ #else
+ Clause& c = ca[reason(var(analyze_stack.last()))]; analyze_stack.pop();
+ #endif
+ if(c.size()==2 && value(c[0])==l_False) {
+ assert(value(c[1])==l_True);
+ Lit tmp = c[0];
+ c[0] = c[1], c[1] = tmp;
+ }
+
+ for (int i = 1; i < c.size(); i++){
+ Lit p = c[i];
+ if (!seen[var(p)] && level(var(p)) > 0){
+ if (reason(var(p)) != CRef_Undef && (abstractLevel(var(p)) & abstract_levels) != 0){
+ seen[var(p)] = 1;
+ analyze_stack.push(p);
+ analyze_toclear.push(p);
+ }else{
+ for (int j = top; j < analyze_toclear.size(); j++)
+ seen[var(analyze_toclear[j])] = 0;
+ analyze_toclear.shrink_(analyze_toclear.size() - top);
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+
+/*_________________________________________________________________________________________________
+|
+| analyzeFinal : (p : Lit) -> [void]
+|
+| Description:
+| Specialized analysis procedure to express the final conflict in terms of assumptions.
+| Calculates the (possibly empty) set of assumptions that led to the assignment of 'p', and
+| stores the result in 'out_conflict'.
+|________________________________________________________________________________________________@*/
+void Solver::analyzeFinal(Lit p, vec<Lit>& out_conflict)
+{
+ out_conflict.shrink_( out_conflict.size() );
+ out_conflict.push(p);
+
+ if (decisionLevel() == 0)
+ return;
+
+ seen[var(p)] = 1;
+
+ for (int i = trail.size()-1; i >= trail_lim[0]; i--){
+ Var x = var(trail[i]);
+ if (seen[x]){
+ if (reason(x) == CRef_Undef){
+ assert(level(x) > 0);
+ out_conflict.push(~trail[i]);
+ }else{
+ #ifdef CGLUCOSE_EXP
+ Clause& c = ca[castCRef(trail[i])];
+ #else
+ Clause& c = ca[reason(x)];
+ #endif
+ // for (int j = 1; j < c.size(); j++) Minisat (glucose 2.0) loop
+ // Bug in case of assumptions due to special data structures for Binary.
+ // Many thanks to Sam Bayless (sbayless@cs.ubc.ca) for discover this bug.
+ for (int j = ((c.size()==2) ? 0:1); j < c.size(); j++)
+ if (level(var(c[j])) > 0)
+ seen[var(c[j])] = 1;
+ }
+
+ seen[x] = 0;
+ }
+ }
+
+ seen[var(p)] = 0;
+}
+
+void Solver::uncheckedEnqueue(Lit p, CRef from)
+{
+ if( justUsage() && !isRoundWatch(var(p)) )
+ return;
+ assert(value(p) == l_Undef);
+ assigns[var(p)] = lbool(!sign(p));
+ vardata[var(p)] = mkVarData(from, decisionLevel());
+ trail.push_(p);
+}
+
+
+/*_________________________________________________________________________________________________
+|
+| propagate : [void] -> [Clause*]
+|
+| Description:
+| Propagates all enqueued facts. If a conflict arises, the conflicting clause is returned,
+| otherwise CRef_Undef.
+|
+| Post-conditions:
+| * the propagation queue is empty, even if there was a conflict.
+|________________________________________________________________________________________________@*/
+CRef Solver::propagate()
+{
+ CRef confl = CRef_Undef;
+ int num_props = 0;
+ watches.cleanAll();
+ watchesBin.cleanAll();
+ while (qhead < trail.size()){
+ Lit p = trail[qhead++]; // 'p' is enqueued fact to propagate.
+ vec<Watcher>& ws = watches[p];
+ Watcher *i, *j, *end;
+ num_props++;
+
+ #ifdef CGLUCOSE_EXP
+ if( 2 <= justUsage() ){
+ CRef stats;
+ if( CRef_Undef != (stats = gatePropagate(p)) ){
+ confl = stats;
+ if( l_True == value(var(p)) ) return confl;
+ }
+ }
+ #endif
+
+ // First, Propagate binary clauses
+ vec<Watcher>& wbin = watchesBin[p];
+ for(int k = 0;k<wbin.size();k++) {
+ Lit imp = wbin[k].blocker;
+ if(value(imp) == l_False) {
+ return wbin[k].cref;
+ }
+ if(value(imp) == l_Undef) {
+ uncheckedEnqueue(imp,wbin[k].cref);
+ }
+ }
+
+
+
+ for (i = j = (Watcher*)ws, end = i + ws.size(); i != end;){
+ // Try to avoid inspecting the clause:
+ Lit blocker = i->blocker;
+ if (value(blocker) == l_True){
+ *j++ = *i++; continue; }
+
+ // Make sure the false literal is data[1]:
+ CRef cr = i->cref;
+ Clause& c = ca[cr];
+ Lit false_lit = ~p;
+ if (c[0] == false_lit)
+ c[0] = c[1], c[1] = false_lit;
+ assert(c[1] == false_lit);
+ i++;
+
+ // If 0th watch is true, then clause is already satisfied.
+ Lit first = c[0];
+ Watcher w = Watcher(cr, first);
+ if (first != blocker && value(first) == l_True){
+ *j++ = w; continue; }
+
+ // Look for new watch:
+ if(incremental) { // ----------------- INCREMENTAL MODE
+ int choosenPos = -1;
+ for (int k = 2; k < c.size(); k++) {
+
+ if (value(c[k]) != l_False){
+ if(decisionLevel()>assumptions.size()) {
+ choosenPos = k;
+ break;
+ } else {
+ choosenPos = k;
+
+ if(value(c[k])==l_True || !isSelector(var(c[k]))) {
+ break;
+ }
+ }
+
+ }
+ }
+ if(choosenPos!=-1) {
+ c[1] = c[choosenPos]; c[choosenPos] = false_lit;
+ watches[~c[1]].push(w);
+ goto NextClause; }
+ } else { // ----------------- DEFAULT MODE (NOT INCREMENTAL)
+ for (int k = 2; k < c.size(); k++) {
+
+ if (value(c[k]) != l_False){
+ c[1] = c[k]; c[k] = false_lit;
+ watches[~c[1]].push(w);
+ goto NextClause; }
+ }
+ }
+
+ // Did not find watch -- clause is unit under assignment:
+ *j++ = w;
+ if (value(first) == l_False){
+ confl = cr;
+ qhead = trail.size();
+ // Copy the remaining watches:
+ while (i < end)
+ *j++ = *i++;
+ }else {
+ uncheckedEnqueue(first, cr);
+
+
+ }
+ NextClause:;
+ }
+ ws.shrink_(i - j);
+ }
+ propagations += num_props;
+ simpDB_props -= num_props;
+
+ return confl;
+}
+
+
+
+
+
+
+/*_________________________________________________________________________________________________
+|
+| reduceDB : () -> [void]
+|
+| Description:
+| Remove half of the learnt clauses, minus the clauses locked by the current assignment. Locked
+| clauses are clauses that are reason to some assignment. Binary clauses are never removed.
+|________________________________________________________________________________________________@*/
+struct reduceDB_lt {
+ ClauseAllocator& ca;
+ reduceDB_lt(ClauseAllocator& ca_) : ca(ca_) {}
+ bool operator () (CRef x, CRef y) {
+
+ // Main criteria... Like in MiniSat we keep all binary clauses
+ if(ca[x].size()> 2 && ca[y].size()==2) return 1;
+
+ if(ca[y].size()> 2 && ca[x].size()==2) return 0;
+ if(ca[x].size()==2 && ca[y].size()==2) return 0;
+
+ // Second one based on literal block distance
+ if(ca[x].lbd()> ca[y].lbd()) return 1;
+ if(ca[x].lbd()< ca[y].lbd()) return 0;
+
+ // Finally we can use old activity or size, we choose the last one
+ return ca[x].activity() < ca[y].activity();
+ //return x->size() < y->size();
+ //return ca[x].size() > 2 && (ca[y].size() == 2 || ca[x].activity() < ca[y].activity()); }
+ }
+};
+
+void Solver::reduceDB()
+{
+ int i, j;
+ nbReduceDB++;
+ sort(learnts, reduceDB_lt(ca));
+
+ // We have a lot of "good" clauses, it is difficult to compare them. Keep more !
+ if(ca[learnts[learnts.size() / RATIOREMOVECLAUSES]].lbd()<=3) nbclausesbeforereduce +=specialIncReduceDB;
+ // Useless :-)
+ if(ca[learnts.last()].lbd()<=5) nbclausesbeforereduce +=specialIncReduceDB;
+
+ // Don't delete binary or locked clauses. From the rest, delete clauses from the first half
+ // Keep clauses which seem to be usefull (their lbd was reduce during this sequence)
+
+ int limit = learnts.size() / 2;
+ for (i = j = 0; i < learnts.size(); i++){
+ Clause& c = ca[learnts[i]];
+ if (c.lbd()>2 && c.size() > 2 && c.canBeDel() && !locked(c) && (i < limit)) {
+ removeClause(learnts[i]);
+ nbRemovedClauses++;
+ }
+ else {
+ if(!c.canBeDel()) limit++; //we keep c, so we can delete an other clause
+ c.setCanBeDel(true); // At the next step, c can be delete
+ learnts[j++] = learnts[i];
+ }
+ }
+ learnts.shrink_(i - j);
+ checkGarbage();
+}
+
+
+void Solver::removeSatisfied(vec<CRef>& cs)
+{
+ int i, j;
+ for (i = j = 0; i < cs.size(); i++){
+ Clause& c = ca[cs[i]];
+ if (satisfied(c))
+ removeClause(cs[i]);
+ else
+ cs[j++] = cs[i];
+ }
+ cs.shrink_(i - j);
+}
+
+
+void Solver::rebuildOrderHeap()
+{
+ vec<Var> vs;
+ for (Var v = 0; v < nVars(); v++)
+ if (decision[v] && value(v) == l_Undef)
+ vs.push(v);
+ order_heap.build(vs);
+}
+
+
+/*_________________________________________________________________________________________________
+|
+| simplify : [void] -> [bool]
+|
+| Description:
+| Simplify the clause database according to the current top-level assigment. Currently, the only
+| thing done here is the removal of satisfied clauses, but more things can be put here.
+|________________________________________________________________________________________________@*/
+bool Solver::simplify()
+{
+ assert(decisionLevel() == 0);
+
+ if (!ok || propagate() != CRef_Undef)
+ return ok = false;
+
+ if (nAssigns() == simpDB_assigns || (simpDB_props > 0))
+ return true;
+
+ // Remove satisfied clauses:
+ removeSatisfied(learnts);
+ if (remove_satisfied) // Can be turned off.
+ removeSatisfied(clauses);
+
+ checkGarbage();
+
+ #ifdef CGLUCOSE_EXP
+ if( !justUsage() )
+ #endif
+ rebuildOrderHeap();
+
+ simpDB_assigns = nAssigns();
+ simpDB_props = clauses_literals + learnts_literals; // (shouldn't depend on stats really, but it will do for now)
+
+ return true;
+}
+
+
+/*_________________________________________________________________________________________________
+|
+| search : (nof_conflicts : int) (params : const SearchParams&) -> [lbool]
+|
+| Description:
+| Search for a model the specified number of conflicts.
+| NOTE! Use negative value for 'nof_conflicts' indicate infinity.
+|
+| Output:
+| 'l_True' if a partial assigment that is consistent with respect to the clauseset is found. If
+| all variables are decision variables, this means that the clause set is satisfiable. 'l_False'
+| if the clause set is unsatisfiable. 'l_Undef' if the bound on number of conflicts is reached.
+|________________________________________________________________________________________________@*/
+lbool Solver::search(int nof_conflicts)
+{
+ assert(ok);
+ int backtrack_level;
+ int conflictC = 0;
+ vec<Lit> learnt_clause,selectors;
+ unsigned int nblevels,szWoutSelectors;
+ bool blocked=false;
+ starts++;
+
+ for (;;){
+ CRef confl = propagate();
+
+ // exact conflict limit
+ if ( !withinBudget() && confl != CRef_Undef ) {
+ lbdQueue.fastclear();
+ cancelUntil(0);
+ return l_Undef; }
+
+ if (confl != CRef_Undef){
+
+ // CONFLICT
+ conflicts++; conflictC++;conflictsRestarts++;
+ if(conflicts%5000==0 && var_decay<0.95)
+ var_decay += 0.01;
+
+ if (verbosity >= 1 && conflicts%verbEveryConflicts==0){
+ printf("c | %8d %7d %5d | %7d %8d %8d | %5d %8d %6d %8d | %6.3f %% \n",
+ (int)starts,(int)nbstopsrestarts, (int)(conflicts/starts),
+ (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]), nClauses(), (int)clauses_literals,
+ (int)nbReduceDB, nLearnts(), (int)nbDL2,(int)nbRemovedClauses, progressEstimate()*100);
+ }
+ if (decisionLevel() == 0)
+ return l_False;
+
+
+ trailQueue.push(trail.size());
+ // BLOCK RESTART (CP 2012 paper)
+ if( conflictsRestarts>LOWER_BOUND_FOR_BLOCKING_RESTART && lbdQueue.isvalid() && trail.size()>R*trailQueue.getavg()) {
+ lbdQueue.fastclear();
+ nbstopsrestarts++;
+ if(!blocked) {lastblockatrestart=starts;nbstopsrestartssame++;blocked=true;}
+ }
+
+ learnt_clause.shrink_( learnt_clause.size() );
+ selectors .shrink_( selectors.size() );
+ analyze(confl, learnt_clause, selectors,backtrack_level,nblevels,szWoutSelectors);
+
+ lbdQueue.push(nblevels);
+ sumLBD += nblevels;
+ cancelUntil(backtrack_level);
+ if (certifiedUNSAT) {
+ for (int i = 0; i < learnt_clause.size(); i++)
+ fprintf(certifiedOutput, "%i " , (var(learnt_clause[i]) + 1) *
+ (-2 * sign(learnt_clause[i]) + 1) );
+ fprintf(certifiedOutput, "0\n");
+ }
+
+ if (learnt_clause.size() == 1){
+ uncheckedEnqueue(learnt_clause[0]);nbUn++;
+ }else{
+ CRef cr = ca.alloc(learnt_clause, true);
+ ca[cr].setLBD(nblevels);
+ ca[cr].setSizeWithoutSelectors(szWoutSelectors);
+ if(nblevels<=2) nbDL2++; // stats
+ if(ca[cr].size()==2) nbBin++; // stats
+ learnts.push(cr);
+ attachClause(cr);
+
+ claBumpActivity(ca[cr]);
+ uncheckedEnqueue(learnt_clause[0], cr);
+ }
+ varDecayActivity();
+ claDecayActivity();
+
+ }else{
+ // Our dynamic restart, see the SAT09 competition compagnion paper
+ if ( (conflictsRestarts && lbdQueue.isvalid() && lbdQueue.getavg()*K > sumLBD/conflictsRestarts) || (pstop && *pstop) ) {
+ lbdQueue.fastclear();
+ progress_estimate = progressEstimate();
+ int bt = 0;
+ if(incremental) { // DO NOT BACKTRACK UNTIL 0.. USELESS
+ bt = (decisionLevel()<assumptions.size()) ? decisionLevel() : assumptions.size();
+ }
+ cancelUntil(bt);
+ return l_Undef;
+ }
+
+ // Simplify the set of problem clauses:
+ if (decisionLevel() == 0 && !simplify()) {
+ return l_False;
+ }
+ // Perform clause database reduction !
+ if(conflicts>=curRestart* nbclausesbeforereduce)
+ {
+ assert(learnts.size()>0);
+ curRestart = (conflicts/ nbclausesbeforereduce)+1;
+ reduceDB();
+ nbclausesbeforereduce += incReduceDB;
+ }
+
+ Lit next = lit_Undef;
+ while (decisionLevel() < assumptions.size()){
+ // Perform user provided assumption:
+ Lit p = assumptions[decisionLevel()];
+ if (value(p) == l_True){
+ // Dummy decision level:
+ newDecisionLevel();
+ } else if (value(p) == l_False){
+ analyzeFinal(~p, conflict);
+ return l_False;
+ } else {
+ next = p;
+ break;
+ }
+ }
+
+ #ifdef CGLUCOSE_EXP
+ // pick from JustQueue
+
+ if (0 < justUsage())
+ if ( next == lit_Undef ){
+ int index = -1;
+ decisions++;
+ next = pickJustLit( index );
+ if(next == lit_Undef)
+ return l_True;
+ //addJwatch(var(next), j_reason);
+ jnext[index] = jlevel[decisionLevel()+1];
+ jlevel[decisionLevel()+1] = index;
+ }
+ #endif
+
+ if (next == lit_Undef){
+ // New variable decision:
+ decisions++;
+ next = pickBranchLit();
+
+ if (next == lit_Undef){
+ // Model found:
+ return l_True;
+ }
+ }
+
+ // Increase decision level and enqueue 'next'
+ newDecisionLevel();
+ uncheckedEnqueue(next);
+ }
+ }
+}
+
+
+
+double Solver::progressEstimate() const
+{
+ double progress = 0;
+ double F = 1.0 / nVars();
+
+ for (int i = 0; i <= decisionLevel(); i++){
+ int beg = i == 0 ? 0 : trail_lim[i - 1];
+ int end = i == decisionLevel() ? trail.size() : trail_lim[i];
+ progress += pow(F, i) * (end - beg);
+ }
+
+ return progress / nVars();
+}
+
+void Solver::printIncrementalStats() {
+
+ printf("c---------- Glucose Stats -------------------------\n");
+ printf("c restarts : %ld\n", starts);
+ printf("c nb ReduceDB : %ld\n", nbReduceDB);
+ printf("c nb removed Clauses : %ld\n", nbRemovedClauses);
+ printf("c nb learnts DL2 : %ld\n", nbDL2);
+ printf("c nb learnts size 2 : %ld\n", nbBin);
+ printf("c nb learnts size 1 : %ld\n", nbUn);
+
+ printf("c conflicts : %ld\n", conflicts);
+ printf("c decisions : %ld\n", decisions);
+ printf("c propagations : %ld\n", propagations);
+
+ printf("c SAT Calls : %d in %g seconds\n", nbSatCalls, totalTime4Sat);
+ printf("c UNSAT Calls : %d in %g seconds\n", nbUnsatCalls, totalTime4Unsat);
+ printf("c--------------------------------------------------\n");
+
+
+}
+
+
+// NOTE: assumptions passed in member-variable 'assumptions'.
+lbool Solver::solve_()
+{
+
+ #ifdef CGLUCOSE_EXP
+ ResetJustData(false);
+ #endif
+
+ if(incremental && certifiedUNSAT) {
+ printf("Can not use incremental and certified unsat in the same time\n");
+ exit(-1);
+ }
+
+ conflict.shrink_(conflict.size());
+ if (!ok){
+ travId_prev = travId;
+ return l_False;
+ }
+ double curTime = cpuTime();
+
+ solves++;
+
+ lbool status = l_Undef;
+ if(!incremental && verbosity>=1) {
+ printf("c ========================================[ MAGIC CONSTANTS ]==============================================\n");
+ printf("c | Constants are supposed to work well together :-) |\n");
+ printf("c | however, if you find better choices, please let us known... |\n");
+ printf("c |-------------------------------------------------------------------------------------------------------|\n");
+ printf("c | | | |\n");
+ printf("c | - Restarts: | - Reduce Clause DB: | - Minimize Asserting: |\n");
+ printf("c | * LBD Queue : %6d | * First : %6d | * size < %3d |\n",lbdQueue.maxSize(),nbclausesbeforereduce,lbSizeMinimizingClause);
+ printf("c | * Trail Queue : %6d | * Inc : %6d | * lbd < %3d |\n",trailQueue.maxSize(),incReduceDB,lbLBDMinimizingClause);
+ printf("c | * K : %6.2f | * Special : %6d | |\n",K,specialIncReduceDB);
+ printf("c | * R : %6.2f | * Protected : (lbd)< %2d | |\n",R,lbLBDFrozenClause);
+ printf("c | | | |\n");
+printf("c ==================================[ Search Statistics (every %6d conflicts) ]=========================\n",verbEveryConflicts);
+ printf("c | |\n");
+
+ printf("c | RESTARTS | ORIGINAL | LEARNT | Progress |\n");
+ printf("c | NB Blocked Avg Cfc | Vars Clauses Literals | Red Learnts LBD2 Removed | | pol-inconsist\n");
+ printf("c =========================================================================================================\n");
+ }
+
+ // Search:
+ int curr_restarts = 0;
+ while (status == l_Undef){
+ status = search(0); // the parameter is useless in glucose, kept to allow modifications
+ if (!withinBudget() || terminate_search_early || (pstop && *pstop)) break;
+ if (nRuntimeLimit && Abc_Clock() > nRuntimeLimit) break;
+ curr_restarts++;
+ }
+
+ if (!incremental && verbosity >= 1)
+ printf("c =========================================================================================================\n");
+
+
+ if (certifiedUNSAT){ // Want certified output
+ if (status == l_False)
+ fprintf(certifiedOutput, "0\n");
+ fclose(certifiedOutput);
+ }
+
+
+ if (status == l_True){
+
+ if( justUsage() ){
+ JustModel.shrink_(JustModel.size());
+ assert(jheap.empty());
+ //JustModel.growTo(nVars());
+ int i = 0, j = 0;
+ JustModel.push(toLit(0));
+ for (; i < trail.size(); i++)
+ if( isRoundWatch(var(trail[i])) && !isTwoFanin(var(trail[i])) )
+ JustModel.push(trail[i]), j++;
+ JustModel[0] = toLit(j);
+ } else {
+ // Extend & copy model:
+ model.shrink_(model.size());
+ model.growTo(nVars());
+ for (int i = 0; i < trail.size(); i++) model[ var(trail[i]) ] = value(var(trail[i]));
+ }
+ }else if (status == l_False && conflict.size() == 0)
+ ok = false;
+
+ //#ifdef CGLUCOSE_EXP
+ //if(status == l_True && 0 < justUsage())
+ // justCheck();
+ //#endif
+
+ cancelUntil(0);
+
+ double finalTime = cpuTime();
+ if(status==l_True) {
+ nbSatCalls++;
+ totalTime4Sat +=(finalTime-curTime);
+ }
+ if(status==l_False) {
+ nbUnsatCalls++;
+ totalTime4Unsat +=(finalTime-curTime);
+ }
+
+ // ABC callback
+ if (pCnfFunc && !terminate_search_early) {// hack to avoid calling callback twise if the solver was terminated early
+ int * pCex = NULL;
+ int message = (status == l_True ? 1 : status == l_False ? 0 : -1);
+ if (status == l_True) {
+ pCex = new int[nVars()];
+ for (int i = 0; i < nVars(); i++)
+ pCex[i] = (model[i] == l_True);
+ }
+
+ int callback_result = pCnfFunc(pCnfMan, message, pCex);
+ assert(callback_result == 0);
+ }
+ else if (pCnfFunc)
+ terminate_search_early = false; // for next run
+
+ travId_prev = travId;
+ return status;
+}
+
+//=================================================================================================
+// Writing CNF to DIMACS:
+//
+// FIXME: this needs to be rewritten completely.
+
+static Var mapVar(Var x, vec<Var>& map, Var& max)
+{
+ if (map.size() <= x || map[x] == -1){
+ map.growTo(x+1, -1);
+ map[x] = max++;
+ }
+ return map[x];
+}
+
+
+void Solver::toDimacs(FILE* f, Clause& c, vec<Var>& map, Var& max)
+{
+ if (satisfied(c)) return;
+
+ for (int i = 0; i < c.size(); i++)
+ if (value(c[i]) != l_False)
+ fprintf(f, "%s%d ", sign(c[i]) ? "-" : "", mapVar(var(c[i]), map, max)+1);
+ fprintf(f, "0\n");
+}
+
+
+void Solver::toDimacs(const char *file, const vec<Lit>& assumps)
+{
+ FILE* f = fopen(file, "wr");
+ if (f == NULL)
+ fprintf(stderr, "could not open file %s\n", file), exit(1);
+ toDimacs(f, assumps);
+ fclose(f);
+}
+
+
+void Solver::toDimacs(FILE* f, const vec<Lit>& assumps)
+{
+ // Handle case when solver is in contradictory state:
+ if (!ok){
+ fprintf(f, "p cnf 1 2\n1 0\n-1 0\n");
+ return; }
+
+ vec<Var> map; Var max = 0;
+
+ // Cannot use removeClauses here because it is not safe
+ // to deallocate them at this point. Could be improved.
+ int i, cnt = 0;
+ for (i = 0; i < clauses.size(); i++)
+ if (!satisfied(ca[clauses[i]]))
+ cnt++;
+
+ for (i = 0; i < clauses.size(); i++)
+ if (!satisfied(ca[clauses[i]])){
+ Clause& c = ca[clauses[i]];
+ for (int j = 0; j < c.size(); j++)
+ if (value(c[j]) != l_False)
+ mapVar(var(c[j]), map, max);
+ }
+
+ // Assumptions are added as unit clauses:
+ cnt += assumptions.size();
+
+ fprintf(f, "p cnf %d %d\n", max, cnt);
+
+ for (i = 0; i < assumptions.size(); i++){
+ assert(value(assumptions[i]) != l_False);
+ fprintf(f, "%s%d 0\n", sign(assumptions[i]) ? "-" : "", mapVar(var(assumptions[i]), map, max)+1);
+ }
+
+ for (i = 0; i < clauses.size(); i++)
+ toDimacs(f, ca[clauses[i]], map, max);
+
+ if (verbosity > 0)
+ printf("Wrote %d clauses with %d variables.\n", cnt, max);
+}
+
+
+//=================================================================================================
+// Garbage Collection methods:
+
+void Solver::relocAll(ClauseAllocator& to)
+{
+ #ifdef CGLUCOSE_EXP
+ if( CRef_Undef != itpc ){
+ setItpcSize(3);
+ ca.reloc(itpc, to);
+ }
+ #endif
+ int v, s, i, j;
+ // All watchers:
+ //
+ // for (int i = 0; i < watches.size(); i++)
+ watches.cleanAll();
+ watchesBin.cleanAll();
+ for (v = 0; v < nVars(); v++)
+ for (s = 0; s < 2; s++){
+ Lit p = mkLit(v, s != 0);
+ // printf(" >>> RELOCING: %s%d\n", sign(p)?"-":"", var(p)+1);
+ vec<Watcher>& ws = watches[p];
+ for (j = 0; j < ws.size(); j++)
+ ca.reloc(ws[j].cref, to);
+ vec<Watcher>& ws2 = watchesBin[p];
+ for (j = 0; j < ws2.size(); j++)
+ ca.reloc(ws2[j].cref, to);
+ }
+
+ // All reasons:
+ //
+ for (i = 0; i < trail.size(); i++){
+ Var v = var(trail[i]);
+
+ #ifdef CGLUCOSE_EXP
+ if( isGateCRef(reason(v)) )
+ continue;
+ #endif
+ if (reason(v) != CRef_Undef && (ca[reason(v)].reloced() || locked(ca[reason(v)])))
+ ca.reloc(vardata[v].reason, to);
+ }
+
+ // All learnt:
+ //
+ for (i = 0; i < learnts.size(); i++)
+ ca.reloc(learnts[i], to);
+
+ // All original:
+ //
+ for (i = 0; i < clauses.size(); i++)
+ ca.reloc(clauses[i], to);
+}
+
+
+void Solver::garbageCollect()
+{
+ // Initialize the next region to a size corresponding to the estimated utilization degree. This
+ // is not precise but should avoid some unnecessary reallocations for the new region:
+ ClauseAllocator to(ca.size() - ca.wasted());
+
+ relocAll(to);
+ if (verbosity >= 2)
+ printf("| Garbage collection: %12d bytes => %12d bytes |\n",
+ ca.size()*ClauseAllocator::Unit_Size, to.size()*ClauseAllocator::Unit_Size);
+ to.moveTo(ca);
+}
+
+void Solver::reset()
+{
+ // Reset everything
+ ok = true;
+ K = (double)opt_K;
+ R = (double)opt_R;
+ firstReduceDB = opt_first_reduce_db;
+ var_decay = (double)opt_var_decay;
+ //max_var_decay = opt_max_var_decay;
+ solves = starts = decisions = propagations = conflicts = conflictsRestarts = 0;
+ curRestart = 1;
+ cla_inc = var_inc = 1;
+ watches.clear(false); // We don't free the memory, new calls should be of the same size order.
+ watchesBin.clear(false);
+ //unaryWatches.clear(false);
+ qhead = 0;
+ simpDB_assigns = -1;
+ simpDB_props = 0;
+ order_heap.clear(false);
+ progress_estimate = 0;
+ //lastLearntClause = CRef_Undef;
+ conflict_budget = -1;
+ propagation_budget = -1;
+ nbVarsInitialFormula = INT32_MAX;
+ totalTime4Sat = 0.;
+ totalTime4Unsat = 0.;
+ nbSatCalls = nbUnsatCalls = 0;
+ MYFLAG = 0;
+ lbdQueue.clear(false);
+ lbdQueue.initSize(sizeLBDQueue);
+ trailQueue.clear(false);
+ trailQueue.initSize(sizeTrailQueue);
+ sumLBD = 0;
+ nbclausesbeforereduce = firstReduceDB;
+ //stats.clear();
+ //stats.growTo(coreStatsSize, 0);
+ clauses.clear(false);
+ learnts.clear(false);
+ //permanentLearnts.clear(false);
+ //unaryWatchedClauses.clear(false);
+ model .shrink_(model .size());
+ conflict.shrink_(conflict.size());
+ activity.shrink_(activity.size());
+ assigns .shrink_(assigns .size());
+ polarity.shrink_(polarity.size());
+ //forceUNSAT.clear(false);
+ decision .shrink_(decision .size());
+ trail .shrink_(trail .size());
+ trail_lim .shrink_(trail_lim .size());
+ vardata .shrink_(vardata .size());
+ assumptions.shrink_(assumptions.size());
+ nbpos .shrink_(nbpos .size());
+ permDiff .shrink_(permDiff .size());
+ #ifdef UPDATEVARACTIVITY
+ lastDecisionLevel.shrink_(lastDecisionLevel.size());
+ #endif
+ ca.clear();
+ seen .shrink_(seen.size());
+ analyze_stack .shrink_(analyze_stack .size());
+ analyze_toclear.shrink_(analyze_toclear.size());
+ add_tmp.clear(false);
+ assumptionPositions.clear(false);
+ initialPositions.clear(false);
+
+ #ifdef CGLUCOSE_EXP
+
+ ResetJustData(false);
+
+ //jwatch.shrink_(jwatch.size());
+ //jdata .shrink_(jdata .size());
+
+ jhead = 0;
+ travId = 0;
+ travId_prev = 0;
+ var2TravId .shrink_(var2TravId.size());
+ JustModel .shrink_(JustModel .size());
+ jlevel .shrink_(jlevel.size());
+ jnext .shrink_(jnext.size());
+
+ //var2FaninLits.shrink_(var2FaninLits.size());
+ var2NodeData .shrink_(var2NodeData .size());
+ var2Fanout0 .shrink_(var2Fanout0 .size());
+ var2FanoutN .shrink_(var2FanoutN .size());
+ //var2FanoutP.clear(false);
+ if( CRef_Undef != itpc ){
+ itpc = CRef_Undef; // clause allocator has been cleared, do not worry
+ // allocate space for clause interpretation
+ vec<Lit> tmp; tmp.growTo(3);
+ itpc = ca.alloc(tmp);
+ ca[itpc].shrink( ca[itpc].size() );
+ }
+ #endif
+}
+
+ABC_NAMESPACE_IMPL_END
diff --git a/src/sat/glucose2/Heap.h b/src/sat/glucose2/Heap.h
new file mode 100644
index 00000000..d68229f6
--- /dev/null
+++ b/src/sat/glucose2/Heap.h
@@ -0,0 +1,163 @@
+/******************************************************************************************[Heap.h]
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Heap_h
+#define Glucose_Heap_h
+
+#include "sat/glucose2/Vec.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// A heap implementation with support for decrease/increase key.
+
+
+template<class Comp>
+class Heap {
+ Comp lt; // The heap is a minimum-heap with respect to this comparator
+ vec<int> heap; // Heap of integers
+ vec<int> indices; // Each integers position (index) in the Heap
+
+ // Index "traversal" functions
+ static inline int left (int i) { return i*2+1; }
+ static inline int right (int i) { return (i+1)*2; }
+ static inline int parent(int i) { return (i-1) >> 1; }
+
+
+ void percolateUp(int i)
+ {
+ int x = heap[i];
+ int p = parent(i);
+
+ while (i != 0 && lt(x, heap[p])){
+ heap[i] = heap[p];
+ indices[heap[p]] = i;
+ i = p;
+ p = parent(p);
+ }
+ heap [i] = x;
+ indices[x] = i;
+ }
+
+
+ void percolateDown(int i)
+ {
+ int x = heap[i];
+ while (left(i) < heap.size()){
+ int child = right(i) < heap.size() && lt(heap[right(i)], heap[left(i)]) ? right(i) : left(i);
+ if (!lt(heap[child], x)) break;
+ heap[i] = heap[child];
+ indices[heap[i]] = i;
+ i = child;
+ }
+ heap [i] = x;
+ indices[x] = i;
+ }
+
+
+ public:
+ Heap(const Comp& c) : lt(c) { }
+
+ int size () const { return heap.size(); }
+ bool empty () const { return heap.size() == 0; }
+ bool inHeap (int n) const { return n < indices.size() && indices[n] >= 0; }
+ int operator[](int index) const { assert(index < heap.size()); return heap[index]; }
+
+
+ void decrease (int n) { assert(inHeap(n)); percolateUp (indices[n]); }
+ void increase (int n) { assert(inHeap(n)); percolateDown(indices[n]); }
+ void prelocate (int ext_cap){ indices.prelocate(ext_cap); }
+
+ // Safe variant of insert/decrease/increase:
+ void update(int n)
+ {
+ if (!inHeap(n))
+ insert(n);
+ else {
+ percolateUp(indices[n]);
+ percolateDown(indices[n]); }
+ }
+
+
+ void insert(int n)
+ {
+ indices.growTo(n+1, -1);
+ assert(!inHeap(n));
+
+ indices[n] = heap.size();
+ heap.push(n);
+ percolateUp(indices[n]);
+ }
+
+
+ int removeMin()
+ {
+ int x = heap[0];
+ heap[0] = heap.last();
+ indices[heap[0]] = 0;
+ indices[x] = -1;
+ heap.pop();
+ if (heap.size() > 1) percolateDown(0);
+ return x;
+ }
+
+
+ // Rebuild the heap from scratch, using the elements in 'ns':
+ void build(vec<int>& ns) {
+ int i;
+ for (i = 0; i < heap.size(); i++)
+ indices[heap[i]] = -1;
+ heap.clear();
+
+ for (i = 0; i < ns.size(); i++){
+ indices[ns[i]] = i;
+ heap.push(ns[i]); }
+
+ for (i = heap.size() / 2 - 1; i >= 0; i--)
+ percolateDown(i);
+ }
+
+ void clear(bool dealloc = false)
+ {
+ int i;
+ for (i = 0; i < heap.size(); i++)
+ indices[heap[i]] = -1;
+ heap.clear(dealloc);
+ }
+ void clear_(bool dealloc = false)
+ {
+ int i;
+ for (i = 0; i < heap.size(); i++)
+ indices[heap[i]] = -1;
+
+ if( ! dealloc ) heap.shrink_( heap.size() );
+ else heap.clear(true);
+ }
+};
+
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/Heap2.h b/src/sat/glucose2/Heap2.h
new file mode 100644
index 00000000..ef6d8302
--- /dev/null
+++ b/src/sat/glucose2/Heap2.h
@@ -0,0 +1,169 @@
+/******************************************************************************************[Heap.h]
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Heap2_h
+#define Glucose_Heap2_h
+
+#include "sat/glucose2/Vec.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// A heap implementation with support for decrease/increase key.
+
+
+template<class Comp, class Obj>
+class Heap2 {
+ Comp lt; // The heap is a minimum-heap with respect to this comparator
+ vec<Obj> heap; // Heap of integers
+ vec<int> indices; // Each integers position (index) in the Heap
+
+ // Index "traversal" functions
+ static inline int left (int i) { return i*2+1; }
+ static inline int right (int i) { return (i+1)*2; }
+ static inline int parent(int i) { return (i-1) >> 1; }
+
+ inline int data (int i) const { return heap[i].data();}
+
+ void percolateUp(int i)
+ {
+ Obj x = heap[i];
+ int p = parent(i);
+
+ while (i != 0 && lt(x, heap[p])){
+ heap[i] = heap[p];
+ indices[data(p)] = i;
+ i = p;
+ p = parent(p);
+ }
+ heap [i] = x;
+ indices[x.data()] = i;
+ }
+
+
+ void percolateDown(int i)
+ {
+ Obj x = heap[i];
+ while (left(i) < heap.size()){
+ int child = right(i) < heap.size() && lt(heap[right(i)], heap[left(i)]) ? right(i) : left(i);
+ if (!lt(heap[child], x)) break;
+ heap[i] = heap[child];
+ indices[data(i)] = i;
+ i = child;
+ }
+ heap [i] = x;
+ indices[x.data()] = i;
+ }
+
+
+ public:
+ Heap2(const Comp& c) : lt(c) { }
+
+ int size () const { return heap.size(); }
+ bool empty () const { return heap.size() == 0; }
+ bool inHeap (int n) const { return n < indices.size() && indices[n] >= 0; }
+ int operator[](int index) const { assert(index < heap.size()); return heap[index].data(); }
+
+
+ void decrease (int n) { assert(inHeap(n)); percolateUp (indices[n]); }
+ void increase (int n) { assert(inHeap(n)); percolateDown(indices[n]); }
+ void prelocate (int ext_cap){ indices.prelocate(ext_cap); }
+ int data_attr (int n) const { return heap[indices[n]].attr(); }
+ // Safe variant of insert/decrease/increase:
+ void update(const Obj& x)
+ {
+ int n = x.data();
+ if (!inHeap(n))
+ insert(x);
+ else {
+ heap[indices[x.data()]] = x;
+ percolateUp(indices[n]);
+ percolateDown(indices[n]); }
+ }
+
+
+ void insert(const Obj& x)
+ {
+ int n = x.data();
+ indices.growTo(n+1, -1);
+ assert(!inHeap(n));
+
+ indices[n] = heap.size();
+ heap.push(x);
+ percolateUp(indices[n]);
+ }
+
+ //Obj prev;
+ int removeMin(int& _attr)
+ {
+ Obj x = heap[0];
+ heap[0] = heap.last();
+ indices[heap[0].data()] = 0;
+ indices[x.data()]= -1;
+ heap.pop();
+ if (heap.size() > 1) percolateDown(0);
+ //prev = x;
+ _attr = x.attr();
+ return x.data();
+ }
+
+
+ // Rebuild the heap from scratch, using the elements in 'ns':
+// void build(vec<int>& ns) {
+// int i;
+// for (i = 0; i < heap.size(); i++)
+// indices[heap[i]] = -1;
+// heap.clear();
+//
+// for (i = 0; i < ns.size(); i++){
+// indices[ns[i]] = i;
+// heap.push(ns[i]); }
+//
+// for (i = heap.size() / 2 - 1; i >= 0; i--)
+// percolateDown(i);
+// }
+
+ void clear(bool dealloc = false)
+ {
+ int i;
+ for (i = 0; i < heap.size(); i++)
+ indices[heap[i].data()] = -1;
+ heap.clear(dealloc);
+ }
+ void clear_(bool dealloc = false)
+ {
+ int i;
+ for (i = 0; i < heap.size(); i++)
+ indices[heap[i].data()] = -1;
+
+ if( ! dealloc ) heap.shrink_( heap.size() );
+ else heap.clear(true);
+ }
+};
+
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/IntTypes.h b/src/sat/glucose2/IntTypes.h
new file mode 100644
index 00000000..3f75862b
--- /dev/null
+++ b/src/sat/glucose2/IntTypes.h
@@ -0,0 +1,49 @@
+/**************************************************************************************[IntTypes.h]
+Copyright (c) 2009-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_IntTypes_h
+#define Glucose_IntTypes_h
+
+#ifdef __sun
+ // Not sure if there are newer versions that support C99 headers. The
+ // needed features are implemented in the headers below though:
+
+# include <sys/int_types.h>
+# include <sys/int_fmtio.h>
+# include <sys/int_limits.h>
+
+#else
+
+#define __STDC_LIMIT_MACROS
+# include "pstdint.h"
+//# include <inttypes.h>
+
+#endif
+
+#include <limits.h>
+
+#ifndef PRIu64
+#define PRIu64 "lu"
+#define PRIi64 "ld"
+#endif
+//=================================================================================================
+
+#include <misc/util/abc_namespaces.h>
+
+#endif
diff --git a/src/sat/glucose2/Map.h b/src/sat/glucose2/Map.h
new file mode 100644
index 00000000..d9c31aae
--- /dev/null
+++ b/src/sat/glucose2/Map.h
@@ -0,0 +1,197 @@
+/*******************************************************************************************[Map.h]
+Copyright (c) 2006-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Map_h
+#define Glucose_Map_h
+
+#include "sat/glucose2/IntTypes.h"
+#include "sat/glucose2/Vec.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// Default hash/equals functions
+//
+
+template<class K> struct Hash { uint32_t operator()(const K& k) const { return hash(k); } };
+template<class K> struct Equal { bool operator()(const K& k1, const K& k2) const { return k1 == k2; } };
+
+template<class K> struct DeepHash { uint32_t operator()(const K* k) const { return hash(*k); } };
+template<class K> struct DeepEqual { bool operator()(const K* k1, const K* k2) const { return *k1 == *k2; } };
+
+static inline uint32_t hash(uint32_t x){ return x; }
+static inline uint32_t hash(uint64_t x){ return (uint32_t)x; }
+static inline uint32_t hash(int32_t x) { return (uint32_t)x; }
+static inline uint32_t hash(int64_t x) { return (uint32_t)x; }
+
+
+//=================================================================================================
+// Some primes
+//
+
+static const int nprimes = 25;
+static const int primes [nprimes] = { 31, 73, 151, 313, 643, 1291, 2593, 5233, 10501, 21013, 42073, 84181, 168451, 337219, 674701, 1349473, 2699299, 5398891, 10798093, 21596719, 43193641, 86387383, 172775299, 345550609, 691101253 };
+
+//=================================================================================================
+// Hash table implementation of Maps
+//
+
+template<class K, class D, class H = Hash<K>, class E = Equal<K> >
+class Map {
+ public:
+ struct Pair { K key; D data; };
+
+ private:
+ H hash;
+ E equals;
+
+ vec<Pair>* table;
+ int cap;
+ int size;
+
+ // Don't allow copying (error prone):
+ Map<K,D,H,E>& operator = (Map<K,D,H,E>& other) { assert(0); }
+ Map (Map<K,D,H,E>& other) { assert(0); }
+
+ bool checkCap(int new_size) const { return new_size > cap; }
+
+ int32_t index (const K& k) const { return hash(k) % cap; }
+ void _insert (const K& k, const D& d) {
+ vec<Pair>& ps = table[index(k)];
+ ps.push(); ps.last().key = k; ps.last().data = d; }
+
+ void rehash () {
+ const vec<Pair>* old = table;
+
+ int old_cap = cap;
+ int newsize = primes[0];
+ for (int i = 1; newsize <= cap && i < nprimes; i++)
+ newsize = primes[i];
+
+ table = new vec<Pair>[newsize];
+ cap = newsize;
+
+ for (int i = 0; i < old_cap; i++){
+ for (int j = 0; j < old[i].size(); j++){
+ _insert(old[i][j].key, old[i][j].data); }}
+
+ delete [] old;
+
+ // printf(" --- rehashing, old-cap=%d, new-cap=%d\n", cap, newsize);
+ }
+
+
+ public:
+
+ Map () : table(NULL), cap(0), size(0) {}
+ Map (const H& h, const E& e) : hash(h), equals(e), table(NULL), cap(0), size(0){}
+ ~Map () { delete [] table; }
+
+ // PRECONDITION: the key must already exist in the map.
+ const D& operator [] (const K& k) const
+ {
+ assert(size != 0);
+ const D* res = NULL;
+ const vec<Pair>& ps = table[index(k)];
+ for (int i = 0; i < ps.size(); i++)
+ if (equals(ps[i].key, k))
+ res = &ps[i].data;
+ assert(res != NULL);
+ return *res;
+ }
+
+ // PRECONDITION: the key must already exist in the map.
+ D& operator [] (const K& k)
+ {
+ assert(size != 0);
+ D* res = NULL;
+ vec<Pair>& ps = table[index(k)];
+ for (int i = 0; i < ps.size(); i++)
+ if (equals(ps[i].key, k))
+ res = &ps[i].data;
+ assert(res != NULL);
+ return *res;
+ }
+
+ // PRECONDITION: the key must *NOT* exist in the map.
+ void insert (const K& k, const D& d) { if (checkCap(size+1)) rehash(); _insert(k, d); size++; }
+ bool peek (const K& k, D& d) const {
+ if (size == 0) return false;
+ const vec<Pair>& ps = table[index(k)];
+ for (int i = 0; i < ps.size(); i++)
+ if (equals(ps[i].key, k)){
+ d = ps[i].data;
+ return true; }
+ return false;
+ }
+
+ bool has (const K& k) const {
+ if (size == 0) return false;
+ const vec<Pair>& ps = table[index(k)];
+ for (int i = 0; i < ps.size(); i++)
+ if (equals(ps[i].key, k))
+ return true;
+ return false;
+ }
+
+ // PRECONDITION: the key must exist in the map.
+ void remove(const K& k) {
+ assert(table != NULL);
+ vec<Pair>& ps = table[index(k)];
+ int j = 0;
+ for (; j < ps.size() && !equals(ps[j].key, k); j++);
+ assert(j < ps.size());
+ ps[j] = ps.last();
+ ps.pop();
+ size--;
+ }
+
+ void clear () {
+ cap = size = 0;
+ delete [] table;
+ table = NULL;
+ }
+
+ int elems() const { return size; }
+ int bucket_count() const { return cap; }
+
+ // NOTE: the hash and equality objects are not moved by this method:
+ void moveTo(Map& other){
+ delete [] other.table;
+
+ other.table = table;
+ other.cap = cap;
+ other.size = size;
+
+ table = NULL;
+ size = cap = 0;
+ }
+
+ // NOTE: given a bit more time, I could make a more C++-style iterator out of this:
+ const vec<Pair>& bucket(int i) const { return table[i]; }
+};
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/Options.h b/src/sat/glucose2/Options.h
new file mode 100644
index 00000000..f2d4d493
--- /dev/null
+++ b/src/sat/glucose2/Options.h
@@ -0,0 +1,392 @@
+/***************************************************************************************[Options.h]
+Copyright (c) 2008-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Options_h
+#define Glucose_Options_h
+
+#define __STDC_FORMAT_MACROS
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+#include "sat/glucose2/IntTypes.h"
+#include "sat/glucose2/Vec.h"
+#include "sat/glucose2/ParseUtils.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//==================================================================================================
+// Top-level option parse/help functions:
+
+
+extern void parseOptions (int& argc, char** argv, bool strict = false);
+extern void printUsageAndExit(int argc, char** argv, bool verbose = false);
+extern void setUsageHelp (const char* str);
+extern void setHelpPrefixStr (const char* str);
+
+
+//==================================================================================================
+// Options is an abstract class that gives the interface for all types options:
+
+
+class Option
+{
+ public:
+ const char* name;
+ const char* description;
+ const char* category;
+ const char* type_name;
+
+ static vec<Option*>& getOptionList () { static vec<Option*> options; return options; }
+ static const char*& getUsageString() { static const char* usage_str; return usage_str; }
+ static const char*& getHelpPrefixString() { static const char* help_prefix_str = ""; return help_prefix_str; }
+
+ struct OptionLt {
+ bool operator()(const Option* x, const Option* y) {
+ int test1 = strcmp(x->category, y->category);
+ return test1 < 0 || (test1 == 0 && strcmp(x->type_name, y->type_name) < 0);
+ }
+ };
+
+ Option(const char* name_,
+ const char* desc_,
+ const char* cate_,
+ const char* type_) :
+ name (name_)
+ , description(desc_)
+ , category (cate_)
+ , type_name (type_)
+ {
+ getOptionList().push(this);
+ }
+
+ public:
+ virtual ~Option() {}
+
+ virtual bool parse (const char* str) = 0;
+ virtual void help (bool verbose = false) = 0;
+
+ friend void parseOptions (int& argc, char** argv, bool strict);
+ friend void printUsageAndExit (int argc, char** argv, bool verbose);
+ friend void setUsageHelp (const char* str);
+ friend void setHelpPrefixStr (const char* str);
+};
+
+
+//==================================================================================================
+// Range classes with specialization for floating types:
+
+
+struct IntRange {
+ int begin;
+ int end;
+ IntRange(int b, int e) : begin(b), end(e) {}
+};
+
+struct Int64Range {
+ int64_t begin;
+ int64_t end;
+ Int64Range(int64_t b, int64_t e) : begin(b), end(e) {}
+};
+
+struct DoubleRange {
+ double begin;
+ double end;
+ bool begin_inclusive;
+ bool end_inclusive;
+ DoubleRange(double b, bool binc, double e, bool einc) : begin(b), end(e), begin_inclusive(binc), end_inclusive(einc) {}
+};
+
+
+//==================================================================================================
+// Double options:
+
+
+class DoubleOption : public Option
+{
+ protected:
+ DoubleRange range;
+ double value;
+
+ public:
+ DoubleOption(const char* c, const char* n, const char* d, double def = double(), DoubleRange r = DoubleRange(-HUGE_VAL, false, HUGE_VAL, false))
+ : Option(n, d, c, "<double>"), range(r), value(def) {
+ // FIXME: set LC_NUMERIC to "C" to make sure that strtof/strtod parses decimal point correctly.
+ }
+
+ operator double (void) const { return value; }
+ operator double& (void) { return value; }
+ DoubleOption& operator=(double x) { value = x; return *this; }
+
+ virtual bool parse(const char* str){
+ const char* span = str;
+
+ if (!match(span, "-") || !match(span, name) || !match(span, "="))
+ return false;
+
+ char* end;
+ double tmp = strtod(span, &end);
+
+ if (end == NULL)
+ return false;
+ else if (tmp >= range.end && (!range.end_inclusive || tmp != range.end)){
+ fprintf(stderr, "ERROR! value <%s> is too large for option \"%s\".\n", span, name);
+ exit(1);
+ }else if (tmp <= range.begin && (!range.begin_inclusive || tmp != range.begin)){
+ fprintf(stderr, "ERROR! value <%s> is too small for option \"%s\".\n", span, name);
+ exit(1); }
+
+ value = tmp;
+ // fprintf(stderr, "READ VALUE: %g\n", value);
+
+ return true;
+ }
+
+ virtual void help (bool verbose = false){
+ fprintf(stderr, " -%-12s = %-8s %c%4.2g .. %4.2g%c (default: %g)\n",
+ name, type_name,
+ range.begin_inclusive ? '[' : '(',
+ range.begin,
+ range.end,
+ range.end_inclusive ? ']' : ')',
+ value);
+ if (verbose){
+ fprintf(stderr, "\n %s\n", description);
+ fprintf(stderr, "\n");
+ }
+ }
+};
+
+
+//==================================================================================================
+// Int options:
+
+
+class IntOption : public Option
+{
+ protected:
+ IntRange range;
+ int32_t value;
+
+ public:
+ IntOption(const char* c, const char* n, const char* d, int32_t def = int32_t(), IntRange r = IntRange(INT32_MIN, INT32_MAX))
+ : Option(n, d, c, "<int32>"), range(r), value(def) {}
+
+ operator int32_t (void) const { return value; }
+ operator int32_t& (void) { return value; }
+ IntOption& operator= (int32_t x) { value = x; return *this; }
+
+ virtual bool parse(const char* str){
+ const char* span = str;
+
+ if (!match(span, "-") || !match(span, name) || !match(span, "="))
+ return false;
+
+ char* end;
+ int32_t tmp = strtol(span, &end, 10);
+
+ if (end == NULL)
+ return false;
+ else if (tmp > range.end){
+ fprintf(stderr, "ERROR! value <%s> is too large for option \"%s\".\n", span, name);
+ exit(1);
+ }else if (tmp < range.begin){
+ fprintf(stderr, "ERROR! value <%s> is too small for option \"%s\".\n", span, name);
+ exit(1); }
+
+ value = tmp;
+
+ return true;
+ }
+
+ virtual void help (bool verbose = false){
+ fprintf(stderr, " -%-12s = %-8s [", name, type_name);
+ if (range.begin == INT32_MIN)
+ fprintf(stderr, "imin");
+ else
+ fprintf(stderr, "%4d", range.begin);
+
+ fprintf(stderr, " .. ");
+ if (range.end == INT32_MAX)
+ fprintf(stderr, "imax");
+ else
+ fprintf(stderr, "%4d", range.end);
+
+ fprintf(stderr, "] (default: %d)\n", value);
+ if (verbose){
+ fprintf(stderr, "\n %s\n", description);
+ fprintf(stderr, "\n");
+ }
+ }
+};
+
+
+// Leave this out for visual C++ until Microsoft implements C99 and gets support for strtoll.
+#ifndef _MSC_VER
+
+class Int64Option : public Option
+{
+ protected:
+ Int64Range range;
+ int64_t value;
+
+ public:
+ Int64Option(const char* c, const char* n, const char* d, int64_t def = int64_t(), Int64Range r = Int64Range(INT64_MIN, INT64_MAX))
+ : Option(n, d, c, "<int64>"), range(r), value(def) {}
+
+ operator int64_t (void) const { return value; }
+ operator int64_t& (void) { return value; }
+ Int64Option& operator= (int64_t x) { value = x; return *this; }
+
+ virtual bool parse(const char* str){
+ const char* span = str;
+
+ if (!match(span, "-") || !match(span, name) || !match(span, "="))
+ return false;
+
+ char* end;
+ int64_t tmp = strtoll(span, &end, 10);
+
+ if (end == NULL)
+ return false;
+ else if (tmp > range.end){
+ fprintf(stderr, "ERROR! value <%s> is too large for option \"%s\".\n", span, name);
+ exit(1);
+ }else if (tmp < range.begin){
+ fprintf(stderr, "ERROR! value <%s> is too small for option \"%s\".\n", span, name);
+ exit(1); }
+
+ value = tmp;
+
+ return true;
+ }
+
+ virtual void help (bool verbose = false){
+ fprintf(stderr, " -%-12s = %-8s [", name, type_name);
+ if (range.begin == INT64_MIN)
+ fprintf(stderr, "imin");
+ else
+ fprintf(stderr, "%4d", (int)range.begin);
+
+ fprintf(stderr, " .. ");
+ if (range.end == INT64_MAX)
+ fprintf(stderr, "imax");
+ else
+ fprintf(stderr, "%4d", (int)range.end);
+
+ fprintf(stderr, "] (default: %d)\n", (int)value);
+ if (verbose){
+ fprintf(stderr, "\n %s\n", description);
+ fprintf(stderr, "\n");
+ }
+ }
+};
+#endif
+
+//==================================================================================================
+// String option:
+
+
+class StringOption : public Option
+{
+ const char* value;
+ public:
+ StringOption(const char* c, const char* n, const char* d, const char* def = NULL)
+ : Option(n, d, c, "<string>"), value(def) {}
+
+ operator const char* (void) const { return value; }
+ operator const char*& (void) { return value; }
+ StringOption& operator= (const char* x) { value = x; return *this; }
+
+ virtual bool parse(const char* str){
+ const char* span = str;
+
+ if (!match(span, "-") || !match(span, name) || !match(span, "="))
+ return false;
+
+ value = span;
+ return true;
+ }
+
+ virtual void help (bool verbose = false){
+ fprintf(stderr, " -%-10s = %8s\n", name, type_name);
+ if (verbose){
+ fprintf(stderr, "\n %s\n", description);
+ fprintf(stderr, "\n");
+ }
+ }
+};
+
+
+//==================================================================================================
+// Bool option:
+
+
+class BoolOption : public Option
+{
+ bool value;
+
+ public:
+ BoolOption(const char* c, const char* n, const char* d, bool v)
+ : Option(n, d, c, "<bool>"), value(v) {}
+
+ operator bool (void) const { return value; }
+ operator bool& (void) { return value; }
+ BoolOption& operator=(bool b) { value = b; return *this; }
+
+ virtual bool parse(const char* str){
+ const char* span = str;
+
+ if (match(span, "-")){
+ bool b = !match(span, "no-");
+
+ if (strcmp(span, name) == 0){
+ value = b;
+ return true; }
+ }
+
+ return false;
+ }
+
+ virtual void help (bool verbose = false){
+
+ fprintf(stderr, " -%s, -no-%s", name, name);
+
+ for (uint32_t i = 0; i < 32 - strlen(name)*2; i++)
+ fprintf(stderr, " ");
+
+ fprintf(stderr, " ");
+ fprintf(stderr, "(default: %s)\n", value ? "on" : "off");
+ if (verbose){
+ fprintf(stderr, "\n %s\n", description);
+ fprintf(stderr, "\n");
+ }
+ }
+};
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/Options2.cpp b/src/sat/glucose2/Options2.cpp
new file mode 100644
index 00000000..b419e054
--- /dev/null
+++ b/src/sat/glucose2/Options2.cpp
@@ -0,0 +1,95 @@
+/**************************************************************************************[Options.cc]
+Copyright (c) 2008-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#include "sat/glucose2/Sort.h"
+#include "sat/glucose2/Options.h"
+#include "sat/glucose2/ParseUtils.h"
+
+ABC_NAMESPACE_IMPL_START
+
+using namespace Gluco2;
+
+void Gluco2::parseOptions(int& argc, char** argv, bool strict)
+{
+ int i, j;
+ for (i = j = 1; i < argc; i++){
+ const char* str = argv[i];
+ if (match(str, "--") && match(str, Option::getHelpPrefixString()) && match(str, "help")){
+ if (*str == '\0')
+ printUsageAndExit(argc, argv);
+ else if (match(str, "-verb"))
+ printUsageAndExit(argc, argv, true);
+ } else {
+ bool parsed_ok = false;
+
+ for (int k = 0; !parsed_ok && k < Option::getOptionList().size(); k++){
+ parsed_ok = Option::getOptionList()[k]->parse(argv[i]);
+
+ // fprintf(stderr, "checking %d: %s against flag <%s> (%s)\n", i, argv[i], Option::getOptionList()[k]->name, parsed_ok ? "ok" : "skip");
+ }
+
+ if (!parsed_ok) {
+ if (strict && match(argv[i], "-"))
+ fprintf(stderr, "ERROR! Unknown flag \"%s\". Use '--%shelp' for help.\n", argv[i], Option::getHelpPrefixString()), exit(1);
+ else
+ argv[j++] = argv[i];
+ }
+ }
+ }
+
+ argc -= (i - j);
+}
+
+
+void Gluco2::setUsageHelp (const char* str){ Option::getUsageString() = str; }
+void Gluco2::setHelpPrefixStr (const char* str){ Option::getHelpPrefixString() = str; }
+void Gluco2::printUsageAndExit (int argc, char** argv, bool verbose)
+{
+ const char* usage = Option::getUsageString();
+ if (usage != NULL)
+ fprintf(stderr, usage, argv[0]);
+
+ sort(Option::getOptionList(), Option::OptionLt());
+
+ const char* prev_cat = NULL;
+ const char* prev_type = NULL;
+
+ for (int i = 0; i < Option::getOptionList().size(); i++){
+ const char* cat = Option::getOptionList()[i]->category;
+ const char* type = Option::getOptionList()[i]->type_name;
+
+ if (cat != prev_cat)
+ fprintf(stderr, "\n%s OPTIONS:\n\n", cat);
+ else if (type != prev_type)
+ fprintf(stderr, "\n");
+
+ Option::getOptionList()[i]->help(verbose);
+
+ prev_cat = Option::getOptionList()[i]->category;
+ prev_type = Option::getOptionList()[i]->type_name;
+ }
+
+ fprintf(stderr, "\nHELP OPTIONS:\n\n");
+ fprintf(stderr, " --%shelp Print help message.\n", Option::getHelpPrefixString());
+ fprintf(stderr, " --%shelp-verb Print verbose help message.\n", Option::getHelpPrefixString());
+ fprintf(stderr, "\n");
+ exit(0);
+}
+
+ABC_NAMESPACE_IMPL_END
diff --git a/src/sat/glucose2/ParseUtils.h b/src/sat/glucose2/ParseUtils.h
new file mode 100644
index 00000000..54a139b1
--- /dev/null
+++ b/src/sat/glucose2/ParseUtils.h
@@ -0,0 +1,155 @@
+/************************************************************************************[ParseUtils.h]
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose2_ParseUtils_h
+#define Glucose2_ParseUtils_h
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "misc/zlib/zlib.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//-------------------------------------------------------------------------------------------------
+// A simple buffered character stream class:
+
+static const int buffer_size = 1048576;
+
+
+class StreamBuffer {
+ gzFile in;
+ unsigned char buf[buffer_size];
+ int pos;
+ int size;
+
+ void assureLookahead() {
+ if (pos >= size) {
+ pos = 0;
+ size = gzread(in, buf, sizeof(buf)); } }
+
+public:
+ explicit StreamBuffer(gzFile i) : in(i), pos(0), size(0) { assureLookahead(); }
+
+ int operator * () const { return (pos >= size) ? EOF : buf[pos]; }
+ void operator ++ () { pos++; assureLookahead(); }
+ int position () const { return pos; }
+};
+
+
+//-------------------------------------------------------------------------------------------------
+// End-of-file detection functions for StreamBuffer and char*:
+
+
+static inline bool isEof(StreamBuffer& in) { return *in == EOF; }
+static inline bool isEof(const char* in) { return *in == '\0'; }
+
+//-------------------------------------------------------------------------------------------------
+// Generic parse functions parametrized over the input-stream type.
+
+
+template<class B>
+static void skipWhitespace(B& in) {
+ while ((*in >= 9 && *in <= 13) || *in == 32)
+ ++in; }
+
+
+template<class B>
+static void skipLine(B& in) {
+ for (;;){
+ if (isEof(in)) return;
+ if (*in == '\n') { ++in; return; }
+ ++in; } }
+
+template<class B>
+static double parseDouble(B& in) { // only in the form X.XXXXXe-XX
+ bool neg= false;
+ double accu = 0.0;
+ double currentExponent = 1;
+ int exponent;
+
+ skipWhitespace(in);
+ if(*in == EOF) return 0;
+ if (*in == '-') neg = true, ++in;
+ else if (*in == '+') ++in;
+ if (*in < '1' || *in > '9') printf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3);
+ accu = (double)(*in - '0');
+ ++in;
+ if (*in != '.') printf("PARSE ERROR! Unexpected char: %c\n", *in),exit(3);
+ ++in; // skip dot
+ currentExponent = 0.1;
+ while (*in >= '0' && *in <= '9')
+ accu = accu + currentExponent * ((double)(*in - '0')),
+ currentExponent /= 10,
+ ++in;
+ if (*in != 'e') printf("PARSE ERROR! Unexpected char: %c\n", *in),exit(3);
+ ++in; // skip dot
+ exponent = parseInt(in); // read exponent
+ accu *= pow(10,exponent);
+ return neg ? -accu:accu;
+}
+
+
+template<class B>
+static int parseInt(B& in) {
+ int val = 0;
+ bool neg = false;
+ skipWhitespace(in);
+ if (*in == '-') neg = true, ++in;
+ else if (*in == '+') ++in;
+ if (*in < '0' || *in > '9') fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", *in), exit(3);
+ while (*in >= '0' && *in <= '9')
+ val = val*10 + (*in - '0'),
+ ++in;
+ return neg ? -val : val; }
+
+
+// String matching: in case of a match the input iterator will be advanced the corresponding
+// number of characters.
+template<class B>
+static bool match(B& in, const char* str) {
+ int i;
+ for (i = 0; str[i] != '\0'; i++)
+ if (in[i] != str[i])
+ return false;
+
+ in += i;
+
+ return true;
+}
+
+// String matching: consumes characters eagerly, but does not require random access iterator.
+template<class B>
+static bool eagerMatch(B& in, const char* str) {
+ for (; *str != '\0'; ++str, ++in)
+ if (*str != *in)
+ return false;
+ return true; }
+
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/Queue.h b/src/sat/glucose2/Queue.h
new file mode 100644
index 00000000..2328fdf9
--- /dev/null
+++ b/src/sat/glucose2/Queue.h
@@ -0,0 +1,73 @@
+/*****************************************************************************************[Queue.h]
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Queue_h
+#define Glucose_Queue_h
+
+#include "sat/glucose2/Vec.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+
+template<class T>
+class Queue {
+ vec<T> buf;
+ int first;
+ int end;
+
+public:
+ typedef T Key;
+
+ Queue() : buf(1), first(0), end(0) {}
+
+ void clear (bool dealloc = false) { buf.clear(dealloc); buf.growTo(1); first = end = 0; }
+ int size () const { return (end >= first) ? end - first : end - first + buf.size(); }
+
+ const T& operator [] (int index) const { assert(index >= 0); assert(index < size()); return buf[(first + index) % buf.size()]; }
+ T& operator [] (int index) { assert(index >= 0); assert(index < size()); return buf[(first + index) % buf.size()]; }
+
+ T peek () const { assert(first != end); return buf[first]; }
+ void pop () { assert(first != end); first++; if (first == buf.size()) first = 0; }
+ void insert(T elem) { // INVARIANT: buf[end] is always unused
+ buf[end++] = elem;
+ if (end == buf.size()) end = 0;
+ if (first == end){ // Resize:
+ vec<T> tmp((buf.size()*3 + 1) >> 1);
+ //**/printf("queue alloc: %d elems (%.1f MB)\n", tmp.size(), tmp.size() * sizeof(T) / 1000000.0);
+ int j, i = 0;
+ for (j = first; j < buf.size(); j++) tmp[i++] = buf[j];
+ for (j = 0 ; j < end ; j++) tmp[i++] = buf[j];
+ first = 0;
+ end = buf.size();
+ tmp.moveTo(buf);
+ }
+ }
+};
+
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/SimpSolver.h b/src/sat/glucose2/SimpSolver.h
new file mode 100644
index 00000000..36d625e9
--- /dev/null
+++ b/src/sat/glucose2/SimpSolver.h
@@ -0,0 +1,230 @@
+/************************************************************************************[SimpSolver.h]
+Copyright (c) 2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_SimpSolver_h
+#define Glucose_SimpSolver_h
+
+#include "sat/glucose2/Queue.h"
+#include "sat/glucose2/Solver.h"
+
+#include "sat/glucose2/CGlucose.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+
+
+class SimpSolver : public Solver {
+ public:
+ // Constructor/Destructor:
+ //
+ SimpSolver();
+ ~SimpSolver();
+
+ // Problem specification:
+ //
+ Var newVar (bool polarity = true, bool dvar = true);
+ void addVar (Var v);
+ bool addClause (const vec<Lit>& ps);
+ bool addEmptyClause(); // Add the empty clause to the solver.
+ bool addClause (Lit p); // Add a unit clause to the solver.
+ bool addClause (Lit p, Lit q); // Add a binary clause to the solver.
+ bool addClause (Lit p, Lit q, Lit r); // Add a ternary clause to the solver.
+ bool addClause_( vec<Lit>& ps);
+ bool substitute(Var v, Lit x); // Replace all occurences of v with x (may cause a contradiction).
+
+ // Variable mode:
+ //
+ void setFrozen (Var v, bool b); // If a variable is frozen it will not be eliminated.
+ bool isEliminated(Var v) const;
+
+ // Solving:
+ //
+ bool solve (const vec<Lit>& assumps, bool do_simp = true, bool turn_off_simp = false);
+ lbool solveLimited(const vec<Lit>& assumps, bool do_simp = true, bool turn_off_simp = false);
+ int solveLimited(int * lit0, int nlits, bool do_simp = false, bool turn_off_simp = false);
+ bool solve ( bool do_simp = true, bool turn_off_simp = false);
+ bool solve (Lit p , bool do_simp = true, bool turn_off_simp = false);
+ bool solve (Lit p, Lit q, bool do_simp = true, bool turn_off_simp = false);
+ bool solve (Lit p, Lit q, Lit r, bool do_simp = true, bool turn_off_simp = false);
+ bool eliminate (bool turn_off_elim = false); // Perform variable elimination based simplification.
+
+ void prelocate(int base_var_num){
+ Solver::prelocate(base_var_num);
+ frozen .prelocate( base_var_num );
+ eliminated.prelocate( base_var_num );
+
+ if (use_simplification){
+ n_occ .prelocate( base_var_num << 1 );
+ occurs .prelocate( base_var_num );
+ touched .prelocate( base_var_num );
+ elim_heap .prelocate( base_var_num );
+ }
+ }
+ // Memory managment:
+ //
+ virtual void reset();
+ virtual void garbageCollect();
+
+
+ // Generate a (possibly simplified) DIMACS file:
+ //
+#if 0
+ void toDimacs (const char* file, const vec<Lit>& assumps);
+ void toDimacs (const char* file);
+ void toDimacs (const char* file, Lit p);
+ void toDimacs (const char* file, Lit p, Lit q);
+ void toDimacs (const char* file, Lit p, Lit q, Lit r);
+#endif
+
+ // Mode of operation:
+ //
+ int parsing;
+ int grow; // Allow a variable elimination step to grow by a number of clauses (default to zero).
+ int clause_lim; // Variables are not eliminated if it produces a resolvent with a length above this limit.
+ // -1 means no limit.
+ int subsumption_lim; // Do not check if subsumption against a clause larger than this. -1 means no limit.
+ double simp_garbage_frac; // A different limit for when to issue a GC during simplification (Also see 'garbage_frac').
+
+ bool use_asymm; // Shrink clauses by asymmetric branching.
+ bool use_rcheck; // Check if a clause is already implied. Prett costly, and subsumes subsumptions :)
+ bool use_elim; // Perform variable elimination.
+
+ // Statistics:
+ //
+ int merges;
+ int asymm_lits;
+ int eliminated_vars;
+ int eliminated_clauses;
+
+ protected:
+
+ // Helper structures:
+ //
+ struct ElimLt {
+ const vec<int>& n_occ;
+ explicit ElimLt(const vec<int>& no) : n_occ(no) {}
+
+ // TODO: are 64-bit operations here noticably bad on 32-bit platforms? Could use a saturating
+ // 32-bit implementation instead then, but this will have to do for now.
+ uint64_t cost (Var x) const { return (uint64_t)n_occ[toInt(mkLit(x))] * (uint64_t)n_occ[toInt(~mkLit(x))]; }
+ bool operator()(Var x, Var y) const { return cost(x) < cost(y); }
+
+ // TODO: investigate this order alternative more.
+ // bool operator()(Var x, Var y) const {
+ // int c_x = cost(x);
+ // int c_y = cost(y);
+ // return c_x < c_y || c_x == c_y && x < y; }
+ };
+
+ struct ClauseDeleted {
+ const ClauseAllocator& ca;
+ explicit ClauseDeleted(const ClauseAllocator& _ca) : ca(_ca) {}
+ bool operator()(const CRef& cr) const { return ca[cr].mark() == 1; } };
+
+ // Solver state:
+ //
+ int elimorder;
+ bool use_simplification;
+ vec<uint32_t> elimclauses;
+ vec<char> touched;
+ OccLists<Var, vec<CRef>, ClauseDeleted>
+ occurs;
+ vec<int> n_occ;
+ Heap<ElimLt> elim_heap;
+ Queue<CRef> subsumption_queue;
+ vec<char> frozen;
+ vec<char> eliminated;
+ int bwdsub_assigns;
+ int n_touched;
+
+ // Temporaries:
+ //
+ CRef bwdsub_tmpunit;
+
+ // Main internal methods:
+ //
+ lbool solve_ (bool do_simp = true, bool turn_off_simp = false);
+ bool asymm (Var v, CRef cr);
+ bool asymmVar (Var v);
+ void updateElimHeap (Var v);
+ void gatherTouchedClauses ();
+ bool merge (const Clause& _ps, const Clause& _qs, Var v, vec<Lit>& out_clause);
+ bool merge (const Clause& _ps, const Clause& _qs, Var v, int& size);
+ bool backwardSubsumptionCheck (bool verbose = false);
+ bool eliminateVar (Var v);
+ void extendModel ();
+
+ void removeClause (CRef cr);
+ bool strengthenClause (CRef cr, Lit l);
+ void cleanUpClauses ();
+ bool implied (const vec<Lit>& c);
+ void relocAll (ClauseAllocator& to);
+};
+
+
+//=================================================================================================
+// Implementation of inline methods:
+
+
+//inline bool SimpSolver::isEliminated (Var v) const { return eliminated[v]; }
+inline bool SimpSolver::isEliminated (Var v) const { return eliminated.size() > 0 ? eliminated[v] != 0 : 0; }
+inline void SimpSolver::updateElimHeap(Var v) {
+ assert(use_simplification);
+ // if (!frozen[v] && !isEliminated(v) && value(v) == l_Undef)
+ if (elim_heap.inHeap(v) || (!frozen[v] && !isEliminated(v) && value(v) == l_Undef))
+ elim_heap.update(v); }
+
+
+inline bool SimpSolver::addClause (const vec<Lit>& ps) { ps.copyTo(add_tmp); return addClause_(add_tmp); }
+inline bool SimpSolver::addEmptyClause() { add_tmp.clear(); return addClause_(add_tmp); }
+inline bool SimpSolver::addClause (Lit p) { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp); }
+inline bool SimpSolver::addClause (Lit p, Lit q) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp); }
+inline bool SimpSolver::addClause (Lit p, Lit q, Lit r) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp); }
+inline void SimpSolver::setFrozen (Var v, bool b) { frozen[v] = (char)b; if (use_simplification && !b) { updateElimHeap(v); } }
+
+inline bool SimpSolver::solve ( bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); return solve_(do_simp, turn_off_simp) == l_True; }
+inline bool SimpSolver::solve (Lit p , bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); return solve_(do_simp, turn_off_simp) == l_True; }
+inline bool SimpSolver::solve (Lit p, Lit q, bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); return solve_(do_simp, turn_off_simp) == l_True; }
+inline bool SimpSolver::solve (Lit p, Lit q, Lit r, bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); assumptions.push(r); return solve_(do_simp, turn_off_simp) == l_True; }
+inline bool SimpSolver::solve (const vec<Lit>& assumps, bool do_simp, bool turn_off_simp){
+ budgetOff(); assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp) == l_True; }
+
+inline lbool SimpSolver::solveLimited (const vec<Lit>& assumps, bool do_simp, bool turn_off_simp){
+ assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp); }
+
+inline int SimpSolver::solveLimited(int * lit0, int nlits, bool do_simp, bool turn_off_simp){
+ assumptions.clear();
+ for(int i = 0; i < nlits; i ++)
+ assumptions.push(toLit(lit0[i]));
+ lbool res = solve_(do_simp, turn_off_simp);
+ return res == l_True ? 1 : (res == l_False ? -1 : 0);
+}
+
+inline void SimpSolver::addVar(Var v) { while (v >= nVars()) newVar(); }
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/SimpSolver2.cpp b/src/sat/glucose2/SimpSolver2.cpp
new file mode 100644
index 00000000..37093277
--- /dev/null
+++ b/src/sat/glucose2/SimpSolver2.cpp
@@ -0,0 +1,781 @@
+/***********************************************************************************[SimpSolver.cc]
+Copyright (c) 2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#include "sat/glucose2/Sort.h"
+#include "sat/glucose2/SimpSolver.h"
+#include "sat/glucose2/System.h"
+
+ABC_NAMESPACE_IMPL_START
+
+using namespace Gluco2;
+
+//=================================================================================================
+// Options:
+
+
+static const char* _cat = "SIMP";
+
+static BoolOption opt_use_asymm (_cat, "asymm", "Shrink clauses by asymmetric branching.", false);
+static BoolOption opt_use_rcheck (_cat, "rcheck", "Check if a clause is already implied. (costly)", false);
+static BoolOption opt_use_elim (_cat, "elim", "Perform variable elimination.", true);
+static IntOption opt_grow (_cat, "grow", "Allow a variable elimination step to grow by a number of clauses.", 0);
+static IntOption opt_clause_lim (_cat, "cl-lim", "Variables are not eliminated if it produces a resolvent with a length above this limit. -1 means no limit", 20, IntRange(-1, INT32_MAX));
+static IntOption opt_subsumption_lim (_cat, "sub-lim", "Do not check if subsumption against a clause larger than this. -1 means no limit.", 1000, IntRange(-1, INT32_MAX));
+static DoubleOption opt_simp_garbage_frac(_cat, "simp-gc-frac", "The fraction of wasted memory allowed before a garbage collection is triggered during simplification.", 0.5, DoubleRange(0, false, HUGE_VAL, false));
+
+
+//=================================================================================================
+// Constructor/Destructor:
+
+
+SimpSolver::SimpSolver() :
+ grow (opt_grow)
+ , clause_lim (opt_clause_lim)
+ , subsumption_lim (opt_subsumption_lim)
+ , simp_garbage_frac (opt_simp_garbage_frac)
+ , use_asymm (opt_use_asymm)
+ , use_rcheck (opt_use_rcheck)
+ , use_elim (opt_use_elim)
+ , merges (0)
+ , asymm_lits (0)
+ , eliminated_vars (0)
+ , eliminated_clauses (0)
+ , elimorder (1)
+ , use_simplification (true)
+ , occurs (ClauseDeleted(ca))
+ , elim_heap (ElimLt(n_occ))
+ , bwdsub_assigns (0)
+ , n_touched (0)
+{
+ vec<Lit> dummy(1,lit_Undef);
+ ca.extra_clause_field = true; // NOTE: must happen before allocating the dummy clause below.
+ bwdsub_tmpunit = ca.alloc(dummy);
+ remove_satisfied = false;
+ parsing = 0;
+}
+
+
+SimpSolver::~SimpSolver()
+{
+}
+
+
+Var SimpSolver::newVar(bool sign, bool dvar) {
+ Var v = Solver::newVar(sign, dvar);
+
+ frozen .push((char)false);
+ eliminated.push((char)false);
+
+ if (use_simplification){
+ n_occ .push(0);
+ n_occ .push(0);
+ occurs .init(v);
+ touched .push(0);
+ elim_heap .insert(v);
+ }
+ return v; }
+
+
+
+lbool SimpSolver::solve_(bool do_simp, bool turn_off_simp)
+{
+ vec<Var> extra_frozen;
+ lbool result = l_True;
+
+ do_simp &= use_simplification;
+
+ if (do_simp){
+ // Assumptions must be temporarily frozen to run variable elimination:
+ for (int i = 0; i < assumptions.size(); i++){
+ Var v = var(assumptions[i]);
+
+ // If an assumption has been eliminated, remember it.
+ assert(!isEliminated(v));
+
+ if (!frozen[v]){
+ // Freeze and store.
+ setFrozen(v, true);
+ extra_frozen.push(v);
+ } }
+
+ result = lbool(eliminate(turn_off_simp));
+ }
+
+ if (result == l_True)
+ result = Solver::solve_();
+ else if (verbosity >= 1)
+ printf("===============================================================================\n");
+
+ if (result == l_True)
+ extendModel();
+
+ if (do_simp)
+ // Unfreeze the assumptions that were frozen:
+ for (int i = 0; i < extra_frozen.size(); i++)
+ setFrozen(extra_frozen[i], false);
+
+ return result;
+}
+
+
+
+bool SimpSolver::addClause_(vec<Lit>& ps)
+{
+#ifndef NDEBUG
+ for (int i = 0; i < ps.size(); i++)
+ assert(!isEliminated(var(ps[i])));
+#endif
+ int nclauses = clauses.size();
+
+ if (use_rcheck && implied(ps))
+ return true;
+
+ if (!Solver::addClause_(ps))
+ return false;
+
+ if(!parsing && certifiedUNSAT) {
+ for (int i = 0; i < ps.size(); i++)
+ fprintf(certifiedOutput, "%i " , (var(ps[i]) + 1) * (-2 * sign(ps[i]) + 1) );
+ fprintf(certifiedOutput, "0\n");
+ }
+
+ if (use_simplification && clauses.size() == nclauses + 1){
+ CRef cr = clauses.last();
+ const Clause& c = ca[cr];
+
+ // NOTE: the clause is added to the queue immediately and then
+ // again during 'gatherTouchedClauses()'. If nothing happens
+ // in between, it will only be checked once. Otherwise, it may
+ // be checked twice unnecessarily. This is an unfortunate
+ // consequence of how backward subsumption is used to mimic
+ // forward subsumption.
+ subsumption_queue.insert(cr);
+ for (int i = 0; i < c.size(); i++){
+ occurs[var(c[i])].push(cr);
+ n_occ[toInt(c[i])]++;
+ touched[var(c[i])] = 1;
+ n_touched++;
+ if (elim_heap.inHeap(var(c[i])))
+ elim_heap.increase(var(c[i]));
+ }
+ }
+
+ return true;
+}
+
+
+void SimpSolver::removeClause(CRef cr)
+{
+ const Clause& c = ca[cr];
+
+ if (use_simplification)
+ for (int i = 0; i < c.size(); i++){
+ n_occ[toInt(c[i])]--;
+ updateElimHeap(var(c[i]));
+ occurs.smudge(var(c[i]));
+ }
+
+ Solver::removeClause(cr);
+}
+
+
+bool SimpSolver::strengthenClause(CRef cr, Lit l)
+{
+ Clause& c = ca[cr];
+ assert(decisionLevel() == 0);
+ assert(use_simplification);
+
+ // FIX: this is too inefficient but would be nice to have (properly implemented)
+ // if (!find(subsumption_queue, &c))
+ subsumption_queue.insert(cr);
+
+ if (certifiedUNSAT) {
+ for (int i = 0; i < c.size(); i++)
+ if (c[i] != l) fprintf(certifiedOutput, "%i " , (var(c[i]) + 1) * (-2 * sign(c[i]) + 1) );
+ fprintf(certifiedOutput, "0\n");
+ }
+
+ if (c.size() == 2){
+ removeClause(cr);
+ c.strengthen(l);
+ }else{
+ if (certifiedUNSAT) {
+ fprintf(certifiedOutput, "d ");
+ for (int i = 0; i < c.size(); i++)
+ fprintf(certifiedOutput, "%i " , (var(c[i]) + 1) * (-2 * sign(c[i]) + 1) );
+ fprintf(certifiedOutput, "0\n");
+ }
+
+ detachClause(cr, true);
+ c.strengthen(l);
+ attachClause(cr);
+ remove(occurs[var(l)], cr);
+ n_occ[toInt(l)]--;
+ updateElimHeap(var(l));
+ }
+
+ return c.size() == 1 ? enqueue(c[0]) && propagate() == CRef_Undef : true;
+}
+
+
+// Returns FALSE if clause is always satisfied ('out_clause' should not be used).
+bool SimpSolver::merge(const Clause& _ps, const Clause& _qs, Var v, vec<Lit>& out_clause)
+{
+ merges++;
+ out_clause.clear();
+
+ bool ps_smallest = _ps.size() < _qs.size();
+ const Clause& ps = ps_smallest ? _qs : _ps;
+ const Clause& qs = ps_smallest ? _ps : _qs;
+
+ int i, j;
+ for (i = 0; i < qs.size(); i++){
+ if (var(qs[i]) != v){
+ for (j = 0; j < ps.size(); j++)
+ if (var(ps[j]) == var(qs[i])) {
+ if (ps[j] == ~qs[i])
+ return false;
+ else
+ goto next;
+ }
+ out_clause.push(qs[i]);
+ }
+ next:;
+ }
+
+ for (i = 0; i < ps.size(); i++)
+ if (var(ps[i]) != v)
+ out_clause.push(ps[i]);
+
+ return true;
+}
+
+
+// Returns FALSE if clause is always satisfied.
+bool SimpSolver::merge(const Clause& _ps, const Clause& _qs, Var v, int& size)
+{
+ merges++;
+
+ bool ps_smallest = _ps.size() < _qs.size();
+ const Clause& ps = ps_smallest ? _qs : _ps;
+ const Clause& qs = ps_smallest ? _ps : _qs;
+ const Lit* __ps = (const Lit*)ps;
+ const Lit* __qs = (const Lit*)qs;
+
+ size = ps.size()-1;
+
+ for (int i = 0; i < qs.size(); i++){
+ if (var(__qs[i]) != v){
+ for (int j = 0; j < ps.size(); j++)
+ if (var(__ps[j]) == var(__qs[i])) {
+ if (__ps[j] == ~__qs[i])
+ return false;
+ else
+ goto next;
+ }
+ size++;
+ }
+ next:;
+ }
+
+ return true;
+}
+
+
+void SimpSolver::gatherTouchedClauses()
+{
+ if (n_touched == 0) return;
+
+ int i,j;
+ for (i = j = 0; i < subsumption_queue.size(); i++)
+ if (ca[subsumption_queue[i]].mark() == 0)
+ ca[subsumption_queue[i]].mark(2);
+
+ for (i = 0; i < touched.size(); i++)
+ if (touched[i]){
+ const vec<CRef>& cs = occurs.lookup(i);
+ for (j = 0; j < cs.size(); j++)
+ if (ca[cs[j]].mark() == 0){
+ subsumption_queue.insert(cs[j]);
+ ca[cs[j]].mark(2);
+ }
+ touched[i] = 0;
+ }
+
+ for (i = 0; i < subsumption_queue.size(); i++)
+ if (ca[subsumption_queue[i]].mark() == 2)
+ ca[subsumption_queue[i]].mark(0);
+
+ n_touched = 0;
+}
+
+
+bool SimpSolver::implied(const vec<Lit>& c)
+{
+ assert(decisionLevel() == 0);
+
+ trail_lim.push(trail.size());
+ for (int i = 0; i < c.size(); i++)
+ if (value(c[i]) == l_True){
+ cancelUntil(0);
+ return false;
+ }else if (value(c[i]) != l_False){
+ assert(value(c[i]) == l_Undef);
+ uncheckedEnqueue(~c[i]);
+ }
+
+ bool result = propagate() != CRef_Undef;
+ cancelUntil(0);
+ return result;
+}
+
+
+// Backward subsumption + backward subsumption resolution
+bool SimpSolver::backwardSubsumptionCheck(bool verbose)
+{
+ int cnt = 0;
+ int subsumed = 0;
+ int deleted_literals = 0;
+ assert(decisionLevel() == 0);
+
+ while (subsumption_queue.size() > 0 || bwdsub_assigns < trail.size()){
+
+ // Empty subsumption queue and return immediately on user-interrupt:
+ if (asynch_interrupt){
+ subsumption_queue.clear();
+ bwdsub_assigns = trail.size();
+ break; }
+
+ // Check top-level assignments by creating a dummy clause and placing it in the queue:
+ if (subsumption_queue.size() == 0 && bwdsub_assigns < trail.size()){
+ Lit l = trail[bwdsub_assigns++];
+ ca[bwdsub_tmpunit][0] = l;
+ ca[bwdsub_tmpunit].calcAbstraction();
+ subsumption_queue.insert(bwdsub_tmpunit); }
+
+ CRef cr = subsumption_queue.peek(); subsumption_queue.pop();
+ Clause& c = ca[cr];
+
+ if (c.mark()) continue;
+
+ if (verbose && verbosity >= 2 && cnt++ % 1000 == 0)
+ printf("subsumption left: %10d (%10d subsumed, %10d deleted literals)\r", subsumption_queue.size(), subsumed, deleted_literals);
+
+ assert(c.size() > 1 || value(c[0]) == l_True); // Unit-clauses should have been propagated before this point.
+
+ // Find best variable to scan:
+ Var best = var(c[0]);
+ for (int i = 1; i < c.size(); i++)
+ if (occurs[var(c[i])].size() < occurs[best].size())
+ best = var(c[i]);
+
+ // Search all candidates:
+ vec<CRef>& _cs = occurs.lookup(best);
+ CRef* cs = (CRef*)_cs;
+
+ for (int j = 0; j < _cs.size(); j++)
+ if (c.mark())
+ break;
+ else if (!ca[cs[j]].mark() && cs[j] != cr && (subsumption_lim == -1 || ca[cs[j]].size() < subsumption_lim)){
+ Lit l = c.subsumes(ca[cs[j]]);
+
+ if (l == lit_Undef)
+ subsumed++, removeClause(cs[j]);
+ else if (l != lit_Error){
+ deleted_literals++;
+
+ if (!strengthenClause(cs[j], ~l))
+ return false;
+
+ // Did current candidate get deleted from cs? Then check candidate at index j again:
+ if (var(l) == best)
+ j--;
+ }
+ }
+ }
+
+ return true;
+}
+
+
+bool SimpSolver::asymm(Var v, CRef cr)
+{
+ Clause& c = ca[cr];
+ assert(decisionLevel() == 0);
+
+ if (c.mark() || satisfied(c)) return true;
+
+ trail_lim.push(trail.size());
+ Lit l = lit_Undef;
+ for (int i = 0; i < c.size(); i++)
+ if (var(c[i]) != v && value(c[i]) != l_False)
+ uncheckedEnqueue(~c[i]);
+ else
+ l = c[i];
+
+ if (propagate() != CRef_Undef){
+ cancelUntil(0);
+ asymm_lits++;
+ if (!strengthenClause(cr, l))
+ return false;
+ }else
+ cancelUntil(0);
+
+ return true;
+}
+
+
+bool SimpSolver::asymmVar(Var v)
+{
+ assert(use_simplification);
+
+ const vec<CRef>& cls = occurs.lookup(v);
+
+ if (value(v) != l_Undef || cls.size() == 0)
+ return true;
+
+ for (int i = 0; i < cls.size(); i++)
+ if (!asymm(v, cls[i]))
+ return false;
+
+ return backwardSubsumptionCheck();
+}
+
+
+static void mkElimClause(vec<uint32_t>& elimclauses, Lit x)
+{
+ elimclauses.push(toInt(x));
+ elimclauses.push(1);
+}
+
+
+static void mkElimClause(vec<uint32_t>& elimclauses, Var v, Clause& c)
+{
+ int first = elimclauses.size();
+ int v_pos = -1;
+
+ // Copy clause to elimclauses-vector. Remember position where the
+ // variable 'v' occurs:
+ for (int i = 0; i < c.size(); i++){
+ elimclauses.push(toInt(c[i]));
+ if (var(c[i]) == v)
+ v_pos = i + first;
+ }
+ assert(v_pos != -1);
+
+ // Swap the first literal with the 'v' literal, so that the literal
+ // containing 'v' will occur first in the clause:
+ uint32_t tmp = elimclauses[v_pos];
+ elimclauses[v_pos] = elimclauses[first];
+ elimclauses[first] = tmp;
+
+ // Store the length of the clause last:
+ elimclauses.push(c.size());
+}
+
+
+
+bool SimpSolver::eliminateVar(Var v)
+{
+ int i, j;
+ assert(!frozen[v]);
+ assert(!isEliminated(v));
+ assert(value(v) == l_Undef);
+
+ // Split the occurrences into positive and negative:
+ //
+ const vec<CRef>& cls = occurs.lookup(v);
+ vec<CRef> pos, neg;
+ for (i = 0; i < cls.size(); i++)
+ (find(ca[cls[i]], mkLit(v)) ? pos : neg).push(cls[i]);
+
+ // Check wether the increase in number of clauses stays within the allowed ('grow'). Moreover, no
+ // clause must exceed the limit on the maximal clause size (if it is set):
+ //
+ int cnt = 0;
+ int clause_size = 0;
+
+ for (i = 0; i < pos.size(); i++)
+ for (j = 0; j < neg.size(); j++)
+ if (merge(ca[pos[i]], ca[neg[j]], v, clause_size) &&
+ (++cnt > cls.size() + grow || (clause_lim != -1 && clause_size > clause_lim)))
+ return true;
+
+ // Delete and store old clauses:
+ eliminated[v] = true;
+ setDecisionVar(v, false);
+ eliminated_vars++;
+
+ if (pos.size() > neg.size()){
+ for (i = 0; i < neg.size(); i++)
+ mkElimClause(elimclauses, v, ca[neg[i]]);
+ mkElimClause(elimclauses, mkLit(v));
+ eliminated_clauses += neg.size();
+ }else{
+ for (i = 0; i < pos.size(); i++)
+ mkElimClause(elimclauses, v, ca[pos[i]]);
+ mkElimClause(elimclauses, ~mkLit(v));
+ eliminated_clauses += pos.size();
+ }
+
+
+ // Produce clauses in cross product:
+ vec<Lit>& resolvent = add_tmp;
+ for (i = 0; i < pos.size(); i++)
+ for (j = 0; j < neg.size(); j++)
+ if (merge(ca[pos[i]], ca[neg[j]], v, resolvent) && !addClause_(resolvent))
+ return false;
+
+ for (i = 0; i < cls.size(); i++)
+ removeClause(cls[i]);
+
+ // Free occurs list for this variable:
+ occurs[v].clear(true);
+
+ // Free watchers lists for this variable, if possible:
+ if (watches[ mkLit(v)].size() == 0) watches[ mkLit(v)].clear(true);
+ if (watches[~mkLit(v)].size() == 0) watches[~mkLit(v)].clear(true);
+
+ return backwardSubsumptionCheck();
+}
+
+
+bool SimpSolver::substitute(Var v, Lit x)
+{
+ assert(!frozen[v]);
+ assert(!isEliminated(v));
+ assert(value(v) == l_Undef);
+
+ if (!ok) return false;
+
+ eliminated[v] = true;
+ setDecisionVar(v, false);
+ const vec<CRef>& cls = occurs.lookup(v);
+
+ vec<Lit>& subst_clause = add_tmp;
+ for (int i = 0; i < cls.size(); i++){
+ Clause& c = ca[cls[i]];
+
+ subst_clause.clear();
+ for (int j = 0; j < c.size(); j++){
+ Lit p = c[j];
+ subst_clause.push(var(p) == v ? x ^ sign(p) : p);
+ }
+
+
+ if (!addClause_(subst_clause))
+ return ok = false;
+
+ removeClause(cls[i]);
+
+ }
+
+ return true;
+}
+
+
+void SimpSolver::extendModel()
+{
+ int i, j;
+ Lit x;
+
+ for (i = elimclauses.size()-1; i > 0; i -= j){
+ for (j = elimclauses[i--]; j > 1; j--, i--)
+ if (modelValue(toLit(elimclauses[i])) != l_False)
+ goto next;
+
+ x = toLit(elimclauses[i]);
+ model[var(x)] = lbool(!sign(x));
+ next:;
+ }
+}
+
+
+bool SimpSolver::eliminate(bool turn_off_elim)
+{
+ //abctime clk = Abc_Clock();
+ if (!simplify())
+ return false;
+ else if (!use_simplification)
+ return true;
+
+ // Main simplification loop:
+ //
+
+ int toPerform = clauses.size()<=4800000;
+
+ if(!toPerform) {
+ printf("c Too many clauses... No preprocessing\n");
+ }
+
+ while (toPerform && (n_touched > 0 || bwdsub_assigns < trail.size() || elim_heap.size() > 0)){
+
+ gatherTouchedClauses();
+ // printf(" ## (time = %6.2f s) BWD-SUB: queue = %d, trail = %d\n", cpuTime(), subsumption_queue.size(), trail.size() - bwdsub_assigns);
+ if ((subsumption_queue.size() > 0 || bwdsub_assigns < trail.size()) &&
+ !backwardSubsumptionCheck(true)){
+ ok = false; goto cleanup; }
+
+ // Empty elim_heap and return immediately on user-interrupt:
+ if (asynch_interrupt){
+ assert(bwdsub_assigns == trail.size());
+ assert(subsumption_queue.size() == 0);
+ assert(n_touched == 0);
+ elim_heap.clear();
+ goto cleanup; }
+
+ // printf(" ## (time = %6.2f s) ELIM: vars = %d\n", cpuTime(), elim_heap.size());
+ for (int cnt = 0; !elim_heap.empty(); cnt++){
+ Var elim = elim_heap.removeMin();
+
+ if (asynch_interrupt) break;
+
+ if (isEliminated(elim) || value(elim) != l_Undef) continue;
+
+ if (verbosity >= 2 && cnt % 100 == 0)
+ printf("elimination left: %10d\r", elim_heap.size());
+
+ if (use_asymm){
+ // Temporarily freeze variable. Otherwise, it would immediately end up on the queue again:
+ bool was_frozen = frozen[elim] != 0;
+ frozen[elim] = true;
+ if (!asymmVar(elim)){
+ ok = false; goto cleanup; }
+ frozen[elim] = was_frozen; }
+
+ // At this point, the variable may have been set by assymetric branching, so check it
+ // again. Also, don't eliminate frozen variables:
+ if (use_elim && value(elim) == l_Undef && !frozen[elim] && !eliminateVar(elim)){
+ ok = false; goto cleanup; }
+
+ checkGarbage(simp_garbage_frac);
+ }
+
+ assert(subsumption_queue.size() == 0);
+ }
+ cleanup:
+
+ // If no more simplification is needed, free all simplification-related data structures:
+ if (turn_off_elim){
+ touched .clear(true);
+ occurs .clear(true);
+ n_occ .clear(true);
+ elim_heap.clear(true);
+ subsumption_queue.clear(true);
+
+ use_simplification = false;
+ remove_satisfied = true;
+ ca.extra_clause_field = false;
+
+ // Force full cleanup (this is safe and desirable since it only happens once):
+ rebuildOrderHeap();
+ garbageCollect();
+ }else{
+ // Cheaper cleanup:
+ cleanUpClauses(); // TODO: can we make 'cleanUpClauses()' not be linear in the problem size somehow?
+ checkGarbage();
+ }
+
+ if (verbosity >= 1 && elimclauses.size() > 0)
+ printf("c | Eliminated clauses: %10.2f Mb |\n",
+ double(elimclauses.size() * sizeof(uint32_t)) / (1024*1024));
+ return ok;
+}
+
+
+void SimpSolver::cleanUpClauses()
+{
+ occurs.cleanAll();
+ int i,j;
+ for (i = j = 0; i < clauses.size(); i++)
+ if (ca[clauses[i]].mark() == 0)
+ clauses[j++] = clauses[i];
+ clauses.shrink_(i - j);
+}
+
+
+//=================================================================================================
+// Garbage Collection methods:
+
+
+void SimpSolver::relocAll(ClauseAllocator& to)
+{
+ int i;
+ if (!use_simplification) return;
+
+ // All occurs lists:
+ //
+ for (i = 0; i < nVars(); i++){
+ vec<CRef>& cs = occurs[i];
+ for (int j = 0; j < cs.size(); j++)
+ ca.reloc(cs[j], to);
+ }
+
+ // Subsumption queue:
+ //
+ for (i = 0; i < subsumption_queue.size(); i++)
+ ca.reloc(subsumption_queue[i], to);
+
+ // Temporary clause:
+ //
+ ca.reloc(bwdsub_tmpunit, to);
+}
+
+
+void SimpSolver::garbageCollect()
+{
+ // Initialize the next region to a size corresponding to the estimated utilization degree. This
+ // is not precise but should avoid some unnecessary reallocations for the new region:
+ ClauseAllocator to(ca.size() - ca.wasted());
+
+ cleanUpClauses();
+ to.extra_clause_field = ca.extra_clause_field; // NOTE: this is important to keep (or lose) the extra fields.
+ relocAll(to);
+ Solver::relocAll(to);
+ if (verbosity >= 2)
+ printf("| Garbage collection: %12d bytes => %12d bytes |\n",
+ ca.size()*ClauseAllocator::Unit_Size, to.size()*ClauseAllocator::Unit_Size);
+ to.moveTo(ca);
+}
+
+void SimpSolver::reset()
+{
+ Solver::reset();
+ grow = opt_grow;
+ asymm_lits = eliminated_vars = bwdsub_assigns = n_touched = 0;
+
+ subsumption_queue.clear(false);
+ vec<Lit> dummy(1,lit_Undef);
+ ca.extra_clause_field = true; // NOTE: must happen before allocating the dummy clause below.
+ bwdsub_tmpunit = ca.alloc(dummy);
+ remove_satisfied = false;
+
+ occurs.clear(false);
+
+ touched .shrink_( touched .size() );
+ n_occ .shrink_( n_occ .size() );
+ eliminated .shrink_( eliminated .size() );
+ frozen .shrink_( frozen .size() );
+ elimclauses .shrink_( elimclauses .size() );
+
+ elim_heap .clear_(false);
+}
+
+ABC_NAMESPACE_IMPL_END
diff --git a/src/sat/glucose2/Solver.h b/src/sat/glucose2/Solver.h
new file mode 100644
index 00000000..b1d38d79
--- /dev/null
+++ b/src/sat/glucose2/Solver.h
@@ -0,0 +1,653 @@
+/****************************************************************************************[Solver.h]
+ Glucose -- Copyright (c) 2009, Gilles Audemard, Laurent Simon
+ CRIL - Univ. Artois, France
+ LRI - Univ. Paris Sud, France
+
+Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of
+Glucose are exactly the same as Minisat on which it is based on. (see below).
+
+---------------
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Solver_h
+#define Glucose_Solver_h
+
+#include "sat/glucose2/Vec.h"
+#include "sat/glucose2/Heap.h"
+#include "sat/glucose2/Alg.h"
+#include "sat/glucose2/Options.h"
+#include "sat/glucose2/SolverTypes.h"
+#include "sat/glucose2/BoundedQueue.h"
+#include "sat/glucose2/Constants.h"
+
+#include "sat/glucose2/CGlucose.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// Solver -- the main class:
+
+class Solver {
+public:
+
+ int SolverType; // ABC identifies Glucose's type as 0
+
+ // Constructor/Destructor:
+ //
+ Solver();
+ virtual ~Solver();
+
+ // ABC callbacks
+ void * pCnfMan; // external CNF manager
+ int(*pCnfFunc)(void * p, int, int*); // external callback. messages: 0: unsat; 1: sat; -1: still working
+ int nCallConfl; // callback will be called every this number of conflicts
+ bool terminate_search_early; // used to stop the solver early if it as instructed by an external caller
+ int * pstop; // another callback
+ uint64_t nRuntimeLimit; // runtime limit
+ vec<int> user_vec;
+ vec<Lit> user_lits;
+
+ // circuit-based solving
+ int jftr;
+ void sat_solver_set_var_fanin_lit(int, int, int);
+ void sat_solver_start_new_round();
+ void sat_solver_mark_cone(int);
+ void sat_solver_set_jftr(int);
+ int sat_solver_jftr();
+ void sat_solver_reset();
+
+ // Problem specification:
+ //
+ Var newVar (bool polarity = true, bool dvar = true); // Add a new variable with parameters specifying variable mode.
+ void addVar (Var v); // Add enough variables to make sure there is variable v.
+
+ bool addClause (const vec<Lit>& ps); // Add a clause to the solver.
+ bool addEmptyClause(); // Add the empty clause, making the solver contradictory.
+ bool addClause (Lit p); // Add a unit clause to the solver.
+ bool addClause (Lit p, Lit q); // Add a binary clause to the solver.
+ bool addClause (Lit p, Lit q, Lit r); // Add a ternary clause to the solver.
+ bool addClause_( vec<Lit>& ps); // Add a clause to the solver without making superflous internal copy. Will
+ // change the passed vector 'ps'.
+
+ // Solving:
+ //
+ bool simplify (); // Removes already satisfied clauses.
+ bool solve (const vec<Lit>& assumps); // Search for a model that respects a given set of assumptions.
+ lbool solveLimited (const vec<Lit>& assumps); // Search for a model that respects a given set of assumptions (With resource constraints).
+ bool solve (); // Search without assumptions.
+ bool solve (Lit p); // Search for a model that respects a single assumption.
+ bool solve (Lit p, Lit q); // Search for a model that respects two assumptions.
+ bool solve (Lit p, Lit q, Lit r); // Search for a model that respects three assumptions.
+ bool okay () const; // FALSE means solver is in a conflicting state
+
+ void toDimacs (FILE* f, const vec<Lit>& assumps); // Write CNF to file in DIMACS-format.
+ void toDimacs (const char *file, const vec<Lit>& assumps);
+ void toDimacs (FILE* f, Clause& c, vec<Var>& map, Var& max);
+ void printLit(Lit l);
+ void printClause(CRef c);
+ void printInitialClause(CRef c);
+ // Convenience versions of 'toDimacs()':
+ void toDimacs (const char* file);
+ void toDimacs (const char* file, Lit p);
+ void toDimacs (const char* file, Lit p, Lit q);
+ void toDimacs (const char* file, Lit p, Lit q, Lit r);
+
+ // Variable mode:
+ //
+ void setPolarity (Var v, bool b); // Declare which polarity the decision heuristic should use for a variable. Requires mode 'polarity_user'.
+ void setDecisionVar (Var v, bool b, bool use_oheap = true); // Declare if a variable should be eligible for selection in the decision heuristic.
+
+ // Read state:
+ //
+ lbool value (Var x) const; // The current value of a variable.
+ lbool value (Lit p) const; // The current value of a literal.
+ lbool modelValue (Var x) const; // The value of a variable in the last model. The last call to solve must have been satisfiable.
+ lbool modelValue (Lit p) const; // The value of a literal in the last model. The last call to solve must have been satisfiable.
+ int nAssigns () const; // The current number of assigned literals.
+ int nClauses () const; // The current number of original clauses.
+ int nLearnts () const; // The current number of learnt clauses.
+ int nVars () const; // The current number of variables.
+ int nFreeVars () const;
+ int * getCex () const;
+ int level (Var x) const; // moved level() to public to compile "struct JustOrderLt" -- alanmi
+
+ // Incremental mode
+ void setIncrementalMode();
+ void initNbInitialVars(int nb);
+ void printIncrementalStats();
+
+ // Resource contraints:
+ //
+ void setConfBudget(int64_t x);
+ void setPropBudget(int64_t x);
+ void budgetOff();
+ void interrupt(); // Trigger a (potentially asynchronous) interruption of the solver.
+ void clearInterrupt(); // Clear interrupt indicator flag.
+
+ // Memory managment:
+ //
+ virtual void reset();
+ virtual void garbageCollect(); // virtuality causes segfault for some reason
+ void checkGarbage(double gf);
+ void checkGarbage();
+
+
+
+
+ // Extra results: (read-only member variable)
+ //
+ vec<lbool> model; // If problem is satisfiable, this vector contains the model (if any).
+ vec<Lit> conflict; // If problem is unsatisfiable (possibly under assumptions),
+ // this vector represent the final conflict clause expressed in the assumptions.
+
+ // Mode of operation:
+ //
+ int verbosity;
+ int verbEveryConflicts;
+ int showModel;
+ // Constants For restarts
+ double K;
+ double R;
+ double sizeLBDQueue;
+ double sizeTrailQueue;
+
+ // Constants for reduce DB
+ int firstReduceDB;
+ int incReduceDB;
+ int specialIncReduceDB;
+ unsigned int lbLBDFrozenClause;
+
+ // Constant for reducing clause
+ int lbSizeMinimizingClause;
+ unsigned int lbLBDMinimizingClause;
+
+ double var_decay;
+ double clause_decay;
+ double random_var_freq;
+ double random_seed;
+ int ccmin_mode; // Controls conflict clause minimization (0=none, 1=basic, 2=deep).
+ int phase_saving; // Controls the level of phase saving (0=none, 1=limited, 2=full).
+ bool rnd_pol; // Use random polarities for branching heuristics.
+ bool rnd_init_act; // Initialize variable activities with a small random value.
+ double garbage_frac; // The fraction of wasted memory allowed before a garbage collection is triggered.
+
+ // Certified UNSAT ( Thanks to Marijn Heule)
+ FILE* certifiedOutput;
+ bool certifiedUNSAT;
+
+
+ // Statistics: (read-only member variable)
+ //
+ int64_t nbRemovedClauses,nbReducedClauses,nbDL2,nbBin,nbUn,nbReduceDB,solves, starts, decisions, rnd_decisions, propagations, conflicts,conflictsRestarts,nbstopsrestarts,nbstopsrestartssame,lastblockatrestart;
+ int64_t dec_vars, clauses_literals, learnts_literals, max_literals, tot_literals;
+
+protected:
+ long curRestart;
+ // Helper structures:
+ //
+ struct VarData { CRef reason; int level; };
+ static inline VarData mkVarData(CRef cr, int l){ VarData d = {cr, l}; return d; }
+
+ struct Watcher {
+ CRef cref;
+ Lit blocker;
+ Watcher(CRef cr, Lit p) : cref(cr), blocker(p) {}
+ bool operator==(const Watcher& w) const { return cref == w.cref; }
+ bool operator!=(const Watcher& w) const { return cref != w.cref; }
+ };
+
+ struct WatcherDeleted
+ {
+ const ClauseAllocator& ca;
+ WatcherDeleted(const ClauseAllocator& _ca) : ca(_ca) {}
+ bool operator()(const Watcher& w) const { return ca[w.cref].mark() == 1; }
+ };
+
+ struct VarOrderLt {
+ const vec<double>& activity;
+ bool operator () (Var x, Var y) const { return activity[x] > activity[y]; }
+ VarOrderLt(const vec<double>& act) : activity(act) { }
+ };
+
+
+ // Solver state:
+ //
+ int lastIndexRed;
+ bool ok; // If FALSE, the constraints are already unsatisfiable. No part of the solver state may be used!
+ double cla_inc; // Amount to bump next clause with.
+ vec<double> activity; // A heuristic measurement of the activity of a variable.
+ double var_inc; // Amount to bump next variable with.
+ OccLists<Lit, vec<Watcher>, WatcherDeleted>
+ watches; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true).
+ OccLists<Lit, vec<Watcher>, WatcherDeleted>
+ watchesBin; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true).
+ vec<CRef> clauses; // List of problem clauses.
+ vec<CRef> learnts; // List of learnt clauses.
+
+ vec<lbool> assigns; // The current assignments.
+ vec<char> polarity; // The preferred polarity of each variable.
+ vec<char> decision; // Declares if a variable is eligible for selection in the decision heuristic.
+ vec<Lit> trail; // Assignment stack; stores all assigments made in the order they were made.
+ vec<int> nbpos;
+ vec<int> trail_lim; // Separator indices for different decision levels in 'trail'.
+ vec<VarData> vardata; // Stores reason and level for each variable.
+ int qhead; // Head of queue (as index into the trail -- no more explicit propagation queue in MiniSat).
+ int simpDB_assigns; // Number of top-level assignments since last execution of 'simplify()'.
+ int64_t simpDB_props; // Remaining number of propagations that must be made before next execution of 'simplify()'.
+ vec<Lit> assumptions; // Current set of assumptions provided to solve by the user.
+ Heap<VarOrderLt> order_heap; // A priority queue of variables ordered with respect to the variable activity.
+ double progress_estimate;// Set by 'search()'.
+ bool remove_satisfied; // Indicates whether possibly inefficient linear scan for satisfied clauses should be performed in 'simplify'.
+ vec<unsigned int> permDiff; // permDiff[var] contains the current conflict number... Used to count the number of LBD
+
+#ifdef UPDATEVARACTIVITY
+ // UPDATEVARACTIVITY trick (see competition'09 companion paper)
+ vec<Lit> lastDecisionLevel;
+#endif
+
+ ClauseAllocator ca;
+
+ int nbclausesbeforereduce; // To know when it is time to reduce clause database
+
+ bqueue<unsigned int> trailQueue,lbdQueue; // Bounded queues for restarts.
+ float sumLBD; // used to compute the global average of LBD. Restarts...
+ int sumAssumptions;
+
+
+ // Temporaries (to reduce allocation overhead). Each variable is prefixed by the method in which it is
+ // used, exept 'seen' wich is used in several places.
+ //
+ vec<char> seen;
+ vec<Lit> analyze_stack;
+ vec<Lit> analyze_toclear;
+ vec<Lit> add_tmp;
+ unsigned int MYFLAG;
+
+
+ double max_learnts;
+ double learntsize_adjust_confl;
+ int learntsize_adjust_cnt;
+
+ // Resource contraints:
+ //
+ int64_t conflict_budget; // -1 means no budget.
+ int64_t propagation_budget; // -1 means no budget.
+ bool asynch_interrupt;
+
+
+ // Variables added for incremental mode
+ int incremental; // Use incremental SAT Solver
+ int nbVarsInitialFormula; // nb VAR in formula without assumptions (incremental SAT)
+ double totalTime4Sat,totalTime4Unsat;
+ int nbSatCalls,nbUnsatCalls;
+ vec<int> assumptionPositions,initialPositions;
+
+
+ // Main internal methods:
+ //
+ void insertVarOrder (Var x); // Insert a variable in the decision order priority queue.
+ Lit pickBranchLit (); // Return the next decision variable.
+ void newDecisionLevel (); // Begins a new decision level.
+ void uncheckedEnqueue (Lit p, CRef from = CRef_Undef); // Enqueue a literal. Assumes value of literal is undefined.
+ bool enqueue (Lit p, CRef from = CRef_Undef); // Test if fact 'p' contradicts current state, enqueue otherwise.
+ CRef propagate (); // Perform unit propagation. Returns possibly conflicting clause.
+ void cancelUntil (int level); // Backtrack until a certain level.
+ void analyze (CRef confl, vec<Lit>& out_learnt, vec<Lit> & selectors, int& out_btlevel,unsigned int &nblevels,unsigned int &szWithoutSelectors); // (bt = backtrack)
+ void analyzeFinal (Lit p, vec<Lit>& out_conflict); // COULD THIS BE IMPLEMENTED BY THE ORDINARIY "analyze" BY SOME REASONABLE GENERALIZATION?
+ bool litRedundant (Lit p, uint32_t abstract_levels); // (helper method for 'analyze()')
+ lbool search (int nof_conflicts); // Search for a given number of conflicts.
+ lbool solve_ (); // Main solve method (assumptions given in 'assumptions').
+ void reduceDB (); // Reduce the set of learnt clauses.
+ void removeSatisfied (vec<CRef>& cs); // Shrink 'cs' to contain only non-satisfied clauses.
+ void rebuildOrderHeap ();
+
+ // Maintaining Variable/Clause activity:
+ //
+ void varDecayActivity (); // Decay all variables with the specified factor. Implemented by increasing the 'bump' value instead.
+ void varBumpActivity (Var v, double inc); // Increase a variable with the current 'bump' value.
+ void varBumpActivity (Var v); // Increase a variable with the current 'bump' value.
+ void claDecayActivity (); // Decay all clauses with the specified factor. Implemented by increasing the 'bump' value instead.
+ void claBumpActivity (Clause& c); // Increase a clause with the current 'bump' value.
+
+ // Operations on clauses:
+ //
+ void attachClause (CRef cr); // Attach a clause to watcher lists.
+ void detachClause (CRef cr, bool strict = false); // Detach a clause to watcher lists.
+ void removeClause (CRef cr); // Detach and free a clause.
+ bool locked (const Clause& c) const; // Returns TRUE if a clause is a reason for some implication in the current state.
+ bool satisfied (const Clause& c) const; // Returns TRUE if a clause is satisfied in the current state.
+
+ unsigned int computeLBD(const vec<Lit> & lits,int end=-1);
+ unsigned int computeLBD(const Clause &c);
+ void minimisationWithBinaryResolution(vec<Lit> &out_learnt);
+
+ void relocAll (ClauseAllocator& to);
+
+ // Misc:
+ //
+ int decisionLevel () const; // Gives the current decisionlevel.
+ uint32_t abstractLevel (Var x) const; // Used to represent an abstraction of sets of decision levels.
+ CRef reason (Var x) const;
+ double progressEstimate () const; // DELETE THIS ?? IT'S NOT VERY USEFUL ...
+ bool withinBudget () const;
+ inline bool isSelector(Var v) {return (incremental && v>nbVarsInitialFormula);}
+
+ // Static helpers:
+ //
+
+ // Returns a random float 0 <= x < 1. Seed must never be 0.
+ static inline double drand(double& seed) {
+ seed *= 1389796;
+ int q = (int)(seed / 2147483647);
+ seed -= (double)q * 2147483647;
+ return seed / 2147483647; }
+
+ // Returns a random integer 0 <= x < size. Seed must never be 0.
+ static inline int irand(double& seed, int size) {
+ return (int)(drand(seed) * size); }
+
+
+ // circuit-based solver
+protected:
+ void uncheckedEnqueue2(Lit p, CRef from = CRef_Undef);
+ bool heap_rescale;
+
+ void addJwatch( Var host, Var member, int index );
+ //void delJwatch( Var member );
+
+ struct NodeData { Lit lit0; Lit lit1; unsigned sort:30; unsigned dir:1; unsigned now:1; };
+ static inline NodeData mkNodeData(){ NodeData w; w.lit0 = toLit(~0); w.lit1 = toLit(~0); w.sort = 0; w.dir = 0; w.now = 0; return w; }
+ vec<NodeData> var2NodeData;
+ //vec<Lit> var2FaninLits; // (~0): undefine
+ vec<unsigned> var2TravId;
+ vec<Lit> var2Fanout0, var2FanoutN;//, var2FanoutP;
+ CRef itpc; // the interpreted clause of a gate
+ void inplace_sort( Var v );
+
+ bool isTwoFanin ( Var v ) const ; // this var has two fanins
+ bool isAND ( Var v ) const { return getFaninVar0(v) < getFaninVar1(v); }
+ bool isJReason ( Var v ) const { return isTwoFanin(v) && ( l_False == value(v) || (!isAND(v) && l_Undef != value(v)) ); }
+ Lit getFaninLit0( Var v ) const { return var2NodeData[ v ].lit0; }
+ Lit getFaninLit1( Var v ) const { return var2NodeData[ v ].lit1; }
+ bool getFaninC0 ( Var v ) const { return sign(getFaninLit0(v)); }
+ bool getFaninC1 ( Var v ) const { return sign(getFaninLit1(v)); }
+ Var getFaninVar0( Var v ) const { return var(getFaninLit0(v)); }
+ Var getFaninVar1( Var v ) const { return var(getFaninLit1(v)); }
+ Lit getFaninPlt0( Var v ) const { return mkLit(getFaninVar0(v), 1 == polarity[getFaninVar0(v)]); }
+ Lit getFaninPlt1( Var v ) const { return mkLit(getFaninVar1(v), 1 == polarity[getFaninVar1(v)]); }
+ Lit maxActiveLit(Lit lit0, Lit lit1) const { return activity[var(lit0)] < activity[var(lit1)]? lit1: lit0; }
+
+ Lit gateJustFanin(Var v) const ; // l_Undef=satisfied, 0/1 = fanin0/fanin1 requires justify
+ void gateAddJwatch(Var v,int index);
+ CRef gatePropagateCheck( Var v, Var t );
+ CRef gatePropagateCheckThis( Var v );
+ CRef gatePropagateCheckFanout( Var v, Lit lfo );
+ void setItpcSize( int sz ); // sz <= 3
+
+ // directly call by original glucose functions
+ void updateJustActivity( Var v );
+ void ResetJustData(bool fCleanMemory);
+ Lit pickJustLit( int& index );
+ void justCheck();
+ void pushJustQueue(Var v, int index);
+ void restoreJustQueue(int level); // call with cancelUntil
+ void gateClearJwatch( Var v, int backtrack_level );
+
+ CRef gatePropagate( Lit p );
+
+ CRef interpret( Var v, Var t );
+ CRef castCRef( Lit p ); // interpret a gate into a clause
+ CRef getConfClause( CRef r );
+
+ CRef Var2CRef( Var v ) const { return v | (1<<(sizeof(CRef)*8-1)); }
+ Var CRef2Var( CRef cr ) const { return cr & ~(1<<(sizeof(CRef)*8-1)); }
+ bool isGateCRef( CRef cr ) const { return CRef_Undef != cr && 0 != (cr & (1<<(sizeof(CRef)*8-1))); }
+
+ unsigned travId_prev, travId;
+
+ //Heap<JustOrderLt> jheap;
+ int jhead;
+
+ struct JustKey {
+ typedef double Key;
+ typedef Var Data;
+ typedef int Attr;
+ Key _key;
+ Data _data;
+ Attr _attr;
+ Data data() const { return _data; }
+ Key key() const { return _key; }
+ Attr attr() const { return _attr; }
+ JustKey():_key(0),_data(0),_attr(0){}
+ JustKey( const Key& nkey, const Data& ndata, const Attr& nattr ): _key(nkey), _data(ndata), _attr(nattr) {}
+ };
+ struct JustOrderLt2 {
+ const Solver * pS;
+ bool operator () (const JustKey& x, const JustKey& y) const {
+ if( x.key() != y.key() ) return x.key() > y.key();
+ if( pS->level( x.data() ) != pS->level( y.data() ) )
+ return pS->level( x.data() ) < pS->level( y.data() );
+ return x.data() > y.data();
+ }
+ JustOrderLt2(const Solver * _pS) : pS(_pS) { }
+ };
+ Heap2<JustOrderLt2, JustKey> jheap;
+ vec<int> jlevel;
+ vec<int> jnext;
+public:
+ void prelocate( int var_num );
+ void setVarFaninLits( Var v, Lit lit1, Lit lit2 );
+ void setVarFaninLits( int v, int lit1, int lit2 ){ setVarFaninLits( Var(v), toLit(lit1), toLit(lit2) ); }
+ //void delVarFaninLits( Var v);
+
+ void setNewRound(){ travId ++ ; }
+ void markCone( Var v );
+ void setJust( int njftr ){ jftr = njftr; }
+ bool isRoundWatch( Var v ) const { return travId==var2TravId[v]; }
+ void justReset(){ jftr = 0; reset(); }
+
+
+ //const JustData& getJustData(int v) const { return jdata[v]; }
+ double varActivity(int v) const { return activity[v];}
+ //double justActivity(int v) const { return jdata[v].act_fanin;}
+ int varPolarity(int v){ return polarity[v]? 1: 0;}
+ vec<Lit> JustModel; // model obtained by justification enabled
+
+ int justUsage() const ;
+ int solveLimited( int * , int nlits );
+};
+
+
+//=================================================================================================
+// Implementation of inline methods:
+
+inline CRef Solver::reason(Var x) const { return vardata[x].reason; }
+inline int Solver::level (Var x) const { return vardata[x].level; }
+
+inline void Solver::insertVarOrder(Var x) {
+ #ifdef CGLUCOSE_EXP
+ if (!justUsage() && !order_heap.inHeap(x) && decision[x]) order_heap.insert(x);
+ #else
+ if (!order_heap.inHeap(x) && decision[x]) order_heap.insert(x);
+ #endif
+}
+
+inline void Solver::varDecayActivity() { var_inc *= (1 / var_decay); }
+inline void Solver::varBumpActivity(Var v) { varBumpActivity(v, var_inc); }
+inline void Solver::varBumpActivity(Var v, double inc) {
+ if ( (activity[v] += inc) > 1e100 ) {
+ heap_rescale = 1;
+ // Rescale:
+ for (int i = 0; i < nVars(); i++)
+ activity[i] *= 1e-100;
+ var_inc *= 1e-100; }
+
+ // Update order_heap with respect to new activity:
+ if (!justUsage() && order_heap.inHeap(v))
+ order_heap.decrease(v);
+}
+
+inline void Solver::claDecayActivity() { cla_inc *= (1 / clause_decay); }
+inline void Solver::claBumpActivity (Clause& c) {
+ if ( (c.activity() += cla_inc) > 1e20 ) {
+ // Rescale:
+ for (int i = 0; i < learnts.size(); i++)
+ ca[learnts[i]].activity() *= (float)1e-20;
+ cla_inc *= 1e-20; } }
+
+inline void Solver::checkGarbage(void){ checkGarbage(garbage_frac); }
+inline void Solver::checkGarbage(double gf){
+ if (ca.wasted() > ca.size() * gf)
+ garbageCollect();}
+
+// NOTE: enqueue does not set the ok flag! (only public methods do)
+inline bool Solver::enqueue (Lit p, CRef from) { return value(p) != l_Undef ? value(p) != l_False : (uncheckedEnqueue(p, from), true); }
+inline bool Solver::addClause (const vec<Lit>& ps) { ps.copyTo(add_tmp); return addClause_(add_tmp); }
+inline bool Solver::addEmptyClause () { add_tmp.clear(); return addClause_(add_tmp); }
+inline bool Solver::addClause (Lit p) { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp); }
+inline bool Solver::addClause (Lit p, Lit q) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp); }
+inline bool Solver::addClause (Lit p, Lit q, Lit r) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp); }
+inline bool Solver::locked (const Clause& c) const {
+ #ifdef CGLUCOSE_EXP
+
+ if(c.size()>2)
+ return value(c[0]) == l_True && reason(var(c[0])) != CRef_Undef && !isGateCRef(reason(var(c[0]))) && ca.lea(reason(var(c[0]))) == &c;
+ return
+ (value(c[0]) == l_True && reason(var(c[0])) != CRef_Undef && !isGateCRef(reason(var(c[0]))) && ca.lea(reason(var(c[0]))) == &c)
+ ||
+ (value(c[1]) == l_True && reason(var(c[1])) != CRef_Undef && !isGateCRef(reason(var(c[1]))) && ca.lea(reason(var(c[1]))) == &c);
+
+ #else
+
+ if(c.size()>2)
+ return value(c[0]) == l_True && reason(var(c[0])) != CRef_Undef && ca.lea(reason(var(c[0]))) == &c;
+ return
+ (value(c[0]) == l_True && reason(var(c[0])) != CRef_Undef && ca.lea(reason(var(c[0]))) == &c)
+ ||
+ (value(c[1]) == l_True && reason(var(c[1])) != CRef_Undef && ca.lea(reason(var(c[1]))) == &c);
+
+ #endif
+ }
+inline void Solver::newDecisionLevel() {trail_lim.push(trail.size());}
+
+inline int Solver::decisionLevel () const { return trail_lim.size(); }
+inline uint32_t Solver::abstractLevel (Var x) const { return 1 << (level(x) & 31); }
+inline lbool Solver::value (Var x) const { return assigns[x]; }
+inline lbool Solver::value (Lit p) const { return assigns[var(p)] ^ sign(p); }
+inline lbool Solver::modelValue (Var x) const { return model[x]; }
+inline lbool Solver::modelValue (Lit p) const { return model[var(p)] ^ sign(p); }
+inline int Solver::nAssigns () const { return trail.size(); }
+inline int Solver::nClauses () const { return clauses.size(); }
+inline int Solver::nLearnts () const { return learnts.size(); }
+inline int Solver::nVars () const { return vardata.size(); }
+inline int Solver::nFreeVars () const { return (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]); }
+inline int * Solver::getCex () const { return (int*) &JustModel[0]; }
+inline void Solver::setPolarity (Var v, bool b) { polarity[v] = b; }
+inline void Solver::setDecisionVar(Var v, bool b, bool use_oheap)
+{
+ if ( b && !decision[v]) dec_vars++;
+ else if (!b && decision[v]) dec_vars--;
+
+ decision[v] = b;
+ if( use_oheap ) insertVarOrder(v);
+}
+inline void Solver::setConfBudget(int64_t x){ conflict_budget = conflicts + x; }
+inline void Solver::setPropBudget(int64_t x){ propagation_budget = propagations + x; }
+inline void Solver::interrupt(){ asynch_interrupt = true; }
+inline void Solver::clearInterrupt(){ asynch_interrupt = false; }
+inline void Solver::budgetOff(){ conflict_budget = propagation_budget = -1; }
+inline bool Solver::withinBudget() const {
+ return !asynch_interrupt &&
+ (conflict_budget < 0 || conflicts < (uint64_t)conflict_budget) &&
+ (propagation_budget < 0 || propagations < (uint64_t)propagation_budget); }
+
+// FIXME: after the introduction of asynchronous interrruptions the solve-versions that return a
+// pure bool do not give a safe interface. Either interrupts must be possible to turn off here, or
+// all calls to solve must return an 'lbool'. I'm not yet sure which I prefer.
+inline bool Solver::solve () { budgetOff(); assumptions.clear(); return solve_() == l_True; }
+inline bool Solver::solve (Lit p) { budgetOff(); assumptions.clear(); assumptions.push(p); return solve_() == l_True; }
+inline bool Solver::solve (Lit p, Lit q) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); return solve_() == l_True; }
+inline bool Solver::solve (Lit p, Lit q, Lit r) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); assumptions.push(r); return solve_() == l_True; }
+inline bool Solver::solve (const vec<Lit>& assumps){ budgetOff(); assumps.copyTo(assumptions); return solve_() == l_True; }
+inline lbool Solver::solveLimited (const vec<Lit>& assumps){ assumps.copyTo(assumptions); return solve_(); }
+inline bool Solver::okay () const { return ok; }
+
+inline void Solver::toDimacs (const char* file){ vec<Lit> as; toDimacs(file, as); }
+inline void Solver::toDimacs (const char* file, Lit p){ vec<Lit> as; as.push(p); toDimacs(file, as); }
+inline void Solver::toDimacs (const char* file, Lit p, Lit q){ vec<Lit> as; as.push(p); as.push(q); toDimacs(file, as); }
+inline void Solver::toDimacs (const char* file, Lit p, Lit q, Lit r){ vec<Lit> as; as.push(p); as.push(q); as.push(r); toDimacs(file, as); }
+
+inline void Solver::addVar(Var v) { while (v >= nVars()) newVar(); }
+
+inline void Solver::sat_solver_set_var_fanin_lit(int v, int lit0, int lit1) { setVarFaninLits( Var(v), toLit(lit0), toLit(lit1) ); }
+inline void Solver::sat_solver_start_new_round() { setNewRound(); }
+inline void Solver::sat_solver_mark_cone(int v) { markCone(v); }
+inline void Solver::sat_solver_set_jftr( int njftr ){ setJust(njftr); }
+inline int Solver::sat_solver_jftr(){ return jftr; }
+inline void Solver::sat_solver_reset(){ justReset(); }
+inline int Solver::solveLimited( int * lit0, int nlits ){
+ assumptions.clear();
+ for(int i = 0; i < nlits; i ++)
+ assumptions.push(toLit(lit0[i]));
+ lbool res = solve_();
+ return res == l_True ? 1 : (res == l_False ? -1 : 0);
+}
+//=================================================================================================
+// Debug etc:
+
+
+inline void Solver::printLit(Lit l)
+{
+ printf("%s%d:%c", sign(l) ? "-" : "", var(l)+1, value(l) == l_True ? '1' : (value(l) == l_False ? '0' : 'X'));
+}
+
+
+inline void Solver::printClause(CRef cr)
+{
+ Clause &c = ca[cr];
+ for (int i = 0; i < c.size(); i++){
+ printLit(c[i]);
+ printf(" ");
+ }
+}
+
+inline void Solver::printInitialClause(CRef cr)
+{
+ Clause &c = ca[cr];
+ for (int i = 0; i < c.size(); i++){
+ if(!isSelector(var(c[i]))) {
+ printLit(c[i]);
+ printf(" ");
+ }
+ }
+}
+
+
+//=================================================================================================
+}
+
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#include "sat/glucose2/CGlucoseCore.h"
+
+#endif
diff --git a/src/sat/glucose2/SolverTypes.h b/src/sat/glucose2/SolverTypes.h
new file mode 100644
index 00000000..c0990226
--- /dev/null
+++ b/src/sat/glucose2/SolverTypes.h
@@ -0,0 +1,450 @@
+/***********************************************************************************[SolverTypes.h]
+ Glucose -- Copyright (c) 2009, Gilles Audemard, Laurent Simon
+ CRIL - Univ. Artois, France
+ LRI - Univ. Paris Sud, France
+
+Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of
+Glucose are exactly the same as Minisat on which it is based on. (see below).
+
+---------------
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+
+#ifndef Glucose_SolverTypes_h
+#define Glucose_SolverTypes_h
+
+#include <assert.h>
+
+#include "sat/glucose2/IntTypes.h"
+#include "sat/glucose2/Alg.h"
+#include "sat/glucose2/Vec.h"
+#include "sat/glucose2/Map.h"
+#include "sat/glucose2/Alloc.h"
+
+#include "sat/glucose2/CGlucose.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// Variables, literals, lifted booleans, clauses:
+
+
+// NOTE! Variables are just integers. No abstraction here. They should be chosen from 0..N,
+// so that they can be used as array indices.
+
+typedef int Var;
+#define var_Undef (-1)
+
+
+struct Lit {
+ int x;
+
+ // Use this as a constructor:
+ friend Lit mkLit(Var var, bool sign);
+ bool operator == (Lit p) const { return x == p.x; }
+ bool operator != (Lit p) const { return x != p.x; }
+ bool operator < (Lit p) const { return x < p.x; } // '<' makes p, ~p adjacent in the ordering.
+};
+
+
+inline Lit mkLit (Var var, bool sign = false) { Lit p; p.x = var + var + (int)sign; return p; }
+inline Lit operator ~(Lit p) { Lit q; q.x = p.x ^ 1; return q; }
+inline Lit operator ^(Lit p, bool b) { Lit q; q.x = p.x ^ (unsigned int)b; return q; }
+inline bool sign (Lit p) { return p.x & 1; }
+inline int var (Lit p) { return p.x >> 1; }
+
+// Mapping Literals to and from compact integers suitable for array indexing:
+inline int toInt (Var v) { return v; }
+inline int toInt (Lit p) { return p.x; }
+inline Lit toLit (int i) { Lit p; p.x = i; return p; }
+
+//const Lit lit_Undef = mkLit(var_Undef, false); // }- Useful special constants.
+//const Lit lit_Error = mkLit(var_Undef, true ); // }
+
+const Lit lit_Undef = { -2 }; // }- Useful special constants.
+const Lit lit_Error = { -1 }; // }
+
+
+//=================================================================================================
+// Lifted booleans:
+//
+// NOTE: this implementation is optimized for the case when comparisons between values are mostly
+// between one variable and one constant. Some care had to be taken to make sure that gcc
+// does enough constant propagation to produce sensible code, and this appears to be somewhat
+// fragile unfortunately.
+
+#define l_True (Gluco2::lbool((uint8_t)0)) // gcc does not do constant propagation if these are real constants.
+#define l_False (Gluco2::lbool((uint8_t)1))
+#define l_Undef (Gluco2::lbool((uint8_t)2))
+
+class lbool {
+ uint8_t value;
+
+public:
+ explicit lbool(uint8_t v) : value(v) { }
+
+ lbool() : value(0) { }
+ explicit lbool(bool x) : value(!x) { }
+
+ bool operator == (lbool b) const { return (((b.value&2) & (value&2)) | (!(b.value&2)&(value == b.value))) != 0; }
+ bool operator != (lbool b) const { return !(*this == b); }
+ lbool operator ^ (bool b) const { return lbool((uint8_t)(value^(uint8_t)b)); }
+
+ lbool operator && (lbool b) const {
+ uint8_t sel = (this->value << 1) | (b.value << 3);
+ uint8_t v = (0xF7F755F4 >> sel) & 3;
+ return lbool(v); }
+
+ lbool operator || (lbool b) const {
+ uint8_t sel = (this->value << 1) | (b.value << 3);
+ uint8_t v = (0xFCFCF400 >> sel) & 3;
+ return lbool(v); }
+
+ friend int toInt (lbool l);
+ friend lbool toLbool(int v);
+};
+inline int toInt (lbool l) { return l.value; }
+inline lbool toLbool(int v) { return lbool((uint8_t)v); }
+
+//=================================================================================================
+// Clause -- a simple class for representing a clause:
+
+class Clause;
+typedef RegionAllocator<uint32_t>::Ref CRef;
+
+class Clause {
+ struct {
+ unsigned mark : 2;
+ unsigned learnt : 1;
+ unsigned has_extra : 1;
+ unsigned reloced : 1;
+ unsigned lbd : 26;
+ unsigned canbedel : 1;
+ unsigned size : 32;
+ unsigned szWithoutSelectors : 32;
+
+ } header;
+ union { Lit lit; float act; uint32_t abs; CRef rel; } data[0];
+
+ friend class ClauseAllocator;
+
+ #ifdef CGLUCOSE_EXP
+ friend class Solver;
+ #endif
+
+ // NOTE: This constructor cannot be used directly (doesn't allocate enough memory).
+ template<class V>
+ Clause(const V& ps, bool use_extra, bool learnt) {
+ header.mark = 0;
+ header.learnt = learnt;
+ header.has_extra = use_extra;
+ header.reloced = 0;
+ header.size = ps.size();
+ header.lbd = 0;
+ header.canbedel = 1;
+ for (int i = 0; i < ps.size(); i++)
+ data[i].lit = ps[i];
+
+ if (header.has_extra){
+ if (header.learnt)
+ data[header.size].act = 0;
+ else
+ calcAbstraction(); }
+ }
+
+public:
+ void calcAbstraction() {
+ assert(header.has_extra);
+ uint32_t abstraction = 0;
+ for (int i = 0; i < size(); i++)
+ abstraction |= 1 << (var(data[i].lit) & 31);
+ data[header.size].abs = abstraction; }
+
+
+ int size () const { return header.size; }
+ void shrink (int i) { assert(i <= size()); if (header.has_extra) data[header.size-i] = data[header.size]; header.size -= i; }
+ void pop () { shrink(1); }
+ bool learnt () const { return header.learnt; }
+ bool has_extra () const { return header.has_extra; }
+ uint32_t mark () const { return header.mark; }
+ void mark (uint32_t m) { header.mark = m; }
+ const Lit& last () const { return data[header.size-1].lit; }
+
+ bool reloced () const { return header.reloced; }
+ CRef relocation () const { return data[0].rel; }
+ void relocate (CRef c) { header.reloced = 1; data[0].rel = c; }
+
+ // NOTE: somewhat unsafe to change the clause in-place! Must manually call 'calcAbstraction' afterwards for
+ // subsumption operations to behave correctly.
+ Lit& operator [] (int i) { return data[i].lit; }
+ Lit operator [] (int i) const { return data[i].lit; }
+ operator const Lit* (void) const { return (Lit*)data; }
+
+ float& activity () { assert(header.has_extra); return data[header.size].act; }
+ uint32_t abstraction () const { assert(header.has_extra); return data[header.size].abs; }
+
+ Lit subsumes (const Clause& other) const;
+ void strengthen (Lit p);
+ void setLBD(int i) {header.lbd = i;}
+ // unsigned int& lbd () { return header.lbd; }
+ unsigned int lbd () const { return header.lbd; }
+ void setCanBeDel(bool b) {header.canbedel = b;}
+ bool canBeDel() {return header.canbedel;}
+ void setSizeWithoutSelectors (unsigned int n) {header.szWithoutSelectors = n; }
+ unsigned int sizeWithoutSelectors () const { return header.szWithoutSelectors; }
+
+};
+
+
+//=================================================================================================
+// ClauseAllocator -- a simple class for allocating memory for clauses:
+
+
+const CRef CRef_Undef = RegionAllocator<uint32_t>::Ref_Undef;
+class ClauseAllocator : public RegionAllocator<uint32_t>
+{
+ static int clauseWord32Size(int size, bool has_extra){
+ return (sizeof(Clause) + (sizeof(Lit) * (size + (int)has_extra))) / sizeof(uint32_t); }
+ public:
+ bool extra_clause_field;
+
+ ClauseAllocator(uint32_t start_cap) : RegionAllocator<uint32_t>(start_cap), extra_clause_field(false){}
+ ClauseAllocator() : extra_clause_field(false){}
+
+ void moveTo(ClauseAllocator& to){
+ to.extra_clause_field = extra_clause_field;
+ RegionAllocator<uint32_t>::moveTo(to); }
+
+ template<class Lits>
+ CRef alloc(const Lits& ps, bool learnt = false)
+ {
+ assert(sizeof(Lit) == sizeof(uint32_t));
+ assert(sizeof(float) == sizeof(uint32_t));
+ bool use_extra = learnt | extra_clause_field;
+
+ CRef cid = RegionAllocator<uint32_t>::alloc(clauseWord32Size(ps.size(), use_extra));
+ new (lea(cid)) Clause(ps, use_extra, learnt);
+
+ return cid;
+ }
+
+ // Deref, Load Effective Address (LEA), Inverse of LEA (AEL):
+ Clause& operator[](Ref r) { return (Clause&)RegionAllocator<uint32_t>::operator[](r); }
+ const Clause& operator[](Ref r) const { return (Clause&)RegionAllocator<uint32_t>::operator[](r); }
+ Clause* lea (Ref r) { return (Clause*)RegionAllocator<uint32_t>::lea(r); }
+ const Clause* lea (Ref r) const { return (Clause*)RegionAllocator<uint32_t>::lea(r); }
+ Ref ael (const Clause* t){ return RegionAllocator<uint32_t>::ael((uint32_t*)t); }
+
+ void free_(CRef cid)
+ {
+ Clause& c = operator[](cid);
+ RegionAllocator<uint32_t>::free_(clauseWord32Size(c.size(), c.has_extra()));
+ }
+
+ void reloc(CRef& cr, ClauseAllocator& to)
+ {
+ Clause& c = operator[](cr);
+
+ if (c.reloced()) { cr = c.relocation(); return; }
+
+ cr = to.alloc(c, c.learnt());
+ c.relocate(cr);
+
+ // Copy extra data-fields:
+ // (This could be cleaned-up. Generalize Clause-constructor to be applicable here instead?)
+ to[cr].mark(c.mark());
+ if (to[cr].learnt()) {
+ to[cr].activity() = c.activity();
+ to[cr].setLBD(c.lbd());
+ to[cr].setSizeWithoutSelectors(c.sizeWithoutSelectors());
+ to[cr].setCanBeDel(c.canBeDel());
+ }
+ else if (to[cr].has_extra()) to[cr].calcAbstraction();
+ }
+};
+
+
+//=================================================================================================
+// OccLists -- a class for maintaining occurence lists with lazy deletion:
+
+template<class Idx, class Vec, class Deleted>
+class OccLists
+{
+ vec<Vec> occs;
+ vec<char> dirty;
+ vec<Idx> dirties;
+ Deleted deleted;
+
+ public:
+ OccLists(const Deleted& d) : deleted(d) {}
+
+ void init (const Idx& idx){ occs.growTo(toInt(idx)+1); dirty.growTo(toInt(idx)+1, 0); }
+ void prelocate (const int num){ occs.prelocate(num); dirty.prelocate(num); }
+ // Vec& operator[](const Idx& idx){ return occs[toInt(idx)]; }
+ Vec& operator[](const Idx& idx){ return occs[toInt(idx)]; }
+ Vec& lookup (const Idx& idx){ if (dirty[toInt(idx)]) clean(idx); return occs[toInt(idx)]; }
+
+ void cleanAll ();
+ void clean (const Idx& idx);
+ void smudge (const Idx& idx){
+ if (dirty[toInt(idx)] == 0){
+ dirty[toInt(idx)] = 1;
+ dirties.push(idx);
+ }
+ }
+
+ void clear(bool free = true){
+ if(free){
+ occs .clear(free);
+ dirty .clear(free);
+ dirties.clear(free);
+ } else {
+ occs .shrink (occs .size());
+ dirty .shrink_(dirty .size());
+ dirties.shrink_(dirties.size());
+ }
+ }
+};
+
+
+template<class Idx, class Vec, class Deleted>
+void OccLists<Idx,Vec,Deleted>::cleanAll()
+{
+ for (int i = 0; i < dirties.size(); i++)
+ // Dirties may contain duplicates so check here if a variable is already cleaned:
+ if (dirty[toInt(dirties[i])])
+ clean(dirties[i]);
+ dirties.shrink_( dirties.size() );
+}
+
+
+template<class Idx, class Vec, class Deleted>
+void OccLists<Idx,Vec,Deleted>::clean(const Idx& idx)
+{
+ Vec& vec = occs[toInt(idx)];
+ int i, j;
+ for (i = j = 0; i < vec.size(); i++)
+ if (!deleted(vec[i]))
+ vec[j++] = vec[i];
+ vec.shrink_(i - j);
+ dirty[toInt(idx)] = 0;
+}
+
+
+//=================================================================================================
+// CMap -- a class for mapping clauses to values:
+
+
+template<class T>
+class CMap
+{
+ struct CRefHash {
+ uint32_t operator()(CRef cr) const { return (uint32_t)cr; } };
+
+ typedef Map<CRef, T, CRefHash> HashTable;
+ HashTable map;
+
+ public:
+ // Size-operations:
+ void clear () { map.clear(); }
+ int size () const { return map.elems(); }
+
+
+ // Insert/Remove/Test mapping:
+ void insert (CRef cr, const T& t){ map.insert(cr, t); }
+ void growTo (CRef cr, const T& t){ map.insert(cr, t); } // NOTE: for compatibility
+ void remove (CRef cr) { map.remove(cr); }
+ bool has (CRef cr, T& t) { return map.peek(cr, t); }
+
+ // Vector interface (the clause 'c' must already exist):
+ const T& operator [] (CRef cr) const { return map[cr]; }
+ T& operator [] (CRef cr) { return map[cr]; }
+
+ // Iteration (not transparent at all at the moment):
+ int bucket_count() const { return map.bucket_count(); }
+ const vec<typename HashTable::Pair>& bucket(int i) const { return map.bucket(i); }
+
+ // Move contents to other map:
+ void moveTo(CMap& other){ map.moveTo(other.map); }
+
+ // TMP debug:
+ void debug(){
+ printf(" --- size = %d, bucket_count = %d\n", size(), map.bucket_count()); }
+};
+
+
+/*_________________________________________________________________________________________________
+|
+| subsumes : (other : const Clause&) -> Lit
+|
+| Description:
+| Checks if clause subsumes 'other', and at the same time, if it can be used to simplify 'other'
+| by subsumption resolution.
+|
+| Result:
+| lit_Error - No subsumption or simplification
+| lit_Undef - Clause subsumes 'other'
+| p - The literal p can be deleted from 'other'
+|________________________________________________________________________________________________@*/
+inline Lit Clause::subsumes(const Clause& other) const
+{
+ //if (other.size() < size() || (extra.abst & ~other.extra.abst) != 0)
+ //if (other.size() < size() || (!learnt() && !other.learnt() && (extra.abst & ~other.extra.abst) != 0))
+ assert(!header.learnt); assert(!other.header.learnt);
+ assert(header.has_extra); assert(other.header.has_extra);
+ if (other.header.size < header.size || (data[header.size].abs & ~other.data[other.header.size].abs) != 0)
+ return lit_Error;
+
+ Lit ret = lit_Undef;
+ const Lit* c = (const Lit*)(*this);
+ const Lit* d = (const Lit*)other;
+
+ for (unsigned i = 0; i < header.size; i++) {
+ // search for c[i] or ~c[i]
+ for (unsigned j = 0; j < other.header.size; j++)
+ if (c[i] == d[j])
+ goto ok;
+ else if (ret == lit_Undef && c[i] == ~d[j]){
+ ret = c[i];
+ goto ok;
+ }
+
+ // did not find it
+ return lit_Error;
+ ok:;
+ }
+
+ return ret;
+}
+
+inline void Clause::strengthen(Lit p)
+{
+ remove(*this, p);
+ calcAbstraction();
+}
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/Sort.h b/src/sat/glucose2/Sort.h
new file mode 100644
index 00000000..6be112ca
--- /dev/null
+++ b/src/sat/glucose2/Sort.h
@@ -0,0 +1,101 @@
+/******************************************************************************************[Sort.h]
+Copyright (c) 2003-2007, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Sort_h
+#define Glucose_Sort_h
+
+#include "sat/glucose2/Vec.h"
+
+//=================================================================================================
+// Some sorting algorithms for vec's
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+template<class T>
+struct LessThan_default {
+ bool operator () (T x, T y) { return x < y; }
+};
+
+
+template <class T, class LessThan>
+void selectionSort(T* array, int size, LessThan lt)
+{
+ int i, j, best_i;
+ T tmp;
+
+ for (i = 0; i < size-1; i++){
+ best_i = i;
+ for (j = i+1; j < size; j++){
+ if (lt(array[j], array[best_i]))
+ best_i = j;
+ }
+ tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp;
+ }
+}
+template <class T> static inline void selectionSort(T* array, int size) {
+ selectionSort(array, size, LessThan_default<T>()); }
+
+template <class T, class LessThan>
+void sort(T* array, int size, LessThan lt)
+{
+ if (size <= 15)
+ selectionSort(array, size, lt);
+
+ else{
+ T pivot = array[size / 2];
+ T tmp;
+ int i = -1;
+ int j = size;
+
+ for(;;){
+ do i++; while(lt(array[i], pivot));
+ do j--; while(lt(pivot, array[j]));
+
+ if (i >= j) break;
+
+ tmp = array[i]; array[i] = array[j]; array[j] = tmp;
+ }
+
+ sort(array , i , lt);
+ sort(&array[i], size-i, lt);
+ }
+}
+template <class T> static inline void sort(T* array, int size) {
+ sort(array, size, LessThan_default<T>()); }
+
+
+//=================================================================================================
+// For 'vec's:
+
+
+template <class T, class LessThan> void sort(vec<T>& v, LessThan lt) {
+ sort((T*)v, v.size(), lt); }
+template <class T> void sort(vec<T>& v) {
+ sort(v, LessThan_default<T>()); }
+
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/System.h b/src/sat/glucose2/System.h
new file mode 100644
index 00000000..088bada5
--- /dev/null
+++ b/src/sat/glucose2/System.h
@@ -0,0 +1,73 @@
+/****************************************************************************************[System.h]
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_System_h
+#define Glucose_System_h
+
+#if defined(__linux__)
+//#include <fpu_control.h>
+#endif
+
+#include "sat/glucose2/IntTypes.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+//-------------------------------------------------------------------------------------------------
+
+namespace Gluco2 {
+
+static inline double cpuTime(void); // CPU-time in seconds.
+extern double memUsed(); // Memory in mega bytes (returns 0 for unsupported architectures).
+extern double memUsedPeak(); // Peak-memory in mega bytes (returns 0 for unsupported architectures).
+
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+//-------------------------------------------------------------------------------------------------
+// Implementation of inline functions:
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+#include <time.h>
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+static inline double Gluco2::cpuTime(void) { return (double)clock() / CLOCKS_PER_SEC; }
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+
+#else
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+static inline double Gluco2::cpuTime(void) {
+ struct rusage ru;
+ getrusage(RUSAGE_SELF, &ru);
+ return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; }
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
+
+#endif
diff --git a/src/sat/glucose2/System2.cpp b/src/sat/glucose2/System2.cpp
new file mode 100644
index 00000000..844220a0
--- /dev/null
+++ b/src/sat/glucose2/System2.cpp
@@ -0,0 +1,116 @@
+/***************************************************************************************[System.cc]
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#include "sat/glucose2/System.h"
+
+#if defined(__linux__)
+
+#include <stdio.h>
+#include <stdlib.h>
+
+ABC_NAMESPACE_IMPL_START
+
+using namespace Gluco2;
+
+// TODO: split the memory reading functions into two: one for reading high-watermark of RSS, and
+// one for reading the current virtual memory size.
+
+static inline int memReadStat(int field)
+{
+ char name[256];
+ pid_t pid = getpid();
+ int value;
+
+ sprintf(name, "/proc/%d/statm", pid);
+ FILE* in = fopen(name, "rb");
+ if (in == NULL) return 0;
+
+ for (; field >= 0; field--)
+ if (fscanf(in, "%d", &value) != 1)
+ printf("ERROR! Failed to parse memory statistics from \"/proc\".\n"), exit(1);
+ fclose(in);
+ return value;
+}
+
+
+static inline int memReadPeak(void)
+{
+ char name[256];
+ pid_t pid = getpid();
+
+ sprintf(name, "/proc/%d/status", pid);
+ FILE* in = fopen(name, "rb");
+ if (in == NULL) return 0;
+
+ // Find the correct line, beginning with "VmPeak:":
+ int peak_kb = 0;
+ while (!feof(in) && fscanf(in, "VmPeak: %d kB", &peak_kb) != 1)
+ while (!feof(in) && fgetc(in) != '\n')
+ ;
+ fclose(in);
+
+ return peak_kb;
+}
+
+double Gluco2::memUsed() { return (double)memReadStat(0) * (double)getpagesize() / (1024*1024); }
+double Gluco2::memUsedPeak() {
+ double peak = memReadPeak() / 1024;
+ return peak == 0 ? memUsed() : peak; }
+
+ABC_NAMESPACE_IMPL_END
+
+#elif defined(__FreeBSD__)
+
+ABC_NAMESPACE_IMPL_START
+
+using namespace Gluco2;
+
+double Gluco2::memUsed(void) {
+ struct rusage ru;
+ getrusage(RUSAGE_SELF, &ru);
+ return (double)ru.ru_maxrss / 1024; }
+double memUsedPeak(void) { return memUsed(); }
+
+ABC_NAMESPACE_IMPL_END
+
+#elif defined(__APPLE__)
+
+#include <malloc/malloc.h>
+
+ABC_NAMESPACE_IMPL_START
+
+double Gluco2::memUsed(void) {
+ malloc_statistics_t t;
+ malloc_zone_statistics(NULL, &t);
+ return (double)t.max_size_in_use / (1024*1024); }
+
+ABC_NAMESPACE_IMPL_END
+
+#else
+
+ABC_NAMESPACE_IMPL_START
+
+double Gluco2::memUsed() {
+ return 0; }
+
+ABC_NAMESPACE_IMPL_END
+
+#endif
+
diff --git a/src/sat/glucose2/Vec.h b/src/sat/glucose2/Vec.h
new file mode 100644
index 00000000..eaeed207
--- /dev/null
+++ b/src/sat/glucose2/Vec.h
@@ -0,0 +1,152 @@
+/*******************************************************************************************[Vec.h]
+Copyright (c) 2003-2007, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+#ifndef Glucose_Vec_h
+#define Glucose_Vec_h
+
+#include <assert.h>
+#include <new>
+
+#include "sat/glucose2/IntTypes.h"
+#include "sat/glucose2/XAlloc.h"
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// Automatically resizable arrays
+//
+// NOTE! Don't use this vector on datatypes that cannot be re-located in memory (with realloc)
+
+template<class T>
+class vec {
+ T* data;
+ int sz;
+ int cap;
+
+ // Don't allow copying (error prone):
+ vec<T>& operator = (vec<T>& other) { assert(0); return *this; }
+ vec (vec<T>& other) { assert(0); }
+
+ // Helpers for calculating next capacity:
+ static inline int imax (int x, int y) { int mask = (y-x) >> (sizeof(int)*8-1); return (x&mask) + (y&(~mask)); }
+ //static inline void nextCap(int& cap){ cap += ((cap >> 1) + 2) & ~1; }
+ static inline void nextCap(int& cap){ cap += ((cap >> 1) + 2) & ~1; }
+
+public:
+ // Constructors:
+ vec() : data(NULL) , sz(0) , cap(0) { }
+ explicit vec(int size) : data(NULL) , sz(0) , cap(0) { growTo(size); }
+ vec(int size, const T& pad) : data(NULL) , sz(0) , cap(0) { growTo(size, pad); }
+ ~vec() { clear(true); }
+
+ // Pointer to first element:
+ operator T* (void) { return data; }
+
+ // Size operations:
+ int size (void) const { return sz; }
+ void shrink (int nelems) { assert(nelems <= sz); for (int i = 0; i < nelems; i++) sz--, data[sz].~T(); }
+ void shrink_ (int nelems) { assert(nelems <= sz); sz -= nelems; }
+ int capacity (void) const { return cap; }
+ void capacity (int min_cap);
+ void prelocate(int ext_cap);
+ void growTo (int size);
+ void growTo_ (int size);
+ void growTo (int size, const T& pad);
+ void clear (bool dealloc = false);
+
+ // Stack interface:
+ void push (void) { if (sz == cap) capacity(sz+1); new (&data[sz]) T(); sz++; }
+ void push (const T& elem) { if (sz == cap) capacity(sz+1); data[sz++] = elem; }
+ void push_ (const T& elem) { assert(sz < cap); data[sz++] = elem; }
+ void pop (void) { assert(sz > 0); sz--, data[sz].~T(); }
+ // NOTE: it seems possible that overflow can happen in the 'sz+1' expression of 'push()', but
+ // in fact it can not since it requires that 'cap' is equal to INT_MAX. This in turn can not
+ // happen given the way capacities are calculated (below). Essentially, all capacities are
+ // even, but INT_MAX is odd.
+
+ const T& last (void) const { return data[sz-1]; }
+ T& last (void) { return data[sz-1]; }
+
+ // Vector interface:
+ const T& operator [] (int index) const { return data[index]; }
+ T& operator [] (int index) { return data[index]; }
+
+ // Duplicatation (preferred instead):
+ void copyTo (vec<T>& copy) const { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
+ void copyTo_(vec<T>& copy) const { copy.shrink_(copy.size()); copy.growTo_(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
+ void moveTo(vec<T>& dest) { dest.clear(true); dest.data = data; dest.sz = sz; dest.cap = cap; data = NULL; sz = 0; cap = 0; }
+};
+
+
+template<class T>
+void vec<T>::capacity(int min_cap) {
+ if (cap >= min_cap) return;
+ int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2
+ if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM))
+ throw OutOfMemoryException();
+ }
+
+template<class T>
+void vec<T>::prelocate(int ext_cap) {
+ if (cap >= ext_cap) return;
+ if (ext_cap > INT_MAX || (((data = (T*)::realloc(data, ext_cap * sizeof(T))) == NULL) && errno == ENOMEM))
+ throw OutOfMemoryException();
+ cap = ext_cap;
+ }
+
+
+template<class T>
+void vec<T>::growTo(int size, const T& pad) {
+ if (sz >= size) return;
+ capacity(size);
+ for (int i = sz; i < size; i++) data[i] = pad;
+ sz = size; }
+
+
+template<class T>
+void vec<T>::growTo(int size) {
+ if (sz >= size) return;
+ capacity(size);
+ for (int i = sz; i < size; i++) new (&data[i]) T();
+ sz = size; }
+
+
+template<class T>
+void vec<T>::growTo_(int size) {
+ if (sz >= size) return;
+ capacity(size);
+ sz = size; }
+
+
+template<class T>
+void vec<T>::clear(bool dealloc) {
+ if (data != NULL){
+ for (int i = 0; i < sz; i++) data[i].~T();
+ sz = 0;
+ if (dealloc) free(data), data = NULL, cap = 0; } }
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/XAlloc.h b/src/sat/glucose2/XAlloc.h
new file mode 100644
index 00000000..716643ef
--- /dev/null
+++ b/src/sat/glucose2/XAlloc.h
@@ -0,0 +1,53 @@
+/****************************************************************************************[XAlloc.h]
+Copyright (c) 2009-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**************************************************************************************************/
+
+
+#ifndef Glucose_XAlloc_h
+#define Glucose_XAlloc_h
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <misc/util/abc_namespaces.h>
+
+ABC_NAMESPACE_CXX_HEADER_START
+
+namespace Gluco2 {
+
+//=================================================================================================
+// Simple layer on top of malloc/realloc to catch out-of-memory situtaions and provide some typing:
+
+class OutOfMemoryException{};
+static inline void* xrealloc(void *ptr, size_t size)
+{
+ void* mem = realloc(ptr, size);
+ if (mem == NULL && errno == ENOMEM){
+ throw OutOfMemoryException();
+ }else {
+ return mem;
+ }
+}
+
+//=================================================================================================
+}
+
+ABC_NAMESPACE_CXX_HEADER_END
+
+#endif
diff --git a/src/sat/glucose2/license b/src/sat/glucose2/license
new file mode 100644
index 00000000..04ed174b
--- /dev/null
+++ b/src/sat/glucose2/license
@@ -0,0 +1,32 @@
+---------------
+
+Glucose -- Copyright (c) 2013, Gilles Audemard, Laurent Simon
+ CRIL - Univ. Artois, France
+ LRI - Univ. Paris Sud, France
+
+Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions
+and copyrights of Glucose are exactly the same as Minisat on which it is based
+on. (see below).
+
+---------------
+
+Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
+Copyright (c) 2007-2010, Niklas Sorensson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
+Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*******************************************************************************/ \ No newline at end of file
diff --git a/src/sat/glucose2/module.make b/src/sat/glucose2/module.make
new file mode 100644
index 00000000..c23cdc53
--- /dev/null
+++ b/src/sat/glucose2/module.make
@@ -0,0 +1,6 @@
+SRC += src/sat/glucose2/AbcGlucose2.cpp \
+ src/sat/glucose2/AbcGlucoseCmd2.cpp \
+ src/sat/glucose2/Glucose2.cpp \
+ src/sat/glucose2/Options2.cpp \
+ src/sat/glucose2/SimpSolver2.cpp \
+ src/sat/glucose2/System2.cpp
diff --git a/src/sat/glucose2/pstdint.h b/src/sat/glucose2/pstdint.h
new file mode 100644
index 00000000..989d0169
--- /dev/null
+++ b/src/sat/glucose2/pstdint.h
@@ -0,0 +1,919 @@
+/* A portable stdint.h
+ ****************************************************************************
+ * BSD License:
+ ****************************************************************************
+ *
+ * Copyright (c) 2005-2016 Paul Hsieh
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************
+ *
+ * Version 0.1.16.0
+ *
+ * The ANSI C standard committee, for the C99 standard, specified the
+ * inclusion of a new standard include file called stdint.h. This is
+ * a very useful and long desired include file which contains several
+ * very precise definitions for integer scalar types that is critically
+ * important for making several classes of applications portable
+ * including cryptography, hashing, variable length integer libraries
+ * and so on. But for most developers its likely useful just for
+ * programming sanity.
+ *
+ * The problem is that some compiler vendors chose to ignore the C99
+ * standard and some older compilers have no opportunity to be updated.
+ * Because of this situation, simply including stdint.h in your code
+ * makes it unportable.
+ *
+ * So that's what this file is all about. It's an attempt to build a
+ * single universal include file that works on as many platforms as
+ * possible to deliver what stdint.h is supposed to. Even compilers
+ * that already come with stdint.h can use this file instead without
+ * any loss of functionality. A few things that should be noted about
+ * this file:
+ *
+ * 1) It is not guaranteed to be portable and/or present an identical
+ * interface on all platforms. The extreme variability of the
+ * ANSI C standard makes this an impossibility right from the
+ * very get go. Its really only meant to be useful for the vast
+ * majority of platforms that possess the capability of
+ * implementing usefully and precisely defined, standard sized
+ * integer scalars. Systems which are not intrinsically 2s
+ * complement may produce invalid constants.
+ *
+ * 2) There is an unavoidable use of non-reserved symbols.
+ *
+ * 3) Other standard include files are invoked.
+ *
+ * 4) This file may come in conflict with future platforms that do
+ * include stdint.h. The hope is that one or the other can be
+ * used with no real difference.
+ *
+ * 5) In the current version, if your platform can't represent
+ * int32_t, int16_t and int8_t, it just dumps out with a compiler
+ * error.
+ *
+ * 6) 64 bit integers may or may not be defined. Test for their
+ * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
+ * Note that this is different from the C99 specification which
+ * requires the existence of 64 bit support in the compiler. If
+ * this is not defined for your platform, yet it is capable of
+ * dealing with 64 bits then it is because this file has not yet
+ * been extended to cover all of your system's capabilities.
+ *
+ * 7) (u)intptr_t may or may not be defined. Test for its presence
+ * with the test: #ifdef PTRDIFF_MAX. If this is not defined
+ * for your platform, then it is because this file has not yet
+ * been extended to cover all of your system's capabilities, not
+ * because its optional.
+ *
+ * 8) The following might not been defined even if your platform is
+ * capable of defining it:
+ *
+ * WCHAR_MIN
+ * WCHAR_MAX
+ * (u)int64_t
+ * PTRDIFF_MIN
+ * PTRDIFF_MAX
+ * (u)intptr_t
+ *
+ * 9) The following have not been defined:
+ *
+ * WINT_MIN
+ * WINT_MAX
+ *
+ * 10) The criteria for defining (u)int_least(*)_t isn't clear,
+ * except for systems which don't have a type that precisely
+ * defined 8, 16, or 32 bit types (which this include file does
+ * not support anyways). Default definitions have been given.
+ *
+ * 11) The criteria for defining (u)int_fast(*)_t isn't something I
+ * would trust to any particular compiler vendor or the ANSI C
+ * committee. It is well known that "compatible systems" are
+ * commonly created that have very different performance
+ * characteristics from the systems they are compatible with,
+ * especially those whose vendors make both the compiler and the
+ * system. Default definitions have been given, but its strongly
+ * recommended that users never use these definitions for any
+ * reason (they do *NOT* deliver any serious guarantee of
+ * improved performance -- not in this file, nor any vendor's
+ * stdint.h).
+ *
+ * 12) The following macros:
+ *
+ * PRINTF_INTMAX_MODIFIER
+ * PRINTF_INT64_MODIFIER
+ * PRINTF_INT32_MODIFIER
+ * PRINTF_INT16_MODIFIER
+ * PRINTF_LEAST64_MODIFIER
+ * PRINTF_LEAST32_MODIFIER
+ * PRINTF_LEAST16_MODIFIER
+ * PRINTF_INTPTR_MODIFIER
+ *
+ * are strings which have been defined as the modifiers required
+ * for the "d", "u" and "x" printf formats to correctly output
+ * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
+ * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
+ * PRINTF_INTPTR_MODIFIER is not defined for some systems which
+ * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
+ * defined if INT64_MAX is not defined. These are an extension
+ * beyond what C99 specifies must be in stdint.h.
+ *
+ * In addition, the following macros are defined:
+ *
+ * PRINTF_INTMAX_HEX_WIDTH
+ * PRINTF_INT64_HEX_WIDTH
+ * PRINTF_INT32_HEX_WIDTH
+ * PRINTF_INT16_HEX_WIDTH
+ * PRINTF_INT8_HEX_WIDTH
+ * PRINTF_INTMAX_DEC_WIDTH
+ * PRINTF_INT64_DEC_WIDTH
+ * PRINTF_INT32_DEC_WIDTH
+ * PRINTF_INT16_DEC_WIDTH
+ * PRINTF_UINT8_DEC_WIDTH
+ * PRINTF_UINTMAX_DEC_WIDTH
+ * PRINTF_UINT64_DEC_WIDTH
+ * PRINTF_UINT32_DEC_WIDTH
+ * PRINTF_UINT16_DEC_WIDTH
+ * PRINTF_UINT8_DEC_WIDTH
+ *
+ * Which specifies the maximum number of characters required to
+ * print the number of that type in either hexadecimal or decimal.
+ * These are an extension beyond what C99 specifies must be in
+ * stdint.h.
+ *
+ * Compilers tested (all with 0 warnings at their highest respective
+ * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
+ * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
+ * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
+ *
+ * This file should be considered a work in progress. Suggestions for
+ * improvements, especially those which increase coverage are strongly
+ * encouraged.
+ *
+ * Acknowledgements
+ *
+ * The following people have made significant contributions to the
+ * development and testing of this file:
+ *
+ * Chris Howie
+ * John Steele Scott
+ * Dave Thorup
+ * John Dill
+ * Florian Wobbe
+ * Christopher Sean Morrison
+ * Mikkel Fahnoe Jorgensen
+ *
+ */
+
+#include <stddef.h>
+#include <limits.h>
+#include <signal.h>
+
+/*
+ * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
+ * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
+ */
+
+#if ((defined(__SUNPRO_C) && __SUNPRO_C >= 0x570) || (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED)
+#include <stdint.h>
+#define _PSTDINT_H_INCLUDED
+# if defined(__GNUC__) && (defined(__x86_64__) || defined(__ppc64__)) && !(defined(__APPLE__) && defined(__MACH__))
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "l"
+# endif
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+# else
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "ll"
+# endif
+# ifndef PRINTF_INT32_MODIFIER
+# if (UINT_MAX == UINT32_MAX)
+# define PRINTF_INT32_MODIFIER ""
+# else
+# define PRINTF_INT32_MODIFIER "l"
+# endif
+# endif
+# endif
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER "h"
+# endif
+# ifndef PRINTF_INTMAX_MODIFIER
+# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
+# endif
+# ifndef PRINTF_INT64_HEX_WIDTH
+# define PRINTF_INT64_HEX_WIDTH "16"
+# endif
+# ifndef PRINTF_UINT64_HEX_WIDTH
+# define PRINTF_UINT64_HEX_WIDTH "16"
+# endif
+# ifndef PRINTF_INT32_HEX_WIDTH
+# define PRINTF_INT32_HEX_WIDTH "8"
+# endif
+# ifndef PRINTF_UINT32_HEX_WIDTH
+# define PRINTF_UINT32_HEX_WIDTH "8"
+# endif
+# ifndef PRINTF_INT16_HEX_WIDTH
+# define PRINTF_INT16_HEX_WIDTH "4"
+# endif
+# ifndef PRINTF_UINT16_HEX_WIDTH
+# define PRINTF_UINT16_HEX_WIDTH "4"
+# endif
+# ifndef PRINTF_INT8_HEX_WIDTH
+# define PRINTF_INT8_HEX_WIDTH "2"
+# endif
+# ifndef PRINTF_UINT8_HEX_WIDTH
+# define PRINTF_UINT8_HEX_WIDTH "2"
+# endif
+# ifndef PRINTF_INT64_DEC_WIDTH
+# define PRINTF_INT64_DEC_WIDTH "19"
+# endif
+# ifndef PRINTF_UINT64_DEC_WIDTH
+# define PRINTF_UINT64_DEC_WIDTH "20"
+# endif
+# ifndef PRINTF_INT32_DEC_WIDTH
+# define PRINTF_INT32_DEC_WIDTH "10"
+# endif
+# ifndef PRINTF_UINT32_DEC_WIDTH
+# define PRINTF_UINT32_DEC_WIDTH "10"
+# endif
+# ifndef PRINTF_INT16_DEC_WIDTH
+# define PRINTF_INT16_DEC_WIDTH "5"
+# endif
+# ifndef PRINTF_UINT16_DEC_WIDTH
+# define PRINTF_UINT16_DEC_WIDTH "5"
+# endif
+# ifndef PRINTF_INT8_DEC_WIDTH
+# define PRINTF_INT8_DEC_WIDTH "3"
+# endif
+# ifndef PRINTF_UINT8_DEC_WIDTH
+# define PRINTF_UINT8_DEC_WIDTH "3"
+# endif
+# ifndef PRINTF_INTMAX_HEX_WIDTH
+# define PRINTF_INTMAX_HEX_WIDTH PRINTF_UINT64_HEX_WIDTH
+# endif
+# ifndef PRINTF_UINTMAX_HEX_WIDTH
+# define PRINTF_UINTMAX_HEX_WIDTH PRINTF_UINT64_HEX_WIDTH
+# endif
+# ifndef PRINTF_INTMAX_DEC_WIDTH
+# define PRINTF_INTMAX_DEC_WIDTH PRINTF_UINT64_DEC_WIDTH
+# endif
+# ifndef PRINTF_UINTMAX_DEC_WIDTH
+# define PRINTF_UINTMAX_DEC_WIDTH PRINTF_UINT64_DEC_WIDTH
+# endif
+
+/*
+ * Something really weird is going on with Open Watcom. Just pull some of
+ * these duplicated definitions from Open Watcom's stdint.h file for now.
+ */
+
+# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
+# if !defined (INT64_C)
+# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
+# endif
+# if !defined (UINT64_C)
+# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
+# endif
+# if !defined (INT32_C)
+# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
+# endif
+# if !defined (UINT32_C)
+# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
+# endif
+# if !defined (INT16_C)
+# define INT16_C(x) (x)
+# endif
+# if !defined (UINT16_C)
+# define UINT16_C(x) (x)
+# endif
+# if !defined (INT8_C)
+# define INT8_C(x) (x)
+# endif
+# if !defined (UINT8_C)
+# define UINT8_C(x) (x)
+# endif
+# if !defined (UINT64_MAX)
+# define UINT64_MAX 18446744073709551615ULL
+# endif
+# if !defined (INT64_MAX)
+# define INT64_MAX 9223372036854775807LL
+# endif
+# if !defined (UINT32_MAX)
+# define UINT32_MAX 4294967295UL
+# endif
+# if !defined (INT32_MAX)
+# define INT32_MAX 2147483647L
+# endif
+# if !defined (INTMAX_MAX)
+# define INTMAX_MAX INT64_MAX
+# endif
+# if !defined (INTMAX_MIN)
+# define INTMAX_MIN INT64_MIN
+# endif
+# endif
+#endif
+
+/*
+ * I have no idea what is the truly correct thing to do on older Solaris.
+ * From some online discussions, this seems to be what is being
+ * recommended. For people who actually are developing on older Solaris,
+ * what I would like to know is, does this define all of the relevant
+ * macros of a complete stdint.h? Remember, in pstdint.h 64 bit is
+ * considered optional.
+ */
+
+#if (defined(__SUNPRO_C) && __SUNPRO_C >= 0x420) && !defined(_PSTDINT_H_INCLUDED)
+#include <sys/inttypes.h>
+#define _PSTDINT_H_INCLUDED
+#endif
+
+#ifndef _PSTDINT_H_INCLUDED
+#define _PSTDINT_H_INCLUDED
+
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t)-1)
+#endif
+
+/*
+ * Deduce the type assignments from limits.h under the assumption that
+ * integer sizes in bits are powers of 2, and follow the ANSI
+ * definitions.
+ */
+
+#ifndef UINT8_MAX
+# define UINT8_MAX 0xff
+#endif
+#if !defined(uint8_t) && !defined(_UINT8_T) && !defined(vxWorks)
+# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
+ typedef unsigned char uint8_t;
+# define UINT8_C(v) ((uint8_t) v)
+# else
+# error "Platform not supported"
+# endif
+#endif
+
+#ifndef INT8_MAX
+# define INT8_MAX 0x7f
+#endif
+#ifndef INT8_MIN
+# define INT8_MIN INT8_C(0x80)
+#endif
+#if !defined(int8_t) && !defined(_INT8_T) && !defined(vxWorks)
+# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
+ typedef signed char int8_t;
+# define INT8_C(v) ((int8_t) v)
+# else
+# error "Platform not supported"
+# endif
+#endif
+
+#ifndef UINT16_MAX
+# define UINT16_MAX 0xffff
+#endif
+#if !defined(uint16_t) && !defined(_UINT16_T) && !defined(vxWorks)
+#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
+ typedef unsigned int uint16_t;
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER ""
+# endif
+# define UINT16_C(v) ((uint16_t) (v))
+#elif (USHRT_MAX == UINT16_MAX)
+ typedef unsigned short uint16_t;
+# define UINT16_C(v) ((uint16_t) (v))
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER "h"
+# endif
+#else
+#error "Platform not supported"
+#endif
+#endif
+
+#ifndef INT16_MAX
+# define INT16_MAX 0x7fff
+#endif
+#ifndef INT16_MIN
+# define INT16_MIN INT16_C(0x8000)
+#endif
+#if !defined(int16_t) && !defined(_INT16_T) && !defined(vxWorks)
+#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
+ typedef signed int int16_t;
+# define INT16_C(v) ((int16_t) (v))
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER ""
+# endif
+#elif (SHRT_MAX == INT16_MAX)
+ typedef signed short int16_t;
+# define INT16_C(v) ((int16_t) (v))
+# ifndef PRINTF_INT16_MODIFIER
+# define PRINTF_INT16_MODIFIER "h"
+# endif
+#else
+#error "Platform not supported"
+#endif
+#endif
+
+#ifndef UINT32_MAX
+# define UINT32_MAX (0xffffffffUL)
+#endif
+#if !defined(uint32_t) && !defined(_UINT32_T) && !defined(vxWorks)
+#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
+ typedef unsigned long uint32_t;
+# define UINT32_C(v) v ## UL
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER "l"
+# endif
+#elif (UINT_MAX == UINT32_MAX)
+ typedef unsigned int uint32_t;
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+# define UINT32_C(v) v ## U
+#elif (USHRT_MAX == UINT32_MAX)
+ typedef unsigned short uint32_t;
+# define UINT32_C(v) ((unsigned short) (v))
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+#else
+#error "Platform not supported"
+#endif
+#endif
+
+#ifndef INT32_MAX
+# define INT32_MAX (0x7fffffffL)
+#endif
+#ifndef INT32_MIN
+# define INT32_MIN INT32_C(0x80000000)
+#endif
+#if !defined(int32_t) && !defined(_INT32_T) && !defined(vxWorks)
+#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
+ typedef signed long int32_t;
+# define INT32_C(v) v ## L
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER "l"
+# endif
+#elif (INT_MAX == INT32_MAX)
+ typedef signed int int32_t;
+# define INT32_C(v) v
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+#elif (SHRT_MAX == INT32_MAX)
+ typedef signed short int32_t;
+# define INT32_C(v) ((short) (v))
+# ifndef PRINTF_INT32_MODIFIER
+# define PRINTF_INT32_MODIFIER ""
+# endif
+#else
+#error "Platform not supported"
+#endif
+#endif
+
+/*
+ * The macro stdint_int64_defined is temporarily used to record
+ * whether or not 64 integer support is available. It must be
+ * defined for any 64 integer extensions for new platforms that are
+ * added.
+ */
+
+#undef stdint_int64_defined
+#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
+# if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
+# define stdint_int64_defined
+ typedef long long int64_t;
+ typedef unsigned long long uint64_t;
+# define UINT64_C(v) v ## ULL
+# define INT64_C(v) v ## LL
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "ll"
+# endif
+# endif
+#endif
+
+#if !defined (stdint_int64_defined)
+# if defined(__GNUC__) && !defined(vxWorks)
+# define stdint_int64_defined
+ __extension__ typedef long long int64_t;
+ __extension__ typedef unsigned long long uint64_t;
+# define UINT64_C(v) v ## ULL
+# define INT64_C(v) v ## LL
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "ll"
+# endif
+# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
+# define stdint_int64_defined
+ typedef long long int64_t;
+ typedef unsigned long long uint64_t;
+# define UINT64_C(v) v ## ULL
+# define INT64_C(v) v ## LL
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "ll"
+# endif
+# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
+# define stdint_int64_defined
+ typedef __int64 int64_t;
+ typedef unsigned __int64 uint64_t;
+# define UINT64_C(v) v ## UI64
+# define INT64_C(v) v ## I64
+# ifndef PRINTF_INT64_MODIFIER
+# define PRINTF_INT64_MODIFIER "I64"
+# endif
+# endif
+#endif
+
+#if !defined (LONG_LONG_MAX) && defined (INT64_C)
+# define LONG_LONG_MAX INT64_C (9223372036854775807)
+#endif
+#ifndef ULONG_LONG_MAX
+# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
+#endif
+
+#if !defined (INT64_MAX) && defined (INT64_C)
+# define INT64_MAX INT64_C (9223372036854775807)
+#endif
+#if !defined (INT64_MIN) && defined (INT64_C)
+# define INT64_MIN INT64_C (-9223372036854775808)
+#endif
+#if !defined (UINT64_MAX) && defined (INT64_C)
+# define UINT64_MAX UINT64_C (18446744073709551615)
+#endif
+
+/*
+ * Width of hexadecimal for number field.
+ */
+
+#ifndef PRINTF_INT64_HEX_WIDTH
+# define PRINTF_INT64_HEX_WIDTH "16"
+#endif
+#ifndef PRINTF_INT32_HEX_WIDTH
+# define PRINTF_INT32_HEX_WIDTH "8"
+#endif
+#ifndef PRINTF_INT16_HEX_WIDTH
+# define PRINTF_INT16_HEX_WIDTH "4"
+#endif
+#ifndef PRINTF_INT8_HEX_WIDTH
+# define PRINTF_INT8_HEX_WIDTH "2"
+#endif
+#ifndef PRINTF_INT64_DEC_WIDTH
+# define PRINTF_INT64_DEC_WIDTH "19"
+#endif
+#ifndef PRINTF_INT32_DEC_WIDTH
+# define PRINTF_INT32_DEC_WIDTH "10"
+#endif
+#ifndef PRINTF_INT16_DEC_WIDTH
+# define PRINTF_INT16_DEC_WIDTH "5"
+#endif
+#ifndef PRINTF_INT8_DEC_WIDTH
+# define PRINTF_INT8_DEC_WIDTH "3"
+#endif
+#ifndef PRINTF_UINT64_DEC_WIDTH
+# define PRINTF_UINT64_DEC_WIDTH "20"
+#endif
+#ifndef PRINTF_UINT32_DEC_WIDTH
+# define PRINTF_UINT32_DEC_WIDTH "10"
+#endif
+#ifndef PRINTF_UINT16_DEC_WIDTH
+# define PRINTF_UINT16_DEC_WIDTH "5"
+#endif
+#ifndef PRINTF_UINT8_DEC_WIDTH
+# define PRINTF_UINT8_DEC_WIDTH "3"
+#endif
+
+/*
+ * Ok, lets not worry about 128 bit integers for now. Moore's law says
+ * we don't need to worry about that until about 2040 at which point
+ * we'll have bigger things to worry about.
+ */
+
+#ifdef stdint_int64_defined
+ typedef int64_t intmax_t;
+ typedef uint64_t uintmax_t;
+# define INTMAX_MAX INT64_MAX
+# define INTMAX_MIN INT64_MIN
+# define UINTMAX_MAX UINT64_MAX
+# define UINTMAX_C(v) UINT64_C(v)
+# define INTMAX_C(v) INT64_C(v)
+# ifndef PRINTF_INTMAX_MODIFIER
+# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
+# endif
+# ifndef PRINTF_INTMAX_HEX_WIDTH
+# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
+# endif
+# ifndef PRINTF_INTMAX_DEC_WIDTH
+# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
+# endif
+#else
+ typedef int32_t intmax_t;
+ typedef uint32_t uintmax_t;
+# define INTMAX_MAX INT32_MAX
+# define UINTMAX_MAX UINT32_MAX
+# define UINTMAX_C(v) UINT32_C(v)
+# define INTMAX_C(v) INT32_C(v)
+# ifndef PRINTF_INTMAX_MODIFIER
+# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
+# endif
+# ifndef PRINTF_INTMAX_HEX_WIDTH
+# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
+# endif
+# ifndef PRINTF_INTMAX_DEC_WIDTH
+# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
+# endif
+#endif
+
+/*
+ * Because this file currently only supports platforms which have
+ * precise powers of 2 as bit sizes for the default integers, the
+ * least definitions are all trivial. Its possible that a future
+ * version of this file could have different definitions.
+ */
+
+#ifndef stdint_least_defined
+ typedef int8_t int_least8_t;
+ typedef uint8_t uint_least8_t;
+ typedef int16_t int_least16_t;
+ typedef uint16_t uint_least16_t;
+ typedef int32_t int_least32_t;
+ typedef uint32_t uint_least32_t;
+# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
+# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
+# define UINT_LEAST8_MAX UINT8_MAX
+# define INT_LEAST8_MAX INT8_MAX
+# define UINT_LEAST16_MAX UINT16_MAX
+# define INT_LEAST16_MAX INT16_MAX
+# define UINT_LEAST32_MAX UINT32_MAX
+# define INT_LEAST32_MAX INT32_MAX
+# define INT_LEAST8_MIN INT8_MIN
+# define INT_LEAST16_MIN INT16_MIN
+# define INT_LEAST32_MIN INT32_MIN
+# ifdef stdint_int64_defined
+ typedef int64_t int_least64_t;
+ typedef uint64_t uint_least64_t;
+# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
+# define UINT_LEAST64_MAX UINT64_MAX
+# define INT_LEAST64_MAX INT64_MAX
+# define INT_LEAST64_MIN INT64_MIN
+# endif
+#endif
+#undef stdint_least_defined
+
+/*
+ * The ANSI C committee has defined *int*_fast*_t types as well. This,
+ * of course, defies rationality -- you can't know what will be fast
+ * just from the type itself. Even for a given architecture, compatible
+ * implementations might have different performance characteristics.
+ * Developers are warned to stay away from these types when using this
+ * or any other stdint.h.
+ */
+
+typedef int_least8_t int_fast8_t;
+typedef uint_least8_t uint_fast8_t;
+typedef int_least16_t int_fast16_t;
+typedef uint_least16_t uint_fast16_t;
+typedef int_least32_t int_fast32_t;
+typedef uint_least32_t uint_fast32_t;
+#define UINT_FAST8_MAX UINT_LEAST8_MAX
+#define INT_FAST8_MAX INT_LEAST8_MAX
+#define UINT_FAST16_MAX UINT_LEAST16_MAX
+#define INT_FAST16_MAX INT_LEAST16_MAX
+#define UINT_FAST32_MAX UINT_LEAST32_MAX
+#define INT_FAST32_MAX INT_LEAST32_MAX
+#define INT_FAST8_MIN INT_LEAST8_MIN
+#define INT_FAST16_MIN INT_LEAST16_MIN
+#define INT_FAST32_MIN INT_LEAST32_MIN
+#ifdef stdint_int64_defined
+ typedef int_least64_t int_fast64_t;
+ typedef uint_least64_t uint_fast64_t;
+# define UINT_FAST64_MAX UINT_LEAST64_MAX
+# define INT_FAST64_MAX INT_LEAST64_MAX
+# define INT_FAST64_MIN INT_LEAST64_MIN
+#endif
+
+#undef stdint_int64_defined
+
+/*
+ * Whatever piecemeal, per compiler thing we can do about the wchar_t
+ * type limits.
+ */
+
+#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__) && !defined(vxWorks)
+# include <wchar.h>
+# ifndef WCHAR_MIN
+# define WCHAR_MIN 0
+# endif
+# ifndef WCHAR_MAX
+# define WCHAR_MAX ((wchar_t)-1)
+# endif
+#endif
+
+/*
+ * Whatever piecemeal, per compiler/platform thing we can do about the
+ * (u)intptr_t types and limits.
+ */
+
+#if (defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)) || defined (_UINTPTR_T)
+# define STDINT_H_UINTPTR_T_DEFINED
+#endif
+
+#ifndef STDINT_H_UINTPTR_T_DEFINED
+# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64) || defined (__ppc64__)
+# define stdint_intptr_bits 64
+# elif defined (__WATCOMC__) || defined (__TURBOC__)
+# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
+# define stdint_intptr_bits 16
+# else
+# define stdint_intptr_bits 32
+# endif
+# elif defined (__i386__) || defined (_WIN32) || defined (WIN32) || defined (__ppc64__)
+# define stdint_intptr_bits 32
+# elif defined (__INTEL_COMPILER)
+/* TODO -- what did Intel do about x86-64? */
+# else
+/* #error "This platform might not be supported yet" */
+# endif
+
+# ifdef stdint_intptr_bits
+# define stdint_intptr_glue3_i(a,b,c) a##b##c
+# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
+# ifndef PRINTF_INTPTR_MODIFIER
+# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
+# endif
+# ifndef PTRDIFF_MAX
+# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
+# endif
+# ifndef PTRDIFF_MIN
+# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
+# endif
+# ifndef UINTPTR_MAX
+# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
+# endif
+# ifndef INTPTR_MAX
+# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
+# endif
+# ifndef INTPTR_MIN
+# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
+# endif
+# ifndef INTPTR_C
+# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
+# endif
+# ifndef UINTPTR_C
+# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
+# endif
+ typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
+ typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
+# else
+/* TODO -- This following is likely wrong for some platforms, and does
+ nothing for the definition of uintptr_t. */
+ typedef ptrdiff_t intptr_t;
+# endif
+# define STDINT_H_UINTPTR_T_DEFINED
+#endif
+
+/*
+ * Assumes sig_atomic_t is signed and we have a 2s complement machine.
+ */
+
+#ifndef SIG_ATOMIC_MAX
+# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
+#endif
+
+#endif
+
+#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
+
+/*
+ * Please compile with the maximum warning settings to make sure macros are
+ * not defined more than once.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define glue3_aux(x,y,z) x ## y ## z
+#define glue3(x,y,z) glue3_aux(x,y,z)
+
+#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,) = glue3(UINT,bits,_C) (0);
+#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,) = glue3(INT,bits,_C) (0);
+
+#define DECL(us,bits) glue3(DECL,us,) (bits)
+
+#define TESTUMAX(bits) glue3(u,bits,) = ~glue3(u,bits,); if (glue3(UINT,bits,_MAX) != glue3(u,bits,)) printf ("Something wrong with UINT%d_MAX\n", bits)
+
+#define REPORTERROR(msg) { err_n++; if (err_first <= 0) err_first = __LINE__; printf msg; }
+
+#define X_SIZE_MAX ((size_t)-1)
+
+int main () {
+ int err_n = 0;
+ int err_first = 0;
+ DECL(I,8)
+ DECL(U,8)
+ DECL(I,16)
+ DECL(U,16)
+ DECL(I,32)
+ DECL(U,32)
+#ifdef INT64_MAX
+ DECL(I,64)
+ DECL(U,64)
+#endif
+ intmax_t imax = INTMAX_C(0);
+ uintmax_t umax = UINTMAX_C(0);
+ char str0[256], str1[256];
+
+ sprintf (str0, "%" PRINTF_INT32_MODIFIER "d", INT32_C(2147483647));
+ if (0 != strcmp (str0, "2147483647")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0));
+ if (atoi(PRINTF_INT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_INT32_DEC_WIDTH : %s\n", PRINTF_INT32_DEC_WIDTH));
+ sprintf (str0, "%" PRINTF_INT32_MODIFIER "u", UINT32_C(4294967295));
+ if (0 != strcmp (str0, "4294967295")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0));
+ if (atoi(PRINTF_UINT32_DEC_WIDTH) != (int) strlen(str0)) REPORTERROR (("Something wrong with PRINTF_UINT32_DEC_WIDTH : %s\n", PRINTF_UINT32_DEC_WIDTH));
+#ifdef INT64_MAX
+ sprintf (str1, "%" PRINTF_INT64_MODIFIER "d", INT64_C(9223372036854775807));
+ if (0 != strcmp (str1, "9223372036854775807")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1));
+ if (atoi(PRINTF_INT64_DEC_WIDTH) != (int) strlen(str1)) REPORTERROR (("Something wrong with PRINTF_INT64_DEC_WIDTH : %s, %d\n", PRINTF_INT64_DEC_WIDTH, (int) strlen(str1)));
+ sprintf (str1, "%" PRINTF_INT64_MODIFIER "u", UINT64_C(18446744073709550591));
+ if (0 != strcmp (str1, "18446744073709550591")) REPORTERROR (("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1));
+ if (atoi(PRINTF_UINT64_DEC_WIDTH) != (int) strlen(str1)) REPORTERROR (("Something wrong with PRINTF_UINT64_DEC_WIDTH : %s, %d\n", PRINTF_UINT64_DEC_WIDTH, (int) strlen(str1)));
+#endif
+
+ sprintf (str0, "%d %x\n", 0, ~0);
+
+ sprintf (str1, "%d %x\n", i8, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i8 : %s\n", str1));
+ sprintf (str1, "%u %x\n", u8, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u8 : %s\n", str1));
+ sprintf (str1, "%d %x\n", i16, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i16 : %s\n", str1));
+ sprintf (str1, "%u %x\n", u16, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u16 : %s\n", str1));
+ sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i32 : %s\n", str1));
+ sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with u32 : %s\n", str1));
+#ifdef INT64_MAX
+ sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with i64 : %s\n", str1));
+#endif
+ sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with imax : %s\n", str1));
+ sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
+ if (0 != strcmp (str0, str1)) REPORTERROR (("Something wrong with umax : %s\n", str1));
+
+ TESTUMAX(8);
+ TESTUMAX(16);
+ TESTUMAX(32);
+#ifdef INT64_MAX
+ TESTUMAX(64);
+#endif
+
+#define STR(v) #v
+#define Q(v) printf ("sizeof " STR(v) " = %u\n", (unsigned) sizeof (v));
+ if (err_n) {
+ printf ("pstdint.h is not correct. Please use sizes below to correct it:\n");
+ }
+
+ Q(int)
+ Q(unsigned)
+ Q(long int)
+ Q(short int)
+ Q(int8_t)
+ Q(int16_t)
+ Q(int32_t)
+#ifdef INT64_MAX
+ Q(int64_t)
+#endif
+
+#if UINT_MAX < X_SIZE_MAX
+ printf ("UINT_MAX < X_SIZE_MAX\n");
+#else
+ printf ("UINT_MAX >= X_SIZE_MAX\n");
+#endif
+ printf ("%" PRINTF_INT64_MODIFIER "u vs %" PRINTF_INT64_MODIFIER "u\n", UINT_MAX, X_SIZE_MAX);
+
+ return EXIT_SUCCESS;
+}
+
+#endif
diff --git a/src/sat/satoko/utils/sdbl.h b/src/sat/satoko/utils/sdbl.h
index 9f90ba02..a26794c7 100644
--- a/src/sat/satoko/utils/sdbl.h
+++ b/src/sat/satoko/utils/sdbl.h
@@ -121,8 +121,8 @@ static inline void sdbl_test()
{
sdbl_t ten100_ = ABC_CONST(0x014c924d692ca61b);
printf("%f\n", sdbl2double(ten100_));
- printf("%016lX\n", double2sdbl(1 /0.95));
- printf("%016lX\n", SDBL_CONST1);
+ //printf("%016lX\n", double2sdbl(1 /0.95));
+ //printf("%016lX\n", SDBL_CONST1);
printf("%f\n", sdbl2double(SDBL_CONST1));
printf("%f\n", sdbl2double(ABC_CONST(0x000086BCA1AF286B)));