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

Index of the simple cycles of bounded length of a digraph. More...

#include <Bounded_Cycle_Index.H>

Collaboration diagram for Aleph::Bounded_Cycle_Index< GT >:
[legend]

Classes

struct  Marks
 
struct  Number_Table
 
struct  Path
 
struct  Shape
 

Public Types

using Arc = typename GT::Arc
 The type of the arcs, const on a view.
 

Public Member Functions

template<class Arc_Less >
requires StrictWeakOrder<Arc_Less, Arc *>
 Bounded_Cycle_Index (const GT &g, std::initializer_list< size_t > lengths, Arc_Less less, const size_t max_cycles=Default_Max_Cycles)
 Build the index of the cycles of g with the lengths given, with the arcs in the order of a comparison.
 
 Bounded_Cycle_Index (const GT &g, std::initializer_list< size_t > lengths, const size_t max_cycles=Default_Max_Cycles)
 Build the index of the cycles of g with the lengths given, with the arcs in the order of the arc iterator of g.
 
template<class Arc_Less >
requires StrictWeakOrder<Arc_Less, Arc *>
 Bounded_Cycle_Index (const GT &g, const Array< size_t > &lengths, Arc_Less less, const size_t max_cycles=Default_Max_Cycles)
 Build the index of the cycles of g with the lengths of an array, with the arcs in the order of a comparison.
 
 Bounded_Cycle_Index (const GT &g, const Array< size_t > &lengths, const size_t max_cycles=Default_Max_Cycles)
 Build the index of the cycles of g with the lengths of an array, with the arcs in the order of the arc iterator of g.
 
 Bounded_Cycle_Index (const Bounded_Cycle_Index &other)
 Copy an index: its catalog, its weights, its stamps and its clock.
 
 Bounded_Cycle_Index (Bounded_Cycle_Index &&other) noexcept
 Take the index of another, in constant time and without failing.
 
Bounded_Cycle_Index & operator= (const Bounded_Cycle_Index &other)
 Make the index a copy of another.
 
Bounded_Cycle_Index & operator= (Bounded_Cycle_Index &&other) noexcept
 Take the index of another, in constant time besides freeing what the index had, and without failing.
 
size_t num_arcs () const noexcept
 The number of arcs of the graph when the index was built.
 
size_t arc_number (const Arc *a) const
 The number of an arc of the graph, in O(1) expected.
 
Arc * arc (const size_t number) const
 The arc with a number.
 
size_t num_cycles () const noexcept
 The number of cycles of the catalog.
 
size_t num_cycles (const size_t length) const noexcept
 The number of cycles of a length.
 
size_t num_cycles_up_to (const size_t max_length) const noexcept
 The number of cycles whose length is at most max_length: the size of the prefix of the catalog that they are.
 
bool has_length (const size_t length) const noexcept
 Return true if length is one of the lengths of the index.
 
size_t longest_length () const noexcept
 The longest length of the set of the index.
 
size_t length (const size_t position) const
 The length of a cycle.
 
std::span< const uint32_t > cycle_arcs (const size_t position) const
 The arcs of a cycle, by their numbers, in its canonical rotation: from the arc of least number, in the order of the cycle.
 
std::span< const uint32_t > cycles_of (const size_t arc) const
 The cycles that go through an arc, by their positions, in ascending order.
 
void set_weight (const size_t arc, const double w)
 Change the weight of an arc, without looking at its cycles.
 
double weight (const size_t arc) const
 The weight of an arc.
 
double weight_sum (const size_t position) const
 The weight of a cycle: the sum of the weights of its arcs, in the order of its canonical rotation.
 
template<class Op >
requires std::invocable<Op &, size_t, double>
size_t update (const size_t arc, const double w, const double bound, const size_t max_length, Op &&op)
 Change the weight of an arc and hand the cycles through it whose weight is below a bound.
 
template<class Op >
requires std::invocable<Op &, size_t, double>
size_t for_each_cycle_below (const Array< size_t > &arcs, const double bound, const size_t max_length, Op &&op)
 Hand the cycles through any of some arcs whose weight is below a bound, each cycle once.
 
template<class Op >
requires std::invocable<Op &, size_t, double>
size_t for_each_cycle_below (std::initializer_list< size_t > arcs, const double bound, const size_t max_length, Op &&op)
 Hand the cycles through any of the arcs of a list whose weight is below a bound, each cycle once.
 
template<class Op >
requires std::invocable<Op &, size_t, double>
size_t for_each_cycle_below (const double bound, const size_t max_length, Op &&op) const
 Hand the cycles of the catalog whose weight is below a bound.
 
uint64_t clock () const noexcept
 The number of writes of a weight so far: each set_weight(), update() and touch() adds one.
 
uint64_t stamp (const size_t arc) const
 The value of clock() when an arc was last written.
 
