decision_engine_mbtf.cpp

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file decision_engine_mbtf.cpp
00004  * \brief Decision Engine
00005  * 
00006  * <hr>
00007  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00008  * Junior University and by New York University. 
00009  *
00010  * License to use, copy, modify, sell and/or distribute this software
00011  * and its documentation for any purpose is hereby granted without
00012  * royalty, subject to the terms and conditions defined in the \ref
00013  * LICENSE file provided with this distribution.  In particular:
00014  *
00015  * - The above copyright notice and this permission notice must appear
00016  * in all copies of the software and related documentation.
00017  *
00018  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00019  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00020  * 
00021  * <hr>
00022  * 
00023  */
00024 /*****************************************************************************/
00025 
00026 
00027 #include "decision_engine_mbtf.h"
00028 #include "theory_core.h"
00029 #include "search.h"
00030 
00031 
00032 using namespace std;
00033 using namespace CVCL;
00034 
00035 #define CACHE_SIZE 20
00036 #define BASE_TRUST_LEVEL 2
00037 #define TURNOVER_RATE 10
00038 
00039 bool DecisionEngineMBTF::isBetter(const Expr& e1, const Expr& e2)
00040 {
00041   ExprMap<int>::iterator it1 = d_index.find(e1.getSimpFrom());
00042   ExprMap<int>::iterator it2 = d_index.find(e2.getSimpFrom());
00043 
00044   if (it1 != d_index.end() &&
00045       (d_cache[it1->second].d_trust >= d_height) &&
00046       (it2 == d_index.end() ||
00047        d_cache[it1->second].d_rank < d_cache[it2->second].d_rank))
00048     return true;
00049   else
00050     return false;
00051 }
00052 
00053 
00054 DecisionEngineMBTF::DecisionEngineMBTF(TheoryCore* core, SearchImplBase* se)
00055   : DecisionEngine(core, se),
00056     d_startLevel(core->getCM()->scopeLevel()),
00057     d_bottomLevel(0),
00058     d_topLevel(0),
00059     d_topLevelLock(false),
00060     d_height(0),
00061     d_cache(CACHE_SIZE)
00062 {
00063 }
00064 
00065 
00066 Expr DecisionEngineMBTF::findSplitter(const Expr& e) {
00067   d_visited.clear();
00068   Expr splitter; // Null by default
00069   if (!e.isNull())
00070   {
00071     d_height = e.getHeight() - 1;
00072     // heights seem to be 1 greater than SVC
00073     // probably because of top-level NOT
00074 
00075     if (!d_topLevelLock)
00076     {
00077       d_topLevel = d_core->getCM()->scopeLevel();
00078       d_topLevelLock = true;
00079     }
00080 
00081     splitter = findSplitterRec(e);
00082     DebugAssert(!splitter.isNull(),
00083                 "findSplitter: can't find splitter in non-literal: "
00084                 + e.toString());
00085     IF_DEBUG(debugger.counter("splitters from non-literals")++);
00086   }
00087   TRACE("splitters verbose", "findSplitter() => ", splitter, "");
00088   return splitter;
00089 }
00090 
00091 
00092 void DecisionEngineMBTF::goalSatisfied()
00093 {
00094   if (d_core->getCM()->scopeLevel() - d_bottomLevel != 0)
00095   {
00096     d_bottomLevel = d_core->getCM()->scopeLevel();
00097     return;
00098   }
00099 
00100   if (d_splitters.size() == 0)
00101     return;
00102 
00103   if (!d_topLevelLock)
00104     d_topLevel = d_bottomLevel - 1;
00105   d_topLevelLock = false;
00106 
00107   int numSplitters = d_bottomLevel - d_startLevel - 1;
00108   int numNewSplitters = d_bottomLevel - d_topLevel;
00109 
00110   vector<CacheEntry> newCache(numSplitters);
00111   ExprMap<int> newIndex;
00112 
00113   int end = d_splitters.size();
00114   int start = end - numSplitters;
00115   if (start < 0)
00116     start = 0;
00117 
00118   const Expr& s = d_splitters[max(0, end - numNewSplitters)];
00119   Expr topSplitter = s.getSimpFrom();
00120   if(!topSplitter.isAbsAtomicFormula()) topSplitter = s;
00121 
00122   ExprMap<int>::iterator it = d_index.find(topSplitter);
00123   int maxTrust = (it != d_index.end()) ? d_cache[it->second].d_trust : numSplitters;
00124 
00125   for (int i = end - 1, j = 0; i >= start; i--, j++)
00126   {
00127     const Expr& s = d_splitters[i];
00128     Expr splitter = s.getSimpFrom();
00129     if(!splitter.isAbsAtomicFormula()) splitter = s;
00130     newCache[j].d_expr = splitter;
00131     newCache[j].d_rank = (numSplitters - j) % numSplitters;
00132     newIndex[splitter] = j;
00133 
00134     ExprMap<int>::iterator it = d_index.find(splitter);
00135     if (j == 0) // the effective splitter
00136       newCache[j].d_trust = maxTrust;
00137     else if (it != d_index.end())
00138       newCache[j].d_trust = max(d_cache[it->second].d_trust - 1, 0);
00139   }
00140 
00141   d_cache = newCache;
00142   d_index = newIndex;
00143   d_bestByExpr.clear();
00144 }

Generated on Thu Apr 13 16:57:30 2006 for CVC Lite by  doxygen 1.4.4