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 |
|
* Implementation of utility for minimizing the number of calls to |
14 |
|
* evaluate a term on substitutions with a fixed domain. |
15 |
|
*/ |
16 |
|
|
17 |
|
#include "theory/quantifiers/sygus/example_min_eval.h" |
18 |
|
|
19 |
|
#include "expr/node_algorithm.h" |
20 |
|
#include "theory/quantifiers/sygus/term_database_sygus.h" |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
namespace theory { |
24 |
|
namespace quantifiers { |
25 |
|
|
26 |
15795 |
ExampleMinEval::ExampleMinEval(Node n, |
27 |
|
const std::vector<Node>& vars, |
28 |
15795 |
EmeEval* ece) |
29 |
|
{ |
30 |
15795 |
AlwaysAssert(d_evalNode.isNull()); |
31 |
15795 |
d_evalNode = n; |
32 |
15795 |
d_vars.insert(d_vars.end(), vars.begin(), vars.end()); |
33 |
|
|
34 |
|
// compute its free variables |
35 |
31590 |
std::unordered_set<Node> fvs; |
36 |
15795 |
expr::getFreeVariables(n, fvs); |
37 |
168858 |
for (size_t i = 0, vsize = vars.size(); i < vsize; i++) |
38 |
|
{ |
39 |
153063 |
if (fvs.find(vars[i]) != fvs.end()) |
40 |
|
{ |
41 |
|
// will use this index |
42 |
29531 |
d_indices.push_back(i); |
43 |
|
} |
44 |
|
} |
45 |
31590 |
Trace("example-cache") << "For " << n << ", " << d_indices.size() << " / " |
46 |
31590 |
<< d_vars.size() << " variables are relevant" |
47 |
15795 |
<< std::endl; |
48 |
15795 |
d_ece = ece; |
49 |
15795 |
} |
50 |
|
|
51 |
138283 |
Node ExampleMinEval::evaluate(const std::vector<Node>& subs) |
52 |
|
{ |
53 |
138283 |
Assert(d_vars.size() == subs.size()); |
54 |
|
|
55 |
138283 |
if (d_indices.size() == d_vars.size()) |
56 |
|
{ |
57 |
|
// no sharing is possible since all variables are relevant, just evaluate |
58 |
40573 |
return d_ece->eval(d_evalNode, d_vars, subs); |
59 |
|
} |
60 |
|
|
61 |
|
// get the subsequence of subs that is relevant |
62 |
195420 |
std::vector<Node> relSubs; |
63 |
292278 |
for (unsigned i = 0, ssize = d_indices.size(); i < ssize; i++) |
64 |
|
{ |
65 |
194568 |
relSubs.push_back(subs[d_indices[i]]); |
66 |
|
} |
67 |
195420 |
Node res = d_trie.existsTerm(relSubs); |
68 |
97710 |
if (res.isNull()) |
69 |
|
{ |
70 |
|
// not already cached, must evaluate |
71 |
66672 |
res = d_ece->eval(d_evalNode, d_vars, subs); |
72 |
|
|
73 |
|
// add to trie |
74 |
66672 |
d_trie.addTerm(res, relSubs); |
75 |
|
} |
76 |
97710 |
return res; |
77 |
|
} |
78 |
|
|
79 |
107245 |
Node EmeEvalTds::eval(TNode n, |
80 |
|
const std::vector<Node>& args, |
81 |
|
const std::vector<Node>& vals) |
82 |
|
{ |
83 |
107245 |
return d_tds->evaluateBuiltin(d_tn, n, vals); |
84 |
|
} |
85 |
|
|
86 |
|
} // namespace quantifiers |
87 |
|
} // namespace theory |
88 |
29502 |
} // namespace cvc5 |