CVC3

search.cpp

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file search.cpp
00004  *
00005  * Author: Clark Barrett, Vijay Ganesh (CNF Converter)
00006  *
00007  * Created: Fri Jan 17 14:19:54 2003
00008  *
00009  * <hr>
00010  *
00011  * License to use, copy, modify, sell and/or distribute this software
00012  * and its documentation for any purpose is hereby granted without
00013  * royalty, subject to the terms and conditions defined in the \ref
00014  * LICENSE file provided with this distribution.
00015  *
00016  * <hr>
00017  *
00018  */
00019 /*****************************************************************************/
00020 
00021 
00022 #include "search.h"
00023 #include "search_rules.h"
00024 #include "theory_core.h"
00025 #include "eval_exception.h"
00026 #include "theorem_manager.h"
00027 #include "command_line_flags.h"
00028 
00029 
00030 using namespace CVC3;
00031 using namespace std;
00032 
00033 
00034 //! Constructor
00035 SearchEngine::SearchEngine(TheoryCore* core)
00036   : d_core(core),
00037     d_commonRules(core->getTM()->getRules())
00038 {
00039 
00040   const CLFlags& flg  = (core->getTM()->getFlags());
00041   if (flg["lfsc-mode"].getInt()!= 0){
00042     d_rules = createRules(this);
00043 
00044   }
00045   else
00046     d_rules = createRules();
00047 
00048 }
00049 
00050 
00051 //! Destructor
00052 SearchEngine::~SearchEngine()
00053 {
00054   delete d_rules;
00055 }
00056 
00057 bool SearchEngine::tryModelGeneration(Theorem& thm) {
00058 
00059   if(!lastThm().isNull()) throw EvalException("Method tryModelGenereation() (or command COUNTERMODEL)\n must be called only after failed QUERY");
00060 
00061   // Save the scope level, to recover on errors
00062   push();
00063   d_core->collectBasicVars();
00064   bool success = d_core->refineCounterExample(thm);
00065   if (!success) {
00066     pop();
00067     return false;
00068   }
00069 
00070   QueryResult qres = checkValid(d_core->falseExpr(), thm);
00071   if(qres == VALID) {
00072     pop();
00073     return false;
00074   }
00075 
00076   success = d_core->buildModel(thm);
00077   if (!success) {
00078       pop();
00079       return false;
00080   }
00081 
00082   qres = checkValid(d_core->falseExpr(), thm);
00083   if(qres == VALID) {
00084       pop();
00085       return false;
00086   }
00087 
00088   return true;
00089 }
00090 
00091 void SearchEngine::getConcreteModel(ExprMap<Expr>& m)
00092 {
00093   TRACE("model" ,  "Building a concrete model", "", "{");
00094   if(!lastThm().isNull())
00095     throw EvalException
00096       ("Method getConcreteModel() (or command COUNTERMODEL)\n"
00097        " must be called only after failed QUERY");
00098   // Save the scope level, to recover on errors
00099   push();
00100   d_core->collectBasicVars();
00101   try {
00102     d_core->refineCounterExample();
00103   } catch(Exception& e) {
00104     // Clean up and re-throw the exception
00105     pop();
00106     throw e;
00107   }
00108   Theorem thm;
00109   QueryResult qres = checkValid(d_core->falseExpr(), thm);
00110   if(qres == VALID) {
00111     vector<Expr> assump;
00112     getAssumptions(assump);
00113     d_core->inconsistentThm().getLeafAssumptions(assump);
00114     Expr a = Expr(RAW_LIST, assump, d_core->getEM());
00115     pop();
00116     throw Exception
00117       ("Model Creation failed after refining counterexample\n"
00118        "due to the following assumptions:\n "
00119        +a.toString()
00120        +"\n\nYou might be using an incomplete fragment of the theory");
00121   }
00122 //   else if (qres != INVALID) {
00123 //     throw EvalException
00124 //       ("Unable to build concrete model");
00125 //   }
00126   try {
00127     d_core->buildModel(m);
00128   } catch(Exception& e) {
00129     // Clean up and re-throw the exception
00130     pop();
00131     throw e;
00132   }
00133   qres = checkValid(d_core->falseExpr(), thm);
00134   if(qres == VALID) {
00135     vector<Expr> assump;
00136     getAssumptions(assump);
00137     Expr a = Expr(RAW_LIST, assump, d_core->getEM());
00138     pop();
00139     throw Exception
00140       ("Model Creation failed due to the following assumptions:\n"
00141        +a.toString()
00142        +"\n\nYou might be using an incomplete fragment of the theory");
00143   }
00144 //   else if (qres != INVALID) {
00145 //     throw EvalException
00146 //       ("Unable to build concrete model");
00147 //   }
00148   TRACE("model" ,  "Building a concrete model", "", "}");
00149 }