15# include <gtest/gtest.h>
40 for (
size_t i = 0; i < n; ++i)
63 for (
size_t i = 0; i < n; ++i)
68 for (
auto it =
nodes.get_it(); it.has_curr(); it.next_ne())
90 for (
size_t i = 0; i < n; ++i)
92 auto *curr = g.
insert_node(
"v" + std::to_string(i));
106 if (n == 0)
return g;
108 for (
size_t i = 1; i < n; ++i)
110 auto *leaf = g.
insert_node(
"leaf" + std::to_string(i));
124 for (
int i = 0; i < 10; ++i)
128 for (
int i = 0; i < 5; ++i)
139 for (
int i = 0; i < 5; ++i)
155 for (
size_t i = 1; i < n; ++i)
164 for (
auto it =
ring.get_it(); it.has_curr(); it.next_ne())
166 auto *curr = it.get_curr();
185 for (
size_t i = 0; i <
m; ++i)
187 for (
size_t i = 0; i < n; ++i)
190 for (
auto li = left.
get_it();
li.has_curr();
li.next_ne())
191 for (
auto ri = right.
get_it();
ri.has_curr();
ri.next_ne())
246 for (
int i = 0; i < 10; ++i)
522 for (
auto it = g.get_node_it(); it.has_curr(); it.next_ne())
650 for (
int i = 0; i < 5; ++i)
707 for (
int i = 0; i < 65; ++i)
717 std::vector<Graph::Node *>
ns;
718 for (
int i = 0; i < 64; ++i)
776 auto *a = g.insert_node(
"a");
777 auto *b = g.insert_node(
"b");
798 auto *a = g.insert_node(
"a");
799 auto *b = g.insert_node(
"b");
1008 std::mt19937
rng(42);
1012 std::vector<Graph::Node *>
nodes;
1017 std::uniform_real_distribution<> dist(0.0, 1.0);
1019 for (
size_t j = i + 1; j <
num_nodes; ++j)
1028 for (
auto it = g.get_node_it(); it.has_curr(); it.next_ne())
1029 delta = std::max(delta, g.get_num_arcs(it.get_curr()));
1041 {10, 0.1,
"sparse"},
1042 {15, 0.3,
"medium"},
1044 {20, 0.05,
"disconnected components"},
1045 {8, 0.8,
"very dense"}
1063 <<
"Greedy produced invalid coloring for " <<
tc.description
1064 <<
" graph (trial " <<
trial <<
")";
1066 <<
"Greedy used " <<
k_greedy <<
" colors but max degree is " << delta
1067 <<
" for " <<
tc.description <<
" graph (trial " <<
trial <<
")";
1072 <<
"Welsh-Powell produced invalid coloring for " <<
tc.description
1073 <<
" graph (trial " <<
trial <<
")";
1075 <<
"Welsh-Powell used " <<
k_wp <<
" colors but max degree is " << delta
1076 <<
" for " <<
tc.description <<
" graph (trial " <<
trial <<
")";
1083 <<
"DSatur produced invalid coloring for " <<
tc.description
1084 <<
" graph (trial " <<
trial <<
")";
1088 <<
"DSatur used " <<
k <<
" colors but max degree is " << delta
1089 <<
" for " <<
tc.description <<
" graph (trial " <<
trial <<
")";
1098 <<
"chromatic_number produced invalid coloring for " <<
tc.description
1099 <<
" graph (trial " <<
trial <<
")";
1102 <<
"Exact chromatic number " <<
chi <<
" exceeds Greedy result " <<
k_greedy
1103 <<
" for " <<
tc.description <<
" graph (trial " <<
trial <<
")";
1105 <<
"Exact chromatic number " <<
chi <<
" exceeds Welsh-Powell result " <<
k_wp
1106 <<
" for " <<
tc.description <<
" graph (trial " <<
trial <<
")";
1108 <<
"Exact chromatic number " <<
chi <<
" exceeds DSatur result " <<
k
1109 <<
" for " <<
tc.description <<
" graph (trial " <<
trial <<
")";
Graph coloring algorithms and heuristics.
virtual Node * insert_node(Node *p)
Arc * insert_arc(Node *src, Node *tgt, void *a)
Functor wrapper for dsatur_coloring.
Generic directed graph (digraph) wrapper template.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Generic key-value map implemented on top of a binary search tree.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Dynamic set backed by balanced binary search trees with automatic memory management.
const size_t & size() const
Returns the cardinality of the set.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
Arc for graphs implemented with simple adjacency lists.
Functor wrapper for greedy_coloring.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Graph class implemented with singly-linked adjacency lists.
Arc * insert_arc(Node *src, Node *tgt, void *a)
virtual Node * insert_node(Node *p)
Insertion of a node whose memory has already been allocated.
A non-degenerate triangle defined by three points.
Functor wrapper for welsh_powell_coloring.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
CityGraph build_random_graph(int num_nodes, double edge_probability, double max_weight, unsigned seed=42)
Build a random graph for performance testing.
static Graph build_complete_bipartite(size_t m, size_t n)
static Graph build_star(size_t n)
static Graph build_petersen()
static Graph build_path(size_t n)
static Graph build_complete_graph(size_t n)
static Graph build_cycle(size_t n)
static Graph build_wheel(size_t n)
static size_t count_distinct_colors(const DynMapTree< Graph::Node *, size_t > &colors)
DynArray< Graph::Node * > nodes
size_t dsatur_coloring(const GT &g, DynMapTree< typename GT::Node *, size_t > &colors)
DSatur graph coloring (saturation-degree heuristic).
bool is_valid_coloring(const GT &g, const DynMapTree< typename GT::Node *, size_t > &colors)
Validates a graph coloring.
size_t chromatic_number(const GT &g, DynMapTree< typename GT::Node *, size_t > &colors)
Computes the exact chromatic number of a small graph.
#define NODE_COOKIE(p)
Return the node cookie
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.
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.
Arc of graph implemented with double-linked adjacency lists.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Array-based graph implementation.
Simple graph implementation with adjacency lists.