From 5fd841c05c707a5dcaff2db835b8e968f0d62f51 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Mon, 23 Dec 2024 15:30:58 -0800 Subject: [PATCH] Filter missing paired info on fly --- src/common/paired_info/pair_info_improver.hpp | 40 +++++++++---------- src/common/paired_info/paired_info.hpp | 22 ++++++++++ .../paired_info/split_path_constructor.hpp | 2 +- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/common/paired_info/pair_info_improver.hpp b/src/common/paired_info/pair_info_improver.hpp index 95969ae8a..a54a9dd86 100644 --- a/src/common/paired_info/pair_info_improver.hpp +++ b/src/common/paired_info/pair_info_improver.hpp @@ -24,17 +24,27 @@ static inline bool ClustersIntersect(omnigraph::de::Point p1, omnigraph::de::Poi math::le(p2.d, p1.d + p1.var + p2.var); } - template -bool AddNonIntersectingInfo(omnigraph::de::PairedInfoIndexT& clustered_index, - typename Graph::EdgeId e1, typename Graph::EdgeId e2, - const omnigraph::de::Point& point_to_add) { +bool CheckNonIntersectingInfo(omnigraph::de::PairedInfoIndexT& clustered_index, + typename Graph::EdgeId e1, typename Graph::EdgeId e2, + const omnigraph::de::Point& p) { auto histogram = clustered_index.Get(e1, e2); for (auto i : histogram) { - if (ClustersIntersect(i, point_to_add)) + if (ClustersIntersect(i, p)) return false; } + return true; +} + + +template +bool AddNonIntersectingInfo(omnigraph::de::PairedInfoIndexT& clustered_index, + typename Graph::EdgeId e1, typename Graph::EdgeId e2, + const omnigraph::de::Point& point_to_add) { + if (!CheckNonIntersectingInfo(clustered_index, e1, e2, point_to_add)) + return false; + clustered_index.Add(e1, e2, point_to_add); return true; } @@ -180,28 +190,16 @@ class PairInfoImprover { for (const auto &path : paths) { TRACE("Path " << path.PrintPath(graph_)); for (const auto &pi : path) - buf.Add(pi.first, pi.second, pi.point); + if (CheckNonIntersectingInfo(index_, pi.first, pi.second, pi.point)) + buf.Add(pi.first, pi.second, pi.point); } } } DEBUG("Fill missing: Threads finished"); DEBUG("Merging maps"); - // FIXME: This is a bit crazy, but we do not have a sane way to iterate - // over buffer. In any case, this is better than it used to be before - omnigraph::de::MutablePairedInfoIndexT to_add(graph_); - to_add.MoveAssign(buf); - - DEBUG("Resulting size " << to_add.size()); - - size_t cnt = 0; - for (auto I = omnigraph::de::half_pair_begin(to_add); - I != omnigraph::de::half_pair_end(to_add); - ++I) { - EdgeId e1 = I.first(), e2 = I.second(); - for (auto p : *I) - cnt += AddNonIntersectingInfo(index_, e1, e2, p); - } + size_t cnt = buf.size(); + index_.MergeAssign(buf); DEBUG("Size of paired index " << index_.size()); diff --git a/src/common/paired_info/paired_info.hpp b/src/common/paired_info/paired_info.hpp index 181c5d605..19778706a 100644 --- a/src/common/paired_info/paired_info.hpp +++ b/src/common/paired_info/paired_info.hpp @@ -300,6 +300,28 @@ class PairedIndex : public PairedBuffer { VERIFY(this->size() >= index_to_add.size()); } + template + void MergeAssign(Buffer& index_to_add) { + if (index_to_add.size() == 0) + return; + + auto locked_table = index_to_add.lock_table(); + for (auto& kvpair : locked_table) { + EdgeId e1_to_add = kvpair.first; auto& map_to_move = kvpair.second; + + for (const auto& to_add : map_to_move) { + EdgePair ep(e1_to_add, to_add.first), conj = this->ConjugatePair(e1_to_add, to_add.first); + if (ep > conj) + continue; + + base::Merge(ep.first, ep.second, *to_add.second); + } + + map_to_move.clear(); + } + VERIFY(this->size() >= index_to_add.size()); + } + template typename std::enable_if::value, void>::type MoveAssign(Buffer& from) { diff --git a/src/common/paired_info/split_path_constructor.hpp b/src/common/paired_info/split_path_constructor.hpp index c355030bd..f536eb6cd 100644 --- a/src/common/paired_info/split_path_constructor.hpp +++ b/src/common/paired_info/split_path_constructor.hpp @@ -106,7 +106,7 @@ class SplitPathConstructor { (size_t) (cur_info.d() + cur_info.var()), dijkstra); DEBUG("Found common part of size " << common_part.size()); - PathInfoClass sub_res(cur_edge); + PathInfo sub_res(cur_edge); if (common_part.size() > 0) { size_t total_length = 0; for (size_t j = 0; j < common_part.size(); ++j)