00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00042 SearchEngine::SearchEngine(TheoryCore* core)
00043 : d_core(core),
00044 d_commonRules(core->getTM()->getRules())
00045 {
00046 d_rules = createRules();
00047 }
00048
00049
00050
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
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
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
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 }