GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/expr_miner_manager.cpp Lines: 42 75 56.0 %
Date: 2021-05-22 Branches: 48 140 34.3 %

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 expression miner manager.
14
 */
15
16
#include "theory/quantifiers/expr_miner_manager.h"
17
18
#include "options/quantifiers_options.h"
19
20
namespace cvc5 {
21
namespace theory {
22
namespace quantifiers {
23
24
9
ExpressionMinerManager::ExpressionMinerManager()
25
    : d_doRewSynth(false),
26
      d_doQueryGen(false),
27
      d_doFilterLogicalStrength(false),
28
      d_use_sygus_type(false),
29
      d_tds(nullptr),
30
18
      d_crd(options::sygusRewSynthCheck(), options::sygusRewSynthAccel(), false)
31
{
32
9
}
33
34
void ExpressionMinerManager::initialize(const std::vector<Node>& vars,
35
                                        TypeNode tn,
36
                                        unsigned nsamples,
37
                                        bool unique_type_ids)
38
{
39
  d_doRewSynth = false;
40
  d_doQueryGen = false;
41
  d_doFilterLogicalStrength = false;
42
  d_sygus_fun = Node::null();
43
  d_use_sygus_type = false;
44
  d_tds = nullptr;
45
  // initialize the sampler
46
  d_sampler.initialize(tn, vars, nsamples, unique_type_ids);
47
}
48
49
9
void ExpressionMinerManager::initializeSygus(TermDbSygus* tds,
50
                                             Node f,
51
                                             unsigned nsamples,
52
                                             bool useSygusType)
53
{
54
9
  d_doRewSynth = false;
55
9
  d_doQueryGen = false;
56
9
  d_doFilterLogicalStrength = false;
57
9
  d_sygus_fun = f;
58
9
  d_use_sygus_type = useSygusType;
59
9
  d_tds = tds;
60
  // initialize the sampler
61
9
  d_sampler.initializeSygus(d_tds, f, nsamples, useSygusType);
62
9
}
63
64
7
void ExpressionMinerManager::enableRewriteRuleSynth()
65
{
66
7
  if (d_doRewSynth)
67
  {
68
    // already enabled
69
    return;
70
  }
71
7
  d_doRewSynth = true;
72
14
  std::vector<Node> vars;
73
7
  d_sampler.getVariables(vars);
74
  // initialize the candidate rewrite database
75
7
  if (!d_sygus_fun.isNull())
76
  {
77
7
    Assert(d_tds != nullptr);
78
7
    d_crd.initializeSygus(vars, d_tds, d_sygus_fun, &d_sampler);
79
  }
80
  else
81
  {
82
    d_crd.initialize(vars, &d_sampler);
83
  }
84
7
  d_crd.setExtendedRewriter(&d_ext_rew);
85
7
  d_crd.setSilent(false);
86
}
87
88
void ExpressionMinerManager::enableQueryGeneration(unsigned deqThresh)
89
{
90
  if (d_doQueryGen)
91
  {
92
    // already enabled
93
    return;
94
  }
95
  d_doQueryGen = true;
96
  std::vector<Node> vars;
97
  d_sampler.getVariables(vars);
98
  // must also enable rewrite rule synthesis
99
  if (!d_doRewSynth)
100
  {
101
    // initialize the candidate rewrite database, in silent mode
102
    enableRewriteRuleSynth();
103
    d_crd.setSilent(true);
104
  }
105
  // initialize the query generator
106
  d_qg.initialize(vars, &d_sampler);
107
  d_qg.setThreshold(deqThresh);
108
}
109
110
void ExpressionMinerManager::enableFilterWeakSolutions()
111
{
112
  d_doFilterLogicalStrength = true;
113
  std::vector<Node> vars;
114
  d_sampler.getVariables(vars);
115
  d_sols.initialize(vars, &d_sampler);
116
  d_sols.setLogicallyStrong(true);
117
}
118
119
2
void ExpressionMinerManager::enableFilterStrongSolutions()
120
{
121
2
  d_doFilterLogicalStrength = true;
122
4
  std::vector<Node> vars;
123
2
  d_sampler.getVariables(vars);
124
2
  d_sols.initialize(vars, &d_sampler);
125
2
  d_sols.setLogicallyStrong(false);
126
2
}
127
128
1064
bool ExpressionMinerManager::addTerm(Node sol,
129
                                     std::ostream& out,
130
                                     bool& rew_print)
131
{
132
  // set the builtin version
133
2128
  Node solb = sol;
134
1064
  if (d_use_sygus_type)
135
  {
136
1064
    solb = d_tds->sygusToBuiltin(sol);
137
  }
138
139
  // add to the candidate rewrite rule database
140
1064
  bool ret = true;
141
1064
  if (d_doRewSynth)
142
  {
143
3024
    Node rsol = d_crd.addTerm(sol, options::sygusRewSynthRec(), out, rew_print);
144
1008
    ret = (sol == rsol);
145
  }
146
147
  // a unique term, let's try the query generator
148
1064
  if (ret && d_doQueryGen)
149
  {
150
    d_qg.addTerm(solb, out);
151
  }
152
153
  // filter based on logical strength
154
1064
  if (ret && d_doFilterLogicalStrength)
155
  {
156
56
    ret = d_sols.addTerm(solb, out);
157
  }
158
2128
  return ret;
159
}
160
161
bool ExpressionMinerManager::addTerm(Node sol, std::ostream& out)
162
{
163
  bool rew_print = false;
164
  return addTerm(sol, out, rew_print);
165
}
166
167
}  // namespace quantifiers
168
}  // namespace theory
169
29211
}  // namespace cvc5