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  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00011  * Junior University and by New York University. 
00012  *
00013  * License to use, copy, modify, sell and/or distribute this software
00014  * and its documentation for any purpose is hereby granted without
00015  * royalty, subject to the terms and conditions defined in the \ref
00016  * LICENSE file provided with this distribution.  In particular:
00017  *
00018  * - The above copyright notice and this permission notice must appear
00019  * in all copies of the software and related documentation.
00020  *
00021  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00022  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00023  * 
00024  * <hr>
00025  * 
00026  */
00027 /*****************************************************************************/
00028 
00029 
00030 #include "search.h"
00031 #include "search_rules.h"
00032 #include "theory_core.h"
00033 #include "eval_exception.h"
00034 #include "theorem_manager.h"
00035 
00036 
00037 using namespace CVCL;
00038 using namespace std;
00039 
00040 
00041 //! Constructor
00042 SearchEngine::SearchEngine(TheoryCore* core)
00043   : d_core(core),
00044     d_commonRules(core->getTM()->getRules())
00045 {
00046   d_rules = createRules();
00047 }
00048 
00049 
00050 //! Destructor
00051 SearchEngine::~SearchEngine()
00052 {
00053   delete d_rules;
00054 }
00055 
00056 
00057 void SearchEngine::getConcreteModel(ExprMap<Expr> & m)
00058 {
00059   TRACE("model" ,  "Building a concrete model", "", "{");
00060   if(!lastThm().isNull())
00061     throw EvalException
00062       ("Method getConcreteModel() (or command COUNTERMODEL)\n"
00063        " must be called only after failed QUERY");
00064   // Save the scope level, to recover on errors
00065   int scope = d_core->getCM()->scopeLevel();
00066   d_core->getCM()->push();
00067   d_core->collectBasicVars();
00068   bool v;
00069   try {
00070     d_core->refineCounterExample();
00071   } catch(Exception& e) {
00072     // Clean up and re-throw the exception
00073     d_core->getCM()->popto(scope);
00074     throw e;
00075   }
00076   v =!checkValid(d_core->falseExpr()).isNull();
00077   if(v) {
00078     vector<Expr> assump;
00079     getAssumptions(assump);
00080     d_core->inconsistentThm().getLeafAssumptions(assump);
00081     Expr a = Expr(RAW_LIST, assump, d_core->getEM());
00082     d_core->getCM()->popto(scope);
00083     throw EvalException
00084       ("Model Creation failed after refining counterexample\n"
00085        "due to the following assumptions:\n "
00086        +a.toString()       
00087        +"\n\nYou might be using an incomplete fragment of the theory");
00088   }
00089   try {
00090     d_core->buildModel(m);
00091   } catch(Exception& e) {
00092     // Clean up and re-throw the exception
00093     d_core->getCM()->popto(scope);
00094     throw e;
00095   }
00096   v =!checkValid(d_core->falseExpr()).isNull();
00097   if(v) {
00098     vector<Expr> assump;
00099     getAssumptions(assump);
00100     Expr a = Expr(RAW_LIST, assump, d_core->getEM());
00101     d_core->getCM()->popto(scope);
00102     throw EvalException
00103       ("Model Creation failed due to the following assumptions:\n"
00104        +a.toString()
00105        +"\n\nYou might be using an incomplete fragment of the theory");
00106   }
00107   TRACE("model" ,  "Building a concrete model", "", "}"); 
00108 }

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