GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bags/solver_state.cpp Lines: 67 67 100.0 %
Date: 2021-09-29 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
6271
SolverState::SolverState(Env& env, Valuation val) : TheoryState(env, val)
31
{
32
6271
  d_true = NodeManager::currentNM()->mkConst(true);
33
6271
  d_false = NodeManager::currentNM()->mkConst(false);
34
6271
  d_nm = NodeManager::currentNM();
35
6271
}
36
37
669
void SolverState::registerBag(TNode n)
38
{
39
669
  Assert(n.getType().isBag());
40
669
  d_bags.insert(n);
41
669
}
42
43
2167
void SolverState::registerCountTerm(TNode n)
44
{
45
2167
  Assert(n.getKind() == BAG_COUNT);
46
4334
  Node element = getRepresentative(n[0]);
47
4334
  Node bag = getRepresentative(n[1]);
48
2167
  d_bagElements[bag].insert(element);
49
2167
}
50
51
21320
const std::set<Node>& SolverState::getBags() { return d_bags; }
52
53
1888
const std::set<Node>& SolverState::getElements(Node B)
54
{
55
3776
  Node bag = getRepresentative(B);
56
3776
  return d_bagElements[bag];
57
}
58
59
10660
const std::set<Node>& SolverState::getDisequalBagTerms() { return d_deq; }
60
61
10660
void SolverState::reset()
62
{
63
10660
  d_bagElements.clear();
64
10660
  d_bags.clear();
65
10660
  d_deq.clear();
66
10660
}
67
68
10660
void SolverState::initialize()
69
{
70
10660
  reset();
71
10660
  collectBagsAndCountTerms();
72
10660
  collectDisequalBagTerms();
73
10660
}
74
75
10660
void SolverState::collectBagsAndCountTerms()
76
{
77
10660
  eq::EqClassesIterator repIt = eq::EqClassesIterator(d_ee);
78
57374
  while (!repIt.isFinished())
79
  {
80
46714
    Node eqc = (*repIt);
81
23357
    Trace("bags-eqc") << "Eqc [ " << eqc << " ] = { ";
82
83
23357
    if (eqc.getType().isBag())
84
    {
85
669
      registerBag(eqc);
86
    }
87
88
23357
    eq::EqClassIterator it = eq::EqClassIterator(eqc, d_ee);
89
78559
    while (!it.isFinished())
90
    {
91
55202
      Node n = (*it);
92
27601
      Trace("bags-eqc") << (*it) << " ";
93
27601
      Kind k = n.getKind();
94
27601
      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
344
        Node count = d_nm->mkNode(BAG_COUNT, n[0], n);
99
172
        registerCountTerm(count);
100
344
        Trace("SolverState::collectBagsAndCountTerms")
101
172
            << "registered " << count << endl;
102
      }
103
27601
      if (k == BAG_COUNT)
104
      {
105
        // this takes care of all count terms in each equivalent class
106
1995
        registerCountTerm(n);
107
3990
        Trace("SolverState::collectBagsAndCountTerms")
108
1995
            << "registered " << n << endl;
109
      }
110
27601
      ++it;
111
    }
112
23357
    Trace("bags-eqc") << " } " << std::endl;
113
23357
    ++repIt;
114
  }
115
116
10660
  Trace("bags-eqc") << "bag representatives: " << d_bags << endl;
117
10660
  Trace("bags-eqc") << "bag elements: " << d_bagElements << endl;
118
10660
}
119
120
10660
void SolverState::collectDisequalBagTerms()
121
{
122
10660
  eq::EqClassIterator it = eq::EqClassIterator(d_false, d_ee);
123
33634
  while (!it.isFinished())
124
  {
125
22974
    Node n = (*it);
126
11487
    if (n.getKind() == EQUAL && n[0].getType().isBag())
127
    {
128
280
      Trace("bags-eqc") << "Disequal terms: " << n << std::endl;
129
280
      d_deq.insert(n);
130
    }
131
11487
    ++it;
132
  }
133
10660
}
134
135
}  // namespace bags
136
}  // namespace theory
137
22746
}  // namespace cvc5