00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef _cvc3__minisat__types_h_
00041 #define _cvc3__minisat__types_h_
00042
00043
00044
00045
00046 #include "minisat_global.h"
00047 #include "theorem.h"
00048 #include <vector>
00049
00050 namespace MiniSat {
00051
00052
00053
00054
00055 typedef int Var;
00056 const int var_Undef = -1;
00057
00058
00059 class Lit {
00060 int x;
00061
00062 explicit Lit(int index) : x(index) {}
00063 public:
00064 Lit() : x(2*var_Undef) {}
00065 explicit Lit(Var var, bool sgn) : x((var+var) + (int)sgn) {}
00066 Lit operator~ () const { return Lit(x ^ 1); };
00067
00068 bool sign () const { return x & 1; };
00069 int var () const { return x >> 1; };
00070 int index () const { return x; };
00071 static Lit toLit (int i) { return Lit(i); };
00072 Lit unsign() const { return Lit(x & ~1); };
00073 static Lit id (Lit p, bool sgn) { return Lit(p.x ^ (int)sgn); };
00074
00075 bool operator == (const Lit q) const { return index() == q.index(); };
00076 bool operator != (const Lit q) const { return !(operator==(q)); };
00077
00078 bool operator < (const Lit q) const { return index() < q.index(); }
00079
00080 unsigned int hash() const { return (unsigned int)x; }
00081
00082 std::string toString() const {
00083 std::ostringstream buffer;
00084 if (sign())
00085 buffer << "+";
00086 else
00087 buffer << "-";
00088 buffer << var();
00089 return buffer.str();
00090 }
00091
00092 int toDimacs() const { return sign() ? -var() - 1 : var() + 1; }
00093 };
00094
00095 const Lit lit_Undef(var_Undef, false);
00096 const Lit lit_Error(var_Undef, true );
00097
00098
00099
00100
00101 class Clause {
00102 unsigned int d_size_learnt;
00103 int d_id;
00104 int d_pushID;
00105 float d_activity;
00106
00107 CVC3::Theorem d_theorem;
00108 Lit d_data[1];
00109
00110 static Clause* s_decision;
00111 static Clause* s_theoryImplication;
00112 public:
00113
00114
00115
00116
00117
00118
00119 Clause(bool learnt, const std::vector<Lit>& ps, CVC3::Theorem theorem,
00120 int id, int pushID) {
00121 d_size_learnt = (ps.size() << 1) | (int)learnt;
00122 d_id = id;
00123 d_pushID = pushID;
00124 d_activity = 0;
00125 d_theorem = theorem;
00126 for (std::vector<Lit>::size_type i = 0; i < ps.size(); i++) d_data[i] = ps[i];
00127 }
00128
00129
00130 friend Clause* Clause_new(const std::vector<Lit>& ps, CVC3::Theorem theorem, int id);
00131 friend Clause* Lemma_new(const std::vector<Lit>& ps, int id, int pushID);
00132
00133 int size () const { return d_size_learnt >> 1; }
00134 bool learnt () const { return d_size_learnt & 1; }
00135 Lit operator [] (int i) const { return d_data[i]; }
00136 Lit& operator [] (int i) { return d_data[i]; }
00137
00138 int id () const { return d_id; }
00139
00140
00141
00142
00143 int pushID () const { return d_pushID; }
00144 float activity () const {
00145 DebugAssert(learnt(), "MiniSat::Types:activity: not a lemma");
00146 return d_activity;
00147 }
00148 void setActivity (float activity) {
00149 DebugAssert(learnt(), "MiniSat::Types:setActivity: not a lemma");
00150 d_activity = activity;
00151 }
00152 void toLit (std::vector<Lit>& literals) const;
00153 CVC3::Theorem getTheorem() const { return d_theorem; };
00154
00155 static int ClauseIDNull() { return 0; }
00156
00157
00158 static Clause* Decision();
00159
00160
00161 static Clause* TheoryImplication();
00162
00163 std::string toString() const {
00164 if (size() == 0) return "";
00165
00166 std::ostringstream buffer;
00167 buffer << d_data[0].toString();
00168 for (int j = 1; j < size(); ++j) {
00169 buffer << " " << d_data[j].toString();
00170 }
00171 return buffer.str();
00172 }
00173
00174 bool contains(Lit l) {
00175 for (int i = 0; i < size(); ++i) {
00176 if (d_data[i] == l) return true;
00177 }
00178 return false;
00179 }
00180 };
00181
00182 Clause* Clause_new(const std::vector<Lit>& ps, CVC3::Theorem theorem, int id);
00183 Clause* Lemma_new(const std::vector<Lit>& ps, int id, int pushID);
00184
00185 }
00186
00187
00188
00189
00190 #endif