Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
const_graph_view_test.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / /
6 / ___ \| | __/ |_) | | | |_____\ V V /
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2026 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32
40#include <gtest/gtest.h>
41
42#include <Bellman_Ford.H>
43#include <Dijkstra.H>
44#include <Negative_Cycles.H>
45#include <ah-graph-concepts.H>
46#include <filter_iterator.H>
47#include <tpl_agraph.H>
49#include <tpl_graph.H>
50#include <tpl_sgraph.H>
51
52#include <stdexcept>
53#include <type_traits>
54#include <utility>
55#include <vector>
56
57using namespace Aleph;
58
59namespace
60{
61 // The expressions that a reader must not be able to write. They are
62 // templates so that an ill-formed expression makes the requires-expression
63 // false instead of making the program ill-formed.
64 template <class It>
65 constexpr bool writes_the_information_through = requires (It it)
66 {
67 it.get_curr()->get_info() = 1;
68 };
69
70 template <class It>
71 constexpr bool writes_the_node_bookkeeping_through = requires (It it)
72 {
73 NODE_COOKIE(it.get_curr()) = nullptr;
74 }
75 or requires (It it) { NODE_COUNTER(it.get_curr()) = 1; }
76 or requires (It it) { NODE_BITS(it.get_curr()).set_bit(Depth_First, 1); };
77
78 template <class It>
79 constexpr bool writes_the_arc_bookkeeping_through = requires (It it)
80 {
81 ARC_COOKIE(it.get_curr()) = nullptr;
82 }
83 or requires (It it) { ARC_COUNTER(it.get_curr()) = 1; }
84 or requires (It it) { ARC_BITS(it.get_curr()).set_bit(Depth_First, 1); };
85
86 template <class It>
87 constexpr bool writes_the_end_points_through = requires (It it)
88 {
89 it.get_src_node()->get_info() = 1;
90 }
91 or requires (It it) { it.get_tgt_node()->get_info() = 1; };
92
93 template <class It>
94 constexpr bool removes_through = requires (It it) { it.del(); };
95
96 // Whether a traversal accepts an operation that demands the pointer P.
97 template <class G, class P>
98 constexpr bool for_each_node_takes = requires (const G & g)
99 {
100 g.for_each_node([] (P) {});
101 };
102
103 template <class G, class P>
104 constexpr bool for_each_arc_takes = requires (const G & g)
105 {
106 g.for_each_arc([] (P) {});
107 };
108
109 template <class G, class N, class P>
110 constexpr bool for_each_arc_of_a_node_takes = requires (const G & g, N p)
111 {
112 g.for_each_arc(p, [] (P) {});
113 };
114
115 template <class G, class P>
116 constexpr bool traverse_nodes_takes = requires (const G & g)
117 {
118 g.traverse_nodes([] (P) { return true; });
119 };
120
121 template <class G, class P>
122 constexpr bool traverse_arcs_takes = requires (const G & g)
123 {
124 g.traverse_arcs([] (P) { return true; });
125 };
126
127 template <class G, class P>
128 constexpr bool search_node_takes = requires (const G & g)
129 {
130 g.search_node([] (P) { return true; });
131 };
132
133 template <class G, class P>
134 constexpr bool search_arc_takes = requires (const G & g)
135 {
136 g.search_arc([] (P) { return true; });
137 };
138
139 template <class G, class P>
140 constexpr bool filter_arcs_takes = requires (const G & g)
141 {
142 g.filter_arcs([] (P) { return true; });
143 };
144
145 template <class G, class P>
146 constexpr bool free_for_each_arc_takes = requires (const G & g)
147 {
148 Aleph::for_each_arc(g, [] (P) {});
149 };
150
151 // Whether const_view() accepts an expression of type and category G.
152 template <class G>
153 constexpr bool const_view_accepts = requires
154 {
155 const_view(std::declval<G>());
156 };
157
158 // Arc filters and distances written for a reader and for a writer.
159 template <class A>
160 struct Reads_Arc
161 {
162 bool operator () (const A *a) const noexcept { return a->get_info() >= 30; }
163 };
164
165 template <class A>
166 struct Writes_Arc
167 {
168 bool operator () (A *a) const noexcept { return ++a->get_info() > 0; }
169 };
170
171 template <class N>
172 struct Reads_Node
173 {
174 bool operator () (const N *p) const noexcept { return p->get_info() % 2 == 0; }
175 };
176
177 // Five nodes 0..4 and six arcs; no loops and no parallel arcs.
178 template <class G>
179 struct Sample
180 {
181 G g;
182 std::vector<typename G::Node *> nodes;
183 std::vector<typename G::Arc *> arcs;
184
185 Sample()
186 {
187 for (int i = 0; i < 5; ++i)
188 nodes.push_back(g.insert_node(i));
189 arcs.push_back(g.insert_arc(nodes[0], nodes[1], 10));
190 arcs.push_back(g.insert_arc(nodes[1], nodes[2], 20));
191 arcs.push_back(g.insert_arc(nodes[2], nodes[0], 30));
192 arcs.push_back(g.insert_arc(nodes[2], nodes[3], 40));
193 arcs.push_back(g.insert_arc(nodes[3], nodes[4], 50));
194 arcs.push_back(g.insert_arc(nodes[0], nodes[3], 60));
195 }
196 };
197
198 template <class G>
199 class ConstGraphView : public ::testing::Test {};
200
201 using Graph_Types = ::testing::Types<
208
209 TYPED_TEST_SUITE(ConstGraphView, Graph_Types);
210}
211
212TYPED_TEST(ConstGraphView, the_iterators_hand_out_pointers_to_const)
213{
214 using G = TypeParam;
215 using Node = typename G::Node;
216 using Arc = typename G::Arc;
217 using View = Const_Graph_View<G>;
218
219 static_assert(std::is_same_v<typename View::Node, const Node>);
220 static_assert(std::is_same_v<typename View::Arc, const Arc>);
221 static_assert(std::is_same_v<typename View::Node_Iterator, Const_Node_Iterator<G>>);
222 static_assert(std::is_same_v<typename View::Arc_Iterator, Const_Arc_Iterator<G>>);
223 static_assert(std::is_same_v<typename View::Node_Arc_Iterator, Const_Node_Arc_Iterator<G>>);
224
225 using NIt = Const_Node_Iterator<G>;
226 using AIt = Const_Arc_Iterator<G>;
227 using NAIt = Const_Node_Arc_Iterator<G>;
228
229 static_assert(std::is_same_v<typename NIt::Item_Type, const Node *>);
230 static_assert(std::is_same_v<typename AIt::Item_Type, const Arc *>);
231 static_assert(std::is_same_v<typename NAIt::Item_Type, const Arc *>);
232
233 static_assert(std::is_same_v<decltype(std::declval<NIt &>().get_curr()), const Node *>);
234 static_assert(std::is_same_v<decltype(std::declval<NIt &>().get_curr_ne()), const Node *>);
235 static_assert(std::is_same_v<decltype(std::declval<NIt &>().get_current_node()), const Node *>);
236 static_assert(std::is_same_v<decltype(std::declval<AIt &>().get_curr()), const Arc *>);
237 static_assert(std::is_same_v<decltype(std::declval<AIt &>().get_curr_ne()), const Arc *>);
238 static_assert(std::is_same_v<decltype(std::declval<AIt &>().get_current_arc()), const Arc *>);
239 static_assert(std::is_same_v<decltype(std::declval<AIt &>().get_src_node()), const Node *>);
240 static_assert(std::is_same_v<decltype(std::declval<AIt &>().get_tgt_node()), const Node *>);
241 static_assert(std::is_same_v<decltype(std::declval<NAIt &>().get_curr()), const Arc *>);
242 static_assert(std::is_same_v<decltype(std::declval<NAIt &>().get_curr_ne()), const Arc *>);
243 static_assert(std::is_same_v<decltype(std::declval<NAIt &>().get_tgt_node()), const Node *>);
244
245 // The iterators are built from a constant graph, from a view and, for the
246 // arcs of a node, from a pointer to a constant node.
247 static_assert(std::is_constructible_v<NIt, const G &>);
248 static_assert(std::is_constructible_v<NIt, const View &>);
249 static_assert(std::is_constructible_v<AIt, const G &>);
250 static_assert(std::is_constructible_v<AIt, const View &>);
251 static_assert(std::is_constructible_v<NAIt, const Node *>);
252
253 // The information and the bookkeeping are read-only through them...
254 static_assert(not writes_the_information_through<NIt>);
255 static_assert(not writes_the_information_through<AIt>);
256 static_assert(not writes_the_information_through<NAIt>);
257 static_assert(not writes_the_node_bookkeeping_through<NIt>);
258 static_assert(not writes_the_arc_bookkeeping_through<AIt>);
259 static_assert(not writes_the_arc_bookkeeping_through<NAIt>);
260 static_assert(not writes_the_end_points_through<AIt>);
261 static_assert(not removes_through<NIt>);
262 static_assert(not removes_through<AIt>);
263 static_assert(not removes_through<NAIt>);
264
265 // ...while the iterators of the graph keep handing out modifiable nodes
266 // and arcs, even on a constant graph: its topology is what is constant.
267 static_assert(std::is_constructible_v<typename G::Node_Iterator, const G &>);
268 static_assert(std::is_same_v<decltype(std::declval<typename G::Node_Iterator &>().get_curr()), Node *>);
269 static_assert(std::is_same_v<decltype(std::declval<typename G::Arc_Iterator &>().get_curr()), Arc *>);
270 static_assert(writes_the_information_through<typename G::Node_Iterator>);
271 static_assert(writes_the_information_through<typename G::Arc_Iterator>);
272 static_assert(writes_the_information_through<typename G::Node_Arc_Iterator>);
273 static_assert(writes_the_node_bookkeeping_through<typename G::Node_Iterator>);
274 static_assert(writes_the_arc_bookkeeping_through<typename G::Arc_Iterator>);
275 static_assert(writes_the_end_points_through<typename G::Arc_Iterator>);
276
277 // A view is one pointer and its iterators are the iterators of the graph.
278 static_assert(sizeof(View) == sizeof(void *));
279 static_assert(std::is_trivially_copyable_v<View>);
280 static_assert(sizeof(NIt) == sizeof(typename G::Node_Iterator));
281 static_assert(sizeof(AIt) == sizeof(typename G::Arc_Iterator));
282 static_assert(sizeof(NAIt) == sizeof(typename G::Node_Arc_Iterator));
283
284 // A view is built from a graph that outlives it, never from a temporary.
285 static_assert(std::is_constructible_v<View, const G &>);
286 static_assert(std::is_constructible_v<View, G &>);
287 static_assert(not std::is_constructible_v<View, G>);
288 static_assert(not std::is_constructible_v<View, const G>);
289 static_assert(not std::is_convertible_v<const G &, View>);
290 static_assert(const_view_accepts<G &>);
291 static_assert(const_view_accepts<const G &>);
292 static_assert(not const_view_accepts<G>);
293 static_assert(not const_view_accepts<const G>);
294 static_assert(std::is_same_v<decltype(const_view(std::declval<G &>())), View>);
295
296 SUCCEED();
297}
298
299TYPED_TEST(ConstGraphView, the_operations_receive_pointers_to_const)
300{
301 using G = TypeParam;
302 using Node = typename G::Node;
303 using Arc = typename G::Arc;
304 using View = Const_Graph_View<G>;
305
306 // An operation written for a reader is accepted; one that demands a
307 // modifiable node or arc is rejected.
308 static_assert(for_each_node_takes<View, const Node *>);
309 static_assert(not for_each_node_takes<View, Node *>);
310 static_assert(for_each_arc_takes<View, const Arc *>);
311 static_assert(not for_each_arc_takes<View, Arc *>);
312 static_assert(for_each_arc_of_a_node_takes<View, const Node *, const Arc *>);
313 static_assert(not for_each_arc_of_a_node_takes<View, const Node *, Arc *>);
314 static_assert(traverse_nodes_takes<View, const Node *>);
315 static_assert(not traverse_nodes_takes<View, Node *>);
316 static_assert(traverse_arcs_takes<View, const Arc *>);
317 static_assert(not traverse_arcs_takes<View, Arc *>);
318 static_assert(search_node_takes<View, const Node *>);
319 static_assert(not search_node_takes<View, Node *>);
320 static_assert(search_arc_takes<View, const Arc *>);
321 static_assert(not search_arc_takes<View, Arc *>);
322 static_assert(filter_arcs_takes<View, const Arc *>);
323 static_assert(not filter_arcs_takes<View, Arc *>);
324
325 // The generic functions of the graphs follow the view.
326 static_assert(free_for_each_arc_takes<View, const Arc *>);
327 static_assert(not free_for_each_arc_takes<View, Arc *>);
328
329 // The graph itself takes both: it hands out modifiable nodes and arcs.
330 static_assert(for_each_node_takes<G, Node *>);
331 static_assert(for_each_node_takes<G, const Node *>);
332 static_assert(for_each_arc_takes<G, Arc *>);
333 static_assert(for_each_arc_takes<G, const Arc *>);
334 static_assert(free_for_each_arc_takes<G, Arc *>);
335
336 // What the members of the view hand out.
337 static_assert(std::is_same_v<decltype(std::declval<const View &>().get_first_node()), const Node *>);
338 static_assert(std::is_same_v<decltype(std::declval<const View &>().get_first_arc()), const Arc *>);
339 static_assert(std::is_same_v<decltype(std::declval<const View &>().get_src_node(nullptr)), const Node *>);
340 static_assert(std::is_same_v<decltype(std::declval<const View &>().get_tgt_node(nullptr)), const Node *>);
341 static_assert(std::is_same_v<decltype(std::declval<const View &>().find_node(0)), const Node *>);
342 static_assert(std::is_same_v<decltype(std::declval<const View &>().find_arc(0)), const Arc *>);
343 static_assert(std::is_same_v<decltype(std::declval<const View &>().nodes()), DynList<const Node *>>);
344 static_assert(std::is_same_v<decltype(std::declval<const View &>().arcs()), DynList<const Arc *>>);
345
346 SUCCEED();
347}
348
349TYPED_TEST(ConstGraphView, the_view_and_its_iterators_satisfy_the_graph_concepts)
350{
351 using G = TypeParam;
352 using View = Const_Graph_View<G>;
353
354 static_assert(AlephGraph<View>);
362
363 // They do not pass for iterators on modifiable nodes and arcs.
367
368 // On a view a filter is a condition on a pointer to const.
369 static_assert(NodeFilter<Reads_Node<typename G::Node>, View>);
370 static_assert(ArcFilter<Reads_Arc<typename G::Arc>, View>);
371 static_assert(not ArcFilter<Writes_Arc<typename G::Arc>, View>);
372 static_assert(ArcFilter<Writes_Arc<typename G::Arc>, G>);
373 static_assert(ArcFilter<Reads_Arc<typename G::Arc>, G>);
374
375 SUCCEED();
376}
377
378TYPED_TEST(ConstGraphView, reads_what_the_graph_reads)
379{
380 using G = TypeParam;
381 using Node = typename G::Node;
382 using Arc = typename G::Arc;
383
384 Sample<G> s;
385 const G & g = s.g;
386 const auto view = const_view(g);
387
388 EXPECT_EQ(view.get_num_nodes(), 5u);
389 EXPECT_EQ(view.vsize(), 5u);
390 EXPECT_EQ(view.get_num_arcs(), 6u);
391 EXPECT_EQ(view.esize(), 6u);
392 EXPECT_FALSE(view.is_empty());
393 EXPECT_EQ(view.is_digraph(), g.is_digraph());
394 EXPECT_EQ(view.get_first_node(), g.get_first_node());
395 EXPECT_EQ(view.get_first_arc(), g.get_first_arc());
396
397 // Same nodes, in the same order.
398 {
399 typename G::Node_Iterator git(g);
400 auto vit = view.get_node_it();
401 size_t n = 0;
402 for (; vit.has_curr(); vit.next_ne(), git.next_ne(), ++n)
403 {
404 ASSERT_TRUE(git.has_curr());
405 EXPECT_EQ(vit.get_curr(), git.get_curr());
406 EXPECT_EQ(vit.get_curr_ne(), vit.get_current_node());
407 EXPECT_EQ(vit.get_current_node_ne(), vit.get_curr());
408 }
409 EXPECT_FALSE(git.has_curr());
410 EXPECT_EQ(n, 5u);
411 EXPECT_THROW((void) vit.get_curr(), std::overflow_error);
412
413 vit.reset_first();
414 ASSERT_TRUE(vit.has_curr());
415 EXPECT_EQ(vit.get_curr(), typename G::Node_Iterator(g).get_curr());
416 }
417
418 // Same arcs, in the same order, with the same end points.
419 {
420 typename G::Arc_Iterator git(g);
421 auto vit = view.get_arc_it();
422 size_t n = 0;
423 for (; vit.has_curr(); vit.next_ne(), git.next_ne(), ++n)
424 {
425 ASSERT_TRUE(git.has_curr());
426 const Arc *a = vit.get_curr();
427 EXPECT_EQ(a, git.get_curr());
428 EXPECT_EQ(vit.get_current_arc(), a);
429 EXPECT_EQ(vit.get_current_arc_ne(), a);
430 EXPECT_EQ(vit.get_src_node(), git.get_src_node());
431 EXPECT_EQ(vit.get_tgt_node(), git.get_tgt_node());
432 EXPECT_EQ(vit.get_src_node_ne(), vit.get_src_node());
433 EXPECT_EQ(vit.get_tgt_node_ne(), vit.get_tgt_node());
434 EXPECT_EQ(view.get_src_node(a), g.get_src_node(git.get_curr()));
435 EXPECT_EQ(view.get_tgt_node(a), g.get_tgt_node(git.get_curr()));
436 }
437 EXPECT_FALSE(git.has_curr());
438 EXPECT_EQ(n, 6u);
439 }
440
441 // Same arcs of every node, with the same node at the other end.
442 for (Node *p : s.nodes)
443 {
444 const Node *cp = p;
445 EXPECT_EQ(view.get_num_arcs(cp), g.get_num_arcs(p));
446 EXPECT_EQ(view.degree(cp), g.degree(p));
447
448 typename G::Node_Arc_Iterator git(p);
449 auto vit = view.get_arc_it(cp);
450 size_t n = 0;
451 for (; vit.has_curr(); vit.next_ne(), git.next_ne(), ++n)
452 {
453 ASSERT_TRUE(git.has_curr());
454 EXPECT_EQ(vit.get_curr(), git.get_curr());
455 EXPECT_EQ(vit.get_current_arc(), git.get_curr());
456 EXPECT_EQ(vit.get_current_arc_ne(), git.get_curr());
457 EXPECT_EQ(vit.get_tgt_node(), git.get_tgt_node());
458 EXPECT_EQ(vit.get_tgt_node_ne(), git.get_tgt_node());
459 EXPECT_EQ(view.get_connected_node(vit.get_curr(), cp),
460 g.get_connected_node(git.get_curr(), p));
461 }
462 EXPECT_FALSE(git.has_curr());
463 EXPECT_EQ(view.arcs(cp).size(), n);
464 EXPECT_EQ(view.adjacent_nodes(cp).size(), n);
465 if (n > 0)
466 EXPECT_EQ(view.get_first_arc(cp), g.get_first_arc(p));
467
468 vit.reset_first();
469 EXPECT_EQ(vit.has_curr(), n > 0);
470 }
471
472 // An arc between two nodes is found from the node that holds it.
473 EXPECT_EQ(view.search_arc(s.nodes[0], s.nodes[1]), s.arcs[0]);
474 EXPECT_EQ(view.search_arc(s.nodes[0], s.nodes[1]), g.search_arc(s.nodes[0], s.nodes[1]));
475 EXPECT_EQ(view.search_arc(s.nodes[4], s.nodes[1]), nullptr);
476}
477
478TYPED_TEST(ConstGraphView, the_functional_members_read_the_graph)
479{
480 using G = TypeParam;
481 using Node = typename G::Node;
482 using Arc = typename G::Arc;
483
484 Sample<G> s;
485 const auto view = const_view(s.g);
486
487 int node_sum = 0;
488 view.for_each_node([&node_sum] (const Node *p) { node_sum += p->get_info(); });
489 EXPECT_EQ(node_sum, 0 + 1 + 2 + 3 + 4);
490
491 long arc_sum = 0;
492 view.for_each_arc([&arc_sum] (const Arc *a) { arc_sum += a->get_info(); });
493 EXPECT_EQ(arc_sum, 10 + 20 + 30 + 40 + 50 + 60);
494
495 // The arcs of the node 2, as the graph class sees them.
496 long of_node_2 = 0;
497 s.g.for_each_arc(s.nodes[2], [&of_node_2] (Arc *a) { of_node_2 += a->get_info(); });
498 long seen = 0;
499 view.for_each_arc(s.nodes[2], [&seen] (const Arc *a) { seen += a->get_info(); });
500 EXPECT_EQ(seen, of_node_2);
501 EXPECT_GT(seen, 0);
502
503 // A generic operation is called with pointers to const too.
504 view.for_each_arc([] (auto a)
505 {
506 static_assert(std::is_same_v<decltype(a), const Arc *>);
507 });
508
509 size_t visited = 0;
510 EXPECT_FALSE(view.traverse_nodes([&visited] (const Node *) { return ++visited < 2; }));
511 EXPECT_EQ(visited, 2u);
512 EXPECT_TRUE(view.traverse_nodes([] (const Node *) { return true; }));
513 EXPECT_TRUE(view.traverse_arcs([] (const Arc *a) { return a->get_info() > 0; }));
514 EXPECT_FALSE(view.traverse_arcs([] (const Arc *a) { return a->get_info() < 60; }));
515 EXPECT_TRUE(view.traverse_arcs(s.nodes[2], [] (const Arc *a) { return a->get_info() > 0; }));
516
517 EXPECT_TRUE(view.all_nodes([] (const Node *p) { return p->get_info() < 5; }));
518 EXPECT_FALSE(view.all_nodes([] (const Node *p) { return p->get_info() < 4; }));
519 EXPECT_TRUE(view.all_arcs([] (const Arc *a) { return a->get_info() % 10 == 0; }));
520 EXPECT_FALSE(view.all_arcs([] (const Arc *a) { return a->get_info() > 10; }));
521 EXPECT_TRUE(view.all_arcs(s.nodes[1], [] (const Arc *a) { return a->get_info() <= 20; }));
522 EXPECT_FALSE(view.all_arcs(s.nodes[2], [] (const Arc *a) { return a->get_info() == 30; }));
523
524 EXPECT_TRUE(view.exists_node([] (const Node *p) { return p->get_info() == 3; }));
525 EXPECT_FALSE(view.exists_node([] (const Node *p) { return p->get_info() == 7; }));
526 EXPECT_TRUE(view.exists_arc([] (const Arc *a) { return a->get_info() == 40; }));
527 EXPECT_FALSE(view.exists_arc([] (const Arc *a) { return a->get_info() == 45; }));
528 EXPECT_TRUE(view.exists_arc(s.nodes[2], [] (const Arc *a) { return a->get_info() == 40; }));
529 EXPECT_FALSE(view.exists_arc(s.nodes[2], [] (const Arc *a) { return a->get_info() == 50; }));
530
531 EXPECT_EQ(view.search_node([] (const Node *p) { return p->get_info() == 3; }), s.nodes[3]);
532 EXPECT_EQ(view.search_node([] (const Node *p) { return p->get_info() == 7; }), nullptr);
533 EXPECT_EQ(view.search_arc([] (const Arc *a) { return a->get_info() == 40; }), s.arcs[3]);
534 EXPECT_EQ(view.search_arc([] (const Arc *a) { return a->get_info() == 45; }), nullptr);
535 EXPECT_EQ(view.search_arc(s.nodes[2], [] (const Arc *a) { return a->get_info() == 40; }), s.arcs[3]);
536 EXPECT_EQ(view.search_arc(s.nodes[2], [] (const Arc *a) { return a->get_info() == 50; }), nullptr);
537
538 EXPECT_EQ(view.find_node(4), s.nodes[4]);
539 EXPECT_EQ(view.find_node(9), nullptr);
540 EXPECT_EQ(view.find_arc(60), s.arcs[5]);
541 EXPECT_EQ(view.find_arc(65), nullptr);
542
543 EXPECT_EQ(view.count_nodes([] (const Node *p) { return p->get_info() % 2 == 0; }), 3u);
544 EXPECT_EQ(view.count_arcs([] (const Arc *a) { return a->get_info() >= 30; }), 4u);
545
546 EXPECT_EQ(view.nodes().size(), 5u);
547 EXPECT_EQ(view.arcs().size(), 6u);
548 EXPECT_EQ(view.filter_nodes([] (const Node *p) { return p->get_info() % 2 == 0; }).size(), 3u);
549 EXPECT_EQ(view.filter_arcs([] (const Arc *a) { return a->get_info() >= 30; }).size(), 4u);
550 EXPECT_EQ(view.filter_arcs(s.nodes[3], [] (const Arc *a) { return a->get_info() == 50; }).size(), 1u);
551
552 long mapped = 0;
553 view.nodes_map([] (const Node *p) { return 2 * p->get_info(); }).for_each([&mapped] (int x) { mapped += x; });
554 EXPECT_EQ(mapped, 20);
555 const auto halves = view.template arcs_map<double>([] (const Arc *a) { return a->get_info() / 20.0; });
556 static_assert(std::is_same_v<decltype(halves), const DynList<double>>);
557 double half_sum = 0;
558 halves.for_each([&half_sum] (double x) { half_sum += x; });
559 EXPECT_DOUBLE_EQ(half_sum, 10.5);
560
561 EXPECT_EQ(view.foldl_nodes(100, [] (const int & acc, const Node *p) { return acc + p->get_info(); }), 110);
562 EXPECT_EQ(view.template foldl_arcs<long>(0, [] (const long & acc, const Arc *a) { return acc + a->get_info(); }),
563 210);
564}
565
566TYPED_TEST(ConstGraphView, a_view_is_not_a_snapshot_and_copies_share_the_graph)
567{
568 using G = TypeParam;
569 using Arc = typename G::Arc;
570
571 Sample<G> s;
572 const auto view = const_view(s.g);
573 const Const_Graph_View<G> copy = view;
574 const Const_Graph_View deduced(s.g);
575 static_assert(std::is_same_v<decltype(deduced), const Const_Graph_View<G>>);
576
577 // The owner of the graph keeps its modifiable interface.
578 s.g.for_each_arc([] (Arc *a) { a->get_info() += 1; });
579 auto *extra = s.g.insert_node(99);
580 s.g.insert_arc(s.nodes[4], extra, 71);
581
582 for (const auto & v : {view, copy, deduced})
583 {
584 EXPECT_EQ(v.get_num_nodes(), 6u);
585 EXPECT_EQ(v.get_num_arcs(), 7u);
586 EXPECT_EQ(v.find_node(99), extra);
587 EXPECT_EQ(v.template foldl_arcs<long>(0, [] (const long & acc, const Arc *a) { return acc + a->get_info(); }),
588 11 + 21 + 31 + 41 + 51 + 61 + 71);
589 }
590}
591
592TYPED_TEST(ConstGraphView, an_empty_graph_is_read_as_empty)
593{
594 using G = TypeParam;
595 using Node = typename G::Node;
596 using Arc = typename G::Arc;
597
598 const G g;
599 const auto view = const_view(g);
600
601 EXPECT_TRUE(view.is_empty());
602 EXPECT_EQ(view.get_num_nodes(), 0u);
603 EXPECT_EQ(view.get_num_arcs(), 0u);
604 EXPECT_FALSE(view.get_node_it().has_curr());
605 EXPECT_FALSE(view.get_arc_it().has_curr());
606 EXPECT_TRUE(view.nodes().is_empty());
607 EXPECT_TRUE(view.arcs().is_empty());
608 EXPECT_EQ(view.search_node([] (const Node *) { return true; }), nullptr);
609 EXPECT_EQ(view.search_arc([] (const Arc *) { return true; }), nullptr);
610 EXPECT_TRUE(view.all_nodes([] (const Node *) { return false; }));
611 EXPECT_FALSE(view.exists_arc([] (const Arc *) { return true; }));
612 EXPECT_EQ(view.count_nodes([] (const Node *) { return true; }), 0u);
613 EXPECT_EQ(view.foldl_nodes(7, [] (const int & acc, const Node *) { return acc + 1; }), 7);
614}
615
616// get_arc() and get_arc(p) of the graph classes, and get_first_arc(p) of
617// List_Graph, did not compile: nothing instantiated them.
618TYPED_TEST(ConstGraphView, the_entry_points_of_the_graph_agree_with_the_view)
619{
620 using G = TypeParam;
621 using Node = typename G::Node;
622 using Arc = typename G::Arc;
623
624 static_assert(std::is_same_v<decltype(std::declval<const G &>().get_node()), Node *>);
625 static_assert(std::is_same_v<decltype(std::declval<const G &>().get_arc()), Arc *>);
626 static_assert(std::is_same_v<decltype(std::declval<const G &>().get_arc(nullptr)), Arc *>);
627 static_assert(std::is_same_v<decltype(std::declval<const G &>().get_first_arc(nullptr)), Arc *>);
628
629 Sample<G> s;
630 const G & g = s.g;
631 const auto view = const_view(g);
632
633 EXPECT_EQ(g.get_node(), g.get_first_node());
634 EXPECT_EQ(g.get_arc(), g.get_first_arc());
635 EXPECT_EQ(view.get_first_node(), g.get_node());
636 EXPECT_EQ(view.get_first_arc(), g.get_arc());
637
638 // The node 0 has arcs on every graph class, directed or not.
639 Node *p = s.nodes[0];
640 EXPECT_EQ(g.get_arc(p), g.get_first_arc(p));
641 EXPECT_EQ(view.get_first_arc(p), g.get_arc(p));
642 EXPECT_TRUE(g.get_src_node(g.get_arc(p)) == p or g.get_tgt_node(g.get_arc(p)) == p);
643
644 // A node without arcs has no first arc.
645 Node *lonely = s.g.insert_node(77);
646 EXPECT_THROW((void) g.get_first_arc(lonely), std::range_error);
647 EXPECT_THROW((void) g.get_arc(lonely), std::range_error);
648 EXPECT_THROW((void) view.get_first_arc(lonely), std::range_error);
649}
650
651TYPED_TEST(ConstGraphView, the_filtered_iterators_and_the_generic_functions_read_a_view)
652{
653 using G = TypeParam;
654 using Node = typename G::Node;
655 using Arc = typename G::Arc;
656 using View = Const_Graph_View<G>;
657
658 Sample<G> s;
659 const View view(s.g);
660
661 // The filtered iterators of the graphs, instantiated on the view.
662 using Filtered_Arcs = Aleph::Arc_Iterator<View, Reads_Arc<Arc>>;
663 static_assert(std::is_same_v<decltype(std::declval<Filtered_Arcs &>().get_curr()), const Arc *>);
664 static_assert(not writes_the_information_through<Filtered_Arcs>);
665 static_assert(not removes_through<Filtered_Arcs>);
666
667 long filtered = 0;
668 for (Filtered_Arcs it(view); it.has_curr(); it.next())
669 filtered += it.get_curr()->get_info();
670 EXPECT_EQ(filtered, 30 + 40 + 50 + 60);
671
672 using Filtered_Nodes = Aleph::Node_Iterator<View, Reads_Node<Node>>;
673 static_assert(std::is_same_v<decltype(std::declval<Filtered_Nodes &>().get_curr()), const Node *>);
674 static_assert(not writes_the_information_through<Filtered_Nodes>);
675
676 int even = 0;
677 for (Filtered_Nodes it(view); it.has_curr(); it.next())
678 even += it.get_curr()->get_info();
679 EXPECT_EQ(even, 0 + 2 + 4);
680
681 // The arcs of the node 2 that pass the filter, as the graph gives them.
682 using Filtered_Node_Arcs = Aleph::Node_Arc_Iterator<View, Reads_Arc<Arc>>;
683 static_assert(std::is_same_v<decltype(std::declval<Filtered_Node_Arcs &>().get_curr()), const Arc *>);
684 static_assert(not writes_the_information_through<Filtered_Node_Arcs>);
685
686 long expected = 0;
687 for (Aleph::Node_Arc_Iterator<G, Reads_Arc<Arc>> it(s.nodes[2]); it.has_curr(); it.next())
688 expected += it.get_curr()->get_info();
689 long of_node = 0;
690 const Node *n2 = s.nodes[2];
691 for (Filtered_Node_Arcs it(n2); it.has_curr(); it.next())
692 of_node += it.get_curr()->get_info();
693 EXPECT_EQ(of_node, expected);
694 EXPECT_GT(of_node, 0);
695
696 // Filter_Iterator directly, with any condition on a pointer to const.
697 auto cheap = [] (const Arc *a) { return a->get_info() < 30; };
698 Filter_Iterator<View, typename View::Arc_Iterator, decltype(cheap)> fit(view, cheap);
699 static_assert(std::is_same_v<decltype(fit.get_curr()), const Arc *>);
700 long cheap_sum = 0;
701 for (; fit.has_curr(); fit.next())
702 cheap_sum += fit.get_curr()->get_info();
703 EXPECT_EQ(cheap_sum, 10 + 20);
704
705 // The free functions of the graphs.
706 long total = 0;
707 Aleph::for_each_arc(view, [&total] (const Arc *a) { total += a->get_info(); });
708 EXPECT_EQ(total, 210);
709
710 int nodes_total = 0;
711 Aleph::for_each_node(view, [&nodes_total] (const Node *p) { nodes_total += p->get_info(); });
712 EXPECT_EQ(nodes_total, 10);
713
714 long through_filter = 0;
715 Aleph::for_each_arc(view, [&through_filter] (const Arc *a) { through_filter += a->get_info(); },
716 Reads_Arc<Arc>());
717 EXPECT_EQ(through_filter, 180);
718
719 EXPECT_TRUE(Aleph::forall_arc(view, [] (const Arc *a) { return a->get_info() > 0; }));
720 EXPECT_FALSE(Aleph::forall_node(view, [] (const Node *p) { return p->get_info() > 0; }));
721}
722
723namespace
724{
726 using Market_View = Const_Graph_View<Market>;
727
728 // An arc distance for a reader: it receives a pointer to const.
729 struct Read_Distance
730 {
731 using Distance_Type = long;
732
733 long operator () (Market_View::Arc *a) const noexcept { return a->get_info(); }
734 };
735
736 struct Market_Sample
737 {
738 Market g;
739 Market::Node *a = g.insert_node(0);
740 Market::Node *b = g.insert_node(1);
741 Market::Node *c = g.insert_node(2);
742 Market::Node *d = g.insert_node(3);
743
744 explicit Market_Sample(const long closing)
745 {
746 g.insert_arc(a, b, 2);
747 g.insert_arc(b, c, -5);
748 g.insert_arc(c, a, closing); // a -> b -> c -> a costs closing - 3
749 g.insert_arc(a, c, 10);
750 g.insert_arc(c, d, 4);
751 }
752 };
753
754 DynList<long> arc_information(const Market_View & view)
755 {
756 return view.arcs_map([] (Market_View::Arc *a) { return a->get_info(); });
757 }
758
759 DynList<int> node_information(const Market_View & view)
760 {
761 return view.nodes_map([] (Market_View::Node *p) { return p->get_info(); });
762 }
763
764 template <class T>
765 bool same_items(const DynList<T> & l1, const DynList<T> & l2)
766 {
767 auto it1 = l1.get_it();
768 auto it2 = l2.get_it();
769 for (; it1.has_curr() and it2.has_curr(); it1.next_ne(), it2.next_ne())
770 if (not (it1.get_curr() == it2.get_curr()))
771 return false;
772 return not it1.has_curr() and not it2.has_curr();
773 }
774}
775
776TEST(ConstGraphViewAlgorithms, the_algorithms_that_keep_bookkeeping_run_on_the_graph_and_preserve_it)
777{
778 Market_Sample negative(1); // the cycle a -> b -> c -> a costs -2
779 const Market_View view(negative.g);
780 const auto arcs_before = arc_information(view);
781 const auto nodes_before = node_information(view);
782
783 // Bellman-Ford keeps its state in the cookies, the counters and the bits
784 // of the nodes and of the arcs, so it takes the graph itself; the
785 // information stays as it was.
786 static_assert(std::is_constructible_v<Bellman_Ford<Market>, Market &>);
787 static_assert(not std::is_constructible_v<Bellman_Ford<Market>, const Market &>);
788 EXPECT_TRUE(Bellman_Ford<Market>(negative.g).has_negative_cycle(negative.a));
789 EXPECT_TRUE(same_items(arc_information(view), arcs_before));
790 EXPECT_TRUE(same_items(node_information(view), nodes_before));
791 EXPECT_EQ(view.get_num_nodes(), 4u);
792 EXPECT_EQ(view.get_num_arcs(), 5u);
793
794 Market_Sample positive(8); // b -> c is still negative, but no cycle is
795 const Market_View positive_view(positive.g);
796 const auto positive_before = arc_information(positive_view);
797 EXPECT_FALSE(Bellman_Ford<Market>(positive.g).has_negative_cycle(positive.a));
798 EXPECT_TRUE(same_items(arc_information(positive_view), positive_before));
799}
800
801TEST(ConstGraphViewAlgorithms, dijkstra_runs_on_the_graph_and_preserves_the_information)
802{
803 Market g;
804 auto *a = g.insert_node(0);
805 auto *b = g.insert_node(1);
806 auto *c = g.insert_node(2);
807 auto *d = g.insert_node(3);
808 g.insert_arc(a, b, 1);
809 g.insert_arc(b, c, 2);
810 g.insert_arc(a, c, 7);
811 g.insert_arc(c, d, 3);
812 g.insert_arc(a, d, 9);
813
814 const Market_View view(g);
815 const auto arcs_before = arc_information(view);
816 const auto nodes_before = node_information(view);
817
818 Path<Market> path(g);
819 EXPECT_EQ(Dijkstra_Min_Paths<Market>().find_min_path(g, a, d, path), 6);
820 EXPECT_EQ(path.size(), 4u); // a, b, c, d
821
822 EXPECT_TRUE(same_items(arc_information(view), arcs_before));
823 EXPECT_TRUE(same_items(node_information(view), nodes_before));
824}
825
826TEST(ConstGraphViewAlgorithms, the_algorithms_without_bookkeeping_run_on_a_view)
827{
828 Market_Sample negative(1);
829 const Market_View view(negative.g);
830 const auto arcs_before = arc_information(view);
831
832 static_assert(ArcDistance<Read_Distance, Market_View>);
833
834 // The same search, on the graph and through the view.
835 const auto on_graph = most_negative_cycle_bounded(negative.g, 3);
836 const auto on_view = most_negative_cycle_bounded(view, 3, Read_Distance());
837 static_assert(std::is_same_v<decltype(on_view.cycle_arcs), DynList<const Market::Arc *>>);
838 static_assert(std::is_same_v<decltype(on_view.cycle_nodes), DynList<const Market::Node *>>);
839 static_assert(std::is_same_v<decltype(on_graph.cycle_arcs), DynList<Market::Arc *>>);
840
841 ASSERT_TRUE(on_graph.has_cycle);
842 ASSERT_TRUE(on_view.has_cycle);
843 EXPECT_EQ(on_view.total_cost, -2);
844 EXPECT_EQ(on_view.total_cost, on_graph.total_cost);
845 EXPECT_EQ(on_view.cycle_arcs.size(), 3u);
846 EXPECT_EQ(on_view.cycle_arcs.size(), on_graph.cycle_arcs.size());
847
848 long recomputed = 0;
849 on_view.cycle_arcs.for_each([&recomputed] (const Market::Arc *a) { recomputed += a->get_info(); });
850 EXPECT_EQ(recomputed, -2);
851
852 const auto cycles = find_disjoint_negative_cycles(view, 3, Negative_Cycle_Exclusion::Min_Weight_Arc,
853 Read_Distance());
854 ASSERT_EQ(cycles.size(), 1u);
855 EXPECT_EQ(cycles.get_first().total_cost, -2);
856 EXPECT_EQ(cycles.get_first().length, 3u);
857
858 EXPECT_TRUE(same_items(arc_information(view), arcs_before));
859
860 // Without a negative cycle the bounded search reports the cheapest cycle
861 // and the disjoint search reports nothing, on the graph and on the view.
862 Market_Sample positive(8);
863 const auto positive_view = const_view(positive.g);
864 const auto cheapest = most_negative_cycle_bounded(positive_view, 3, Read_Distance());
865 ASSERT_TRUE(cheapest.has_cycle);
866 EXPECT_EQ(cheapest.total_cost, 5);
867 EXPECT_EQ(cheapest.total_cost, most_negative_cycle_bounded(positive.g, 3).total_cost);
868 EXPECT_TRUE(find_disjoint_negative_cycles(positive_view, 3, Negative_Cycle_Exclusion::Min_Weight_Arc,
869 Read_Distance()).is_empty());
870 EXPECT_TRUE(find_disjoint_negative_cycles(positive.g, 3).is_empty());
871}
Bellman-Ford algorithm for single-source shortest paths.
Dijkstra's shortest path algorithm.
Enumeration of negative cycles and bounded-length most negative cycle in directed graphs.
C++20 concepts for the protocol shared by graph algorithms.
TYPED_TEST_SUITE(ArcHeapLifecycle, ArcHeapKinds)
WeightedDigraph::Node Node
WeightedDigraph::Arc Arc
Bellman-Ford algorithm for shortest paths with negative weights.
bool has_negative_cycle(Node *start)
Test if a negative cycle exists starting from a specific node.
Read-only iterator on the arcs of a graph.
Strict read-only view of a graph.
Read-only iterator on the arcs of a node.
Read-only iterator on the nodes of a graph.
Generic directed graph (digraph) wrapper template.
Definition graph-dry.H:4377
Spanning tree calculation of all shortest paths from a given node according to Dijkstra's algorithm.
Definition Dijkstra.H:117
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
Arc for graphs implemented with simple adjacency lists.
Definition tpl_sgraph.H:197
Iterator on the arcs of a graph.
Definition tpl_graph.H:854
Arc * get_curr() const
See get_current_arc().
Definition tpl_graph.H:885
Node * get_tgt_node() const
Return the connected node to source node (src passed in construction time) through the current arc.
Definition tpl_graph.H:911
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:439
Node * get_first_node() const
Return any node in the graph.
Definition tpl_graph.H:590
Arc * get_first_arc(Node *node) const
Return any arc adjacent to a node.
Definition tpl_graph.H:609
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:535
_Graph_Node Node
The graph type.
Definition tpl_graph.H:443
_Graph_Arc 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
Graph class implemented with singly-linked adjacency lists.
Definition tpl_sgraph.H:274
Number Theoretic Transform over Z / MOD Z.
Definition ntt.H:115
Filtered iterator on the nodes of a graph.
Definition tpl_graph.H:1287
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
Minimal std::expected-style result type for C++20.
void for_each_arc(Operation &op) const
Unconditionally traverse all the arcs of graph and on each one perform an operation.
Definition graph-dry.H:1805
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:1017
Node * get_node() const
Return any node in the graph.
Definition graph-dry.H:994
bool traverse_nodes(Operation &op) const
Conditioned traversal of all the nodes of a graph.
Definition graph-dry.H:1587
bool is_digraph() const noexcept
Return true if the graph this is directed.
Definition graph-dry.H:937
Arc * get_arc() const
Return any arc in the graph.
Definition graph-dry.H:1004
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
Definition graph-dry.H:1058
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
Definition graph-dry.H:1064
size_t degree(Node *p) const noexcept
Return the total of arcs (or degree) of a node.
Definition graph-dry.H:1075
Arc * search_arc(Op &op) const
Linear search of an arc.
Definition graph-dry.H:2945
auto filter_arcs(Op &op) const
Filter the arcs of graph satisfying a condition.
Definition graph-dry.H:2350
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:1023
Node * search_node(Op &op) const
Linear search of a node.
Definition graph-dry.H:2891
bool traverse_arcs(Operation &op) const
Conditioned traversal of all the arcs of a graph.
Definition graph-dry.H:1654
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:663
Concept for basic graph iterators.
Definition graph-dry.H:393
Concept for graph arc iterators.
Definition graph-dry.H:451
Concept for graph node iterators.
Definition graph-dry.H:432
Concept for node adjacency iterators.
Definition graph-dry.H:475
Concept for resettable graph iterators.
Definition graph-dry.H:413
TYPED_TEST(ConstGraphView, the_iterators_hand_out_pointers_to_const)
#define TEST(name)
pair< size_t, string > P
Generic filter iterator wrapper for Aleph containers.
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
DynArray< Graph::Arc * > arcs
Definition graphpic.C:408
Const_Graph_View< GT > const_view(const GT &g) noexcept
Strict read-only view of a graph.
DynList< Negative_Cycle_Item< GT, typename Distance::Distance_Type > > find_disjoint_negative_cycles(const GT &g, const size_t max_cycles, const Negative_Cycle_Exclusion exclusion=Negative_Cycle_Exclusion::Min_Weight_Arc, Distance distance=Distance(), SA sa=SA())
Find up to max_cycles negative cycles, excluding arcs of each cycle found before searching for the ne...
void for_each_node(const GT &g, Op operation, SN sn=SN())
Traverse all the nodes of graph filtering some ones according to a condition and executing an operati...
Definition tpl_graph.H:1320
#define ARC_COOKIE(p)
Return the arc cookie
Bounded_Cycle_Result< GT, typename Distance::Distance_Type > most_negative_cycle_bounded(const GT &g, const size_t max_length, Distance distance=Distance(), SA sa=SA())
Most negative simple cycle of at most max_length arcs, ranked by total cost (not by mean cost as Karp...
#define NODE_COUNTER(p)
Get the counter of a node.
#define ARC_COUNTER(p)
Return the counter of arc p.
bool forall_node(const GT &g, Op cond, SN sn=SN())
Return true if condition cond is met on every filtered node of the graph.
Definition tpl_graph.H:1381
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
void for_each_arc(const GT &g, Op operation, SA sa=SA())
Traverse all the arcs of graph filtering some ones according to a condition and executing an operatio...
Definition tpl_graph.H:1339
#define NODE_BITS(p)
Get the control bits of a node.
bool forall_arc(const GT &g, Op cond, SA sa=SA())
Return true if condition cond is met on every filtered arc of the graph.
Definition tpl_graph.H:1403
void find_min_path(Mat &p, long src_idx, long tgt_idx, Path< typename Mat::Graph_Type > &path)
Build a minimum path from Floyd-Warshall path matrix using indices.
Definition mat_path.H:191
@ Depth_First
Definition aleph-graph.H:73
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
and
Check uniqueness with explicit hash + equality functors.
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
Definition ahAlgo.H:76
Filtered iterator on all the arcs of a graph.
Definition tpl_graph.H:1200
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:231
Iterator on all arcs of a graph.
Definition tpl_graph.H:941
Node * get_tgt_node() const
Return the target node of current arc.
Definition tpl_graph.H:992
Node * get_src_node() const
Return the source node of the current arc.
Definition tpl_graph.H:979
Filtered iterator of adjacent arcs of a node.
Definition tpl_graph.H:1155
Node * get_curr() const
Return the current node.
Definition graph-dry.H:522
DynList< int > l1
DynList< int > l2
tuple< int, double > Sample
Array-based graph implementation.
Strict read-only access to a graph: Const_Graph_View and the read-only iterators on the nodes,...
Generic graph and digraph implementations.
Simple graph implementation with adjacency lists.