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 <vector>
00048 
00049 namespace MiniSat {
00050 
00051   
00052   
00053   
00054   typedef int Var;
00055   const int var_Undef = -1;
00056 
00057 
00058   class Lit {
00059     int     x;
00060 
00061     explicit Lit(int index) : x(index) {}   
00062   public:
00063     Lit() : x(2*var_Undef) {}   
00064     explicit Lit(Var var, bool sgn) : x((var+var) + (int)sgn) {}
00065     Lit operator~ () const { return Lit(x ^ 1); };
00066 
00067     bool sign  () const { return x & 1; };
00068     int  var   () const { return x >> 1; };
00069     int  index () const { return x; };
00070     static Lit  toLit (int i) { return Lit(i); };
00071     Lit  unsign() const { return Lit(x & ~1); };
00072     static Lit  id  (Lit p, bool sgn) { return Lit(p.x ^ (int)sgn); };
00073 
00074     bool operator == (const Lit q) const { return index() == q.index(); };
00075     bool operator != (const Lit q) const { return !(operator==(q)); };
00076     
00077     bool operator <  (const Lit q) const { return index() < q.index(); }
00078 
00079     uint hash() const { return (uint)x; }
00080 
00081     std::string toString() const {
00082       std::ostringstream buffer;
00083       if (sign())
00084   buffer << "+";
00085       else
00086   buffer << "-";
00087       buffer << var();
00088       return buffer.str();
00089     }
00090 
00091     int toDimacs() const { return sign() ? -var() - 1 : var() + 1; }
00092   };
00093 
00094   const Lit lit_Undef(var_Undef, false);  
00095   const Lit lit_Error(var_Undef, true );  
00096 
00097 
00098 
00099   
00100   class Clause {
00101     uint    size_learnt;
00102     Lit     data[1];
00103 
00104     static Clause* s_decision;
00105     static Clause* s_theoryImplication;
00106   public:
00107     
00108     
00109     
00110     
00111     
00112     
00113     
00114     
00115     
00116     
00117     
00118     Clause(bool learnt, const std::vector<Lit>& ps, int id_) {
00119         size_learnt = (ps.size() << 1) | (int)learnt;
00120         for (std::vector<Lit>::size_type i = 0; i < ps.size(); i++) data[i] = ps[i];
00121   id() = id_;
00122         if (learnt) activity() = 0;
00123     }
00124 
00125     
00126     friend Clause* Clause_new(const std::vector<Lit>& ps, int id);
00127     friend Clause* Lemma_new(const std::vector<Lit>& ps, int id, int pushID);
00128 
00129     int       size        ()      const { return size_learnt >> 1; }
00130     bool      learnt      ()      const { return size_learnt & 1; }
00131     Lit       operator [] (int i) const { return data[i]; }
00132     Lit&      operator [] (int i)       { return data[i]; }
00133     
00134     int&      id          ()      const { return *((int*)&data[size()]); }
00135     
00136     
00137     
00138     
00139     int&      pushID      ()      const {
00140       if (learnt())
00141   return *((int*)&data[size() + 2]);
00142       else
00143   return id();
00144     }
00145     float&    activity    ()      const {
00146       DebugAssert(learnt(), "MiniSat::Types:activity: not a lemma");
00147       return *((float*)&data[size() + 1]);
00148     }
00149     void      toLit       (std::vector<Lit>& literals) const;
00150 
00151     static int ClauseIDNull() { return 0; }
00152 
00153     
00154     static Clause* Decision();
00155     
00156     
00157     static Clause* TheoryImplication();
00158 
00159     std::string toString() const {
00160       if (size() == 0) return "";
00161 
00162       std::ostringstream buffer;
00163       buffer << data[0].toString();
00164       for (int j = 1; j < size(); ++j) {
00165   buffer << " " << data[j].toString();
00166       }
00167       return buffer.str();
00168     }
00169   };
00170 
00171   Clause* Clause_new(const std::vector<Lit>& ps, int id);
00172   Clause* Lemma_new(const std::vector<Lit>& ps, int id, int pushID);
00173 
00174 }
00175 
00176 
00177 
00178 
00179 #endif