GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/quantifiers_state.cpp Lines: 41 81 50.6 %
Date: 2021-05-24 Branches: 62 246 25.2 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner, Morgan Deters
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
 * Utility for quantifiers state.
14
 */
15
16
#include "theory/quantifiers/quantifiers_state.h"
17
18
#include "options/quantifiers_options.h"
19
#include "theory/uf/equality_engine_iterator.h"
20
21
namespace cvc5 {
22
namespace theory {
23
namespace quantifiers {
24
25
9459
QuantifiersState::QuantifiersState(context::Context* c,
26
                                   context::UserContext* u,
27
                                   Valuation val,
28
9459
                                   const LogicInfo& logicInfo)
29
9459
    : TheoryState(c, u, val), d_ierCounterc(c), d_logicInfo(logicInfo)
30
{
31
  // allow theory combination to go first, once initially
32
18918
  d_ierCounter = options::instWhenTcFirst() ? 0 : 1;
33
9459
  d_ierCounterc = d_ierCounter;
34
9459
  d_ierCounterLc = 0;
35
9459
  d_ierCounterLastLc = 0;
36
9459
  d_instWhenPhase =
37
28377
      1 + (options::instWhenPhase() < 1 ? 1 : options::instWhenPhase());
38
9459
}
39
40
23062
void QuantifiersState::incrementInstRoundCounters(Theory::Effort e)
41
{
42
23062
  if (e == Theory::EFFORT_FULL)
43
  {
44
    // increment if a last call happened, we are not strictly enforcing
45
    // interleaving, or already were in phase
46
24774
    if (d_ierCounterLastLc != d_ierCounterLc
47
18892
        || !options::instWhenStrictInterleave()
48
21833
        || d_ierCounter % d_instWhenPhase != 0)
49
    {
50
4592
      d_ierCounter = d_ierCounter + 1;
51
4592
      d_ierCounterLastLc = d_ierCounterLc;
52
4592
      d_ierCounterc = d_ierCounterc.get() + 1;
53
    }
54
  }
55
10675
  else if (e == Theory::EFFORT_LAST_CALL)
56
  {
57
10675
    d_ierCounterLc = d_ierCounterLc + 1;
58
  }
59
23062
}
60
61
154258
bool QuantifiersState::getInstWhenNeedsCheck(Theory::Effort e) const
62
{
63
308516
  Trace("qstate-debug") << "Get inst when needs check, counts=" << d_ierCounter
64
154258
                        << ", " << d_ierCounterLc << std::endl;
65
  // determine if we should perform check, based on instWhenMode
66
154258
  bool performCheck = false;
67
154258
  if (options::instWhenMode() == options::InstWhenMode::FULL)
68
  {
69
36
    performCheck = (e >= Theory::EFFORT_FULL);
70
  }
71
154222
  else if (options::instWhenMode() == options::InstWhenMode::FULL_DELAY)
72
  {
73
    performCheck = (e >= Theory::EFFORT_FULL) && !d_valuation.needCheck();
74
  }
75
154222
  else if (options::instWhenMode() == options::InstWhenMode::FULL_LAST_CALL)
76
  {
77
143302
    performCheck =
78
35013
        ((e == Theory::EFFORT_FULL && d_ierCounter % d_instWhenPhase != 0)
79
281313
         || e == Theory::EFFORT_LAST_CALL);
80
  }
81
21840
  else if (options::instWhenMode()
82
10920
           == options::InstWhenMode::FULL_DELAY_LAST_CALL)
83
  {
84
    performCheck = ((e == Theory::EFFORT_FULL && !d_valuation.needCheck()
85
                     && d_ierCounter % d_instWhenPhase != 0)
86
                    || e == Theory::EFFORT_LAST_CALL);
87
  }
88
10920
  else if (options::instWhenMode() == options::InstWhenMode::LAST_CALL)
89
  {
90
10920
    performCheck = (e >= Theory::EFFORT_LAST_CALL);
91
  }
92
  else
93
  {
94
    performCheck = true;
95
  }
96
154258
  Trace("qstate-debug") << "...returned " << performCheck << std::endl;
97
154258
  return performCheck;
98
}
99
100
uint64_t QuantifiersState::getInstRoundDepth() const
101
{
102
  return d_ierCounterc.get();
103
}
104
105
uint64_t QuantifiersState::getInstRounds() const { return d_ierCounter; }
106
107
void QuantifiersState::debugPrintEqualityEngine(const char* c) const
108
{
109
  bool traceEnabled = Trace.isOn(c);
110
  if (!traceEnabled)
111
  {
112
    return;
113
  }
114
  eq::EqualityEngine* ee = getEqualityEngine();
115
  eq::EqClassesIterator eqcs_i = eq::EqClassesIterator(ee);
116
  std::map<TypeNode, uint64_t> tnum;
117
  while (!eqcs_i.isFinished())
118
  {
119
    TNode r = (*eqcs_i);
120
    TypeNode tr = r.getType();
121
    if (tnum.find(tr) == tnum.end())
122
    {
123
      tnum[tr] = 0;
124
    }
125
    tnum[tr]++;
126
    bool firstTime = true;
127
    Trace(c) << "  " << r;
128
    Trace(c) << " : { ";
129
    eq::EqClassIterator eqc_i = eq::EqClassIterator(r, ee);
130
    while (!eqc_i.isFinished())
131
    {
132
      TNode n = (*eqc_i);
133
      if (r != n)
134
      {
135
        if (firstTime)
136
        {
137
          Trace(c) << std::endl;
138
          firstTime = false;
139
        }
140
        Trace(c) << "    " << n << std::endl;
141
      }
142
      ++eqc_i;
143
    }
144
    if (!firstTime)
145
    {
146
      Trace(c) << "  ";
147
    }
148
    Trace(c) << "}" << std::endl;
149
    ++eqcs_i;
150
  }
151
  Trace(c) << std::endl;
152
  for (const std::pair<const TypeNode, uint64_t>& t : tnum)
153
  {
154
    Trace(c) << "# eqc for " << t.first << " : " << t.second << std::endl;
155
  }
156
}
157
158
3971
const LogicInfo& QuantifiersState::getLogicInfo() const { return d_logicInfo; }
159
160
236789
QuantifiersStatistics& QuantifiersState::getStats() { return d_statistics; }
161
162
}  // namespace quantifiers
163
}  // namespace theory
164
66014
}  // namespace cvc5