1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 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 { |
24 |
|
namespace theory { |
25 |
|
|
26 |
9853 |
ModelManagerDistributed::ModelManagerDistributed(TheoryEngine& te, |
27 |
|
Env& env, |
28 |
9853 |
EqEngineManager& eem) |
29 |
9853 |
: ModelManager(te, env, eem) |
30 |
|
{ |
31 |
9853 |
} |
32 |
|
|
33 |
29559 |
ModelManagerDistributed::~ModelManagerDistributed() |
34 |
|
{ |
35 |
|
// pop the model context which we pushed on initialization |
36 |
9853 |
d_modelEeContext.pop(); |
37 |
19706 |
} |
38 |
|
|
39 |
9853 |
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 |
19706 |
EeSetupInfo esim; |
45 |
9853 |
esim.d_notify = notify; |
46 |
9853 |
esim.d_name = d_model->getName() + "::ee"; |
47 |
9853 |
esim.d_constantsAreTriggers = false; |
48 |
19706 |
d_modelEqualityEngineAlloc.reset( |
49 |
9853 |
d_eem.allocateEqualityEngine(esim, &d_modelEeContext)); |
50 |
9853 |
d_modelEqualityEngine = d_modelEqualityEngineAlloc.get(); |
51 |
|
// finish initializing the model |
52 |
9853 |
d_model->finishInit(d_modelEqualityEngine); |
53 |
|
// We push a context during initialization since the model is cleared during |
54 |
|
// collectModelInfo using pop/push. |
55 |
9853 |
d_modelEeContext.push(); |
56 |
9853 |
} |
57 |
|
|
58 |
16518 |
bool ModelManagerDistributed::prepareModel() |
59 |
|
{ |
60 |
33036 |
Trace("model-builder") << "ModelManagerDistributed: reset model..." |
61 |
16518 |
<< std::endl; |
62 |
|
|
63 |
|
// push/pop to clear the equality engine of the model |
64 |
16518 |
d_modelEeContext.pop(); |
65 |
16518 |
d_modelEeContext.push(); |
66 |
|
|
67 |
|
// Collect model info from the theories |
68 |
33036 |
Trace("model-builder") << "ModelManagerDistributed: Collect model info..." |
69 |
16518 |
<< 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 |
16518 |
const LogicInfo& logicInfo = d_env.getLogicInfo(); |
75 |
231230 |
for (TheoryId theoryId = theory::THEORY_FIRST; theoryId < theory::THEORY_LAST; |
76 |
|
++theoryId) |
77 |
|
{ |
78 |
214715 |
if (!logicInfo.isTheoryEnabled(theoryId)) |
79 |
|
{ |
80 |
|
// theory not active, skip |
81 |
92162 |
continue; |
82 |
|
} |
83 |
122553 |
Theory* t = d_te.theoryOf(theoryId); |
84 |
245106 |
Trace("model-builder") << " CollectModelInfo on theory: " << theoryId |
85 |
122553 |
<< std::endl; |
86 |
|
// collect the asserted terms |
87 |
245104 |
std::set<Node> termSet; |
88 |
122553 |
collectAssertedTerms(theoryId, termSet); |
89 |
|
// also get relevant terms |
90 |
122553 |
t->computeRelevantTerms(termSet); |
91 |
122553 |
if (!t->collectModelInfo(d_model.get(), termSet)) |
92 |
|
{ |
93 |
4 |
Trace("model-builder") |
94 |
2 |
<< "ModelManagerDistributed: fail collect model info" << std::endl; |
95 |
2 |
return false; |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
16515 |
if (!collectModelBooleanVariables()) |
100 |
|
{ |
101 |
|
Trace("model-builder") << "ModelManagerDistributed: fail Boolean variables" |
102 |
|
<< std::endl; |
103 |
|
return false; |
104 |
|
} |
105 |
|
|
106 |
16515 |
return true; |
107 |
|
} |
108 |
|
|
109 |
16515 |
bool ModelManagerDistributed::finishBuildModel() const |
110 |
|
{ |
111 |
|
// do not use relevant terms |
112 |
16515 |
if (!d_modelBuilder->buildModel(d_model.get())) |
113 |
|
{ |
114 |
|
Trace("model-builder") << "ModelManager: fail build model" << std::endl; |
115 |
|
return false; |
116 |
|
} |
117 |
16515 |
return true; |
118 |
|
} |
119 |
|
|
120 |
|
} // namespace theory |
121 |
29340 |
} // namespace cvc5 |