[9] | 1 | #ifndef MAINSOLVER_H |
---|
| 2 | #define MAINSOLVER_H |
---|
| 3 | |
---|
| 4 | //shared files |
---|
| 5 | #include <Interface/AnalyzerData.h> |
---|
| 6 | |
---|
| 7 | #include "../Basics.h" |
---|
| 8 | #include "InstanceGraph/InstanceGraph.h" |
---|
| 9 | |
---|
| 10 | #include "FormulaCache.h" |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | /** \addtogroup Interna Solver Interna |
---|
| 14 | * Dies sind alle Klassen, die ausschlieï¿œich vom Solver selbst verwendet werden |
---|
| 15 | * sollten. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | /*@{*/ |
---|
| 20 | |
---|
| 21 | typedef unsigned char viewStateT; |
---|
| 22 | #define NIL 0 |
---|
| 23 | #define IN_SUP_COMP 1 |
---|
| 24 | #define SEEN 2 |
---|
| 25 | #define IN_OTHER_COMP 3 |
---|
| 26 | |
---|
| 27 | enum retStateT{ |
---|
| 28 | |
---|
| 29 | EXIT, |
---|
| 30 | RESOLVED, |
---|
| 31 | PROCESS_COMPONENT |
---|
| 32 | }; |
---|
| 33 | |
---|
| 34 | enum retIBCPT |
---|
| 35 | { |
---|
| 36 | NOTHING_FOUND, |
---|
| 37 | FOUND, |
---|
| 38 | CONTRADICTION, |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | class CMainSolver : public CInstanceGraph |
---|
| 43 | { |
---|
| 44 | CDecisionStack decStack; // decision stack |
---|
| 45 | CStopWatch stopWatch; |
---|
| 46 | |
---|
| 47 | CFormulaCache xFormulaCache; |
---|
| 48 | vector<AntAndLit> bcpImplQueue; |
---|
| 49 | |
---|
| 50 | int lastTimeCClDeleted; |
---|
| 51 | int lastCClCleanUp; |
---|
| 52 | |
---|
| 53 | unsigned int remPoll; |
---|
| 54 | |
---|
| 55 | retStateT backTrack(); |
---|
| 56 | |
---|
| 57 | // removes all cachePollutions that might be present in decedants of comnponents from the |
---|
| 58 | // present decision level |
---|
| 59 | void removeAllCachePollutions(); |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | bool findVSADSDecVar(LiteralIdT &theLit, const CComponentId & superComp); |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | bool decide(); |
---|
| 66 | |
---|
| 67 | bool bcp(); |
---|
| 68 | |
---|
| 69 | void handleSolution() |
---|
| 70 | { |
---|
| 71 | int actCompVars = 0; |
---|
| 72 | static CRealNum rnCodedSols; |
---|
| 73 | |
---|
| 74 | // in fact the active component should only contain active vars |
---|
| 75 | if(decStack.TOS_countRemComps() != 0) |
---|
| 76 | actCompVars = decStack.TOS_NextComp().countVars(); |
---|
| 77 | |
---|
| 78 | pow2(rnCodedSols, actCompVars); |
---|
| 79 | decStack.top().includeSol(rnCodedSols); |
---|
| 80 | theRunAn.addValue(SOLUTION, decStack.getDL()); |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | retStateT resolveConflict(); |
---|
| 85 | |
---|
| 86 | SOLVER_StateT countSAT(); |
---|
| 87 | |
---|
| 88 | bool performPreProcessing(); |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | * passes a componentId to rComp that is made of all |
---|
| 93 | * active variables and clauses |
---|
| 94 | * !! used to initialize decStack at DL zero |
---|
| 95 | **/ |
---|
| 96 | void makeCompIdFromActGraph(CComponentId& rComp); |
---|
| 97 | |
---|
| 98 | // BEGIN component analysis |
---|
| 99 | vector<VarIdT> componentSearchStack; |
---|
| 100 | bool recordRemainingComps(); |
---|
| 101 | bool getComp(const VarIdT &theVar, |
---|
| 102 | const CComponentId &superComp, |
---|
| 103 | viewStateT lookUpCls[], |
---|
| 104 | viewStateT lookUpVars[]); |
---|
| 105 | // END component analysis |
---|
| 106 | |
---|
| 107 | void printComponent(const CComponentId& rComp); |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | inline bool assignVal(const LiteralIdT &rLitId, AntecedentT ant = AntecedentT(NOT_A_CLAUSE)) |
---|
| 111 | { |
---|
| 112 | return getVar(rLitId).setVal(rLitId.polarity(), decStack.getDL(), ant); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | bool BCP(vector<AntAndLit> &thePairsOfImpl); |
---|
| 116 | |
---|
| 117 | ///////////////////////////////////////////// |
---|
| 118 | // BEGIN conflict analysis |
---|
| 119 | ///////////////////////////////////////////// |
---|
| 120 | |
---|
| 121 | private: |
---|
| 122 | |
---|
| 123 | vector<LiteralIdT> theQueue; |
---|
| 124 | vector<LiteralIdT> ca_1UIPClause; |
---|
| 125 | vector<LiteralIdT> ca_lastUIPClause; |
---|
| 126 | |
---|
| 127 | int imaxDecLev; |
---|
| 128 | |
---|
| 129 | // includes the causes of a variable assignment via |
---|
| 130 | // breadth first search |
---|
| 131 | void caIncludeCauses(LiteralIdT theLit, bool viewedVars[]); |
---|
| 132 | void caIncorporateLit(const LiteralIdT &Lit, bool viewedVars[]); |
---|
| 133 | |
---|
| 134 | void caAddtoCauses(LiteralIdT theLit, bool viewedVars[]); |
---|
| 135 | // initializes all data structures for the analysis |
---|
| 136 | // especially the startin point of the analysis i plugged into the queue |
---|
| 137 | bool caInit(vector<AntecedentT> & theConflicted, bool viewedVars[]); |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | bool caGetCauses_lastUIP(vector<AntecedentT> & theConflicted); |
---|
| 141 | bool caGetCauses_firstUIP(vector<AntecedentT> & theConflicted); |
---|
| 142 | |
---|
| 143 | // whenever a variable that is not implied causes a conflict |
---|
| 144 | // the conflict clause generated from this conflict implies a flip |
---|
| 145 | // of that variable: |
---|
| 146 | // creation of that clause and recording the implication is done by: |
---|
| 147 | |
---|
| 148 | const vector<LiteralIdT> &caGetPrev1UIPCCl() |
---|
| 149 | { |
---|
| 150 | return ca_1UIPClause; |
---|
| 151 | } |
---|
| 152 | const vector<LiteralIdT> &caGetPrevLastUIPCCl() |
---|
| 153 | { |
---|
| 154 | return ca_lastUIPClause; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | /// ermittelt den maximalen Entscheidungslevel von |
---|
| 158 | /// Variablen die zu den Konfliktursachen gehï¿œen. |
---|
| 159 | /// Ein Aufruf ist erst nach dem Auftruf von getCausesOf sinnvoll |
---|
| 160 | int getMaxDecLevFromAnalysis() const {return imaxDecLev;} |
---|
| 161 | |
---|
| 162 | /// gibt KonfliktKlausel zurck die durch die |
---|
| 163 | /// vorhergehende Analyse gewonnen wurde |
---|
| 164 | bool create1UIPCCl() |
---|
| 165 | { |
---|
| 166 | return createConflictClause(ca_1UIPClause); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | bool createLastUIPCCl() |
---|
| 170 | { |
---|
| 171 | return createConflictClause(ca_lastUIPClause); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | ///////////////////////////////////////////// |
---|
| 175 | // END conflict analysis |
---|
| 176 | ///////////////////////////////////////////// |
---|
| 177 | |
---|
| 178 | ///////////////////////////////////////////// |
---|
| 179 | // BEGIN implicitBCP |
---|
| 180 | ///////////////////////////////////////////// |
---|
| 181 | |
---|
| 182 | /// this method is used for heuristically testing variable assignments |
---|
| 183 | /// whether they incur a conflict. If so we can infer the opposite assignment of |
---|
| 184 | /// the variable in question |
---|
| 185 | /// Thus the method will then perform the assignment |
---|
| 186 | /// Furthermore it manages the necessary entries to the decision stack itself |
---|
| 187 | /// returned value: analogously to the bcp procedure: false iff a conflict is found |
---|
| 188 | bool implicitBCP(); |
---|
| 189 | |
---|
| 190 | bool createAntClauseFor(const LiteralIdT &Lit); |
---|
| 191 | |
---|
| 192 | ///////////////////////////////////////////// |
---|
| 193 | // END implicitBCP |
---|
| 194 | ///////////////////////////////////////////// |
---|
| 195 | |
---|
| 196 | ///////////////////////////////////////////// |
---|
| 197 | // BEGIN PreProcessing methods |
---|
| 198 | //////////////////////////////////////////// |
---|
| 199 | |
---|
| 200 | ///NOTE: Preprocessing methods assume that no conflict clauses are present ! |
---|
| 201 | |
---|
| 202 | bool prep_IBCP(vector<AntAndLit> &impls); |
---|
| 203 | /// Preprocessing |
---|
| 204 | /// i.e. the "hard" version of ImplicitBCP |
---|
| 205 | /// used for preprosessing ONLY |
---|
| 206 | bool prepFindHiddenBackBoneLits(); |
---|
| 207 | |
---|
| 208 | /// Apply the BCP rule in a Preprocessing step: |
---|
| 209 | /// That is: if firstLit is a valid literal, propagation is started there |
---|
| 210 | /// firstLit should not be assigned already! |
---|
| 211 | /// furthermore ALL unit clauses are processed |
---|
| 212 | bool prepBCP(LiteralIdT firstLit = NOT_A_LIT); |
---|
| 213 | |
---|
| 214 | ///////////////////////////////////////////// |
---|
| 215 | // END PreProcessing methods |
---|
| 216 | ///////////////////////////////////////////// |
---|
| 217 | |
---|
| 218 | bool printUnitClauses(); |
---|
| 219 | |
---|
| 220 | public: |
---|
| 221 | |
---|
| 222 | // class constructor |
---|
| 223 | CMainSolver(); |
---|
| 224 | |
---|
| 225 | // class destructor |
---|
| 226 | ~CMainSolver(); |
---|
| 227 | |
---|
| 228 | void solve(const char *lpstrFileName); |
---|
| 229 | |
---|
| 230 | void setTimeBound(long int i) |
---|
| 231 | { |
---|
| 232 | stopWatch.setTimeBound(i); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | }; |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | /*@}*/ |
---|
| 239 | #endif // SOLVER_H |
---|
| 240 | |
---|
| 241 | |
---|