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