GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bags/solver_state.cpp Lines: 67 67 100.0 %
Date: 2021-11-05 Branches: 123 252 48.8 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Mudathir Mohamed, Aina Niemetz
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 bags state object.
14
 */
15
16
#include "theory/bags/solver_state.h"
17
18
#include "expr/attribute.h"
19
#include "expr/bound_var_manager.h"
20
#include "expr/skolem_manager.h"
21
#include "theory/uf/equality_engine.h"
22
23
using namespace std;
24
using namespace cvc5::kind;
25
26
namespace cvc5 {
27
namespace theory {
28
namespace bags {
29
30
15271
SolverState::SolverState(Env& env, Valuation val) : TheoryState(env, val)
31
{
32
15271
  d_true = NodeManager::currentNM()->mkConst(true);
33
15271
  d_false = NodeManager::currentNM()->mkConst(false);
34
15271
  d_nm = NodeManager::currentNM();
35
15271
}
36
37
1511
void SolverState::registerBag(TNode n)
38
{
39
1511
  Assert(n.getType().isBag());
40
1511
  d_bags.insert(n);
41
1511
}
42
43
6174
void SolverState::registerCountTerm(TNode n)
44
{
45
6174
  Assert(n.getKind() == BAG_COUNT);
46
12348
  Node element = getRepresentative(n[0]);
47
12348
  Node bag = getRepresentative(n[1]);
48
6174
  d_bagElements[bag].insert(element);
49
6174
}
50
51
36488
const std::set<Node>& SolverState::getBags() { return d_bags; }
52
53
4589
const std::set<Node>& SolverState::getElements(Node B)
54
{
55
9178
  Node bag = getRepresentative(B);
56
9178
  return d_bagElements[bag];
57
}
58
59
18244
const std::set<Node>& SolverState::getDisequalBagTerms() { return d_deq; }
60
61
18244
void SolverState::reset()
62
{
63
18244
  d_bagElements.clear();
64
18244
  d_bags.clear();
65
18244
  d_deq.clear();
66
18244
}
67
68
18244
void SolverState::initialize()
69
{
70
18244
  reset();
71
18244
  collectBagsAndCountTerms();
72
18244
  collectDisequalBagTerms();
73
18244
}
74
75
18244
void SolverState::collectBagsAndCountTerms()
76
{
77
18244
  eq::EqClassesIterator repIt = eq::EqClassesIterator(d_ee);
78
103090
  while (!repIt.isFinished())
79
  {
80
84846
    Node eqc = (*repIt);
81
42423
    Trace("bags-eqc") << "Eqc [ " << eqc << " ] = { ";
82
83
42423
    if (eqc.getType().isBag())
84
    {
85
1511
      registerBag(eqc);
86
    }
87
88
42423
    eq::EqClassIterator it = eq::EqClassIterator(eqc, d_ee);
89
152603
    while (!it.isFinished())
90
    {
91
110180
      Node n = (*it);
92
55090
      Trace("bags-eqc") << (*it) << " ";
93
55090
      Kind k = n.getKind();
94
55090
      if (k == MK_BAG)
95
      {
96
        // for terms (bag x c) we need to store x by registering the count term
97
        // (bag.count x (bag x c))
98
1160
        Node count = d_nm->mkNode(BAG_COUNT, n[0], n);
99
580
        registerCountTerm(count);
100
1160
        Trace("SolverState::collectBagsAndCountTerms")
101
580
            << "registered " << count << endl;
102
      }
103
55090
      if (k == BAG_COUNT)
104
      {
105
        // this takes care of all count terms in each equivalent class
106
5594
        registerCountTerm(n);
107
11188
        Trace("SolverState::collectBagsAndCountTerms")
108
5594
            << "registered " << n << endl;
109
      }
110
55090
      ++it;
111
    }
112
42423
    Trace("bags-eqc") << " } " << std::endl;
113
42423
    ++repIt;
114
  }
115
116
18244
  Trace("bags-eqc") << "bag representatives: " << d_bags << endl;
117
18244
  Trace("bags-eqc") << "bag elements: " << d_bagElements << endl;
118
18244
}
119
120
18244
void SolverState::collectDisequalBagTerms()
121
{
122
18244
  eq::EqClassIterator it = eq::EqClassIterator(d_false, d_ee);
123
57734
  while (!it.isFinished())
124
  {
125
39490
    Node n = (*it);
126
19745
    if (n.getKind() == EQUAL && n[0].getType().isBag())
127
    {
128
445
      Trace("bags-eqc") << "Disequal terms: " << n << std::endl;
129
445
      d_deq.insert(n);
130
    }
131
19745
    ++it;
132
  }
133
18244
}
134
135
}  // namespace bags
136
}  // namespace theory
137
31125
}  // namespace cvc5