void touch (const size_t arc)
 Mark an arc as written without changing its weight, for what the caller keeps of its cycles and depends on more than the weight.
 
bool is_stale (const size_t position, const uint64_t computed_at) const
 Return true if an arc of a cycle was written after a moment: what was computed of the cycle then is old.
 
void swap (Bounded_Cycle_Index &other) noexcept
 Exchange two indexes in constant time, without failing: how to replace an index by another built apart, with another set of lengths.
 

Static Public Member Functions

static constexpr double sum_error_bound (const size_t k, const double max_abs_weight) noexcept
 A bound of the rounding error of the sum of the weights of a cycle.
 

Static Public Attributes

static constexpr size_t Max_Length = 8
 The longest length of a cycle that an index can hold.
 
static constexpr size_t Default_Max_Cycles = size_t(1) << 24
 The number of cycles that an index holds, when no other is given.
 

Private Member Functions

template<class Arc_Less >
void build (const GT &g, const uint32_t lengths, Arc_Less &less, const size_t max_cycles)
 
size_t length_of (const size_t position) const noexcept
 
size_t first_arc_of (const size_t position, const size_t k) const noexcept
 
size_t checked_arc (const size_t arc) const
 
size_t checked_position (const size_t position) const
 
size_t longest_up_to (const size_t max_length) const noexcept
 
double sum_at (const size_t first, const size_t k) const noexcept
 
template<class Number , class Op >
size_t look_at (const Array< Number > &block, const size_t arc, const double bound, const size_t max_length, const bool skip, Op &op) const
 
template<class Op >
size_t look_at (const size_t arc, const double bound, const size_t max_length, const bool skip, Op &op) const
 
template<class Op >
size_t look_at_each (const size_t *arcs, const size_t n, const double bound, const size_t max_length, Op &op)
 

Static Private Member Functions

template<class On_Cycle >
static void extend (const Shape &shape, Path &path, const uint32_t node, On_Cycle &on_cycle)
 
template<class On_Cycle >
static void enumerate (const Shape &shape, On_Cycle &&on_cycle)
 
template<class It >
static uint32_t length_bits (It first, const It last)
 
static void check_weight (const double w)
 
static void check_bound (const double bound)
 

Private Attributes

Number_Table arc_numbers_
 
Array< Arc * > arcs_
 
uint32_t lengths_ = 0
 
size_t longest_ = 0
 
size_t length_first_ [Stride] = {}
 
size_t arcs_before_ [Stride] = {}
 
Array< uint32_t > cycle_arcs_
 
Array< uint32_t > member_first_
 
Array< uint32_t > members_
 
Array< uint32_t > group_member_
 
Array< size_t > group_first_
 
Array< uint16_t > narrow_
 
Array< uint32_t > wide_
 
Array< double > weight_
 
Array< uint64_t > stamp_
 
uint64_t clock_ = 0
 
Array< unsigned char > done_
 

Static Private Attributes

static constexpr uint32_t Not_Found = std::numeric_limits<uint32_t>::max()
 
static constexpr size_t Stride = Max_Length + 2
 

Detailed Description

template<AlephGraph GT>
class Aleph::Bounded_Cycle_Index< GT >

Index of the simple cycles of bounded length of a digraph.

See the description of the file for the catalog, the weights, the filter and its margin.

The index is built in \(O(V + E \log E + C k^2)\) time, with the sort of the arcs at its expected cost, besides the search, which walks each simple path of fewer arcs than the longest length whose first arc is its least one; C is the number of cycles and k their length. It takes \(O(E + C k^2)\) memory: for each arc, the arcs of each of its cycles are kept contiguous, so that a change of the arc reads them in a row. update() takes \(O(c\,k)\) for an arc that is in c cycles.

An index can be copied, assigned, moved and exchanged with swap(). A copy is another index of the same graph, with the weights, the stamps and the clock of the first. An index that is moved from is left without arcs and without cycles.

Template Parameters
GTthe type of the digraph: a graph class of Aleph or a Const_Graph_View of one.

Definition at line 183 of file Bounded_Cycle_Index.H.

Member Typedef Documentation

◆ Arc

template<AlephGraph GT>
using Aleph::Bounded_Cycle_Index< GT >::Arc = typename GT::Arc

The type of the arcs, const on a view.

Definition at line 186 of file Bounded_Cycle_Index.H.

Constructor & Destructor Documentation

◆ Bounded_Cycle_Index() [1/6]

template<AlephGraph GT>
template<class Arc_Less >
requires StrictWeakOrder<Arc_Less, Arc *>
Aleph::Bounded_Cycle_Index< GT >::Bounded_Cycle_Index ( const GT &  g,
std::initializer_list< size_t >  lengths,
Arc_Less  less,
const size_t  max_cycles = Default_Max_Cycles 
)
inline

Build the index of the cycles of g with the lengths given, with the arcs in the order of a comparison.

