00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef satSolver_h
00023 #define satSolver_h
00024
00025 #ifdef _WIN32
00026 #define inline __inline // compatible with MS VS 6.0
00027 #endif
00028
00029 #include "satVec.h"
00030 #include "satMem.h"
00031
00032
00033
00034
00035
00036
00037 #ifndef __cplusplus
00038 #ifndef bool
00039 #define bool int
00040 #endif
00041 #endif
00042
00043 static const bool true = 1;
00044 static const bool false = 0;
00045
00046 typedef int lit;
00047 typedef char lbool;
00048
00049 #ifndef SINT64
00050 #define SINT64
00051
00052 #ifdef _WIN32
00053 typedef signed __int64 sint64;
00054 #else
00055 typedef long long sint64;
00056 #endif
00057
00058 #endif
00059
00060 static const int var_Undef = -1;
00061 static const lit lit_Undef = -2;
00062
00063 static const lbool l_Undef = 0;
00064 static const lbool l_True = 1;
00065 static const lbool l_False = -1;
00066
00067 static inline lit toLit (int v) { return v + v; }
00068 static inline lit toLitCond(int v, int c) { return v + v + (c != 0); }
00069 static inline lit lit_neg (lit l) { return l ^ 1; }
00070 static inline int lit_var (lit l) { return l >> 1; }
00071 static inline int lit_sign (lit l) { return l & 1; }
00072 static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
00073 static inline lit lit_read (int s) { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }
00074
00075
00076
00077
00078
00079 struct sat_solver_t;
00080 typedef struct sat_solver_t sat_solver;
00081
00082 extern sat_solver* sat_solver_new(void);
00083 extern void sat_solver_delete(sat_solver* s);
00084
00085 extern bool sat_solver_addclause(sat_solver* s, lit* begin, lit* end);
00086 extern bool sat_solver_simplify(sat_solver* s);
00087 extern int sat_solver_solve(sat_solver* s, lit* begin, lit* end, sint64 nConfLimit, sint64 nInsLimit, sint64 nConfLimitGlobal, sint64 nInsLimitGlobal);
00088
00089 extern int sat_solver_nvars(sat_solver* s);
00090 extern int sat_solver_nclauses(sat_solver* s);
00091 extern int sat_solver_nconflicts(sat_solver* s);
00092
00093 extern void sat_solver_setnvars(sat_solver* s,int n);
00094
00095 struct stats_t
00096 {
00097 sint64 starts, decisions, propagations, inspects, conflicts;
00098 sint64 clauses, clauses_literals, learnts, learnts_literals, max_literals, tot_literals;
00099 };
00100 typedef struct stats_t stats;
00101
00102 extern void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars );
00103 extern void Sat_SolverPrintStats( FILE * pFile, sat_solver * p );
00104 extern int * Sat_SolverGetModel( sat_solver * p, int * pVars, int nVars );
00105 extern void Sat_SolverDoubleClauses( sat_solver * p, int iVar );
00106
00107
00108 extern void Sat_SolverTraceStart( sat_solver * pSat, char * pName );
00109 extern void Sat_SolverTraceStop( sat_solver * pSat );
00110 extern void Sat_SolverTraceWrite( sat_solver * pSat, int * pBeg, int * pEnd, int fRoot );
00111
00112
00113 extern void sat_solver_store_alloc( sat_solver * s );
00114 extern void sat_solver_store_write( sat_solver * s, char * pFileName );
00115 extern void sat_solver_store_free( sat_solver * s );
00116 extern void sat_solver_store_mark_roots( sat_solver * s );
00117 extern void sat_solver_store_mark_clauses_a( sat_solver * s );
00118 extern void * sat_solver_store_release( sat_solver * s );
00119
00120
00121
00122
00123 struct clause_t;
00124 typedef struct clause_t clause;
00125
00126 struct sat_solver_t
00127 {
00128 int size;
00129 int cap;
00130 int qhead;
00131 int qtail;
00132
00133
00134 vecp clauses;
00135 vecp learnts;
00136
00137
00138 double var_inc;
00139 double var_decay;
00140 float cla_inc;
00141 float cla_decay;
00142
00143 vecp* wlists;
00144 double* activity;
00145 lbool* assigns;
00146 int* orderpos;
00147 clause** reasons;
00148 int* levels;
00149 lit* trail;
00150
00151 clause* binary;
00152 lbool* tags;
00153 veci tagged;
00154 veci stack;
00155
00156 veci order;
00157 veci trail_lim;
00158 veci model;
00159
00160 int root_level;
00161 int simpdb_assigns;
00162 int simpdb_props;
00163 double random_seed;
00164 double progress_estimate;
00165 int verbosity;
00166
00167 stats stats;
00168
00169 sint64 nConfLimit;
00170 sint64 nInsLimit;
00171
00172 veci act_vars;
00173 double* factors;
00174 int nRestarts;
00175 int nCalls;
00176 int nCalls2;
00177
00178 Sat_MmStep_t * pMem;
00179
00180 int fSkipSimplify;
00181
00182
00183 void * pStore;
00184
00185
00186 FILE * pFile;
00187 int nClauses;
00188 int nRoots;
00189 };
00190
00191 #endif