Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
graph_exhaustive_connectivity_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
43#include <set>
44#include <stdexcept>
45#include <string>
46#include <vector>
47
48#include <gtest/gtest.h>
49
50#include <tpl_graph.H>
51#include <tpl_components.H>
52#include <tpl_graph_utils.H>
53#include <tpl_cut_nodes.H>
54#include <tpl_test_acyclique.H>
55#include <tpl_bipartite.H>
56#include <tpl_spanning_tree.H>
57#include <Blossom.H>
58#include <eulerian.H>
59
60#include "graph_harness.H"
61#include "graph_oracles.H"
62
63using namespace Aleph;
64using namespace graph_harness;
65namespace oracle = graph_oracles;
66
67namespace
68{
69 template <class List>
70 std::set<int> numbers(const List & l)
71 {
72 std::set<int> r;
73 for (auto it = l.get_it(); it.has_curr(); it.next_ne())
74 r.insert(num(it.get_curr()));
75 return r;
76 }
77
78 std::string text(const std::set<int> & s)
79 {
80 std::string r = "{";
81 for (int x : s)
82 r += (r.size() > 1 ? " " : "") + std::to_string(x);
83 return r + "}";
84 }
85
87 std::vector<int> starts(const Spec & s)
88 {
89 if (s.n == 0)
90 return {};
91 if (s.n == 1)
92 return {0};
93 return {0, s.n - 1};
94 }
95
100 template <class GT>
101 std::string subgraph_error(Built<GT> & b, GT & sg, const std::set<int> & want_nodes,
102 const std::set<int> & want_arcs)
103 {
104 std::set<int> got_nodes, got_arcs;
105 for (auto it = sg.get_node_it(); it.has_curr(); it.next_ne())
106 {
107 auto q = it.get_curr();
108 const int x = num(q);
109 got_nodes.insert(x);
110 if (x < 0 or size_t(x) >= b.nodes.size() or mapped_node<GT>(q) != b.nodes[size_t(x)])
111 return "the copy of " + std::to_string(x) + " maps to another node";
112 if (mapped_node<GT>(b.nodes[size_t(x)]) != q)
113 return "the node " + std::to_string(x) + " does not map to its copy";
114 }
115 for (auto it = sg.get_arc_it(); it.has_curr(); it.next_ne())
116 {
117 auto c = it.get_curr();
118 const int i = c->get_info();
119 got_arcs.insert(i);
120 if (i < 0 or size_t(i) >= b.arcs.size() or mapped_arc<GT>(c) != b.arcs[size_t(i)])
121 return "the copy of the arc " + std::to_string(i) + " maps to another arc";
122 auto a = b.arcs[size_t(i)];
123 if (mapped_arc<GT>(a) != c)
124 return "the arc " + std::to_string(i) + " does not map to its copy";
125 auto src = mapped_node<GT>(sg.get_src_node(c));
126 auto tgt = mapped_node<GT>(sg.get_tgt_node(c));
127 auto g_src = b.g.get_src_node(a);
128 auto g_tgt = b.g.get_tgt_node(a);
129 if (not ((src == g_src and tgt == g_tgt) or (src == g_tgt and tgt == g_src)))
130 return "the copy of the arc " + std::to_string(i) + " joins other nodes";
131 }
132 if (got_nodes != want_nodes or sg.get_num_nodes() != want_nodes.size())
133 return "the nodes are " + text(got_nodes) + ", not " + text(want_nodes);
134 if (got_arcs != want_arcs or sg.get_num_arcs() != want_arcs.size())
135 return "the arcs are " + text(got_arcs) + ", not " + text(want_arcs);
136 return "";
137 }
138}
139
140template <class GT>
141class ExhaustiveConnectivity : public ::testing::Test {};
142
144
145TYPED_TEST(ExhaustiveConnectivity, ComponentsMatchTheOracle)
146{
147 using GT = TypeParam;
148 Check count("Unconnected_Components::count_components()");
149 Check lists("Unconnected_Components::operator()");
150 Check inconnected("inconnected_components()");
151 Check connectivity("test_connectivity()");
152
153 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
154 {
155 Built<GT> b(s);
156 const int want = oracle::components(s);
157
158 count.run();
159 const size_t c = Unconnected_Components<GT>().count_components(b.g);
160 if (int(c) != want)
161 count.fail(s, std::to_string(c) + " components, not " + std::to_string(want));
162
163 auto total_arcs = [] (const auto & l)
164 {
165 size_t arcs = 0;
166 for (auto it = l.get_it(); it.has_curr(); it.next_ne())
167 arcs += it.get_curr().get_num_arcs();
168 return arcs;
169 };
170
171 lists.run();
174 if (int(l.size()) != want or total_arcs(l) != s.num_arcs())
175 lists.fail(s, std::to_string(l.size()) + " components, "
176 + std::to_string(total_arcs(l)) + " arcs");
177
178 inconnected.run();
179 auto ic = inconnected_components(b.g);
180 if (int(ic.size()) != want or total_arcs(ic) != s.num_arcs())
181 inconnected.fail(s, std::to_string(ic.size()) + " components, "
182 + std::to_string(total_arcs(ic)) + " arcs");
183
184 connectivity.run();
185 const bool connected = test_connectivity(b.g);
186 if (connected != (s.n > 0 and want == 1))
187 connectivity.fail(s, std::string("says ") + (connected ? "" : "not ") + "connected");
188 });
189
190 count.expect();
191 lists.expect();
192 inconnected.expect();
193 connectivity.expect();
194}
195
196// Build_Subgraph from each start copies its component, with the cookies
197// clear and with cookies toward a graph that went, as those that a mapping
198// to a graph leaves after it goes
199TYPED_TEST(ExhaustiveConnectivity, SubgraphsMatchTheOracle)
200{
201 using GT = TypeParam;
202 Check clear("Build_Subgraph");
203 Check stale("Build_Subgraph, with cookies toward a graph that went");
204 Check listed("Build_Subgraph, into a list of the nodes");
205
206 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
207 {
208 const auto comp = oracle::component_of(s);
209 for (int start : starts(s))
210 {
211 std::set<int> want_nodes, want_arcs;
212 for (int x = 0; x < s.n; ++x)
213 if (comp[size_t(x)] == comp[size_t(start)])
214 want_nodes.insert(x);
215 for (size_t i = 0; i < s.arcs.size(); ++i)
216 if (comp[size_t(s.arcs[i][0])] == comp[size_t(start)])
217 want_arcs.insert(int(i));
218
219 for (const bool old_cookies : {false, true})
220 {
221 Check & check = old_cookies ? stale : clear;
222 check.run();
223 Built<GT> b(s);
224 if (old_cookies)
225 {
226 GT other;
227 auto o = other.insert_node(-1);
228 auto oa = other.insert_arc(o, o, -1);
229 for (auto p : b.nodes)
230 NODE_COOKIE(p) = o;
231 for (auto a : b.arcs)
232 ARC_COOKIE(a) = oa;
233 }
234 GT sg;
235 Build_Subgraph<GT>()(b.g, sg, b.nodes[size_t(start)]);
236 if (auto e = subgraph_error(b, sg, want_nodes, want_arcs); not e.empty())
237 check.fail(s, "from " + std::to_string(start) + ": " + e);
238 }
239
240 listed.run();
241 Built<GT> b(s);
243 Build_Subgraph<GT>()(b.g, l, b.nodes[size_t(start)]);
244 if (const auto got = numbers(l); got != want_nodes or l.size() != want_nodes.size())
245 listed.fail(s, "from " + std::to_string(start) + " gives " + text(got) + ", not "
246 + text(want_nodes));
247 }
248 });
249
250 clear.expect();
251 stale.expect();
252 listed.expect();
253}
254
255TYPED_TEST(ExhaustiveConnectivity, CutNodesAndBridgesMatchTheOracle)
256{
257 using GT = TypeParam;
258 Check function("compute_cut_nodes()");
259 Check object("Compute_Cut_Nodes");
260 Check bridges("find_bridges()");
261
262 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
263 {
264 Built<GT> b(s);
265 const auto want_bridges = oracle::bridges(s);
266 for (int start : starts(s))
267 {
268 const auto want = oracle::cut_nodes(s, start);
269 auto * src = b.nodes[size_t(start)];
270
271 function.run();
272 const auto got_f = numbers(compute_cut_nodes(b.g, src));
273 if (got_f != want)
274 function.fail(s, "from " + std::to_string(start) + " gives " + text(got_f)
275 + ", not " + text(want));
276
277 object.run();
280 cc(src, l);
281 const auto got_o = numbers(l);
282 if (got_o != want)
283 object.fail(s, "from " + std::to_string(start) + " gives " + text(got_o)
284 + ", not " + text(want));
285
286 bridges.run();
287 std::set<int> got_b;
288 auto lb = find_bridges(b.g, src);
289 for (auto it = lb.get_it(); it.has_curr(); it.next_ne())
290 got_b.insert(num(it.get_curr()));
291 if (got_b != want_bridges)
292 bridges.fail(s, "from " + std::to_string(start) + " gives " + text(got_b)
293 + ", not " + text(want_bridges));
294 }
295 });
296
297 function.expect();
298 object.expect();
299 bridges.expect();
300}
301
302TYPED_TEST(ExhaustiveConnectivity, CyclesMatchTheOracle)
303{
304 using GT = TypeParam;
305 Check acyclique("is_graph_acyclique()");
306 Check has_cycle("Has_Cycle");
307 Check through("test_for_cycle(g, start)");
308
309 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
310 {
311 Built<GT> b(s);
312 const bool cycle = oracle::has_cycle(s);
313
314 acyclique.run();
315 if (is_graph_acyclique(b.g) == cycle)
316 acyclique.fail(s, cycle ? "says acyclic" : "says cyclic");
317
318 has_cycle.run();
319 if (Has_Cycle<GT>()(b.g) != cycle)
320 has_cycle.fail(s, cycle ? "finds no cycle" : "finds a cycle");
321
322 for (int start : starts(s))
323 {
324 through.run();
325 const bool want = oracle::on_cycle(s, start);
326 if (test_for_cycle(b.g, b.nodes[size_t(start)]) != want)
327 through.fail(s, "from " + std::to_string(start)
328 + (want ? " finds no cycle" : " finds a cycle"));
329 }
330 });
331
332 acyclique.expect();
333 has_cycle.expect();
334 through.expect();
335}
336
337TYPED_TEST(ExhaustiveConnectivity, BipartitionAndMatchingsMatchTheOracle)
338{
339 using GT = TypeParam;
340 Check bipartite("compute_bipartite()");
341 Check hopcroft_karp("hopcroft_karp_matching()");
342 Check by_flow("compute_maximum_cardinality_bipartite_matching()");
343 Check blossom("blossom_maximum_cardinality_matching()");
344
345 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
346 {
347 if (s.n == 0)
348 return;
349 Built<GT> b(s);
350 const bool want_bipartite = oracle::is_bipartite(s);
351 const int want_size = oracle::max_matching(s);
352
353 bipartite.run();
354 try
355 {
357 compute_bipartite(b.g, l, r);
358 const auto L = numbers(l), R = numbers(r);
359 bool ok = want_bipartite and int(L.size() + R.size()) == s.n;
360 for (int x : L)
361 ok = ok and R.count(x) == 0;
362 for (const auto & a : s.arcs)
363 ok = ok and L.count(a[0]) != L.count(a[1]);
364 if (not ok)
365 bipartite.fail(s, want_bipartite ? "gives a wrong partition"
366 : "does not throw on a graph that is not bipartite");
367 }
368 catch (const std::domain_error &)
369 {
370 if (want_bipartite)
371 bipartite.fail(s, "throws on a bipartite graph");
372 }
373
374 auto check_matching = [&] (Check & check, const DynDlist<typename GT::Arc *> & m)
375 {
376 std::vector<int> arcs;
377 for (auto it = m.get_it(); it.has_curr(); it.next_ne())
378 arcs.push_back(num(it.get_curr()));
379 if (not oracle::is_matching(s, arcs) or int(arcs.size()) != want_size)
380 check.fail(s, std::to_string(arcs.size()) + " arcs, not "
381 + std::to_string(want_size)
382 + (oracle::is_matching(s, arcs) ? "" : ", and not a matching"));
383 };
384
385 if (want_bipartite)
386 {
387 hopcroft_karp.run();
390 check_matching(hopcroft_karp, m);
391
392 by_flow.run();
393 try
394 {
397 check_matching(by_flow, mf);
398 }
399 catch (const std::exception & e)
400 {
401 by_flow.fail(s, std::string("throws ") + e.what());
402 }
403 }
404
405 blossom.run();
407 const size_t size = blossom_maximum_cardinality_matching(b.g, mb);
408 check_matching(blossom, mb);
409 if (size != mb.size())
410 blossom.fail(s, "returns " + std::to_string(size) + " for "
411 + std::to_string(mb.size()) + " arcs");
412 });
413
414 bipartite.expect();
415 hopcroft_karp.expect();
416 by_flow.expect();
417 blossom.expect();
418}
419
420TYPED_TEST(ExhaustiveConnectivity, SpanningTreesCoverTheComponentOfTheStart)
421{
422 using GT = TypeParam;
423 Check depth("Find_Depth_First_Spanning_Tree");
424 Check breadth("Find_Breadth_First_Spanning_Tree");
425
426 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
427 {
428 Built<GT> b(s);
429 const auto comp = oracle::component_of(s);
430 for (int start : starts(s))
431 {
432 int size = 0;
433 for (int x = 0; x < s.n; ++x)
434 size += comp[size_t(x)] == comp[size_t(start)];
435
436 for (Check * check : {&depth, &breadth})
437 {
438 check->run();
439 GT tree;
440 if (check == &depth)
441 Find_Depth_First_Spanning_Tree<GT>()(b.g, b.nodes[size_t(start)], tree);
442 else
443 Find_Breadth_First_Spanning_Tree<GT>()(b.g, b.nodes[size_t(start)], tree);
444
445 // The tree spans the component of start, and its nodes map
446 // to those of g and back
447 bool ok = int(tree.get_num_nodes()) == size
448 and int(tree.get_num_arcs()) == size - 1;
449 std::set<int> seen;
450 for (typename GT::Node_Iterator it(tree); it.has_curr() and ok; it.next_ne())
451 {
452 auto * t = it.get_curr_ne();
453 auto * p = static_cast<typename GT::Node *>(NODE_COOKIE(t));
454 ok = p != nullptr and num(p) == num(t)
455 and comp[size_t(num(p))] == comp[size_t(start)]
456 and NODE_COOKIE(p) == t and seen.insert(num(p)).second;
457 }
458 if (not ok)
459 check->fail(s, "from " + std::to_string(start) + ": a tree of "
460 + std::to_string(tree.get_num_nodes()) + " nodes and "
461 + std::to_string(tree.get_num_arcs()) + " arcs, not "
462 + std::to_string(size) + " nodes");
463 }
464 }
465 });
466
467 depth.expect();
468 breadth.expect();
469}
470
471TYPED_TEST(ExhaustiveConnectivity, EulerMatchesTheOracle)
472{
473 using GT = TypeParam;
474 Check euler("Test_Eulerian::compute()");
475 Check walk("Find_Eulerian_Path");
476 Check nodes("Find_Eulerian_Path::find_node_sequence()");
477 // Without arcs, Find_Eulerian_Path said None, and Test_Eulerian Cycle
478 Check empty("Find_Eulerian_Path, without arcs");
479
480 auto same_class = [] (Eulerian_Type got, oracle::Euler want)
481 {
482 return (got == Eulerian_Type::Cycle) == (want == oracle::Euler::Cycle)
483 and (got == Eulerian_Type::Path) == (want == oracle::Euler::Path);
484 };
485
486 for_each_spec(domain(4, 3), false, [&] (const Spec & s)
487 {
488 Built<GT> b(s);
489 euler.run();
490 const auto want = oracle::euler_class(s, false);
491 if (not same_class(Test_Eulerian<GT>().compute(b.g), want))
492 euler.fail(s, "a wrong class");
493
494 // The walks, where there is one
495 if (want == oracle::Euler::None)
496 return;
497 const bool closed = want == oracle::Euler::Cycle;
498
499 if (s.arcs.empty())
500 {
501 empty.run();
502 const auto r = Find_Eulerian_Path<GT>()(b.g);
503 if (r.type != Eulerian_Type::Cycle or not r.path.is_empty())
504 empty.fail(s, "says another class, or gives arcs");
505 return;
506 }
507
508 walk.run();
509 const auto r = Find_Eulerian_Path<GT>()(b.g);
510 std::vector<int> arcs;
511 for (auto it = r.path.get_it(); it.has_curr(); it.next_ne())
512 arcs.push_back(num(it.get_curr()));
513 if (not same_class(r.type, want) or not oracle::is_euler_walk(s, arcs, false, closed))
514 walk.fail(s, "a wrong class or walk");
515
516 // The nodes go along the arcs that the finder gives, from an end
517 nodes.run();
518 std::vector<int> seq;
520 for (auto it = l.get_it(); it.has_curr(); it.next_ne())
521 seq.push_back(num(it.get_curr()));
522 bool ok = seq.size() == arcs.size() + 1;
523 for (size_t i = 0; ok and i < arcs.size(); ++i)
524 {
525 const auto & a = s.arcs[size_t(arcs[i])];
526 ok = (a[0] == seq[i] and a[1] == seq[i + 1]) or (a[1] == seq[i] and a[0] == seq[i + 1]);
527 }
528 if (not ok or (closed and seq.front() != seq.back()))
529 nodes.fail(s, "the nodes do not follow the arcs");
530 });
531
532 euler.expect();
533 walk.expect();
534 nodes.expect();
535 empty.expect();
536}
Edmonds' Blossom algorithm for maximum matching in general graphs.
Build a mapped subgraph from a graph starting at a given node.
Computation of cut nodes (articulation points) of a graph.
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.
Finds and constructs an Eulerian path or cycle using Hierholzer's algorithm.
Definition eulerian.H:477
DynList< typename GT::Node * > find_node_sequence(GT &g)
Get the node sequence of the Eulerian path/cycle.
Definition eulerian.H:744
Determines whether a graph contains cycles.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:535
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Definition tpl_graph.H:618
Tests whether a graph or digraph is Eulerian.
Definition eulerian.H:241
Compute the connected components of a graph.
size_t count_components(const GT &g)
Count the number of connected components in a graph.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Definition graph-dry.H:975
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Definition graph-dry.H:3144
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:1017
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
Definition graph-dry.H:1064
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Definition graph-dry.H:3122
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:1023
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:663
The failures of one property over a domain.
void expect() const
Expects what the mark says, and prints the first failures.
void fail(const Spec &s, const std::string &what)
Counts a failure on spec, with what went wrong.
void run() noexcept
Counts a run of the property.
Eulerian graph detection and path/cycle finding.
TYPED_TEST(ExhaustiveConnectivity, ComponentsMatchTheOracle)
TYPED_TEST_SUITE(ExhaustiveConnectivity, Undirected_Kinds)
Every small multigraph, on every kind of graph, for the tests.
Answers computed from a Spec of graph_harness.H, without Aleph.
DynArray< Graph::Node * > nodes
Definition graphpic.C:406
DynArray< Graph::Arc * > arcs
Definition graphpic.C:408
void compute_bipartite(const GT &g, DynDlist< typename GT::Node * > &l, DynDlist< typename GT::Node * > &r, SA sa=SA())
Computes the partition sets of a bipartite graph.
void compute_maximum_cardinality_bipartite_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Computes the maximum cardinality matching of a bipartite graph.
#define ARC_COOKIE(p)
Return the arc cookie
bool has_cycle(const GT &g)
Return true if an undirected graph has at least one cycle.
DynList< GT > inconnected_components(const GT &g)
Forward declaration for inconnected_components().
bool test_for_cycle(const GT &g, typename GT::Node *src)
Search for a cycle reachable from a given node.
bool test_connectivity(const GT &g)
Connectivity test for undirected graphs.
void hopcroft_karp_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Computes a maximum cardinality matching on a bipartite graph using the Hopcroft-Karp algorithm.
#define NODE_COOKIE(p)
Return the node cookie
DynList< typename GT::Node * > compute_cut_nodes(const GT &g, typename GT::Node *start)
Compute articulation points (cut vertices) of an undirected graph.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
DynList< typename GT::Arc * > find_bridges(const GT &g, typename GT::Node *start, SA sa=SA())
Find all bridge edges in a connected undirected graph.
bool is_graph_acyclique(const GT &g, typename GT::Node *start_node)
Return true if an undirected graph is acyclic.
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
Eulerian_Type
Enumeration for Eulerian graph classification.
Definition eulerian.H:114
and
Check uniqueness with explicit hash + equality functors.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
Definition ah-date.H:140
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
::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.
size_t for_each_spec(const Domain &d, bool directed, F &&f)
Calls f(spec) with every spec of d, smallest first, and returns how many there were.
int num(Node *p)
The number of a node of a built graph.
Domain domain(int max_nodes, int max_arcs)
The domain of max_nodes nodes and max_arcs arcs, of one more of each in heavy mode,...
bool is_matching(const Spec &s, const std::vector< int > &arcs)
Whether the arcs, by number, form a matching of s.
bool has_cycle(const Spec &s)
Whether the multigraph, not directed, has a cycle.
int max_matching(const Spec &s)
The size of a maximum matching, by brute force over the subsets of the arcs; loops never match.
Euler euler_class(const Spec &s, bool directed)
The Eulerian class of s: the arcs must be in one component (weakly, in a digraph),...
std::vector< int > component_of(const Spec &s, int skip_node=-1, int skip_arc=-1)
The number of the component of each node, as that of its root, of the graph without the node skip_nod...
std::set< int > cut_nodes(const Spec &s)
The nodes whose removal splits their component.
std::set< int > bridges(const Spec &s)
The arcs, by number, whose removal splits their component.
int components(const Spec &s, int skip_node=-1, int skip_arc=-1)
The number of components, without the node skip_node and the arc skip_arc.
bool on_cycle(const Spec &s, int x)
Whether the node x lies on a cycle of the multigraph, not directed.
bool is_bipartite(const Spec &s)
Whether the multigraph, not directed, has two colors with no arc inside one (a loop is an odd cycle)
Euler
What kind of Eulerian walk the multigraph has.
bool is_euler_walk(const Spec &s, const std::vector< int > &arcs, bool directed, bool closed)
Whether arcs, by number, walk every arc of s once, each from the node where the one before ended (fro...
STL namespace.
A graph made from a spec, with its nodes and arcs by number.
std::vector< typename GT::Node * > nodes
std::vector< typename GT::Arc * > arcs
A small multigraph: its nodes are 0 .
size_t num_arcs() const noexcept
std::vector< std::array< int, 2 > > arcs
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
bool check(GT &g)
Gsl_Compatible_Rng r
Bipartite graph detection and 2-coloring.
Graph connectivity and connected components.
Articulation points (cut nodes), bridges, and biconnected components.
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.
Spanning tree generation algorithms.
DAG (acyclic) graph testing.
DynList< int > l