GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/sygus/sygus_enumerator_callback.cpp Lines: 1 41 2.4 %
Date: 2021-08-17 Branches: 2 128 1.6 %

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