TeDDy 4.1.0
Decision diagram library.
|
Base class for all diagram managers that generically implements all of the algorithms. More...
#include <diagram_manager.hpp>
Public Types | |
using | diagram_t = diagram< Data, Degree > |
Alias for the diagram type used in the functions of this manager. | |
Public Member Functions | |
auto | constant (int32 val) -> diagram_t |
Creates diagram representing constant function. | |
auto | variable (int32 index) -> diagram_t |
Creates diagram representing function of single variable. | |
template<class Foo = void> requires (is_bdd<Degree>) | |
auto | variable_not (int32 index) -> utils::second_t< Foo, diagram_t > |
Creates BDD representing function of complemented variable. | |
auto | operator() (int32 index) -> diagram_t |
Creates diagram representing function of single variable. | |
template<std::convertible_to< int32 > T> | |
auto | variables (std::initializer_list< T > indices) -> std::vector< diagram_t > |
Creates vector of diagrams representing single variables. | |
template<std::input_iterator I, std::sentinel_for< I > S> | |
auto | variables (I first, S last) -> std::vector< diagram_t > |
Creates vector of diagrams representing functions of single variables. | |
template<std::ranges::input_range Is> | |
auto | variables (Is const &indices) -> std::vector< diagram_t > |
Creates vector of diagrams representing single variables. | |
template<std::input_iterator I, std::sentinel_for< I > S> | |
auto | from_vector (I first, S last) -> diagram_t |
Creates diagram from a truth vector of a function. | |
template<std::ranges::input_range R> | |
auto | from_vector (R &&vector) -> diagram_t |
Creates diagram from a truth vector of a function. | |
auto | to_vector (diagram_t const &diagram) const -> std::vector< int32 > |
Creates truth vector from the diagram. | |
template<std::output_iterator< teddy::int32 > O> | |
auto | to_vector_g (diagram_t const &diagram, O out) const -> void |
Creates truth vector from the diagram. | |
template<class Foo = void> requires (is_bdd<Degree>) | |
auto | from_pla (pla_file const &file, fold_type foldType=fold_type::Tree) -> utils::second_t< Foo, std::vector< diagram_t > > |
Creates BDDs defined by PLA file. | |
template<expression_node Node> | |
auto | from_expression_tree (Node const &root) -> diagram_t |
Creates diagram from an expression tree (AST). | |
template<teddy_bin_op Op> | |
auto | apply (diagram_t const &lhs, diagram_t const &rhs) -> diagram_t |
Merges two diagrams using given binary operation. | |
template<teddy_bin_op Op, class... Diagram> | |
auto | apply_n (Diagram const &... diagrams) -> diagram_t |
TODO. | |
template<teddy_bin_op Op, std::ranges::input_range R> | |
auto | left_fold (R const &diagrams) -> diagram_t |
Merges diagams in the range using the apply function and binary operation. | |
template<teddy_bin_op Op, std::input_iterator I, std::sentinel_for< I > S> | |
auto | left_fold (I first, S last) -> diagram_t |
Merges diagams in the range using the apply function and binary operation. | |
template<teddy_bin_op Op, std::ranges::random_access_range R> | |
auto | tree_fold (R &diagrams) -> diagram_t |
Merges diagams in the range using the apply function and binary operation. | |
template<teddy_bin_op Op, std::random_access_iterator I, std::sentinel_for< I > S> | |
auto | tree_fold (I first, S last) -> diagram_t |
Merges diagams in the range using the apply function and binary operation. | |
template<in_var_values Vars> | |
auto | evaluate (diagram_t const &diagram, Vars const &values) const -> int32 |
Evaluates value of the function represented by the diagram. | |
auto | satisfy_count (int32 value, diagram_t const &diagram) -> int64 |
Calculates number of variable assignments for which the functions evaluates to certain value. | |
template<out_var_values Vars> | |
auto | satisfy_one (int32 value, diagram_t const &diagram) -> std::optional< Vars > |
Finds variable assignment for which diagram evaluates to value . | |
template<out_var_values Vars> | |
auto | satisfy_all (int32 value, diagram_t const &diagram) const -> std::vector< Vars > |
Enumerates all elements of the satisfying set. | |
template<out_var_values Vars, std::output_iterator< Vars > O> | |
auto | satisfy_all_g (int32 value, diagram_t const &diagram, O out) const -> void |
Enumerates all elements of the satisfying set. | |
auto | get_cofactor (diagram_t const &diagram, int32 varIndex, int32 varValue) -> diagram_t |
Calculates cofactor of the functions. | |
auto | get_cofactor (diagram_t const &diagram, std::vector< var_cofactor > const &vars) -> diagram_t |
template<int_to_int F> | |
auto | transform (diagram_t const &diagram, F transformer) -> diagram_t |
Transforms values of the function. | |
template<class Foo = void> requires (is_bdd<Degree>) | |
auto | negate (diagram_t const &diagram) -> utils::second_t< Foo, diagram_t > |
Negates Boolean function. | |
auto | get_dependency_set (diagram_t const &diagram) const -> std::vector< int32 > |
Enumerates indices of variables that the function depends on. | |
template<std::output_iterator< int32 > O> | |
auto | get_dependency_set_g (diagram_t const &diagram, O out) const -> void |
Enumerates indices of variables that the function depends on. | |
auto | reduce (diagram_t const &diagram) -> diagram_t |
Reduces diagrams to its canonical form. | |
auto | get_node_count () const -> int64 |
Returns number of nodes that are currently used by the manager. | |
auto | get_node_count (diagram_t const &diagram) const -> int64 |
Returns number of nodes in the diagram including terminal nodes. | |
auto | to_dot_graph (std::ostream &out) const -> void |
Prints dot representation of the graph. | |
auto | to_dot_graph (std::ostream &out, diagram_t const &diagram) const -> void |
Prints dot representation of the diagram. | |
auto | force_gc () -> void |
Runs garbage collection. | |
auto | force_reorder () -> void |
Runs variable reordering heuristic. | |
auto | clear_cache () -> void |
Clears apply cache. | |
auto | get_var_count () const -> int32 |
Returns number of variables for this manager set in the constructor. | |
auto | get_order () const -> std::vector< int32 > const & |
Returns current order of variables. | |
auto | get_domains () const -> std::vector< int32 > |
Return domains of variables. | |
auto | set_cache_ratio (double ratio) -> void |
Sets the relative cache size w.r.t the number of nodes. | |
auto | set_gc_ratio (double ratio) -> void |
Sets ratio used to determine new node pool allocation. | |
auto | set_auto_reorder (bool doReorder) -> void |
Enables or disables automatic variable reordering. | |
diagram_manager (diagram_manager &&) noexcept=default | |
auto | operator= (diagram_manager &&) noexcept -> diagram_manager &=default |
diagram_manager (diagram_manager const &)=delete | |
auto | operator= (diagram_manager const &) -> diagram_manager &=delete |
template<out_var_values Vars, std::output_iterator< Vars > OutputIt> | |
auto | satisfy_all_g (int32 const value, diagram_t const &diagram, OutputIt out) const -> void |
Protected Types | |
using | node_t = typename diagram< Data, Degree >::node_t |
using | son_container = typename node_t::son_container |
Protected Member Functions | |
diagram_manager (int32 varCount, int64 nodePoolSize, int64 extraNodePoolSize, std::vector< int32 > order) | |
Initializes diagram manager. | |
diagram_manager (int32 varCount, int64 nodePoolSize, int64 extraNodePoolSize, domains::mixed domain, std::vector< int32 > order) | |
Initializes diagram manager. | |
Protected Attributes | |
node_manager< Data, Degree, Domain > | nodes_ |
Base class for all diagram managers that generically implements all of the algorithms.
|
protected |
Initializes diagram manager.
This overload is for managers that have fixed domains (known at copile time).
varCount | Number of variables. |
nodePoolSize | Number of nodes that is pre-allocated. |
extraNodePoolSize | Size of the additional node pools. |
order | Order of variables. |
|
protected |
Initializes diagram manager.
This overload is for managers that have mixed domains specified by the ds
paramter.
varCount | Number of variables. |
nodePoolSize | Number of nodes that is pre-allocated. |
extraNodePoolSize | Size of the additional node pools. |
ds | Domains of varibales. |
order | Order of variables. |
auto teddy::diagram_manager< Data, Degree, Domain >::constant | ( | int32 | val | ) | -> diagram_t |
Creates diagram representing constant function.
val | Value of the constant function |
auto teddy::diagram_manager< Data, Degree, Domain >::variable | ( | int32 | index | ) | -> diagram_t |
Creates diagram representing function of single variable.
index | Index of the variable |
auto teddy::diagram_manager< Data, Degree, Domain >::variable_not | ( | int32 | index | ) | -> utils::second_t<Foo, diagram_t> |
Creates BDD representing function of complemented variable.
index | Index of the variable |
auto teddy::diagram_manager< Data, Degree, Domain >::operator() | ( | int32 | index | ) | -> diagram_t |
Creates diagram representing function of single variable.
i | Index of the variable |
auto teddy::diagram_manager< Data, Degree, Domain >::variables | ( | std::initializer_list< T > | indices | ) | -> std::vector<diagram_t> |
Creates vector of diagrams representing single variables.
T | integral type convertible to unsgined int |
indices | initializer list of indices |
auto teddy::diagram_manager< Data, Degree, Domain >::variables | ( | I | first, |
S | last | ||
) | -> std::vector<diagram_t> |
Creates vector of diagrams representing functions of single variables.
I | iterator type for the input range. |
S | sentinel type for I . (end iterator) |
first | iterator to the first element of range of indices represented by integral type convertible to unsgined int. |
last | sentinel for first (end iterator). |
auto teddy::diagram_manager< Data, Degree, Domain >::variables | ( | Is const & | indices | ) | -> std::vector<diagram_t> |
Creates vector of diagrams representing single variables.
Is | range of integral indices |
indices | range of Ts (e.g. std::vector<int>) |
auto teddy::diagram_manager< Data, Degree, Domain >::from_vector | ( | I | first, |
S | last | ||
) | -> diagram_t |
Creates diagram from a truth vector of a function.
Example for the function f(x) = max(x0, x1, x2):
I | Iterator type for the input range. |
S | Sentinel type for I (end iterator) |
first | iterator to the first element of the truth vector |
last | sentinel for first (end iterator) |
auto teddy::diagram_manager< Data, Degree, Domain >::from_vector | ( | R && | vector | ) | -> diagram_t |
Creates diagram from a truth vector of a function.
See the other overload for details.
R | Type of the range that contains the truth vector |
vector | Range representing the truth vector Elements of the range must be convertible to int |
auto teddy::diagram_manager< Data, Degree, Domain >::to_vector | ( | diagram_t const & | diagram | ) | const -> std::vector<int32> |
Creates truth vector from the diagram.
Significance of variables is the same as in the from_vector
function i.e., variable on the last level of the diagram is least significant. The following assertion holds:
diagram | Diagram |
auto teddy::diagram_manager< Data, Degree, Domain >::to_vector_g | ( | diagram_t const & | diagram, |
O | out | ||
) | const -> void |
Creates truth vector from the diagram.
O | Output iterator type |
diagram | Diagram |
out | Output iterator that is used to output the truth vector |
auto teddy::diagram_manager< Data, Degree, Domain >::from_pla | ( | pla_file const & | file, |
fold_type | foldType = fold_type::Tree |
||
) | -> utils::second_t<Foo, std::vector<diagram_t>> |
Creates BDDs defined by PLA file.
Foo | Dummy template to enable SFINE. |
file | PLA file loaded in the instance of pla_file class. |
foldType | fold type used in diagram creation. |
auto teddy::diagram_manager< Data, Degree, Domain >::from_expression_tree | ( | Node const & | root | ) | -> diagram_t |
Creates diagram from an expression tree (AST).
Node | Node type of the tree. Must provide API given by the concept. Required API might change in the future. |
root | Root of the expression tree. |
auto teddy::diagram_manager< Data, Degree, Domain >::apply | ( | diagram_t const & | lhs, |
diagram_t const & | rhs | ||
) | -> diagram_t |
Merges two diagrams using given binary operation.
Binary operations are defined in the namespace teddy::ops
. All availabe operations are listed in the following table:
Op | Binary operation |
lhs | first diagram |
rhs | second diagram |
lhs
and rhs
auto teddy::diagram_manager< Data, Degree, Domain >::left_fold | ( | R const & | diagrams | ) | -> diagram_t |
Merges diagams in the range using the apply
function and binary operation.
Uses left fold order of evaluation (sequentially from the left).
Op | Binary operation |
R | Range containing diagrams (e.g. std::vector<diagram_t>) |
diagrams | Input range of diagrams to be merged |
auto teddy::diagram_manager< Data, Degree, Domain >::left_fold | ( | I | first, |
S | last | ||
) | -> diagram_t |
Merges diagams in the range using the apply
function and binary operation.
Uses left fold order of evaluation (sequentially from the left).
Op | Binary operation |
I | Range iterator type |
S | Sentinel type for I (end iterator) |
first | Input iterator to the first diagram |
last | Sentinel for first (end iterator) |
auto teddy::diagram_manager< Data, Degree, Domain >::tree_fold | ( | R & | diagrams | ) | -> diagram_t |
Merges diagams in the range using the apply
function and binary operation.
Uses tree fold order of evaluation ((d1 op d2) op (d3 op d4) ...) . Tree fold uses the input range range
to store some intermediate results. range
is left in valid but unspecified state.
Op | Binary operation |
R | Range containing diagrams (e.g. std::vector<diagram_t>) |
diagrams | Random access range of diagrams to be merged (e.g. std::vector) |
auto teddy::diagram_manager< Data, Degree, Domain >::tree_fold | ( | I | first, |
S | last | ||
) | -> diagram_t |
Merges diagams in the range using the apply
function and binary operation.
Uses tree fold order of evaluation ((d1 op d2) op (d3 op d4) ...) . Tree fold uses the input range range
to store some intermediate results. range
is left in valid but unspecified state.
Op | Binary operation |
I | Range iterator type |
S | Sentinel type for I (end iterator) |
first | Random access iterator to the first diagram |
last | Sentinel for first (end iterator) |
auto teddy::diagram_manager< Data, Degree, Domain >::evaluate | ( | diagram_t const & | diagram, |
Vars const & | values | ||
) | const -> int32 |
Evaluates value of the function represented by the diagram.
Complexity is O(n)
where n
is the number of variables.
Vars | Container type that defines operator[] and returns value convertible to int |
diagram | Diagram |
values | Container holding values of variables |
d
for variable values given in vs
auto teddy::diagram_manager< Data, Degree, Domain >::satisfy_count | ( | int32 | value, |
diagram_t const & | diagram | ||
) | -> int64 |
Calculates number of variable assignments for which the functions evaluates to certain value.
Complexity is O
(|d|) where |d|
is the number of nodes.
value | Value of the function |
diagram | Diagram representing the function |
d
evaluates to val
auto teddy::diagram_manager< Data, Degree, Domain >::satisfy_one | ( | int32 | value, |
diagram_t const & | diagram | ||
) | -> std::optional<Vars> |
Finds variable assignment for which diagram evaluates to value
.
Complexity is O
(|n|) where |n|
is the number of nodes.
value | Value of the function |
diagram | Diagram representing the function |
auto teddy::diagram_manager< Data, Degree, Domain >::satisfy_all | ( | int32 | value, |
diagram_t const & | diagram | ||
) | const -> std::vector<Vars> |
Enumerates all elements of the satisfying set.
Enumerates all elements of the satisfying set of the function i.e. variable assignments for which the function evaluates to certain value.
Complexity is O
(n*|Sf|) where |Sf|
is the size of the satisfying set and n
is the number of variables. Please note that this is quite high for bigger functions and the computation will probably not finish in reasonable time.
Vars | Container type that defines operator [] and allows assigning integers, std::vector is also allowed |
value | Value of the function |
diagram | Diagram representing the function |
Vars
auto teddy::diagram_manager< Data, Degree, Domain >::satisfy_all_g | ( | int32 | value, |
diagram_t const & | diagram, | ||
O | out | ||
) | const -> void |
Enumerates all elements of the satisfying set.
Enumerates all elements of the satisfying set of the function i.e. variable assignments for which the function evaluates to certain value.
Complexity is O
(n*|Sf|) where |Sf|
is the size of the satisfying set and n
is the number of variables. Please note that this is quite high for bigger functions and the computation will probably not finish in reasonable time.
Vars | Container type that defines operator [] and allows assigning integers. std::vector is also allowed. |
O | Output iterator type. |
value | Value of the function |
diagram | Diagram representing the function |
out | Output iterator that is used to output instances of Vars . |
auto teddy::diagram_manager< Data, Degree, Domain >::get_cofactor | ( | diagram_t const & | diagram, |
int32 | varIndex, | ||
int32 | varValue | ||
) | -> diagram_t |
Calculates cofactor of the functions.
Calculates cofactor of the function i.e. fixes value of the i
th variable to the value val
.
diagram | Diagram representing the function |
varIndex | Index of the variable to be fixed |
varValue | Value to which the i th varibale should be fixed |
auto teddy::diagram_manager< Data, Degree, Domain >::transform | ( | diagram_t const & | diagram, |
F | transformer | ||
) | -> diagram_t |
Transforms values of the function.
F | Type of the transformation function |
diagram | Diagram representing the function |
transformer | Transformation function that is applied to values of the function. |
auto teddy::diagram_manager< Data, Degree, Domain >::negate | ( | diagram_t const & | diagram | ) | -> utils::second_t<Foo, diagram_t> |
Negates Boolean function.
diagram | Diagram representing the function |
transformer | Transformation function that is applied to values of the function. |
auto teddy::diagram_manager< Data, Degree, Domain >::get_dependency_set | ( | diagram_t const & | diagram | ) | const -> std::vector<int32> |
Enumerates indices of variables that the function depends on.
diagram | Diagram representing the function |
auto teddy::diagram_manager< Data, Degree, Domain >::get_dependency_set_g | ( | diagram_t const & | diagram, |
O | out | ||
) | const -> void |
Enumerates indices of variables that the function depends on.
O | Output iterator type. |
diagram | Diagram representing the function. |
out | Output iterator that is used to output indices. |
auto teddy::diagram_manager< Data, Degree, Domain >::reduce | ( | diagram_t const & | diagram | ) | -> diagram_t |
Reduces diagrams to its canonical form.
You probably won't need to call this.
diagram | Diagram |
auto teddy::diagram_manager< Data, Degree, Domain >::get_node_count |
Returns number of nodes that are currently used by the manager.
This function returns number of nodes that are currently stored in the unique tables. Total number of allocated nodes might and probably will be higher. See implementation details on github for details.
auto teddy::diagram_manager< Data, Degree, Domain >::get_node_count | ( | diagram_t const & | diagram | ) | const -> int64 |
Returns number of nodes in the diagram including terminal nodes.
diagram | Diagram |
auto teddy::diagram_manager< Data, Degree, Domain >::to_dot_graph | ( | std::ostream & | out | ) | const -> void |
Prints dot representation of the graph.
Prints dot representation of the entire multi rooted graph to the output stream.
out | Output stream (e.g. std::cout or std::ofstream ) |
auto teddy::diagram_manager< Data, Degree, Domain >::to_dot_graph | ( | std::ostream & | out, |
diagram_t const & | diagram | ||
) | const -> void |
Prints dot representation of the diagram.
Prints dot representation of the diagram to the output stream.
out | Output stream (e.g. std::cout or std::ofstream ) |
diagram | Diagram |
auto teddy::diagram_manager< Data, Degree, Domain >::force_gc |
Runs garbage collection.
Forces the garbage collection to run which removes nodes that are not referenced from the unique tables. These nodes, however, are not deallocated. See implementation details on github for details. GC is run automatically so you probably won't need to run this function yourself.
auto teddy::diagram_manager< Data, Degree, Domain >::get_var_count |
Returns number of variables for this manager set in the constructor.
auto teddy::diagram_manager< Data, Degree, Domain >::get_order |
Returns current order of variables.
If no sifting was performed in between call to the constructor and call to this function then the order is the same as specified in the constructor.
auto teddy::diagram_manager< Data, Degree, Domain >::get_domains |
Return domains of variables.
In case of bdd_manager
and mdd_manager
domains of each variable is the same i.e. 2 or P. In case of imdd_manager
and ifmdd_manager
the domains are the same as set in the constructor.
auto teddy::diagram_manager< Data, Degree, Domain >::set_cache_ratio | ( | double | ratio | ) | -> void |
Sets the relative cache size w.r.t the number of nodes.
Size of the cache is calculated as:
ratio | Number from the interval (0,oo) |
auto teddy::diagram_manager< Data, Degree, Domain >::set_gc_ratio | ( | double | ratio | ) | -> void |
Sets ratio used to determine new node pool allocation.
New pool is allocated if:
ratio | Number from the interval [0,1] |
auto teddy::diagram_manager< Data, Degree, Domain >::set_auto_reorder | ( | bool | doReorder | ) | -> void |
Enables or disables automatic variable reordering.
Note that when automatic reordering is enabled the manager can't guarantee that all diagrams will remain canonical. To ensure that a diagram d
is canonical (e.g. to compare two functions), you need to call reduce
on them.
doReorder | Specifies whether to disable (false) or enable (true) automatic reordering |