GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/sygus/sygus_enumerator_callback.cpp Lines: 42 42 100.0 %
Date: 2021-09-15 Branches: 71 142 50.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner
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
 * sygus_enumerator
14
 */
15
16
#include "theory/quantifiers/sygus/sygus_enumerator_callback.h"
17
18
#include "theory/datatypes/sygus_datatype_utils.h"
19
#include "theory/quantifiers/sygus/example_eval_cache.h"
20
#include "theory/quantifiers/sygus/sygus_stats.h"
21
#include "theory/quantifiers/sygus_sampler.h"
22
#include "theory/rewriter.h"
23
24
namespace cvc5 {
25
namespace theory {
26
namespace quantifiers {
27
28
167
SygusEnumeratorCallback::SygusEnumeratorCallback(Node e, SygusStatistics* s)
29
167
    : d_enum(e), d_stats(s)
30
{
31
167
  d_tn = e.getType();
32
167
}
33
34
55282
bool SygusEnumeratorCallback::addTerm(Node n, std::unordered_set<Node>& bterms)
35
{
36
110564
  Node bn = datatypes::utils::sygusToBuiltin(n);
37
110564
  Node bnr = Rewriter::callExtendedRewrite(bn);
38
55282
  if (d_stats != nullptr)
39
  {
40
55282
    ++(d_stats->d_enumTermsRewrite);
41
  }
42
  // call the solver-specific notify term
43
55282
  notifyTermInternal(n, bn, bnr);
44
  // check whether we should keep the term, which is based on the callback,
45
  // and the builtin terms
46
  // First, must be unique up to rewriting
47
55282
  if (bterms.find(bnr) != bterms.end())
48
  {
49
22955
    Trace("sygus-enum-exc") << "Exclude: " << bn << std::endl;
50
22955
    return false;
51
  }
52
  // insert to builtin term cache, regardless of whether it is redundant
53
  // based on the callback
54
32327
  bterms.insert(bnr);
55
  // callback-specific add term
56
32327
  if (!addTermInternal(n, bn, bnr))
57
  {
58
16958
    Trace("sygus-enum-exc")
59
8479
        << "Exclude: " << bn << " due to callback" << std::endl;
60
8479
    return false;
61
  }
62
23848
  Trace("sygus-enum-terms") << "tc(" << d_tn << "): term " << bn << std::endl;
63
23848
  return true;
64
}
65
66
167
SygusEnumeratorCallbackDefault::SygusEnumeratorCallbackDefault(
67
    Node e,
68
    SygusStatistics* s,
69
    ExampleEvalCache* eec,
70
    SygusSampler* ssrv,
71
167
    std::ostream* out)
72
167
    : SygusEnumeratorCallback(e, s), d_eec(eec), d_samplerRrV(ssrv), d_out(out)
73
{
74
167
}
75
55282
void SygusEnumeratorCallbackDefault::notifyTermInternal(Node n,
76
                                                        Node bn,
77
                                                        Node bnr)
78
{
79
55282
  if (d_samplerRrV != nullptr)
80
  {
81
1626
    Assert(d_out != nullptr);
82
1626
    d_samplerRrV->checkEquivalent(bn, bnr, *d_out);
83
  }
84
55282
}
85
86
32327
bool SygusEnumeratorCallbackDefault::addTermInternal(Node n, Node bn, Node bnr)
87
{
88
  // if we are doing PBE symmetry breaking
89
32327
  if (d_eec != nullptr)
90
  {
91
14013
    if (d_stats != nullptr)
92
    {
93
14013
      ++(d_stats->d_enumTermsExampleEval);
94
    }
95
    // Is it equivalent under examples?
96
19547
    Node bne = d_eec->addSearchVal(d_tn, bnr);
97
14013
    if (!bne.isNull())
98
    {
99
14013
      if (bnr != bne)
100
      {
101
16958
        Trace("sygus-enum-exc")
102
8479
            << "Exclude (by examples): " << bn << ", since we already have "
103
8479
            << bne << std::endl;
104
8479
        return false;
105
      }
106
    }
107
  }
108
23848
  return true;
109
}
110
111
}  // namespace quantifiers
112
}  // namespace theory
113
29577
}  // namespace cvc5