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 equality sharing. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/ee_manager_distributed.h" |
17 |
|
|
18 |
|
#include "theory/quantifiers_engine.h" |
19 |
|
#include "theory/shared_solver.h" |
20 |
|
#include "theory/theory_engine.h" |
21 |
|
#include "theory/uf/equality_engine.h" |
22 |
|
|
23 |
|
namespace cvc5 { |
24 |
|
namespace theory { |
25 |
|
|
26 |
9818 |
EqEngineManagerDistributed::EqEngineManagerDistributed(TheoryEngine& te, |
27 |
9818 |
SharedSolver& shs) |
28 |
9818 |
: EqEngineManager(te, shs), d_masterEENotify(nullptr) |
29 |
|
{ |
30 |
9818 |
} |
31 |
|
|
32 |
19636 |
EqEngineManagerDistributed::~EqEngineManagerDistributed() |
33 |
|
{ |
34 |
19636 |
} |
35 |
|
|
36 |
9818 |
void EqEngineManagerDistributed::initializeTheories() |
37 |
|
{ |
38 |
9818 |
context::Context* c = d_te.getSatContext(); |
39 |
|
// initialize the shared solver |
40 |
19636 |
EeSetupInfo esis; |
41 |
9818 |
if (d_sharedSolver.needsEqualityEngine(esis)) |
42 |
|
{ |
43 |
|
// allocate an equality engine for the shared terms database |
44 |
9818 |
d_stbEqualityEngine.reset(allocateEqualityEngine(esis, c)); |
45 |
9818 |
d_sharedSolver.setEqualityEngine(d_stbEqualityEngine.get()); |
46 |
|
} |
47 |
|
else |
48 |
|
{ |
49 |
|
Unhandled() << "Expected shared solver to use equality engine"; |
50 |
|
} |
51 |
|
|
52 |
9818 |
const LogicInfo& logicInfo = d_te.getLogicInfo(); |
53 |
9818 |
if (logicInfo.isQuantified()) |
54 |
|
{ |
55 |
|
// construct the master equality engine |
56 |
6728 |
Assert(d_masterEqualityEngine == nullptr); |
57 |
6728 |
QuantifiersEngine* qe = d_te.getQuantifiersEngine(); |
58 |
6728 |
Assert(qe != nullptr); |
59 |
6728 |
d_masterEENotify.reset(new quantifiers::MasterNotifyClass(qe)); |
60 |
20184 |
d_masterEqualityEngine.reset(new eq::EqualityEngine(*d_masterEENotify.get(), |
61 |
6728 |
d_te.getSatContext(), |
62 |
|
"theory::master", |
63 |
6728 |
false)); |
64 |
|
} |
65 |
|
// allocate equality engines per theory |
66 |
137452 |
for (TheoryId theoryId = theory::THEORY_FIRST; |
67 |
137452 |
theoryId != theory::THEORY_LAST; |
68 |
|
++theoryId) |
69 |
|
{ |
70 |
127634 |
Theory* t = d_te.theoryOf(theoryId); |
71 |
127634 |
if (t == nullptr) |
72 |
|
{ |
73 |
|
// theory not active, skip |
74 |
29456 |
continue; |
75 |
|
} |
76 |
|
// always allocate an object in d_einfo here |
77 |
127634 |
EeTheoryInfo& eet = d_einfo[theoryId]; |
78 |
225812 |
EeSetupInfo esi; |
79 |
127634 |
if (!t->needsEqualityEngine(esi)) |
80 |
|
{ |
81 |
|
// the theory said it doesn't need an equality engine, skip |
82 |
19638 |
continue; |
83 |
|
} |
84 |
117814 |
if (esi.d_useMaster) |
85 |
|
{ |
86 |
|
// the theory said it wants to use the master equality engine |
87 |
9818 |
eet.d_usedEe = d_masterEqualityEngine.get(); |
88 |
9818 |
continue; |
89 |
|
} |
90 |
|
// allocate the equality engine |
91 |
98178 |
eet.d_allocEe.reset(allocateEqualityEngine(esi, c)); |
92 |
|
// the theory uses the equality engine |
93 |
98178 |
eet.d_usedEe = eet.d_allocEe.get(); |
94 |
|
// if there is a master equality engine |
95 |
98178 |
if (d_masterEqualityEngine != nullptr) |
96 |
|
{ |
97 |
|
// set the master equality engine of the theory's equality engine |
98 |
67280 |
eet.d_allocEe->setMasterEqualityEngine(d_masterEqualityEngine.get()); |
99 |
|
} |
100 |
|
} |
101 |
9818 |
} |
102 |
|
|
103 |
7473 |
void EqEngineManagerDistributed::notifyModel(bool incomplete) |
104 |
|
{ |
105 |
|
// should have a consistent master equality engine |
106 |
7473 |
if (d_masterEqualityEngine.get() != nullptr) |
107 |
|
{ |
108 |
3245 |
AlwaysAssert(d_masterEqualityEngine->consistent()); |
109 |
|
} |
110 |
7473 |
} |
111 |
|
|
112 |
|
} // namespace theory |
113 |
29340 |
} // namespace cvc5 |