GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/expr_miner.cpp Lines: 40 44 90.9 %
Date: 2021-05-22 Branches: 52 132 39.4 %

Line Exec Source
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
247
Node ExprMiner::convertToSkolem(Node n)
40
{
41
494
  std::vector<Node> fvs;
42
247
  TermUtil::computeVarContains(n, fvs);
43
247
  if (fvs.empty())
44
  {
45
6
    return n;
46
  }
47
482
  std::vector<Node> sfvs;
48
482
  std::vector<Node> sks;
49
  // map to skolems
50
241
  NodeManager* nm = NodeManager::currentNM();
51
241
  SkolemManager* sm = nm->getSkolemManager();
52
718
  for (unsigned i = 0, size = fvs.size(); i < size; i++)
53
  {
54
954
    Node v = fvs[i];
55
    // only look at the sampler variables
56
477
    if (std::find(d_vars.begin(), d_vars.end(), v) != d_vars.end())
57
    {
58
477
      sfvs.push_back(v);
59
477
      std::map<Node, Node>::iterator itf = d_fv_to_skolem.find(v);
60
477
      if (itf == d_fv_to_skolem.end())
61
      {
62
110
        Node sk = sm->mkDummySkolem("rrck", v.getType());
63
55
        d_fv_to_skolem[v] = sk;
64
55
        sks.push_back(sk);
65
      }
66
      else
67
      {
68
422
        sks.push_back(itf->second);
69
      }
70
    }
71
  }
72
241
  return n.substitute(sfvs.begin(), sfvs.end(), sks.begin(), sks.end());
73
}
74
75
247
void ExprMiner::initializeChecker(std::unique_ptr<SmtEngine>& checker,
76
                                  Node query)
77
{
78
247
  Assert (!query.isNull());
79
494
  if (Options::current().wasSetByUser(options::sygusExprMinerCheckTimeout))
80
  {
81
    initializeSubsolver(checker, true, options::sygusExprMinerCheckTimeout());
82
  }
83
  else
84
  {
85
247
    initializeSubsolver(checker);
86
  }
87
  // also set the options
88
247
  checker->setOption("sygus-rr-synth-input", "false");
89
247
  checker->setOption("input-language", "smt2");
90
  // Convert bound variables to skolems. This ensures the satisfiability
91
  // check is ground.
92
494
  Node squery = convertToSkolem(query);
93
247
  checker->assertFormula(squery);
94
247
}
95
96
54
Result ExprMiner::doCheck(Node query)
97
{
98
108
  Node queryr = Rewriter::rewrite(query);
99
54
  if (queryr.isConst())
100
  {
101
    if (!queryr.getConst<bool>())
102
    {
103
      return Result(Result::UNSAT);
104
    }
105
    else
106
    {
107
      return Result(Result::SAT);
108
    }
109
  }
110
108
  std::unique_ptr<SmtEngine> smte;
111
54
  initializeChecker(smte, query);
112
54
  return smte->checkSat();
113
}
114
115
}  // namespace quantifiers
116
}  // namespace theory
117
28441
}  // namespace cvc5