Parameters
[in]gthe digraph, or a view of it. It must outlive the index, with the nodes and the arcs that it has now.
[in]lengthsthe lengths of the cycles, each from 1 to Max_Length.
[in]lessthe order of the arcs: less(a, b) is true if the arc a takes a number before b. It must be a strict weak order; the arcs that it does not tell apart keep the order of the arc iterator of g. What it throws goes to the caller, and no index is built.
[in]max_cyclesthe most cycles that the index may hold.
Exceptions
std::domain_errorif g is not directed, if a length is not from 1 to Max_Length or if there is no length.
std::length_errorif g has more than max_cycles cycles of those lengths, or more nodes, arcs or arcs of cycles than fit in 32 bits.
std::bad_allocif there is no memory.

Definition at line 730 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::build(), and Aleph::Bounded_Cycle_Index< GT >::length_bits().

◆ Bounded_Cycle_Index() [2/6]

template<AlephGraph GT>
Aleph::Bounded_Cycle_Index< GT >::Bounded_Cycle_Index ( const GT &  g,
std::initializer_list< size_t >  lengths,
const size_t  max_cycles = Default_Max_Cycles 
)
inline

Build the index of the cycles of g with the lengths given, with the arcs in the order of the arc iterator of g.

Parameters
[in]gthe digraph, or a view of it. It must outlive the index, with the nodes and the arcs that it has now.
[in]lengthsthe lengths of the cycles, each from 1 to Max_Length.
[in]max_cyclesthe most cycles that the index may hold.
Exceptions
std::domain_errorif g is not directed, if a length is not from 1 to Max_Length or if there is no length.
std::length_errorif g has more than max_cycles cycles of those lengths, or more nodes, arcs or arcs of cycles than fit in 32 bits.
std::bad_allocif there is no memory.

Definition at line 751 of file Bounded_Cycle_Index.H.

◆ Bounded_Cycle_Index() [3/6]

template<AlephGraph GT>
template<class Arc_Less >
requires StrictWeakOrder<Arc_Less, Arc *>
Aleph::Bounded_Cycle_Index< GT >::Bounded_Cycle_Index ( const GT &  g,
const Array< size_t > &  lengths,
Arc_Less  less,
const size_t  max_cycles = Default_Max_Cycles 
)
inline

Build the index of the cycles of g with the lengths of an array, with the arcs in the order of a comparison.

Parameters
[in]gthe digraph, or a view of it. It must outlive the index, with the nodes and the arcs that it has now.
[in]lengthsthe lengths of the cycles, each from 1 to Max_Length.
[in]lessthe order of the arcs, a strict weak order; the arcs that it does not tell apart keep the order of the arc iterator of g. What it throws goes to the caller, and no index is built.
[in]max_cyclesthe most cycles that the index may hold.
Exceptions
std::domain_errorif g is not directed, if a length is not from 1 to Max_Length or if there is no length.
std::length_errorif g has more than max_cycles cycles of those lengths, or more nodes, arcs or arcs of cycles than fit in 32 bits.
std::bad_allocif there is no memory.

Definition at line 776 of file Bounded_Cycle_Index.H.

References ah_domain_error_if, Aleph::bits(), Aleph::Bounded_Cycle_Index< GT >::build(), Aleph::Bounded_Cycle_Index< GT >::length_bits(), and Aleph::Array< T >::size().

◆ Bounded_Cycle_Index() [4/6]

template<AlephGraph GT>
Aleph::Bounded_Cycle_Index< GT >::Bounded_Cycle_Index ( const GT &  g,
const Array< size_t > &  lengths,
const size_t  max_cycles = Default_Max_Cycles 
)
inline

Build the index of the cycles of g with the lengths of an array, with the arcs in the order of the arc iterator of g.

Parameters
[in]gthe digraph, or a view of it. It must outlive the index, with the nodes and the arcs that it has now.
[in]lengthsthe lengths of the cycles, each from 1 to Max_Length.
[in]max_cyclesthe most cycles that the index may hold.
Exceptions
std::domain_errorif g is not directed, if a length is not from 1 to Max_Length or if there is no length.
std::length_errorif g has more than max_cycles cycles of those lengths, or more nodes, arcs or arcs of cycles than fit in 32 bits.
std::bad_allocif there is no memory.

Definition at line 802 of file Bounded_Cycle_Index.H.

◆ Bounded_Cycle_Index() [5/6]

template<AlephGraph GT>
Aleph::Bounded_Cycle_Index< GT >::Bounded_Cycle_Index ( const Bounded_Cycle_Index< GT > &  other)
inline

Copy an index: its catalog, its weights, its stamps and its clock.

The copy is another index of the same graph, which must outlive it too. It is in no query: a copy made by the function that receives the cycles of for_each_cycle_below() hands every cycle that it is asked for afterwards.

