Ultra 0.9.4
Loading...
Searching...
No Matches
print_internal.h
Go to the documentation of this file.
1
12
13#if !defined(ULTRA_PRINT_INTERNAL_H)
14#define ULTRA_PRINT_INTERNAL_H
15
16#include "kernel/individual.h"
17#include "utility/log.h"
18
19namespace ultra::internal
20{
21
28template<Individual I>
29void print_linear_in_line(std::ostream &s, const I &ind)
30{
31 if (ind.empty())
32 return;
33
34 s << *ind.begin();
35 for (auto it(std::next(ind.begin())); it != ind.end(); ++it)
36 s << ' ' << *it;
37}
38
49template<Individual I>
50void print_linear_graphviz(std::ostream &s, const I &ind)
51{
52 s << "graph {\n";
53
54 std::size_t i(0);
55 for (const auto &g : ind)
56 {
57 s << " g" << i << " [label=" << g << ", shape=circle];\n";
58 ++i;
59 }
60
61 for (std::size_t j(1); j < i; ++j)
62 s << " g" << (j - 1) << " -- g" << j << ";\n";
63
64 s << '}';
65}
66
67template<class Individual>
68void print_linear(std::ostream &s, const Individual &ind,
69 out::print_format_t format, std::string_view type_name)
70{
71 switch (format)
72 {
73 case out::graphviz_f:
74 print_linear_graphviz(s, ind);
75 return;
76
77 case out::in_line_f:
78 print_linear_in_line(s, ind);
79 return;
80
81 default:
82 ultraWARNING("Unsupported print format for {}", type_name);
83 print_linear_in_line(s, ind);
84 }
85}
86
87} // namespace ultra::internal
88
89#endif // include guard
Definition individual.h:93
print_format_t
Rendering format used to print an individual.
Definition individual.h:29
void print_linear_in_line(std::ostream &s, const I &ind)
Definition print_internal.h:29
void print_linear_graphviz(std::ostream &s, const I &ind)
Definition print_internal.h:50