GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/solution_filter.cpp Lines: 28 45 62.2 %
Date: 2021-05-22 Branches: 48 172 27.9 %

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