Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type > Class Template Reference

Rank cycles of at most three arcs exactly, reusing scratch sums. More...

#include <Negative_Cycles.H>

Collaboration diagram for Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >:
[legend]

Public Member Functions

template<AlephGraph GT>
 Short_Cycle_Best (const Indexed_Graph< GT, Cost_Type > &ig, const size_t bound)
 Prepare a rigorous rounding filter for this graph and bound.
 
template<AlephGraph GT>
void offer (const Indexed_Graph< GT, Cost_Type > &ig, const size_t *path, const size_t len)
 Offer a cycle; exact cost and then length decide the winner.
 
Cost_Type total ()
 Published total of the winning cycle.
 

Public Attributes

size_t length = 0
 Zero until the first cycle is offered.
 
size_t arcs [3] = {}
 Original snapshot indices in cycle order.
 
bool above_range = false
 Whether a cycle was skipped because its total is above the largest value of the cost type.
 

Static Private Member Functions

template<AlephGraph GT>
static int plain_sum (const Indexed_Graph< GT, Cost_Type > &ig, const size_t *idx, const size_t len, Cost_Type &sum)
 

Private Attributes

Cost_Type plain_ = Cost_Type{0}
 
Cost_Type error_ = Cost_Type{0}
 
Cost_Type reject_above_ = Cost_Type{0}
 
bool exact_sums_ = true
 
Exact_Sum< Cost_Type > best_
 
Exact_Sum< Cost_Type > candidate_
 
Exact_Sum< Cost_Type > difference_
 

Detailed Description

template<typename Cost_Type>
class Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >

Rank cycles of at most three arcs exactly, reusing scratch sums.

A rounded sum can reject a candidate only when it is above an outward bound of best_plain + 2 * error: both plain sums are within error of their exact values. Ambiguous comparisons use exact expansions.

Template Parameters
Cost_TypeArc weight type.

Definition at line 2054 of file Negative_Cycles.H.

Constructor & Destructor Documentation

◆ Short_Cycle_Best()

template<typename Cost_Type >
template<AlephGraph GT>
Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::Short_Cycle_Best ( const Indexed_Graph< GT, Cost_Type > &  ig,
const size_t  bound 
)
inline

Prepare a rigorous rounding filter for this graph and bound.

Parameters
[in]igIndexed graph searched.
[in]boundLargest cycle length, in [1, 3].

Definition at line 2102 of file Negative_Cycles.H.

References Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::error_, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::exact_sums_, and Aleph::negative_cycles_detail::short_sums_are_exact().

Member Function Documentation

◆ offer()

template<typename Cost_Type >
template<AlephGraph GT>
void Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer ( const Indexed_Graph< GT, Cost_Type > &  ig,
const size_t *  path,
const size_t  len 
)
inline

Offer a cycle; exact cost and then length decide the winner.

The weights are added in cycle order. If a partial sum leaves the cost type, two weights of opposite signs are added first, which cannot leave it; if the total still does, it is out of range. A total above the type is worse than any that fits and is skipped (above_range); one below it would be the best cycle, which has no representable cost, and throws.

Parameters
[in]igIndexed graph searched.
[in]pathSnapshot arc indices of the candidate.
[in]lenCandidate length, in [1, 3].
Exceptions
std::overflow_errorAn integral total below the cost type.
std::domain_errorA floating-point total below the format, or an exact sum that is not finite.

Definition at line 2125 of file Negative_Cycles.H.

References Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::above_range, Aleph::negative_cycles_detail::Exact_Sum< T >::add(), ah_domain_error_if, ah_overflow_error_if, Aleph::and, Aleph::negative_cycles_detail::Indexed_Graph< GT, Cost_Type >::arcs, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::arcs, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::best_, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::candidate_, Aleph::negative_cycles_detail::Exact_Sum< T >::clear(), Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::difference_, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::error_, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::exact_sums_, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::length, out, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::plain_, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::plain_sum(), Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::reject_above_, Aleph::negative_cycles_detail::Exact_Sum< T >::sign(), and Aleph::sum().

Referenced by Aleph::most_negative_cycle_up_to_3().

◆ plain_sum()

template<typename Cost_Type >
template<AlephGraph GT>
static int Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::plain_sum ( const Indexed_Graph< GT, Cost_Type > &  ig,
const size_t *  idx,
const size_t  len,
Cost_Type &  sum 
)
inlinestaticprivate

◆ total()

template<typename Cost_Type >
Cost_Type Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::total ( )
inline

Published total of the winning cycle.

Returns
Exact integral total, or floating total within one ulp and with the exact sign. Zero when no cycle was offered.
Exceptions
std::domain_errorIf the floating total does not fit the cost type.

Definition at line 2212 of file Negative_Cycles.H.

References ah_domain_error_if, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::best_, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::exact_sums_, Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::plain_, and Aleph::negative_cycles_detail::Exact_Sum< T >::rounded().

Referenced by Aleph::most_negative_cycle_up_to_3().

Member Data Documentation

◆ above_range

template<typename Cost_Type >
bool Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::above_range = false

Whether a cycle was skipped because its total is above the largest value of the cost type.

If no cycle was kept, the best one does not fit.

Definition at line 2095 of file Negative_Cycles.H.

Referenced by Aleph::most_negative_cycle_up_to_3(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().

◆ arcs

template<typename Cost_Type >
size_t Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::arcs[3] = {}

Original snapshot indices in cycle order.

Definition at line 2092 of file Negative_Cycles.H.

Referenced by Aleph::most_negative_cycle_up_to_3(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().

◆ best_

◆ candidate_

template<typename Cost_Type >
Exact_Sum<Cost_Type> Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::candidate_
private

◆ difference_

template<typename Cost_Type >
Exact_Sum<Cost_Type> Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::difference_
private

◆ error_

◆ exact_sums_

◆ length

template<typename Cost_Type >
size_t Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::length = 0

Zero until the first cycle is offered.

Definition at line 2091 of file Negative_Cycles.H.

Referenced by Aleph::most_negative_cycle_up_to_3(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().

◆ plain_

template<typename Cost_Type >
Cost_Type Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::plain_ = Cost_Type{0}
private

◆ reject_above_

template<typename Cost_Type >
Cost_Type Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::reject_above_ = Cost_Type{0}
private

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