source: vis_dev/sharpSAT/src/src_sharpSAT/MainSolver/DecisionStack.cpp @ 69

Last change on this file since 69 was 9, checked in by cecile, 13 years ago

add sharpSat

File size: 2.7 KB
Line 
1#include "DecisionStack.h"
2
3
4
5void CDecisionStack::reactivateTOS()
6{         
7   for(vector<LiteralIdT>::const_iterator it = TOS_ImpliedLits_begin();it != TOS_ImpliedLits_end();it++)
8   {   
9     theClPool.getVar(*it).unsetVal();     
10   } 
11}
12
13bool CDecisionStack::flipTOS()
14{   
15   if(getDL() <= 0) return false; 
16   if (top().isFlipped()) return false; // es wurde schonmal geflippt
17         
18   top().flipped = true;
19   
20   reactivateTOS();     
21   allImpliedLits.resize(top().iImpLitOfs);   
22   storeTOSCachedChildren();       
23   top().iEndRemComps = top().iRemCompOfs;
24   
25   while(allComponentsStack.size() > top().iRemCompOfs)
26   {
27     delete allComponentsStack.back();
28     allComponentsStack.pop_back();
29   }
30   return true;   
31}
32
33bool CDecisionStack::storeTOSCachedChildren()
34{
35  vector<CComponentId *>::iterator it = allComponentsStack.begin() +top().iRemCompOfs;
36  for(;it != allComponentsStack.end(); it++)
37  {
38    if((*it)->cachedAs != 0) allComponentsStack[top().refCompId]->cachedChildren.push_back((*it)->cachedAs);
39 
40  }
41  return true;
42}
43
44bool CDecisionStack::pop()
45{
46   if(getDL() <= 0) return false; 
47   
48   reactivateTOS(); 
49   allImpliedLits.resize(top().iImpLitOfs);   
50   storeTOSCachedChildren();
51   
52   while(allComponentsStack.size() > top().iRemCompOfs)
53   {
54     delete allComponentsStack.back();
55     allComponentsStack.pop_back();
56   }   
57     
58   (end()-2)->includeSol(top().getOverallSols());       
59   
60   pop_back();     
61   return true;   
62}
63
64
65void CDecisionStack::push()
66{   
67   push_back(CDecision()); 
68   
69   top().refCompId = (end()-2)->iEndRemComps-1;
70   (end()-2)->popRemComp();   
71   
72   top().iImpLitOfs = allImpliedLits.size();
73   top().iRemCompOfs = allComponentsStack.size(); 
74   top().iEndRemComps = allComponentsStack.size();
75}
76
77
78void CDecisionStack::init(unsigned int resSize)
79{   
80  clear(); 
81  reserve(resSize);
82  allImpliedLits.clear();
83  allImpliedLits.reserve(theClPool.countAllVars());
84  allComponentsStack.clear();
85  allComponentsStack.reserve(theClPool.countAllVars()); 
86  allComponentsStack.push_back(new CComponentId()); 
87
88  // initialize the stack to contain at least level zero 
89  push_back(CDecision());   
90  back().flipped = true; 
91  top().iRemCompOfs = 1; 
92  top().iEndRemComps = 1; 
93  addToDecLev = 0;
94}
95
96void CDecisionStack::TOS_sortRemComps()
97{ 
98  CComponentId * vBuf;
99  vector<CComponentId *> &keys = allComponentsStack;
100 
101  int uLower = top().iRemCompOfs;
102  int uUpper = top().iEndRemComps-1;
103 
104 
105  for(int i = uLower; i <=uUpper;i++)
106   for(int j = i+1; j <=uUpper;j++)
107   { 
108     if(keys[i]->countVars() < keys[j]->countVars())
109     {
110       vBuf = keys[i];
111       keys[i] = keys[j];
112       keys[j] = vBuf;   
113     }   
114   }   
115}
Note: See TracBrowser for help on using the repository browser.