Adiar  2.1.0
An External Memory Decision Diagram Library
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 
9 namespace adiar
10 {
11  // Class declarations to be able to reference it
12  class zdd;
13 
23  class __zdd : public internal::__dd
24  {
25  public:
29  __zdd();
30 
35 
39  __zdd(const shared_arc_file_type& f, const exec_policy& ep);
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  };
53 
61  class zdd : public internal::dd
62  {
64  // Friends
65  // |- classes
66  friend __zdd;
67 
68  // |- functions
69  friend size_t
70  zdd_nodecount(const zdd&);
71  friend label_type
72  zdd_varcount(const zdd&);
73 
74  friend bool
75  zdd_subseteq(const exec_policy& ep, const zdd&, const zdd&);
76  friend bool
77  zdd_disjoint(const exec_policy& ep, const zdd&, const zdd&);
78 
79  public:
84  static constexpr std::string_view false_print = "Ø";
85 
89  static constexpr std::string_view true_print = "{Ø}";
91 
93  // Constructors
94  public:
100  zdd();
101 
109 
114  zdd(const shared_node_file_type& A, bool negate = false, signed_label_type shift = 0);
116 
121  zdd(const zdd& oA);
122 
126  zdd(zdd&& A);
127 
138  zdd(__zdd&& A);
139 
141  // Accessors overwrite
142  public:
150  internal::cut::size_type
151  max_1level_cut(const internal::cut ct) const
152  {
153  return add_false_cofactor(ct, this->_file->max_1level_cut);
154  }
155 
162  internal::cut::size_type
163  max_2level_cut(const internal::cut ct) const
164  {
165  return add_false_cofactor(ct, this->_file->max_2level_cut);
166  }
167 
169 
170  private:
175  internal::cut::size_type
176  add_false_cofactor(const internal::cut ct, const internal::cuts_t& ilevel_cuts) const
177  {
178  const internal::safe_size_t cut_size = ilevel_cuts[ct];
179 
180  // Bit-mask (allowing implicit conversion to size_t with bit-operators) to get the cut-type
181  // WITHOUT the false arcs.
182  constexpr size_t bit_mask = internal::cut::Internal_True;
183  const internal::cut ct_excl_false = static_cast<internal::cut>(ct & bit_mask);
184 
185  // In product construction algorithms we need to take into account the (single) suppressed
186  // false arc, which may suddenly become visible (e.g. 'zdd_union'). Here, the DAG gets stuck
187  // inside of a copy of only one of the input ZDDs. To get there, one followed an arc of the
188  // input but afterwards one pairs with an invisible false arc that spans all levels.
189  //
190  // We do not need to account for this invisible false arc in the following two cases
191  //
192  // - If the requested cut does not include false arcs.
193  //
194  // - If the cut size is strictly larger than the corresponding cut excluding false. In this
195  // case, we already have a false arc to pair with.
196  const size_t add_suppressed = !ct.includes(false) && cut_size == ilevel_cuts[ct_excl_false];
197 
198  return internal::to_size(cut_size + add_suppressed);
199  }
200 
202 
204  // Assignment operator overloadings
205  public:
209  zdd&
210  operator=(const zdd& other);
211 
216  zdd&
217  operator=(__zdd&& other);
218 
222  zdd&
223  operator&=(const zdd& other);
224 
226  zdd&
227  operator&=(zdd&& other);
229 
233  zdd&
234  operator*=(const zdd& other);
235 
237  zdd&
238  operator*=(zdd&& other);
240 
244  zdd&
245  operator|=(const zdd& other);
246 
248  zdd&
249  operator|=(zdd&& other);
251 
255  zdd&
256  operator+=(const zdd& other);
257 
259  zdd&
260  operator+=(zdd&& other);
262 
266  zdd&
267  operator-=(const zdd& other);
268 
270  zdd&
271  operator-=(zdd&& other);
273  };
274 }
275 
276 #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:80
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:265
shared_file_ptr< node_file_type > shared_node_file_type
File type for the shared file object representing the diagram.
Definition: dd.h:317
node_type::signed_label_type signed_label_type
Type for difference between variable labels.
Definition: dd.h:287
node_type::label_type label_type
Type of this node's variable label.
Definition: dd.h:282
signed_label_type shift() const
Read-only access to the number of levels to shift.
Definition: dd.h:415
shared_node_file_type _file
The file describing the actual DAG of the decision diagram.
Definition: dd.h:325
typename node_type::terminal_type terminal_type
Type of a terminal value.
Definition: dd.h:307
Reduced Ordered Zero-suppressed Decision Diagram.
Definition: zdd.h:62
zdd & operator*=(const zdd &other)
zdd & operator+=(const zdd &other)
friend size_t zdd_nodecount(const zdd &)
The number of (internal) nodes used to represent the family of sets.
zdd(terminal_type t)
Implicit conversion from a terminal value to respectively construct Ø and {Ø} from respectively 0 and...
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 in the ZDD.
friend bool zdd_disjoint(const exec_policy &ep, const zdd &, const zdd &)
Whether the two families are disjoint.
zdd(__zdd &&A)
Implicit move conversion from a possibly to-be reduced result from an algorithm to a zdd.
zdd & operator&=(const zdd &other)
zdd(zdd &&A)
Move construction, taking over ownership of the files underneath.
zdd & operator=(__zdd &&other)
Assigns new zdd to a variable; the content is derefenced before the given __zdd is reduced into a zdd...
zdd(const zdd &oA)
Copy construction, incrementing thre reference count on the file underneath.
zdd & operator=(const zdd &other)
Assigns new zdd.
zdd & operator-=(const zdd &other)
zdd()
Default construction, creating the empty set Ø.
zdd & operator|=(const zdd &other)
Core types.
Definition: adiar.h:40