LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
Macutek.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// lal includes
45#include <lal/graphs/rooted_tree.hpp>
46#include <lal/linarr/chunking/chunk.hpp>
47#include <lal/detail/linarr/chunking/generic.hpp>
48
49namespace lal {
50namespace detail {
51
61template <class arrangement_t>
62class chunks_Macutek : public chunks_generic<arrangement_t> {
63public:
69 chunks_Macutek(const graphs::rooted_tree& rt, const arrangement_t& arr)
70 noexcept
71 : generic(rt, arr)
72 {
73 }
74
81 void chunk_input_tree() noexcept {
83
84 position_t p{0ull};
85
87 m_sequence.set_chunk_index(m_arr[p], 0);
88
89 ++p;
90 for (; p < m_n; ++p) {
91 const node prev = m_arr[p - 1ull];
92 const node current = m_arr[p];
93
94 const bool are_syntactically_linked =
95 m_rt.has_edge(prev, current) or m_rt.has_edge(current, prev);
96
97 if (are_syntactically_linked) {
98 last_chunk().add_node( current );
99 }
100 else {
102 }
103
104 m_sequence.set_chunk_index(m_arr[p], m_sequence.size() - 1);
105 }
106
108 }
109
110private:
112 void set_parent_chunks() noexcept {
113 for (std::size_t i = 0; i < m_sequence.size(); ++i) {
115 }
116 }
117
118private:
119
122
123 // member variables
125 using generic::m_n;
126 using generic::m_arr;
127 using generic::m_rt;
128
129 // member functions
132
133};
134
135} // -- namespace detail
136} // -- namespace lal
Implementation of Mačutek's algorithm for chunking.
Definition Macutek.hpp:62
void chunk_input_tree() noexcept
Main method of this class.
Definition Macutek.hpp:81
const uint64_t m_n
Number of vertices of the tree.
Definition generic.hpp:147
const arrangement_t m_arr
Linear arrangement.
Definition generic.hpp:145
linarr::chunk_sequence m_sequence
The sequence of chunks obtained.
Definition generic.hpp:150
chunks_Macutek(const graphs::rooted_tree &rt, const arrangement_t &arr) noexcept
Constructor.
Definition Macutek.hpp:69
void set_parent_chunks() noexcept
Set the parent node of all chunks.
Definition Macutek.hpp:112
void set_parent_chunk(linarr::chunk &c) noexcept
Set the parent node of a chunks.
Definition generic.hpp:109
linarr::chunk & last_chunk() noexcept
Returns a reference to the last chunk in the sentence.
Definition generic.hpp:95
const graphs::rooted_tree & m_rt
Input rooted tree.
Definition generic.hpp:143
Basic algorithms existent in every definition of chunking.
Definition generic.hpp:61
const uint64_t m_n
Number of vertices of the tree.
Definition generic.hpp:147
const arrangement_t m_arr
Linear arrangement.
Definition generic.hpp:145
linarr::chunk_sequence m_sequence
The sequence of chunks obtained.
Definition generic.hpp:150
void set_parent_chunk(linarr::chunk &c) noexcept
Set the parent node of a chunks.
Definition generic.hpp:109
linarr::chunk & last_chunk() noexcept
Returns a reference to the last chunk in the sentence.
Definition generic.hpp:95
const graphs::rooted_tree & m_rt
Input rooted tree.
Definition generic.hpp:143
bool has_edge(const node u, const node v) const noexcept
Returns true if the edge exists in the graph.
Rooted tree graph class.
Definition rooted_tree.hpp:109
void push_chunk() noexcept
Adds a new chunk to the collection.
Definition chunk_sequence.hpp:155
std::size_t size() const noexcept
Returns the number of chunks.
Definition chunk_sequence.hpp:181
void init(const std::size_t n) noexcept
Initializes this chunk sequence.
Definition chunk_sequence.hpp:121
void add_node(const node u) noexcept
Adds a new node to this chunk.
Definition chunk.hpp:78
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51
Typesafe position type.
Definition basic_types.hpp:244