GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/inst_strategy_pool.cpp Lines: 55 69 79.7 %
Date: 2021-09-17 Branches: 73 181 40.3 %

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