Parameters
[in]otherthe index to copy.
Exceptions
std::bad_allocif there is no memory.
Note
\(O(E + C k^2)\) time and memory.

Definition at line 818 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arcs_before_, k, Aleph::Bounded_Cycle_Index< GT >::length_first_, and Aleph::Bounded_Cycle_Index< GT >::Stride.

◆ Bounded_Cycle_Index() [6/6]

template<AlephGraph GT>
Aleph::Bounded_Cycle_Index< GT >::Bounded_Cycle_Index ( Bounded_Cycle_Index< GT > &&  other)
inlinenoexcept

Take the index of another, in constant time and without failing.

Parameters
[in,out]otherthe index to take. It is left without arcs and without cycles: it can be asked, assigned and destroyed.

Definition at line 841 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arcs_before_, k, Aleph::Bounded_Cycle_Index< GT >::length_first_, and Aleph::Bounded_Cycle_Index< GT >::Stride.

Member Function Documentation

◆ arc()

◆ arc_number()

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::arc_number ( const Arc *  a) const
inline

The number of an arc of the graph, in O(1) expected.

Parameters
[in]aan arc of the graph of the index.
Returns
its number, from 0 to num_arcs() - 1.
Exceptions
std::domain_errorif a was not an arc of the graph.

Definition at line 901 of file Bounded_Cycle_Index.H.

References ah_domain_error_if, Aleph::Bounded_Cycle_Index< GT >::arc_numbers_, Aleph::Bounded_Cycle_Index< GT >::Number_Table::find(), and Aleph::Bounded_Cycle_Index< GT >::Not_Found.

Referenced by TEST().

◆ build()

template<AlephGraph GT>
template<class Arc_Less >
void Aleph::Bounded_Cycle_Index< GT >::build ( const GT &  g,
const uint32_t  lengths,
Arc_Less &  less,
const size_t  max_cycles 
)
inlineprivate

Definition at line 392 of file Bounded_Cycle_Index.H.

