1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Mudathir Mohamed |
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 |
|
* Bag enumerator implementation |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/bags/theory_bags_type_enumerator.h" |
17 |
|
|
18 |
|
#include "expr/emptybag.h" |
19 |
|
#include "theory/rewriter.h" |
20 |
|
#include "theory_bags_type_enumerator.h" |
21 |
|
#include "util/rational.h" |
22 |
|
|
23 |
|
namespace cvc5 { |
24 |
|
namespace theory { |
25 |
|
namespace bags { |
26 |
|
|
27 |
|
BagEnumerator::BagEnumerator(TypeNode type, TypeEnumeratorProperties* tep) |
28 |
|
: TypeEnumeratorBase<BagEnumerator>(type), |
29 |
|
d_nodeManager(NodeManager::currentNM()), |
30 |
|
d_elementTypeEnumerator(type.getBagElementType(), tep) |
31 |
|
{ |
32 |
|
d_currentBag = d_nodeManager->mkConst(EmptyBag(type)); |
33 |
|
d_element = *d_elementTypeEnumerator; |
34 |
|
} |
35 |
|
|
36 |
|
BagEnumerator::BagEnumerator(const BagEnumerator& enumerator) |
37 |
|
: TypeEnumeratorBase<BagEnumerator>(enumerator.getType()), |
38 |
|
d_nodeManager(enumerator.d_nodeManager), |
39 |
|
d_elementTypeEnumerator(enumerator.d_elementTypeEnumerator), |
40 |
|
d_currentBag(enumerator.d_currentBag), |
41 |
|
d_element(enumerator.d_element) |
42 |
|
{ |
43 |
|
} |
44 |
|
|
45 |
|
BagEnumerator::~BagEnumerator() {} |
46 |
|
|
47 |
|
Node BagEnumerator::operator*() |
48 |
|
{ |
49 |
|
Trace("bag-type-enum") << "BagEnumerator::operator* d_currentBag = " |
50 |
|
<< d_currentBag << std::endl; |
51 |
|
|
52 |
|
return d_currentBag; |
53 |
|
} |
54 |
|
|
55 |
|
BagEnumerator& BagEnumerator::operator++() |
56 |
|
{ |
57 |
|
// increase the multiplicity by one |
58 |
|
Node one = d_nodeManager->mkConst(Rational(1)); |
59 |
|
TypeNode elementType = d_elementTypeEnumerator.getType(); |
60 |
|
Node singleton = d_nodeManager->mkBag(elementType, d_element, one); |
61 |
|
if (d_currentBag.getKind() == kind::EMPTYBAG) |
62 |
|
{ |
63 |
|
d_currentBag = singleton; |
64 |
|
} |
65 |
|
else |
66 |
|
{ |
67 |
|
d_currentBag = |
68 |
|
d_nodeManager->mkNode(kind::UNION_DISJOINT, singleton, d_currentBag); |
69 |
|
} |
70 |
|
|
71 |
|
d_currentBag = Rewriter::rewrite(d_currentBag); |
72 |
|
|
73 |
|
Assert(d_currentBag.isConst()); |
74 |
|
|
75 |
|
Trace("bag-type-enum") << "BagEnumerator::operator++ d_currentBag = " |
76 |
|
<< d_currentBag << std::endl; |
77 |
|
return *this; |
78 |
|
} |
79 |
|
|
80 |
|
bool BagEnumerator::isFinished() |
81 |
|
{ |
82 |
|
// bags sequence is infinite and it never ends |
83 |
|
return false; |
84 |
|
} |
85 |
|
|
86 |
|
} // namespace bags |
87 |
|
} // namespace theory |
88 |
29340 |
} // namespace cvc5 |