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-07 Branches: 72 144 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
23
namespace cvc5 {
24
namespace theory {
25
namespace quantifiers {
26
27
166
SygusEnumeratorCallback::SygusEnumeratorCallback(Node e, SygusStatistics* s)
28
166
    : d_enum(e), d_stats(s)
29
{
30
166
  d_tn = e.getType();
31
166
}
32
33
55281
bool SygusEnumeratorCallback::addTerm(Node n, std::unordered_set<Node>& bterms)
34
{
35
110562
  Node bn = datatypes::utils::sygusToBuiltin(n);
36
110562
  Node bnr = d_extr.extendedRewrite(bn);
37
55281
  if (d_stats != nullptr)
38
  {
39
55281
    ++(d_stats->d_enumTermsRewrite);
40
  }
41
  // call the solver-specific notify term
42
55281
  notifyTermInternal(n, bn, bnr);
43
  // check whether we should keep the term, which is based on the callback,
44
  // and the builtin terms
45
  // First, must be unique up to rewriting
46
55281
  if (bterms.find(bnr) != bterms.end())
47
  {
48
22955
    Trace("sygus-enum-exc") << "Exclude: " << bn << std::endl;
49
22955
    return false;
50
  }
51
  // insert to builtin term cache, regardless of whether it is redundant
52
  // based on the callback
53
32326
  bterms.insert(bnr);
54
  // callback-specific add term
55
32326
  if (!addTermInternal(n, bn, bnr))
56
  {
57
16956
    Trace("sygus-enum-exc")
58
8478
        << "Exclude: " << bn << " due to callback" << std::endl;
59
8478
    return false;
60
  }
61
23848
  Trace("sygus-enum-terms") << "tc(" << d_tn << "): term " << bn << std::endl;
62
23848
  return true;
63
}
64
65
166
SygusEnumeratorCallbackDefault::SygusEnumeratorCallbackDefault(
66
    Node e,
67
    SygusStatistics* s,
68
    ExampleEvalCache* eec,
69
    SygusSampler* ssrv,
70
166
    std::ostream* out)
71
166
    : SygusEnumeratorCallback(e, s), d_eec(eec), d_samplerRrV(ssrv), d_out(out)
72
{
73
166
}
74
55281
void SygusEnumeratorCallbackDefault::notifyTermInternal(Node n,
75
                                                        Node bn,
76
                                                        Node bnr)
77
{
78
55281
  if (d_samplerRrV != nullptr)
79
  {
80
1626
    Assert(d_out != nullptr);
81
1626
    d_samplerRrV->checkEquivalent(bn, bnr, *d_out);
82
  }
83
55281
}
84
85
32326
bool SygusEnumeratorCallbackDefault::addTermInternal(Node n, Node bn, Node bnr)
86
{
87
  // if we are doing PBE symmetry breaking
88
32326
  if (d_eec != nullptr)
89
  {
90
14013
    if (d_stats != nullptr)
91
    {
92
14013
      ++(d_stats->d_enumTermsExampleEval);
93
    }
94
    // Is it equivalent under examples?
95
19548
    Node bne = d_eec->addSearchVal(d_tn, bnr);
96
14013
    if (!bne.isNull())
97
    {
98
14013
      if (bnr != bne)
99
      {
100
16956
        Trace("sygus-enum-exc")
101
8478
            << "Exclude (by examples): " << bn << ", since we already have "
102
8478
            << bne << std::endl;
103
8478
        return false;
104
      }
105
    }
106
  }
107
23848
  return true;
108
}
109
110
}  // namespace quantifiers
111
}  // namespace theory
112
29502
}  // namespace cvc5