|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Rank cycles of at most three arcs exactly, reusing scratch sums. More...
#include <Negative_Cycles.H>
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_ |
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.
| Cost_Type | Arc weight type. |
Definition at line 2054 of file Negative_Cycles.H.
|
inline |
Prepare a rigorous rounding filter for this graph and bound.
| [in] | ig | Indexed graph searched. |
| [in] | bound | Largest 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().
|
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.
| [in] | ig | Indexed graph searched. |
| [in] | path | Snapshot arc indices of the candidate. |
| [in] | len | Candidate length, in [1, 3]. |
| std::overflow_error | An integral total below the cost type. |
| std::domain_error | A 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().
|
inlinestaticprivate |
Definition at line 2065 of file Negative_Cycles.H.
References Aleph::and, Aleph::negative_cycles_detail::Indexed_Graph< GT, Cost_Type >::arcs, Aleph::sum(), and w.
Referenced by Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().
|
inline |
Published total of the winning cycle.
| std::domain_error | If 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().
| 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().
| 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().
|
private |
Definition at line 2060 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::total().
|
private |
Definition at line 2060 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().
|
private |
Definition at line 2060 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().
|
private |
Definition at line 2057 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::Short_Cycle_Best(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().
|
private |
| 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().
|
private |
Definition at line 2056 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::total().
|
private |
Definition at line 2058 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().