Adiar 2.1.0
An External Memory Decision Diagram Library
Loading...
Searching...
No Matches
zdd.h
1#ifndef ADIAR_ZDD_ZDD_H
2#define ADIAR_ZDD_ZDD_H
3
4#include <string_view>
5
6#include <adiar/internal/cut.h>
7#include <adiar/internal/dd.h>
8
9namespace adiar
10{
11 // Class declarations to be able to reference it
12 class zdd;
13
23 class __zdd : public internal::__dd
24 {
25 public:
30
35
40
44 __zdd(const zdd& zdd);
45
46 // NOTE:
47 // '__dd' class includes 'max_1level_cut' and 'max_2level_cut' operations. This does not take
48 // the potential extra 'false' arc into account.
49 //
50 // For now, we do not care to add this, since we are not using `__zdd` in a context where it
51 // is necessary such as 'zdd_union'.
52
56 explicit
57 operator bool() &&;
58 };
59
67 class zdd : public internal::dd
68 {
70 // Friends
71 // |- classes
72 friend __zdd;
73
74 // |- functions
75 friend size_t
77 friend label_type
79
80 friend bool
81 zdd_subseteq(const exec_policy& ep, const zdd&, const zdd&);
82 friend bool
83 zdd_disjoint(const exec_policy& ep, const zdd&, const zdd&);
84
85 public:
90 static constexpr std::string_view false_print = "Ø";
91
95 static constexpr std::string_view true_print = "{Ø}";
97
99 // Constructors
100 public:
107
115
120 zdd(const shared_node_file_type& A, bool negate = false, signed_label_type shift = 0);
122
127 zdd(const zdd& oA);
128
133
145
147 // Accessors overwrite
148 public:
156 internal::cut::size_type
157 max_1level_cut(const internal::cut ct) const
158 {
159 return add_false_cofactor(ct, this->_file->max_1level_cut);
160 }
161
168 internal::cut::size_type
169 max_2level_cut(const internal::cut ct) const
170 {
171 return add_false_cofactor(ct, this->_file->max_2level_cut);
172 }
173
175
176 private:
181 internal::cut::size_type
182 add_false_cofactor(const internal::cut ct, const internal::cuts_t& ilevel_cuts) const
183 {
184 const internal::safe_size_t cut_size = ilevel_cuts[ct];
185
186 // Bit-mask (allowing implicit conversion to size_t with bit-operators) to get the cut-type
187 // WITHOUT the false arcs.
188 constexpr size_t bit_mask = internal::cut::Internal_True;
189 const internal::cut ct_excl_false = static_cast<internal::cut>(ct & bit_mask);
190
191 // In product construction algorithms we need to take into account the (single) suppressed
192 // false arc, which may suddenly become visible (e.g. 'zdd_union'). Here, the DAG gets stuck
193 // inside of a copy of only one of the input ZDDs. To get there, one followed an arc of the
194 // input but afterwards one pairs with an invisible false arc that spans all levels.
195 //
196 // We do not need to account for this invisible false arc in the following two cases
197 //
198 // - If the requested cut does not include false arcs.
199 //
200 // - If the cut size is strictly larger than the corresponding cut excluding false. In this
201 // case, we already have a false arc to pair with.
202 const size_t add_suppressed = !ct.includes(false) && cut_size == ilevel_cuts[ct_excl_false];
203
204 return internal::to_size(cut_size + add_suppressed);
205 }
206
208
210 // Operator overloading for use in conditionals
211 public:
215 explicit
216 operator bool() const;
217
219 // Assignment operator overloadings
220 public:
224 zdd&
226
231 zdd&
233
237 zdd&
239
241 zdd&
244
248 zdd&
250
252 zdd&
255
259 zdd&
261
263 zdd&
266
270 zdd&
272
274 zdd&
277
281 zdd&
283
285 zdd&
288 };
289}
290
291#endif // ADIAR_ZDD_ZDD_H
A (possibly unreduced) Zero-suppressed Decision Diagram.
Definition zdd.h:24
__zdd()
Default constructor with an empty result.
__zdd(const zdd &zdd)
Conversion constructor from a bdd to pass along a prior value.
__zdd(const shared_arc_file_type &f, const exec_policy &ep)
Wrapper for an algorithm's unreduced output.
__zdd(const shared_node_file_type &f)
Wrapper for an algorithm's already reduced output.
Settings to dictate the execution of Adiar's algorithms.
Definition exec_policy.h:35
Definition dd.h:45
shared_levelized_file< arc_type > shared_arc_file_type
Type of the file object arc-based representation of a diagram.
Definition dd.h:95
shared_levelized_file< node_type > shared_node_file_type
Type of the file object node-based representation of a diagram.
Definition dd.h:55
Container for the files that represent a Decision Diagram.
Definition dd.h:280
level_type label_type
Type of variable labels.
Definition dd.h:312
signed_level_type signed_label_type
Type for difference between variable labels.
Definition dd.h:317
shared_file_ptr< node_file_type > shared_node_file_type
File type for the shared file object representing the diagram.
Definition dd.h:347
signed_label_type shift() const
Read-only access to the number of levels to shift.
Definition dd.h:445
shared_node_file_type _file
The file describing the actual DAG of the decision diagram.
Definition dd.h:355
typename node_type::terminal_type terminal_type
Type of a terminal value.
Definition dd.h:337
Reduced Ordered Zero-suppressed Decision Diagram.
Definition zdd.h:68
friend size_t zdd_nodecount(const zdd &)
The number of (internal) nodes used to represent the family of sets.
zdd & operator=(const zdd &other)
Assigns new zdd.
zdd & operator&=(const zdd &other)
zdd(terminal_type t)
Implicit conversion from a terminal value to respectively construct Ø and {Ø} from respectively 0 and...
zdd & operator-=(const zdd &other)
friend label_type zdd_varcount(const zdd &)
The number of variables that exist in the family of sets, i.e. the number of levels present in the ZD...
zdd & operator=(__zdd &&other)
Assigns new zdd to a variable; the content is derefenced before the given __zdd is reduced into a zdd...
zdd & operator*=(const zdd &other)
zdd(__zdd &&A)
Implicit move conversion from a possibly to-be reduced result from an algorithm to a zdd.
zdd(zdd &&A)
Move construction, taking over ownership of the files underneath.
zdd & operator+=(const zdd &other)
zdd(const zdd &oA)
Copy construction, incrementing thre reference count on the file underneath.
zdd & operator|=(const zdd &other)
zdd()
Default construction, creating the empty set Ø.
consumer< ValueType > make_consumer(OutputIt &&iter)
Wrap an iterator into a consumer function.
Definition functional.h:71
Core types.
Definition adiar.h:40