LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
formal_constraints.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/iterators/E_iterator.hpp>
46#include <lal/detail/identity_arrangement.hpp>
47#include <lal/graphs/rooted_tree.hpp>
48
49namespace lal {
50namespace detail {
51
68template <detail::linarr_type arr_type>
70 const graphs::rooted_tree& rt,
72)
73noexcept
74{
75#if defined DEBUG
76 assert(rt.is_rooted_tree());
77#endif
78
79 // case where the linear arrangement is not given
80 if (arr.m_arr.size() == 0) {
81 const node r = rt.get_root();
82 iterators::E_iterator e_it(rt);
83 while (not e_it.end()) {
84 const auto [s,t] = e_it.yield_edge();
85 const bool r_covered_st = s < r and r < t;
86 const bool r_covered_ts = t < r and r < s;
87 if (r_covered_st or r_covered_ts) { return true; }
88 }
89 return false;
90 }
91
92 // the linear arrangement is given
93 const position pr = arr[node_t{rt.get_root()}];
94
95 iterators::E_iterator e_it(rt);
96 while (not e_it.end()) {
97 const auto [s,t] = e_it.yield_edge_t();
98 const position ps = arr[s];
99 const position pt = arr[t];
100
101 const bool r_covered_st = ps < pr and pr < pt;
102 const bool r_covered_ts = pt < pr and pr < ps;
103 if (r_covered_st or r_covered_ts) { return true; }
104 }
105 return false;
106}
107
129template <detail::linarr_type arr_type>
131 const graphs::rooted_tree& rt,
133)
134noexcept
135{
136#if defined DEBUG
137 assert(rt.is_rooted_tree());
138#endif
139
140 // check for planarity
141 // this function already checks that an arrangement must be valid
142 if (not is_planar(rt, arr)) { return false; }
143 return not is_root_covered(rt, arr);
144}
145
146} // -- namespace detail
147} // -- namespace lal
Rooted tree graph class.
Definition: rooted_tree.hpp:103
Iterator over the set of edges of a graph.
Definition: E_iterator.hpp:97
edge_t yield_edge_t() noexcept
Returns the current edge and advances the iterator.
Definition: E_iterator.hpp:133
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition: E_iterator.hpp:117
edge yield_edge() noexcept
Returns the current edge and advances the iterator.
Definition: E_iterator.hpp:126
bool is_projective(const graphs::rooted_tree &rt, const detail::linarr_wrapper< arr_type > &arr) noexcept
Is a given arrangement projective?
Definition: formal_constraints.hpp:130
bool is_root_covered(const graphs::rooted_tree &rt, const detail::linarr_wrapper< arr_type > &arr) noexcept
Is the root of a rooted tree covered in a given arrangement?
Definition: formal_constraints.hpp:69
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t position
Node's position type.
Definition: basic_types.hpp:55
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53
A wrapper to easily use identity arrangements.
Definition: identity_arrangement.hpp:72
Typesafe node type.
Definition: basic_types.hpp:67