LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
lal::generate::_tree_generator< tree_t, > Class Template Referenceabstract

Base class for tree generators. More...

#include <tree_generator.hpp>

Public Member Functions

 _tree_generator () noexcept=default
 Default constructor.
 
 _tree_generator (const uint64_t n) noexcept
 Constructor with number of nodes.
 
 _tree_generator (const _tree_generator &Gen) noexcept=default
 Default copy constructor.
 
 _tree_generator (_tree_generator &&Gen) noexcept=default
 Default move constructor.
 
virtual ~_tree_generator () noexcept=default
 Default destructor.
 
void init (const uint64_t n) noexcept
 Initializes the tree generator.
 
void clear () noexcept
 Clears the memory used by the generator.
 
_tree_generatoroperator= (const _tree_generator &Gen)=default
 Default copy assignment operator.
 
_tree_generatoroperator= (_tree_generator &&Gen)=default
 Default move assignment operator.
 
tree_t get_tree () noexcept
 Retrieve the generated tree.
 
virtual tree_t yield_tree () noexcept=0
 Yields a tree, advancing the generator if necessary.
 
void activate_all_postprocessing_actions () noexcept
 Activates all postprocessing actions.
 
void deactivate_all_postprocessing_actions () noexcept
 Deactivates all postprocessing actions.
 
void set_normalize_tree (const bool v) noexcept
 Should trees be normalized?
 
void set_calculate_size_subtrees (const bool v) noexcept
 Should the size of the subtrees be calculated?
 
void set_calculate_tree_type (const bool v) noexcept
 Should the tree be classified into types?
 

Protected Member Functions

virtual tree_t __get_tree () noexcept=0
 Retrieve the generated tree.
 

Protected Attributes

uint64_t m_n = 0
 Number of vertices.
 
bool m_normalize_tree = true
 Normalize the generated tree.
 
bool m_calculate_size_subtrees = true
 Calculate the size of the subtrees of the generated rooted tree.
 
bool m_calculate_tree_type = true
 Calculate the type of tree of the generated tree.
 

Static Private Attributes

static constexpr bool is_free = std::is_base_of_v<graphs::free_tree, tree_t>
 Helpful Boolean value to compact 'if constexpr' expressions.
 

Detailed Description

template<class tree_t, std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
class lal::generate::_tree_generator< tree_t, >

Base class for tree generators.

This class is simply a helper for postprocessing a generated tree. The postprocessing actions applied to the tree depends on whether said tree is a rooted tree or a free tree.

The list of methods that govern postprocessing actions are:

Users can deactivate all postprocessing actions with deactivate_all_postprocessing_actions and activate all of them with activate_all_postprocessing_actions.

There are two types of classes inheriting from this base class. The exhaustive classes, and the random classes. The former provide an exhaustive enumeration of a given type of trees ( \(\{\text{labeled}/\text{unlabeled}\} \times \{\text{rooted}/\text{free}\}\)); the latter generate a given type of tree (the aforementioned four combinations), uniformly at random.

The names of the classes inheriting from this follow one very simple pattern. This is explained in the documentation of the lal::generate namespace (or, if you are a Python user, lal.generate module).

The exhaustive classes have three different usages:

lal::generate::all_2_3_trees Gen(10);
while (not Gen.end()) {
const auto T = Gen.get_tree();
// ...
Gen.next();
}
for (lal::generate::all_2_3_trees Gen(10); not Gen.end(); Gen.next()) {
const auto T = Gen.get_tree();
// ...
}
lal::generate::all_2_3_trees Gen(10);
while (not Gen.end()) {
const auto T = Gen.yield_tree();
// ...
}

Random classes are a bit simpler to use, with, basically, two different usages:

lal::generate::rand_2_3_trees Gen(10);
for (int i = 0; i < N; ++i) {
const auto T = Gen.get_tree();
// ...
}
lal::generate::rand_2_3_trees Gen(10);
for (int i = 0; i < N; ++i) {
const auto T = Gen.yield_tree();
// ...
}
Template Parameters
tree_tType of tree.

Constructor & Destructor Documentation

