📄 vsids.cpp
字号:
/********************************************************************************************MiraXT -- Copyright (c) 2007, Tobias Schubert, Matthew Lewis, Natalia Kalinnik, Bernd Becker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies orsubstantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.********************************************************************************************/// Definition of the (modified) VSIDS decision heuristic.class VSIDS{private: vec<int> varOrder; // Ordered list of all variables to select the free one with the highest activity. vec<int> Buckets; // Used to perform "bucket sort" to sort varOrder. unsigned int* varActivity; // Activity of each variable. int lastSearchPos; // Last search position within varOrder. int numDecisions; // Number of overall decisions. public: // Constructor / Destructor. VSIDS(unsigned int* varActivityIn); ~VSIDS(void) { /* Nothing to do. */ }; // Select a free variable and the truth value it should be set to. int decide(int* Assignment); // Sort varOrder using a variant of "bucket sort". void sort(bool setup); // Reset "lastSearchPtr". void resetVSIDSPtr(void) { lastSearchPos = numLiterals; }};// Constructor.VSIDS::VSIDS(unsigned int* varActivityIn){ lastSearchPos = numLiterals; varActivity = varActivityIn; numDecisions = 0; varOrder.growTo(numLiterals+1,0); Buckets.growTo(numBuckets+1,0);#ifdef PseudoRandom srand(0);#endif}// Select the next free variable and the truth value it should be set to.int VSIDS::decide(int* Assignment){ // Variables. int Literal; // Increment number of decisions. numDecisions++;#ifdef PseudoRandom // Select the next decision variable randomly. if ((numDecisions & PseudoRandomValue) == 0) { int RND = (rand() % lastSearchPos) + 1; // Check the "varActivity" array. while(RND > 0) { // Read current literal. Literal = varOrder[RND]; // Literal unassigned? if(Assignment[Literal] == 0) { RND--; #ifdef FixedZeroPolarity // Set "Literal" always to value "0". Literal = (Literal << 1) + 1;#else // Check whether +Literal or -Literal has the higher activity. Literal = Literal << 1; if (varActivity[Literal] < varActivity[Literal+1]) { Literal++; }#endif // Return variable and truth value. return Literal; } RND--; } } #endif // Check the entire "varActivity" array. while(lastSearchPos > 0) { // Read current literal. Literal = varOrder[lastSearchPos]; // Literal unassigned? if(Assignment[Literal] == 0) { // Update lastSearchPos for the next decision. lastSearchPos--;#ifdef FixedZeroPolarity // Set "Literal" always to value "0". Literal = (Literal << 1) + 1; #else // Check whether +Literal or -Literal has the higher activity. Literal = Literal << 1; if (varActivity[Literal] < varActivity[Literal+1]) { Literal++; }#endif // Return variable and truth value. return Literal; } // Decrement lastSearchPos. lastSearchPos--; } // No unassigned variable left --> benchmark is satisfiable. return 0;}// Sort varOrder using a variant of "bucket sort". After performing "sort" // the variables are ordered by an increasing activity.void VSIDS::sort(bool setup){ // Variables. int i, pos, shifting; unsigned int score; // Permit normalizing the variable's activities used below during the initialization phase. if (setup) { shifting = 0; } else { shifting = shiftAmount; } // Initialization. for(i=0; i<=numBuckets; i++) { Buckets[i] = 0; } // Compute the variable's score and update "Buckets". for(i=1; i<=numLiterals; i++) { score = (varActivity[i << 1] + varActivity[(i << 1) + 1]) >> shifting; if (score > numBuckets) { Buckets[numBuckets]++; } else { Buckets[score]++; } } // Calculate the final values for all buckets. for(i=1; i<=numBuckets; i++) { Buckets[i] += Buckets[i-1]; } // Now, order the variables by an increasing activity. for(i=1; i<=numLiterals; i++) { score = (varActivity[i << 1] + varActivity[(i << 1) + 1]) >> shifting; if (score > numBuckets) { score = numBuckets; } pos = Buckets[score]; Buckets[score]--; varOrder[pos] = i; } // Reset lastSearchPos. resetVSIDSPtr();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -