LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory - model_manager_distributed.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 50 56 89.3 %
Date: 2026-01-19 13:01:48 Functions: 6 6 100.0 %
Branches: 17 28 60.7 %

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

Generated by: LCOV version 1.14