1 #ifndef ADIAR_INTERNAL_DD_H
2 #define ADIAR_INTERNAL_DD_H
6 #include <adiar/exec_policy.h>
8 #include <adiar/internal/cut.h>
9 #include <adiar/internal/data_types/arc.h>
10 #include <adiar/internal/data_types/node.h>
11 #include <adiar/internal/io/arc_file.h>
12 #include <adiar/internal/io/node_file.h>
14 namespace adiar::internal
28 using no_file = std::monostate;
86 std::variant<no_file, shared_node_file_type, shared_arc_file_type>
_union;
139 template <
typename file_t>
143 return std::holds_alternative<file_t>(
_union);
151 template <
typename file_t>
155 return std::get<file_t>(
_union);
166 return has<no_file>();
178 if (has<shared_arc_file_type>()) {
180 return get<shared_arc_file_type>()->size() / 2u;
182 if (has<shared_node_file_type>()) {
return get<shared_node_file_type>()->size(); }
195 if (has<shared_arc_file_type>()) {
197 return af->max_1level_cut + (ct.includes(
false) ? af->number_of_terminals[
false] : 0u)
198 + (ct.includes(
true) ? af->number_of_terminals[
true] : 0u);
200 if (has<shared_node_file_type>()) {
return get<shared_node_file_type>()->max_1level_cut[ct]; }
213 if (has<shared_arc_file_type>()) {
216 (3 * af->max_1level_cut) / 2 + (ct.includes(
false) ? af->number_of_terminals[
false] : 0u)
217 + (ct.includes(
true) ? af->number_of_terminals[
true] : 0u),
219 (af->size() / 2u) + 1);
221 if (has<shared_node_file_type>()) {
return get<shared_node_file_type>()->max_2level_cut[ct]; }
231 if (has<shared_arc_file_type>()) {
232 return get<shared_arc_file_type>()->number_of_terminals[this->_negate ^ value];
234 if (has<shared_node_file_type>()) {
235 return get<shared_node_file_type>()->number_of_terminals[this->_negate ^ value];
246 if (has<shared_arc_file_type>()) {
248 return af->number_of_terminals[
false] + af->number_of_terminals[
true];
250 if (has<shared_node_file_type>()) {
252 return nf->number_of_terminals[
false] + nf->number_of_terminals[
true];
399 return this->_file.get();
428 max_1level_cut(
const cut ct)
const
430 return this->_file->max_1level_cut[negate_cut_type(ct)];
440 max_2level_cut(
const cut ct)
const
442 return this->_file->max_2level_cut[negate_cut_type(ct)];
453 return this->_file->size();
462 return this->_file->width;
471 return this->_file->number_of_terminals[this->_negate ^ value];
489 negate_cut_type(
const cut ct)
const
491 if (!this->_negate) {
return ct; }
494 case cut::Internal_False:
return cut::Internal_True;
495 case cut::Internal_True:
return cut::Internal_False;
507 , _negate(
dd._negate)
512 template <
typename DD,
typename __DD>
526 using __dd_type = __DD;
531 using node_type =
typename dd_type::node_type;
536 using pointer_type =
typename dd_type::pointer_type;
541 using children_type =
typename node_type::children_type;
546 using label_type =
typename dd_type::label_type;
551 using signed_label_type =
typename dd_type::label_type;
556 static constexpr label_type max_label = dd_type::max_label;
561 using id_type =
typename dd_type::id_type;
566 static constexpr id_type max_id = dd_type::max_id;
571 using terminal_type =
typename dd_type::terminal_type;
576 using shared_node_file_type =
typename __dd_type::shared_node_file_type;
581 using shared_arc_file_type =
typename __dd_type::shared_arc_file_type;
591 static inline pointer_type
592 reduction_rule(
const node_type& n);
600 static inline children_type
601 reduction_rule_inv(
const pointer_type& child);
Settings to dictate the execution of Adiar's algorithms.
Definition: exec_policy.h:35
exec_policy _policy
Copy of the execution policy given to the top-down algorithm.
Definition: dd.h:101
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
node_type::signed_label_type signed_label_type
Type for difference between variable labels.
Definition: dd.h:70
__dd()=default
Default construction to nothing.
arc arc_type
Type of nodes of this diagram.
Definition: dd.h:75
__dd(const shared_arc_file_type &f, const exec_policy &ep)
Conversion for algorithms returning to-be reduced arcs.
Definition: dd.h:121
const file_t & get() const
Get the content of a certain type.
Definition: dd.h:153
std::variant< no_file, shared_node_file_type, shared_arc_file_type > _union
Union of levelized node or arc files to reflect the possible return types of a function and a 'no_fil...
Definition: dd.h:86
bool has() const
Whether the union currently holds a certain file type.
Definition: dd.h:141
__dd(const shared_node_file_type &f)
Conversion for algorithms returning already-reduced nodes.
Definition: dd.h:114
cut::size_type max_2level_cut(const cut ct) const
Obtain the 2-level cut of the desired type, i.e. of the sub-graph including the desired type of arcs.
Definition: dd.h:211
size_t number_of_terminals() const
Number of terminals.
Definition: dd.h:244
bool _negate
Propagation of the dd.negate flag.
Definition: dd.h:91
node node_type
Type of nodes of this diagram.
Definition: dd.h:50
node_type::pointer_type pointer_type
Type of pointers of this diagram.
Definition: dd.h:60
size_t size() const
Number of nodes.
Definition: dd.h:176
cut::size_type max_1level_cut(const cut ct) const
Obtain the 1-level cut of the desired type, i.e. of the sub-graph including the desired type of arcs.
Definition: dd.h:193
bool empty() const
Whether it currently holds no content.
Definition: dd.h:164
node_type::label_type label_type
Type of this node's variable label.
Definition: dd.h:65
signed_label_type _shift
Propagation of the dd.negate flag.
Definition: dd.h:96
size_t number_of_terminals(const bool value) const
Number of terminals of a certain value.
Definition: dd.h:229
Container for the files that represent a Decision Diagram.
Definition: dd.h:265
static constexpr id_type max_id
The maximal possible value for this nodes level identifier.
Definition: dd.h:302
const node_file_type * operator->() const
Read-only access to the members of the raw files and meta information, i.e. this is similar to writin...
Definition: dd.h:397
levelized_file< node_type > node_file_type
File type for the file object representing the diagram.
Definition: dd.h:312
bool _negate
Whether to negate the leaves when reading nodes from the file.
Definition: dd.h:343
bool is_negated() const
Read-only access to the negation flag.
Definition: dd.h:406
signed_label_type _shift
Number of levels to shift by.
Definition: dd.h:348
const shared_node_file_type file_ptr() const
Read-only access to the raw files and meta information.
Definition: dd.h:387
dd(const shared_node_file_type &f, bool negate=false, signed_label_type shift=0)
Constructor to wrap the node-based result of an algorithm.
Definition: dd.h:356
shared_file_ptr< node_file_type > shared_node_file_type
File type for the shared file object representing the diagram.
Definition: dd.h:317
static constexpr label_type max_label
The maximal possible value for a unique identifier's label.
Definition: dd.h:292
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
node_type::pointer_type pointer_type
Type of pointers of this diagram.
Definition: dd.h:277
void deref()
Release the claim on the underlying file, thereby decreasing its reference counter....
Definition: dd.h:333
signed_label_type shift() const
Read-only access to the number of levels to shift.
Definition: dd.h:415
dd(dd &&dd)=default
Move construction, taking over ownership of the files underneath.
shared_node_file_type _file
The file describing the actual DAG of the decision diagram.
Definition: dd.h:325
size_t number_of_terminals(const bool value) const
Number of terminals of a certain value.
Definition: dd.h:469
typename node_type::terminal_type terminal_type
Type of a terminal value.
Definition: dd.h:307
node_type::id_type id_type
Type of this node's level identifier.
Definition: dd.h:297
size_t size() const
The number of elements in the node file.
Definition: dd.h:451
dd(const dd &dd)=default
Copy construction, incrementing the reference count on the file underneath.
size_t width() const
The number of nodes on the widest level.
Definition: dd.h:460
node node_type
Type of nodes of this diagram.
Definition: dd.h:272
size_t number_of_terminals() const
Number of terminals.
Definition: dd.h:478