37# include <gtest/gtest.h>
60 using Edge_Def = std::tuple<size_t, size_t, long long>;
61 using Float_Edge_Def = std::tuple<size_t, size_t, double>;
68 std::vector<typename GT::Node *>
nodes;
69 std::vector<typename GT::Arc *>
arcs;
72 using Built_Graph = Built_Graph_T<Graph>;
73 using Built_Float_Graph = Built_Graph_T<Float_Graph>;
74 using Built_Array_Graph = Built_Graph_T<Array_Graph>;
76 template <
class GT,
typename Weight_Type>
78 build_graph_generic(
const size_t n,
const std::vector<std::tuple<size_t, size_t, Weight_Type>> & edges)
80 Built_Graph_T<GT> built;
81 built.nodes.reserve(n);
82 built.arcs.reserve(edges.size());
84 for (
size_t i = 0; i < n; ++i)
85 built.nodes.push_back(built.g.insert_node(
static_cast<int>(i)));
87 for (
const auto & [u, v,
w] : edges)
89 built.
arcs.push_back(built.g.insert_arc(built.
nodes[u], built.
nodes[v],
w));
94 Built_Graph
build_graph(
const size_t n,
const std::vector<Edge_Def> & edges)
96 return build_graph_generic<Graph, long long>(n, edges);
99 Built_Float_Graph build_float_graph(
const size_t n,
const std::vector<Float_Edge_Def> & edges)
101 return build_graph_generic<Float_Graph, double>(n, edges);
104 Built_Array_Graph build_array_graph(
const size_t n,
const std::vector<Edge_Def> & edges)
106 return build_graph_generic<Array_Graph, long long>(n, edges);
110 struct Exact_Oracle_Result
113 long double minimum_mean = std::numeric_limits<long double>::infinity();
117 Exact_Oracle_Result exact_minimum_mean_cycle(
const Built_Graph & built)
119 const size_t n = built.nodes.size();
121 Exact_Oracle_Result
oracle;
122 std::vector<bool> visited(n,
false);
124 std::function<void(
size_t,
size_t,
long long,
size_t)>
dfs =
125 [&](
const size_t start,
127 const long long cost,
132 Arc * arc = it.get_current_arc_ne();
133 const size_t v =
static_cast<size_t>(it.get_tgt_node()->get_info());
134 const long long w = arc->get_info();
138 const size_t cyc_len = len + 1;
139 const long double mean =
static_cast<long double>(cost +
w)
140 /
static_cast<long double>(cyc_len);
142 if (mean <
oracle.minimum_mean)
151 dfs(start, v, cost +
w, len + 1);
156 for (
size_t s = 0; s < n; ++s)
167 bool witness_cycle_is_consistent(
const Graph & g,
const Result &
r)
169 if (
r.cycle_length == 0)
170 return r.cycle_nodes.is_empty()
and r.cycle_arcs.is_empty();
172 if (
r.cycle_nodes.size() !=
r.cycle_length + 1)
174 if (
r.cycle_arcs.size() !=
r.cycle_length)
177 auto node_it =
r.cycle_nodes.get_it();
178 if (not node_it.has_curr())
181 Node * first = node_it.get_curr();
185 for (
auto arc_it =
r.cycle_arcs.get_it(); arc_it.has_curr(); arc_it.next_ne())
187 if (not node_it.has_curr())
190 Arc * arc = arc_it.get_curr();
200 return curr == first
and not node_it.has_curr();
206 Arc * blocked =
nullptr;
208 bool operator()(
Arc * arc)
const noexcept
210 return arc != blocked;
216TEST(MinMeanCycleTest, EmptyDigraphReturnsNoCycle)
221 EXPECT_FALSE(
r.has_cycle);
222 EXPECT_EQ(
r.cycle_length, 0u);
223 EXPECT_TRUE(
r.cycle_nodes.is_empty());
224 EXPECT_TRUE(
r.cycle_arcs.is_empty());
228TEST(MinMeanCycleTest, DagReturnsNoCycle)
230 const std::vector<Edge_Def> edges = {
231 {0, 1, 2}, {1, 2, 3}, {2, 3, 4}, {0, 3, 10}
234 auto built = build_graph(4, edges);
237 EXPECT_FALSE(
r.has_cycle);
238 EXPECT_EQ(
r.cycle_length, 0u);
242TEST(MinMeanCycleTest, SelfLoopCanBeOptimalCycle)
244 const std::vector<Edge_Def> edges = {
245 {0, 1, 8}, {1, 1, 3}, {1, 2, 7}, {2, 0, 9}
248 auto built = build_graph(3, edges);
251 ASSERT_TRUE(
r.has_cycle);
252 EXPECT_NEAR(
static_cast<double>(
r.minimum_mean), 3.0, 1e-12);
253 EXPECT_EQ(
r.cycle_length, 1u);
254 EXPECT_EQ(
r.cycle_nodes.size(), 2u);
255 EXPECT_EQ(
r.cycle_total_cost, 3);
256 EXPECT_TRUE(witness_cycle_is_consistent(built.g,
r));
260TEST(MinMeanCycleTest, ChoosesMinimumAmongMultipleCycles)
262 const std::vector<Edge_Def> edges = {
263 {0, 1, 3}, {1, 0, 1},
264 {1, 2, 1}, {2, 1, 1},
268 auto built = build_graph(3, edges);
271 ASSERT_TRUE(
r.has_cycle);
272 EXPECT_NEAR(
static_cast<double>(
r.minimum_mean), 1.0, 1e-12);
273 EXPECT_TRUE(witness_cycle_is_consistent(built.g,
r));
277TEST(MinMeanCycleTest, SupportsNegativeMeanCycles)
279 const std::vector<Edge_Def> edges = {
280 {0, 1, -5}, {1, 2, 1}, {2, 0, 1},
284 auto built = build_graph(4, edges);
287 ASSERT_TRUE(
r.has_cycle);
288 EXPECT_NEAR(
static_cast<double>(
r.minimum_mean), -1.0, 1e-12);
289 EXPECT_TRUE(witness_cycle_is_consistent(built.g,
r));
293TEST(MinMeanCycleTest, ArcFilterChangesResult)
295 const std::vector<Edge_Def> edges = {
296 {0, 1, 1}, {1, 0, 1},
300 auto built = build_graph(4, edges);
303 ASSERT_TRUE(full.has_cycle);
304 EXPECT_NEAR(
static_cast<double>(full.minimum_mean), 1.0, 1e-12);
306 const Hide_Arc
filter{built.arcs[0]};
307 const auto filtered = karp_minimum_mean_cycle<Graph, Dft_Dist<Graph>, Hide_Arc>(
310 ASSERT_TRUE(filtered.has_cycle);
311 EXPECT_NEAR(
static_cast<double>(filtered.minimum_mean), 3.0, 1e-12);
312 EXPECT_TRUE(witness_cycle_is_consistent(built.g, filtered));
315TEST(MinMeanCycleTest, AccessorIsReadOncePerAcceptedArc)
322 using Distance_Type =
long long;
323 int * calls =
nullptr;
325 Distance_Type operator()(
Arc * arc)
const
328 return arc->get_info();
332 auto built = build_graph(4, {{0, 1, 1}, {1, 0, 1}, {1, 2, -4}, {2, 1, 1}, {2, 3, 7}});
333 const Hide_Arc
filter{built.arcs[4]};
336 const auto full = karp_minimum_mean_cycle<Graph, Counting_Dist, Hide_Arc>(
337 built.g, Counting_Dist{&calls},
filter);
338 ASSERT_TRUE(full.has_cycle);
339 EXPECT_EQ(full.minimum_mean, -1.5L);
340 EXPECT_EQ(full.cycle_total_cost, -3);
344 const auto value = karp_minimum_mean_cycle_value<Graph, Counting_Dist, Hide_Arc>(
345 built.g, Counting_Dist{&calls},
filter);
346 EXPECT_EQ(
value.minimum_mean, full.minimum_mean);
350TEST(MinMeanCycleTest, WitnessMeansAreComparedExactly)
356 EXPECT_TRUE(mean_less(-3LL, 2, -2LL, 2));
357 EXPECT_FALSE(mean_less(-3LL, 3, -2LL, 2));
358 EXPECT_TRUE(mean_less(-5LL, 3, -3LL, 2));
359 EXPECT_FALSE(mean_less(-3LL, 2, -5LL, 3));
360 EXPECT_TRUE(mean_less(1LL, 3, 1LL, 2));
361 EXPECT_FALSE(mean_less(2LL, 6, 1LL, 3));
362 EXPECT_TRUE(mean_less(-1.5, 1, -1.0, 1));
363# if ALEPH_KARP_INT128
367 using min_mean_cycle_detail::karp_int128_t;
368 constexpr int shift = std::numeric_limits<long double>::digits + 2;
369 static_assert(shift <= 124,
"3 * 2^shift must fit a 128-bit integer");
370 const karp_int128_t big =
static_cast<karp_int128_t
>(1) << shift;
371 ASSERT_EQ(
static_cast<long double>(big - 1),
static_cast<long double>(big));
372 EXPECT_TRUE(mean_less(3 * big - 3, 3, big, 1));
373 EXPECT_FALSE(mean_less(big, 1, 3 * big - 3, 3));
377TEST(MinMeanCycleTest, TableBytesAreTheBytesArrayReserves)
382 using namespace min_mean_cycle_detail;
384 ASSERT_TRUE((karp_table_bytes<true, long long>(0, Karp_Sums::Long_Long, bytes)));
385 EXPECT_EQ(bytes, 0u);
386 ASSERT_TRUE((karp_table_bytes<true, long long>(3, Karp_Sums::Long_Long, bytes)));
387 EXPECT_EQ(bytes, 16u * (8 + 8));
388 ASSERT_TRUE((karp_table_bytes<false, long long>(3, Karp_Sums::Long_Long, bytes)));
389 EXPECT_EQ(bytes, 16u * 8);
390 ASSERT_TRUE((karp_table_bytes<true, long long>(1000, Karp_Sums::Long_Long, bytes)));
391 EXPECT_EQ(bytes, (
size_t{1} << 20) * 16);
392 ASSERT_TRUE((karp_table_bytes<true, double>(15, Karp_Sums::Cost_Type_Checked, bytes)));
393 EXPECT_EQ(bytes, 256u * (
sizeof(
double) + 8));
394 ASSERT_TRUE((karp_table_bytes<false, long double>(15, Karp_Sums::Cost_Type_Checked, bytes)));
395 EXPECT_EQ(bytes, 256u *
sizeof(
long double));
396# if ALEPH_KARP_INT128
397 ASSERT_TRUE((karp_table_bytes<true, long long>(3, Karp_Sums::Int128, bytes)));
398 EXPECT_EQ(bytes, 16u * (16 + 8));
403 EXPECT_FALSE((karp_table_bytes<true, long long>(std::numeric_limits<size_t>::max() / 2,
404 Karp_Sums::Long_Long, bytes)));
405 EXPECT_FALSE((karp_table_bytes<false, long long>(
size_t{1} << (std::numeric_limits<size_t>::digits / 2 - 1),
406 Karp_Sums::Long_Long, bytes)));
409 using In = Incoming_Arc<Graph, long long>;
410 const auto lists = [](
const long long w)
415 incoming(0).
append(In{1,
nullptr,
w});
416 incoming(1).
append(In{0,
nullptr, -
w});
419 EXPECT_EQ(karp_sums(lists(5)), Karp_Sums::Long_Long);
420 EXPECT_EQ(karp_sums(lists(std::numeric_limits<long long>::max() / 2 - 1)), Karp_Sums::Long_Long);
421# if ALEPH_KARP_INT128
422 EXPECT_EQ(karp_sums(lists(std::numeric_limits<long long>::max() / 2 + 1)), Karp_Sums::Int128);
424 EXPECT_EQ(karp_sums(lists(std::numeric_limits<long long>::max() / 2 + 1)), Karp_Sums::Long_Long_Checked);
427 floating.
append(
Array<Incoming_Arc<Float_Graph, double>>());
428 EXPECT_EQ(karp_sums(floating), Karp_Sums::Cost_Type_Checked);
431TEST(MinMeanCycleTest, WitnessIsASimpleCycle)
437 const auto check = [](
const auto & g,
const auto &
r,
const bool exact) -> ::testing::AssertionResult
439 using GT = std::decay_t<
decltype(g)>;
440 if (
r.cycle_length == 0 or
r.cycle_nodes.size() !=
r.cycle_length + 1
441 or
r.cycle_arcs.size() !=
r.cycle_length)
442 return ::testing::AssertionFailure() <<
"sizes";
443 std::vector<typename GT::Node *>
nodes;
444 for (
auto it =
r.cycle_nodes.get_it(); it.has_curr(); it.next_ne())
445 nodes.push_back(it.get_curr());
447 return ::testing::AssertionFailure() <<
"not closed";
448 for (
size_t i = 0; i + 1 <
nodes.size(); ++i)
449 for (
size_t j = i + 1; j + 1 <
nodes.size(); ++j)
451 return ::testing::AssertionFailure() <<
"node repeated: not a simple cycle";
454 for (
auto it =
r.cycle_arcs.get_it(); it.has_curr(); it.next_ne(), ++i)
456 auto * arc = it.get_curr();
458 return ::testing::AssertionFailure() <<
"arcs do not follow the nodes";
459 sum +=
static_cast<long double>(arc->get_info());
461 const long double cost =
static_cast<long double>(
r.cycle_total_cost);
462 const long double mean = cost /
static_cast<long double>(
r.cycle_length);
463 const long double tol = exact ? 0.0L : 1e-9L * (1.0L + std::fabs(
sum));
464 if (std::fabs(
sum - cost) > tol)
465 return ::testing::AssertionFailure() <<
"cost " << cost <<
" but arcs add up to " <<
sum;
466 if (std::fabs(
mean -
r.minimum_mean) > (exact ? 0.0L : 1e-9L * (1.0L + std::fabs(
mean))))
467 return ::testing::AssertionFailure() <<
"witness mean " <<
mean <<
", reported " <<
r.minimum_mean;
468 return ::testing::AssertionSuccess();
471 std::mt19937_64
rng(20261002);
472 for (
size_t trial = 0; trial < 3000; ++trial)
474 const size_t n = 1 +
rng() % 9;
475 const size_t m =
rng() % (3 * n + 1);
476 std::vector<Float_Edge_Def> fedges;
477 std::vector<Edge_Def> iedges;
478 for (
size_t i = 0; i <
m; ++i)
480 const size_t u =
rng() % n;
481 const size_t v =
rng() % n;
482 const double unit = std::uniform_real_distribution<double>(-1.0, 1.0)(
rng);
483 const int exponent =
static_cast<int>(
rng() % 40) - 20;
484 const long long w =
static_cast<long long>(
rng() % 41) - 20;
485 fedges.emplace_back(u, v, std::ldexp(unit, exponent));
486 iedges.emplace_back(u, v,
w);
489 auto fg = build_float_graph(n, fedges);
492 ASSERT_TRUE(
check(fg.g, fr,
false)) <<
"double, trial=" << trial;
494 auto ig = build_graph(n, iedges);
497 ASSERT_TRUE(
check(ig.g, ir,
true)) <<
"long long, trial=" << trial;
501TEST(MinMeanCycleTest, FloatingWeightsAndValueOnlyApiWork)
503 const std::vector<Float_Edge_Def> edges = {
504 {0, 1, 0.5}, {1, 0, 1.0},
505 {1, 2, 2.5}, {2, 1, 2.5}
508 auto built = build_float_graph(3, edges);
514 ASSERT_TRUE(full.has_cycle);
515 EXPECT_NEAR(
static_cast<double>(full.minimum_mean), 0.75, 1e-12);
517 ASSERT_TRUE(
value.has_cycle);
518 EXPECT_NEAR(
static_cast<double>(
value.minimum_mean), 0.75, 1e-12);
520 ASSERT_TRUE(alias_value.has_cycle);
521 EXPECT_NEAR(
static_cast<double>(alias_value.minimum_mean), 0.75, 1e-12);
523 ASSERT_TRUE(value_functor.has_cycle);
524 EXPECT_NEAR(
static_cast<double>(value_functor.minimum_mean), 0.75, 1e-12);
527TEST(MinMeanCycleTest, NonFiniteFloatingWeightsThrowDomainError)
529 Float_Graph inf_graph;
530 auto * i0 = inf_graph.insert_node(0);
531 auto * i1 = inf_graph.insert_node(1);
532 inf_graph.insert_arc(i0, i1, std::numeric_limits<double>::infinity());
533 inf_graph.insert_arc(i1, i0, 1.0);
538 Float_Graph nan_graph;
539 auto * n0 = nan_graph.insert_node(0);
540 auto * n1 = nan_graph.insert_node(1);
541 nan_graph.insert_arc(n0, n1, std::numeric_limits<double>::quiet_NaN());
542 nan_graph.insert_arc(n1, n0, 1.0);
548TEST(MinMeanCycleTest, IntegerOverflowInAccumulationThrows)
554 const std::vector<Edge_Def> edges = {
555 {0, 1, std::numeric_limits<long long>::max()},
559 auto built = build_graph(2, edges);
561# if ALEPH_KARP_INT128
563 ASSERT_TRUE(
value.has_cycle);
564 EXPECT_EQ(
value.minimum_mean, 0x1p62L);
570TEST(MinMeanCycleTest, SumsBeyondTheCostTypeAreExact)
576 const long long max = std::numeric_limits<long long>::max();
577 const long long q = 1LL << 62;
579 auto loop = build_graph(1, {{0, 0,
max}});
580 auto pair = build_graph(3, {{0, 1, q}, {1, 0, q}, {0, 0, q - 1}, {2, 0, -q}, {2, 1, -q}});
581# if ALEPH_KARP_INT128
583 ASSERT_TRUE(
r.has_cycle);
584 EXPECT_EQ(
r.minimum_mean,
static_cast<long double>(
max));
585 EXPECT_EQ(
r.cycle_total_cost,
max);
586 EXPECT_EQ(
r.cycle_length, 1u);
589 ASSERT_TRUE(p.has_cycle);
590 EXPECT_EQ(p.minimum_mean,
static_cast<long double>(q - 1));
591 EXPECT_EQ(p.cycle_total_cost, q - 1);
592 EXPECT_EQ(p.cycle_length, 1u);
600 const int imax = std::numeric_limits<int>::max();
601 auto narrow = build_graph_generic<Int_Graph, int>(3, {{0, 1, imax}, {1, 0, imax}, {0, 0, imax - 1}});
603 ASSERT_TRUE(i.has_cycle);
604 EXPECT_EQ(i.cycle_total_cost, imax - 1);
605 EXPECT_EQ(i.minimum_mean,
static_cast<long double>(imax - 1));
608TEST(MinMeanCycleTest, BoundedSumsMayReachOneBelowTheSentinel)
613 const long long w = (1LL << 62) - 1;
614 auto b = build_graph(2, {{0, 1,
w}, {1, 0,
w}});
616 ASSERT_TRUE(
r.has_cycle);
617 EXPECT_EQ(
r.minimum_mean,
static_cast<long double>(
w));
618 EXPECT_EQ(
r.cycle_total_cost, 2 *
w);
622TEST(MinMeanCycleTest, AMinimumMeanCycleWhoseCostFitsIsPreferred)
630# if ALEPH_KARP_INT128
631 auto b = build_graph_generic<Small_Graph, int8_t>(3, {{0, 1, -124}, {1, 0, -124}, {2, 2, -124}});
633 ASSERT_TRUE(
r.has_cycle);
634 EXPECT_EQ(
r.minimum_mean, -124.0L);
635 EXPECT_EQ(
r.cycle_length, 1u);
636 EXPECT_EQ(
r.cycle_total_cost, -124);
637 EXPECT_EQ(
r.witness_node, b.nodes[2]);
641 auto alone = build_graph_generic<Small_Graph, int8_t>(2, {{0, 1, -124}, {1, 0, -124}});
646# if ALEPH_KARP_INT128
647TEST(MinMeanCycleTest, TheVertexIsChosenWithExactMeans)
653 const long long a = 1LL << 62;
654 auto b =
build_graph(6, {{0, 1, a}, {1, 2, a}, {2, 3, a}, {3, 4, a}, {4, 0, a + 1}, {5, 5, a}});
656 ASSERT_TRUE(
r.has_cycle);
657 EXPECT_EQ(
r.minimum_mean,
static_cast<long double>(a));
658 EXPECT_EQ(
r.cycle_length, 1u);
659 EXPECT_EQ(
r.cycle_total_cost, a);
664TEST(MinMeanCycleTest, SupportsArrayDigraphBackend)
666 const std::vector<Edge_Def> edges = {
667 {0, 1, 3}, {1, 2, 3}, {2, 0, 0},
671 auto built = build_array_graph(4, edges);
675 ASSERT_TRUE(
r.has_cycle);
676 EXPECT_NEAR(
static_cast<double>(
r.minimum_mean), 2.0, 1e-12);
677 ASSERT_TRUE(v.has_cycle);
678 EXPECT_NEAR(
static_cast<double>(v.minimum_mean), 2.0, 1e-12);
682TEST(MinMeanCycleTest, FunctorAndAliasMatchFreeFunction)
684 const std::vector<Edge_Def> edges = {
685 {0, 1, 2}, {1, 0, 2},
689 auto built = build_graph(3, edges);
695 ASSERT_EQ(free_result.has_cycle, alias_result.has_cycle);
696 ASSERT_EQ(free_result.has_cycle, functor_result.has_cycle);
697 if (free_result.has_cycle)
699 EXPECT_NEAR(
static_cast<double>(free_result.minimum_mean),
700 static_cast<double>(alias_result.minimum_mean),
702 EXPECT_NEAR(
static_cast<double>(free_result.minimum_mean),
703 static_cast<double>(functor_result.minimum_mean),
709TEST(MinMeanCycleTest, UndirectedGraphThrowsDomainError)
720TEST(MinMeanCycleTest, RandomSmallGraphsMatchExactOracle)
722 std::mt19937_64
rng(0xDA7A5EEDULL);
723 std::uniform_int_distribution<int> n_dist(2, 7);
724 std::bernoulli_distribution has_edge(0.36);
725 std::uniform_int_distribution<int> weight_dist(-9, 13);
727 for (
size_t trial = 0; trial < 90; ++trial)
729 const size_t n =
static_cast<size_t>(n_dist(
rng));
730 std::vector<Edge_Def> edges;
731 for (
size_t u = 0; u < n; ++u)
732 for (
size_t v = 0; v < n; ++v)
736 if (std::bernoulli_distribution(0.12)(
rng))
737 edges.emplace_back(u, v,
static_cast<long long>(weight_dist(
rng)));
742 edges.emplace_back(u, v,
static_cast<long long>(weight_dist(
rng)));
745 auto built = build_graph(n, edges);
746 const auto exact = exact_minimum_mean_cycle(built);
750 ASSERT_EQ(got.has_cycle, exact.has_cycle) <<
"trial=" << trial;
751 ASSERT_EQ(value_only.has_cycle, exact.has_cycle) <<
"trial=" << trial;
752 if (not got.has_cycle)
755 EXPECT_NEAR(
static_cast<double>(got.minimum_mean),
756 static_cast<double>(exact.minimum_mean),
758 <<
"trial=" << trial;
759 EXPECT_NEAR(
static_cast<double>(value_only.minimum_mean),
760 static_cast<double>(exact.minimum_mean),
762 <<
"trial=" << trial;
764 EXPECT_GT(got.cycle_length, 0u) <<
"trial=" << trial;
765 EXPECT_TRUE(witness_cycle_is_consistent(built.g, got)) <<
"trial=" << trial;
767 const long double witness_mean =
static_cast<long double>(got.cycle_total_cost)
768 /
static_cast<long double>(got.cycle_length);
769 EXPECT_GE(witness_mean + 1e-12L, got.minimum_mean) <<
"trial=" << trial;
Minimum mean cycle in directed graphs (Karp algorithm).
WeightedDigraph::Node Node
size_t size_t int32_t value
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Default distance accessor for arc weights.
Generic directed graph (digraph) wrapper template.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Functor wrapper for value-only minimum mean cycle.
Functor wrapper for Karp minimum mean cycle.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
DynArray< Graph::Node * > nodes
DynArray< Graph::Arc * > arcs
Min_Mean_Cycle_Value_Result minimum_mean_cycle_value(const GT &g, Distance distance=Distance(), SA sa=SA())
Alias for karp_minimum_mean_cycle_value().
Min_Mean_Cycle_Result< GT, typename Distance::Distance_Type > minimum_mean_cycle(const GT &g, Distance distance=Distance(), SA sa=SA())
Alias for karp_minimum_mean_cycle().
Min_Mean_Cycle_Value_Result karp_minimum_mean_cycle_value(const GT &g, Distance distance=Distance(), SA sa=SA())
Compute only the minimum mean value (without witness walk).
Min_Mean_Cycle_Result< GT, typename Distance::Distance_Type > karp_minimum_mean_cycle(const GT &g, Distance distance=Distance(), SA sa=SA())
Compute minimum mean cycle by Karp's algorithm.
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.
bool mean_less(const Acc c1, const size_t l1, const Acc c2, const size_t l2)
Whether the mean c1 / l1 is smaller than c2 / l2.
Main namespace for Aleph-w library functions.
Container2< typename Container1::Item_Type > filter(Container1 &container, Operation &operation)
Filter elements that satisfy operation.
and
Check uniqueness with explicit hash + equality functors.
auto mean(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute the arithmetic mean.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
void next()
Advance all underlying iterators (bounds-checked).
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
std::tuple< size_t, size_t, long long > Edge_Def
Built_Graph_T< GT > build_graph_generic(const size_t n, const std::vector< std::tuple< size_t, size_t, Weight_Type > > &edges)
Built_Graph_T< Graph > build_graph(const size_t n, const std::vector< Edge_Def > &edges)
List_Digraph< Graph_Node< int >, Graph_Arc< double > > Float_Graph
bool has_cycle(const Spec &s)
Whether the multigraph, not directed, has a cycle.
Arc of graph implemented with double-linked adjacency lists.
Result of minimum mean cycle computation.
bool has_cycle
True if at least one directed cycle exists.
Filtered iterator of adjacent arcs of a node.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Array-based graph implementation.
Generic graph and digraph implementations.