1 /********************* */
2 /*! \file expr_miner.cpp
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Andres Noetzli
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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.\endverbatim
12 ** \brief Implementation of expr_miner
15 #include "theory/quantifiers/expr_miner.h"
17 #include "api/cvc4cpp.h"
18 #include "options/quantifiers_options.h"
19 #include "smt/smt_engine.h"
20 #include "smt/smt_engine_scope.h"
21 #include "theory/quantifiers/term_util.h"
22 #include "theory/smt_engine_subsolver.h"
25 using namespace CVC4::kind
;
29 namespace quantifiers
{
31 void ExprMiner::initialize(const std::vector
<Node
>& vars
, SygusSampler
* ss
)
34 d_vars
.insert(d_vars
.end(), vars
.begin(), vars
.end());
37 Node
ExprMiner::convertToSkolem(Node n
)
39 std::vector
<Node
> fvs
;
40 TermUtil::computeVarContains(n
, fvs
);
45 std::vector
<Node
> sfvs
;
46 std::vector
<Node
> sks
;
48 NodeManager
* nm
= NodeManager::currentNM();
49 for (unsigned i
= 0, size
= fvs
.size(); i
< size
; i
++)
52 // only look at the sampler variables
53 if (std::find(d_vars
.begin(), d_vars
.end(), v
) != d_vars
.end())
56 std::map
<Node
, Node
>::iterator itf
= d_fv_to_skolem
.find(v
);
57 if (itf
== d_fv_to_skolem
.end())
59 Node sk
= nm
->mkSkolem("rrck", v
.getType());
60 d_fv_to_skolem
[v
] = sk
;
65 sks
.push_back(itf
->second
);
69 return n
.substitute(sfvs
.begin(), sfvs
.end(), sks
.begin(), sks
.end());
72 void ExprMiner::initializeChecker(SmtEngine
* checker
,
74 ExprManagerMapCollection
& varMap
,
78 // Convert bound variables to skolems. This ensures the satisfiability
80 Node squery
= convertToSkolem(query
);
81 if (options::sygusExprMinerCheckUseExport())
83 initializeSubsolverWithExport(checker
,
88 options::sygusExprMinerCheckTimeout());
89 checker
->setOption("sygus-rr-synth-input", false);
90 checker
->setOption("input-language", "smt2");
95 initializeSubsolver(checker
, squery
.toExpr());
100 Result
ExprMiner::doCheck(Node query
)
102 Node queryr
= Rewriter::rewrite(query
);
103 if (queryr
.isConst())
105 if (!queryr
.getConst
<bool>())
107 return Result(Result::UNSAT
);
111 return Result(Result::SAT
);
114 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
115 // This is only temporarily until we have separate options for each
116 // SmtEngine instance. We should reuse the same ExprManager with
117 // a different SmtEngine (and different options) here, eventually.
118 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
119 NodeManager
* nm
= NodeManager::currentNM();
120 bool needExport
= false;
121 api::Solver
slv(&nm
->getOptions());
122 ExprManager
* em
= slv
.getExprManager();
123 SmtEngine
* smte
= slv
.getSmtEngine();
124 ExprManagerMapCollection varMap
;
125 initializeChecker(smte
, em
, varMap
, queryr
, needExport
);
126 return smte
->checkSat();
129 } // namespace quantifiers
130 } // namespace theory