|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Index of the simple cycles of bounded length of a digraph, with a weight for each arc and a filter by the weight of a cycle. More...
#include <cmath>#include <concepts>#include <cstddef>#include <cstdint>#include <initializer_list>#include <limits>#include <span>#include <utility>#include <ah-concepts.H>#include <ah-errors.H>#include <ah-graph-concepts.H>#include <tpl_array.H>#include <tpl_graph.H>#include <tpl_sort_utils.H>Go to the source code of this file.
Classes | |
| struct | Aleph::Arc_List_Order |
The order of the arc iterator of the graph, as a comparison for Bounded_Cycle_Index: it tells no arc apart from another. More... | |
| class | Aleph::Bounded_Cycle_Index< GT > |
| Index of the simple cycles of bounded length of a digraph. More... | |
| struct | Aleph::Bounded_Cycle_Index< GT >::Number_Table |
| struct | Aleph::Bounded_Cycle_Index< GT >::Shape |
| struct | Aleph::Bounded_Cycle_Index< GT >::Path |
| struct | Aleph::Bounded_Cycle_Index< GT >::Marks |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
Index of the simple cycles of bounded length of a digraph, with a weight for each arc and a filter by the weight of a cycle.
Bounded_Cycle_Index enumerates once the simple directed cycles of a digraph whose lengths are in a set, keeps for each arc the cycles that go through it, and, when the weight of an arc changes, hands to a function the cycles of that arc whose weight is below a bound. It is made for graphs whose shape does not change while the weights of their arcs do, as a graph of markets, where a quote changes two arcs and only the cycles through them need to be looked at again.
The arcs take the numbers 0, 1, ... in the order of a comparison given by the caller; the arcs that it does not tell apart keep the order of the arc iterator of the graph. A cycle is the sequence of the numbers of its arcs, rotated so that it starts with the least of them, which is its canonical rotation: each cycle is in the catalog once, parallel arcs give different cycles, and a loop is a cycle of length 1. The cycles are ordered by length and, with the same length, lexicographically by the numbers of their arcs; the position of a cycle in that order identifies it. So the cycles whose length is at most m are a prefix of the catalog, with the positions that they have in the catalog of that smaller set of lengths.
Each arc has a weight, a double, which the index keeps apart from the graph. The weight of a cycle is the sum of the weights of its arcs, added in the order of its canonical rotation from the weights of the moment: no sum is kept from one change to the next, so that no error is carried, and the sum of a cycle is the same number whichever of its arcs changed. An arc that cannot be used has the weight \(+\infty\), which is the weight of every arc until it is given one: no cycle through it is below a bound.
update() changes the weight of an arc and hands the cycles of that arc whose sum is below a bound. To change several arcs before looking at any cycle, as the two arcs of a market, change them with set_weight() and then call for_each_cycle_below() with those arcs, which hands each cycle once, also when several of them are in it.
The filter is exact for the weights that it is given: it compares the sum, in double, with the bound. When the weights approximate exact quantities, as \(w = -\log r\) for a rate \(r\), a cycle whose exact product \(P\) exceeds a threshold \(q\) has an exact sum \(S = -\log P\) below \(t = -\log q\). If the sum that the index computes is within \(\varepsilon_S\) of \(S\) and the bound that the caller computes is within \(\varepsilon_t\) of \(t\), no such cycle is lost with the bound
\[ t_{approx} + \varepsilon_S + \varepsilon_t \]
The margin widens what is accepted: it is added to the bound, not subtracted from it. Those additions are rounded as well, and a bound that is rounded down loses the cycle whose sum equals it: the bound given must not be less than that expression. Round it up, with std::nextafter() towards \(+\infty\) after each addition, or take a margin that is wider than the two errors. The cycles that the margin lets through are candidates, to be decided with the exact rule. sum_error_bound() gives the part of \(\varepsilon_S\) that is of the index, the rounding of the sum; the error of each weight, that of the conversion of the rate and that of its logarithm, is of who computes the weights. With several thresholds, give the widest bound and classify the cycle with the sum that the function receives.
The index keeps pointers to the arcs: the graph must outlive it, at the same address, with the nodes and the arcs that it had when the index was built. It does not use the cookies, the counters or the bits of the nodes and of the arcs, so that it works on a const graph and on a Const_Graph_View. It is not thread safe.
Definition in file Bounded_Cycle_Index.H.