通用的数据结构在文件夹mtl中可以查询
基本的数据结构在SolverTypes.h中定义
1. Lit
1 struct Lit { 2 int x; 3 4 // Use this as a constructor: 5 friend Lit mkLit(Var var, bool sign ); 6 7 bool operator == (Lit p) const { return x == p.x; } 8 bool operator != (Lit p) const { return x != p.x; } 9 bool operator < (Lit p) const { return x < p.x; }
|
|
2. Clause
1 class Clause; 2 typedef RegionAllocator<uint32_t>::Ref CRef; 3 4 class Clause { 5 struct { 6 unsigned mark : 2; 7 unsigned learnt : 1; 8 unsigned has_extra : 1; 9 unsigned reloced : 1; 10 unsigned lbd : 26; 11 unsigned removable : 1; 12 unsigned size : 32; 13 //simplify 14 unsigned simplified : 1;} header; 15 union { Lit lit; float act; uint32_t abs; uint32_t touched; CRef rel; } data[0]; 16 17 friend class ClauseAllocator; 18 19 // NOTE: This constructor cannot be used directly (doesn't allocate enough memory). 20 template<class V> 21 Clause(const V& ps, bool use_extra, bool learnt) { 22 header.mark = 0; 23 header.learnt = learnt; 24 header.has_extra = learnt | use_extra; 25 header.reloced = 0; 26 header.size = ps.size(); 27 header.lbd = 0; 28 header.removable = 1; 29 //simplify 30 // 31 header.simplified = 0; 32 33 for (int i = 0; i < ps.size(); i++) 34 data[i].lit = ps[i]; 35 36 if (header.has_extra){ 37 if (header.learnt){ 38 data[header.size].act = 0; 39 data[header.size+1].touched = 0; 40 }else 41 calcAbstraction(); } 42 } 43 44 public: 45 void calcAbstraction() { 46 assert(header.has_extra); 47 uint32_t abstraction = 0; 48 for (int i = 0; i < size(); i++) 49 abstraction |= 1 << (var(data[i].lit) & 31); 50 data[header.size].abs = abstraction; } 51 52 53 int size () const { return header.size; } 54 void shrink (int i) { assert(i <= size());
|
|
3. OccLists
1 //================================================================================================= 2 // OccLists -- a class for maintaining occurence lists with lazy deletion: 3 4 template<class Idx, class Vec, class Deleted> 5 class OccLists 6 { 7 vec<Vec> occs; 8 vec<char> dirty; 9 vec<Idx> dirties; 10 Deleted deleted; 11 12 public: 13 OccLists(const Deleted& d) : deleted(d) {} 14 15 void init (const Idx& idx){ occs.growTo(toInt(idx)+1); dirty.growTo(toInt(idx)+1, 0); } 16 // Vec& operator[](const Idx& idx){ return occs[toInt(idx)]; } 17 Vec& operator[](const Idx& idx){ return occs[toInt(idx)]; } 18 Vec& lookup (const Idx& idx){ if (dirty[toInt(idx)]) clean(idx); return occs[toInt(idx)]; } 19 20 void cleanAll (); 21 void clean (const Idx& idx); 22 void smudge (const Idx& idx){ 23 if (dirty[toInt(idx)] == 0){ 24 dirty[toInt(idx)] = 1; 25 dirties.push(idx); 26 } 27 } 28 29 void clear(bool free = true){ 30 occs .clear(free); 31 dirty .clear(free); 32 dirties.clear(free); 33 } 34 35 //----------------------------------------------------- 36 //将观察体系各个观察中的观察元随机排列 37 //update on 2020-8-8 38 void randomlizeAll(); 39 void randomlize(const Idx& idx); 40 //void randomlizeAll(); 41 }; 42 43 44 template<class Idx, class Vec, class Deleted> 45 void OccLists<Idx,Vec,Deleted>::cleanAll() 46 { 47 for (int i = 0; i < dirties.size(); i++) 48 // Dirties may contain duplicates so check here if a variable is already cleaned: 49 if (dirty[toInt(dirties[i])]) 50 clean(dirties[i]); 51 dirties.clear(); 52 } 53 54 55 template<class Idx, class Vec, class Deleted> 56 void OccLists<Idx,Vec,Deleted>::clean(const Idx& idx) 57 { 58 Vec& vec = occs[toInt(idx)]; 59 int i, j; 60 for (i = j = 0; i < vec.size(); i++) 61 if (!deleted(vec[i])) 62 vec[j++] = vec[i]; 63 vec.shrink(i - j); 64 dirty[toInt(idx)] = 0; 65 } 66 67 template<class Idx, class Vec, class Deleted> 68 void OccLists<Idx,Vec,Deleted>::randomlizeAll() 69 { 70 for (int i = 0; i < occs.size(); i++){ 71 Vec& vec = occs[i]; 72 randomlizeT(vec); 73 } 74 } 75 76 template<class Idx, class Vec, class Deleted> 77 void OccLists<Idx,Vec,Deleted>::randomlize(const Idx& idx) 78 { 79 Vec& vec = occs[toInt(idx)]; 80 randomlizeT(vec); 81 }
|
|