37# include <gtest/gtest.h>
63 using Edge_Def = std::tuple<size_t, size_t, long long>;
70 bool operator==(
const Canonical_Path & other)
const noexcept
72 if (cost != other.cost or
nodes.size() != other.nodes.size())
75 for (
size_t i = 0; i <
nodes.size(); ++i)
76 if (
nodes(i) != other.nodes(i))
89 for (
size_t i = 0; i < a.
size(); ++i)
99 const size_t min_size = std::min(a.
size(), b.
size());
100 for (
size_t i = 0; i < min_size; ++i)
112 bool canonical_less(
const Canonical_Path & a,
const Canonical_Path & b)
114 if (a.cost != b.cost)
115 return a.cost < b.cost;
116 return node_sequence_less(a.nodes, b.nodes);
122 for (
size_t i = 1; i < paths.
size(); ++i)
124 Canonical_Path key = paths[i];
126 while (j > 0
and canonical_less(key, paths[j - 1]))
128 paths[j] = paths[j - 1];
137 const Canonical_Path & needle)
139 for (
size_t i = 0; i < paths.
size(); ++i)
140 if (paths[i] == needle)
150 for (
const auto & e :
init)
166 built.nodes.reserve(n);
167 for (
size_t i = 0; i < n; ++i)
168 built.nodes.append(built.g.insert_node(
static_cast<int>(i)));
170 for (
auto it = edges.
get_it(); it.has_curr(); it.next_ne())
172 const auto & [u, v,
w] = it.get_curr();
174 built.g.insert_arc(built.nodes[u], built.nodes[v],
w);
185 ids.
append(it.get_current_node_ne()->get_info());
195 Node * node = it.get_current_node_ne();
204 template <
class Result_List>
208 for (
auto it = results.get_it(); it.has_curr(); it.next_ne())
210 const auto & item = it.get_curr();
213 extract_node_ids(item.path)});
216 sort_canonical_paths(
out);
222 exact_k_shortest_simple_paths(
Node * source,
229 if (source == target)
233 p.nodes.append(source->get_info());
243 std::function<void(
Node *,
long long)>
dfs =
244 [&](
Node * u,
const long long cost)
250 for (
size_t i = 0; i < stack.
size(); ++i)
251 p.nodes.append(stack(i));
258 Arc * arc = it.get_current_arc_ne();
259 Node * v = it.get_tgt_node();
264 stack.
append(v->get_info());
265 dfs(v, cost + arc->get_info());
272 stack.
append(source->get_info());
275 sort_canonical_paths(
all);
278 while (
all.size() >
k)
279 (void)
all.remove_last();
287 std::bernoulli_distribution has_edge(0.36);
288 std::uniform_int_distribution<int> base_w(1, 40);
292 for (
size_t u = 0; u < n; ++u)
293 for (
size_t v = 0; v < n; ++v)
295 if (u == v or not has_edge(
rng))
297 const long long w =
static_cast<long long>(base_w(
rng))
298 +
static_cast<long long>(edge_id * 101);
299 edges.
append(Edge_Def{u, v,
w});
307TEST(KShortestPathsTest, YenKnownGraphProducesExpectedCosts)
309 const auto edges = make_edges({
310 {0, 1, 1}, {0, 2, 1}, {1, 3, 1}, {2, 3, 1},
311 {1, 2, 1}, {2, 1, 1}, {0, 3, 5}
313 auto built = build_graph(4, edges);
315 const auto got = yen_k_shortest_paths<Graph>(
316 built.g, built.nodes[0], built.nodes[3], 5);
317 auto normalized = normalize_results(got);
319 ASSERT_EQ(normalized.size(), 5u);
320 EXPECT_EQ(normalized[0].cost, 2);
321 EXPECT_EQ(normalized[1].cost, 2);
322 EXPECT_EQ(normalized[2].cost, 3);
323 EXPECT_EQ(normalized[3].cost, 3);
324 EXPECT_EQ(normalized[4].cost, 5);
328TEST(KShortestPathsTest, EppsteinApiMatchesYenOnKnownGraph)
330 const auto edges = make_edges({
331 {0, 1, 1}, {0, 2, 1}, {1, 3, 1}, {2, 3, 1},
334 auto built = build_graph(4, edges);
336 const auto yen = normalize_results(
337 yen_k_shortest_paths<Graph>(built.g, built.nodes[0], built.nodes[3], 6));
338 const auto epp = normalize_results(
339 eppstein_k_shortest_paths<Graph>(built.g, built.nodes[0], built.nodes[3], 6));
341 ASSERT_GE(epp.size(), yen.size());
343 for (
size_t i = 0; i < yen.size(); ++i)
345 EXPECT_TRUE(contains_canonical_path(epp, yen[i]));
350TEST(KShortestPathsTest, EppsteinCanReturnCyclicAlternatives)
352 const auto edges = make_edges({
353 {0, 1, 1}, {1, 2, 1}, {2, 3, 1},
356 auto built = build_graph(5, edges);
358 const auto yen = normalize_results(
359 yen_k_shortest_paths<Graph>(built.g, built.nodes[0], built.nodes[3], 4));
360 const auto epp = normalize_results(
361 eppstein_k_shortest_paths<Graph>(built.g, built.nodes[0], built.nodes[3], 4));
363 ASSERT_EQ(yen.size(), 1u);
364 ASSERT_EQ(epp.size(), 4u);
366 EXPECT_EQ(epp[0].cost, 3);
367 EXPECT_EQ(epp[1].cost, 5);
368 EXPECT_EQ(epp[2].cost, 7);
369 EXPECT_EQ(epp[3].cost, 9);
371 EXPECT_FALSE(same_node_sequence(epp[1].
nodes, yen[0].
nodes));
375TEST(KShortestPathsTest, SourceEqualsTargetReturnsTrivialPath)
377 const auto edges = make_edges({
378 {0, 1, 2}, {1, 2, 2}, {2, 0, 2}
380 auto built = build_graph(3, edges);
382 const auto got = yen_k_shortest_paths<Graph>(
383 built.g, built.nodes[1], built.nodes[1], 10);
385 ASSERT_EQ(got.size(), 1u);
386 const auto normalized = normalize_results(got);
387 ASSERT_EQ(normalized.size(), 1u);
388 EXPECT_EQ(normalized[0].cost, 0);
389 ASSERT_EQ(normalized[0].
nodes.size(), 1u);
390 EXPECT_EQ(normalized[0].
nodes(0), 1);
394TEST(KShortestPathsTest, UnreachableReturnsEmpty)
396 const auto edges = make_edges({
397 {0, 1, 1}, {1, 0, 1}, {2, 3, 1}
399 auto built = build_graph(4, edges);
401 const auto got = yen_k_shortest_paths<Graph>(
402 built.g, built.nodes[0], built.nodes[3], 4);
403 EXPECT_TRUE(got.is_empty());
407TEST(KShortestPathsTest, NegativeWeightsThrowDomainError)
409 const auto edges = make_edges({
410 {0, 1, 2}, {1, 2, -5}, {0, 2, 9}
412 auto built = build_graph(3, edges);
415 (yen_k_shortest_paths<Graph>(built.g, built.nodes[0], built.nodes[2], 3)),
418 (eppstein_k_shortest_paths<Graph>(built.g, built.nodes[0], built.nodes[2], 3)),
423TEST(KShortestPathsTest, RandomSmallGraphsMatchExactOracle)
425 std::mt19937_64
rng(0xBADC0FFEEULL);
426 std::uniform_int_distribution<int> n_dist(3, 8);
428 for (
size_t trial = 0; trial < 80; ++trial)
430 const size_t n =
static_cast<size_t>(n_dist(
rng));
431 auto built = build_graph(n, random_graph_edges(
rng, n));
432 Node * source = built.nodes[0];
433 Node * target = built.nodes[n - 1];
434 constexpr size_t K = 7;
436 const auto expected = exact_k_shortest_simple_paths(
439 const auto yen = normalize_results(
440 yen_k_shortest_paths<Graph>(built.g, source, target, K));
441 const auto epp = normalize_results(
442 eppstein_k_shortest_paths<Graph>(built.g, source, target, K));
444 ASSERT_EQ(yen.size(),
expected.size()) <<
"trial=" << trial;
445 ASSERT_GE(epp.size(),
expected.size()) <<
"trial=" << trial;
446 ASSERT_LE(epp.size(), K) <<
"trial=" << trial;
448 for (
size_t i = 0; i <
expected.size(); ++i)
450 EXPECT_EQ(yen[i].cost,
expected[i].cost)
451 <<
"trial=" << trial <<
", i=" << i;
453 <<
"trial=" << trial <<
", i=" << i;
457 EXPECT_EQ(epp[0].cost,
expected[0].cost)
458 <<
"trial=" << trial;
460 for (
size_t i = 1; i < epp.size(); ++i)
462 EXPECT_GE(epp[i].cost, epp[i - 1].cost)
463 <<
"trial=" << trial <<
", i=" << i;
469TEST(KShortestPathsTest, ReturnedPathsAreSimpleAndNonDecreasingCost)
471 const auto edges = make_edges({
472 {0, 1, 1}, {0, 2, 4}, {1, 2, 1}, {1, 3, 2},
473 {2, 3, 1}, {2, 4, 3}, {3, 4, 1}
475 auto built = build_graph(5, edges);
477 const auto got = yen_k_shortest_paths<Graph>(
478 built.g, built.nodes[0], built.nodes[4], 10);
480 long long prev = std::numeric_limits<long long>::min();
481 for (
auto it = got.get_it(); it.has_curr(); it.next_ne())
483 const auto & item = it.get_curr();
484 EXPECT_TRUE(is_simple_path(item.path));
485 EXPECT_GE(item.total_cost, prev);
486 prev = item.total_cost;
491TEST(KShortestPathsTest, EppsteinResultsAreNonDecreasingCost)
493 const auto edges = make_edges({
494 {0, 1, 1}, {1, 2, 1}, {2, 3, 1},
497 auto built = build_graph(5, edges);
499 const auto got = eppstein_k_shortest_paths<Graph>(
500 built.g, built.nodes[0], built.nodes[3], 8);
502 long long prev = std::numeric_limits<long long>::min();
503 for (
auto it = got.get_it(); it.has_curr(); it.next_ne())
505 const auto & item = it.get_curr();
506 EXPECT_GE(item.total_cost, prev);
507 prev = item.total_cost;
512TEST(KShortestPathsTest, SelfLoopAndParallelArcs)
527 const auto edges = make_edges({
533 auto built = build_graph(3, edges);
536 const auto yen_results = normalize_results(
537 yen_k_shortest_paths<Graph>(built.g, built.nodes[0], built.nodes[2], K));
538 const auto epp_results = normalize_results(
539 eppstein_k_shortest_paths<Graph>(built.g, built.nodes[0], built.nodes[2], K));
541 ASSERT_EQ(yen_results.size(), 2u);
542 ASSERT_EQ(epp_results.size(), 2u);
545 EXPECT_EQ(yen_results[0].cost, 15);
546 EXPECT_EQ(yen_results[0].
nodes.size(), 3u);
547 EXPECT_EQ(yen_results[0].
nodes(0), 0);
548 EXPECT_EQ(yen_results[0].
nodes(1), 1);
549 EXPECT_EQ(yen_results[0].
nodes(2), 2);
552 EXPECT_EQ(yen_results[1].cost, 25);
553 EXPECT_EQ(yen_results[1].
nodes.size(), 3u);
554 EXPECT_EQ(yen_results[1].
nodes(0), 0);
555 EXPECT_EQ(yen_results[1].
nodes(1), 1);
556 EXPECT_EQ(yen_results[1].
nodes(2), 2);
559 EXPECT_EQ(epp_results[0], yen_results[0]);
563 EXPECT_EQ(epp_results[1].cost, 20);
564 EXPECT_EQ(epp_results[1].
nodes.size(), 4u);
565 EXPECT_EQ(epp_results[1].
nodes(0), 0);
566 EXPECT_EQ(epp_results[1].
nodes(1), 1);
567 EXPECT_EQ(epp_results[1].
nodes(2), 1);
568 EXPECT_EQ(epp_results[1].
nodes(3), 2);
577TEST(KShortestPathsTest, EppsteinLeavesOutTheWalksWhoseCostDoesNotFit)
580 constexpr int M = std::numeric_limits<int>::max();
583 auto * s = g.insert_node(0);
584 auto * t = g.insert_node(1);
585 g.insert_arc(s, t, 1);
586 g.insert_arc(t, t, M);
588 const auto one = eppstein_k_shortest_paths<Int_Graph>(g, s, t, 1);
589 ASSERT_EQ(one.size(), 1u);
590 EXPECT_EQ(one.get_first().total_cost, 1);
592 EXPECT_THROW(eppstein_k_shortest_paths<Int_Graph>(g, s, t, 2), std::overflow_error);
595 g.insert_arc(s, t, 5);
596 const auto two = eppstein_k_shortest_paths<Int_Graph>(g, s, t, 2);
597 ASSERT_EQ(two.size(), 2u);
598 EXPECT_EQ(two.get_first().total_cost, 1);
599 EXPECT_EQ(two.get_last().total_cost, 5);
600 EXPECT_THROW(eppstein_k_shortest_paths<Int_Graph>(g, s, t, 3), std::overflow_error);
604 auto * a =
h.insert_node(0);
605 auto * b =
h.insert_node(1);
606 auto * x =
h.insert_node(2);
607 h.insert_arc(a, b, 1);
608 h.insert_arc(a, x, M);
609 h.insert_arc(x, b, 1);
610 EXPECT_EQ(eppstein_k_shortest_paths<Int_Graph>(
h, a, b, 1).
size(), 1u);
611 EXPECT_THROW(eppstein_k_shortest_paths<Int_Graph>(
h, a, b, 2), std::overflow_error);
617TEST(KShortestPathsTest, APathOfExactlyMaxIsGiven)
620 constexpr int M = std::numeric_limits<int>::max();
623 auto * a = g.insert_node(0);
624 auto * b = g.insert_node(1);
625 auto * c = g.insert_node(2);
626 g.insert_arc(a, b, M - 1);
627 g.insert_arc(b, c, 1);
629 for (
bool by_yen : {
true,
false})
631 SCOPED_TRACE(by_yen ?
"Yen" :
"Eppstein");
632 const auto one = by_yen ? yen_k_shortest_paths<Int_Graph>(g, a, c, 2)
633 : eppstein_k_shortest_paths<Int_Graph>(g, a, c, 2);
634 ASSERT_EQ(one.size(), 1u);
635 EXPECT_EQ(one.get_first().total_cost, M);
639 g.insert_arc(a, b, M / 2);
640 for (
bool by_yen : {
true,
false})
642 SCOPED_TRACE(by_yen ?
"Yen" :
"Eppstein");
643 const auto two = by_yen ? yen_k_shortest_paths<Int_Graph>(g, a, c, 2)
644 : eppstein_k_shortest_paths<Int_Graph>(g, a, c, 2);
645 ASSERT_EQ(two.size(), 2u);
646 EXPECT_EQ(two.get_first().total_cost, M / 2 + 1);
647 EXPECT_EQ(two.get_last().total_cost, M);
654TEST(KShortestPathsTest, YenGoesOnPastASpurNodeBeyondMax)
657 constexpr int M = std::numeric_limits<int>::max();
660 auto * s = g.insert_node(0);
661 auto * a = g.insert_node(1);
662 auto * c = g.insert_node(2);
663 auto * d = g.insert_node(3);
664 auto * t = g.insert_node(4);
665 g.insert_arc(s, a, 1);
666 g.insert_arc(a, t, 1);
667 g.insert_arc(a, c, 1);
668 g.insert_arc(c, t, 1);
669 g.insert_arc(s, d, M - 1);
670 g.insert_arc(d, t, M - 1);
672 const auto two = yen_k_shortest_paths<Int_Graph>(g, s, t, 2);
673 ASSERT_EQ(two.size(), 2u);
674 EXPECT_EQ(two.get_first().total_cost, 2);
675 EXPECT_EQ(two.get_last().total_cost, 3);
677 EXPECT_THROW(yen_k_shortest_paths<Int_Graph>(g, s, t, 3), std::overflow_error);
682TEST(KShortestPathsTest, EppsteinTakesAHeavyParallelArcOfTheTree)
686 constexpr int M = std::numeric_limits<int>::max();
689 auto * s = g.insert_node(0);
690 auto * a = g.insert_node(1);
691 auto * t = g.insert_node(2);
692 g.insert_arc(s, a, 1);
693 g.insert_arc(s, a, M);
694 g.insert_arc(a, t, 1);
695 const auto walks = eppstein_k_shortest_paths<Int_Graph>(g, s, t, 1);
696 ASSERT_EQ(walks.size(), 1u);
697 EXPECT_EQ(walks.get_first().total_cost, 2);
700 auto * us = u.insert_node(0);
701 auto * ua = u.insert_node(1);
702 auto * ut = u.insert_node(2);
703 u.insert_arc(us, ua, 1);
704 u.insert_arc(us, ua, M);
705 u.insert_arc(ua, ut, 1);
706 const auto uwalks = eppstein_k_shortest_paths<Int_Undigraph>(u, us, ut, 1);
707 ASSERT_EQ(uwalks.size(), 1u);
708 EXPECT_EQ(uwalks.get_first().total_cost, 2);
716TEST(KShortestPathsTest, EppsteinLeavesOutOfItsIndexANodeBeyondMax)
720 constexpr int M = std::numeric_limits<int>::max();
725 auto * s = g.insert_node(0);
726 auto * t = g.insert_node(1);
727 auto * x = g.insert_node(2);
728 auto *
y = g.insert_node(3);
729 g.insert_arc(s, t, 1);
730 g.insert_arc(x,
y, M - 1);
731 g.insert_arc(
y, t, M - 1);
733 const auto walks = eppstein_k_shortest_paths<Int_Graph>(g, s, t, 2);
734 ASSERT_EQ(walks.size(), 1u);
735 EXPECT_EQ(walks.get_first().total_cost, 1);
736 const auto from_y = eppstein_k_shortest_paths<Int_Graph>(g,
y, t, 1);
737 ASSERT_EQ(from_y.size(), 1u);
738 EXPECT_EQ(from_y.get_first().total_cost, M - 1);
740 EXPECT_THROW(eppstein_k_shortest_paths<Int_Graph>(g, x, t, 1), std::overflow_error);
743 g.insert_arc(s, x, 1);
744 const auto one = eppstein_k_shortest_paths<Int_Graph>(g, s, t, 1);
745 ASSERT_EQ(one.size(), 1u);
746 EXPECT_EQ(one.get_first().total_cost, 1);
747 EXPECT_THROW(eppstein_k_shortest_paths<Int_Graph>(g, s, t, 2), std::overflow_error);
751 auto * us = u.insert_node(0);
752 auto * ut = u.insert_node(1);
753 auto * ux = u.insert_node(2);
754 auto * uy = u.insert_node(3);
755 u.insert_arc(us, ut, 1);
756 u.insert_arc(ux, uy, M - 1);
757 u.insert_arc(uy, ut, M - 1);
758 const auto uwalks = eppstein_k_shortest_paths<Int_Undigraph>(u, us, ut, 2);
759 ASSERT_EQ(uwalks.size(), 2u);
760 EXPECT_EQ(uwalks.get_first().total_cost, 1);
761 EXPECT_EQ(uwalks.get_last().total_cost, 3);
762 EXPECT_THROW(eppstein_k_shortest_paths<Int_Undigraph>(u, ux, ut, 1), std::overflow_error);
769TEST(KShortestPathsTest, AnOverflowErrorOfTheDistanceOrOfTheFilterPassesOn)
772 using Arc = Int_Graph::Arc;
773 constexpr int M = std::numeric_limits<int>::max();
778 auto * s = g.insert_node(0);
779 auto * a = g.insert_node(1);
780 auto * c = g.insert_node(2);
781 auto * d = g.insert_node(3);
782 auto * t = g.insert_node(4);
783 g.insert_arc(s, a, 1);
784 g.insert_arc(a, t, 1);
785 g.insert_arc(a, c, 1);
786 g.insert_arc(c, t, 1);
787 g.insert_arc(s, d, M - 1);
788 g.insert_arc(d, t, M - 1);
799 throw std::overflow_error(
"thrown by the distance");
800 return arc->get_info();
807 bool operator()(
Arc *)
const
810 throw std::overflow_error(
"thrown by the filter");
815 size_t distance_calls = 0, filter_calls = 0;
816 for (
bool by_yen : {
true,
false})
817 for (
bool by_distance : {
true,
false})
819 SCOPED_TRACE(std::string(by_yen ?
"Yen" :
"Eppstein")
820 + (by_distance ?
", the distance" :
", the filter"));
821 const size_t & calls = by_distance ? distance_calls : filter_calls;
823 by_distance ?
"thrown by the distance" :
"thrown by the filter";
824 auto run = [&] (
size_t at)
826 distance_calls = filter_calls = 0;
827 const Distance distance{&distance_calls, by_distance ? at : 0};
828 const Filter
filter{&filter_calls, by_distance ? 0 : at};
834 ASSERT_EQ(run(0), 2u);
835 const size_t total = calls;
836 ASSERT_GT(total, 0u);
837 for (
size_t at = 1; at <= total; ++at)
844 catch (
const std::overflow_error & e)
847 EXPECT_STREQ(e.what(), what) <<
"at the call " << at;
850 EXPECT_TRUE(threw or calls < at)
851 <<
"the call " << at <<
" threw nothing out";
875TEST(KShortestPathsTest, PerfRegression)
877 const char * env = std::getenv(
"PERF_TESTS_ENABLED");
878 if (env ==
nullptr or std::string(env) !=
"1")
879 GTEST_SKIP() <<
"Skipped: set PERF_TESTS_ENABLED=1 to run";
881 constexpr size_t N = 40;
882 constexpr size_t K = 25;
883 constexpr int TRIALS = 3;
884 constexpr long long BUDGET_MS = 1000;
885 constexpr uint64_t MASTER_SEED = 0xDEADBEEFCAFEBABEULL;
887 std::mt19937_64
rng(MASTER_SEED);
889 for (
int trial = 0; trial < TRIALS; ++trial)
891 auto built = build_graph(
N, random_graph_edges(
rng,
N));
892 Node * src = built.nodes[0];
893 Node * tgt = built.nodes[
N - 1];
897 const auto t0 = std::chrono::steady_clock::now();
898 const auto result = yen_k_shortest_paths<Graph>(built.g, src, tgt, K);
899 const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
900 std::chrono::steady_clock::now() - t0).count();
902 EXPECT_LE(elapsed, BUDGET_MS)
903 <<
"yen_k_shortest_paths exceeded budget on trial " << trial
904 <<
": " << elapsed <<
" ms (budget " << BUDGET_MS <<
" ms,"
905 <<
" N=" <<
N <<
", K=" << K <<
", seed=" << MASTER_SEED <<
")";
907 EXPECT_LE(result.size(), K) <<
"trial=" << trial;
910 long long prev = std::numeric_limits<long long>::min();
911 for (
auto it = result.get_it(); it.has_curr(); it.next_ne())
913 EXPECT_GE(it.get_curr().total_cost, prev) <<
"trial=" << trial;
914 prev = it.get_curr().total_cost;
920 const auto t0 = std::chrono::steady_clock::now();
921 const auto result = eppstein_k_shortest_paths<Graph>(built.g, src, tgt, K);
922 const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
923 std::chrono::steady_clock::now() - t0).count();
925 EXPECT_LE(elapsed, BUDGET_MS)
926 <<
"eppstein_k_shortest_paths exceeded budget on trial " << trial
927 <<
": " << elapsed <<
" ms (budget " << BUDGET_MS <<
" ms,"
928 <<
" N=" <<
N <<
", K=" << K <<
", seed=" << MASTER_SEED <<
")";
930 EXPECT_LE(result.size(), K) <<
"trial=" << trial;
932 long long prev = std::numeric_limits<long long>::min();
933 for (
auto it = result.get_it(); it.has_curr(); it.next_ne())
935 EXPECT_GE(it.get_curr().total_cost, prev) <<
"trial=" << trial;
936 prev = it.get_curr().total_cost;
K-shortest path algorithms (Yen and Eppstein-style API).
WeightedDigraph::Node Node
size_t size_t int32_t * out
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
T & append(const T &data)
Append a copy of data
void reserve(size_t cap)
Reserves cap cells into the array.
Generic directed graph (digraph) wrapper template.
size_t size() const noexcept
Return the current dimension of array.
T pop()
Remove the last item of array (as if this was a stack)
T & append()
Allocate a new entry to the end of array.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Arc Arc
The node class type.
Number Theoretic Transform over Z / MOD Z.
Open addressing hash table with linear probing collision resolution.
constexpr bool contains(const Key &key) const noexcept
Alias for has().
void remove(const Key &key)
Remove the key referenced by key.
Iterator on nodes and arcs of a path.
bool has_current_node() const noexcept
Return true if the iterator has a current node.
Minimal std::expected-style result type for C++20.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
DynArray< Graph::Node * > nodes
DynList< K_Shortest_Path_Item< GT, typename Distance::Distance_Type > > yen_k_shortest_paths(const GT &g, typename GT::Node *source, typename GT::Node *target, const size_t k, Distance distance=Distance(), SA sa=SA())
Compute k shortest loopless paths using Yen's algorithm.
DynList< K_Shortest_Path_Item< GT, typename Distance::Distance_Type > > eppstein_k_shortest_paths(const GT &g, typename GT::Node *source, typename GT::Node *target, const size_t k, Distance distance=Distance(), SA sa=SA())
Compute k shortest general (loopy) paths.
DFSResult< typename Domain::Distance > dfs(Domain &domain, typename Domain::State &state, SearchPath< typename Domain::Move > &path, const typename Domain::Distance g, const typename Domain::Distance threshold, const size_t depth, IDAStarResult< Solution, typename Domain::Distance > &result, OnSolution &on_solution)
Core recursive DFS used by IDA* for a single threshold pass.
Main namespace for Aleph-w library functions.
bool operator==(const DynList< T > &l1, const DynList< T > &l2)
Equality operator for DynList.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
Container2< typename Container1::Item_Type > filter(Container1 &container, Operation &operation)
Filter elements that satisfy operation.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
and
Check uniqueness with explicit hash + equality functors.
static std::atomic< bool > init
std::tuple< size_t, size_t, long long > Edge_Def
Built_Graph_T< Graph > build_graph(const size_t n, const std::vector< Edge_Def > &edges)
Arc of graph implemented with double-linked adjacency lists.
Filtered iterator of adjacent arcs of a node.
Distance_Type operator()(Arc *a) const
Dynamic array container with automatic resizing.
Lazy and scalable dynamic array implementation.
Generic graph and digraph implementations.
Open addressing hash table with linear probing.