Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
graph_exhaustive_robustness_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
52#include <gtest/gtest.h>
53
54#include "allocation_failure.H"
55
56#include <algorithm>
57#include <cstdlib>
58#include <functional>
59#include <iostream>
60#include <memory>
61#include <new>
62#include <set>
63#include <stdexcept>
64#include <string>
65#include <utility>
66#include <vector>
67
68#include <tpl_graph.H>
69#include <tpl_components.H>
70#include <tpl_graph_utils.H>
71#include <tpl_cut_nodes.H>
72#include <tpl_test_acyclique.H>
73#include <tpl_bipartite.H>
74#include <tpl_spanning_tree.H>
75#include <tpl_find_path.H>
76#include <tpl_test_path.H>
77#include <Blossom.H>
78#include <eulerian.H>
79#include <Tarjan.H>
80#include <kosaraju.H>
81#include <topological_sort.H>
82#include <Bidirectional_BFS.H>
83#include <warshall.H>
84#include <Dominators.H>
85#include <Kruskal.H>
86#include <Prim.H>
87#include <graph_to_tree.H>
88#include <generate_df_tree.H>
89
91#include "graph_harness.H"
92
93using namespace Aleph;
94using namespace graph_harness;
95
96namespace
97{
100 std::vector<Spec> sweep_specs(bool digraph)
101 {
102 Spec a;
103 a.n = 5;
104 a.arcs = {{0, 1}, {1, 2}, {2, 0}, {2, 3}, {3, 3}, {1, 2}};
105 Spec b;
106 b.n = 6;
107 b.arcs = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}};
108 Spec c;
109 c.n = 4;
110 c.arcs = digraph ? std::vector<std::array<int, 2>>{{0, 1}, {1, 0}, {1, 2}, {2, 3}, {3, 1}}
111 : std::vector<std::array<int, 2>>{{0, 1}, {2, 3}, {3, 2}};
112 for (Spec * s : {&a, &b, &c})
113 for (size_t i = 0; i < s->arcs.size(); ++i)
114 s->w.push_back(static_cast<long long>(s->arcs.size() - i));
115 return {a, b, c};
116 }
117
118 std::string text(std::vector<int> v, bool sorted = true)
119 {
120 if (sorted)
121 std::sort(v.begin(), v.end());
122 std::string r = "(";
123 for (size_t i = 0; i < v.size(); ++i)
124 r += (i == 0 ? "" : " ") + std::to_string(v[i]);
125 return r + ")";
126 }
127
128 template <class List>
129 std::vector<int> numbers(const List & l)
130 {
131 std::vector<int> r;
132 for (auto it = l.get_it(); it.has_curr(); it.next_ne())
133 r.push_back(num(it.get_curr()));
134 return r;
135 }
136
138 template <class Lists>
139 std::string text_of_lists(const Lists & lists)
140 {
141 std::vector<std::string> r;
142 for (auto it = lists.get_it(); it.has_curr(); it.next_ne())
143 r.push_back(text(numbers(it.get_curr())));
144 std::sort(r.begin(), r.end());
145 std::string t;
146 for (const auto & x : r)
147 t += x;
148 return t;
149 }
150
151 template <class GT>
152 std::string text_of_graphs(const DynList<GT> & graphs)
153 {
154 std::vector<std::string> r;
155 for (auto it = graphs.get_it(); it.has_curr(); it.next_ne())
156 {
157 std::vector<int> nodes, arcs;
158 for (auto j = it.get_curr().get_node_it(); j.has_curr(); j.next_ne())
159 nodes.push_back(num(j.get_curr()));
160 for (auto j = it.get_curr().get_arc_it(); j.has_curr(); j.next_ne())
161 arcs.push_back(num(j.get_curr()));
162 r.push_back(text(nodes) + text(arcs));
163 }
164 std::sort(r.begin(), r.end());
165 std::string t;
166 for (const auto & x : r)
167 t += x;
168 return t;
169 }
170
171 template <class GT>
172 std::string text_of_path(const Path<GT> & p)
173 {
174 std::string r;
175 for (typename Path<GT>::Iterator it(p); it.has_current_node(); it.next_ne())
176 {
177 r += std::to_string(num(it.get_current_node_ne()));
178 if (it.has_current_arc())
179 r += "-" + std::to_string(num(it.get_current_arc_ne())) + "-";
180 }
181 return r;
182 }
183
186 template <class GT>
187 std::string closed_walk_text(const Path<GT> & p, const Spec & s)
188 {
189 if (p.is_empty())
190 return "none";
191 std::vector<int> nodes, arcs;
192 for (typename Path<GT>::Iterator it(p); it.has_current_node(); it.next_ne())
193 {
194 nodes.push_back(num(it.get_current_node_ne()));
195 if (it.has_current_arc())
196 arcs.push_back(num(it.get_current_arc_ne()));
197 }
198 bool ok = not arcs.empty() and nodes.front() == nodes.back()
199 and nodes.size() == arcs.size() + 1;
200 for (size_t i = 0; ok and i < arcs.size(); ++i)
201 ok = s.arcs[size_t(arcs[i])][0] == nodes[i] and s.arcs[size_t(arcs[i])][1] == nodes[i + 1];
202 return ok ? "cycle" : "not a cycle: " + text_of_path(p);
203 }
204
206 template <class GT>
207 std::string text_of_tree(const GT & tree)
208 {
209 std::vector<int> nodes, arcs;
210 for (auto it = tree.get_node_it(); it.has_curr(); it.next_ne())
211 nodes.push_back(num(it.get_curr()));
212 for (auto it = tree.get_arc_it(); it.has_curr(); it.next_ne())
213 arcs.push_back(num(it.get_curr()));
214 return text(nodes) + text(arcs);
215 }
216
218 template <class GT>
219 std::string painted(const GT & g, unsigned b)
220 {
221 std::vector<int> arcs;
222 for (auto it = g.get_arc_it(); it.has_curr(); it.next_ne())
223 if (ARC_BITS(it.get_curr()).get_bit(b))
224 arcs.push_back(num(it.get_curr()));
225 return text(arcs);
226 }
227
228 std::string text_of_df_tree(Df_Low_Tree_Node * t)
229 {
230 const auto & k = t->get_key();
231 std::string r = k.label + "," + std::to_string(k.df) + "," + std::to_string(k.low) + "[";
232 for (auto * c = t->get_left_child(); c != nullptr; c = c->get_right_sibling())
233 r += text_of_df_tree(c);
234 return r + "]";
235 }
236
237 template <class GT>
238 struct Copy_Key
239 {
240 void operator () (typename GT::Node * p, Tree_Node<int> * t) const
241 {
242 t->get_key() = p->get_info();
243 }
244 };
245
247 template <class GT>
248 struct Algorithm
249 {
250 std::string name;
251 std::function<std::string (Built<GT> &, const Spec &)> run;
252 };
253
255 template <class GT>
256 std::vector<Algorithm<GT>> algorithms()
257 {
258 using Node = typename GT::Node;
259 using Arc = typename GT::Arc;
261 std::vector<Algorithm<GT>> r;
262 auto add = [&r] (std::string name, auto f) { r.push_back({std::move(name), f}); };
263
264
265
266 if (not GT().is_digraph())
267 {
268 add("Unconnected_Components, lists", [] (Built<GT> & b, const Spec &)
269 {
272 return text_of_lists(l);
273 });
274 add("Unconnected_Components, graphs", [] (Built<GT> & b, const Spec &)
275 {
278 return text_of_graphs(l);
279 });
280 add("compute_cut_nodes()", [] (Built<GT> & b, const Spec &)
281 {
282 return text(numbers(compute_cut_nodes(b.g, b.nodes[0])));
283 });
284 add("find_bridges()", [] (Built<GT> & b, const Spec &)
285 {
286 return text(numbers(find_bridges(b.g, b.nodes[0])));
287 });
288 add("is_graph_acyclique()", [] (Built<GT> & b, const Spec &)
289 {
290 return std::string(is_graph_acyclique(b.g) ? "acyclic" : "cyclic");
291 });
292 add("test_for_cycle()", [] (Built<GT> & b, const Spec &)
293 {
294 return std::string(test_for_cycle(b.g, b.nodes[0]) ? "cycle" : "none");
295 });
296 add("compute_bipartite()", [] (Built<GT> & b, const Spec &)
297 {
298 try
299 {
301 compute_bipartite(b.g, l, rr);
302 return text(numbers(l)) + text(numbers(rr));
303 }
304 catch (const std::domain_error &)
305 {
306 return std::string("not bipartite");
307 }
308 });
309 add("blossom_maximum_cardinality_matching()", [] (Built<GT> & b, const Spec &)
310 {
313 return text(numbers(m));
314 });
315 add("Find_Depth_First_Spanning_Tree", [] (Built<GT> & b, const Spec &)
316 {
317 GT tree;
319 return text_of_tree(tree);
320 });
321 add("Find_Breadth_First_Spanning_Tree", [] (Built<GT> & b, const Spec &)
322 {
323 GT tree;
325 return text_of_tree(tree);
326 });
327 add("Kruskal_Min_Spanning_Tree", [] (Built<GT> & b, const Spec & s)
328 {
329 Dist d;
330 d.weights = &s.w;
331 GT tree;
333 kruskal(b.g, tree);
334 return text_of_tree(tree);
335 });
336 add("Kruskal_Min_Spanning_Tree, painted", [] (Built<GT> & b, const Spec & s)
337 {
338 Dist d;
339 d.weights = &s.w;
341 kruskal(b.g);
342 return painted(b.g, Aleph::Spanning_Tree);
343 });
344 add("Prim_Min_Spanning_Tree", [] (Built<GT> & b, const Spec & s)
345 {
346 Dist d;
347 d.weights = &s.w;
348 GT tree;
350 prim(b.g, b.nodes[0], tree);
351 return text_of_tree(tree);
352 });
353 add("Prim_Min_Spanning_Tree, painted", [] (Built<GT> & b, const Spec & s)
354 {
355 Dist d;
356 d.weights = &s.w;
358 prim(b.g, b.nodes[0]);
359 return painted(b.g, Aleph::Spanning_Tree);
360 });
361 add("build_df_low_tree()", [] (Built<GT> & b, const Spec &)
362 {
364 // freed if writing the answer runs out of memory
365 const std::unique_ptr<Df_Low_Tree_Node, void (*)(Df_Low_Tree_Node *)>
366 t(build_df_low_tree(b.g, b.nodes[0], non_tree),
367 [] (Df_Low_Tree_Node * p) { destroy_tree(p); });
368 return text_of_df_tree(t.get()) + std::to_string(non_tree.size());
369 });
370 add("Find_Eulerian_Path", [] (Built<GT> & b, const Spec &)
371 {
372 const auto res = Find_Eulerian_Path<GT>()(b.g);
373 return text(numbers(res.path), false);
374 });
375 add("Bidirectional_BFS", [] (Built<GT> & b, const Spec & s)
376 {
377 return text_of_path(Bidirectional_BFS<GT>()(b.g, b.nodes[0], b.nodes[size_t(s.n - 1)]));
378 });
379 }
380 else
381 {
382 add("Tarjan_Connected_Components, lists", [] (Built<GT> & b, const Spec &)
383 {
386 return text_of_lists(l);
387 });
388 add("Tarjan_Connected_Components, blocks", [] (Built<GT> & b, const Spec &)
389 {
390 DynList<GT> blk;
393 return text_of_graphs(blk) + text(numbers(arcs));
394 });
395 // The cycle goes through a block whose nodes are new, so that in
396 // List_SDigraph, which keeps its nodes by address, it may be
397 // another one in each run: the answer is whether it is one
398 add("Tarjan_Connected_Components::compute_cycle()", [] (Built<GT> & b, const Spec & s)
399 {
400 Path<GT> p(b.g);
402 return closed_walk_text(p, s);
403 });
404 add("kosaraju_connected_components(), lists", [] (Built<GT> & b, const Spec &)
405 {
406 return text_of_lists(kosaraju_connected_components(b.g));
407 });
408 add("kosaraju_connected_components(), blocks", [] (Built<GT> & b, const Spec &)
409 {
410 DynList<GT> blk;
413 return text_of_graphs(blk) + text(numbers(arcs));
414 });
415 add("Q_Topological_Sort::ranks()", [] (Built<GT> & b, const Spec &)
416 {
417 const auto ranks = Q_Topological_Sort<GT>().ranks(b.g);
418 std::string r;
419 for (auto it = ranks.get_it(); it.has_curr(); it.next_ne())
420 r += text(numbers(it.get_curr()));
421 return r;
422 });
423 add("compute_dominators()", [] (Built<GT> & b, const Spec &)
424 {
425 std::vector<int> idoms;
426 const auto l = compute_dominators(b.g, b.nodes[0]);
427 for (auto it = l.get_it(); it.has_curr(); it.next_ne())
428 idoms.push_back(num(it.get_curr().first) * 100
429 + (it.get_curr().second ? num(it.get_curr().second) : 99));
430 return text(idoms);
431 });
432 add("build_dominator_tree()", [] (Built<GT> & b, const Spec &)
433 {
434 GT tree;
435 build_dominator_tree(b.g, b.nodes[0], tree);
436 return std::to_string(tree.get_num_nodes()) + "," + std::to_string(tree.get_num_arcs());
437 });
438 add("compute_post_dominators()", [] (Built<GT> & b, const Spec & s)
439 {
440 std::vector<int> idoms;
441 const auto l = compute_post_dominators(b.g, b.nodes[size_t(s.n - 1)]);
442 for (auto it = l.get_it(); it.has_curr(); it.next_ne())
443 idoms.push_back(num(it.get_curr().first) * 100
444 + (it.get_curr().second ? num(it.get_curr().second) : 99));
445 return text(idoms);
446 });
447 add("warshall_compute_transitive_clausure()", [] (Built<GT> & b, const Spec & s)
448 {
451 std::string r;
452 for (int u = 0; u < s.n; ++u)
453 for (int v = 0; v < s.n; ++v)
454 r += char('0' + int(mat(b.nodes[size_t(u)], b.nodes[size_t(v)])));
455 return r;
456 });
457 }
458
459 // On both
460 add("Find_Path_Depth_First", [] (Built<GT> & b, const Spec & s)
461 {
462 Path<GT> p(b.g);
463 (void) Find_Path_Depth_First<GT>()(b.g, b.nodes[0], b.nodes[size_t(s.n - 1)], p);
464 return text_of_path(p);
465 });
466 add("Find_Path_Breadth_First", [] (Built<GT> & b, const Spec & s)
467 {
468 Path<GT> p(b.g);
469 (void) Find_Path_Breadth_First<GT>()(b.g, b.nodes[0], b.nodes[size_t(s.n - 1)], p);
470 return text_of_path(p);
471 });
472 add("Test_For_Path", [] (Built<GT> & b, const Spec & s)
473 {
474 return std::string(Test_For_Path<GT>()(b.g, b.nodes[0], b.nodes[size_t(s.n - 1)])
475 ? "path" : "none");
476 });
477 add("Test_Eulerian::compute()", [] (Built<GT> & b, const Spec &)
478 {
479 return std::to_string(int(Test_Eulerian<GT>().compute(b.g)));
480 });
481 add("copy_graph() with the cookies", [] (Built<GT> & b, const Spec &)
482 {
483 GT c;
484 copy_graph(c, b.g, true);
485 return text_of_tree(c);
486 });
487 return r;
488 }
489
492 template <class GT>
493 std::string structure_error(const Built<GT> & b, const Spec & s)
494 {
495 if (b.g.get_num_nodes() != size_t(s.n) or b.g.get_num_arcs() != s.arcs.size())
496 return "the graph lost nodes or arcs";
497 for (size_t i = 0; i < s.arcs.size(); ++i)
498 if (b.g.get_src_node(b.arcs[i]) != b.nodes[size_t(s.arcs[i][0])]
499 or b.g.get_tgt_node(b.arcs[i]) != b.nodes[size_t(s.arcs[i][1])])
500 return "the arc " + std::to_string(i) + " lost its ends";
501 for (int x = 0; x < s.n; ++x)
502 {
503 size_t count = 0;
504 for (typename GT::Node_Arc_Iterator it(b.nodes[size_t(x)]); it.has_curr(); it.next_ne())
505 ++count;
506 if (count != b.g.get_num_arcs(b.nodes[size_t(x)]))
507 return "the list of the node " + std::to_string(x) + " is broken";
508 }
509 return "";
510 }
511
517 template <class GT>
518 std::string sweep(const Algorithm<GT> & algo, Built<GT> & b, const Spec & s)
519 {
520 if (std::getenv("ALEPH_GRAPH_HARNESS_TRACE") != nullptr)
521 std::cerr << algo.name << " on " << s.str() << std::endl;
522 const std::string want = algo.run(b, s);
523 for (size_t k = 1; k < 1000000; ++k)
524 {
525 std::string got;
526 bool threw = false;
527 size_t refused = 0;
528 {
529 Fail_At fail(k);
530 try
531 {
532 got = algo.run(b, s);
533 }
534 catch (const std::bad_alloc &)
535 {
536 threw = true;
537 }
538 refused = refused_allocations;
539 }
540 if (auto e = structure_error(b, s); not e.empty())
541 return "at the allocation " + std::to_string(k) + ": " + e;
542 if (threw)
543 {
544 if (const auto again = algo.run(b, s); again != want)
545 return "after a failure at the allocation " + std::to_string(k)
546 + ", it gives " + again + ", not " + want;
547 continue;
548 }
549 // std::stable_sort and the streams of the error messages take
550 // memory without throwing, and do without it
551 if (got != want)
552 return (refused > 0 ? "it caught the failure of the allocation " + std::to_string(k)
553 + " and went on, and gives " : "it gives ") + got + ", not " + want;
554 if (refused == 0)
555 return ""; // it did not reach the allocation k
556 }
557 return "it never ends";
558 }
559}
560
561template <class GT>
562class GraphFailAt : public ::testing::Test
563{
564protected:
565 void SetUp() override
566 {
568 GTEST_SKIP() << "ThreadSanitizer replaces the global operator new";
569 }
570};
571
573
574TYPED_TEST(GraphFailAt, EveryAllocationOfEveryAlgorithmMayFail)
575{
576 using GT = TypeParam;
577 const auto algos = algorithms<GT>();
578 std::vector<Check> checks;
579 for (const auto & a : algos)
580 checks.emplace_back(a.name);
581
582 for (const Spec & s : sweep_specs(GT().is_digraph()))
583 for (size_t i = 0; i < algos.size(); ++i)
584 {
585 checks[i].run();
586 Built<GT> b(s);
587 if (auto e = sweep(algos[i], b, s); not e.empty())
588 checks[i].fail(s, e);
589 }
590
591 for (const auto & c : checks)
592 c.expect();
593}
594
595namespace
596{
598 alignas(64) unsigned char left_over[4096] = {};
599
602 template <class GT>
603 void dirty(const GT & g)
604 {
605 auto soil = [] (auto * x)
606 {
607 for (int bit = 0; bit < Num_Bits_Graph; ++bit)
608 x->attrs.control_bits.set_bit(bit, 1);
609 x->attrs.counter = 1000003;
610 x->attrs.cookie = left_over;
611 };
612 for (auto it = g.get_node_it(); it.has_curr(); it.next_ne())
613 soil(it.get_curr());
614 for (auto it = g.get_arc_it(); it.has_curr(); it.next_ne())
615 soil(it.get_curr());
616 }
617}
618
619template <class GT>
620class GraphDirtyState : public ::testing::Test {};
621
623
624TYPED_TEST(GraphDirtyState, EveryAlgorithmIgnoresWhatOthersLeft)
625{
626 using GT = TypeParam;
627 const auto algos = algorithms<GT>();
628 std::vector<Check> checks;
629 for (const auto & a : algos)
630 checks.emplace_back(a.name);
631
632 for (const Spec & s : sweep_specs(GT().is_digraph()))
633 for (size_t i = 0; i < algos.size(); ++i)
634 {
635 checks[i].run();
636 Built<GT> b(s);
637 const std::string want = algos[i].run(b, s);
638 dirty(b.g);
639 ASSERT_TRUE(IS_NODE_VISITED(b.nodes[0], Aleph::Depth_First)
640 and NODE_COUNTER(b.nodes[0]) == 1000003
641 and NODE_COOKIE(b.nodes[0]) == left_over);
642 if (const std::string got = algos[i].run(b, s); got != want)
643 checks[i].fail(s, "gives " + got + ", not " + want);
644 }
645
646 for (const auto & c : checks)
647 c.expect();
648}
Bidirectional BFS for shortest unweighted path.
Edmonds' Blossom algorithm for maximum matching in general graphs.
Dominator and post-dominator tree computation via the Lengauer-Tarjan algorithm.
Kruskal's minimum spanning tree algorithm.
Prim's algorithm for minimum spanning trees.
Tarjan's algorithm for strongly connected components.
A global operator new that a test can make fail.
#define ALEPH_ALLOCATION_FAILURE_UNDER_TSAN
WeightedDigraph::Node Node
WeightedDigraph::Arc Arc
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Bidirectional BFS for finding shortest unweighted paths.
Bit matrix for graph connectivity.
Node belonging to a double circular linked list with header node.
Definition tpl_dnode.H:106
Dynamic doubly linked list with O(1) size and bidirectional access.
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
size_t size() const noexcept
Return the number of items of the list, in constant time.
Definition htlist.H:1264
Compute a breadth-first spanning tree of a graph.
Compute a depth-first spanning tree of a graph.
Finds and constructs an Eulerian path or cycle using Hierholzer's algorithm.
Definition eulerian.H:477
Performs a breadth-first search for a path between a pair of nodes.
Performs a depth-first search for a path between a pair of nodes.
Computes the minimum spanning tree of a graph using Kruskal's algorithm.
Definition Kruskal.H:94
Iterator on nodes and arcs of a path.
Definition tpl_graph.H:4395
bool has_current_node() const noexcept
Return true if the iterator has a current node.
Definition tpl_graph.H:4512
Path on a graph.
Definition tpl_graph.H:3832
bool is_empty() const noexcept
Return true if the path is empty.
Definition tpl_graph.H:3993
Computes the minimum spanning tree of a graph using Prim's algorithm.
Definition Prim.H:223
Computes topological ordering using breadth-first search (Kahn's algorithm).
RankList< List< typename GT::Node * > > ranks(const GT &g)
Compute rank-based topological ordering.
Computes strongly connected components (SCCs) in a directed graph using Tarjan's algorithm.
Definition Tarjan.H:174
void connected_components(const GT &g, DynList< GT > &blk_list, DynList< typename GT::Arc * > &arc_list)
Computes the strongly connected components (SCCs) of a digraph.
Definition Tarjan.H:721
bool compute_cycle(const GT &g, Path< GT > &path)
Finds and constructs a cycle in the digraph, if one exists.
Definition Tarjan.H:972
Tests whether a graph or digraph is Eulerian.
Definition eulerian.H:241
Checks whether a path exists between two nodes.
Forward declaration used by CRTP helpers before the full node definition.
Tree_Node * get_left_child() const noexcept
Returns the leftmost child of this.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
Compute the connected components of a graph.
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
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:1017
bool is_digraph() const noexcept
Return true if the graph this is directed.
Definition graph-dry.H:937
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
Definition graph-dry.H:1064
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Definition graph-dry.H:3122
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:1023
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:663
Eulerian graph detection and path/cycle finding.
Pictures of depth-first trees with their df and low numbers.
TYPED_TEST_SUITE(GraphFailAt, All_Kinds)
TYPED_TEST(GraphFailAt, EveryAllocationOfEveryAlgorithmMayFail)
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.
Convert spanning tree graphs to Tree_Node structures.
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
DynArray< Graph::Arc * > arcs
Definition graphpic.C:408
void compute_bipartite(const GT &g, DynDlist< typename GT::Node * > &l, DynDlist< typename GT::Node * > &r, SA sa=SA())
Computes the partition sets of a bipartite graph.
void kosaraju_connected_components(const GT &g, DynList< GT > &blk_list, DynList< typename GT::Arc * > &arc_list)
Compute strongly connected components using Kosaraju's algorithm.
Definition kosaraju.H:267
#define NODE_COUNTER(p)
Get the counter of a node.
bool test_for_cycle(const GT &g, typename GT::Node *src)
Search for a cycle reachable from a given node.
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_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
void build_dominator_tree(GT &g, typename GT::Node *root, GT &tree, SA sa=SA())
Build the dominator tree of a digraph.
Definition Dominators.H:678
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
DynList< typename GT::Node * > compute_cut_nodes(const GT &g, typename GT::Node *start)
Compute articulation points (cut vertices) of an undirected graph.
void warshall_compute_transitive_clausure(GT &g, Bit_Mat_Graph< GT, SA > &mat, SA sa=SA())
Computes the transitive closure of a graph using Warshall's algorithm.
Definition warshall.H:84
DynList< std::pair< typename GT::Node *, typename GT::Node * > > compute_dominators(GT &g, typename GT::Node *root, SA sa=SA())
Compute immediate dominators of a digraph from a root node.
Definition Dominators.H:657
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
DynList< std::pair< typename GT::Node *, typename GT::Node * > > compute_post_dominators(const GT &g, typename GT::Node *exit_node, SA sa=SA())
Compute immediate post-dominators of a digraph from an exit node.
DynList< typename GT::Arc * > find_bridges(const GT &g, typename GT::Node *start, SA sa=SA())
Find all bridge edges in a connected undirected graph.
bool is_graph_acyclique(const GT &g, typename GT::Node *start_node)
Return true if an undirected graph is acyclic.
void copy_graph(GT &gtgt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
Definition tpl_graph.H:4794
@ Depth_First
Definition aleph-graph.H:73
@ Num_Bits_Graph
Definition aleph-graph.H:85
@ Spanning_Tree
Definition aleph-graph.H:79
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
Kosaraju's algorithm for finding strongly connected components.
Main namespace for Aleph-w library functions.
Tree_Node< Df_Low_Key > Df_Low_Tree_Node
Node of the depth-first tree that build_df_low_tree() returns.
and
Check uniqueness with explicit hash + equality functors.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
Definition ah-date.H:140
Array< size_t > ranks(const Array< T > &array)
Computes the rank of each element in an Array.
Definition ahSort.H:696
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
double add(double a, double b)
int num(Node *p)
The number of a node of a built graph.
::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 > >, 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 > > > All_Kinds
The six kinds, with int infos.
STL namespace.
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
std::vector< typename GT::Arc * > arcs
A small multigraph: its nodes are 0 .
std::string str() const
The spec as text, ready to be written back as a test case.
std::vector< long long > w
std::vector< std::array< int, 2 > > arcs
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
static int * k
Gsl_Compatible_Rng r
Topological sorting algorithms for directed acyclic graphs (DAGs).
Bipartite graph detection and 2-coloring.
Graph connectivity and connected components.
Articulation points (cut nodes), bridges, and biconnected components.
Path finding algorithms in graphs.
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.
Spanning tree generation algorithms.
DAG (acyclic) graph testing.
Path existence testing.
DynList< int > l
Warshall's algorithm for transitive closure.