source: vis_dev/sharpSAT/src/shared/Interface/AnalyzerData.cpp @ 69

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

shared missing for sharpSAT

File size: 7.5 KB
Line 
1// Class automatically generated by Dev-C++ New Class wizard
2
3#include "AnalyzerData.h" // class's header file
4
5// class constructor
6AnalyzerData::AnalyzerData()
7{
8    init();
9}
10
11void AnalyzerData::init()
12{
13    nVars = 0;
14    nUsedVars = 0;
15   
16    nOriginalClauses = 0;
17   
18    nRemovedClauses = 0;   
19   
20    nAddedClauses = 0;
21   
22    evalData.clear();
23    evalData.resize(XX_MAX_IDX,0.0);
24   
25    nReceivedSatAssignments = 0;   
26   
27    rnProbOfSat = 0.0;   
28     
29    nConflicts = 0;
30    nImplications = 0;
31    nImplicitImplications = 0;
32    nProcessedComponents = 0;
33       
34    maxDecLevel = 0;
35    nDecisions = 0;   
36}
37
38void AnalyzerData::loadFromFile(const char *lpcstrFileName)
39{
40  ifstream in(lpcstrFileName);
41 
42  init();
43 
44  const int sz = 1024;
45  char buf[sz];
46  char desc[100];
47 
48  bool valIdentified = false;
49 
50  memset(desc,0,100);
51  while(in.getline(desc,100))
52  {
53    valIdentified = false;
54   
55    for(unsigned int i = 0; i < INT_MAX_ID; i++)
56     if(!strcmp(desc,intDataDesc[i]))
57      {
58        valIdentified = true;   
59        in.getline(buf,sz);
60        setI((INT_DATA_ID) i, atoi(buf));
61        break;
62      }   
63   
64   
65    if(!valIdentified)
66     for(int i = 0; i < XX_MAX_IDX; i++)
67      if(!strcmp(desc,doubleDataDesc[i]))
68      {
69        valIdentified = true;
70        in.getline(buf,sz);
71        evalData[i] = strtod(buf,NULL);
72        break;
73      }   
74     
75    if(!valIdentified)
76    {
77      if(!strcmp(desc,"time"))
78      {
79       in.getline(buf,sz);
80       elapsedTime = strtod(buf,NULL);
81      }       
82      else if(!strcmp(desc,"SolverExitState"))
83      {
84         in.getline(buf,sz);
85         theExitState = (SOLVER_StateT) atoi(buf);
86      } else if(!strcmp(desc,"rnProbOfSAT"))
87      {
88         in >> rnProbOfSat;     
89      }   
90    }     
91  }
92}
93
94
95void AnalyzerData::writeToFile(const char *lpcstrFileName) const
96{
97  ofstream out(lpcstrFileName);
98 
99  for(int i = 0; i < INT_MAX_ID;i++)
100  {
101     out<<intDataDesc[i]<<endl;   
102     out<<getI((INT_DATA_ID)i)<<endl;
103  }
104 
105  for(int i = 0; i < XX_MAX_IDX;i++)
106  {
107     out<<doubleDataDesc[i]<<endl;   
108     out<<get((DATA_IDX)i)<<endl;
109  }
110 
111  out<<"time"<<endl;
112  out<<elapsedTime<<endl;
113   
114  out<<"SolverExitState"<<endl;
115  out<<theExitState<<endl;
116 
117  #ifdef GMP_BIGNUM
118    char buf[nVars+2];
119    memset(buf,0,nVars+2);
120    mp_exp_t exp;
121    mpf_get_str(buf,&exp,10,nVars+2,rnProbOfSat.get_mpf_t());
122 
123    out<<"rnProbOfSAT"<<endl;
124    out<<"0."<<buf<<"e"<<exp<<endl;
125  #else
126    out<<"rnProbOfSAT"<<endl;
127    out<<rnProbOfSat<<endl;
128  #endif
129}
130
131
132
133unsigned int AnalyzerData::getI(INT_DATA_ID idataID) const
134{
135  unsigned int res = 0;
136 
137  switch(idataID)
138  {
139    case NVARS: res = nVars;
140                break;
141    case NUSED_VARS: res = nUsedVars;
142                break;
143    case NORIGINAL_CLAUSES: res = nOriginalClauses;
144                break;
145    case NREMOVED_CLAUSES: res = nRemovedClauses;
146                break;
147    case NADDED_CLAUSES: res = nAddedClauses;
148                break;
149    case NRECEIVED_ASS:  res = nReceivedSatAssignments;
150                break;
151    case NCONFLICTS: res = nConflicts; 
152                break;
153    case NIMPLICATIONS: res = nImplications; 
154                break;
155    case NIBCPIMPLS: res = nImplicitImplications; 
156                break;
157    case NPROCESSED_COMPS:res = nProcessedComponents; 
158                break;
159    case MAX_DL: res = maxDecLevel; 
160                break;
161    case MAX_SOL_DL: res = maxSolutionLevel;
162                break;
163    case NDECISIONS: res = nDecisions;     
164                break;
165    default: break;
166  };
167
168  return res;
169}
170
171
172bool AnalyzerData::setI(INT_DATA_ID idataID, int val)
173{ 
174  switch(idataID)
175  {
176    case NVARS: nVars = val;
177                break;
178    case NUSED_VARS: nUsedVars = val;
179                break;
180    case NORIGINAL_CLAUSES: nOriginalClauses = val;
181                break;
182    case NREMOVED_CLAUSES: nRemovedClauses = val;
183                break;
184    case NADDED_CLAUSES: nAddedClauses = val;
185                break;
186    case NRECEIVED_ASS:  nReceivedSatAssignments = val;
187                break;
188    case NCONFLICTS: nConflicts = val; 
189                break;
190    case NIMPLICATIONS: nImplications = val; 
191                break;
192    case NIBCPIMPLS: nImplicitImplications = val; 
193                break;
194    case NPROCESSED_COMPS: nProcessedComponents = val; 
195                break;
196    case MAX_DL:  maxDecLevel = val; 
197                break;
198    case MAX_SOL_DL: maxSolutionLevel = val;
199                break;
200    case NDECISIONS: nDecisions = val;     
201                break;
202    default: return false;
203  };
204  return true;
205}
206
207// class destructor
208AnalyzerData::~AnalyzerData()
209{
210        // insert your code here
211}
212
213
214CRunAnalyzer::CRunAnalyzer()
215{
216        // insert your code here
217}
218
219
220
221
222
223const AnalyzerData &CRunAnalyzer::getData() const
224{               
225    return theData;             
226}
227               
228void CRunAnalyzer::init(int nVars, int nClauses)
229{
230    theData.init();
231       
232        theData.nVars = nVars;
233        theData.nOriginalClauses = nClauses;   
234       
235    first = true;
236}
237       
238
239void CRunAnalyzer::setValue(DATA_IDX dataIDX, double someData) 
240{
241   theData.evalData[dataIDX] = someData;
242}
243
244void CRunAnalyzer::addValue(ID_DATA dataID, int actDecLevel, double someData)
245{
246   switch(dataID)
247   {
248      case CCL_1stUIP:     
249         if(someData > theData.evalData[LONGEST_CCL_1stUIP])
250                      theData.evalData[LONGEST_CCL_1stUIP] = someData;
251         theData.evalData[AVG_CCL_1stUIP] += (double) someData;
252         break;
253         
254      case CCL_lastUIP:     
255         if(someData > theData.evalData[LONGEST_CCL_lastUIP])
256                      theData.evalData[LONGEST_CCL_lastUIP] = someData;
257         theData.evalData[AVG_CCL_lastUIP] += (double) someData;
258         break;
259         
260      case CONFLICT:         
261         theData.nConflicts+= (int) someData;
262         theData.evalData[AVG_CONFLICT_LEV] += (double) actDecLevel;
263         theData.evalData[AVG_DEC_LEV] += (double) actDecLevel;
264         break;
265         
266      case DECISION:
267         theData.nDecisions++;
268         
269         if (actDecLevel > theData.maxDecLevel)
270               theData.maxDecLevel = actDecLevel;
271         break; 
272
273      case SOLUTION:
274         
275         theData.evalData[AVG_SOLUTION_LEV] += (double) actDecLevel;
276         theData.evalData[AVG_DEC_LEV] += (double) actDecLevel;   
277         theData.nReceivedSatAssignments++; 
278         break;
279         
280      case IMPLICATION:
281     
282         theData.nImplications += (int) someData;
283         break;         
284      case IBCPIMPL:
285         theData.nImplicitImplications += (int) someData;
286         break;         
287   };
288}     
289
290void CRunAnalyzer::addClause()
291{
292    theData.nAddedClauses++;
293}
294 
295
296void CRunAnalyzer::setUsedVars(unsigned int nUsedVars)
297{
298    theData.nUsedVars = nUsedVars;
299}
300
301void CRunAnalyzer::setSatCount(const CRealNum &rnCodedSols)
302{ 
303 to_div_2exp(theData.rnProbOfSat,rnCodedSols,theData.nUsedVars); 
304}
305
306/*
307bool CRunAnalyzer::includeInPrBackBone(CAssignment &s, double nSols)
308{
309    //theData.thePrBackBone.include(s,nSols);
310        return true;
311}
312*/
313
314CRunAnalyzer::~CRunAnalyzer()
315{
316        // insert your code here
317}
318
319// No description
320void CRunAnalyzer::finishcountSATAnalysis()
321{
322   theData.finishcountSATAnalysis();
323}
324
325
326void AnalyzerData::finishcountSATAnalysis()
327{
328   if (nConflicts != 0)
329   {
330      evalData[AVG_CONFLICT_LEV] /= (double) nConflicts + nImplicitImplications;
331      evalData[AVG_CCL_1stUIP] /= (double) nConflicts + nImplicitImplications;
332      evalData[AVG_CCL_lastUIP] /= (double)nConflicts + nImplicitImplications; 
333   }
334   
335   if (nReceivedSatAssignments != 0)
336   {
337      evalData[AVG_SOLUTION_LEV] /= (double) nReceivedSatAssignments;   
338   }
339   else evalData[AVG_SOLUTION_LEV] = 0.0;
340   
341   if (nConflicts != 0  || nReceivedSatAssignments != 0)
342      evalData[AVG_DEC_LEV] /= (double) nConflicts + nReceivedSatAssignments;   
343}
344
Note: See TracBrowser for help on using the repository browser.