GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/sygus/example_min_eval.cpp Lines: 30 30 100.0 %
Date: 2021-05-22 Branches: 46 108 42.6 %

Line Exec Source
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
15772
ExampleMinEval::ExampleMinEval(Node n,
27
                               const std::vector<Node>& vars,
28
15772
                               EmeEval* ece)
29
{
30
15772
  AlwaysAssert(d_evalNode.isNull());
31
15772
  d_evalNode = n;
32
15772
  d_vars.insert(d_vars.end(), vars.begin(), vars.end());
33
34
  // compute its free variables
35
31544
  std::unordered_set<Node> fvs;
36
15772
  expr::getFreeVariables(n, fvs);
37
168743
  for (size_t i = 0, vsize = vars.size(); i < vsize; i++)
38
  {
39
152971
    if (fvs.find(vars[i]) != fvs.end())
40
    {
41
      // will use this index
42
29464
      d_indices.push_back(i);
43
    }
44
  }
45
31544
  Trace("example-cache") << "For " << n << ", " << d_indices.size() << " / "
46
31544
                         << d_vars.size() << " variables are relevant"
47
15772
                         << std::endl;
48
15772
  d_ece = ece;
49
15772
}
50
51
138286
Node ExampleMinEval::evaluate(const std::vector<Node>& subs)
52
{
53
138286
  Assert(d_vars.size() == subs.size());
54
55
138286
  if (d_indices.size() == d_vars.size())
56
  {
57
    // no sharing is possible since all variables are relevant, just evaluate
58
40664
    return d_ece->eval(d_evalNode, d_vars, subs);
59
  }
60
61
  // get the subsequence of subs that is relevant
62
195244
  std::vector<Node> relSubs;
63
292093
  for (unsigned i = 0, ssize = d_indices.size(); i < ssize; i++)
64
  {
65
194471
    relSubs.push_back(subs[d_indices[i]]);
66
  }
67
195244
  Node res = d_trie.existsTerm(relSubs);
68
97622
  if (res.isNull())
69
  {
70
    // not already cached, must evaluate
71
66603
    res = d_ece->eval(d_evalNode, d_vars, subs);
72
73
    // add to trie
74
66603
    d_trie.addTerm(res, relSubs);
75
  }
76
97622
  return res;
77
}
78
79
107267
Node EmeEvalTds::eval(TNode n,
80
                      const std::vector<Node>& args,
81
                      const std::vector<Node>& vals)
82
{
83
107267
  return d_tds->evaluateBuiltin(d_tn, n, vals);
84
}
85
86
}  // namespace quantifiers
87
}  // namespace theory
88
28194
}  // namespace cvc5