13#include "quetzal/coalescence/graph/binary_tree.hpp"
14#include "quetzal/coalescence/graph/k_ary_tree.hpp"
15#include "quetzal/io/newick/ast.hpp"
16#include "quetzal/io/newick/generator.hpp"
17#include "quetzal/io/newick/parser.hpp"
29 std::reference_wrapper<Gen> _generator;
30 boost::visit _previous;
35 void operator()(boost::visit stage,
auto v)
39 case boost::visit::pre:
40 _generator.get().pre_order()(v);
41 _previous = boost::visit::pre;
43 case boost::visit::in:
44 if (_previous == boost::visit::post)
45 _generator.get().in_order()();
46 _previous = boost::visit::in;
48 case boost::visit::post:
49 _generator.get().post_order()(v);
50 _previous = boost::visit::post;
64 void discover_vertex(
auto v,
auto const &)
const
69 void finish_vertex(
auto v,
auto const &)
const
74 void tree_edge(
auto e,
auto const &g)
const
76 if (stack_.top()++ > 0)
85template <
typename Flavor>
86std::string generate_from(
92 using vertex_type = tree_type::vertex_descriptor;
97 std::predicate<vertex_type>
auto has_parent = [&graph](vertex_type
const &v) {
return graph.has_predecessor(v); };
98 std::predicate<vertex_type>
auto has_children = [&graph](vertex_type v) {
return graph.has_successors(v); };
99 newick::Formattable<vertex_type>
auto branch_length = [](vertex_type) {
return ""; };
100 newick::Formattable<vertex_type>
auto label = [](vertex_type v) {
return ""; };
104 using Gen =
decltype(gen);
106 detail::TreeVisitorWrapper vis(gen);
107 graph.depth_first_search(root, vis);
108 return gen.take_result();
114template <
typename Flavor>
115std::string generate_from(
121 using vertex_type =
typename tree_type::vertex_descriptor;
125 std::predicate<vertex_type>
auto has_parent = [&graph](vertex_type
const &v) {
return graph.has_predecessor(v); };
127 std::predicate<vertex_type>
auto has_children = [&graph](vertex_type v) {
128 return static_cast<bool>(graph.out_degree(v));
131 newick::Formattable<vertex_type>
auto branch_length = [](vertex_type) {
return ""; };
133 newick::Formattable<vertex_type>
auto label = [](vertex_type) {
return ""; };
137 using Gen =
decltype(gen);
142 std::reference_wrapper<Gen> _generator;
143 boost::visit _previous;
144 VisWrap(Gen &gen) : _generator(gen)
147 void operator()(boost::visit stage, vertex_type v)
151 case boost::visit::pre:
152 _generator.get().pre_order()(v);
153 _previous = boost::visit::pre;
155 case boost::visit::in:
156 if (_previous == boost::visit::post)
157 _generator.get().in_order()();
158 _previous = boost::visit::in;
160 case boost::visit::post:
161 _generator.get().post_order()(v);
162 _previous = boost::visit::post;
168 graph.depth_first_search(root, vis);
169 return gen.take_result();
175template <
class VertexProperty,
class EdgeProperty,
typename Flavor>
176 requires(!std::is_same_v<VertexProperty, boost::no_property> && !std::is_same_v<VertexProperty, boost::no_property>)
183 using vertex_descriptor =
typename tree_type::vertex_descriptor;
184 using edge_descriptor =
typename tree_type::edge_descriptor;
188 std::predicate<vertex_descriptor>
auto has_parent = [&graph](vertex_descriptor
const &v) {
189 return graph.has_predecessor(v);
192 std::predicate<vertex_descriptor>
auto has_children = [&graph](vertex_descriptor v) {
193 return static_cast<bool>(graph.out_degree(v));
196 newick::Formattable<vertex_descriptor>
auto branch_length = [&graph = std::as_const(graph)](vertex_descriptor v) {
197 std::string s = graph.has_predecessor(v) ? graph[edge_descriptor(graph.predecessor(v), v)].label() :
"";
201 newick::Formattable<vertex_descriptor>
auto label = [&graph](vertex_descriptor v) {
return graph[v].label(); };
205 using Gen =
decltype(gen);
210 std::reference_wrapper<Gen> _generator;
211 boost::visit _previous;
212 VisWrap(Gen &gen) : _generator(gen)
215 void operator()(boost::visit stage, vertex_descriptor v)
219 case boost::visit::pre:
220 _generator.get().pre_order()(v);
221 _previous = boost::visit::pre;
223 case boost::visit::in:
224 if (_previous == boost::visit::post)
225 _generator.get().in_order()();
226 _previous = boost::visit::in;
228 case boost::visit::post:
229 _generator.get().post_order()(v);
230 _previous = boost::visit::post;
236 graph.depth_first_search(root, vis);
237 return gen.take_result();
243template <
class VertexProperty,
class EdgeProperty,
typename Flavor>
244 requires(!std::is_same_v<VertexProperty, boost::no_property> && !std::is_same_v<VertexProperty, boost::no_property>)
252 using vertex_descriptor =
typename tree_type::vertex_descriptor;
253 using edge_descriptor =
typename tree_type::edge_descriptor;
257 std::predicate<vertex_descriptor>
auto has_parent = [&graph](vertex_descriptor
const &v) {
258 return graph.has_predecessor(v);
261 std::predicate<vertex_descriptor>
auto has_children = [&graph](vertex_descriptor v) {
262 return static_cast<bool>(graph.out_degree(v));
266 std::string s = graph.has_predecessor(v) ? graph[graph.edge(graph.predecessor(v), v).value()].label() :
"";
274 using Gen =
decltype(gen);
279 std::reference_wrapper<Gen> _generator;
280 boost::visit _previous;
281 VisWrap(Gen &gen) : _generator(gen)
284 void operator()(boost::visit stage, vertex_descriptor v)
288 case boost::visit::pre:
289 _generator.get().pre_order()(v);
290 _previous = boost::visit::pre;
292 case boost::visit::in:
293 if (_previous == boost::visit::post)
294 _generator.get().in_order()();
295 _previous = boost::visit::in;
297 case boost::visit::post:
298 _generator.get().post_order()(v);
299 _previous = boost::visit::post;
305 graph.depth_first_search(root, vis);
Definition binary_tree.hpp:330
Definition k_ary_tree.hpp:349