LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
Dmin_Planar_HS.hpp
1/*********************************************************************
2 *
3 * Linear Arrangement Library - A library that implements a collection
4 * algorithms for linear arrangments of graphs.
5 *
6 * Copyright (C) 2019 - 2023
7 *
8 * This file is part of Linear Arrangement Library. The full code is available
9 * at:
10 * https://github.com/LAL-project/linear-arrangement-library.git
11 *
12 * Linear Arrangement Library is free software: you can redistribute it
13 * and/or modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * Linear Arrangement Library is distributed in the hope that it will be
18 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public License
23 * along with Linear Arrangement Library. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * Contact:
26 *
27 * LluĂ­s Alemany Puig (lalemany@cs.upc.edu)
28 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
29 * CQL (Complexity and Quantitative Linguistics Lab)
30 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
31 * Webpage: https://cqllab.upc.edu/people/lalemany/
32 *
33 * Juan Luis Esteban (esteban@cs.upc.edu)
34 * LOGPROG: Logics and Programming Research Group
35 * Office 110, Omega building
36 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
37 * Webpage: https://www.cs.upc.edu/~esteban/
38 *
39 * Ramon Ferrer i Cancho (rferrericancho@cs.upc.edu)
40 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
41 * CQL (Complexity and Quantitative Linguistics Lab)
42 * Office S124, Omega building
43 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
44 * Webpage: https://cqllab.upc.edu/people/rferrericancho/
45 *
46 ********************************************************************/
47
48// C++ includes
49#if defined DEBUG
50#include <cassert>
51#endif
52#include <vector>
53
54// lal includes
55#include <lal/graphs/free_tree.hpp>
56#include <lal/detail/linarr/Dmin_utils.hpp>
57#include <lal/detail/linarr/Dopt_utils.hpp>
58#include <lal/detail/pairs_utils.hpp>
59
60namespace lal {
61namespace detail {
62namespace Dmin {
63namespace planar {
64
82template <bool make_arrangement>
83std::conditional_t<
84 make_arrangement,
85 std::pair<uint64_t, linear_arrangement>,
86 uint64_t
87>
88HS(const graphs::free_tree& t) noexcept
89{
90#if defined DEBUG
91 assert(t.is_tree());
92#endif
93
94 const uint64_t n = t.get_num_nodes();
95 if (n == 1) {
96 if constexpr (make_arrangement) {
97 return {0, linear_arrangement::identity(1)};
98 }
99 else {
100 return 0;
101 }
102 }
103
104 // Make the sorted adjacency list rooted at the centroid of the tree.
105 // This adjacency list is sorted non-increasingly by size of the subtrees.
106 // LARGEST to SMALLEST
107
108 std::vector<std::vector<node_size>> L;
109 const node c = centroidal_vertex_plus_adjacency_list(t, 0, L).first;
110
111 // construct the optimal planar arrangement by calculating the optimal
112 // projective arrangement
113
114 if constexpr (make_arrangement) {
115 linear_arrangement arr(n);
116 const uint64_t D = Dmin_utils::embed<true>(L, c, arr);
117 return {D, std::move(arr)};
118 }
119 else {
121 const uint64_t D = Dmin_utils::embed<false>(L, c, arr);
122 return D;
123 }
124}
125
126} // -- namespace planar
127} // -- namespace Dmin
128} // -- namespace detail
129} // -- namespace lal
Free tree graph class.
Definition: free_tree.hpp:60
Linear arrangement of vertices.
Definition: linear_arrangement.hpp:103
void identity() noexcept
Makes this arrangement an identity arrangement.
Definition: linear_arrangement.hpp:452
std::conditional_t< make_arrangement, std::pair< uint64_t, linear_arrangement >, uint64_t > HS(const graphs::free_tree &t) noexcept
Minimum planar arrangement of a free tree.
Definition: Dmin_Planar_HS.hpp:88
std::pair< node, node > centroidal_vertex_plus_adjacency_list(const tree_t &t, node x, std::vector< std::vector< node_size > > &L) noexcept
Calculates the centroid and the corresponding rooted adjacency list.
Definition: tree_centroid.hpp:343
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53