50#include <lal/graphs/directed_graph.hpp>
51#include <lal/graphs/undirected_graph.hpp>
52#include <lal/numeric/rational.hpp>
53#include <lal/iterators/Q_iterator.hpp>
54#include <lal/detail/identity_arrangement.hpp>
55#include <lal/detail/macros/basic_convert.hpp>
71uint64_t
alpha(
const int64_t n,
const int64_t d1,
const int64_t d2)
noexcept {
74 if (1 <= n - (d1 + d2)) {
76 f += (d1 - 1)*(n - d2 - d1);
82 f += ((d2 - n)*(d2 - n + 1))/2;
87 f += (d1 - 1)*(n - d2 - d1);
89 if (1 + d2 - d1 >= 1) {
90 if (1 + d2 <= n - d1) {
94 f += ((n - d2)*(n - d2 - 1))/2;
115uint64_t
beta(
const int64_t n,
const int64_t d1,
const int64_t d2)
noexcept {
119 if (1 <= n - (d1 + d2)) {
121 f += (n - d2)*(n - d2) + 3*(d1 + d2 - n) - d1*d1;
127 f += (d2 - n)*(d2 - n + 1);
132 if (1 + d2 <= n - d1) {
134 f += (n - d1)*(n - d1) - 5*(n - d1 - d2) - d2*d2;
139 f += d1*(2*d2 - d1 - 3);
143 f += (d2 - n)*(2*d1 - d2 - n + 3);
151 f += n*(n - 3) + d1*(6 - 2*n);
158 f += (d1 - n)*(d1 - n + 1);
181template <
typename result_t,
class graph_t,
class arrangement_t>
184 const arrangement_t& arr
189 const uint64_t n = g.get_num_nodes();
193 while (not q.
end()) {
197 const auto [s,t] = st;
198 const auto [u,v] = uv;
203 const auto [al, be] =
205 std::make_pair(
alpha(nn, len_st, len_uv),
beta(nn, len_st, len_uv))
207 std::make_pair(
alpha(nn, len_uv, len_st),
beta(nn, len_uv, len_st))
210 if constexpr (std::is_same_v<result_t, numeric::rational>) {
Iterator over the set of pairs of independent edges of a graph.
Definition: Q_iterator.hpp:107
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition: Q_iterator.hpp:125
void next() noexcept
Moves the iterator to the next pair, if there is any.
Definition: Q_iterator.hpp:143
edge_pair_t get_edge_pair_t() const noexcept
Returns the current edge pair.
Definition: Q_iterator.hpp:131
Exact rational number.
Definition: rational.hpp:63
constexpr uint64_t alpha(const int64_t n, const int64_t d1, const int64_t d2) noexcept
Amount of crossings pairs of edges of given lengths.
Definition: predict_C.hpp:71
constexpr double to_double(const T &t) noexcept
Conversion to double.
Definition: basic_convert.hpp:62
constexpr int64_t to_int64(const T &t) noexcept
Conversion to int64_t.
Definition: basic_convert.hpp:52
result_t predict_C_using_edge_lengths(const graph_t &g, const arrangement_t &arr) noexcept
Predicted number of crossings based on the sum of edge lengths.
Definition: predict_C.hpp:182
constexpr uint64_t to_uint64(const T &t) noexcept
Conversion to uint64_t.
Definition: basic_convert.hpp:57
constexpr T abs_diff(const T &t1, const T &t2) noexcept
Absolute difference of two values.
Definition: basic_convert.hpp:67
constexpr uint64_t beta(const int64_t n, const int64_t d1, const int64_t d2) noexcept
Amount of pairs of edges of given lengths.
Definition: predict_C.hpp:115
Main namespace of the library.
Definition: basic_types.hpp:50