73static const char *
fill_palette[] = {
"#f94144",
"#277da1",
"#90be6d",
"#f8961e",
"#7b2cbf",
"#577590"};
75static const char *
font_palette[] = {
"#ffffff",
"#ffffff",
"#111111",
"#111111",
"#ffffff",
"#ffffff"};
77static const char *
palette_names[] = {
"coral",
"ocean",
"sage",
"amber",
"violet",
"slate"};
133 if (right[i] == node)
148 out <<
" " <<
dot_id <<
" [label=\"" << label <<
"\\nc" <<
color <<
"\""
151 <<
", pos=\"" << pos <<
"\"];\n";
157 ofstream
out(filename);
160 out <<
"graph CrownColoring {\n"
161 <<
" layout=neato;\n"
162 <<
" overlap=false;\n"
163 <<
" splines=true;\n"
164 <<
" outputorder=edgesfirst;\n"
165 <<
" graph [label=\"" << title <<
"\\n"
168 <<
"\", labelloc=t, fontsize=20, fontname=\"Helvetica\"];\n"
169 <<
" node [shape=circle, style=filled, fixedsize=true,\n"
170 <<
" width=0.95, height=0.95, penwidth=1.8,\n"
171 <<
" color=\"#1f2937\", fontname=\"Helvetica\"];\n"
172 <<
" edge [color=\"#94a3b8\", penwidth=1.5];\n"
173 <<
" left_partition [shape=plaintext, fixedsize=false,"
174 <<
" label=\"Left partition U\", pos=\"0,9.5!\"];\n"
175 <<
" right_partition [shape=plaintext, fixedsize=false,"
176 <<
" label=\"Right partition V\", pos=\"5,9.5!\"];\n";
186 for (Graph::Arc_Iterator it(g); it.has_curr(); it.next_ne())
188 Node *src = it.get_src_node();
189 Node *tgt = it.get_tgt_node();
206template <
class Coloring>
216 cout <<
" " <<
suffix <<
": " <<
num_colors <<
" color(s) -> " << filename <<
'\n';
222 const string prefix =
argc > 1 ?
argv[1] :
"graph_coloring_crown";
229 cout <<
"Graph coloring Graphviz example\n";
230 cout <<
"==============================\n";
233 cout <<
"Node order is adversarial for greedy coloring: "
234 <<
"u0, v0, u1, v1, ...\n\n";
248 cout <<
"\nRender any DOT file with Graphviz, for example:\n";
249 cout <<
" neato -n -Tsvg " <<
prefix <<
"_dsatur.dot -o " <<
prefix <<
"_dsatur.svg\n";
250 cout <<
" neato -n -Tpng " <<
prefix <<
"_exact.dot -o " <<
prefix <<
"_exact.png\n";
254catch (
const exception &e)
256 cerr <<
"Error: " << e.what() <<
'\n';
Graph coloring algorithms and heuristics.
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error()
Throws std::runtime_error unconditionally.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
WeightedDigraph::Node Node
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
_Graph_Node Node
The graph type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
constexpr size_t get_num_arcs() const noexcept
static const char * font_palette[]
static void write_coloring_dot(const string &filename, const string &title, const Graph &g, Node *left[Crown_Size], Node *right[Crown_Size], const ColorMap &colors, size_t num_colors)
static const char * right_positions[Crown_Size]
static void export_variant(const string &prefix, const string &suffix, const string &title, const Graph &g, Node *left[Crown_Size], Node *right[Crown_Size], Coloring coloring)
static const char * palette_names[]
static string color_legend(size_t num_colors)
static const char * fill_palette[]
static constexpr size_t Crown_Size
static string color_name(size_t c)
static const char * left_positions[Crown_Size]
static void locate_node(Node *node, Node *left[Crown_Size], Node *right[Crown_Size], bool &is_left, size_t &index)
static constexpr size_t palette_size()
static void build_crown_graph(Graph &g, Node *left[Crown_Size], Node *right[Crown_Size])
static void write_colored_node(ostream &out, const string &dot_id, const string &label, const char *pos, size_t color)
size_t dsatur_coloring(const GT &g, DynMapTree< typename GT::Node *, size_t > &colors)
DSatur graph coloring (saturation-degree heuristic).
size_t chromatic_number(const GT &g, DynMapTree< typename GT::Node *, size_t > &colors)
Computes the exact chromatic number of a small graph.
size_t greedy_coloring(const GT &g, DynMapTree< typename GT::Node *, size_t > &colors)
Greedy graph coloring in iteration order.
size_t welsh_powell_coloring(const GT &g, DynMapTree< typename GT::Node *, size_t > &colors)
Welsh-Powell graph coloring.
Main namespace for Aleph-w library functions.
static void suffix(Node *root, DynList< Node * > &acc)
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
static void prefix(Node *root, DynList< Node * > &acc)
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
static long & color(typename GT::Node *p)
Arc of graph implemented with double-linked adjacency lists.
Generic graph and digraph implementations.