58#include <lal/linear_arrangement.hpp>
59#include <lal/graphs/rooted_tree.hpp>
60#include <lal/detail/array.hpp>
61#include <lal/iterators/E_iterator.hpp>
62#include <lal/detail/graphs/size_subtrees.hpp>
63#include <lal/detail/sorting/counting_sort.hpp>
64#include <lal/detail/properties/tree_centroid.hpp>
65#include <lal/detail/macros/basic_convert.hpp>
66#include <lal/detail/linarr/D/Dopt_utils.hpp>
109template <
bool make_arrangement>
112 const std::vector<std::vector<node_size>>& L,
126 const auto& children_size_of_r = L[r];
137 uint64_t acc_size_left = 0;
139 uint64_t acc_size_right = 0;
142 uint64_t n_intervals_left = 0;
144 uint64_t n_intervals_right = 0;
154 std::optional<uint64_t> previous_size;
160 for (
const auto& [vi, ni] : children_size_of_r) {
165 assert(*previous_size >= ni);
167 previous_size = {ni};
186 n_intervals_left += roots_side;
190 acc_size_left += roots_side*ni;
194 if constexpr (make_arrangement) {
195 ini += roots_side*ni;
204 if constexpr (make_arrangement) {
208 if constexpr (make_arrangement) {
234template <
bool make_arrangement>
238 const std::vector<std::vector<node_size>>& L,
273template <
bool make_arrangement>
276 const std::vector<std::vector<node_size>>& L,
284 const auto& Cv = L[v];
285 uint64_t cost_branch = 0;
289 uint64_t under_anchor = 0;
293 for (std::size_t i = 1; i < Cv.size(); i += 2) {
294 under_anchor += Cv[i].size;
297 if constexpr (make_arrangement) {
298 base += dir*(
to_int64(under_anchor) + 1);
301 cost_branch += under_anchor;
306 uint64_t i = Cv.size();
309 for (
auto it = Cv.rbegin(); it != Cv.rend(); ++it, --i) {
311 assert(i <= Cv.size());
314 const auto& [vi, ni] = *it;
337 if constexpr (make_arrangement) {
358template <
bool make_arrangement>
361 const std::vector<std::vector<node_size>>& L,
367 const uint64_t n = L.size();
371 uint64_t left_sum = 0;
372 uint64_t right_sum = 0;
374 uint64_t i = L[r].size();
377 for (
auto it = L[r].rbegin(); it != L[r].rend(); ++it, --i) {
378 const auto& [vi, ni] = *it;
380 assert(i <= L[r].size());
405 if constexpr (make_arrangement) {
406 arr.assign(r, left_sum + 1 - 1);
408 for (
node v = 0; v < n; ++v) {
Linear arrangement of vertices.
Definition linear_arrangement.hpp:103
uint64_t arrange_projective(const uint64_t n, const std::vector< std::vector< node_size > > &L, const node r, linear_arrangement &arr) noexcept
Wrapper method for the recursive method arrange.
Definition utils.hpp:236
uint64_t arrange(const std::vector< std::vector< node_size > > &L, const node r, const Dopt_utils::place r_place, position ini, position fin, linear_arrangement &arr) noexcept
Make a minimum projective arrangement using the sorted, rooted adjacency list L.
Definition utils.hpp:111
uint64_t embed_branch(const std::vector< std::vector< node_size > > &L, const node v, int64_t base, const int64_t dir, array< int64_t > &rel_pos) noexcept
Embed a tree's branch.
Definition utils.hpp:275
uint64_t embed(const std::vector< std::vector< node_size > > &L, const node r, linear_arrangement &arr) noexcept
Embed a tree's branch.
Definition utils.hpp:360
unsigned char side
Useful typedef to denote relative position.
Definition Dopt_utils.hpp:74
static constexpr side other_side(side s) noexcept
Other side of a vertex. If s is RIGHT_SIDE, returns LEFT_SIDE.
Definition Dopt_utils.hpp:91
static constexpr place PLACE_RIGHT_OF
A vertex is to be placed to the right of a vertex.
Definition Dopt_utils.hpp:79
static constexpr side LEFT_SIDE
Left side of a vertex.
Definition Dopt_utils.hpp:86
static constexpr side RIGHT_SIDE
Right side of a vertex.
Definition Dopt_utils.hpp:84
static constexpr bool is_even(uint64_t i) noexcept
Is an integer number even?
Definition Dopt_utils.hpp:94
static constexpr place PLACE_LEFT_OF
A vertex is to be placed to the left of a vertex.
Definition Dopt_utils.hpp:77
static constexpr place PLACE_NONE_OF
There is no vertex to use as reference to determine the side.
Definition Dopt_utils.hpp:81
unsigned char place
Useful typedef to denote relative position.
Definition Dopt_utils.hpp:72
constexpr int64_t to_int64(const T &t) noexcept
Conversion to int64_t.
Definition basic_convert.hpp:57
constexpr uint64_t to_uint64(const T &t) noexcept
Conversion to uint64_t.
Definition basic_convert.hpp:52
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t position
Node's position type.
Definition basic_types.hpp:53
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59
Typesafe node type.
Definition basic_types.hpp:70