GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/inst_strategy_pool.cpp Lines: 55 69 79.7 %
Date: 2021-05-22 Branches: 73 187 39.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds
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
 * Pool-based instantiation strategy
14
 */
15
16
#include "theory/quantifiers/inst_strategy_pool.h"
17
18
#include "options/quantifiers_options.h"
19
#include "theory/quantifiers/first_order_model.h"
20
#include "theory/quantifiers/instantiate.h"
21
#include "theory/quantifiers/quantifiers_inference_manager.h"
22
#include "theory/quantifiers/term_pools.h"
23
#include "theory/quantifiers/term_registry.h"
24
#include "theory/quantifiers/term_tuple_enumerator.h"
25
26
using namespace cvc5::kind;
27
using namespace cvc5::context;
28
29
namespace cvc5 {
30
namespace theory {
31
namespace quantifiers {
32
33
6414
InstStrategyPool::InstStrategyPool(QuantifiersState& qs,
34
                                   QuantifiersInferenceManager& qim,
35
                                   QuantifiersRegistry& qr,
36
6414
                                   TermRegistry& tr)
37
6414
    : QuantifiersModule(qs, qim, qr, tr)
38
{
39
6414
}
40
41
7331
void InstStrategyPool::presolve() {}
42
43
91213
bool InstStrategyPool::needsCheck(Theory::Effort e)
44
{
45
91213
  return d_qstate.getInstWhenNeedsCheck(e);
46
}
47
48
24825
void InstStrategyPool::reset_round(Theory::Effort e) {}
49
50
25053
void InstStrategyPool::registerQuantifier(Node q)
51
{
52
  // take into account user pools
53
25053
  if (q.getNumChildren() == 3)
54
  {
55
9962
    Node subsPat = d_qreg.substituteBoundVariablesToInstConstants(q[2], q);
56
    // add patterns
57
10303
    for (const Node& p : subsPat)
58
    {
59
5322
      if (p.getKind() == INST_POOL)
60
      {
61
8
        d_userPools[q].push_back(p);
62
      }
63
    }
64
  }
65
25053
}
66
67
40742
void InstStrategyPool::check(Theory::Effort e, QEffort quant_e)
68
{
69
40742
  if (d_userPools.empty())
70
  {
71
40738
    return;
72
  }
73
4
  double clSet = 0;
74
4
  if (Trace.isOn("pool-engine"))
75
  {
76
    clSet = double(clock()) / double(CLOCKS_PER_SEC);
77
    Trace("pool-engine") << "---Pool instantiation, effort = " << e << "---"
78
                         << std::endl;
79
  }
80
4
  FirstOrderModel* fm = d_treg.getModel();
81
4
  bool inConflict = false;
82
4
  uint64_t addedLemmas = 0;
83
4
  size_t nquant = fm->getNumAssertedQuantifiers();
84
4
  std::map<Node, std::vector<Node> >::iterator uit;
85
8
  for (size_t i = 0; i < nquant; i++)
86
  {
87
8
    Node q = fm->getAssertedQuantifier(i, true);
88
4
    uit = d_userPools.find(q);
89
4
    if (uit == d_userPools.end())
90
    {
91
      // no user pools for this
92
      continue;
93
    }
94
4
    if (!d_qreg.hasOwnership(q, this) || !fm->isQuantifierActive(q))
95
    {
96
      // quantified formula is not owned by this or is inactive
97
      continue;
98
    }
99
    // process with each user pool
100
8
    for (const Node& p : uit->second)
101
    {
102
4
      inConflict = process(q, p, addedLemmas);
103
4
      if (inConflict)
104
      {
105
        break;
106
      }
107
    }
108
4
    if (inConflict)
109
    {
110
      break;
111
    }
112
  }
113
4
  if (Trace.isOn("pool-engine"))
114
  {
115
    Trace("pool-engine") << "Added lemmas = " << addedLemmas << std::endl;
116
    double clSet2 = double(clock()) / double(CLOCKS_PER_SEC);
117
    Trace("pool-engine") << "Finished pool instantiation, time = "
118
                         << (clSet2 - clSet) << std::endl;
119
  }
120
}
121
122
140752
std::string InstStrategyPool::identify() const
123
{
124
140752
  return std::string("InstStrategyPool");
125
}
126
127
4
bool InstStrategyPool::process(Node q, Node p, uint64_t& addedLemmas)
128
{
129
  TermTupleEnumeratorEnv ttec;
130
4
  ttec.d_fullEffort = true;
131
4
  ttec.d_increaseSum = options::fullSaturateSum();
132
4
  TermPools* tp = d_treg.getTermPools();
133
  std::shared_ptr<TermTupleEnumeratorInterface> enumerator(
134
8
      mkTermTupleEnumeratorPool(q, &ttec, tp, p));
135
4
  Instantiate* ie = d_qim.getInstantiate();
136
8
  std::vector<Node> terms;
137
8
  std::vector<bool> failMask;
138
  // we instantiate exhaustively
139
4
  enumerator->init();
140
12
  while (enumerator->hasNext())
141
  {
142
4
    if (d_qstate.isInConflict())
143
    {
144
      // could be conflicting for an internal reason
145
      return true;
146
    }
147
4
    enumerator->next(terms);
148
    // try instantiation
149
4
    failMask.clear();
150
4
    if (ie->addInstantiationExpFail(
151
            q, terms, failMask, InferenceId::QUANTIFIERS_INST_POOL))
152
    {
153
4
      Trace("pool-inst") << "Success with " << terms << std::endl;
154
4
      addedLemmas++;
155
    }
156
    else
157
    {
158
      Trace("pool-inst") << "Fail with " << terms << std::endl;
159
      // notify the enumerator of the failure
160
      enumerator->failureReason(failMask);
161
    }
162
  }
163
4
  return false;
164
}
165
166
}  // namespace quantifiers
167
}  // namespace theory
168
28194
}  // namespace cvc5