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
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #ifndef CLAUSEHELPER_H_JUN_26_2005
00067 #define CLAUSEHELPER_H_JUN_26_2005
00068
00069 struct VarsGroundedType
00070 {
00071 VarsGroundedType() : isGrounded(false), typeId(-1), numGndings(-1) {}
00072 VarsGroundedType(const VarsGroundedType& vgt)
00073 {
00074 vars.copyFrom(vgt.vars);
00075 isGrounded = vgt.isGrounded;
00076 typeId = vgt.typeId;
00077 numGndings = vgt.numGndings;
00078 }
00079
00080 Array<Term*> vars;
00081 bool isGrounded;
00082 int typeId;
00083 int numGndings;
00084 };
00085
00086
00087 struct LitIdxVarIdsGndings
00088 {
00089 unsigned int litIdx;
00090 Array<int> varIds;
00091 ArraysAccessor<int> varGndings;
00092 Array<Predicate*> subseqGndLits;
00093 bool litUnseen;
00094 Array<Predicate*> bannedPreds;
00095 };
00096
00097
00098 typedef hash_set<string, HashString, EqualString> FormulaStringSet;
00099
00100
00101 struct CacheCount
00102 {
00103 CacheCount(const int& gg, const int& cc, const double& ccnt) :
00104 g(gg), c(cc), cnt(ccnt) {}
00105 ~CacheCount() {}
00106 int g;
00107 int c;
00108 double cnt;
00109 };
00110
00111
00112
00113 enum { OP_NONE = 0, OP_ADD = 1, OP_REMOVE = 2, OP_REPLACE = 3,
00114 OP_REPLACE_ADDPRED = 4, OP_REPLACE_REMPRED = 5 };
00115
00116
00117
00118
00119 struct AuxClauseData
00120 {
00121 AuxClauseData() : gain(0), constTermPtrs(NULL), op(OP_NONE),
00122 removedClauseIdx(-1), cache(NULL), removedPredIdx(-1),
00123 hasBeenExpanded(false), lastStepExpanded(-1),
00124 lastStepOverMinWeight(-1) {}
00125
00126 AuxClauseData(const double& ggain, const int& oop,
00127 const int& rremovedClauseIdx)
00128 : gain(ggain), constTermPtrs(NULL), op(oop),
00129 removedClauseIdx(rremovedClauseIdx), cache(NULL), removedPredIdx(-1),
00130 hasBeenExpanded(false), lastStepExpanded(-1),
00131 lastStepOverMinWeight(-1) {}
00132
00133 AuxClauseData(const double& ggain, const int& oop,
00134 const int& rremovedClauseIdx,
00135 const bool& hhasBeenExpanded,
00136 const int& llastStepExpanded,
00137 const int& llastStepOverMinWeight)
00138 : gain(ggain), constTermPtrs(NULL), op(oop),
00139 removedClauseIdx(rremovedClauseIdx), cache(NULL), removedPredIdx(-1),
00140 hasBeenExpanded(hhasBeenExpanded), lastStepExpanded(llastStepExpanded),
00141 lastStepOverMinWeight(llastStepOverMinWeight) {}
00142
00143 AuxClauseData(const double& ggain, const int& oop,
00144 const int& rremovedClauseIdx, const string& prevClause,
00145 const string& addedPred, const int& remPredIdx)
00146 : gain(ggain), constTermPtrs(NULL), op(oop),
00147 removedClauseIdx(rremovedClauseIdx), cache(NULL),
00148 prevClauseStr(prevClause), addedPredStr(addedPred),
00149 removedPredIdx(remPredIdx),
00150 hasBeenExpanded(false), lastStepExpanded(-1),
00151 lastStepOverMinWeight(-1) {}
00152
00153 ~AuxClauseData()
00154 {
00155 if (constTermPtrs) delete constTermPtrs;
00156 if (cache) deleteCache();
00157 }
00158
00159
00160 void deleteCache()
00161 {
00162 if (cache)
00163 {
00164 for (int i = 0; i < cache->size(); i++)
00165 {
00166 Array<Array<CacheCount*>*>* aacc = (*cache)[i];
00167 for (int j = 0; j < aacc->size(); j++)
00168 {
00169 Array<CacheCount*>* ccArr = (*aacc)[j];
00170 if (ccArr == NULL) continue;
00171 ccArr->deleteItemsAndClear();
00172 }
00173 aacc->deleteItemsAndClear();
00174 }
00175 cache->deleteItemsAndClear();
00176 delete cache;
00177 cache = NULL;
00178 }
00179 }
00180
00181
00182 void compress()
00183 {
00184 if (constTermPtrs) constTermPtrs->compress();
00185 if (cache)
00186 {
00187 for (int i = 0; i < cache->size(); i++)
00188 {
00189 Array<Array<CacheCount*>*>* aacc = (*cache)[i];
00190 for (int j = 0; j < aacc->size(); j++)
00191 {
00192 Array<CacheCount*>* ccArr = (*aacc)[j];
00193 if (ccArr == NULL) continue;
00194 ccArr->compress();
00195 }
00196 aacc->compress();
00197 }
00198 cache->compress();
00199 }
00200
00201 }
00202
00203
00204 double sizeMB() const
00205 {
00206 double sz = fixedSizeB_;
00207 if (cache)
00208 {
00209 for (int i = 0; i < cache->size(); i++)
00210 for (int j = 0; j < (*cache)[i]->size(); j++)
00211 {
00212 if((*(*cache)[i])[j] == NULL) continue;
00213 sz += (*(*cache)[i])[j]->size() * (sizeof(CacheCount) +
00214 sizeof(CacheCount*));
00215 }
00216 }
00217 if (constTermPtrs) sz += constTermPtrs->size() * sizeof(Term*);
00218 return sz/1000000.0;
00219 }
00220
00221
00222 static void computeFixedSizeB() { fixedSizeB_ = sizeof(AuxClauseData); }
00223
00224
00225 void reset()
00226 {
00227 gain = 0;
00228 if (constTermPtrs) constTermPtrs->clear();
00229 op = OP_NONE;
00230 removedClauseIdx = -1;
00231 deleteCache(); cache = NULL;
00232 prevClauseStr = "";
00233 addedPredStr = "";
00234 removedPredIdx = -1;
00235 }
00236
00237 double gain;
00238 Array<Term*>* constTermPtrs;
00239 int op;
00240 int removedClauseIdx;
00241
00242
00243 Array<Array<Array<CacheCount*>*>*>* cache;
00244
00245 string prevClauseStr;
00246 string addedPredStr;
00247 int removedPredIdx;
00248
00249
00250 bool hasBeenExpanded;
00251 int lastStepExpanded;
00252 int lastStepOverMinWeight;
00253
00254 static double fixedSizeB_;
00255 };
00256
00257
00258 #endif