Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
graph_contract_matrix_search_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
54#include <set>
55#include <stdexcept>
56#include <type_traits>
57#include <utility>
58
59#include <gtest/gtest.h>
60
61#include <tpl_graph.H>
62#include <tpl_find_path.H>
63#include <Bidirectional_BFS.H>
64#include <tpl_components.H>
65#include <tpl_cut_nodes.H>
66#include <tpl_spanning_tree.H>
67#include <tpl_test_acyclique.H>
69#include <tpl_test_cycle.H>
70#include <tpl_test_path.H>
71
72#include "graph_harness.H"
75
76using namespace Aleph;
77using namespace graph_harness;
78using namespace graph_contract_matrix;
79
80namespace
81{
83 template <class List>
84 std::set<int> arc_numbers(const List & l)
85 {
86 std::set<int> r;
87 for (auto it = l.get_it(); it.has_curr(); it.next_ne())
88 r.insert(it.get_curr()->get_info());
89 return r;
90 }
91} // namespace
92
93namespace
94{
96 Spec shortcut()
97 {
98 Spec s;
99 s.n = 4;
100 s.arcs = {{0, 1}, {1, 2}, {1, 3}, {2, 3}};
101 return s;
102 }
103
105 Spec halves()
106 {
107 Spec s;
108 s.n = 4;
109 s.arcs = {{0, 1}, {2, 3}, {1, 2}};
110 return s;
111 }
112
114 Spec triangle()
115 {
116 Spec s;
117 s.n = 3;
118 s.arcs = {{0, 1}, {1, 2}, {2, 0}};
119 return s;
120 }
121
123 template <class GT>
124 std::set<int> graph_arcs(const GT & g)
125 {
126 std::set<int> r;
127 for (typename GT::Arc_Iterator it(g); it.has_curr(); it.next_ne())
128 r.insert(it.get_curr_ne()->get_info());
129 return r;
130 }
131
133 template <class GT>
134 std::set<int> path_arcs(const Path<GT> & p)
135 {
136 std::set<int> r;
137 p.for_each_arc([&r] (typename GT::Arc * a) { r.insert(a->get_info()); });
138 return r;
139 }
140
142 template <class List>
143 std::set<int> node_numbers(const List & l)
144 {
145 std::set<int> r;
146 for (auto it = l.get_it(); it.has_curr(); it.next_ne())
147 r.insert(num(it.get_curr()));
148 return r;
149 }
150
153 template <class GT>
154 void expect_path(const Path<GT> & p, int from, int to, bool hidden)
155 {
156 ASSERT_FALSE(p.is_empty());
157 EXPECT_EQ(num(p.get_first_node()), from);
158 EXPECT_EQ(num(p.get_last_node()), to);
159 if (hidden)
160 {
161 EXPECT_EQ(path_arcs(p).count(Hidden), 0U) << "the path takes the hidden arc";
162 }
163 }
164
165 // What some calls need of a filter, and the ArcFilter concept does not
166 // ask, by which the tests leave out their known failures: they build the
167 // filter with SA()
168
170 template <class SA>
171 constexpr bool default_built = std::is_default_constructible_v<SA>;
172} // namespace
173
174template <class GT>
175class ContractSearchAll : public ::testing::Test {};
176
178
179template <class GT>
180class ContractSearchUndirected : public ::testing::Test {};
181
183
184template <class GT>
185class ContractSearchDirected : public ::testing::Test {};
186
188
189TYPED_TEST(ContractSearchAll, FindPathDepthFirst)
190{
191 using GT = TypeParam;
192 Built<GT> b(shortcut());
193 auto * s = b.nodes[0];
194 auto * t = b.nodes[3];
195 for_each_filter<GT>([&] (auto sa, const char * name)
196 {
197 using SA = decltype(sa);
198 constexpr bool hiding = hides<GT, SA>;
199 SCOPED_TRACE(name);
200 for_each_constness(b.g, [&] (auto & g)
201 {
202 auto goal = [t] (typename GT::Node * p) { return p == t; };
204 Path<GT> p(g);
205 EXPECT_TRUE(lvalue(g, s, t, p));
206 expect_path(p, 0, 3, hiding);
207 expect_path(lvalue(g, s, t), 0, 3, hiding);
208 expect_path(lvalue(g, s, goal), 0, 3, hiding);
209
210 SA copy = sa;
212 expect_path(rvalue(g, s, [t] (typename GT::Node * p) { return p == t; }),
213 0, 3, hiding);
214
215 if constexpr (default_built<SA>) // a filter built by default hides nothing
217 0, 3, false);
218 });
219 });
220}
221
222TYPED_TEST(ContractSearchAll, FindPathBreadthFirst)
223{
224 using GT = TypeParam;
225 Built<GT> b(shortcut());
226 auto * s = b.nodes[0];
227 auto * t = b.nodes[3];
228 for_each_filter<GT>([&] (auto sa, const char * name)
229 {
230 using SA = decltype(sa);
231 constexpr bool hiding = hides<GT, SA>;
232 SCOPED_TRACE(name);
233 for_each_constness(b.g, [&] (auto & g)
234 {
235 auto goal = [t] (typename GT::Node * p) { return p == t; };
237 Path<GT> p(g);
238 EXPECT_TRUE(lvalue(g, s, t, p));
239 expect_path(p, 0, 3, hiding);
240 expect_path(lvalue(g, s, t), 0, 3, hiding);
241 expect_path(lvalue(g, s, goal), 0, 3, hiding);
242
243 SA copy = sa;
245 expect_path(rvalue(g, s, goal), 0, 3, hiding);
246
247 if constexpr (default_built<SA>)
249 0, 3, false);
250 });
251 });
252}
253
255{
256 using GT = TypeParam;
257 Built<GT> b(shortcut()); // each arc goes from its first node to its second
258 auto * s = b.nodes[0];
259 auto * t = b.nodes[3];
260 for_each_filter<GT>([&] (auto sa, const char * name)
261 {
262 using SA = decltype(sa);
263 constexpr bool hiding = hides<GT, SA>;
264 SCOPED_TRACE(name);
265 for_each_constness(b.g, [&] (auto & g)
266 {
267 auto goal = [t] (typename GT::Node * p) { return p == t; };
269 expect_path(lvalue.dfs(s, t), 0, 3, hiding);
270 expect_path(lvalue.bfs(s, t), 0, 3, hiding);
271 expect_path(lvalue.dfs(s, goal), 0, 3, hiding);
272 expect_path(lvalue.bfs(s, goal), 0, 3, hiding);
273
274 SA copy = sa;
276 expect_path(rvalue.dfs(s, [t] (typename GT::Node * p) { return p == t; }),
277 0, 3, hiding);
278 expect_path(rvalue.bfs(s, [t] (typename GT::Node * p) { return p == t; }),
279 0, 3, hiding);
280
281 if constexpr (default_built<SA>)
282 expect_path(Directed_Find_Path<GT, Out_Iterator, SA>(g).bfs(s, t), 0, 3, false);
283 });
284 });
285}
286
288{
289 using GT = TypeParam;
290 Built<GT> b(shortcut());
291 auto * s = b.nodes[0];
292 auto * t = b.nodes[3];
293 for_each_filter<GT>([&] (auto sa, const char * name)
294 {
295 using SA = decltype(sa);
296 constexpr bool hiding = hides<GT, SA>;
298 SCOPED_TRACE(name);
299 for_each_constness(b.g, [&] (auto & g)
300 {
301 // The filter as an lvalue, const or not
302 BiBFS by_lvalue(sa);
303 BiBFS by_const(std::as_const(sa));
304 Path<GT> p(g);
305 EXPECT_TRUE(by_lvalue.find_path(g, s, t, p));
306 expect_path(p, 0, 3, hiding);
307 EXPECT_TRUE(by_const(g, s, t, p));
308 expect_path(p, 0, 3, hiding);
309 expect_path(by_lvalue(g, s, t), 0, 3, hiding);
310
311 SA copy = sa;
312 BiBFS rvalue(std::move(copy));
313 expect_path(rvalue(g, s, t), 0, 3, hiding);
314
315 if constexpr (default_built<SA>)
316 expect_path(BiBFS()(g, s, t), 0, 3, false);
317 });
318 });
319}
320
321TYPED_TEST(ContractSearchDirected, BidirectionalBFSOutIn)
322{
323 using GT = TypeParam;
324 Built<GT> b(shortcut());
325 auto * s = b.nodes[0];
326 auto * t = b.nodes[3];
327 for_each_filter<GT>([&] (auto sa, const char * name)
328 {
329 using SA = decltype(sa);
330 constexpr bool hiding = hides<GT, SA>;
332 SCOPED_TRACE(name);
333 for_each_constness(b.g, [&] (auto & g)
334 {
335 // The filter as an lvalue, const or not
336 BiBFS by_lvalue(sa);
337 BiBFS by_const(std::as_const(sa));
338 Path<GT> p(g);
339 EXPECT_TRUE(by_lvalue.find_path(g, s, t, p));
340 expect_path(p, 0, 3, hiding);
341 EXPECT_TRUE(by_const(g, s, t, p));
342 expect_path(p, 0, 3, hiding);
343 expect_path(by_lvalue(g, s, t), 0, 3, hiding);
344
345 SA copy = sa;
346 BiBFS rvalue(std::move(copy));
347 expect_path(rvalue(g, s, t), 0, 3, hiding);
348
349 if constexpr (default_built<SA>)
350 expect_path(BiBFS()(g, s, t), 0, 3, false);
351 });
352 });
353}
354
356{
357 using GT = TypeParam;
358 Built<GT> b(halves()); // from 0, the arc 2 is the way to 2 and 3
359 for_each_filter<GT>([&] (auto sa, const char * name)
360 {
361 using SA = decltype(sa);
362 constexpr bool hiding = hides<GT, SA>;
363 SCOPED_TRACE(name);
364 const size_t nodes = hiding ? 2 : 4;
365 const std::set<int> arcs = hiding ? std::set<int>{0} : std::set<int>{0, 1, 2};
366 for_each_constness(b.g, [&] (auto & g)
367 {
368 // The marks of a former copy would stop the next one
369 Build_Subgraph<GT, SA> build(sa);
370 g.reset_nodes();
371 g.reset_arcs();
372 GT sg;
373 build(g, sg, b.nodes[0]);
374 EXPECT_EQ(sg.get_num_nodes(), nodes);
375 EXPECT_EQ(graph_arcs(sg), arcs);
376
377 g.reset_nodes();
378 g.reset_arcs();
379 const GT copy = build(g, b.nodes[0]);
380 EXPECT_EQ(copy.get_num_nodes(), nodes);
381 EXPECT_EQ(graph_arcs(copy), arcs);
382
383 g.reset_nodes();
384 g.reset_arcs();
385 DynList<typename GT::Node *> l;
386 build(g, l, b.nodes[0]);
387 EXPECT_EQ(l.size(), nodes);
388
389 if constexpr (default_built<SA>)
390 {
391 g.reset_nodes();
392 g.reset_arcs();
393 EXPECT_EQ((Build_Subgraph<GT, SA>()(g, b.nodes[0]).get_num_nodes()), 4U);
394 }
395 });
396 });
397}
398
399// On a digraph the arcs that leave each node do not give the components,
400// and every operation throws domain_error, before it calls the filter
401TYPED_TEST(ContractSearchAll, UnconnectedComponents)
402{
403 using GT = TypeParam;
404 Built<GT> b(halves());
405 for_each_filter<GT>([&] (auto sa, const char * name)
406 {
407 using SA = decltype(sa);
408 constexpr bool hiding = hides<GT, SA>;
409 SCOPED_TRACE(name);
410 for_each_constness(b.g, [&] (auto & g)
411 {
412 Unconnected_Components<GT, SA> cc(sa);
413 if (g.is_digraph())
414 {
415 DynList<GT> blocks;
416 DynList<DynList<typename GT::Node *>> lists;
417 EXPECT_THROW_OR_FILTER(cc(g, blocks), std::domain_error);
418 EXPECT_THROW_OR_FILTER(cc(g, lists), std::domain_error);
419 EXPECT_THROW_OR_FILTER((void) cc.count_components(g), std::domain_error);
420 EXPECT_THROW_OR_FILTER((void) cc.is_connected(g), std::domain_error);
421 EXPECT_THROW_OR_FILTER(cc.template compute_blocks<DynList>(g, blocks),
422 std::domain_error);
423 EXPECT_THROW_OR_FILTER(cc.template compute_lists<DynList>(g, lists),
424 std::domain_error);
425 EXPECT_TRUE(blocks.is_empty());
426 EXPECT_TRUE(lists.is_empty());
427 return;
428 }
429
430 DynList<GT> blocks;
431 cc(g, blocks);
433 cc(g, lists);
434 const size_t count = cc.count_components(g);
435 EXPECT_EQ(blocks.size(), count);
436 EXPECT_EQ(lists.size(), count);
437 size_t arcs = 0;
438 for (auto it = blocks.get_it(); it.has_curr(); it.next_ne())
439 {
440 arcs += it.get_curr().get_num_arcs();
441 if (hiding)
442 {
443 EXPECT_EQ(graph_arcs(it.get_curr()).count(Hidden), 0U);
444 }
445 }
446
447 EXPECT_EQ(count, hiding ? 2U : 1U);
448 EXPECT_EQ(cc.is_connected(g), not hiding);
449 EXPECT_EQ(arcs, hiding ? 2U : 3U);
450
451 DynList<GT> blocks2;
452 cc.template compute_blocks<DynList>(g, blocks2);
453 EXPECT_EQ(blocks2.size(), count);
455 cc.template compute_lists<DynList>(g, lists2);
456 EXPECT_EQ(lists2.size(), count);
457
458 if constexpr (default_built<SA>)
459 {
460 EXPECT_EQ((Unconnected_Components<GT, SA>().count_components(g)), 1U);
461 }
462 });
463 });
464}
465
467{
468 using GT = TypeParam;
469 Built<GT> b(triangle()); // without the arc 2, 1 is a cut node
470 for_each_filter<GT>([&] (auto sa, const char * name)
471 {
472 using SA = decltype(sa);
473 constexpr bool hiding = hides<GT, SA>;
474 SCOPED_TRACE(name);
475 const std::set<int> cut = hiding ? std::set<int>{1} : std::set<int>{};
476 for_each_constness(b.g, [&] (auto & g)
477 {
478 Compute_Cut_Nodes<GT, SA> cc(g, sa);
479 DynDlist<typename GT::Node *> l;
480 cc(l);
481 EXPECT_EQ(node_numbers(l), cut);
482 cc(b.nodes[0], l);
483 EXPECT_EQ(node_numbers(l), cut);
484 cc.cut_nodes(b.nodes[0], l);
485 EXPECT_EQ(node_numbers(l), cut);
486 // the next color: two blocks around 1, or none painted
487 EXPECT_EQ(cc.paint_subgraphs(), hiding ? 3 : 1);
488
489 if (hiding)
490 {
491 GT block;
492 cc.map_subgraph(block, 1);
493 EXPECT_EQ(block.get_num_nodes(), 1U);
494 }
495 GT cut_graph;
497 cc.map_cut_graph(cut_graph, cross);
498 EXPECT_EQ(cut_graph.get_num_nodes(), cut.size());
499 const std::set<int> crossing = hiding ? std::set<int>{0, 1} : std::set<int>{};
500 EXPECT_EQ(arc_numbers(cross), crossing);
501
502 Compute_Cut_Nodes<GT, SA> again(g, sa);
503 again(l);
504 DynDlist<GT> blocks;
505 GT cut_graph2;
507 again.compute_blocks(blocks, cut_graph2, cross2);
508 EXPECT_EQ(blocks.size(), hiding ? 2U : 1U);
509
510 if constexpr (default_built<SA>)
511 {
512 Compute_Cut_Nodes<GT, SA> by_default(g);
513 by_default(l);
514 EXPECT_TRUE(l.is_empty());
515 }
516 });
517 });
518}
519
521{
522 using GT = TypeParam;
523 Built<GT> b(triangle()); // without the arc 2, the arcs 0 and 1 are bridges
524 for_each_filter<GT>([&] (auto sa, const char * name)
525 {
526 using SA = decltype(sa);
527 constexpr bool hiding = hides<GT, SA>;
528 SCOPED_TRACE(name);
529 const std::set<int> want = hiding ? std::set<int>{0, 1} : std::set<int>{};
530 for_each_constness(b.g, [&] (auto & g)
531 {
532 Compute_Bridges<GT, SA> cb(g, sa);
533 EXPECT_EQ(arc_numbers(cb.find_bridges(b.nodes[0])), want);
534 EXPECT_EQ(arc_numbers(cb.find_bridges()), want);
535 EXPECT_EQ(arc_numbers(cb(b.nodes[0])), want);
536 EXPECT_EQ(arc_numbers(cb()), want);
537
538 if constexpr (default_built<SA>)
539 {
540 EXPECT_TRUE((Compute_Bridges<GT, SA>(g).find_bridges().is_empty()));
541 }
542 });
543 });
544}
545
547{
548 using GT = TypeParam;
549 Built<GT> b(triangle());
550 for_each_filter<GT>([&] (auto sa, const char * name)
551 {
552 using SA = decltype(sa);
553 constexpr bool hiding = hides<GT, SA>;
554 SCOPED_TRACE(name);
555 const std::set<int> want = hiding ? std::set<int>{0, 1} : std::set<int>{};
556 for_each_constness(b.g, [&] (auto & g)
557 {
558 EXPECT_EQ(arc_numbers(find_bridges(g, b.nodes[0], sa)), want);
559 if constexpr (default_built<SA>)
560 {
561 EXPECT_TRUE((find_bridges<GT, SA>(g, b.nodes[0]).is_empty()));
562 }
563 });
564 });
565}
566
567TYPED_TEST(ContractSearchAll, FindDepthFirstSpanningTree)
568{
569 using GT = TypeParam;
570 Built<GT> b(shortcut());
571 Built<GT> apart(halves()); // without the arc 2, no node reaches all
572 // In a digraph only 0 reaches every node, and the first node of a
573 // List_SDigraph, which follows the addresses, may be another one, from
574 // which no tree spans the graph
575 const bool first_spans = not b.g.is_digraph() or num(b.g.get_first_node()) == 0;
576 for_each_filter<GT>([&] (auto sa, const char * name)
577 {
578 using SA = decltype(sa);
579 constexpr bool hiding = hides<GT, SA>;
580 SCOPED_TRACE(name);
581 auto expect_tree = [&] (const GT & tree, bool hidden)
582 {
583 EXPECT_EQ(tree.get_num_nodes(), 4U);
584 EXPECT_EQ(tree.get_num_arcs() + 1, tree.get_num_nodes());
585 if (hidden)
586 {
587 EXPECT_EQ(graph_arcs(tree).count(Hidden), 0U);
588 }
589 };
590 // The tree takes a graph that is not const
592 GT tree;
593 if (first_spans)
594 {
595 EXPECT_EQ(dfs(b.g, tree), b.g.get_first_node());
596 expect_tree(tree, hiding);
597 }
598 else
599 EXPECT_EQ(dfs(b.g, tree), nullptr);
600 GT tree2;
601 EXPECT_NE(dfs(b.g, b.nodes[0], tree2), nullptr);
602 expect_tree(tree2, hiding);
603
604 if (hiding)
605 {
606 GT forest;
607 EXPECT_EQ(dfs(apart.g, forest), nullptr);
608 }
609
610 if constexpr (default_built<SA>)
611 {
612 GT tree3;
613 auto * root = Find_Depth_First_Spanning_Tree<GT, SA>()(b.g, tree3);
614 if (first_spans)
615 {
616 EXPECT_NE(root, nullptr);
617 expect_tree(tree3, false);
618 }
619 else
620 EXPECT_EQ(root, nullptr);
621 }
622 });
623}
624
625TYPED_TEST(ContractSearchAll, FindBreadthFirstSpanningTree)
626{
627 using GT = TypeParam;
628 Built<GT> b(shortcut());
629 for_each_filter<GT>([&] (auto sa, const char * name)
630 {
631 using SA = decltype(sa);
632 constexpr bool hiding = hides<GT, SA>;
633 SCOPED_TRACE(name);
634 // As in the depth-first tree: from the first node of a digraph,
635 // maybe fewer nodes than from 0
636 auto expect_tree = [&] (const GT & tree, size_t nodes, bool hidden)
637 {
638 if (nodes != 0)
639 {
640 EXPECT_EQ(tree.get_num_nodes(), nodes);
641 }
642 EXPECT_EQ(tree.get_num_arcs() + 1, tree.get_num_nodes());
643 if (hidden)
644 {
645 EXPECT_EQ(graph_arcs(tree).count(Hidden), 0U);
646 }
647 };
648 const size_t from_first = b.g.is_digraph() ? 0 : 4;
649 // The tree takes a graph that is not const
651 GT tree;
652 bfs(b.g, b.nodes[0], tree);
653 expect_tree(tree, 4, hiding);
654 GT tree2;
655 EXPECT_NE(bfs(b.g, tree2), nullptr);
656 expect_tree(tree2, from_first, hiding);
657
658 if constexpr (default_built<SA>)
659 {
660 GT tree3;
661 EXPECT_NE((Find_Breadth_First_Spanning_Tree<GT, SA>()(b.g, tree3)), nullptr);
662 expect_tree(tree3, from_first, false);
663 }
664 });
665}
666
668{
669 using GT = TypeParam;
670 Built<GT> b(triangle());
671 for_each_filter<GT>([&] (auto sa, const char * name)
672 {
673 using SA = decltype(sa);
674 constexpr bool hiding = hides<GT, SA>;
675 SCOPED_TRACE(name);
676 const bool acyclic = hiding;
677 // The test takes a graph that is not const
679 EXPECT_EQ(lvalue(b.g), acyclic);
680 EXPECT_EQ(lvalue(b.g, acyclic ? 2 : 3), acyclic);
681
682 SA copy = sa;
683 Is_Graph_Acyclique<GT, SA> rvalue(std::move(copy));
684 EXPECT_EQ(rvalue(b.g), acyclic);
685
686 if constexpr (default_built<SA>)
687 {
688 EXPECT_FALSE((Is_Graph_Acyclique<GT, SA>()(b.g)));
689 }
690 });
691}
692
694{
695 using GT = TypeParam;
696 Built<GT> b(triangle());
697 for_each_filter<GT>([&] (auto sa, const char * name)
698 {
699 using SA = decltype(sa);
700 constexpr bool hiding = hides<GT, SA>;
701 SCOPED_TRACE(name);
702 const bool cycle = not hiding;
703 // The test takes a graph that is not const
704 const Has_Cycle<GT, SA> lvalue(sa);
705 EXPECT_EQ(lvalue(b.g), cycle);
706 EXPECT_EQ(lvalue(b.g, cycle ? 3 : 2), cycle);
707
708 SA copy = sa;
709 const Has_Cycle<GT, SA> rvalue(std::move(copy));
710 EXPECT_EQ(rvalue(b.g), cycle);
711
712 if constexpr (default_built<SA>)
713 {
714 EXPECT_TRUE((Has_Cycle<GT, SA>()(b.g)));
715 }
716 });
717}
718
720{
721 using GT = TypeParam;
722 Built<GT> b(halves());
723 for_each_filter<GT>([&] (auto sa, const char * name)
724 {
725 using SA = decltype(sa);
726 constexpr bool hiding = hides<GT, SA>;
727 SCOPED_TRACE(name);
728 const bool connected = not hiding;
729 // The test takes a graph that is not const
731 EXPECT_EQ(test(b.g, sa), connected);
732 SA copy = sa;
733 EXPECT_EQ(test(b.g, std::move(copy)), connected);
734
735 if constexpr (default_built<SA>)
736 {
737 EXPECT_TRUE(test(b.g));
738 }
739 });
740}
741
743{
744 using GT = TypeParam;
745 Built<GT> b(triangle());
746 for_each_filter<GT>([&] (auto sa, const char * name)
747 {
748 using SA = decltype(sa);
749 constexpr bool hiding = hides<GT, SA>;
750 SCOPED_TRACE(name);
751 for_each_constness(b.g, [&] (auto & g)
752 {
753 const Test_For_Cycle<GT, SA> test(sa);
754 EXPECT_EQ(test(g, b.nodes[0]), not hiding);
755
756 if constexpr (default_built<SA>)
757 {
758 EXPECT_TRUE((Test_For_Cycle<GT, SA>()(g, b.nodes[0])));
759 }
760 });
761 });
762}
763
765{
766 using GT = TypeParam;
767 Built<GT> b(halves());
768 for_each_filter<GT>([&] (auto sa, const char * name)
769 {
770 using SA = decltype(sa);
771 constexpr bool hiding = hides<GT, SA>;
772 SCOPED_TRACE(name);
773 for_each_constness(b.g, [&] (auto & g)
774 {
775 Test_For_Path<GT, SA> test(sa);
776 EXPECT_EQ(test(g, b.nodes[0], b.nodes[3]), not hiding);
777
778 if constexpr (default_built<SA>)
779 {
780 EXPECT_TRUE((Test_For_Path<GT, SA>()(g, b.nodes[0], b.nodes[3])));
781 }
782 });
783 });
784}
Bidirectional BFS for shortest unweighted path.
Bidirectional BFS for finding shortest unweighted paths.
Computation of cut nodes (articulation points) of a graph.
void compute_blocks(DynDlist< GT > &block_list, GT &cut_graph, DynDlist< typename GT::Arc * > &cross_arc_list)
Build mapped graphs around cut nodes.
Path search on directed graphs defined through a graph class (not a digraph).
Path< GT > dfs(typename GT::Node *start, Op &op)
Path< GT > bfs(typename GT::Node *start, Op &op)
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.
const size_t & size() const noexcept
Return the number of elements (constant time)
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.
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.
constexpr bool is_empty() const noexcept
Definition htlist.H:434
Determines whether a graph contains cycles.
Determines whether a graph is acyclic (contains no cycles).
Node * get_first_node() const
Return any node in the graph.
Definition tpl_graph.H:590
Path on a graph.
Definition tpl_graph.H:3832
Node * get_first_node() const
Return the first node of path; throws overflow_error if path is empty.
Definition tpl_graph.H:4316
bool is_empty() const noexcept
Return true if the path is empty.
Definition tpl_graph.H:3993
Node * get_last_node() const
Return the last node of path; throws overflow_error if path is empty.
Definition tpl_graph.H:4323
void for_each_arc(Operation op=Operation()) const
Execute an operation on each arc of path.
Definition tpl_graph.H:4540
Compute the connected components of a graph.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
Definition graph-dry.H:854
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Definition graph-dry.H:975
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_it()
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:663
Determines if a graph g is connected.
__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
What the files of the contract matrix of the graph templates, graph_contract_matrix_*_test....
TYPED_TEST(ContractSearchAll, FindPathDepthFirst)
TYPED_TEST_SUITE(ContractSearchAll, All_Kinds)
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.
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
DynArray< Graph::Arc * > arcs
Definition graphpic.C:408
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
void for_each_constness(GT &g, F &&f)
Calls f(g) with g as it is and as a const graph.
constexpr int Hidden
The number of the arc that the filters hide.
::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.
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.
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< std::array< int, 2 > > arcs
void test()
Definition test-comb.C:40
Gsl_Compatible_Rng r
Graph connectivity and connected components.
Articulation points (cut nodes), bridges, and biconnected components.
Path finding algorithms in graphs.
Generic graph and digraph implementations.
Spanning tree generation algorithms.
DAG (acyclic) graph testing.
Graph connectivity testing.
Cycle detection in graphs.
Path existence testing.
DynList< int > l