References ah_domain_error_if, ah_length_error_if, Aleph::and, Aleph::Array< T >::append(), Aleph::Bounded_Cycle_Index< GT >::arc(), Aleph::Bounded_Cycle_Index< GT >::arc_numbers_, arcs, Aleph::Bounded_Cycle_Index< GT >::arcs_, Aleph::Bounded_Cycle_Index< GT >::arcs_before_, Aleph::count(), Aleph::Array< T >::create_reserved(), Aleph::Bounded_Cycle_Index< GT >::cycle_arcs_, Aleph::Bounded_Cycle_Index< GT >::done_, Aleph::Bounded_Cycle_Index< GT >::enumerate(), Aleph::Bounded_Cycle_Index< GT >::first_arc_of(), GraphCommon< GT, Node, Arc >::get_num_arcs(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::Bounded_Cycle_Index< GT >::group_first_, Aleph::Bounded_Cycle_Index< GT >::group_member_, GraphCommon< GT, Node, Arc >::is_digraph(), k, Aleph::Bounded_Cycle_Index< GT >::length_first_, Aleph::Bounded_Cycle_Index< GT >::Shape::lengths, Aleph::Bounded_Cycle_Index< GT >::lengths_, Aleph::Bounded_Cycle_Index< GT >::Shape::longest, Aleph::Bounded_Cycle_Index< GT >::longest_, Aleph::Bounded_Cycle_Index< GT >::Max_Length, Aleph::Bounded_Cycle_Index< GT >::member_first_, Aleph::Bounded_Cycle_Index< GT >::members_, Aleph::Bounded_Cycle_Index< GT >::narrow_, Aleph::next(), nodes, Aleph::Bounded_Cycle_Index< GT >::Not_Found, Aleph::Bounded_Cycle_Index< GT >::num_cycles(), Aleph::Bounded_Cycle_Index< GT >::Shape::out_arcs, Aleph::Bounded_Cycle_Index< GT >::Shape::out_first, Aleph::Bounded_Cycle_Index< GT >::Number_Table::put(), Aleph::quicksort_op(), Aleph::Bounded_Cycle_Index< GT >::Shape::source, Aleph::Bounded_Cycle_Index< GT >::stamp_, Aleph::Bounded_Cycle_Index< GT >::Stride, Aleph::Bounded_Cycle_Index< GT >::Shape::target, V, Aleph::Bounded_Cycle_Index< GT >::weight_, and Aleph::Bounded_Cycle_Index< GT >::wide_.

Referenced by Aleph::Bounded_Cycle_Index< GT >::Bounded_Cycle_Index(), and Aleph::Bounded_Cycle_Index< GT >::Bounded_Cycle_Index().

◆ check_bound()

template<AlephGraph GT>
static void Aleph::Bounded_Cycle_Index< GT >::check_bound ( const double  bound)
inlinestaticprivate

◆ check_weight()

template<AlephGraph GT>
static void Aleph::Bounded_Cycle_Index< GT >::check_weight ( const double  w)
inlinestaticprivate

Definition at line 584 of file Bounded_Cycle_Index.H.

References ah_domain_error_if, and w.

Referenced by Aleph::Bounded_Cycle_Index< GT >::set_weight().

◆ checked_arc()

◆ checked_position()

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::checked_position ( const size_t  position) const
inlineprivate

◆ clock()

template<AlephGraph GT>
uint64_t Aleph::Bounded_Cycle_Index< GT >::clock ( ) const
inlinenoexcept

The number of writes of a weight so far: each set_weight(), update() and touch() adds one.

Definition at line 1191 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::clock_.

Referenced by TEST().

◆ cycle_arcs()

template<AlephGraph GT>
std::span< const uint32_t > Aleph::Bounded_Cycle_Index< GT >::cycle_arcs ( const size_t  position) const
inline

The arcs of a cycle, by their numbers, in its canonical rotation: from the arc of least number, in the order of the cycle.

Parameters
[in]positionthe position of a cycle in the catalog.
Returns
the numbers of its arcs: a range of the memory of the index, valid until the index is destroyed, assigned or moved from. swap() takes that memory to the other index.
Exceptions
std::out_of_rangeif there is no cycle at that position.

Definition at line 973 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::checked_position(), Aleph::Bounded_Cycle_Index< GT >::cycle_arcs_, Aleph::Bounded_Cycle_Index< GT >::first_arc_of(), k, and Aleph::Bounded_Cycle_Index< GT >::length_of().

Referenced by Aleph::Bounded_Cycle_Index< GT >::is_stale(), TEST(), TEST(), TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().

◆ cycles_of()

template<AlephGraph GT>
std::span< const uint32_t > Aleph::Bounded_Cycle_Index< GT >::cycles_of ( const size_t  arc) const
inline

The cycles that go through an arc, by their positions, in ascending order.

Parameters
[in]arcthe number of an arc.
Returns
the positions, none if the arc is in no cycle of the catalog: a range of the memory of the index, valid until the index is destroyed, assigned or moved from. swap() takes that memory to the other index.
Exceptions
std::out_of_rangeif there is no arc with that number.

Definition at line 989 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arc(), Aleph::Bounded_Cycle_Index< GT >::checked_arc(), Aleph::Bounded_Cycle_Index< GT >::member_first_, and Aleph::Bounded_Cycle_Index< GT >::members_.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TYPED_TEST(), and TYPED_TEST().

◆ enumerate()

◆ extend()

◆ first_arc_of()

◆ for_each_cycle_below() [1/3]

template<AlephGraph GT>
template<class Op >
requires std::invocable<Op &, size_t, double>
size_t Aleph::Bounded_Cycle_Index< GT >::for_each_cycle_below ( const Array< size_t > &  arcs,
const double  bound,
const size_t  max_length,
Op &&  op 
)
inline

Hand the cycles through any of some arcs whose weight is below a bound, each cycle once.

It is how to look at the cycles after set_weight() has changed several arcs: no cycle is seen with only a part of the changes. op(position, sum) is called once for each cycle that goes through any of the arcs, whose length is at most max_length and whose sum is below bound: by arc, in the order given, and by ascending position among those of an arc. It must not change the index. If it throws, the cycles that were not reached are not handed, and the index is ready for another query.

Parameters
[in]arcsthe numbers of the arcs; a number may be repeated.
[in]bounda cycle is handed if its sum is less than it.
[in]max_lengththe longest length of the cycles to look at.
[in]opthe function that receives each cycle.
Returns
the number of cycles looked at.
Exceptions
std::out_of_rangeif there is no arc with one of the numbers; no cycle is handed then.
std::domain_errorif bound is not a number.
Note
\(O(n + c\,k)\) besides what op takes, for n arcs given and the c cycles of at most max_length arcs, of k arcs each, counted once for each different arc given that they go through: a cycle through several of those arcs is read for each of them and handed once. An arc that is given again costs \(O(1)\).

Definition at line 1099 of file Bounded_Cycle_Index.H.

References arcs, and Aleph::Bounded_Cycle_Index< GT >::look_at_each().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), and TYPED_TEST().

◆ for_each_cycle_below() [2/3]

template<AlephGraph GT>
template<class Op >
requires std::invocable<Op &, size_t, double>
size_t Aleph::Bounded_Cycle_Index< GT >::for_each_cycle_below ( const double  bound,
const size_t  max_length,
Op &&  op 
) const
inline

Hand the cycles of the catalog whose weight is below a bound.

op(position, sum) is called for each cycle whose length is at most max_length and whose sum is below bound, in ascending order of position. If it throws, the cycles that were not reached are not handed.

