58#include <lal/graphs/rooted_tree.hpp>
59#include <lal/detail/linarr/DMax_utils.hpp>
60#include <lal/detail/linarr/Dopt_utils.hpp>
61#include <lal/detail/linarr/DMax_Projective_AEF.hpp>
62#include <lal/detail/type_traits/conditional_list.hpp>
109typedef std::vector<std::vector<sorted_adjacency_list_info>>
124 typedef std::pair<edge, uint64_t>
edge_size;
126 const uint64_t n = t.get_num_nodes();
127 const uint64_t m = n - 1;
139 sorting::counting_sort<edge_size, sorting::non_increasing_t>
142 [](
const edge_size& T) -> std::size_t { return std::get<1>(T); }
148 for (std::size_t idx = 0; idx < S.
size(); ++idx) {
149 const auto& T = S[idx];
151 const auto [u, v] = T.
first;
152 const uint64_t nv = T.second;
153 const uint64_t sigma_u_v = M[u].size();
167 nv + (M[u].size() > 0 ? M[u].back().partial_sum : 0)
170 J[idx] = {{v,u}, n - nv, sigma_u_v};
173 assert(t.has_edge(u,v));
178 for (
node u = 0; u < n; ++u) {
179 assert(M[u].size() == t.get_degree(u));
192 for (
const auto& [e, suv, sigma_v_u] : J) {
193 const auto u = e.first;
195 M[u][ I[u] ].index_of_parent_within_childs_list = sigma_v_u;
231template <return_type_all_maxs res_type>
239 std::pair<std::vector<uint64_t>, uint64_t>,
240 std::vector<uint64_t>,
246 constexpr bool calculate_max_root =
250 const uint64_t n = t.get_num_nodes();
253 std::vector<uint64_t> DMax_per_vertex(n, 0);
256 DMax_per_vertex[0] = 0;
258 return {std::move(DMax_per_vertex), 0};
261 return DMax_per_vertex;
268 DMax_per_vertex[0] = 1;
269 DMax_per_vertex[1] = 1;
271 return {std::move(DMax_per_vertex), 0};
274 return DMax_per_vertex;
284 const node starting_vertex = 0;
286 assert(starting_vertex < n);
293 DMax_per_vertex[starting_vertex] = projective::AEF<false>(rt);
297 uint64_t max_DMax = DMax_per_vertex[starting_vertex];
302 visited[starting_vertex] = 1;
304 Q.push(starting_vertex);
306 while (not Q.empty()) {
307 const node u = Q.front();
310 const auto& Mu = M[u];
311 for (
const auto& [v, s_u_v, sigma_u_v, sigma_v_u, partial_sum_ui] : Mu) {
312 if (visited[v] == 1) {
continue; }
314 const uint64_t s_v_u = n - s_u_v;
315 const uint64_t partial_sum_vi = M[v][sigma_v_u].partial_sum;
319 + (partial_sum_vi + (t.get_degree(v) - (sigma_v_u + 1))*s_v_u)
320 - (partial_sum_ui + (t.get_degree(u) - (sigma_u_v + 1))*s_u_v)
326 if constexpr (calculate_max_root) {
327 if (max_DMax < DMax_per_vertex[v]) {
328 max_DMax = DMax_per_vertex[v];
336 return {std::move(DMax_per_vertex),
max_root};
339 return DMax_per_vertex;
360template <
bool make_arrangement>
363 std::pair<uint64_t, linear_arrangement>,
368 const uint64_t n = t.get_num_nodes();
372 if constexpr (not make_arrangement) {
374 return (n*(n - 1))/2;
379 if constexpr (make_arrangement) {
387 if constexpr (make_arrangement) {
396 all_max_sum_lengths_values<return_type_all_maxs::max_root>(t);
401 return projective::AEF<make_arrangement>(rt);
Free tree graph class.
Definition: free_tree.hpp:60
Rooted tree graph class.
Definition: rooted_tree.hpp:103
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:452
std::vector< std::vector< sorted_adjacency_list_info > > sorted_adjacency_list
Useful shorthand for a sorted adjacency list.
Definition: DMax_Planar_AEF.hpp:110
return_type_all_maxs
All return types as enumeration values.
Definition: DMax_Planar_AEF.hpp:207
@ 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: DMax_Planar_AEF.hpp:366
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: DMax_Planar_AEF.hpp:244
sorted_adjacency_list make_sorted_adjacency_list(const graphs::free_tree &t) noexcept
Construct the for every vertex in the tree. .
Definition: DMax_Planar_AEF.hpp:121
void counting_sort(const value_iterator_t begin, const value_iterator_t end, const std::size_t largest_key_plus_1, const std::function< std::size_t(const value_t &)> &key, countingsort::memory< value_t > &mem) noexcept
Counting sort algorithm with reusable memory.
Definition: counting_sort.hpp:155
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:158
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:50
std::pair< node, node > edge
See Edge page for further details.
Definition: basic_types.hpp:58
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53
A tuple used to construct the sorted adjacency list.
Definition: DMax_Planar_AEF.hpp:92
uint64_t size
Directional size (u,v)
Definition: DMax_Planar_AEF.hpp:96
std::size_t sigma
Index of 'v' within list of 'u'.
Definition: DMax_Planar_AEF.hpp:98
edge_size_sigma(edge _e, uint64_t _size, std::size_t _sigma) noexcept
Constructor.
Definition: DMax_Planar_AEF.hpp:103
edge e
Edge (u,v)
Definition: DMax_Planar_AEF.hpp:94
edge_size_sigma() noexcept
Constructor.
Definition: DMax_Planar_AEF.hpp:101
A piece of information within u's list.
Definition: DMax_Planar_AEF.hpp:70
uint64_t size
The number of nodes in the tree T^parent_child.
Definition: DMax_Planar_AEF.hpp:76
uint64_t index_of_parent_within_childs_list
Definition: DMax_Planar_AEF.hpp:85
uint64_t index_of_child_within_parents_list
Definition: DMax_Planar_AEF.hpp:81
node child
Definition: DMax_Planar_AEF.hpp:73
uint64_t partial_sum
The sum of this size plus all the sizes before it.
Definition: DMax_Planar_AEF.hpp:88
A sequence of Boolean values.
Definition: bool_sequence.hpp:52
Wrapper of a C array for autmatic deallocation of memory.
Definition: data_array.hpp:59
T & first() noexcept
Non-constant reference to the first element in the array.
Definition: data_array.hpp:234
std::size_t size() const noexcept
Size of the array.
Definition: data_array.hpp:204
T * end() noexcept
Non-constant raw pointer to last+1 element.
Definition: data_array.hpp:293
T * begin() noexcept
Non-constant raw pointer to first element.
Definition: data_array.hpp:291
Struct used in many algorithms to sort edges according to some integer value.
Definition: pairs_utils.hpp:65
Non-increasing sort.
Definition: sorting_types.hpp:51
A sequence of types.
Definition: type_sequence.hpp:51