Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
graph_exhaustive_trees_test.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
48#include <algorithm>
49#include <map>
50#include <random>
51#include <set>
52#include <stdexcept>
53#include <string>
54#include <vector>
55
56#include <gtest/gtest.h>
57
58#include <tpl_graph.H>
59#include <Kruskal.H>
60#include <Prim.H>
61#include <graph_to_tree.H>
62#include <generate_df_tree.H>
63
65#include "graph_harness.H"
66#include "graph_oracles.H"
67
68using namespace Aleph;
69using namespace graph_harness;
70namespace oracle = graph_oracles;
73
74namespace
75{
78 template <class F>
79 void for_each_weighting(Spec s, long long lo, long long hi, F && f)
80 {
81 s.w.assign(s.arcs.size(), lo);
82 while (true)
83 {
84 f(static_cast<const Spec &>(s));
85 size_t i = 0;
86 while (i < s.w.size() and s.w[i] == hi)
87 s.w[i++] = lo;
88 if (i == s.w.size())
89 return;
90 ++s.w[i];
91 }
92 }
93
97 std::string forest_error(const Spec & s, const std::vector<int> & arcs,
98 unsigned long hidden, int start = -1)
99 {
100 std::vector<int> orig;
101 const Spec shown = oracle::without(s, hidden, orig);
102 const auto comp = oracle::component_of(shown);
103
104 // The part that must be spanned: all, or the component of start
105 Spec part;
106 part.n = s.n;
107 for (size_t i = 0; i < shown.arcs.size(); ++i)
108 if (start == -1 or comp[size_t(shown.arcs[i][0])] == comp[size_t(start)])
109 {
110 part.arcs.push_back(shown.arcs[i]);
111 part.w.push_back(shown.w[i]);
112 }
113 int nodes = s.n;
114 if (start != -1)
115 nodes = int(std::count(comp.begin(), comp.end(), comp[size_t(start)]));
116 const int want_arcs = nodes - (start == -1 ? oracle::components(shown) : 1);
117
118 oracle::Union_Find uf(s.n);
119 long long total = 0;
120 for (int i : arcs)
121 {
122 if (i < 0 or size_t(i) >= s.arcs.size())
123 return "an arc that is not of the graph";
124 if (not graph_filters::shown(hidden, i))
125 return "the hidden arc " + std::to_string(i);
126 const auto & a = s.arcs[size_t(i)];
127 if (start != -1 and comp[size_t(a[0])] != comp[size_t(start)])
128 return "the arc " + std::to_string(i) + " out of the component of the start";
129 if (not uf.join(a[0], a[1]))
130 return "the arc " + std::to_string(i) + " closes a cycle";
131 total += s.w[size_t(i)];
132 }
133 if (int(arcs.size()) != want_arcs)
134 return std::to_string(arcs.size()) + " arcs, not " + std::to_string(want_arcs);
135 if (const long long want = oracle::min_spanning_forest_weight(part); total != want)
136 return "weight " + std::to_string(total) + ", not " + std::to_string(want);
137 return "";
138 }
139
141 template <class GT>
142 std::vector<int> painted_arcs(const GT & g)
143 {
144 std::vector<int> r;
145 for (auto it = g.get_arc_it(); it.has_curr(); it.next_ne())
146 if (IS_ARC_VISITED(it.get_curr(), Aleph::Spanning_Tree))
147 r.push_back(num(it.get_curr()));
148 return r;
149 }
150
153 template <class GT>
154 std::vector<int> tree_arcs(const GT & g, const GT & tree)
155 {
156 if (tree.get_num_nodes() != g.get_num_nodes())
157 return {-1};
158 for (auto it = g.get_node_it(); it.has_curr(); it.next_ne())
159 {
160 auto * p = it.get_curr();
161 auto * t = mapped_node<GT>(p);
162 if (t == nullptr or num(t) != num(p) or mapped_node<GT>(t) != p)
163 return {-1};
164 }
165 std::vector<int> r;
166 for (auto it = tree.get_arc_it(); it.has_curr(); it.next_ne())
167 {
168 auto * ta = it.get_curr();
169 auto * ga = mapped_arc<GT>(ta);
170 if (ga == nullptr or num(ga) != num(ta) or mapped_arc<GT>(ga) != ta)
171 return {-1};
172 r.push_back(num(ga));
173 }
174 return r;
175 }
176
179 template <class GT>
180 void check_spanning_trees(const Spec & s, unsigned long hidden, bool every_start,
181 Check & kruskal, Check & kruskal_paint, Check & prim,
182 Check & prim_paint)
183 {
184 using Dist = Weight_Of<GT, long long>;
185 using Filter = Hide_Mask<GT>;
186 Built<GT> b(s);
187 Dist d;
188 d.weights = &s.w;
189 const std::string hiding = hidden == 0 ? "" : "hiding " + std::to_string(hidden) + ": ";
190
191 kruskal.run();
192 {
193 GT tree;
194 Kruskal_Min_Spanning_Tree<GT, Dist, Filter>(d, Filter{hidden})(b.g, tree);
195 if (auto e = forest_error(s, tree_arcs(b.g, tree), hidden); not e.empty())
196 kruskal.fail(s, hiding + e);
197 }
198
199 kruskal_paint.run();
200 {
201 Kruskal_Min_Spanning_Tree<GT, Dist, Filter>(d, Filter{hidden})(b.g);
202 if (auto e = forest_error(s, painted_arcs(b.g), hidden); not e.empty())
203 kruskal_paint.fail(s, hiding + e);
204 }
205
206 std::vector<int> starts;
207 for (int x = 0; x < s.n; ++x)
208 if (every_start or x == 0 or x == s.n - 1)
209 starts.push_back(x);
210 for (int start : starts)
211 {
212 const std::string from = hiding + "from " + std::to_string(start) + ": ";
213 prim.run();
214 {
215 GT tree;
217 (b.g, b.nodes[size_t(start)], tree);
218 if (auto e = forest_error(s, tree_arcs(b.g, tree), hidden, start); not e.empty())
219 prim.fail(s, from + e);
220 }
221
222 prim_paint.run();
223 {
224 Prim_Min_Spanning_Tree<GT, Dist, Filter>(d, Filter{hidden})(b.g, b.nodes[size_t(start)]);
225 if (auto e = forest_error(s, painted_arcs(b.g), hidden, start); not e.empty())
226 prim_paint.fail(s, from + e);
227 }
228 }
229 }
230}
231
232template <class GT>
233class ExhaustiveTrees : public ::testing::Test {};
234
236
237TYPED_TEST(ExhaustiveTrees, SpanningTreesAreMinimumForEveryWeighting)
238{
239 using GT = TypeParam;
240 Check kruskal("Kruskal_Min_Spanning_Tree, the tree");
241 Check kruskal_paint("Kruskal_Min_Spanning_Tree, the painting");
242 Check prim("Prim_Min_Spanning_Tree, the tree");
243 Check prim_paint("Prim_Min_Spanning_Tree, the painting");
244
245 for_each_spec(domain(3, 3), false, [&] (const Spec & spec)
246 {
247 for_each_weighting(spec, -1, 1, [&] (const Spec & s)
248 {
249 check_spanning_trees<GT>(s, 0, true, kruskal, kruskal_paint, prim, prim_paint);
250 });
251 });
252
253 kruskal.expect();
254 kruskal_paint.expect();
255 prim.expect();
256 prim_paint.expect();
257}
258
259TYPED_TEST(ExhaustiveTrees, SpanningTreesRespectTheFilter)
260{
261 using GT = TypeParam;
262 Check kruskal("Kruskal_Min_Spanning_Tree, the tree");
263 Check kruskal_paint("Kruskal_Min_Spanning_Tree, the painting");
264 Check prim("Prim_Min_Spanning_Tree, the tree");
265 Check prim_paint("Prim_Min_Spanning_Tree, the painting");
266
267 for_each_spec(domain(4, 3), false, [&] (const Spec & spec)
268 {
269 // Distinct weights, against the order of the arcs
270 Spec s = spec;
271 s.w.clear();
272 for (size_t i = 0; i < s.arcs.size(); ++i)
273 s.w.push_back(static_cast<long long>(s.arcs.size() - i));
274 for (unsigned long hidden = 1; hidden < (1UL << s.num_arcs()); ++hidden)
275 check_spanning_trees<GT>(s, hidden, false, kruskal, kruskal_paint, prim, prim_paint);
276 });
277
278 kruskal.expect();
279 kruskal_paint.expect();
280 prim.expect();
281 prim_paint.expect();
282}
283
284TYPED_TEST(ExhaustiveTrees, SpanningTreesAreMinimumOnRandomGraphs)
285{
286 using GT = TypeParam;
287 Check kruskal("Kruskal_Min_Spanning_Tree, the tree");
288 Check kruskal_paint("Kruskal_Min_Spanning_Tree, the painting");
289 Check prim("Prim_Min_Spanning_Tree, the tree");
290 Check prim_paint("Prim_Min_Spanning_Tree, the painting");
291
292 std::mt19937 rng(seed(732));
293 const int graphs = heavy() ? 3000 : 300;
294 for (int k = 0; k < graphs; ++k)
295 {
296 const int n = 5 + int(rng() % 4);
297 const int m = n - 2 + int(rng() % unsigned(n + 2));
298 Spec s = random_spec(rng, n, m, false);
299 random_weights(rng, s, -3, 5);
300 check_spanning_trees<GT>(s, 0, true, kruskal, kruskal_paint, prim, prim_paint);
301 }
302
303 kruskal.expect();
304 kruskal_paint.expect();
305 prim.expect();
306 prim_paint.expect();
307}
308
309template <class GT>
310class ExhaustiveTreesOnDigraphs : public ::testing::Test {};
311
313
314TYPED_TEST(ExhaustiveTreesOnDigraphs, SpanningTreesRejectADigraph)
315{
316 using GT = TypeParam;
317 GT g, tree;
318 auto * p = g.insert_node(0);
319 auto * q = g.insert_node(1);
320 g.insert_arc(p, q, 0);
321 EXPECT_THROW(Kruskal_Min_Spanning_Tree<GT>()(g, tree), std::domain_error);
322 EXPECT_THROW(Kruskal_Min_Spanning_Tree<GT>()(g), std::domain_error);
323 EXPECT_THROW(Prim_Min_Spanning_Tree<GT>()(g, p, tree), std::domain_error);
324}
325
326namespace
327{
328 template <class GT>
329 struct Copy_Key
330 {
331 void operator () (typename GT::Node * p, Tree_Node<int> * t) const
332 {
333 t->get_key() = p->get_info();
334 }
335 };
336
341 std::string tree_node_error(const Spec & s, Tree_Node<int> * troot, int root,
342 unsigned long hidden)
343 {
344 std::vector<int> orig;
345 const Spec shown = oracle::without(s, hidden, orig);
346 const auto comp = oracle::component_of(shown);
347 std::multiset<std::pair<int, int>> joined;
348 for (const auto & a : shown.arcs)
349 joined.insert({std::min(a[0], a[1]), std::max(a[0], a[1])});
350
351 std::set<int> seen;
352 std::vector<Tree_Node<int> *> todo = {troot};
353 if (troot->get_key() != root)
354 return "the root is " + std::to_string(troot->get_key());
355 while (not todo.empty())
356 {
357 Tree_Node<int> * t = todo.back();
358 todo.pop_back();
359 const int x = t->get_key();
360 if (x < 0 or x >= s.n or not seen.insert(x).second
361 or comp[size_t(x)] != comp[size_t(root)])
362 return "the node " + std::to_string(x) + " is twice or out of the component";
363 for (auto * c = t->get_left_child(); c != nullptr; c = c->get_right_sibling())
364 {
365 const auto it = joined.find({std::min(x, c->get_key()), std::max(x, c->get_key())});
366 if (it == joined.end())
367 return "no shown arc joins " + std::to_string(x) + " and "
368 + std::to_string(c->get_key());
369 joined.erase(it);
370 todo.push_back(c);
371 }
372 }
373 const auto size = std::count(comp.begin(), comp.end(), comp[size_t(root)]);
374 if (std::ptrdiff_t(seen.size()) != size)
375 return std::to_string(seen.size()) + " nodes, not " + std::to_string(size);
376 return "";
377 }
378}
379
380TYPED_TEST(ExhaustiveTrees, TreesFromGraphsMatchTheirComponents)
381{
382 using GT = TypeParam;
383 using Filter = Hide_Mask<GT>;
384 Check function("graph_to_tree_node()");
385 Check functor("Graph_To_Tree_Node");
386 Check hides_cycle("Graph_To_Tree_Node, a filter that hides a cycle");
387
388 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
389 {
390 Built<GT> b(s);
391 const bool cyclic = oracle::has_cycle(s);
392 for (int root = 0; root < s.n; ++root)
393 {
394 const std::string from = "from " + std::to_string(root) + ": ";
395 function.run();
396 try
397 {
399 = graph_to_tree_node<GT, int, Copy_Key<GT>>(b.g, b.nodes[size_t(root)]);
400 if (cyclic)
401 function.fail(s, from + "converts a graph with a cycle");
402 else if (auto e = tree_node_error(s, t, root, 0); not e.empty())
403 function.fail(s, from + e);
404 destroy_tree(t);
405 }
406 catch (const std::domain_error &)
407 {
408 if (not cyclic)
409 function.fail(s, from + "rejects a forest");
410 }
411
412 for (unsigned long hidden = 0; hidden < (1UL << s.num_arcs()); ++hidden)
413 {
414 std::vector<int> orig;
415 const bool shown_cyclic = oracle::has_cycle(oracle::without(s, hidden, orig));
416 Check & check = cyclic and not shown_cyclic ? hides_cycle : functor;
417 check.run();
418 const std::string at = from + "hiding " + std::to_string(hidden) + ": ";
419 try
420 {
422 (Filter{hidden})(b.g, b.nodes[size_t(root)]);
423 if (shown_cyclic)
424 check.fail(s, at + "converts a graph with a cycle");
425 else if (auto e = tree_node_error(s, t, root, hidden); not e.empty())
426 check.fail(s, at + e);
427 destroy_tree(t);
428 }
429 catch (const std::domain_error &)
430 {
431 if (not shown_cyclic)
432 check.fail(s, at + "rejects a forest");
433 }
434 }
435 }
436 });
437
438 function.expect();
439 functor.expect();
440 hides_cycle.expect();
441}
442
443namespace
444{
452 std::string df_low_error(const Spec & s, Df_Low_Tree_Node * root,
453 const DynList<Df_Low_Non_Tree_Arc> & non_tree,
454 int src, unsigned long hidden)
455 {
456 std::vector<int> orig;
457 const Spec shown = oracle::without(s, hidden, orig);
458 const auto comp = oracle::component_of(shown);
459 std::multiset<std::pair<int, int>> joined;
460 for (const auto & a : shown.arcs)
461 if (a[0] != a[1] and comp[size_t(a[0])] == comp[size_t(src)])
462 joined.insert({std::min(a[0], a[1]), std::max(a[0], a[1])});
463
464 // The preorder, the parents and the df of each node
465 std::map<Df_Low_Tree_Node *, Df_Low_Tree_Node *> parent;
466 std::vector<Df_Low_Tree_Node *> preorder;
467 std::vector<Df_Low_Tree_Node *> todo = {root};
468 parent[root] = nullptr;
469 while (not todo.empty())
470 {
471 auto * t = todo.back();
472 todo.pop_back();
473 preorder.push_back(t);
474 std::vector<Df_Low_Tree_Node *> children;
475 for (auto * c = t->get_left_child(); c != nullptr; c = c->get_right_sibling())
476 {
477 children.push_back(c);
478 parent[c] = t;
479 }
480 for (auto it = children.rbegin(); it != children.rend(); ++it)
481 todo.push_back(*it);
482 }
483
484 std::set<int> seen;
485 for (size_t i = 0; i < preorder.size(); ++i)
486 {
487 const Df_Low_Key & k = preorder[i]->get_key();
488 const int x = std::stoi(k.label);
489 if (x < 0 or x >= s.n or not seen.insert(x).second or comp[size_t(x)] != comp[size_t(src)])
490 return "the node " + k.label + " is twice or out of the component";
491 if (k.df != long(i))
492 return "the df of " + k.label + " is " + std::to_string(k.df) + ", not "
493 + std::to_string(i);
494 if (auto * p = parent[preorder[i]]; p != nullptr)
495 {
496 const int y = std::stoi(p->get_key().label);
497 const auto it = joined.find({std::min(x, y), std::max(x, y)});
498 if (it == joined.end())
499 return "no arc joins " + k.label + " and its parent " + p->get_key().label;
500 joined.erase(it);
501 }
502 }
503 if (std::ptrdiff_t(seen.size()) != std::count(comp.begin(), comp.end(), comp[size_t(src)])
504 or std::stoi(root->get_key().label) != src)
505 return "the tree does not span the component";
506
507 // The arcs out of the tree go from a descendant to an ancestor, and
508 // they are the arcs left
509 std::map<Df_Low_Tree_Node *, long> reach;
510 for (auto it = non_tree.get_it(); it.has_curr(); it.next_ne())
511 {
512 auto [d, a] = it.get_curr();
513 bool ancestor = false;
514 for (auto * p = parent[d]; p != nullptr and not ancestor; p = parent[p])
515 ancestor = p == a;
516 const int x = std::stoi(d->get_key().label), y = std::stoi(a->get_key().label);
517 const auto j = joined.find({std::min(x, y), std::max(x, y)});
518 if (not ancestor or j == joined.end())
519 return "the arc out of the tree " + std::to_string(x) + "-" + std::to_string(y)
520 + " is not from a descendant to an ancestor, or is not left";
521 joined.erase(j);
522 reach[d] = reach.count(d) ? std::min(reach[d], a->get_key().df) : a->get_key().df;
523 }
524 if (not joined.empty())
525 return "an arc out of the tree is missing";
526
527 // low, from the leaves up
528 std::map<Df_Low_Tree_Node *, long> low;
529 for (auto it = preorder.rbegin(); it != preorder.rend(); ++it)
530 {
531 auto * t = *it;
532 long l = t->get_key().df;
533 if (reach.count(t))
534 l = std::min(l, reach[t]);
535 for (auto * c = t->get_left_child(); c != nullptr; c = c->get_right_sibling())
536 l = std::min(l, low[c]);
537 low[t] = l;
538 const long want = t == root ? -1 : l;
539 if (t->get_key().low != want)
540 return "the low of " + t->get_key().label + " is " + std::to_string(t->get_key().low)
541 + ", not " + std::to_string(want);
542 }
543 return "";
544 }
545}
546
547TYPED_TEST(ExhaustiveTrees, DepthFirstTreesHaveTheirNumbers)
548{
549 using GT = TypeParam;
550 using Filter = Hide_Mask<GT>;
551 Check df_low("build_df_low_tree()");
552
553 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
554 {
555 Built<GT> b(s);
556 for (unsigned long hidden = 0; hidden < (1UL << s.num_arcs()); ++hidden)
557 for (int src = 0; src < s.n; ++src)
558 {
559 df_low.run();
562 = build_df_low_tree(b.g, b.nodes[size_t(src)], non_tree,
563 Dft_Df_Tree_Label<GT>(), Filter{hidden});
564 if (auto e = df_low_error(s, root, non_tree, src, hidden); not e.empty())
565 df_low.fail(s, "from " + std::to_string(src) + " hiding " + std::to_string(hidden)
566 + ": " + e);
568 }
569 });
570
571 df_low.expect();
572}
Kruskal's minimum spanning tree algorithm.
Prim's algorithm for minimum spanning trees.
size_t size() const noexcept
Return the current dimension of array.
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
Functor class to convert a tree graph to Tree_Node structure.
Computes the minimum spanning tree of a graph using Kruskal's algorithm.
Definition Kruskal.H:94
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:535
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:618
Computes the minimum spanning tree of a graph using Prim's algorithm.
Definition Prim.H:223
Forward declaration used by CRTP helpers before the full node definition.
Tree_Node * get_left_child() const noexcept
Returns the leftmost child of this.
Tree_Node * get_right_sibling() const noexcept
Returns the right sibling of this.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
Definition graph-dry.H:753
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Definition graph-dry.H:975
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Definition graph-dry.H:3144
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Definition graph-dry.H:3122
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:663
The failures of one property over a domain.
void expect() const
Expects what the mark says, and prints the first failures.
void fail(const Spec &s, const std::string &what)
Counts a failure on spec, with what went wrong.
void run() noexcept
Counts a run of the property.
static mt19937 rng
Pictures of depth-first trees with their df and low numbers.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Definition gmpfrxx.h:4138
TYPED_TEST_SUITE(ExhaustiveTrees, Undirected_Kinds)
TYPED_TEST(ExhaustiveTrees, SpanningTreesAreMinimumForEveryWeighting)
The kinds of arc filter and of distance that the graph algorithms must accept.
Every small multigraph, on every kind of graph, for the tests.
Answers computed from a Spec of graph_harness.H, without Aleph.
Convert spanning tree graphs to Tree_Node structures.
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
DynArray< Graph::Arc * > arcs
Definition graphpic.C:408
Df_Low_Tree_Node * build_df_low_tree(const GT &g, typename GT::Node *src, DynList< Df_Low_Non_Tree_Arc > &non_tree_arcs, Node_Label node_label=Node_Label(), SA sa=SA())
Build the depth-first spanning tree of an undirected graph, with the df and low numbers of its nodes.
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
@ Spanning_Tree
Definition aleph-graph.H:79
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
static mpfr_t y
Definition mpfr_mul_d.c:3
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
static long & low(typename GT::Node *p)
Internal helper: low-link value stored directly in NODE_COOKIE(p).
and
Check uniqueness with explicit hash + equality functors.
static long & df(typename GT::Node *p)
Internal helper: DFS discovery time stored in NODE_COUNTER(p).
constexpr bool shown(unsigned long hidden, int i) noexcept
Whether the arc number i is shown by the mask hidden.
::testing::Types< Aleph::List_Digraph< Aleph::Graph_Node< int >, Aleph::Graph_Arc< int > >, Aleph::List_SDigraph< Aleph::Graph_Snode< int >, Aleph::Graph_Sarc< int > >, Aleph::Array_Digraph< Aleph::Graph_Anode< int >, Aleph::Graph_Aarc< int > > > Directed_Kinds
The directed kinds, with int infos.
::testing::Types< Aleph::List_Graph< Aleph::Graph_Node< int >, Aleph::Graph_Arc< int > >, Aleph::List_SGraph< Aleph::Graph_Snode< int >, Aleph::Graph_Sarc< int > >, Aleph::Array_Graph< Aleph::Graph_Anode< int >, Aleph::Graph_Aarc< int > > > Undirected_Kinds
The kinds of graph that are not directed, with int infos.
size_t for_each_spec(const Domain &d, bool directed, F &&f)
Calls f(spec) with every spec of d, smallest first, and returns how many there were.
Spec random_spec(std::mt19937 &rng, int n, int m, bool directed, bool loops=true, bool parallel=true)
A random spec of n nodes and m arcs, with loops and parallel arcs if asked; parallel is ignored when ...
int num(Node *p)
The number of a node of a built graph.
Domain domain(int max_nodes, int max_arcs)
The domain of max_nodes nodes and max_arcs arcs, of one more of each in heavy mode,...
bool heavy()
Whether the mode is heavy, which asks for the larger domains.
void random_weights(std::mt19937 &rng, Spec &s, long long lo, long long hi)
Gives each arc of s a weight from lo to hi.
bool has_cycle(const Spec &s)
Whether the multigraph, not directed, has a cycle.
long long min_spanning_forest_weight(const Spec &s)
The weight of a minimum spanning forest: Kruskal on the list of arcs.
std::vector< int > component_of(const Spec &s, int skip_node=-1, int skip_arc=-1)
The number of the component of each node, as that of its root, of the graph without the node skip_nod...
int components(const Spec &s, int skip_node=-1, int skip_arc=-1)
The number of components, without the node skip_node and the arc skip_arc.
Spec without(const Spec &s, unsigned long hidden, std::vector< int > &orig)
The spec without the arcs whose numbers are set in hidden, with orig[i] the number in s of its i-th a...
Key of a node of a depth-first tree with df and low numbers.
Default label of a graph node: its information, written with operator <<.
Hides the arcs of a mask; copyable, assignable, noexcept.
The weight of an arc, read by its number from a vector.
A graph made from a spec, with its nodes and arcs by number.
std::vector< typename GT::Node * > nodes
A small multigraph: its nodes are 0 .
std::vector< long long > w
size_t num_arcs() const noexcept
std::vector< std::array< int, 2 > > arcs
Union-find over the nodes 0 .. n - 1.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
bool check(GT &g)
DynArray< int > preorder
ValueArg< size_t > seed
Definition testHash.C:53
static int * k
Gsl_Compatible_Rng r
Generic graph and digraph implementations.
DynList< int > l