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 operator bool() &&;
57 };
58
66 class zdd : public internal::dd
67 {
69 // Friends
70 // |- classes
71 friend __zdd;
72
73 // |- functions
74 friend size_t
76 friend label_type
78
79 friend bool
80 zdd_subseteq(const exec_policy& ep, const zdd&, const zdd&);
81 friend bool
82 zdd_disjoint(const exec_policy& ep, const zdd&, const zdd&);
83
84 public:
89 static constexpr std::string_view false_print = "Ø";
90
94 static constexpr std::string_view true_print = "{Ø}";
96
98 // Constructors
99 public:
106
114
119 zdd(const shared_node_file_type& A, bool negate = false, signed_label_type shift = 0);
121
126 zdd(const zdd& oA);
127
132
144
146 // Accessors overwrite
147 public:
155 internal::cut::size_type
156 max_1level_cut(const internal::cut ct) const
157 {
158 return add_false_cofactor(ct, this->_file->max_1level_cut);
159 }
160
167 internal::cut::size_type
168 max_2level_cut(const internal::cut ct) const
169 {
170 return add_false_cofactor(ct, this->_file->max_2level_cut);
171 }
172
174
175 private:
180 internal::cut::size_type
181 add_false_cofactor(const internal::cut ct, const internal::cuts_t& ilevel_cuts) const
182 {
183 const internal::safe_size_t cut_size = ilevel_cuts[ct];
184
185 // Bit-mask (allowing implicit conversion to size_t with bit-operators) to get the cut-type
186 // WITHOUT the false arcs.
187 constexpr size_t bit_mask = internal::cut::Internal_True;
188 const internal::cut ct_excl_false = static_cast<internal::cut>(ct & bit_mask);
189
190 // In product construction algorithms we need to take into account the (single) suppressed
191 // false arc, which may suddenly become visible (e.g. 'zdd_union'). Here, the DAG gets stuck
192 // inside of a copy of only one of the input ZDDs. To get there, one followed an arc of the
193 // input but afterwards one pairs with an invisible false arc that spans all levels.
194 //
195 // We do not need to account for this invisible false arc in the following two cases
196 //
197 // - If the requested cut does not include false arcs.
198 //
199 // - If the cut size is strictly larger than the corresponding cut excluding false. In this
200 // case, we already have a false arc to pair with.
201 const size_t add_suppressed = !ct.includes(false) && cut_size == ilevel_cuts[ct_excl_false];
202
203 return internal::to_size(cut_size + add_suppressed);
204 }
205
207
209 // Operator overloading for use in conditionals
210 public:
211
215 explicit operator bool() const;
216
218 // Assignment operator overloadings
219 public:
223 zdd&
225
230 zdd&
232
236 zdd&
238
240 zdd&
243
247 zdd&
249
251 zdd&
254
258 zdd&
260
262 zdd&
265
269 zdd&
271
273 zdd&
276
280 zdd&
282
284 zdd&
287 };
288}
289
290#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:85
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:270
shared_file_ptr< node_file_type > shared_node_file_type
File type for the shared file object representing the diagram.
Definition dd.h:327
node_type::signed_label_type signed_label_type
Type for difference between variable labels.
Definition dd.h:297
node_type::label_type label_type
Type of this node's variable label.
Definition dd.h:292
signed_label_type shift() const
Read-only access to the number of levels to shift.
Definition dd.h:425
shared_node_file_type _file
The file describing the actual DAG of the decision diagram.
Definition dd.h:335
typename node_type::terminal_type terminal_type
Type of a terminal value.
Definition dd.h:317
Reduced Ordered Zero-suppressed Decision Diagram.
Definition zdd.h:67
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 bool zdd_subseteq(const exec_policy &ep, const zdd &, const zdd &)
Whether one family is a subset or equal to the 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...
friend bool zdd_disjoint(const exec_policy &ep, const zdd &, const zdd &)
Whether the two families are disjoint.
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