Skip to content

Commit

Permalink
Filter missing paired info on fly
Browse files Browse the repository at this point in the history
  • Loading branch information
asl committed Dec 25, 2024
1 parent 6e631fb commit 5fd841c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
40 changes: 19 additions & 21 deletions src/common/paired_info/pair_info_improver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<class Graph>
bool AddNonIntersectingInfo(omnigraph::de::PairedInfoIndexT<Graph>& clustered_index,
typename Graph::EdgeId e1, typename Graph::EdgeId e2,
const omnigraph::de::Point& point_to_add) {
bool CheckNonIntersectingInfo(omnigraph::de::PairedInfoIndexT<Graph>& 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<class Graph>
bool AddNonIntersectingInfo(omnigraph::de::PairedInfoIndexT<Graph>& 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;
}
Expand Down Expand Up @@ -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<Graph> 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());

Expand Down
22 changes: 22 additions & 0 deletions src/common/paired_info/paired_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,28 @@ class PairedIndex : public PairedBuffer<G, Traits, Container> {
VERIFY(this->size() >= index_to_add.size());
}

template<class Buffer>
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<class Buffer>
typename std::enable_if<std::is_convertible<typename Buffer::InnerMap, InnerMap>::value,
void>::type MoveAssign(Buffer& from) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/paired_info/split_path_constructor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Graph> 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)
Expand Down

0 comments on commit 5fd841c

Please sign in to comment.