Parameters
[in]bounda cycle is handed if its sum is less than it.
[in]max_lengththe longest length of the cycles to look at.
[in]opthe function that receives each cycle.
Returns
the number of cycles looked at.
Exceptions
std::domain_errorif bound is not a number.
Note
\(O(C\,k)\) besides what op takes, for the C cycles of the catalog of at most max_length arcs, of k arcs each.

Definition at line 1151 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::check_bound(), Aleph::Bounded_Cycle_Index< GT >::first_arc_of(), k, Aleph::Bounded_Cycle_Index< GT >::length_first_, Aleph::Bounded_Cycle_Index< GT >::longest_up_to(), Aleph::sum(), and Aleph::Bounded_Cycle_Index< GT >::sum_at().

◆ for_each_cycle_below() [3/3]

template<AlephGraph GT>
template<class Op >
requires std::invocable<Op &, size_t, double>
size_t Aleph::Bounded_Cycle_Index< GT >::for_each_cycle_below ( std::initializer_list< size_t >  arcs,
const double  bound,
const size_t  max_length,
Op &&  op 
)
inline

Hand the cycles through any of the arcs of a list whose weight is below a bound, each cycle once.

It is for_each_cycle_below() for an array of arcs, with the arcs written in the call: for_each_cycle_below({a, b}, bound, m, op).

Parameters
[in]arcsthe numbers of the arcs; a number may be repeated.
[in]bounda cycle is handed if its sum is less than it.
[in]max_lengththe longest length of the cycles to look at.
[in]opthe function that receives each cycle.
Returns
the number of cycles looked at.
Exceptions
std::out_of_rangeif there is no arc with one of the numbers; no cycle is handed then.
std::domain_errorif bound is not a number.
Note
\(O(n + c\,k)\) besides what op takes, as with an array of arcs: n arcs given, and c cycles of k arcs counted once for each different arc given that they go through.

Definition at line 1126 of file Bounded_Cycle_Index.H.

References arcs, and Aleph::Bounded_Cycle_Index< GT >::look_at_each().

◆ has_length()

template<AlephGraph GT>
bool Aleph::Bounded_Cycle_Index< GT >::has_length ( const size_t  length) const
inlinenoexcept

Return true if length is one of the lengths of the index.

Definition at line 944 of file Bounded_Cycle_Index.H.

References Aleph::and, Aleph::Bounded_Cycle_Index< GT >::length(), Aleph::Bounded_Cycle_Index< GT >::lengths_, and Aleph::Bounded_Cycle_Index< GT >::Max_Length.

Referenced by TEST().

◆ is_stale()

template<AlephGraph GT>
bool Aleph::Bounded_Cycle_Index< GT >::is_stale ( const size_t  position,
const uint64_t  computed_at 
) const
inline

Return true if an arc of a cycle was written after a moment: what was computed of the cycle then is old.

Parameters
[in]positionthe position of a cycle in the catalog.
[in]computed_atthe value of clock() at that moment.
Returns
true if stamp() of one of its arcs is greater.
Exceptions
std::out_of_rangeif there is no cycle at that position.

Definition at line 1222 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arc(), Aleph::Bounded_Cycle_Index< GT >::cycle_arcs(), and Aleph::Bounded_Cycle_Index< GT >::stamp_.

◆ length()

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::length ( const size_t  position) const
inline

The length of a cycle.

Parameters
[in]positionthe position of a cycle in the catalog.
Returns
the number of its arcs.
Exceptions
std::out_of_rangeif there is no cycle at that position.

Definition at line 958 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::checked_position(), and Aleph::Bounded_Cycle_Index< GT >::length_of().

Referenced by Aleph::Bounded_Cycle_Index< GT >::has_length(), Aleph::Bounded_Cycle_Index< GT >::num_cycles(), TYPED_TEST(), and TYPED_TEST().

◆ length_bits()

template<AlephGraph GT>
template<class It >
static uint32_t Aleph::Bounded_Cycle_Index< GT >::length_bits ( It  first,
const It  last 
)
inlinestaticprivate

◆ length_of()

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::length_of ( const size_t  position) const
inlineprivatenoexcept

◆ longest_length()

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::longest_length ( ) const
inlinenoexcept

The longest length of the set of the index.

Definition at line 950 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::longest_.

Referenced by TEST().

◆ longest_up_to()

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::longest_up_to ( const size_t  max_length) const
inlineprivatenoexcept

◆ look_at() [1/2]

◆ look_at() [2/2]

template<AlephGraph GT>
template<class Op >
size_t Aleph::Bounded_Cycle_Index< GT >::look_at ( const size_t  arc,
const double  bound,
const size_t  max_length,
const bool  skip,
Op &  op 
) const
inlineprivate

◆ look_at_each()

template<AlephGraph GT>
template<class Op >
size_t Aleph::Bounded_Cycle_Index< GT >::look_at_each ( const size_t *  arcs,
const size_t  n,
const double  bound,
const size_t  max_length,
Op &  op 
)
inlineprivate

