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/arrangement_wrapper.hpp>
55#include <lal/detail/macros/basic_convert.hpp>
72uint64_t
alpha(
const int64_t n,
const int64_t d1,
const int64_t d2)
noexcept {
75 if (1 <= n - (d1 + d2)) {
77 f += (d1 - 1)*(n - d2 - d1);
83 f += ((d2 - n)*(d2 - n + 1))/2;
88 f += (d1 - 1)*(n - d2 - d1);
90 if (1 + d2 - d1 >= 1) {
91 if (1 + d2 <= n - d1) {
95 f += ((n - d2)*(n - d2 - 1))/2;
117uint64_t
beta(
const int64_t n,
const int64_t d1,
const int64_t d2)
noexcept {
121 if (1 <= n - (d1 + d2)) {
123 f += (n - d2)*(n - d2) + 3*(d1 + d2 - n) - d1*d1;
129 f += (d2 - n)*(d2 - n + 1);
134 if (1 + d2 <= n - d1) {
136 f += (n - d1)*(n - d1) - 5*(n - d1 - d2) - d2*d2;
141 f += d1*(2*d2 - d1 - 3);
145 f += (d2 - n)*(2*d1 - d2 - n + 3);
153 f += n*(n - 3) + d1*(6 - 2*n);
160 f += (d1 - n)*(d1 - n + 1);
183template <
typename result_t,
class graph_t,
class arrangement_t>
185(
const graph_t& g,
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:128
void next() noexcept
Moves the iterator to the next pair, if there is any.
Definition Q_iterator.hpp:146
edge_pair_t get_edge_pair_t() const noexcept
Returns the current edge pair.
Definition Q_iterator.hpp:134
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.hpp:72
constexpr double to_double(const T &t) noexcept
Conversion to double.
Definition basic_convert.hpp:72
constexpr int64_t to_int64(const T &t) noexcept
Conversion to int64_t.
Definition basic_convert.hpp:57
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.hpp:185
constexpr uint64_t to_uint64(const T &t) noexcept
Conversion to uint64_t.
Definition basic_convert.hpp:52
constexpr T abs_diff(const T &t1, const T &t2) noexcept
Absolute difference of two values.
Definition basic_convert.hpp:77
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.hpp:117
Main namespace of the library.
Definition basic_types.hpp:48