|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Example: the cycles of a market that a quote can make profitable, with Bounded_Cycle_Index.
More...
#include <cmath>#include <iostream>#include <limits>#include <string>#include <gmpxx.h>#include <Bounded_Cycle_Index.H>#include <tpl_array.H>#include <tpl_const_graph_view.H>#include <tpl_graph.H>Go to the source code of this file.
Functions | |
| int | main () |
Example: the cycles of a market that a quote can make profitable, with Bounded_Cycle_Index.
A market is a digraph whose nodes are assets and whose arcs are trades: the arc a -> b carries the rate at which one unit of a turns into units of b, fees included. A cycle is profitable when the product of its rates exceeds one. A quote changes the two arcs of one market, and only the cycles through them can change their answer.
Bounded_Cycle_Index enumerates once the cycles of the lengths wanted and, for each change, looks only at the cycles of the arc that changed. It works with one double for each arc, -log(rate), so that a profitable cycle has a negative sum, and it hands the cycles whose sum is below a bound. That sum is rounded: the index does not decide. The bound is given a margin, so that no profitable cycle is lost, and each cycle that the index hands is decided here with the exact product of its rates, which are rationals. The index spares the exact product of the cycles that are far from being profitable, which are nearly all.
The example shows:
set_weight() for all the arcs and for_each_cycle_below() for the whole catalog, to start;set_weight(), and then for_each_cycle_below() with both, which sees the two changes at once and hands each cycle once;update(), for the change of one arc;stamp() and is_stale(), to know whether what was computed of a cycle is still good. Definition in file bounded_cycle_index_example.cc.
| int main | ( | void | ) |
Definition at line 150 of file bounded_cycle_index_example.cc.
References Aleph::all().