1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, 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 |
|
* Utilities for filtering solutions. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/quantifiers/solution_filter.h" |
17 |
|
|
18 |
|
#include <fstream> |
19 |
|
|
20 |
|
#include "options/base_options.h" |
21 |
|
#include "options/quantifiers_options.h" |
22 |
|
#include "smt/smt_engine.h" |
23 |
|
#include "smt/smt_engine_scope.h" |
24 |
|
#include "util/random.h" |
25 |
|
|
26 |
|
using namespace cvc5::kind; |
27 |
|
|
28 |
|
namespace cvc5 { |
29 |
|
namespace theory { |
30 |
|
namespace quantifiers { |
31 |
|
|
32 |
9 |
SolutionFilterStrength::SolutionFilterStrength() : d_isStrong(true) {} |
33 |
2 |
void SolutionFilterStrength::initialize(const std::vector<Node>& vars, |
34 |
|
SygusSampler* ss) |
35 |
|
{ |
36 |
2 |
ExprMiner::initialize(vars, ss); |
37 |
2 |
} |
38 |
|
|
39 |
2 |
void SolutionFilterStrength::setLogicallyStrong(bool isStrong) |
40 |
|
{ |
41 |
2 |
d_isStrong = isStrong; |
42 |
2 |
} |
43 |
|
|
44 |
56 |
bool SolutionFilterStrength::addTerm(Node n, std::ostream& out) |
45 |
|
{ |
46 |
56 |
if (!n.getType().isBoolean()) |
47 |
|
{ |
48 |
|
// currently, should not register non-Boolean terms here |
49 |
|
Assert(false); |
50 |
|
return true; |
51 |
|
} |
52 |
112 |
Node basen = d_isStrong ? n : n.negate(); |
53 |
56 |
NodeManager* nm = NodeManager::currentNM(); |
54 |
|
// Do i subsume the disjunction of all previous solutions? If so, we discard |
55 |
|
// this immediately |
56 |
112 |
Node curr; |
57 |
56 |
if (!d_curr_sols.empty()) |
58 |
|
{ |
59 |
108 |
curr = d_curr_sols.size() == 1 |
60 |
160 |
? d_curr_sols[0] |
61 |
52 |
: nm->mkNode(d_isStrong ? OR : AND, d_curr_sols); |
62 |
73 |
Node imp = nm->mkNode(AND, basen.negate(), curr); |
63 |
108 |
Trace("sygus-sol-implied") |
64 |
54 |
<< " implies: check subsumed (strong=" << d_isStrong << ") " << imp |
65 |
54 |
<< "..." << std::endl; |
66 |
|
// check the satisfiability query |
67 |
73 |
Result r = doCheck(imp); |
68 |
54 |
Trace("sygus-sol-implied") << " implies: ...got : " << r << std::endl; |
69 |
54 |
if (r.asSatisfiabilityResult().isSat() == Result::UNSAT) |
70 |
|
{ |
71 |
|
// it is subsumed by the current, discard this |
72 |
35 |
return false; |
73 |
|
} |
74 |
|
} |
75 |
|
// check which solutions would have been filtered if the current had come |
76 |
|
// first |
77 |
21 |
if (options::sygusFilterSolRevSubsume()) |
78 |
|
{ |
79 |
|
std::vector<Node> nsubsume; |
80 |
|
for (const Node& s : d_curr_sols) |
81 |
|
{ |
82 |
|
Node imp = nm->mkNode(AND, s.negate(), basen); |
83 |
|
Trace("sygus-sol-implied") |
84 |
|
<< " implies: check subsuming " << imp << "..." << std::endl; |
85 |
|
// check the satisfiability query |
86 |
|
Result r = doCheck(imp); |
87 |
|
Trace("sygus-sol-implied") << " implies: ...got : " << r << std::endl; |
88 |
|
if (r.asSatisfiabilityResult().isSat() != Result::UNSAT) |
89 |
|
{ |
90 |
|
nsubsume.push_back(s); |
91 |
|
} |
92 |
|
else |
93 |
|
{ |
94 |
|
Options& opts = smt::currentSmtEngine()->getOptions(); |
95 |
|
std::ostream* smtOut = opts.base.out; |
96 |
|
(*smtOut) << "; (filtered " << (d_isStrong ? s : s.negate()) << ")" |
97 |
|
<< std::endl; |
98 |
|
} |
99 |
|
} |
100 |
|
d_curr_sols.clear(); |
101 |
|
d_curr_sols.insert(d_curr_sols.end(), nsubsume.begin(), nsubsume.end()); |
102 |
|
} |
103 |
21 |
d_curr_sols.push_back(basen); |
104 |
21 |
return true; |
105 |
|
} |
106 |
|
|
107 |
|
} // namespace quantifiers |
108 |
|
} // namespace theory |
109 |
29340 |
} // namespace cvc5 |