50#include <lal/basic_types.hpp>
51#include <lal/graphs/free_tree.hpp>
52#include <lal/graphs/rooted_tree.hpp>
53#include <lal/properties/branchless_path.hpp>
54#include <lal/detail/array.hpp>
55#include <lal/detail/graphs/traversal.hpp>
73template <
class tree_t>
79 std::vector<properties::branchless_path>& res,
84 const uint64_t n = t.get_num_nodes();
87 if (t.get_degree(u) != 2 and t.get_degree(v) != 2) {
90 if (u > v) {
return; }
93 assert(t.has_edge(u, v) or t.has_edge(v, u));
103 res.push_back(std::move(p));
108 assert(not bfs.node_was_visited(u));
111 if (bfs.node_was_visited(v)) {
return; }
120 bfs.set_visited(u, 1);
126 const auto& seq = p.get_vertex_sequence();
127 node lowest_lexicographic = n + 1;
128 for (std::size_t i = 1; i < seq.size() - 1; ++i) {
129 lowest_lexicographic = std::min(lowest_lexicographic, seq[i]);
131 p.set_lowest_lexicographic(lowest_lexicographic);
134 bfs.set_visited(p.get_h1(), 0);
135 bfs.set_visited(p.get_h2(), 0);
138 res.push_back(std::move(p));
147template <
class tree_t>
148[[nodiscard]] std::vector<properties::branchless_path>
152 const uint64_t n = t.get_num_nodes();
155 std::vector<properties::branchless_path> res;
163 bfs.set_process_current(
164 [&](
const auto&,
node u) {
166 if (t.get_degree(u) != 2) {
175 [&](
const auto&,
node u) {
return t.get_degree(u) != 2; }
179 for (
node u = 0; u < n; ++u) {
180 if (t.get_degree(u) == 2) {
continue; }
182 if constexpr (std::is_base_of_v<graphs::free_tree, tree_t>) {
183 for (
node v : t.get_neighbors(u)) {
187 else if constexpr (std::is_base_of_v<graphs::rooted_tree, tree_t>) {
188 for (
node v : t.get_out_neighbors(u)) {
191 for (
node v : t.get_in_neighbors(u)) {
Abstract graph Breadth-First Search traversal.
Definition traversal.hpp:89
Branchless paths in trees.
Definition branchless_path.hpp:73
void add_node(node u) noexcept
Adds a node to this path.
Definition branchless_path.hpp:99
void expand_branchless_path(const tree_t &t, const node u, const node v, BFS< tree_t > &bfs, std::vector< properties::branchless_path > &res, properties::branchless_path &p) noexcept
Completes the branchless path.
Definition branchless_paths_compute.hpp:75
std::vector< properties::branchless_path > branchless_paths_compute(const tree_t &t) noexcept
Finds all branchless paths in a tree.
Definition branchless_paths_compute.hpp:149
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