73template <
typename State>
90namespace ca_dot_detail {
92inline std::string
quote(
const std::string &s)
94 std::ostringstream
out;
96 for (
const char c : s)
98 if (c ==
'"' or c ==
'\\')
116 return (c >=
'a' and c <=
'z')
or (c >=
'A' and c <=
'Z')
or c ==
'_';
124 for (std::size_t i = 1; i < s.size(); ++i)
145template <
typename Graph,
typename Palette>
150 requires requires(
const Graph &g, std::size_t n,
Palette &&p,
const typename Graph::state_type &v) {
154 { p(v) } -> std::convertible_to<std::string>;
157 const char *kind =
opts.undirected ?
"graph" :
"digraph";
158 const char *edge =
opts.undirected ?
"--" :
"->";
160 out <<
" node [shape=circle, style=filled, fixedsize=true, width=0.42];\n";
162 for (std::size_t n = 0; n < graph.size(); ++n)
164 const std::string
fill =
palette(graph.at_node(n));
166 if (
opts.include_labels)
169 out <<
", label=\"\"";
171 out <<
", fontcolor=\"white\"";
175 for (std::size_t n = 0; n < graph.size(); ++n)
177 const auto &
row = graph.neighbours(n);
178 for (std::size_t
k = 0;
k <
row.size(); ++
k)
180 const std::size_t
m =
row[
k];
183 out <<
" n" << n <<
' ' << edge <<
" n" <<
m <<
";\n";
206template <
typename Graph,
typename Palette>
211 std::ostringstream
out;
220template <
typename Palette>
240 const std::size_t zero_pad = 6)
255 template <
typename Graph>
259 if (
const auto parent = path.parent_path();
not parent.empty())
260 std::filesystem::create_directories(parent);
261 std::ofstream
out(path);
270template <
typename Palette>
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
size_t size_t int32_t value
size_t size_t int32_t * out
Directory-backed frame sinks for CA trajectories.
Path-pattern sink that writes GraphViz DOT frames.
std::filesystem::path pattern_
Dot_Frame_Sink(std::filesystem::path path_pattern, Palette palette, DOT_Render_Options opts={}, const std::size_t zero_pad=6)
Build a DOT frame sink.
void accept(const std::size_t step, const Graph &graph)
Write one DOT frame.
static void flush()
DOT frames are written eagerly; this is a no-op.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
std::string quote(const std::string &s)
std::string quote_id_if_needed(const std::string &s)
Return s as a bare DOT identifier when it matches [A-Za-z_][A-Za-z_0-9]*, otherwise return quote(s).
std::filesystem::path format_step_path(const std::filesystem::path &pattern, const std::size_t step, const std::size_t zero_pad=6)
Format a step-indexed file path.
void render_graph_lattice_dot(std::ostream &out, const Graph &graph, Palette &&palette, const DOT_Render_Options &opts={})
Render a graph CA frame as GraphViz DOT.
std::string render_graph_lattice_dot_string(const Graph &graph, Palette &&palette, const DOT_Render_Options &opts={})
Return a graph frame rendered as DOT.
Main namespace for Aleph-w library functions.
void fill(Itor beg, const Itor &end, const T &value)
Fill a range with a value.
and
Check uniqueness with explicit hash + equality functors.
Default binary DOT fill-colour palette.
std::string dead_colour
fill colour for dead cells
std::string alive_colour
fill colour for live cells
State dead
state considered dead
std::string operator()(const State &value) const
Map a cell state to a GraphViz colour.
bool undirected
use graph/-- and suppress duplicate edges
bool include_labels
label nodes with their numeric id
std::string graph_name
DOT graph identifier.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
CA whose underlying topology is an arbitrary undirected graph.