◆ _tree_generator() [1/3]

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
lal::generate::_tree_generator< tree_t, >::_tree_generator ( const uint64_t n)
inlinenoexcept

Constructor with number of nodes.

Parameters
nNumber of nodes

◆ _tree_generator() [2/3]

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
lal::generate::_tree_generator< tree_t, >::_tree_generator ( const _tree_generator< tree_t, > & Gen)
defaultnoexcept

Default copy constructor.

Parameters
GenGenerator of the same type.

◆ _tree_generator() [3/3]

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
lal::generate::_tree_generator< tree_t, >::_tree_generator ( _tree_generator< tree_t, > && Gen)
defaultnoexcept

Default move constructor.

Parameters
GenGenerator of the same type.

Member Function Documentation

◆ __get_tree()

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
virtual tree_t lal::generate::_tree_generator< tree_t, >::__get_tree ( )
nodiscardprotectedpure virtualnoexcept

◆ activate_all_postprocessing_actions()

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
void lal::generate::_tree_generator< tree_t, >::activate_all_postprocessing_actions ( )
inlinenoexcept

Activates all postprocessing actions.

The full list of postprocessing actions can be found in the documentation of this class.

◆ deactivate_all_postprocessing_actions()

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
void lal::generate::_tree_generator< tree_t, >::deactivate_all_postprocessing_actions ( )
inlinenoexcept

Deactivates all postprocessing actions.

The full list of postprocessing actions can be found in the documentation of this class.

◆ get_tree()

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
tree_t lal::generate::_tree_generator< tree_t, >::get_tree ( )
inlinenodiscardnoexcept

Retrieve the generated tree.

This function first calls __get_tree and then modifies the generated tree according to the values:

Returns
A free/rooted tree depending on the type of the class inheriting from this. The type of generation of tree differs from one type of class to another.

◆ operator=() [1/2]

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
_tree_generator & lal::generate::_tree_generator< tree_t, >::operator= ( _tree_generator< tree_t, > && Gen)
default

Default move assignment operator.

Parameters
GenGenerator of the same type.

◆ operator=() [2/2]

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
_tree_generator & lal::generate::_tree_generator< tree_t, >::operator= ( const _tree_generator< tree_t, > & Gen)
default

Default copy assignment operator.

Parameters
GenGenerator of the same type.

◆ set_calculate_size_subtrees()

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
void lal::generate::_tree_generator< tree_t, >::set_calculate_size_subtrees ( const bool v)
inlinenoexcept

Should the size of the subtrees be calculated?

Parameters
vBoolean value.

◆ set_calculate_tree_type()

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
void lal::generate::_tree_generator< tree_t, >::set_calculate_tree_type ( const bool v)
inlinenoexcept

Should the tree be classified into types?

See lal::graphs::tree_type for details on the classification.

Parameters
vBoolean value.

◆ set_normalize_tree()

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
void lal::generate::_tree_generator< tree_t, >::set_normalize_tree ( const bool v)
inlinenoexcept

Should trees be normalized?

Parameters
vBoolean value.

◆ yield_tree()

template<class tree_t , std::enable_if_t< std::is_base_of_v< graphs::tree, tree_t >, bool > = true>
virtual tree_t lal::generate::_tree_generator< tree_t, >::yield_tree ( )
nodiscardpure virtualnoexcept

Yields a tree, advancing the generator if necessary.

In case the class that inherits from this one is exhaustive then this function also moves the generator forward with its appropriate method. If the class is random, then it just calls get_tree().

Returns
A free/rooted tree depending on the type of the class inheriting from this. The type of generation of tree differs from one type of class to another.
Postcondition
The generator advances to the next tree.

Implemented in lal::generate::all_lab_free_trees, lal::generate::all_lab_rooted_trees, lal::generate::all_ulab_free_bistar_trees, lal::generate::all_ulab_free_trees, lal::generate::all_ulab_rooted_trees, lal::generate::rand_lab_free_trees, lal::generate::rand_lab_rooted_trees, lal::generate::rand_ulab_free_trees, and lal::generate::rand_ulab_rooted_trees.


The documentation for this class was generated from the following file: