GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/expr_miner_manager.cpp Lines: 44 77 57.1 %
Date: 2021-09-29 Branches: 43 124 34.7 %

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