45#include <lal/iterators/E_iterator.hpp>
46#include <lal/graphs/rooted_tree.hpp>
47#include <lal/properties/bipartite_graph_coloring.hpp>
48#include <lal/detail/arrangement_wrapper.hpp>
68template <
class arrangement_t>
74 assert(rt.is_rooted_tree());
81 while (not e_it.
end()) {
86 const bool r_covered_st = ps < pr and pr < pt;
87 const bool r_covered_ts = pt < pr and pr < ps;
88 if (r_covered_st or r_covered_ts) {
return true; }
109template <
class arrangement_t>
115 assert(rt.is_rooted_tree());
120 if (not is_planar(rt, arr)) {
return false; }
138template <
class arrangement_t>
143 const auto n = c.size();
146 while (p < n and num_changes <= 1) {
147 const node u = arr[p - 1ull];
148 const auto color_u = c.get_color_of(u);
149 const node v = arr[p];
150 const auto color_v = c.get_color_of(v);
151 num_changes += color_v != color_u;
154 return num_changes <= 1;
170template <
class graph_t,
class arrangement_t>
171[[nodiscard]]
bool is_bipartite(
const graph_t& g,
const arrangement_t& arr)
179 const auto n = g.get_num_nodes();
182 const auto color_a_vertex = [&](
node u) {
183 color_per_vertex[u] = blue;
184 if constexpr (std::is_base_of_v<graphs::directed_graph, graph_t>) {
185 for (
node v : g.get_out_neighbors(u)) { color_per_vertex[v] = red; }
186 for (
node v : g.get_in_neighbors(u)) { color_per_vertex[v] = red; }
189 for (
node v : g.get_neighbors(u)) { color_per_vertex[v] = red; }
197 while (p < n and num_changes <= 1) {
198 const node u = arr[p];
199 if (color_per_vertex[u] == invalid) {
202 const node v = arr[p - 1ull];
203 num_changes += color_per_vertex[v] != color_per_vertex[u];
206 return num_changes <= 1;
Rooted tree graph class.
Definition rooted_tree.hpp:109
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
A class to represent a coloring of the vertices of a bipartite graph.
Definition bipartite_graph_coloring.hpp:60
static constexpr color_t invalid_color
An invalid color, used to initialize colors to an invalid value.
Definition bipartite_graph_coloring.hpp:70
uint64_t color_t
A useful type for colors.
Definition bipartite_graph_coloring.hpp:68
static constexpr color_t red
A color, called red, of value 0.
Definition bipartite_graph_coloring.hpp:72
static constexpr color_t blue
A color, called blue, of value 1.
Definition bipartite_graph_coloring.hpp:74
bool is_root_covered(const graphs::rooted_tree &rt, const arrangement_t &arr) noexcept
Is the root of a rooted tree covered in a given arrangement?
Definition formal_constraints.hpp:70
bool is_bipartite(const graph_t &g, const arrangement_t &arr) noexcept
Is a given arrangement bipartite?
Definition formal_constraints.hpp:171
bool is_bipartite__connected(const properties::bipartite_graph_coloring &c, const arrangement_t &arr) noexcept
Is a given arrangement bipartite?
Definition formal_constraints.hpp:140
bool is_projective(const graphs::rooted_tree &rt, const arrangement_t &arr) noexcept
Is a given arrangement projective?
Definition formal_constraints.hpp:111
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
Typesafe node type.
Definition basic_types.hpp:70
Typesafe position type.
Definition basic_types.hpp:244