51#include <lal/linear_arrangement.hpp>
52#include <lal/detail/array.hpp>
53#include <lal/iterators/E_iterator.hpp>
54#include <lal/detail/graphs/size_subtrees.hpp>
55#include <lal/detail/sorting/counting_sort.hpp>
56#include <lal/detail/properties/tree_centroid.hpp>
62namespace bipartite_opt_utils {
82 bool make_arrangement,
85 class bipartite_coloring_t
87[[nodiscard]] std::conditional_t<
89 std::pair<uint64_t, linear_arrangement>,
93(
const graph_t& g,
const bipartite_coloring_t& c)
96 static_assert(std::is_base_of_v<graphs::graph, graph_t>);
98 const auto n = g.get_num_nodes();
102 if constexpr (make_arrangement) {
111 std::size_t size_1 = 0;
113 std::size_t size_2 = 0;
116 const auto first_color = c[0];
117 for (
node u = 0; u < n; ++u) {
118 if (c[u] == first_color) {
119 vertices_color_1[size_1++] = u;
122 vertices_color_2[size_2++] = u;
126 const auto sort_nodes =
134 [&](
const node u) -> std::size_t {
137 return g.get_degree(u);
141 sort_nodes(vertices_color_1, size_1);
142 sort_nodes(vertices_color_2, size_2);
148 if constexpr (make_arrangement) {
153 for (std::size_t i = size_1 - 1; i > 0; --i) {
154 const node u = vertices_color_1[i];
155 if constexpr (make_arrangement) {
159 D += (n - p)*g.get_degree(u);
163 const node u = vertices_color_1[0];
164 if constexpr (make_arrangement) {
165 arr.
assign(vertices_color_1[0], p);
168 D += (n - p)*g.get_degree(u);
171 for (std::size_t i = 0; i < size_2; ++i) {
172 const node u = vertices_color_2[i];
173 if constexpr (make_arrangement) {
177 D -= (n - p)*g.get_degree(u);
180 if constexpr (make_arrangement) {
181 return {D, std::move(arr)};
Linear arrangement of vertices.
Definition linear_arrangement.hpp:103
void assign(const NODE u, const POSITION p) noexcept
Assigns a node u to position p.
Definition linear_arrangement.hpp:379
void resize(std::size_t n) noexcept
Changes the size of the arrangement.
Definition linear_arrangement.hpp:355
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 > optimal_bipartite_arrangement_AEF(const graph_t &g, const bipartite_coloring_t &c) noexcept
Optimal bipartite arrangement.
Definition bipartite_opt_utils.hpp:93
sort_type
The different types of sorting patterns.
Definition sorting_types.hpp:49
void counting_sort(const value_iterator_t begin, const value_iterator_t end, const std::size_t largest_key_plus_1, const Callable &key, countingsort::memory< value_t > &mem) noexcept
Counting sort algorithm with reusable memory.
Definition counting_sort.hpp:152
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t position
Node's position type.
Definition basic_types.hpp:53
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59
T * begin() noexcept
Non-constant raw pointer to first element.
Definition array.hpp:300