Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test_bidirectional_bfs.cc
Go to the documentation of this file.
1
9# include <gtest/gtest.h>
10# include <Bidirectional_BFS.H>
11# include <tpl_find_path.H>
12# include <tpl_graph.H>
13# include <tpl_sgraph.H>
14# include <tpl_agraph.H>
15
16using namespace Aleph;
17
18// ============================================================================
19// Type aliases
20// ============================================================================
21
23using Node = GT::Node;
24using Arc = GT::Arc;
25
28using DArc = DGT::Arc;
29
30// Helper: count path length (number of edges)
31template <class G>
33{
34 if (p.is_empty())
35 return 0;
36 size_t count = 0;
37 for (typename Path<G>::Iterator it(p); it.has_curr(); it.next())
38 ++count;
39 return count > 0 ? count - 1 : 0; // nodes - 1 = edges
40}
41
42// ============================================================================
43// TEST 1: Basic shortest path
44// ============================================================================
45TEST(BidirectionalBFS, BasicShortestPath)
46{
47 GT g;
48 auto n0 = g.insert_node(0);
49 auto n1 = g.insert_node(1);
50 auto n2 = g.insert_node(2);
51 auto n3 = g.insert_node(3);
52
53 g.insert_arc(n0, n1, 0);
54 g.insert_arc(n1, n2, 0);
55 g.insert_arc(n2, n3, 0);
56 g.insert_arc(n0, n3, 0); // direct edge
57
59 Path<GT> path(g);
60 bool found = bibfs(g, n0, n3, path);
61
62 ASSERT_TRUE(found);
63 EXPECT_EQ(path_edge_count(path), 1u); // direct edge n0->n3
64}
65
66// ============================================================================
67// TEST 2: Path to self
68// ============================================================================
69TEST(BidirectionalBFS, PathToSelf)
70{
71 GT g;
72 auto n0 = g.insert_node(0);
73
75 Path<GT> path(g);
76 bool found = bibfs(g, n0, n0, path);
77
78 EXPECT_TRUE(found);
79}
80
81// ============================================================================
82// TEST 3: No path exists
83// ============================================================================
84TEST(BidirectionalBFS, NoPathExists)
85{
86 GT g;
87 auto n0 = g.insert_node(0);
88 auto n1 = g.insert_node(1);
89
91 Path<GT> path(g);
92 bool found = bibfs(g, n0, n1, path);
93
94 EXPECT_FALSE(found);
95}
96
97// ============================================================================
98// TEST 4: Single node
99// ============================================================================
100TEST(BidirectionalBFS, SingleNode)
101{
102 GT g;
103 auto n0 = g.insert_node(0);
104
106 Path<GT> path(g);
107 bool found = bibfs(g, n0, n0, path);
108
109 EXPECT_TRUE(found);
110}
111
112// ============================================================================
113// TEST 5: Linear chain
114// ============================================================================
115TEST(BidirectionalBFS, LinearChain)
116{
117 GT g;
118 auto n0 = g.insert_node(0);
119 auto n1 = g.insert_node(1);
120 auto n2 = g.insert_node(2);
121 auto n3 = g.insert_node(3);
122
123 g.insert_arc(n0, n1, 0);
124 g.insert_arc(n1, n2, 0);
125 g.insert_arc(n2, n3, 0);
126
128 Path<GT> path(g);
129 bool found = bibfs(g, n0, n3, path);
130
131 ASSERT_TRUE(found);
132 EXPECT_EQ(path_edge_count(path), 3u);
133}
134
135// ============================================================================
136// TEST 6: Complete graph K4
137// ============================================================================
138TEST(BidirectionalBFS, CompleteGraphK4)
139{
140 GT g;
141 auto n0 = g.insert_node(0);
142 auto n1 = g.insert_node(1);
143 auto n2 = g.insert_node(2);
144 auto n3 = g.insert_node(3);
145
146 g.insert_arc(n0, n1, 0);
147 g.insert_arc(n0, n2, 0);
148 g.insert_arc(n0, n3, 0);
149 g.insert_arc(n1, n2, 0);
150 g.insert_arc(n1, n3, 0);
151 g.insert_arc(n2, n3, 0);
152
154 Path<GT> path(g);
155 bool found = bibfs(g, n0, n3, path);
156
157 ASSERT_TRUE(found);
158 EXPECT_EQ(path_edge_count(path), 1u); // direct edge
159}
160
161// ============================================================================
162// TEST 7: Null node validation
163// ============================================================================
164TEST(BidirectionalBFS, NullNodeValidation)
165{
166 GT g;
167 auto n0 = g.insert_node(0);
168
170 Path<GT> path(g);
171
172 EXPECT_THROW(bibfs(g, nullptr, n0, path), std::domain_error);
173 EXPECT_THROW(bibfs(g, n0, nullptr, path), std::domain_error);
174}
175
176// ============================================================================
177// TEST 8: Disconnected components
178// ============================================================================
179TEST(BidirectionalBFS, DisconnectedComponents)
180{
181 GT g;
182 auto n0 = g.insert_node(0);
183 auto n1 = g.insert_node(1);
184 auto n2 = g.insert_node(2);
185 auto n3 = g.insert_node(3);
186
187 g.insert_arc(n0, n1, 0);
188 g.insert_arc(n2, n3, 0);
189
191 Path<GT> path(g);
192 bool found = bibfs(g, n0, n3, path);
193
194 EXPECT_FALSE(found);
195}
196
197// ============================================================================
198// TEST 9: Two-node graph
199// ============================================================================
200TEST(BidirectionalBFS, TwoNodeGraph)
201{
202 GT g;
203 auto n0 = g.insert_node(0);
204 auto n1 = g.insert_node(1);
205
206 g.insert_arc(n0, n1, 0);
207
209 Path<GT> path(g);
210 bool found = bibfs(g, n0, n1, path);
211
212 ASSERT_TRUE(found);
213 EXPECT_EQ(path_edge_count(path), 1u);
214}
215
216// ============================================================================
217// TEST 10: Graph with cycle
218// ============================================================================
219TEST(BidirectionalBFS, GraphWithCycle)
220{
221 GT g;
222 auto n0 = g.insert_node(0);
223 auto n1 = g.insert_node(1);
224 auto n2 = g.insert_node(2);
225 auto n3 = g.insert_node(3);
226
227 // Cycle: n0-n1-n2-n3-n0
228 g.insert_arc(n0, n1, 0);
229 g.insert_arc(n1, n2, 0);
230 g.insert_arc(n2, n3, 0);
231 g.insert_arc(n3, n0, 0);
232
234 Path<GT> path(g);
235 bool found = bibfs(g, n0, n2, path);
236
237 ASSERT_TRUE(found);
238 EXPECT_EQ(path_edge_count(path), 2u); // n0->n1->n2 or n0->n3->n2
239}
240
241// ============================================================================
242// TEST 11: Odd-length path
243// ============================================================================
244TEST(BidirectionalBFS, OddLengthPath)
245{
246 GT g;
247 auto n0 = g.insert_node(0);
248 auto n1 = g.insert_node(1);
249 auto n2 = g.insert_node(2);
250
251 g.insert_arc(n0, n1, 0);
252 g.insert_arc(n1, n2, 0);
253
255 Path<GT> path(g);
256 bool found = bibfs(g, n0, n2, path);
257
258 ASSERT_TRUE(found);
259
260 // Verify exact path: n0 -> n1 -> n2
262 for (Path<GT>::Iterator it(path); it.has_curr(); it.next())
263 nodes.append(it.get_current_node()->get_info());
264
265 ASSERT_EQ(nodes.size(), 3u);
266 auto pit = nodes.get_it();
267 EXPECT_EQ(pit.get_curr(), 0); pit.next();
268 EXPECT_EQ(pit.get_curr(), 1); pit.next();
269 EXPECT_EQ(pit.get_curr(), 2);
270}
271
272// ============================================================================
273// TEST 12: Even-length path
274// ============================================================================
275TEST(BidirectionalBFS, EvenLengthPath)
276{
277 GT g;
278 auto n0 = g.insert_node(0);
279 auto n1 = g.insert_node(1);
280 auto n2 = g.insert_node(2);
281 auto n3 = g.insert_node(3);
282
283 g.insert_arc(n0, n1, 0);
284 g.insert_arc(n1, n2, 0);
285 g.insert_arc(n2, n3, 0);
286
288 Path<GT> path(g);
289 bool found = bibfs(g, n0, n3, path);
290
291 ASSERT_TRUE(found);
292 EXPECT_EQ(path_edge_count(path), 3u);
293}
294
295// ============================================================================
296// TEST 13: Cross-validation with standard BFS
297// ============================================================================
298TEST(BidirectionalBFS, CrossValidationWithBFS)
299{
300 GT g;
301 auto n0 = g.insert_node(0);
302 auto n1 = g.insert_node(1);
303 auto n2 = g.insert_node(2);
304 auto n3 = g.insert_node(3);
305 auto n4 = g.insert_node(4);
306
307 g.insert_arc(n0, n1, 0);
308 g.insert_arc(n0, n2, 0);
309 g.insert_arc(n1, n3, 0);
310 g.insert_arc(n2, n4, 0);
311 g.insert_arc(n3, n4, 0);
312
313 // Bidirectional BFS
315 Path<GT> bi_path(g);
316 bool bi_found = bibfs(g, n0, n4, bi_path);
317
318 // Standard BFS
320 Path<GT> std_path(g);
321 bool std_found = std_bfs(g, n0, n4, std_path);
322
323 EXPECT_EQ(bi_found, std_found);
324 if (bi_found and std_found)
325 {
326 EXPECT_EQ(path_edge_count(bi_path), path_edge_count(std_path));
327 }
328}
329
330// ============================================================================
331// TEST 14: Multiple successive computations
332// ============================================================================
333TEST(BidirectionalBFS, MultipleComputations)
334{
335 GT g;
336 auto n0 = g.insert_node(0);
337 auto n1 = g.insert_node(1);
338 auto n2 = g.insert_node(2);
339
340 g.insert_arc(n0, n1, 0);
341 g.insert_arc(n1, n2, 0);
342
344
345 Path<GT> p1(g);
346 EXPECT_TRUE(bibfs(g, n0, n2, p1));
347
348 Path<GT> p2(g);
349 EXPECT_TRUE(bibfs(g, n2, n0, p2));
350
351 EXPECT_EQ(path_edge_count(p1), path_edge_count(p2));
352}
353
354// ============================================================================
355// TEST 15: Large graph
356// ============================================================================
357TEST(BidirectionalBFS, LargeGraph)
358{
359 GT g;
360 const int N = 200;
361
363 for (int i = 0; i < N; ++i)
364 nodes[i] = g.insert_node(i);
365
366 for (int i = 0; i < N - 1; ++i)
367 g.insert_arc(nodes[i], nodes[i + 1], 0);
368
370 Path<GT> path(g);
371 bool found = bibfs(g, nodes[0], nodes[N - 1], path);
372
373 ASSERT_TRUE(found);
374 EXPECT_EQ(path_edge_count(path), static_cast<size_t>(N - 1));
375}
376
377// ============================================================================
378// TEST 16: Operator returning Path
379// ============================================================================
380TEST(BidirectionalBFS, OperatorReturnsPath)
381{
382 GT g;
383 auto n0 = g.insert_node(0);
384 auto n1 = g.insert_node(1);
385 auto n2 = g.insert_node(2);
386
387 g.insert_arc(n0, n1, 0);
388 g.insert_arc(n1, n2, 0);
389
391 auto path = bibfs(g, n0, n2);
392
393 EXPECT_FALSE(path.is_empty());
394 EXPECT_EQ(path_edge_count(path), 2u);
395}
396
397// ============================================================================
398// TEST 17: Star graph
399// ============================================================================
400TEST(BidirectionalBFS, StarGraph)
401{
402 GT g;
403 auto center = g.insert_node(0);
404 auto n1 = g.insert_node(1);
405 auto n2 = g.insert_node(2);
406 auto n3 = g.insert_node(3);
407 auto n4 = g.insert_node(4);
408
409 g.insert_arc(center, n1, 0);
410 g.insert_arc(center, n2, 0);
411 g.insert_arc(center, n3, 0);
412 g.insert_arc(center, n4, 0);
413
415 Path<GT> path(g);
416 bool found = bibfs(g, n1, n4, path);
417
418 ASSERT_TRUE(found);
419 EXPECT_EQ(path_edge_count(path), 2u); // n1->center->n4
420}
421
422// ============================================================================
423// TEST 18: Binary tree-like graph
424// ============================================================================
425TEST(BidirectionalBFS, BinaryTreeGraph)
426{
427 GT g;
428 // 0
429 // / \ (backslash)
430 // 1 2
431 // /| |\ (backslash)
432 // 3 4 5 6
433 auto n0 = g.insert_node(0);
434 auto n1 = g.insert_node(1);
435 auto n2 = g.insert_node(2);
436 auto n3 = g.insert_node(3);
437 auto n4 = g.insert_node(4);
438 auto n5 = g.insert_node(5);
439 auto n6 = g.insert_node(6);
440
441 g.insert_arc(n0, n1, 0);
442 g.insert_arc(n0, n2, 0);
443 g.insert_arc(n1, n3, 0);
444 g.insert_arc(n1, n4, 0);
445 g.insert_arc(n2, n5, 0);
446 g.insert_arc(n2, n6, 0);
447
449 Path<GT> path(g);
450 bool found = bibfs(g, n3, n6, path);
451
452 ASSERT_TRUE(found);
453 EXPECT_EQ(path_edge_count(path), 4u); // n3->n1->n0->n2->n6
454}
455
456// ============================================================================
457// TEST 19: Digraph forward only
458// ============================================================================
459TEST(BidirectionalBFS, DigraphForward)
460{
461 DGT g;
462 auto n0 = g.insert_node(0);
463 auto n1 = g.insert_node(1);
464 auto n2 = g.insert_node(2);
465
466 g.insert_arc(n0, n1, 0);
467 g.insert_arc(n1, n2, 0);
468
469 // For digraphs, we need Out_Iterator for forward and In_Iterator for backward
471 Path<DGT> path(g);
472 bool found = bibfs(g, n0, n2, path);
473
474 ASSERT_TRUE(found);
475 EXPECT_EQ(path_edge_count(path), 2u);
476}
477
478// ============================================================================
479// TEST 20: Digraph no backward path
480// ============================================================================
481TEST(BidirectionalBFS, DigraphNoBackward)
482{
483 DGT g;
484 auto n0 = g.insert_node(0);
485 auto n1 = g.insert_node(1);
486
487 g.insert_arc(n0, n1, 0);
488
490 Path<DGT> p2(g);
491 bool found = bibfs(g, n1, n0, p2);
492
493 EXPECT_FALSE(found);
494}
495
496// ============================================================================
497// TEST 21: Digraph with In_Iterator backward search
498// ============================================================================
499TEST(BidirectionalBFS, DigraphInIteratorBackward)
500{
501 DGT g;
502 auto n0 = g.insert_node(0);
503 auto n1 = g.insert_node(1);
504 auto n2 = g.insert_node(2);
505 auto n3 = g.insert_node(3);
506
507 g.insert_arc(n0, n1, 0);
508 g.insert_arc(n1, n2, 0);
509 g.insert_arc(n2, n3, 0);
510
512 Path<DGT> path(g);
513 bool found = bibfs(g, n0, n3, path);
514
515 ASSERT_TRUE(found);
516 EXPECT_EQ(path_edge_count(path), 3u);
517
518 // Verify path
520 for (Path<DGT>::Iterator it(path); it.has_curr(); it.next())
521 nodes.append(it.get_current_node()->get_info());
522
523 ASSERT_EQ(nodes.size(), 4u);
524 auto pit = nodes.get_it();
525 EXPECT_EQ(pit.get_curr(), 0); pit.next();
526 EXPECT_EQ(pit.get_curr(), 1); pit.next();
527 EXPECT_EQ(pit.get_curr(), 2); pit.next();
528 EXPECT_EQ(pit.get_curr(), 3);
529}
530
531// ============================================================================
532// TEST 21b: Digraph whose search goes backward before it meets: the arcs
533// into each node come from an In_Arcs_Index, since a digraph keeps each
534// arc only in the list of its source
535// ============================================================================
536template <class G>
537void diamond_backward(bool says_directed = false)
538{
539 // 0 -> 1, 0 -> 2, 1 -> 3, 2 -> 3, and 4 -> 3, which the forward search
540 // does not reach: the forward frontier {1, 2} is larger than {3}, so
541 // the search goes back from 3. A graph of an undirected type that says
542 // that it is directed keeps each arc in the list of its source too
543 G g;
544 if (says_directed)
545 g.set_digraph(true);
546 typename G::Node * n[5];
547 for (int i = 0; i < 5; ++i)
548 n[i] = g.insert_node(i);
549 g.insert_arc(n[0], n[1], 0);
550 g.insert_arc(n[0], n[2], 0);
551 g.insert_arc(n[1], n[3], 0);
552 g.insert_arc(n[2], n[3], 0);
553 g.insert_arc(n[4], n[3], 0);
554
556 Path<G> path(g);
557 ASSERT_TRUE(bibfs(g, n[0], n[3], path));
558 EXPECT_EQ(path.size(), 3u);
559 EXPECT_EQ(path.get_first_node(), n[0]);
560 EXPECT_EQ(path.get_last_node(), n[3]);
561 EXPECT_TRUE(path.check_directed());
562
563 // No path against the arcs, and none from a node that nothing reaches
564 Path<G> none(g);
565 EXPECT_FALSE(bibfs(g, n[3], n[0], none));
566 EXPECT_FALSE(bibfs(g, n[1], n[4], none));
567 EXPECT_TRUE(bibfs(g, n[4], n[3], none));
568 EXPECT_EQ(none.size(), 2u);
569}
570
571TEST(BidirectionalBFS, DigraphBackwardStepsSeeTheArcsIntoEachNode)
572{
573 diamond_backward<DGT>();
574 diamond_backward<List_SDigraph<Graph_Snode<int>, Graph_Sarc<int>>>();
575 diamond_backward<Array_Digraph<Graph_Anode<int>, Graph_Aarc<int>>>();
576}
577
578// The search decides by the graph, not only by its type: one of an
579// undirected type that says that it is directed goes back by the index too
580TEST(BidirectionalBFS, AGraphThatSaysThatItIsDirectedSeesTheArcsIntoEachNode)
581{
582 diamond_backward<GT>(true);
583 diamond_backward<List_SGraph<Graph_Snode<int>, Graph_Sarc<int>>>(true);
584 diamond_backward<Array_Graph<Graph_Anode<int>, Graph_Aarc<int>>>(true);
585}
586
587// ============================================================================
588// === EXAMPLE: Social network ===
589// Find the shortest connection between two people in a social network.
590//
591// Alice -- Bob -- Charlie
592// | |
593// Diana -- Eve -- Frank
594//
595// Shortest Alice->Frank: Alice->Diana->Eve->Frank (3 hops)
596// or Alice->Bob->Charlie->Frank (3 hops)
597// ============================================================================
598TEST(BidirectionalBFS, SocialNetworkExample)
599{
600 GT g;
601 auto alice = g.insert_node(0); // Alice
602 auto bob = g.insert_node(1); // Bob
603 auto charlie = g.insert_node(2); // Charlie
604 auto diana = g.insert_node(3); // Diana
605 auto eve = g.insert_node(4); // Eve
606 auto frank = g.insert_node(5); // Frank
607
608 g.insert_arc(alice, bob, 0);
609 g.insert_arc(bob, charlie, 0);
610 g.insert_arc(charlie, frank, 0);
611 g.insert_arc(alice, diana, 0);
612 g.insert_arc(diana, eve, 0);
613 g.insert_arc(eve, frank, 0);
614
616 Path<GT> path(g);
617 bool found = bibfs(g, alice, frank, path);
618
619 ASSERT_TRUE(found);
620 EXPECT_EQ(path_edge_count(path), 3u);
621}
622
623// ============================================================================
624// TEST 23: Path correctness (first and last node)
625// ============================================================================
626TEST(BidirectionalBFS, PathEndsCorrectness)
627{
628 GT g;
629 auto n0 = g.insert_node(0);
630 auto n1 = g.insert_node(1);
631 auto n2 = g.insert_node(2);
632 auto n3 = g.insert_node(3);
633 auto n4 = g.insert_node(4);
634
635 g.insert_arc(n0, n1, 0);
636 g.insert_arc(n1, n2, 0);
637 g.insert_arc(n2, n3, 0);
638 g.insert_arc(n3, n4, 0);
639
641 Path<GT> path(g);
642 bool found = bibfs(g, n0, n4, path);
643
644 ASSERT_TRUE(found);
645
646 // Verify first node is n0 and last is n4
648 for (Path<GT>::Iterator it(path); it.has_curr(); it.next())
649 nodes.append(it.get_current_node()->get_info());
650
651 ASSERT_GE(nodes.size(), 2u);
652 EXPECT_EQ(nodes.get_first(), 0);
653 EXPECT_EQ(nodes.get_last(), 4);
654}
655
656// ============================================================================
657// TEST 24: Cross-validation with BFS on various endpoints
658// ============================================================================
659TEST(BidirectionalBFS, CrossValidationMultipleEndpoints)
660{
661 GT g;
662 const int N = 10;
663
665 for (int i = 0; i < N; ++i)
666 nodes[i] = g.insert_node(i);
667
668 // Create a connected graph
669 for (int i = 0; i < N - 1; ++i)
670 g.insert_arc(nodes[i], nodes[i + 1], 0);
671
672 // Add some shortcuts
673 g.insert_arc(nodes[0], nodes[5], 0);
674 g.insert_arc(nodes[3], nodes[8], 0);
675
676 for (int start = 0; start < N; start += 3)
677 for (int end = start + 1; end < N; end += 2)
678 {
681
682 Path<GT> bi_path(g), std_path(g);
683 bool bi_found = bibfs(g, nodes[start], nodes[end], bi_path);
684 bool std_found = std_bfs(g, nodes[start], nodes[end], std_path);
685
686 EXPECT_EQ(bi_found, std_found)
687 << "Mismatch for start=" << start << " end=" << end;
688 if (bi_found and std_found)
689 {
690 EXPECT_EQ(path_edge_count(bi_path), path_edge_count(std_path))
691 << "Length mismatch for start=" << start << " end=" << end;
692 }
693 }
694}
695
696// ============================================================================
697// TEST 25: Grid graph
698// ============================================================================
699TEST(BidirectionalBFS, GridGraph)
700{
701 GT g;
702 const int ROWS = 4, COLS = 4;
703 Node * grid[ROWS][COLS];
704
705 for (int r = 0; r < ROWS; ++r)
706 for (int c = 0; c < COLS; ++c)
707 grid[r][c] = g.insert_node(r * COLS + c);
708
709 for (int r = 0; r < ROWS; ++r)
710 for (int c = 0; c < COLS; ++c)
711 {
712 if (c + 1 < COLS)
713 g.insert_arc(grid[r][c], grid[r][c + 1], 0);
714 if (r + 1 < ROWS)
715 g.insert_arc(grid[r][c], grid[r + 1][c], 0);
716 }
717
719 Path<GT> path(g);
720 bool found = bibfs(g, grid[0][0], grid[ROWS - 1][COLS - 1], path);
721
722 ASSERT_TRUE(found);
723 // Manhattan distance = (ROWS-1) + (COLS-1)
724 EXPECT_EQ(path_edge_count(path), static_cast<size_t>(ROWS + COLS - 2));
725}
726
727// ============================================================================
728// TEST 26: Meeting-point regression (must return shortest path)
729// ============================================================================
730TEST(BidirectionalBFS, MeetingPointDepthSumRegression)
731{
732 GT g;
733 auto s = g.insert_node(0);
734 auto a1 = g.insert_node(1);
735 auto a2 = g.insert_node(2);
736 auto a3 = g.insert_node(3);
737 auto b1 = g.insert_node(4);
738 auto b2 = g.insert_node(5);
739 auto t = g.insert_node(6);
740
741 // Longer branch: s-a1-a2-a3-t (4 edges)
742 g.insert_arc(s, a1, 0);
743 g.insert_arc(a1, a2, 0);
744 g.insert_arc(a2, a3, 0);
745 g.insert_arc(a3, t, 0);
746
747 // Shorter branch: s-b1-b2-t (3 edges)
748 g.insert_arc(s, b1, 0);
749 g.insert_arc(b1, b2, 0);
750 g.insert_arc(b2, t, 0);
751
754
755 Path<GT> bi_path(g), std_path(g);
756 ASSERT_TRUE(bibfs(g, s, t, bi_path));
757 ASSERT_TRUE(std_bfs(g, s, t, std_path));
758
759 EXPECT_EQ(path_edge_count(bi_path), 3u);
760 EXPECT_EQ(path_edge_count(bi_path), path_edge_count(std_path));
761}
Bidirectional BFS for shortest unweighted path.
WeightedDigraph::Node Node
WeightedDigraph::Arc Arc
static Array create(const size_t n)
Create an array with n logical elements.
Definition tpl_array.H:245
Bidirectional BFS for finding shortest unweighted paths.
auto has_curr() const noexcept(noexcept(std::declval< I & >().has_curr())) -> decltype(std::declval< I & >().has_curr())
true if there is a current item.
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:4377
typename BaseGraph::Arc Arc
Definition graph-dry.H:4381
typename BaseGraph::Node Node
Definition graph-dry.H:4380
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
T & append(const T &item)
Definition htlist.H:1362
Performs a breadth-first search for a path between a pair of nodes.
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
Graph_Arc< int > Arc
The node class type.
Definition tpl_graph.H:444
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:618
Number Theoretic Transform over Z / MOD Z.
Definition ntt.H:115
Iterator on nodes and arcs of a path.
Definition tpl_graph.H:4395
Path on a graph.
Definition tpl_graph.H:3832
size_t size() const noexcept
Return the path length in nodes.
Definition tpl_graph.H:3987
bool check_directed() const
Return true if the directed path is consistent: each arc goes from its node to the next one,...
Definition tpl_graph.H:3904
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 set_digraph(bool val)
Temporal indication for preventing to other algorithms that an graph must be treated as a directed gr...
Definition graph-dry.H:972
#define TEST(name)
#define N
Definition fib.C:294
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
bool none(const Container &container, Operation &operation)
Return true if no element satisfies operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:231
size_t path_edge_count(Path< G > &p)
DGT::Arc DArc
DGT::Node DNode
void diamond_backward(bool says_directed=false)
Gsl_Compatible_Rng r
Array-based graph implementation.
Path finding algorithms in graphs.
Generic graph and digraph implementations.
Simple graph implementation with adjacency lists.