LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
Projective_AEF.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 - 2024
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 (lluis.alemany.puig@upc.edu)
28 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
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 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
41 * CQL (Complexity and Quantitative Linguistics Lab)
42 * Office 220, 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#pragma once
49
50// C++ includes
51#if defined DEBUG
52#include <cassert>
53#endif
54#include <type_traits>
55#include <vector>
56
57// lal includes
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
62namespace lal {
63namespace detail {
64namespace DMax {
65namespace projective {
66
80template <bool make_arrangement>
81[[nodiscard]] std::conditional_t<
82 make_arrangement,
83 std::pair<uint64_t, linear_arrangement>,
84 uint64_t
85>
86AEF(const graphs::rooted_tree& t) noexcept
87{
88#if defined DEBUG
89 assert(t.is_rooted_tree());
90#endif
91
92 const uint64_t n = t.get_num_nodes();
93 if (n == 1) {
94 if constexpr (make_arrangement) {
95 return {0, linear_arrangement::identity(1)};
96 }
97 else {
98 return 0;
99 }
100 }
101
102 std::vector<std::vector<node_size>> L(n);
105 (t, L);
106
107 // construct the optimal projective arrangement
108
109 linear_arrangement arr(make_arrangement ? n : 0);
110 const uint64_t D =
112 (n, L, t.get_root(), arr);
113
114 if constexpr (make_arrangement) {
115 return {D, std::move(arr)};
116 }
117 else {
118 return D;
119 }
120}
121
122} // -- namespace projective
123} // -- namespace DMax
124} // -- namespace detail
125} // -- namespace lal
Rooted tree graph class.
Definition rooted_tree.hpp:109
Linear arrangement of vertices.
Definition linear_arrangement.hpp:103
void identity() noexcept
Makes this arrangement an identity arrangement.
Definition linear_arrangement.hpp:507
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
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:200
void make_sorted_adjacency_list_rooted(const graphs::rooted_tree &t, std::vector< std::vector< node_size > > &L) noexcept
Make a sorted, rooted adjacency list sorted according to the sizes of the subtrees of the input roote...
Definition Dopt_utils.hpp:125
@ non_increasing
Non-increasing sort.
Main namespace of the library.
Definition basic_types.hpp:48