Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Bounded_Cycle_Result< GT, Cost_Type > Struct Template Reference

Result of most_negative_cycle_bounded(). More...

#include <Negative_Cycles.H>

Collaboration diagram for Aleph::Bounded_Cycle_Result< GT, Cost_Type >:
[legend]

Public Member Functions

bool is_negative () const noexcept
 True if a cycle was found and its total cost is negative.
 

Public Attributes

bool has_cycle = false
 True if the graph has a cycle of at most max_length arcs.
 
bool is_exact = false
 Proof that total_cost is the minimum cost of a simple cycle of at most max_length arcs: true exactly when optimality_gap is zero.
 
bool matches_relaxed_bound = false
 True when, in the arithmetic of the search, the cost the search computed for the reported cycle equals the minimum cost over the relaxed set of closed walks the dynamic program ranges over (see most_negative_cycle_bounded()), and that cost and the recomputed total_cost agree on the sign.
 
Cost_Type optimality_gap = Cost_Type{0}
 Rigorous upper bound of how much cheaper than total_cost the best simple cycle of at most max_length arcs can be: it is never negative, and zero means is_exact.
 
Cycle_Numeric_Quality numeric_quality = Cycle_Numeric_Quality::Exact
 Whether the sums and comparisons behind this result were exact.
 
Cost_Type total_cost = Cost_Type{0}
 Sum of the arc weights of the reported cycle (for floating-point costs the exact sum, rounded once, which can differ from the plain rounded sums the dynamic program compared).
 
size_t length = 0
 Number of arcs of the reported cycle.
 
DynList< typename GT::Node * > cycle_nodes
 Closed walk, first node repeated at the end.
 
DynList< typename GT::Arc * > cycle_arcs
 Arcs aligned with cycle_nodes.
 

Detailed Description

template<AlephGraph GT, typename Cost_Type>
struct Aleph::Bounded_Cycle_Result< GT, Cost_Type >

Result of most_negative_cycle_bounded().

cycle_nodes is a closed walk (the first node is repeated at the end) and cycle_arcs[i] goes from cycle_nodes[i] to cycle_nodes[i + 1], the same layout as Min_Mean_Cycle_Result.

Template Parameters
GTGraph type.
Cost_TypeArc weight type returned by the distance accessor.

Definition at line 261 of file Negative_Cycles.H.

Member Function Documentation

◆ is_negative()

template<AlephGraph GT, typename Cost_Type >
bool Aleph::Bounded_Cycle_Result< GT, Cost_Type >::is_negative ( ) const
inlinenoexcept

True if a cycle was found and its total cost is negative.

Definition at line 323 of file Negative_Cycles.H.

References Aleph::and, Aleph::Bounded_Cycle_Result< GT, Cost_Type >::has_cycle, and Aleph::Bounded_Cycle_Result< GT, Cost_Type >::total_cost.

Member Data Documentation

◆ cycle_arcs

template<AlephGraph GT, typename Cost_Type >
DynList<typename GT::Arc *> Aleph::Bounded_Cycle_Result< GT, Cost_Type >::cycle_arcs

Arcs aligned with cycle_nodes.

Definition at line 320 of file Negative_Cycles.H.

◆ cycle_nodes

template<AlephGraph GT, typename Cost_Type >
DynList<typename GT::Node *> Aleph::Bounded_Cycle_Result< GT, Cost_Type >::cycle_nodes

Closed walk, first node repeated at the end.

Definition at line 319 of file Negative_Cycles.H.

◆ has_cycle

template<AlephGraph GT, typename Cost_Type >
bool Aleph::Bounded_Cycle_Result< GT, Cost_Type >::has_cycle = false

True if the graph has a cycle of at most max_length arcs.

Definition at line 263 of file Negative_Cycles.H.

Referenced by Aleph::Bounded_Cycle_Result< GT, Cost_Type >::is_negative().

◆ is_exact

template<AlephGraph GT, typename Cost_Type >
bool Aleph::Bounded_Cycle_Result< GT, Cost_Type >::is_exact = false

