GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/decision/assertion_list.cpp Lines: 1 61 1.6 %
Date: 2021-05-22 Branches: 2 161 1.2 %

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
 * Implementation of assertion list
14
 */
15
16
#include "decision/assertion_list.h"
17
18
namespace cvc5 {
19
namespace decision {
20
21
const char* toString(DecisionStatus s)
22
{
23
  switch (s)
24
  {
25
    case DecisionStatus::INACTIVE: return "INACTIVE";
26
    case DecisionStatus::NO_DECISION: return "NO_DECISION";
27
    case DecisionStatus::DECISION: return "DECISION";
28
    case DecisionStatus::BACKTRACK: return "BACKTRACK";
29
    default: return "?";
30
  }
31
}
32
33
std::ostream& operator<<(std::ostream& out, DecisionStatus s)
34
{
35
  out << toString(s);
36
  return out;
37
}
38
39
AssertionList::AssertionList(context::Context* ac,
40
                             context::Context* ic,
41
                             bool useDyn)
42
    : d_assertions(ac),
43
      d_assertionIndex(ic),
44
      d_usingDynamic(useDyn),
45
      d_dindex(ic)
46
{
47
}
48
49
void AssertionList::presolve()
50
{
51
  Trace("jh-status") << "AssertionList::presolve" << std::endl;
52
  d_assertionIndex = 0;
53
  d_dlist.clear();
54
  d_dindex = 0;
55
}
56
57
void AssertionList::addAssertion(TNode n) { d_assertions.push_back(n); }
58
59
TNode AssertionList::getNextAssertion()
60
{
61
  size_t fromIndex;
62
  if (d_usingDynamic)
63
  {
64
    // is a dynamic assertion ready?
65
    fromIndex = d_dindex.get();
66
    if (fromIndex < d_dlist.size())
67
    {
68
      d_dindex = d_dindex.get() + 1;
69
      Trace("jh-status") << "Assertion " << d_dlist[fromIndex].getId()
70
                         << " from dynamic list" << std::endl;
71
      return d_dlist[fromIndex];
72
    }
73
  }
74
  // check if dynamic assertions
75
  fromIndex = d_assertionIndex.get();
76
  Assert(fromIndex <= d_assertions.size());
77
  if (fromIndex == d_assertions.size())
78
  {
79
    return Node::null();
80
  }
81
  // increment for the next iteration
82
  d_assertionIndex = d_assertionIndex + 1;
83
  Trace("jh-status") << "Assertion " << d_assertions[fromIndex].getId()
84
                     << std::endl;
85
  return d_assertions[fromIndex];
86
}
87
size_t AssertionList::size() const { return d_assertions.size(); }
88
89
void AssertionList::notifyStatus(TNode n, DecisionStatus s)
90
{
91
  Trace("jh-status") << "Assertion status " << s << " for " << n.getId()
92
                     << ", current " << d_dindex.get() << "/" << d_dlist.size()
93
                     << std::endl;
94
  if (!d_usingDynamic)
95
  {
96
    // not using dynamic ordering, return
97
    return;
98
  }
99
  if (s == DecisionStatus::NO_DECISION)
100
  {
101
    // no decision does not impact the decision order
102
    return;
103
  }
104
  std::unordered_set<TNode>::iterator it = d_dlistSet.find(n);
105
  if (s == DecisionStatus::DECISION)
106
  {
107
    if (it == d_dlistSet.end())
108
    {
109
      // if we just had a status on an assertion and it didn't occur in dlist,
110
      // then our index should have exhausted dlist
111
      Assert(d_dindex.get() == d_dlist.size());
112
      if (d_dindex.get() == d_dlist.size())
113
      {
114
        d_dindex = d_dindex.get() + 1;
115
      }
116
      // add to back of the decision list if not already there
117
      d_dlist.push_back(n);
118
      d_dlistSet.insert(n);
119
      Trace("jh-status") << "...push due to decision" << std::endl;
120
    }
121
    return;
122
  }
123
  if (s == DecisionStatus::BACKTRACK)
124
  {
125
    // backtrack inserts at the current position
126
    if (it == d_dlistSet.end())
127
    {
128
      d_dlist.insert(d_dlist.begin(), n);
129
      d_dlistSet.insert(n);
130
    }
131
  }
132
}
133
134
}  // namespace decision
135
28191
}  // namespace cvc5