Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Management of a distributed approach for model generation. 11 : : */ 12 : : 13 : : #include "theory/model_manager_distributed.h" 14 : : 15 : : #include "smt/env.h" 16 : : #include "theory/theory_engine.h" 17 : : #include "theory/theory_model.h" 18 : : #include "theory/theory_model_builder.h" 19 : : 20 : : namespace cvc5::internal { 21 : : namespace theory { 22 : : 23 : 51327 : ModelManagerDistributed::ModelManagerDistributed(Env& env, 24 : : TheoryEngine& te, 25 : 51327 : EqEngineManager& eem) 26 : 51327 : : ModelManager(env, te, eem) 27 : : { 28 : 51327 : } 29 : : 30 : 101958 : ModelManagerDistributed::~ModelManagerDistributed() 31 : : { 32 : : // pop the model context which we pushed on initialization 33 : 50979 : d_modelEeContext.pop(); 34 : 101958 : } 35 : : 36 : 51327 : void ModelManagerDistributed::initializeModelEqEngine( 37 : : eq::EqualityEngineNotify* notify) 38 : : { 39 : : // initialize the model equality engine, use the provided notification object, 40 : : // which belongs e.g. to CombinationModelBased 41 : 51327 : EeSetupInfo esim; 42 : 51327 : esim.d_notify = notify; 43 : 51327 : esim.d_name = d_model->getName() + "::ee"; 44 : 51327 : esim.d_constantsAreTriggers = false; 45 : 51327 : d_modelEqualityEngineAlloc.reset( 46 : 51327 : d_eem.allocateEqualityEngine(esim, &d_modelEeContext)); 47 : 51327 : d_modelEqualityEngine = d_modelEqualityEngineAlloc.get(); 48 : : // finish initializing the model 49 : 51327 : d_model->finishInit(d_modelEqualityEngine); 50 : : // We push a context during initialization since the model is cleared during 51 : : // collectModelInfo using pop/push. 52 : 51327 : d_modelEeContext.push(); 53 : 51327 : } 54 : : 55 : 36115 : bool ModelManagerDistributed::prepareModel() 56 : : { 57 [ + - ]: 72230 : Trace("model-builder") << "ModelManagerDistributed: reset model..." 58 : 36115 : << std::endl; 59 : : 60 : : // push/pop to clear the equality engine of the model 61 : 36115 : d_modelEeContext.pop(); 62 : 36115 : d_modelEeContext.push(); 63 : : 64 : : // Collect model info from the theories 65 [ + - ]: 72230 : Trace("model-builder") << "ModelManagerDistributed: Collect model info..." 66 : 36115 : << std::endl; 67 : : // Consult each active theory to get all relevant information concerning the 68 : : // model, which includes both dump their equality information and assigning 69 : : // values. Notice the order of theories here is important and is the same 70 : : // as the list in CVC5_FOR_EACH_THEORY in theory_engine.cpp. 71 : 36115 : const LogicInfo& logicInfo = d_env.getLogicInfo(); 72 [ + + ]: 538862 : for (TheoryId theoryId = theory::THEORY_FIRST; theoryId < theory::THEORY_LAST; 73 : 502747 : ++theoryId) 74 : : { 75 [ + + ]: 503012 : if (!logicInfo.isTheoryEnabled(theoryId)) 76 : : { 77 : : // theory not active, skip 78 : 245519 : continue; 79 : : } 80 : 329723 : Theory* t = d_te.theoryOf(theoryId); 81 [ + + ]: 329723 : if (theoryId == TheoryId::THEORY_BOOL 82 [ + + ]: 293608 : || theoryId == TheoryId::THEORY_BUILTIN) 83 : : { 84 [ + - ]: 144460 : Trace("model-builder") 85 : 0 : << " Skipping theory " << theoryId 86 : 72230 : << " as it does not contribute to the model anyway" << std::endl; 87 : 72230 : continue; 88 : : } 89 [ + - ]: 514986 : Trace("model-builder") << " CollectModelInfo on theory: " << theoryId 90 : 257493 : << std::endl; 91 : : // collect the asserted terms 92 : 257493 : std::set<Node> termSet; 93 : 257493 : t->collectAssertedTermsForModel(termSet); 94 : : // also get relevant terms 95 : 257493 : t->computeRelevantTerms(termSet); 96 [ + + ]: 257493 : if (!t->collectModelInfo(d_model.get(), termSet)) 97 : : { 98 [ + - ]: 530 : Trace("model-builder") 99 : 265 : << "ModelManagerDistributed: fail collect model info" << std::endl; 100 : 265 : return false; 101 : : } 102 [ + + ]: 257493 : } 103 : : 104 [ - + ]: 35850 : if (!collectModelBooleanVariables()) 105 : : { 106 [ - - ]: 0 : Trace("model-builder") << "ModelManagerDistributed: fail Boolean variables" 107 : 0 : << std::endl; 108 : 0 : return false; 109 : : } 110 : : 111 : 35850 : return true; 112 : : } 113 : : 114 : 35850 : bool ModelManagerDistributed::finishBuildModel() const 115 : : { 116 : : // do not use relevant terms 117 [ - + ]: 35850 : if (!d_modelBuilder->buildModel(d_model.get())) 118 : : { 119 [ - - ]: 0 : Trace("model-builder") << "ModelManager: fail build model" << std::endl; 120 : 0 : return false; 121 : : } 122 : 35850 : return true; 123 : : } 124 : : 125 : : } // namespace theory 126 : : } // namespace cvc5::internal