1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/********************* */
/*! \file bag_solver.cpp
** \verbatim
** Top contributors (to current version):
** Mudathir Mohamed
** This file is part of the CVC4 project.
** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
** in the top-level source directory and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**
** \brief solver for the theory of bags.
**
** solver for the theory of bags.
**/
#include "theory/bags/bag_solver.h"
#include "theory/bags/inference_generator.h"
using namespace std;
using namespace CVC4::context;
using namespace CVC4::kind;
namespace CVC4 {
namespace theory {
namespace bags {
BagSolver::BagSolver(SolverState& s, InferenceManager& im, TermRegistry& tr)
: d_state(s), d_im(im), d_termReg(tr)
{
d_zero = NodeManager::currentNM()->mkConst(Rational(0));
d_one = NodeManager::currentNM()->mkConst(Rational(1));
d_true = NodeManager::currentNM()->mkConst(true);
d_false = NodeManager::currentNM()->mkConst(false);
}
BagSolver::~BagSolver() {}
void BagSolver::postCheck()
{
for (const Node& n : d_state.getBags())
{
Kind k = n.getKind();
switch (k)
{
case kind::MK_BAG: checkMkBag(n); break;
case kind::UNION_DISJOINT: checkUnionDisjoint(n); break;
case kind::UNION_MAX: checkUnionMax(n); break;
case kind::DIFFERENCE_SUBTRACT: checkDifferenceSubtract(n); break;
default: break;
}
}
}
void BagSolver::checkUnionDisjoint(const Node& n)
{
Assert(n.getKind() == UNION_DISJOINT);
TypeNode elementType = n.getType().getBagElementType();
for (const Node& e : d_state.getElements(elementType))
{
InferenceGenerator ig(&d_state);
InferInfo i = ig.unionDisjoint(n, e);
i.process(&d_im, true);
Trace("bags::BagSolver::postCheck") << i << endl;
}
}
void BagSolver::checkUnionMax(const Node& n)
{
Assert(n.getKind() == UNION_MAX);
TypeNode elementType = n.getType().getBagElementType();
for (const Node& e : d_state.getElements(elementType))
{
InferenceGenerator ig(&d_state);
InferInfo i = ig.unionMax(n, e);
i.process(&d_im, true);
Trace("bags::BagSolver::postCheck") << i << endl;
}
}
void BagSolver::checkDifferenceSubtract(const Node& n)
{
Assert(n.getKind() == DIFFERENCE_SUBTRACT);
TypeNode elementType = n.getType().getBagElementType();
for (const Node& e : d_state.getElements(elementType))
{
InferenceGenerator ig(&d_state);
InferInfo i = ig.differenceSubtract(n, e);
i.process(&d_im, true);
Trace("bags::BagSolver::postCheck") << i << endl;
}
}
void BagSolver::checkMkBag(const Node& n)
{
Assert(n.getKind() == MK_BAG);
TypeNode elementType = n.getType().getBagElementType();
for (const Node& e : d_state.getElements(elementType))
{
InferenceGenerator ig(&d_state);
InferInfo i = ig.mkBag(n, e);
i.process(&d_im, true);
Trace("bags::BagSolver::postCheck") << i << endl;
}
}
} // namespace bags
} // namespace theory
} // namespace CVC4
|