1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Andres Noetzli, Aina Niemetz |
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 expr_miner. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/quantifiers/expr_miner.h" |
17 |
|
|
18 |
|
#include "expr/skolem_manager.h" |
19 |
|
#include "options/quantifiers_options.h" |
20 |
|
#include "smt/smt_engine.h" |
21 |
|
#include "smt/smt_engine_scope.h" |
22 |
|
#include "theory/quantifiers/term_util.h" |
23 |
|
#include "theory/rewriter.h" |
24 |
|
#include "theory/smt_engine_subsolver.h" |
25 |
|
|
26 |
|
using namespace std; |
27 |
|
using namespace cvc5::kind; |
28 |
|
|
29 |
|
namespace cvc5 { |
30 |
|
namespace theory { |
31 |
|
namespace quantifiers { |
32 |
|
|
33 |
62 |
void ExprMiner::initialize(const std::vector<Node>& vars, SygusSampler* ss) |
34 |
|
{ |
35 |
62 |
d_sampler = ss; |
36 |
62 |
d_vars.insert(d_vars.end(), vars.begin(), vars.end()); |
37 |
62 |
} |
38 |
|
|
39 |
256 |
Node ExprMiner::convertToSkolem(Node n) |
40 |
|
{ |
41 |
512 |
std::vector<Node> fvs; |
42 |
256 |
TermUtil::computeVarContains(n, fvs); |
43 |
256 |
if (fvs.empty()) |
44 |
|
{ |
45 |
5 |
return n; |
46 |
|
} |
47 |
502 |
std::vector<Node> sfvs; |
48 |
502 |
std::vector<Node> sks; |
49 |
|
// map to skolems |
50 |
251 |
NodeManager* nm = NodeManager::currentNM(); |
51 |
251 |
SkolemManager* sm = nm->getSkolemManager(); |
52 |
741 |
for (unsigned i = 0, size = fvs.size(); i < size; i++) |
53 |
|
{ |
54 |
980 |
Node v = fvs[i]; |
55 |
|
// only look at the sampler variables |
56 |
490 |
if (std::find(d_vars.begin(), d_vars.end(), v) != d_vars.end()) |
57 |
|
{ |
58 |
490 |
sfvs.push_back(v); |
59 |
490 |
std::map<Node, Node>::iterator itf = d_fv_to_skolem.find(v); |
60 |
490 |
if (itf == d_fv_to_skolem.end()) |
61 |
|
{ |
62 |
116 |
Node sk = sm->mkDummySkolem("rrck", v.getType()); |
63 |
58 |
d_fv_to_skolem[v] = sk; |
64 |
58 |
sks.push_back(sk); |
65 |
|
} |
66 |
|
else |
67 |
|
{ |
68 |
432 |
sks.push_back(itf->second); |
69 |
|
} |
70 |
|
} |
71 |
|
} |
72 |
251 |
return n.substitute(sfvs.begin(), sfvs.end(), sks.begin(), sks.end()); |
73 |
|
} |
74 |
|
|
75 |
256 |
void ExprMiner::initializeChecker(std::unique_ptr<SmtEngine>& checker, |
76 |
|
Node query) |
77 |
|
{ |
78 |
256 |
Assert (!query.isNull()); |
79 |
256 |
if (Options::current().quantifiers.sygusExprMinerCheckTimeoutWasSetByUser) |
80 |
|
{ |
81 |
|
initializeSubsolver( |
82 |
|
checker, nullptr, true, options::sygusExprMinerCheckTimeout()); |
83 |
|
} |
84 |
|
else |
85 |
|
{ |
86 |
256 |
initializeSubsolver(checker); |
87 |
|
} |
88 |
|
// also set the options |
89 |
256 |
checker->setOption("sygus-rr-synth-input", "false"); |
90 |
256 |
checker->setOption("input-language", "smt2"); |
91 |
|
// Convert bound variables to skolems. This ensures the satisfiability |
92 |
|
// check is ground. |
93 |
512 |
Node squery = convertToSkolem(query); |
94 |
256 |
checker->assertFormula(squery); |
95 |
256 |
} |
96 |
|
|
97 |
54 |
Result ExprMiner::doCheck(Node query) |
98 |
|
{ |
99 |
108 |
Node queryr = Rewriter::rewrite(query); |
100 |
54 |
if (queryr.isConst()) |
101 |
|
{ |
102 |
|
if (!queryr.getConst<bool>()) |
103 |
|
{ |
104 |
|
return Result(Result::UNSAT); |
105 |
|
} |
106 |
|
else |
107 |
|
{ |
108 |
|
return Result(Result::SAT); |
109 |
|
} |
110 |
|
} |
111 |
108 |
std::unique_ptr<SmtEngine> smte; |
112 |
54 |
initializeChecker(smte, query); |
113 |
54 |
return smte->checkSat(); |
114 |
|
} |
115 |
|
|
116 |
|
} // namespace quantifiers |
117 |
|
} // namespace theory |
118 |
29340 |
} // namespace cvc5 |