GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/quantifiers_state.cpp Lines: 41 81 50.6 %
Date: 2021-09-18 Branches: 52 220 23.6 %

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
9940
QuantifiersState::QuantifiersState(Env& env,
26
                                   Valuation val,
27
9940
                                   const LogicInfo& logicInfo)
28
    : TheoryState(env, val),
29
      d_ierCounterc(env.getContext()),
30
9940
      d_logicInfo(logicInfo)
31
{
32
  // allow theory combination to go first, once initially
33
9940
  d_ierCounter = options::instWhenTcFirst() ? 0 : 1;
34
9940
  d_ierCounterc = d_ierCounter;
35
9940
  d_ierCounterLc = 0;
36
9940
  d_ierCounterLastLc = 0;
37
9940
  d_instWhenPhase =
38
9940
      1 + (options::instWhenPhase() < 1 ? 1 : options::instWhenPhase());
39
9940
}
40
41
26610
void QuantifiersState::incrementInstRoundCounters(Theory::Effort e)
42
{
43
26610
  if (e == Theory::EFFORT_FULL)
44
  {
45
    // increment if a last call happened, we are not strictly enforcing
46
    // interleaving, or already were in phase
47
30464
    if (d_ierCounterLastLc != d_ierCounterLc
48
12283
        || !options::instWhenStrictInterleave()
49
27515
        || d_ierCounter % d_instWhenPhase != 0)
50
    {
51
4727
      d_ierCounter = d_ierCounter + 1;
52
4727
      d_ierCounterLastLc = d_ierCounterLc;
53
4727
      d_ierCounterc = d_ierCounterc.get() + 1;
54
    }
55
  }
56
11378
  else if (e == Theory::EFFORT_LAST_CALL)
57
  {
58
11378
    d_ierCounterLc = d_ierCounterLc + 1;
59
  }
60
26610
}
61
62
145410
bool QuantifiersState::getInstWhenNeedsCheck(Theory::Effort e) const
63
{
64
290820
  Trace("qstate-debug") << "Get inst when needs check, counts=" << d_ierCounter
65
145410
                        << ", " << d_ierCounterLc << std::endl;
66
  // determine if we should perform check, based on instWhenMode
67
145410
  bool performCheck = false;
68
145410
  if (options::instWhenMode() == options::InstWhenMode::FULL)
69
  {
70
36
    performCheck = (e >= Theory::EFFORT_FULL);
71
  }
72
145374
  else if (options::instWhenMode() == options::InstWhenMode::FULL_DELAY)
73
  {
74
    performCheck = (e >= Theory::EFFORT_FULL) && !d_valuation.needCheck();
75
  }
76
145374
  else if (options::instWhenMode() == options::InstWhenMode::FULL_LAST_CALL)
77
  {
78
133296
    performCheck =
79
42025
        ((e == Theory::EFFORT_FULL && d_ierCounter % d_instWhenPhase != 0)
80
261036
         || e == Theory::EFFORT_LAST_CALL);
81
  }
82
24156
  else if (options::instWhenMode()
83
12078
           == options::InstWhenMode::FULL_DELAY_LAST_CALL)
84
  {
85
    performCheck = ((e == Theory::EFFORT_FULL && !d_valuation.needCheck()
86
                     && d_ierCounter % d_instWhenPhase != 0)
87
                    || e == Theory::EFFORT_LAST_CALL);
88
  }
89
12078
  else if (options::instWhenMode() == options::InstWhenMode::LAST_CALL)
90
  {
91
12078
    performCheck = (e >= Theory::EFFORT_LAST_CALL);
92
  }
93
  else
94
  {
95
    performCheck = true;
96
  }
97
145410
  Trace("qstate-debug") << "...returned " << performCheck << std::endl;
98
145410
  return performCheck;
99
}
100
101
uint64_t QuantifiersState::getInstRoundDepth() const
102
{
103
  return d_ierCounterc.get();
104
}
105
106
uint64_t QuantifiersState::getInstRounds() const { return d_ierCounter; }
107
108
void QuantifiersState::debugPrintEqualityEngine(const char* c) const
109
{
110
  bool traceEnabled = Trace.isOn(c);
111
  if (!traceEnabled)
112
  {
113
    return;
114
  }
115
  eq::EqualityEngine* ee = getEqualityEngine();
116
  eq::EqClassesIterator eqcs_i = eq::EqClassesIterator(ee);
117
  std::map<TypeNode, uint64_t> tnum;
118
  while (!eqcs_i.isFinished())
119
  {
120
    TNode r = (*eqcs_i);
121
    TypeNode tr = r.getType();
122
    if (tnum.find(tr) == tnum.end())
123
    {
124
      tnum[tr] = 0;
125
    }
126
    tnum[tr]++;
127
    bool firstTime = true;
128
    Trace(c) << "  " << r;
129
    Trace(c) << " : { ";
130
    eq::EqClassIterator eqc_i = eq::EqClassIterator(r, ee);
131
    while (!eqc_i.isFinished())
132
    {
133
      TNode n = (*eqc_i);
134
      if (r != n)
135
      {
136
        if (firstTime)
137
        {
138
          Trace(c) << std::endl;
139
          firstTime = false;
140
        }
141
        Trace(c) << "    " << n << std::endl;
142
      }
143
      ++eqc_i;
144
    }
145
    if (!firstTime)
146
    {
147
      Trace(c) << "  ";
148
    }
149
    Trace(c) << "}" << std::endl;
150
    ++eqcs_i;
151
  }
152
  Trace(c) << std::endl;
153
  for (const std::pair<const TypeNode, uint64_t>& t : tnum)
154
  {
155
    Trace(c) << "# eqc for " << t.first << " : " << t.second << std::endl;
156
  }
157
}
158
159
5825
const LogicInfo& QuantifiersState::getLogicInfo() const { return d_logicInfo; }
160
161
243791
QuantifiersStatistics& QuantifiersState::getStats() { return d_statistics; }
162
163
}  // namespace quantifiers
164
}  // namespace theory
165
29574
}  // namespace cvc5