◆ num_arcs()

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::num_arcs ( ) const
inlinenoexcept

The number of arcs of the graph when the index was built.

Definition at line 893 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arcs_, and Aleph::Array< T >::size().

Referenced by Aleph::Bounded_Cycle_Index< GT >::enumerate(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().

◆ num_cycles() [1/2]

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::num_cycles ( ) const
inlinenoexcept

◆ num_cycles() [2/2]

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::num_cycles ( const size_t  length) const
inlinenoexcept

The number of cycles of a length.

Parameters
[in]lengtha length.
Returns
how many cycles of the catalog have that length; 0 if the length is not of the set.

Definition at line 926 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::length(), Aleph::Bounded_Cycle_Index< GT >::length_first_, and Aleph::Bounded_Cycle_Index< GT >::Max_Length.

◆ num_cycles_up_to()

template<AlephGraph GT>
size_t Aleph::Bounded_Cycle_Index< GT >::num_cycles_up_to ( const size_t  max_length) const
inlinenoexcept

The number of cycles whose length is at most max_length: the size of the prefix of the catalog that they are.

Parameters
[in]max_lengtha length.
Returns
how many cycles of the catalog are not longer.

Definition at line 938 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::length_first_, and Aleph::Bounded_Cycle_Index< GT >::Max_Length.

Referenced by TEST(), TEST(), and TEST().

◆ operator=() [1/2]

template<AlephGraph GT>
Bounded_Cycle_Index & Aleph::Bounded_Cycle_Index< GT >::operator= ( Bounded_Cycle_Index< GT > &&  other)
inlinenoexcept

Take the index of another, in constant time besides freeing what the index had, and without failing.

Parameters
[in,out]otherthe index to take. It is left without arcs and without cycles.
Returns
the index.

Definition at line 886 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::swap().

◆ operator=() [2/2]

template<AlephGraph GT>
Bounded_Cycle_Index & Aleph::Bounded_Cycle_Index< GT >::operator= ( const Bounded_Cycle_Index< GT > &  other)
inline

Make the index a copy of another.

The copy is made apart and then exchanged with the index: if there is no memory for it, the index keeps all that it had. For a moment both are in memory.

Parameters
[in]otherthe index to copy.
Returns
the index.
Exceptions
std::bad_allocif there is no memory; the index does not change.
Note
\(O(E + C k^2)\) time and memory.

Definition at line 872 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::swap().

◆ set_weight()

template<AlephGraph GT>
void Aleph::Bounded_Cycle_Index< GT >::set_weight ( const size_t  arc,
const double  w 
)
inline

Change the weight of an arc, without looking at its cycles.

Parameters
[in]arcthe number of an arc.
[in]wits weight; \(+\infty\) for an arc that cannot be used.
Exceptions
std::out_of_rangeif there is no arc with that number.
std::domain_errorif w is not a number or is \(-\infty\).

Definition at line 1005 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arc(), Aleph::Bounded_Cycle_Index< GT >::check_weight(), Aleph::Bounded_Cycle_Index< GT >::checked_arc(), Aleph::Bounded_Cycle_Index< GT >::clock_, Aleph::Bounded_Cycle_Index< GT >::stamp_, w, and Aleph::Bounded_Cycle_Index< GT >::weight_.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TYPED_TEST(), TYPED_TEST(), and Aleph::Bounded_Cycle_Index< GT >::update().

◆ stamp()

template<AlephGraph GT>
uint64_t Aleph::Bounded_Cycle_Index< GT >::stamp ( const size_t  arc) const
inline

The value of clock() when an arc was last written.

Parameters
[in]arcthe number of an arc.
Returns
that value; 0 if the arc was never written.
Exceptions
std::out_of_rangeif there is no arc with that number.

Definition at line 1199 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arc(), Aleph::Bounded_Cycle_Index< GT >::checked_arc(), and Aleph::Bounded_Cycle_Index< GT >::stamp_.

Referenced by TEST().

◆ sum_at()

template<AlephGraph GT>
double Aleph::Bounded_Cycle_Index< GT >::sum_at ( const size_t  first,
const size_t  k 
) const
inlineprivatenoexcept

◆ sum_error_bound()

template<AlephGraph GT>
static constexpr double Aleph::Bounded_Cycle_Index< GT >::sum_error_bound ( const size_t  k,
const double  max_abs_weight 
)
inlinestaticconstexprnoexcept

A bound of the rounding error of the sum of the weights of a cycle.

The sum of k weights of magnitude at most max_abs_weight, as the index adds them, is within this of their exact sum, provided that k * max_abs_weight is finite. It says nothing of the error of each weight, which is of who computes it.

Parameters
[in]kthe number of arcs of the cycle.
[in]max_abs_weighta bound of the magnitude of each weight.
Returns
the bound: 0 for a cycle of one arc.

Definition at line 1174 of file Bounded_Cycle_Index.H.

References k.

Referenced by TEST().

◆ swap()

◆ touch()

template<AlephGraph GT>
void Aleph::Bounded_Cycle_Index< GT >::touch ( const size_t  arc)
inline

Mark an arc as written without changing its weight, for what the caller keeps of its cycles and depends on more than the weight.

Parameters
[in]arcthe number of an arc.
Exceptions
std::out_of_rangeif there is no arc with that number.

Definition at line 1208 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arc(), Aleph::Bounded_Cycle_Index< GT >::checked_arc(), Aleph::Bounded_Cycle_Index< GT >::clock_, and Aleph::Bounded_Cycle_Index< GT >::stamp_.

◆ update()

template<AlephGraph GT>
template<class Op >
requires std::invocable<Op &, size_t, double>
size_t Aleph::Bounded_Cycle_Index< GT >::update ( const size_t  arc,
const double  w,
const double  bound,
const size_t  max_length,
Op &&  op 
)
inline

Change the weight of an arc and hand the cycles through it whose weight is below a bound.

op(position, sum) is called for each cycle of the arc whose length is at most max_length and whose sum is below bound, in ascending order of position. It must not change the index. If it throws, the weight is changed and the cycles that were not reached are not handed.

Parameters
[in]arcthe number of an arc.
[in]wits weight; \(+\infty\) for an arc that cannot be used.
[in]bounda cycle is handed if its sum is less than it; see the description of the file for its margin.
[in]max_lengththe longest length of the cycles to look at.
[in]opthe function that receives each cycle.
Returns
the number of cycles looked at.
Exceptions
std::out_of_rangeif there is no arc with that number.
std::domain_errorif w is not a number or is \(-\infty\), or if bound is not a number.
Note
\(O(c\,k)\) besides what op takes, for the c cycles of the arc of at most max_length arcs, of k arcs each: the weight of each of their arcs is read.

Definition at line 1062 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arc(), Aleph::Bounded_Cycle_Index< GT >::check_bound(), Aleph::Bounded_Cycle_Index< GT >::longest_up_to(), Aleph::Bounded_Cycle_Index< GT >::look_at(), Aleph::Bounded_Cycle_Index< GT >::set_weight(), and w.

Referenced by TEST(), TEST(), TEST(), TEST(), and TYPED_TEST().

◆ weight()

template<AlephGraph GT>
double Aleph::Bounded_Cycle_Index< GT >::weight ( const size_t  arc) const
inline

The weight of an arc.

Parameters
[in]arcthe number of an arc.
Returns
its weight; \(+\infty\) if it was given none.
Exceptions
std::out_of_rangeif there is no arc with that number.

Definition at line 1018 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::arc(), Aleph::Bounded_Cycle_Index< GT >::checked_arc(), and Aleph::Bounded_Cycle_Index< GT >::weight_.

Referenced by TEST(), TEST(), TEST(), and TYPED_TEST().

◆ weight_sum()

template<AlephGraph GT>
double Aleph::Bounded_Cycle_Index< GT >::weight_sum ( const size_t  position) const
inline

The weight of a cycle: the sum of the weights of its arcs, in the order of its canonical rotation.

It is the number that update() and for_each_cycle_below() hand for the cycle, with the same weights.

Parameters
[in]positionthe position of a cycle in the catalog.
Returns
the sum.
Exceptions
std::out_of_rangeif there is no cycle at that position.

Definition at line 1030 of file Bounded_Cycle_Index.H.

References Aleph::Bounded_Cycle_Index< GT >::checked_position(), Aleph::Bounded_Cycle_Index< GT >::first_arc_of(), k, Aleph::Bounded_Cycle_Index< GT >::length_of(), and Aleph::Bounded_Cycle_Index< GT >::sum_at().

Referenced by TEST(), TEST(), TEST(), and TYPED_TEST().

Member Data Documentation

◆ arc_numbers_

◆ arcs_

◆ arcs_before_

◆ clock_

◆ cycle_arcs_

◆ Default_Max_Cycles

template<AlephGraph GT>
constexpr size_t Aleph::Bounded_Cycle_Index< GT >::Default_Max_Cycles = size_t(1) << 24
staticconstexpr

The number of cycles that an index holds, when no other is given.

Definition at line 192 of file Bounded_Cycle_Index.H.

◆ done_

◆ group_first_

◆ group_member_

◆ length_first_

◆ lengths_

◆ longest_

◆ Max_Length

◆ member_first_

◆ members_

◆ narrow_

◆ Not_Found

template<AlephGraph GT>
constexpr uint32_t Aleph::Bounded_Cycle_Index< GT >::Not_Found = std::numeric_limits<uint32_t>::max()
staticconstexprprivate

◆ stamp_

◆ Stride

◆ weight_

◆ wide_


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