Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
blossom_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
31
46# include <gtest/gtest.h>
47
48# include <algorithm>
49# include <bit>
50# include <chrono>
51# include <cstdint>
52# include <cstdlib>
53# include <functional>
54# include <random>
55# include <string>
56# include <stdexcept>
57# include <utility>
58# include <vector>
59
60# include <Blossom.H>
61# include <tpl_array.H>
62# include <tpl_bipartite.H>
63# include <tpl_dynArray.H>
64# include <tpl_dynSetTree.H>
65# include <tpl_graph.H>
66# include <tpl_olhash.H>
67# include <tpl_sgraph.H>
68# include <tpl_agraph.H>
69
70using namespace Aleph;
71
72namespace
73{
74 template <class GT>
75 GT build_graph(size_t n,
76 const DynArray<std::pair<size_t, size_t>> & edges,
77 int arc_info = 1)
78 {
79 GT g;
80 for (size_t i = 0; i < n; ++i)
81 static_cast<void>(g.insert_node(static_cast<int>(i)));
82
85 [&](typename GT::Node * p)
86 {
87 const size_t id = static_cast<size_t>(p->get_info());
88 if (id < n)
89 nodes(id) = p;
90 });
91
92 for (size_t i = 0; i < n; ++i)
93 ah_runtime_error_if(nodes(i) == nullptr)
94 << "build_graph(): node id " << i << " not found after insertion";
95
96 for (const auto & [u, v] : edges)
97 {
98 if (u >= n or v >= n)
99 continue;
100 g.insert_arc(nodes(u), nodes(v), arc_info);
101 }
102
103 return g;
104 }
105
106 template <class GT>
107 GT build_graph(size_t n,
108 std::initializer_list<std::pair<size_t, size_t>> edges,
109 int arc_info = 1)
110 {
112 for (const auto & edge : edges)
113 aleph_edges.append(edge);
114 EXPECT_EQ(aleph_edges.size(), edges.size());
115
116 return build_graph<GT>(n, aleph_edges, arc_info);
117 }
118
119
120
121 template <class GT>
122 bool verify_matching(const GT & g, const DynDlist<typename GT::Arc *> & matching)
123 {
125 for (typename GT::Arc_Iterator it(g); it.has_curr(); it.next_ne())
126 arcs_in_graph.insert(it.get_curr());
127
129 for (auto it = matching.get_it(); it.has_curr(); it.next_ne())
130 {
131 auto * arc = it.get_curr();
132 if (arc == nullptr)
133 return false;
134
135 if (not arcs_in_graph.contains(arc))
136 return false;
137
138 auto * src = g.get_src_node(arc);
139 auto * tgt = g.get_tgt_node(arc);
140 if (src == nullptr or tgt == nullptr)
141 return false;
142
143 if (src == tgt)
144 return false;
145
146 if (used_nodes.contains_or_insert(src).second)
147 return false;
148
149 if (used_nodes.contains_or_insert(tgt).second)
150 return false;
151 }
152
153 return true;
154 }
155
156 DynArray<std::pair<size_t, size_t>> normalize_simple_edges
157 (size_t n, const DynArray<std::pair<size_t, size_t>> & edges)
158 {
160
161 for (size_t i = 0; i < edges.size(); ++i)
162 {
163 auto [u, v] = edges(i);
164 if (u >= n or v >= n or u == v)
165 continue;
166 if (u > v)
167 std::swap(u, v);
168 seen.insert(std::make_pair(u, v));
169 }
170
172 for (const auto & p : seen)
173 simple_edges.append(p);
174
175 return simple_edges;
176 }
177
178 size_t exact_maximum_matching_size(size_t n,
179 const DynArray<std::pair<size_t, size_t>> & edges)
180 {
181 if (n == 0)
182 return 0;
183
184 // Enough for all tests in this file; keeps DP vector small and fast.
185 ah_runtime_error_if(n > 20) << "exact_maximum_matching_size supports n <= 20";
186
187 Array<uint64_t> adj(n, uint64_t{0});
188 auto simple = normalize_simple_edges(n, edges);
189 for (size_t i = 0; i < simple.size(); ++i)
190 {
191 auto [u, v] = simple(i);
192 adj(u) |= (uint64_t{1} << v);
193 adj(v) |= (uint64_t{1} << u);
194 }
195
196 const size_t state_count = static_cast<size_t>(uint64_t{1} << n);
197 Array<int> memo(state_count, -1);
198
199 std::function<int(uint64_t)> solve = [&](uint64_t mask) -> int
200 {
201 if (mask == 0)
202 return 0;
203
204 int & ans = memo(static_cast<size_t>(mask));
205 if (ans != -1)
206 return ans;
207
208 const size_t i = static_cast<size_t>(std::countr_zero(mask));
209 const uint64_t rest = mask & ~(uint64_t{1} << i);
210
211 ans = solve(rest); // leave i unmatched
212
213 uint64_t options = adj(i) & rest;
214 while (options != 0)
215 {
216 const size_t j = static_cast<size_t>(std::countr_zero(options));
217 options &= (options - 1);
218 ans = std::max(ans,
219 1 + solve(rest & ~(uint64_t{1} << j)));
220 }
221
222 return ans;
223 };
224
225 const uint64_t all = (uint64_t{1} << n) - 1;
226 return static_cast<size_t>(solve(all));
227 }
228
229 template <class GT>
230 size_t run_blossom(const GT & g, DynDlist<typename GT::Arc *> & matching)
231 {
232 return blossom_maximum_cardinality_matching<GT>(g, matching);
233 }
234
235 template <class GT>
236 GT build_bipartite_graph(size_t left_size,
237 size_t right_size,
238 const DynArray<std::pair<size_t, size_t>> & edges_lr)
239 {
240 GT g;
241 const size_t n = left_size + right_size;
242
243 for (size_t i = 0; i < left_size; ++i)
244 static_cast<void>(g.insert_node(static_cast<int>(i)));
245
246 for (size_t i = 0; i < right_size; ++i)
247 static_cast<void>(g.insert_node(static_cast<int>(left_size + i)));
248
251 [&](typename GT::Node * p)
252 {
253 const size_t id = static_cast<size_t>(p->get_info());
254 if (id < n)
255 nodes(id) = p;
256 });
257
258 for (size_t i = 0; i < n; ++i)
259 ah_runtime_error_if(nodes(i) == nullptr)
260 << "build_bipartite_graph(): node id " << i << " not found after insertion";
261
262 for (size_t i = 0; i < edges_lr.size(); ++i)
263 {
264 auto [l, r] = edges_lr(i);
265 if (l >= left_size or r >= right_size)
266 continue;
267 g.insert_arc(nodes(l), nodes(left_size + r), 1);
268 }
269
270 return g;
271 }
272
273 template <class GT>
274 class BlossomMatchingTypedTest : public ::testing::Test
275 {
276 };
277
278 using GraphBackends = ::testing::Types<
282
283 TYPED_TEST_SUITE(BlossomMatchingTypedTest, GraphBackends);
284
285} // namespace
286
287
288TYPED_TEST(BlossomMatchingTypedTest, EmptyGraph)
289{
290 using Graph = TypeParam;
291
292 Graph g;
294
295 const size_t cardinality = run_blossom(g, matching);
296
297 EXPECT_EQ(cardinality, 0u);
298 EXPECT_TRUE(matching.is_empty());
299 EXPECT_TRUE(verify_matching(g, matching));
300}
301
302TYPED_TEST(BlossomMatchingTypedTest, SingleEdge)
303{
304 using Graph = TypeParam;
305
306 auto g = build_graph<Graph>(2, {{0, 1}});
308
309 const size_t cardinality = run_blossom(g, matching);
310
311 EXPECT_EQ(cardinality, 1u);
312 EXPECT_EQ(matching.size(), 1u);
313 EXPECT_TRUE(verify_matching(g, matching));
314}
315
316TYPED_TEST(BlossomMatchingTypedTest, OddCycleC5)
317{
318 using Graph = TypeParam;
319
320 auto g = build_graph<Graph>(5, {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 0}});
322
323 const size_t cardinality = run_blossom(g, matching);
324
325 EXPECT_EQ(cardinality, 2u);
326 EXPECT_EQ(matching.size(), 2u);
327 EXPECT_TRUE(verify_matching(g, matching));
328}
329
330TYPED_TEST(BlossomMatchingTypedTest, CompleteGraphK6)
331{
332 using Graph = TypeParam;
333
335 for (size_t i = 0; i < 6; ++i)
336 for (size_t j = i + 1; j < 6; ++j)
337 edges.append(std::make_pair(i, j));
338 ASSERT_EQ(edges.size(), 15u);
339
340 auto g = build_graph<Graph>(6, edges);
342
343 const size_t cardinality = run_blossom(g, matching);
344
345 EXPECT_EQ(cardinality, 3u);
346 EXPECT_EQ(matching.size(), 3u);
347 EXPECT_TRUE(verify_matching(g, matching));
348}
349
350TYPED_TEST(BlossomMatchingTypedTest, BlossomContractionScenario)
351{
352 using Graph = TypeParam;
353
354 // 5-cycle plus three stems:
355 // cycle: 0-1-2-3-4-0, stems: 1-5, 2-6, 3-7
356 // Maximum matching = 4
357 auto g = build_graph<Graph>(8,
358 {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 0},
359 {1, 5}, {2, 6}, {3, 7}});
361
362 const size_t cardinality = run_blossom(g, matching);
363
364 EXPECT_EQ(cardinality, 4u);
365 EXPECT_EQ(matching.size(), 4u);
366 EXPECT_TRUE(verify_matching(g, matching));
367}
368
369TYPED_TEST(BlossomMatchingTypedTest, HandlesLoopsAndParallelArcs)
370{
371 using Graph = TypeParam;
372
373 auto g = build_graph<Graph>(4,
374 {
375 {0, 0},
376 {0, 1},
377 {0, 1},
378 {1, 2},
379 {2, 3},
380 {3, 3}
381 });
382
384 const size_t cardinality = run_blossom(g, matching);
385
386 EXPECT_EQ(cardinality, 2u);
387 EXPECT_EQ(matching.size(), 2u);
388 EXPECT_TRUE(verify_matching(g, matching));
389}
390
391TYPED_TEST(BlossomMatchingTypedTest, FunctorWrapperMatchesFreeFunction)
392{
393 using Graph = TypeParam;
394
395 auto g = build_graph<Graph>(7,
396 {{0, 1}, {1, 2}, {2, 0}, {2, 3}, {3, 4},
397 {4, 5}, {5, 6}, {1, 6}});
398
400 DynDlist<typename Graph::Arc *> functor_matching;
401
402 const size_t c1 = blossom_maximum_cardinality_matching<Graph>(g, free_matching);
403 const size_t c2 = Compute_Maximum_Cardinality_General_Matching<Graph>()(g, functor_matching);
404
405 EXPECT_EQ(c1, c2);
406 EXPECT_EQ(free_matching.size(), functor_matching.size());
407 EXPECT_TRUE(verify_matching(g, free_matching));
408 EXPECT_TRUE(verify_matching(g, functor_matching));
409}
410
411TYPED_TEST(BlossomMatchingTypedTest, RandomGraphsAgreeWithExactDP)
412{
413 using Graph = TypeParam;
414
415 std::mt19937 rng(20260220);
416 std::uniform_real_distribution<double> coin(0.0, 1.0);
417
418 for (size_t n = 2; n <= 10; ++n)
419 for (int sample = 0; sample < 30; ++sample)
420 {
421 const double p = 0.10 + 0.03 * static_cast<double>(sample);
422
424 for (size_t u = 0; u < n; ++u)
425 for (size_t v = u + 1; v < n; ++v)
426 if (coin(rng) < p)
427 edges.append(std::make_pair(u, v));
428 ASSERT_TRUE(edges.all([] (const auto & e) { return e.first < e.second; }));
429
430 auto g = build_graph<Graph>(n, edges);
431
433 const size_t blossom_size = run_blossom(g, matching);
434 const size_t exact_size = exact_maximum_matching_size(n, edges);
435
436 EXPECT_EQ(blossom_size, exact_size)
437 << "n=" << n << " sample=" << sample;
438 EXPECT_EQ(matching.size(), blossom_size)
439 << "n=" << n << " sample=" << sample;
440 EXPECT_TRUE(verify_matching(g, matching))
441 << "n=" << n << " sample=" << sample;
442 }
443}
444
445TYPED_TEST(BlossomMatchingTypedTest, AgreesWithHopcroftKarpOnBipartiteGraphs)
446{
447 using Graph = TypeParam;
448
449 std::mt19937 rng(7);
450 std::uniform_real_distribution<double> coin(0.0, 1.0);
451
452 for (size_t left = 1; left <= 6; ++left)
453 for (size_t right = 1; right <= 6; ++right)
454 for (int sample = 0; sample < 10; ++sample)
455 {
456 const double p = 0.15 + 0.07 * static_cast<double>(sample);
458 size_t appended = 0;
459 for (size_t l = 0; l < left; ++l)
460 for (size_t r = 0; r < right; ++r)
461 if (coin(rng) < p)
462 {
463 edges_lr.append(std::make_pair(l, r));
464 ++appended;
465 }
466 ASSERT_EQ(edges_lr.size(), appended);
467
468 auto g = build_bipartite_graph<Graph>(left, right, edges_lr);
469
470 DynDlist<typename Graph::Arc *> blossom_matching;
472
473 const size_t blossom_size =
474 blossom_maximum_cardinality_matching<Graph>(g, blossom_matching);
475 hopcroft_karp_matching<Graph>(g, hk_matching);
476
477 EXPECT_EQ(blossom_size, hk_matching.size())
478 << "left=" << left << " right=" << right << " sample=" << sample;
479 EXPECT_TRUE(verify_matching(g, blossom_matching));
480 EXPECT_TRUE(verify_matching(g, hk_matching));
481 }
482}
483
484TYPED_TEST(BlossomMatchingTypedTest, NestedOddCyclesWithStems)
485{
486 using Graph = TypeParam;
487
488 // Two connected 5-cycles plus stems:
489 // C1: 0-1-2-3-4-0
490 // C2: 2-5-6-7-8-2
491 // stems: 1-9, 4-10, 6-11
492 //
493 // This family tends to trigger multiple blossom contractions and expansions.
495 {0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 0},
496 {2, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 2},
497 {1, 9}, {4, 10}, {6, 11}
498 };
499
500 auto g = build_graph<Graph>(12, edges);
502
503 const size_t blossom_size = run_blossom(g, matching);
504 const size_t exact_size = exact_maximum_matching_size(12, edges);
505
506 EXPECT_EQ(blossom_size, exact_size);
507 EXPECT_EQ(matching.size(), blossom_size);
508 EXPECT_TRUE(verify_matching(g, matching));
509}
510
511TYPED_TEST(BlossomMatchingTypedTest, FlowerWithSharedCenterAndBridge)
512{
513 using Graph = TypeParam;
514
515 // "Flower": three odd petals sharing vertex 0, connected to a tail.
516 // Petals:
517 // 0-1-2-0
518 // 0-3-4-0
519 // 0-5-6-0
520 // Tail:
521 // 2-7-8-9
523 {0, 1}, {1, 2}, {2, 0},
524 {0, 3}, {3, 4}, {4, 0},
525 {0, 5}, {5, 6}, {6, 0},
526 {2, 7}, {7, 8}, {8, 9}
527 };
528
529 auto g = build_graph<Graph>(10, edges);
531
532 const size_t blossom_size = run_blossom(g, matching);
533 const size_t exact_size = exact_maximum_matching_size(10, edges);
534
535 EXPECT_EQ(blossom_size, exact_size);
536 EXPECT_EQ(matching.size(), blossom_size);
537 EXPECT_TRUE(verify_matching(g, matching));
538}
539
540TYPED_TEST(BlossomMatchingTypedTest, DenseRandomStressCrossBackendAgreement)
541{
542 using Graph = TypeParam;
543
544 std::mt19937 rng(0xB10550u);
545 std::uniform_real_distribution<double> coin(0.0, 1.0);
546
547 // Stress sizes beyond exact-DP range.
548 for (int sample = 0; sample < 12; ++sample)
549 {
550 const size_t n = 30 + static_cast<size_t>(sample % 11); // [30, 40]
551 const double p = 0.16 + 0.01 * static_cast<double>(sample);
552
554 for (size_t u = 0; u < n; ++u)
555 for (size_t v = u + 1; v < n; ++v)
556 if (coin(rng) < p)
557 edges.append(std::make_pair(u, v));
558 ASSERT_TRUE(edges.all([] (const auto & e) { return e.first < e.second; }));
559
560 auto g = build_graph<Graph>(n, edges);
562 const size_t blossom_size = run_blossom(g, matching);
563
564 EXPECT_EQ(matching.size(), blossom_size)
565 << "sample=" << sample << " n=" << n;
566 EXPECT_TRUE(verify_matching(g, matching))
567 << "sample=" << sample << " n=" << n;
568 EXPECT_LE(blossom_size, n / 2)
569 << "sample=" << sample << " n=" << n;
570 }
571}
572
573TYPED_TEST(BlossomMatchingTypedTest, BlossomMatchingPerfRegression)
574{
575 using Graph = TypeParam;
576
577 const char * run_perf = std::getenv("ALEPH_RUN_BLOSSOM_PERF");
578 if (run_perf == nullptr or std::string(run_perf) != "1")
579 GTEST_SKIP() << "Set ALEPH_RUN_BLOSSOM_PERF=1 to run blossom perf regression test";
580
581 constexpr size_t n = 900;
582 constexpr double p = 0.02;
583 constexpr unsigned seed = 0xB10550u;
584# ifdef NDEBUG
585 constexpr long long kBudgetMs = 12000;
586# else
587 constexpr long long kBudgetMs = 25000;
588# endif
589
590 std::mt19937 rng(seed);
591 std::uniform_real_distribution<double> coin(0.0, 1.0);
592
594 for (size_t u = 0; u < n; ++u)
595 for (size_t v = u + 1; v < n; ++v)
596 if (coin(rng) < p)
597 edges.append(std::make_pair(u, v));
598
599 if (edges.is_empty())
600 edges.append(std::make_pair(0, 1));
601 EXPECT_TRUE(edges.all([] (const auto & e) { return e.first < e.second; }));
602
603 auto g = build_graph<Graph>(n, edges);
605
606 const auto t0 = std::chrono::steady_clock::now();
607 const size_t blossom_size = run_blossom(g, matching);
608 const auto elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
609 std::chrono::steady_clock::now() - t0).count();
610
611 EXPECT_EQ(matching.size(), blossom_size);
612 EXPECT_TRUE(verify_matching(g, matching));
613 EXPECT_LE(blossom_size, n / 2);
614 EXPECT_LT(elapsed_ms, kBudgetMs)
615 << "Blossom perf regression: n=" << n
616 << ", edges=" << edges.size()
617 << ", elapsed_ms=" << elapsed_ms
618 << ", budget_ms=" << kBudgetMs;
619}
620
621// -----------------------------------------------------------------------------
622// Dedicated non-typed tests
623// -----------------------------------------------------------------------------
624
625namespace
626{
627 struct Positive_Arc_Filter
628 {
629 template <class Arc>
630 bool operator()(Arc * a) const noexcept
631 {
632 return a->get_info() > 0;
633 }
634 };
635}
636
637TEST(BlossomMatchingStandaloneTest, ArcFilterIsRespected)
638{
640
641 Graph g;
642 auto * n0 = g.insert_node(0);
643 auto * n1 = g.insert_node(1);
644 auto * n2 = g.insert_node(2);
645 auto * n3 = g.insert_node(3);
646
647 // Positive arc.
648 g.insert_arc(n0, n1, 1);
649 // Zero arcs (filtered out).
650 g.insert_arc(n1, n2, 0);
651 g.insert_arc(n2, n3, 0);
652 g.insert_arc(n0, n3, 0);
653
654 DynDlist<Graph::Arc *> matching;
655 const size_t cardinality =
656 blossom_maximum_cardinality_matching<Graph, Positive_Arc_Filter>(
657 g, matching, Positive_Arc_Filter());
658
659 EXPECT_EQ(cardinality, 1u);
660 EXPECT_EQ(matching.size(), 1u);
661 EXPECT_TRUE(verify_matching(g, matching));
662}
663
664TEST(BlossomMatchingStandaloneTest, DigraphThrowsDomainError)
665{
667
668 Digraph g;
669 auto * n0 = g.insert_node(0);
670 auto * n1 = g.insert_node(1);
671 g.insert_arc(n0, n1, 1);
672
674
675 EXPECT_THROW(blossom_maximum_cardinality_matching<Digraph>(g, matching),
676 std::domain_error);
677}
Edmonds' Blossom algorithm for maximum matching in general graphs.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
Definition ah-errors.H:415
TYPED_TEST_SUITE(ArcHeapLifecycle, ArcHeapKinds)
WeightedDigraph::Arc Arc
bool verify_matching(const Graph &g, const DynDlist< Graph::Arc * > &matching)
Verifies that a matching is valid:
TYPED_TEST(BlossomMatchingTypedTest, EmptyGraph)
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:141
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Definition tpl_array.H:450
Functor wrapper for maximum cardinality general matching.
Definition Blossom.H:482
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:4377
size_t size() const noexcept
Return the current dimension of array.
T & append()
Allocate a new entry to the end of array.
bool is_empty() const noexcept
Return true if the array is empty.
Dynamic doubly linked list with O(1) size and bidirectional access.
const size_t & size() const noexcept
Return the number of elements (constant time)
Dynamic set backed by balanced binary search trees with automatic memory management.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
std::pair< Key *, bool > contains_or_insert(const Key &key)
Arc for graphs implemented with simple adjacency lists.
Definition tpl_sgraph.H:197
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
Graph class implemented with singly-linked adjacency lists.
Definition tpl_sgraph.H:274
Open addressing hash table with linear probing collision resolution.
Definition tpl_olhash.H:175
constexpr bool contains(const Key &key) const noexcept
Alias for has().
Definition hashDry.H:769
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
Definition ah-dry.H:1666
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
Definition graph-dry.H:753
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:1017
void for_each_node(Operation &operation) const
Unconditionally traverse all the nodes of graph and on each one perform an operation.
Definition graph-dry.H:1765
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
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
Definition hashDry.H:507
#define TEST(name)
static mt19937 rng
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
Main namespace for Aleph-w library functions.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
Built_Graph_T< Graph > build_graph(const size_t n, const std::vector< Edge_Def > &edges)
static struct argp_option options[]
Definition ntreepic.C:1890
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:231
ValueArg< size_t > seed
Definition testHash.C:53
Gsl_Compatible_Rng r
Array-based graph implementation.
Dynamic array container with automatic resizing.
Bipartite graph detection and 2-coloring.
Lazy and scalable dynamic array implementation.
Dynamic set implementations based on balanced binary search trees.
Generic graph and digraph implementations.
Open addressing hash table with linear probing.
Simple graph implementation with adjacency lists.
DynList< int > l