LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
D_rla.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 * Ramon Ferrer i Cancho (rferrericancho@cs.upc.edu)
34 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office 220, 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// C++ includes
45#if defined DEBUG
46#include <cassert>
47#endif
48
49// lal includes
50#include <lal/numeric/rational.hpp>
51#include <lal/graphs/undirected_graph.hpp>
52#include <lal/graphs/free_tree.hpp>
53#include <lal/graphs/rooted_tree.hpp>
54
55namespace lal {
56namespace properties {
57
58// D: sum of length of edges
59
60/* ---------------------------- */
61/* EXPECTATION OF D: E_rla[D] */
62/* (unconstrained arrangements) */
63
76noexcept
77{
78 return numeric::rational((g.get_num_nodes() + 1)*g.get_num_edges(), 3);
79}
80
89[[nodiscard]] inline double exp_sum_edge_lengths(const graphs::undirected_graph& g)
90noexcept
91{
93}
94
106(const graphs::free_tree& t)
107noexcept
108{
109#if defined DEBUG
110 assert(t.is_tree());
111#endif
112 const uint64_t n = t.get_num_nodes();
113 return numeric::rational(n*n - 1, 3);
114}
115
124[[nodiscard]] inline double exp_sum_edge_lengths(const graphs::free_tree& t) noexcept
125{
126#if defined DEBUG
127 assert(t.is_tree());
128#endif
130}
131
143(const graphs::rooted_tree& t)
144noexcept
145{
146#if defined DEBUG
147 assert(t.is_rooted_tree());
148#endif
149 const uint64_t n = t.get_num_nodes();
150 return numeric::rational(n*n - 1, 3);
151}
152
161[[nodiscard]] inline double exp_sum_edge_lengths(const graphs::rooted_tree& t)
162noexcept
163{
164#if defined DEBUG
165 assert(t.is_rooted_tree());
166#endif
168}
169
170/* ---------------------------- */
171/* EXPECTATION OF D: E_rla[D] */
172/* (bipartite arrangements) */
173
188noexcept
189{
190 return numeric::rational(g.get_num_nodes()*g.get_num_edges(), 2);
191}
192
205[[nodiscard]] inline double exp_sum_edge_lengths_bipartite
207noexcept
208{
210}
211
212/* ------------------------- */
213/* EXPECTATION OF D: E_pr[D] */
214/* (projective arrangements) */
215
229(const graphs::rooted_tree& rt)
230noexcept;
231
242[[nodiscard]] inline double exp_sum_edge_lengths_projective(const graphs::rooted_tree& rt)
243noexcept
244{
246}
247
248
249/* ------------------------- */
250/* EXPECTATION OF D: E_pl[D] */
251/* (planar arrangements) */
252
266(const graphs::free_tree& t)
267noexcept;
283(const graphs::rooted_tree& rt)
284noexcept
285{
286 return exp_sum_edge_lengths_planar_rational(rt.to_undirected());
287}
288
299[[nodiscard]] inline double exp_sum_edge_lengths_planar
300(const graphs::free_tree& t)
301noexcept
302{
304}
315[[nodiscard]] inline double exp_sum_edge_lengths_planar
316(const graphs::rooted_tree& rt)
317noexcept
318{
320}
321
322
323/* ---------------------------- */
324/* VARIANCE OF D: V_rla[D] */
325/* (unconstrained arrangements) */
326
339noexcept;
348[[nodiscard]] inline double var_sum_edge_lengths
350noexcept
351{
353}
354
355} // -- namespace properties
356} // -- namespace lal
Free tree graph class.
Definition free_tree.hpp:60
Rooted tree graph class.
Definition rooted_tree.hpp:109
Undirected graph class.
Definition undirected_graph.hpp:66
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:853
numeric::rational exp_sum_edge_lengths_bipartite_rational(const graphs::undirected_graph &g) noexcept
Expected sum of edge lengths of a bipartite graph in bipartite arrangments, .
Definition D_rla.hpp:187
numeric::rational var_sum_edge_lengths_rational(const graphs::undirected_graph &g) noexcept
Computes the variance of the sum of the length of edges of a graph, .
numeric::rational exp_sum_edge_lengths_rational(const graphs::undirected_graph &g) noexcept
Expected sum of edge lengths of an undirected graph in unconstrained arrangments, .
Definition D_rla.hpp:75
double exp_sum_edge_lengths(const graphs::undirected_graph &g) noexcept
Expected sum of edge lengths of an undirected graph in unconstrained arrangments, .
Definition D_rla.hpp:89
numeric::rational exp_sum_edge_lengths_projective_rational(const graphs::rooted_tree &rt) noexcept
Expected sum of edge lengths of a tree constrained to projective arrangments, .
double exp_sum_edge_lengths_planar(const graphs::free_tree &t) noexcept
Expected sum of edge lengths of a tree constrained to planar arrangments, .
Definition D_rla.hpp:300
double exp_sum_edge_lengths_bipartite(const graphs::undirected_graph &g) noexcept
Expected sum of edge lengths of a bipartite graph in bipartite arrangments, .
Definition D_rla.hpp:206
double var_sum_edge_lengths(const graphs::undirected_graph &g) noexcept
Computes the variance of the sum of the length of edges of a graph, .
Definition D_rla.hpp:349
double exp_sum_edge_lengths_projective(const graphs::rooted_tree &rt) noexcept
Expected sum of edge lengths of a tree constrained to projective arrangments, .
Definition D_rla.hpp:242
numeric::rational exp_sum_edge_lengths_planar_rational(const graphs::free_tree &t) noexcept
Expected sum of edge lengths of a tree constrained to planar arrangments, .
Main namespace of the library.
Definition basic_types.hpp:48