/*********************************************************************************** CryptoMiniSat -- Copyright (c) 2009 Mate Soos This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . **************************************************************************************************/ #ifndef VARREPLACER_H #define VARREPLACER_H #ifdef _MSC_VER #include #else #include #endif //_MSC_VER #include #include #include "Solver.h" #include "SolverTypes.h" #include "Clause.h" #include "Vec.h" namespace CMSat { using std::map; using std::vector; /** @brief Replaces variables with their anti/equivalents */ class VarReplacer { public: VarReplacer(Solver& solver); ~VarReplacer(); bool performReplace(const bool always = false); bool needsReplace(); template bool replace(T& ps, const bool xorEqualFalse, const bool addBinAsLearnt = false, const bool addToWatchLists = true); void extendModelPossible() const; void extendModelImpossible(Solver& solver2) const; uint32_t getNumReplacedLits() const; uint32_t getNumReplacedVars() const; uint32_t getNumLastReplacedVars() const; uint32_t getNewToReplaceVars() const; uint32_t getNumTrees() const; vector getReplacingVars() const; const vector& getReplaceTable() const; bool varHasBeenReplaced(const Var var) const; bool replacingVar(const Var var) const; void newVar(); vec cannot_eliminate; //No need to update, only stores binary clauses, that //have been allocated within pool //friend class ClauseAllocator; private: bool performReplaceInternal(); bool replace_set(vec& cs); bool replaceBins(); bool replace_set(vec& cs); bool handleUpdatedClause(Clause& c, const Lit origLit1, const Lit origLit2, const Lit origLit3); bool handleUpdatedClause(XorClause& c, const Var origVar1, const Var origVar2); void addBinaryXorClause(Lit lit1, Lit lit2, const bool addBinAsLearnt = false); void setAllThatPointsHereTo(const Var var, const Lit lit); bool alreadyIn(const Var var, const Lit lit); vector table; /// > reverseTable; /// 0) || getNewToReplaceVars() > limit) return performReplaceInternal(); return true; } inline bool VarReplacer::needsReplace() { uint32_t limit = (uint32_t)((double)solver.order_heap.size()*PERCENTAGEPERFORMREPLACE); return (getNewToReplaceVars() > limit); } inline uint32_t VarReplacer::getNumReplacedLits() const { return replacedLits; } inline uint32_t VarReplacer::getNumReplacedVars() const { return replacedVars; } inline uint32_t VarReplacer::getNumLastReplacedVars() const { return lastReplacedVars; } inline uint32_t VarReplacer::getNewToReplaceVars() const { return replacedVars-lastReplacedVars; } inline const vector& VarReplacer::getReplaceTable() const { return table; } inline bool VarReplacer::varHasBeenReplaced(const Var var) const { return table[var].var() != var; } inline bool VarReplacer::replacingVar(const Var var) const { return (reverseTable.find(var) != reverseTable.end()); } inline uint32_t VarReplacer::getNumTrees() const { return reverseTable.size(); } } #endif //VARREPLACER_H