LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
dependency_flux.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 * Ramon Ferrer i Cancho (rferrericancho@cs.upc.edu)
34 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office S124, Omega building
37 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
38 * Webpage: https://cqllab.upc.edu/people/rferrericancho/
39 *
40 ********************************************************************/
41
42#pragma once
43
44// lal includes
45#include <lal/linear_arrangement.hpp>
46#include <lal/numeric/rational.hpp>
47#include <lal/graphs/rooted_tree.hpp>
48#include <lal/graphs/free_tree.hpp>
49
50namespace lal {
51namespace linarr {
52
59public:
60
61 // GETTERS
62
64 uint64_t get_left_span() const noexcept { return m_left_span;; }
66 uint64_t get_right_span() const noexcept { return m_right_span; }
68 uint64_t get_size() const noexcept
69 { return m_dependencies.size(); }
71 uint64_t get_weight() const noexcept { return m_weight; }
72
74 uint64_t& get_left_span() noexcept { return m_left_span;; }
76 uint64_t& get_right_span() noexcept { return m_right_span; }
78 uint64_t& get_weight() noexcept { return m_weight; }
79
81 std::vector<edge>& get_dependencies() { return m_dependencies; }
82
84 const std::vector<edge>& get_dependencies() const noexcept
85 { return m_dependencies; }
86
103 double get_RL_ratio() const noexcept
104 { return get_RL_ratio_rational().to_double(); }
105
114 { return numeric::rational(m_weight, m_dependencies.size()); }
122 double get_WS_ratio() const noexcept
123 { return get_WS_ratio_rational().to_double(); }
124
125 // SETTERS
126
128 void set_left_span(uint64_t ls) noexcept { m_left_span = ls; }
130 void set_right_span(uint64_t rs) noexcept { m_right_span = rs; }
132 void set_weight(uint64_t w) noexcept { m_weight = w; }
133
135 void set_dependencies(const std::vector<edge>& deps) noexcept
136 { m_dependencies = deps; }
137
139 void set_dependencies(std::vector<edge>&& deps) noexcept
140 { m_dependencies = std::move(deps); }
141
142private:
145 uint64_t m_left_span = 0;
148 uint64_t m_right_span = 0;
154 std::vector<edge> m_dependencies;
161 uint64_t m_weight = 0;
162};
163
174std::vector<dependency_flux>
175compute_flux(const graphs::free_tree& t, const linear_arrangement& pi = {}) noexcept;
176
187inline
188std::vector<dependency_flux> compute_flux
189(const graphs::rooted_tree& t, const linear_arrangement& pi = {}) noexcept
190{
191#if defined DEBUG
192 assert(t.is_rooted_tree());
193#endif
194 return compute_flux(t.to_free_tree(), pi);
195}
196
197
198} // -- namespace linarr
199} // -- namespace lal
Free tree graph class.
Definition: free_tree.hpp:60
Rooted tree graph class.
Definition: rooted_tree.hpp:103
free_tree to_free_tree(bool norm=true, bool check=true) const noexcept
Converts this rooted tree into a free tree (see free_tree).
bool is_rooted_tree() const noexcept
Is this tree a valid rooted tree?
Definition: rooted_tree.hpp:468
Dependency flux.
Definition: dependency_flux.hpp:58
void set_left_span(uint64_t ls) noexcept
Sets the left span.
Definition: dependency_flux.hpp:128
void set_right_span(uint64_t rs) noexcept
Sets the right span.
Definition: dependency_flux.hpp:130
double get_WS_ratio() const noexcept
Returns the W/S ratio.
Definition: dependency_flux.hpp:122
void set_dependencies(const std::vector< edge > &deps) noexcept
Sets the set of dependencies.
Definition: dependency_flux.hpp:135
uint64_t m_right_span
Definition: dependency_flux.hpp:148
void set_dependencies(std::vector< edge > &&deps) noexcept
Sets the set of dependencies.
Definition: dependency_flux.hpp:139
uint64_t & get_left_span() noexcept
Returns a reference to the left span of this flux.
Definition: dependency_flux.hpp:74
numeric::rational get_RL_ratio_rational() const noexcept
Returns the R/L ratio.
Definition: dependency_flux.hpp:94
uint64_t m_left_span
Definition: dependency_flux.hpp:145
double get_RL_ratio() const noexcept
Returns the R/L ratio.
Definition: dependency_flux.hpp:103
void set_weight(uint64_t w) noexcept
Sets the weight.
Definition: dependency_flux.hpp:132
uint64_t get_weight() const noexcept
Returns weight of this flux.
Definition: dependency_flux.hpp:71
std::vector< edge > & get_dependencies()
Returns a reference to the set of dependencies.
Definition: dependency_flux.hpp:81
uint64_t get_left_span() const noexcept
Returns left span of this flux.
Definition: dependency_flux.hpp:64
uint64_t m_weight
Weight of this flux.
Definition: dependency_flux.hpp:161
numeric::rational get_WS_ratio_rational() const noexcept
Returns the W/S ratio.
Definition: dependency_flux.hpp:113
uint64_t get_size() const noexcept
Returns the size of this flux.
Definition: dependency_flux.hpp:68
const std::vector< edge > & get_dependencies() const noexcept
Returns the set of dependencies.
Definition: dependency_flux.hpp:84
uint64_t get_right_span() const noexcept
Returns right span of this flux.
Definition: dependency_flux.hpp:66
std::vector< edge > m_dependencies
Dependencies in this flux.
Definition: dependency_flux.hpp:154
uint64_t & get_weight() noexcept
Returns a reference to the weight of this flux.
Definition: dependency_flux.hpp:78
uint64_t & get_right_span() noexcept
Returns a reference to the right span of this flux.
Definition: dependency_flux.hpp:76
Linear arrangement of vertices.
Definition: linear_arrangement.hpp:103
Exact rational number.
Definition: rational.hpp:63
double to_double() const noexcept
Converts this rational to a double-precision floating-point value.
Definition: rational.hpp:850
std::vector< dependency_flux > compute_flux(const graphs::free_tree &t, const linear_arrangement &pi={}) noexcept
Computes the flux of a dependency tree.
Main namespace of the library.
Definition: basic_types.hpp:50