GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/sygus/example_min_eval.cpp Lines: 30 30 100.0 %
Date: 2021-08-16 Branches: 46 106 43.4 %

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