Proof that total_cost is the minimum cost of a simple cycle of at most max_length arcs: true exactly when optimality_gap is zero.

With integral costs that is when the cost equals the minimum over the relaxed set of closed walks the dynamic program ranges over (see most_negative_cycle_bounded()). With floating-point costs the gap also covers the rounding of the search, so a proof is possible when no sum the search computes can be rounded (numeric_quality is Cycle_Numeric_Quality::Exact) and, rarely, otherwise; with market-like weights it is usually false even though the gap is tiny. matches_relaxed_bound keeps what the search concluded in its own arithmetic.

It is a sufficient condition for optimality of the cost, not a necessary one: it can be false although the reported cycle is optimal, and being false does not mean that every minimum-cost closed walk is non-simple. It says nothing about the number of arcs: among cycles of equal cost the one with fewest arcs is preferred only among the candidates the search evaluated, so a shorter cycle of the same cost may exist even when the flag is true.

Note
During development, before 2026-10-02, this flag was also set for floating-point costs whenever matches_relaxed_bound was.

Definition at line 287 of file Negative_Cycles.H.

◆ length

template<AlephGraph GT, typename Cost_Type >
size_t Aleph::Bounded_Cycle_Result< GT, Cost_Type >::length = 0

Number of arcs of the reported cycle.

Definition at line 318 of file Negative_Cycles.H.

◆ matches_relaxed_bound

template<AlephGraph GT, typename Cost_Type >
bool Aleph::Bounded_Cycle_Result< GT, Cost_Type >::matches_relaxed_bound = false

True when, in the arithmetic of the search, the cost the search computed for the reported cycle equals the minimum cost over the relaxed set of closed walks the dynamic program ranges over (see most_negative_cycle_bounded()), and that cost and the recomputed total_cost agree on the sign.

That set contains every simple cycle of the bound, so in exact arithmetic no simple cycle is cheaper than the reported one. With integral costs it equals is_exact. With floating-point costs it is a strong hint, not a proof: rounding can make a worse cycle win. For instance, in the ring 2^54, 1, -2^54, -2 (exact total -1) the plain sum loses the 1 and gives -2, so the ring beats a self-loop of -1.5 and this flag is true for it.

Definition at line 300 of file Negative_Cycles.H.

◆ numeric_quality

template<AlephGraph GT, typename Cost_Type >
Cycle_Numeric_Quality Aleph::Bounded_Cycle_Result< GT, Cost_Type >::numeric_quality = Cycle_Numeric_Quality::Exact

Whether the sums and comparisons behind this result were exact.

Definition at line 315 of file Negative_Cycles.H.

Referenced by Aleph::most_negative_cycle_bounded().

◆ optimality_gap

template<AlephGraph GT, typename Cost_Type >
Cost_Type Aleph::Bounded_Cycle_Result< GT, Cost_Type >::optimality_gap = Cost_Type{0}

Rigorous upper bound of how much cheaper than total_cost the best simple cycle of at most max_length arcs can be: it is never negative, and zero means is_exact.

With integral costs it is the exact difference with the relaxed minimum (saturated to the largest value of the type if it overflows). With floating-point costs it also covers the rounding of every sum the search made, computed with outward rounding; for market-like weights it is of the order of L² · u · max|weight| (u the unit roundoff), while for weights that cancel across many orders of magnitude it can be large, and then it says so. Meaningful only when has_cycle.

Definition at line 312 of file Negative_Cycles.H.

◆ total_cost

template<AlephGraph GT, typename Cost_Type >
Cost_Type Aleph::Bounded_Cycle_Result< GT, Cost_Type >::total_cost = Cost_Type{0}

Sum of the arc weights of the reported cycle (for floating-point costs the exact sum, rounded once, which can differ from the plain rounded sums the dynamic program compared).

Definition at line 317 of file Negative_Cycles.H.

Referenced by Aleph::Bounded_Cycle_Result< GT, Cost_Type >::is_negative().


The documentation for this struct was generated from the following file: