58#include <lal/graphs/rooted_tree.hpp>
59#include <lal/detail/linarr/D/DMax/utils.hpp>
60#include <lal/detail/linarr/D/Dopt_utils.hpp>
61#include <lal/detail/linarr/D/DMax/Projective_AEF.hpp>
62#include <lal/detail/type_traits/conditional_list.hpp>
105 const uint64_t _size,
106 const std::size_t _sigma
114typedef std::vector<std::vector<sorted_adjacency_list_info>>
129 typedef std::pair<edge, uint64_t>
edge_size;
131 const uint64_t n = t.get_num_nodes();
132 const uint64_t m = n - 1;
147 [](
const edge_size& T) -> std::size_t { return std::get<1>(T); }
153 for (std::size_t idx = 0; idx < S.
size(); ++idx) {
154 const auto& T = S[idx];
156 const auto [u, v] = T.
first;
157 const uint64_t nv = T.second;
158 const uint64_t sigma_u_v = M[u].size();
172 nv + (M[u].size() > 0 ? M[u].back().partial_sum : 0)
175 J[idx] = {{v,u}, n - nv, sigma_u_v};
178 assert(t.has_edge(u,v));
183 for (
node u = 0; u < n; ++u) {
184 assert(M[u].size() == t.get_degree(u));
197 for (
const auto& [e, suv, sigma_v_u] : J) {
198 const auto u = e.first;
200 M[u][ I[u] ].index_of_parent_within_childs_list = sigma_v_u;
236template <return_type_all_maxs res_type>
244 std::pair<std::vector<uint64_t>, uint64_t>,
245 std::vector<uint64_t>,
251 constexpr bool calculate_max_root =
255 const uint64_t n = t.get_num_nodes();
258 std::vector<uint64_t> DMax_per_vertex(n, 0);
261 DMax_per_vertex[0] = 0;
263 return {std::move(DMax_per_vertex), 0};
266 return DMax_per_vertex;
273 DMax_per_vertex[0] = 1;
274 DMax_per_vertex[1] = 1;
276 return {std::move(DMax_per_vertex), 0};
279 return DMax_per_vertex;
289 const node starting_vertex = 0;
291 assert(starting_vertex < n);
302 uint64_t max_DMax = DMax_per_vertex[starting_vertex];
307 visited[starting_vertex] = 1;
309 Q.push(starting_vertex);
311 while (not Q.empty()) {
312 const node u = Q.front();
315 const auto& Mu = M[u];
316 for (
const auto& [v, s_u_v, sigma_u_v, sigma_v_u, partial_sum_ui] : Mu) {
317 if (visited[v] == 1) {
continue; }
319 const uint64_t s_v_u = n - s_u_v;
320 const uint64_t partial_sum_vi = M[v][sigma_v_u].partial_sum;
324 + (partial_sum_vi + (t.get_degree(v) - (sigma_v_u + 1))*s_v_u)
325 - (partial_sum_ui + (t.get_degree(u) - (sigma_u_v + 1))*s_u_v)
331 if constexpr (calculate_max_root) {
332 if (max_DMax < DMax_per_vertex[v]) {
333 max_DMax = DMax_per_vertex[v];
341 return {std::move(DMax_per_vertex),
max_root};
344 return DMax_per_vertex;
365template <
bool make_arrangement>
366[[nodiscard]] std::conditional_t<
368 std::pair<uint64_t, linear_arrangement>,
373 const uint64_t n = t.get_num_nodes();
377 if constexpr (not make_arrangement) {
379 return (n*(n - 1))/2;
384 if constexpr (make_arrangement) {
392 if constexpr (make_arrangement) {
Free tree graph class.
Definition free_tree.hpp:60
Rooted tree graph class.
Definition rooted_tree.hpp:109
void calculate_size_subtrees() noexcept
Calculates the number of nodes at every rooted subtree.
void identity() noexcept
Makes this arrangement an identity arrangement.
Definition linear_arrangement.hpp:507
std::vector< std::vector< sorted_adjacency_list_info > > sorted_adjacency_list
Useful shorthand for a sorted adjacency list.
Definition Planar_AEF.hpp:115
return_type_all_maxs
All return types as enumeration values.
Definition Planar_AEF.hpp:212
@ DMax_value_vertex
Return only the max projective values for every vertex of the tree.
@ DMax_value_vertex_and_max_root
@ max_root
Return only a vertex that maximizes the maximum projective.
std::conditional_t< make_arrangement, std::pair< uint64_t, linear_arrangement >, uint64_t > AEF(const graphs::free_tree &t) noexcept
Maximum planar arrangement of a free tree.
Definition Planar_AEF.hpp:371
conditional_list_t< bool_sequence< res_type==return_type_all_maxs::DMax_value_vertex_and_max_root, res_type==return_type_all_maxs::DMax_value_vertex, res_type==return_type_all_maxs::max_root >, type_sequence< std::pair< std::vector< uint64_t >, uint64_t >, std::vector< uint64_t >, uint64_t > > all_max_sum_lengths_values(const graphs::free_tree &t) noexcept
Maximum planar arrangement of a free tree.
Definition Planar_AEF.hpp:249
sorted_adjacency_list make_sorted_adjacency_list(const graphs::free_tree &t) noexcept
Construct the for every vertex in the tree. .
Definition Planar_AEF.hpp:126
std::conditional_t< make_arrangement, std::pair< uint64_t, linear_arrangement >, uint64_t > AEF(const graphs::rooted_tree &t) noexcept
Maximum projective arrangement of a rooted tree.
Definition Projective_AEF.hpp:86
@ non_increasing
Non-increasing sort.
void counting_sort(const value_iterator_t begin, const value_iterator_t end, const std::size_t largest_key_plus_1, const Callable &key, countingsort::memory< value_t > &mem) noexcept
Counting sort algorithm with reusable memory.
Definition counting_sort.hpp:152
uint64_t calculate_bidirectional_sizes(const tree_t &t, const uint64_t n, const node u, const node v, iterator_t &it) noexcept
Calculates the values for the edges reachable from in the subtree .
Definition size_subtrees.hpp:168
typename conditional_list< bool_seq, type_seq >::type conditional_list_t
Shorthand for conditional_list.
Definition conditional_list.hpp:78
@ caterpillar
Caterpillar trees.
Main namespace of the library.
Definition basic_types.hpp:48
std::pair< node, node > edge
See Edge page for further details.
Definition basic_types.hpp:56
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51
A tuple used to construct the sorted adjacency list.
Definition Planar_AEF.hpp:92
uint64_t size
Directional size (u,v)
Definition Planar_AEF.hpp:96
std::size_t sigma
Index of 'v' within list of 'u'.
Definition Planar_AEF.hpp:98
edge e
Edge (u,v)
Definition Planar_AEF.hpp:94
edge_size_sigma() noexcept
Constructor.
Definition Planar_AEF.hpp:101
edge_size_sigma(const edge _e, const uint64_t _size, const std::size_t _sigma) noexcept
Constructor.
Definition Planar_AEF.hpp:103
A piece of information within u's list.
Definition Planar_AEF.hpp:70
uint64_t size
The number of nodes in the tree T^parent_child.
Definition Planar_AEF.hpp:76
uint64_t index_of_parent_within_childs_list
Definition Planar_AEF.hpp:85
uint64_t index_of_child_within_parents_list
Definition Planar_AEF.hpp:81
node child
Definition Planar_AEF.hpp:73
uint64_t partial_sum
The sum of this size plus all the sizes before it.
Definition Planar_AEF.hpp:88
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59
T & first() noexcept
Non-constant reference to the first element in the array.
Definition array.hpp:243
T * begin() noexcept
Non-constant raw pointer to first element.
Definition array.hpp:300
T * end() noexcept
Non-constant raw pointer to last+1 element.
Definition array.hpp:302
std::size_t size() const noexcept
Size of the array.
Definition array.hpp:215
A sequence of Boolean values.
Definition bool_sequence.hpp:52
Struct used in many algorithms to sort edges according to some integer value.
Definition pairs_utils.hpp:65
A sequence of types.
Definition type_sequence.hpp:51