Refactor initialization of quantifiers model and builder (#6175)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Fri, 19 Mar 2021 18:05:47 +0000 (13:05 -0500)
committerGitHub <noreply@github.com>
Fri, 19 Mar 2021 18:05:47 +0000 (18:05 +0000)
This is in preparation for breaking several circular dependencies and moving
the instantiate utility into the theory inference manager.

src/theory/quantifiers/quantifiers_modules.cpp
src/theory/quantifiers/quantifiers_modules.h
src/theory/quantifiers/theory_quantifiers.cpp
src/theory/quantifiers/theory_quantifiers.h
src/theory/quantifiers_engine.cpp
src/theory/quantifiers_engine.h
src/theory/theory_engine.cpp

index 0b1f18f5b74cfd7b9e8f35a6cebf6acaae426a9d..11d9a116c1dd2a0d1c1129aa316d02de35a64546 100644 (file)
@@ -27,6 +27,7 @@ QuantifiersModules::QuantifiersModules()
       d_alpha_equiv(nullptr),
       d_inst_engine(nullptr),
       d_model_engine(nullptr),
+      d_builder(nullptr),
       d_bint(nullptr),
       d_qcf(nullptr),
       d_sg_gen(nullptr),
@@ -82,6 +83,22 @@ void QuantifiersModules::initialize(QuantifiersEngine* qe,
   {
     d_model_engine.reset(new ModelEngine(qe, qs, qim, qr));
     modules.push_back(d_model_engine.get());
+    Trace("quant-init-debug")
+        << "Initialize model engine, mbqi : " << options::mbqiMode() << " "
+        << options::fmfBound() << std::endl;
+    if (useFmcModel())
+    {
+      Trace("quant-init-debug") << "...make fmc builder." << std::endl;
+      d_builder.reset(new fmcheck::FullModelChecker(qs, qr));
+    }
+    else
+    {
+      Trace("quant-init-debug")
+          << "...make default model builder." << std::endl;
+      d_builder.reset(new QModelBuilder(qs, qr));
+    }
+    // !!!!!!!!!!!!! temporary (project #15)
+    d_builder->finishInit(qe);
   }
   if (options::quantDynamicSplit() != options::QuantDSplitMode::NONE)
   {
@@ -106,6 +123,13 @@ void QuantifiersModules::initialize(QuantifiersEngine* qe,
   }
 }
 
+bool QuantifiersModules::useFmcModel()
+{
+  return options::mbqiMode() == options::MbqiMode::FMC
+         || options::mbqiMode() == options::MbqiMode::TRUST
+         || options::fmfBound();
+}
+
 }  // namespace quantifiers
 }  // namespace theory
 }  // namespace CVC4
index 3b460283b253038fffe1e3b93fc59093c16e6d01..c111eba258b0268fa6625bc54b06d7a62986860c 100644 (file)
@@ -21,6 +21,8 @@
 #include "theory/quantifiers/conjecture_generator.h"
 #include "theory/quantifiers/ematching/instantiation_engine.h"
 #include "theory/quantifiers/fmf/bounded_integers.h"
+#include "theory/quantifiers/fmf/full_model_check.h"
+#include "theory/quantifiers/fmf/model_builder.h"
 #include "theory/quantifiers/fmf/model_engine.h"
 #include "theory/quantifiers/inst_strategy_enumerative.h"
 #include "theory/quantifiers/quant_conflict_find.h"
@@ -59,6 +61,9 @@ class QuantifiersModules
                   DecisionManager* dm,
                   std::vector<QuantifiersModule*>& modules);
 
+  /** Whether we use the full model check builder and corresponding model */
+  static bool useFmcModel();
+
  private:
   //------------------------------ quantifier utilities
   /** relevant domain */
@@ -70,6 +75,8 @@ class QuantifiersModules
   std::unique_ptr<InstantiationEngine> d_inst_engine;
   /** model engine */
   std::unique_ptr<ModelEngine> d_model_engine;
+  /** model builder */
+  std::unique_ptr<quantifiers::QModelBuilder> d_builder;
   /** bounded integers utility */
   std::unique_ptr<BoundedIntegers> d_bint;
   /** Conflict find mechanism for quantifiers */
index e054fd3097e530c76ad3155103e0678a26a39eb6..5bcc80eb032554a538333ecf68954eb8d16bef55 100644 (file)
 
 #include "theory/quantifiers/theory_quantifiers.h"
 
-#include "base/check.h"
-#include "expr/kind.h"
 #include "expr/proof_node_manager.h"
 #include "options/quantifiers_options.h"
-#include "theory/quantifiers/ematching/instantiation_engine.h"
-#include "theory/quantifiers/fmf/model_engine.h"
-#include "theory/quantifiers/quantifiers_attributes.h"
+#include "theory/quantifiers/first_order_model.h"
+#include "theory/quantifiers/fmf/first_order_model_fmc.h"
+#include "theory/quantifiers/quantifiers_modules.h"
 #include "theory/quantifiers/quantifiers_rewriter.h"
-#include "theory/quantifiers/term_database.h"
-#include "theory/quantifiers/term_util.h"
-#include "theory/quantifiers_engine.h"
 #include "theory/valuation.h"
 
 using namespace CVC4::kind;
@@ -46,8 +41,7 @@ TheoryQuantifiers::TheoryQuantifiers(Context* c,
       d_qstate(c, u, valuation, logicInfo),
       d_qreg(),
       d_treg(d_qstate, d_qreg),
-      d_qim(*this, d_qstate, pnm),
-      d_qengine(d_qstate, d_qreg, d_treg, d_qim, pnm)
+      d_qim(*this, d_qstate, pnm)
 {
   // Finish initializing the term registry by hooking it up to the inference
   // manager. This is required due to a cyclic dependency between the term
@@ -73,10 +67,42 @@ TheoryQuantifiers::TheoryQuantifiers(Context* c,
   // use the inference manager as the official inference manager
   d_inferManager = &d_qim;
 
+  Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl;
+  Trace("quant-engine-debug")
+      << "Initialize model, mbqi : " << options::mbqiMode() << std::endl;
+  // Finite model finding requires specialized ways of building the model.
+  // We require constructing the model here, since it is required for
+  // initializing the CombinationEngine and the rest of quantifiers engine.
+  if (options::finiteModelFind() || options::fmfBound())
+  {
+    if (QuantifiersModules::useFmcModel())
+    {
+      d_qmodel.reset(new quantifiers::fmcheck::FirstOrderModelFmc(
+          d_qstate, d_qreg, d_treg, "FirstOrderModelFmc"));
+    }
+    else
+    {
+      d_qmodel.reset(new quantifiers::FirstOrderModel(
+          d_qstate, d_qreg, d_treg, "FirstOrderModel"));
+    }
+  }
+  else
+  {
+    d_qmodel.reset(new quantifiers::FirstOrderModel(
+        d_qstate, d_qreg, d_treg, "FirstOrderModel"));
+  }
+
+  // construct the quantifiers engine
+  d_qengine.reset(new QuantifiersEngine(
+      d_qstate, d_qreg, d_treg, d_qim, d_qmodel.get(), pnm));
+
+  //!!!!!!!!!!!!!! temporary (project #15)
+  d_qmodel->finishInit(d_qengine.get());
+
   // Set the pointer to the quantifiers engine, which this theory owns. This
   // pointer will be retreived by TheoryEngine and set to all theories
   // post-construction.
-  d_quantEngine = &d_qengine;
+  d_quantEngine = d_qengine.get();
 }
 
 TheoryQuantifiers::~TheoryQuantifiers() {
index e9785fcea29021cf2e6271346201a89d465dc50e..9714ec71841fb9ff9ebf717132def23a6e0e3e5b 100644 (file)
@@ -20,6 +20,7 @@
 #define CVC4__THEORY__QUANTIFIERS__THEORY_QUANTIFIERS_H
 
 #include "expr/node.h"
+#include "theory/quantifiers/first_order_model.h"
 #include "theory/quantifiers/proof_checker.h"
 #include "theory/quantifiers/quantifiers_inference_manager.h"
 #include "theory/quantifiers/quantifiers_registry.h"
@@ -87,13 +88,15 @@ class TheoryQuantifiers : public Theory {
   /** The quantifiers state */
   QuantifiersState d_qstate;
   /** The quantifiers registry */
-  quantifiers::QuantifiersRegistry d_qreg;
+  QuantifiersRegistry d_qreg;
+  /** extended model object */
+  std::unique_ptr<FirstOrderModel> d_qmodel;
   /** The term registry */
-  quantifiers::TermRegistry d_treg;
+  TermRegistry d_treg;
   /** The quantifiers inference manager */
   QuantifiersInferenceManager d_qim;
   /** The quantifiers engine, which lives here */
-  QuantifiersEngine d_qengine;
+  std::unique_ptr<QuantifiersEngine> d_qengine;
 };/* class TheoryQuantifiers */
 
 }/* CVC4::theory::quantifiers namespace */
index d6aaeed3f414edfc9a4e99c9ae153c9694e8d10f..7d5c4cf1941190a9ee25d11f2da91af3331fe842 100644 (file)
@@ -51,6 +51,7 @@ QuantifiersEngine::QuantifiersEngine(
     quantifiers::QuantifiersRegistry& qr,
     quantifiers::TermRegistry& tr,
     quantifiers::QuantifiersInferenceManager& qim,
+    quantifiers::FirstOrderModel* qm,
     ProofNodeManager* pnm)
     : d_qstate(qstate),
       d_qim(qim),
@@ -60,58 +61,20 @@ QuantifiersEngine::QuantifiersEngine(
       d_qreg(qr),
       d_treg(tr),
       d_tr_trie(new inst::TriggerTrie),
-      d_model(nullptr),
-      d_builder(nullptr),
-      d_eq_query(nullptr),
+      d_model(qm),
+      d_eq_query(new quantifiers::EqualityQueryQuantifiersEngine(qstate, qm)),
       d_instantiate(
           new quantifiers::Instantiate(this, qstate, qim, d_qreg, pnm)),
       d_skolemize(new quantifiers::Skolemize(d_qstate, d_pnm)),
       d_quants_prereg(qstate.getUserContext()),
       d_quants_red(qstate.getUserContext())
 {
-  //---- utilities
-  // quantifiers registry must come before the other utilities
+  // initialize the utilities
+  d_util.push_back(d_eq_query.get());
+  // quantifiers registry must come before the remaining utilities
   d_util.push_back(&d_qreg);
   d_util.push_back(tr.getTermDatabase());
-
   d_util.push_back(d_instantiate.get());
-
-  Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl;
-  Trace("quant-engine-debug") << "Initialize model, mbqi : " << options::mbqiMode() << std::endl;
-
-  //---- end utilities
-
-  // Finite model finding requires specialized ways of building the model.
-  // We require constructing the model and model builder here, since it is
-  // required for initializing the CombinationEngine.
-  if (options::finiteModelFind() || options::fmfBound())
-  {
-    Trace("quant-engine-debug") << "Initialize model engine, mbqi : " << options::mbqiMode() << " " << options::fmfBound() << std::endl;
-    if (options::mbqiMode() == options::MbqiMode::FMC
-        || options::mbqiMode() == options::MbqiMode::TRUST
-        || options::fmfBound())
-    {
-      Trace("quant-engine-debug") << "...make fmc builder." << std::endl;
-      d_model.reset(new quantifiers::fmcheck::FirstOrderModelFmc(
-          qstate, qr, tr, "FirstOrderModelFmc"));
-      d_builder.reset(new quantifiers::fmcheck::FullModelChecker(qstate, qr));
-    }else{
-      Trace("quant-engine-debug") << "...make default model builder." << std::endl;
-      d_model.reset(
-          new quantifiers::FirstOrderModel(qstate, qr, tr, "FirstOrderModel"));
-      d_builder.reset(new quantifiers::QModelBuilder(qstate, qr));
-    }
-    d_builder->finishInit(this);
-  }else{
-    d_model.reset(
-        new quantifiers::FirstOrderModel(qstate, qr, tr, "FirstOrderModel"));
-  }
-  //!!!!!!!!!!!!!!!!!!!!! temporary (project #15)
-  d_model->finishInit(this);
-  // initialize the equality query
-  d_eq_query.reset(
-      new quantifiers::EqualityQueryQuantifiersEngine(qstate, d_model.get()));
-  d_util.insert(d_util.begin(), d_eq_query.get());
 }
 
 QuantifiersEngine::~QuantifiersEngine() {}
@@ -157,11 +120,11 @@ quantifiers::QuantifiersRegistry& QuantifiersEngine::getQuantifiersRegistry()
 
 quantifiers::QModelBuilder* QuantifiersEngine::getModelBuilder() const
 {
-  return d_builder.get();
+  return d_qmodules->d_builder.get();
 }
 quantifiers::FirstOrderModel* QuantifiersEngine::getModel() const
 {
-  return d_model.get();
+  return d_model;
 }
 quantifiers::TermDb* QuantifiersEngine::getTermDatabase() const
 {
index 92b90c375fc636c55d9723e713db9ad34c4e498e..625bac40a75edc3991e760007328a27460f5872f 100644 (file)
@@ -68,6 +68,7 @@ class QuantifiersEngine {
                     quantifiers::QuantifiersRegistry& qr,
                     quantifiers::TermRegistry& tr,
                     quantifiers::QuantifiersInferenceManager& qim,
+                    quantifiers::FirstOrderModel* qm,
                     ProofNodeManager* pnm);
   ~QuantifiersEngine();
   //---------------------- external interface
@@ -247,9 +248,7 @@ public:
   /** all triggers will be stored in this trie */
   std::unique_ptr<inst::TriggerTrie> d_tr_trie;
   /** extended model object */
-  std::unique_ptr<quantifiers::FirstOrderModel> d_model;
-  /** model builder */
-  std::unique_ptr<quantifiers::QModelBuilder> d_builder;
+  quantifiers::FirstOrderModel* d_model;
   /** equality query class */
   std::unique_ptr<quantifiers::EqualityQueryQuantifiersEngine> d_eq_query;
   /** instantiate utility */
index 64181a8ee2121be1fbbabcf6cc4deb360711f398..efa3f916384a4fa36ee6a5efd4925a28698bc6bc 100644 (file)
@@ -167,18 +167,19 @@ void TheoryEngine::finishInit()
     d_quantEngine = d_theoryTable[THEORY_QUANTIFIERS]->getQuantifiersEngine();
     Assert(d_quantEngine != nullptr);
   }
+  // finish initializing the quantifiers engine, which must come before
+  // initializing theory combination, since quantifiers engine may have a
+  // special model builder object
+  if (d_logicInfo.isQuantified())
+  {
+    d_quantEngine->finishInit(this, d_decManager.get());
+  }
   // initialize the theory combination manager, which decides and allocates the
   // equality engines to use for all theories.
   d_tc->finishInit();
   // get pointer to the shared solver
   d_sharedSolver = d_tc->getSharedSolver();
 
-  // finish initializing the quantifiers engine
-  if (d_logicInfo.isQuantified())
-  {
-    d_quantEngine->finishInit(this, d_decManager.get());
-  }
-
   // finish initializing the theories by linking them with the appropriate
   // utilities and then calling their finishInit method.
   for(TheoryId theoryId = theory::THEORY_FIRST; theoryId != theory::THEORY_LAST; ++ theoryId) {