From 8f455abec0d349949960eaefdd0aedd8dff8e7ca Mon Sep 17 00:00:00 2001 From: fgodi Date: Tue, 31 May 2016 14:15:46 +0000 Subject: works git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bottleneckDistance@1227 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6b7d024adef25ef52ac48a2a0ead692be798a708 --- src/Bipartite_graphs_matching/example/basic.cpp | 1 + .../include/gudhi/Internal_point.h | 2 +- .../include/gudhi/Neighbors_finder.h | 2 +- .../include/gudhi/Planar_neighbors_finder.h | 30 ++++++++++++++-------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Bipartite_graphs_matching/example/basic.cpp b/src/Bipartite_graphs_matching/example/basic.cpp index 09530f9a..f1c9d36e 100644 --- a/src/Bipartite_graphs_matching/example/basic.cpp +++ b/src/Bipartite_graphs_matching/example/basic.cpp @@ -36,6 +36,7 @@ int main(){ objetfichier.open("results.csv", std::ios::out); for(int n =50; n<=1000; n+=100){ +std::cout << n << "\n"; std::uniform_real_distribution unif1(0.,upper_bound); std::uniform_real_distribution unif2(upper_bound/1000.,upper_bound/100.); std::default_random_engine re; diff --git a/src/Bipartite_graphs_matching/include/gudhi/Internal_point.h b/src/Bipartite_graphs_matching/include/gudhi/Internal_point.h index 6c9389b7..3dc37962 100644 --- a/src/Bipartite_graphs_matching/include/gudhi/Internal_point.h +++ b/src/Bipartite_graphs_matching/include/gudhi/Internal_point.h @@ -42,7 +42,7 @@ struct Internal_point { double& y() { return vec[ 1 ]; } bool operator==(const Internal_point& p) const { - return (x() == p.x()) && (y() == p.y()) && (point_index==p.point_index); + return point_index==p.point_index; } bool operator!=(const Internal_point& p) const { return ! (*this == p); } /* diff --git a/src/Bipartite_graphs_matching/include/gudhi/Neighbors_finder.h b/src/Bipartite_graphs_matching/include/gudhi/Neighbors_finder.h index 7fa9453d..f346c62f 100644 --- a/src/Bipartite_graphs_matching/include/gudhi/Neighbors_finder.h +++ b/src/Bipartite_graphs_matching/include/gudhi/Neighbors_finder.h @@ -106,7 +106,7 @@ inline int Neighbors_finder::pull_near(int u_point_index) { int tmp; int c = G::corresponding_point_in_v(u_point_index); if (G::on_the_u_diagonal(u_point_index) && !projections_f.empty()) - //All projections are at distance 0 + //Any pair of projection is at distance 0 tmp = *projections_f.cbegin(); else if (contains(c) && (G::distance(u_point_index, c) <= r)) //Is the query point near to its projection ? diff --git a/src/Bipartite_graphs_matching/include/gudhi/Planar_neighbors_finder.h b/src/Bipartite_graphs_matching/include/gudhi/Planar_neighbors_finder.h index ec5c6f91..3d6d0084 100644 --- a/src/Bipartite_graphs_matching/include/gudhi/Planar_neighbors_finder.h +++ b/src/Bipartite_graphs_matching/include/gudhi/Planar_neighbors_finder.h @@ -94,7 +94,7 @@ private: }; /** \internal \typedef \brief Planar_neighbors_finder is the used implementation. */ -typedef Cgal_pnf Planar_neighbors_finder; +typedef Naive_pnf Planar_neighbors_finder; inline Naive_pnf::Naive_pnf(double r_) : r(r_), grid() { } @@ -110,12 +110,12 @@ inline void Naive_pnf::add(int v_point_index) { } inline void Naive_pnf::remove(int v_point_index) { - if(!contains(v_point_index)) - for(auto it = grid.find(get_v_key(v_point_index)); it!=grid.end(); it++) - if(it->second==v_point_index){ - grid.erase(it); - return; - } + if(v_point_index != null_point_index()) + for(auto it = grid.find(get_v_key(v_point_index)); it!=grid.end(); it++) + if(it->second==v_point_index){ + grid.erase(it); + return; + } } inline bool Naive_pnf::contains(int v_point_index) const { @@ -136,6 +136,7 @@ inline int Naive_pnf::pull_near(int u_point_index) { for(auto it = grid.find(std::make_pair(i0 +(i%3)-1, j0+(j%3)-1)); it!=grid.end(); it++) if (G::distance(u_point_index, it->second) <= r) { int tmp = it->second; + grid.erase(it); return tmp; } return null_point_index(); @@ -165,18 +166,24 @@ inline Cgal_pnf::Cgal_pnf(double r_) /** \internal \brief A point added will be possibly pulled. */ inline void Cgal_pnf::add(int v_point_index){ + if(v_point_index == null_point_index()) + return; contents.insert(v_point_index); kd_t.insert(G::get_v_point(v_point_index)); } /** \internal \brief A point manually removed will no longer be possibly pulled. */ inline void Cgal_pnf::remove(int v_point_index){ - contents.erase(v_point_index); - kd_t.remove(G::get_v_point(v_point_index)); + if(contains(v_point_index)){ + contents.erase(v_point_index); + kd_t.remove(G::get_v_point(v_point_index)); + } } /** \internal \brief Can the point given as parameter be returned ? */ inline bool Cgal_pnf::contains(int v_point_index) const{ + if(v_point_index == null_point_index()) + return false; return contents.count(v_point_index)>0; } @@ -188,7 +195,9 @@ inline int Cgal_pnf::pull_near(int u_point_index){ auto it = search.begin(); if(it==search.end() || G::distance(u_point_index, it->first.point_index) > r) return null_point_index(); - return it->first.point_index; + int tmp = it->first.point_index; + remove(tmp); + return tmp; } inline std::shared_ptr< std::list > Cgal_pnf::pull_all_near(int u_point_index) { @@ -196,7 +205,6 @@ inline std::shared_ptr< std::list > Cgal_pnf::pull_all_near(int u_point_ind int last_pull = pull_near(u_point_index); while (last_pull != null_point_index()) { all_pull->emplace_back(last_pull); - remove(last_pull); last_pull = pull_near(u_point_index); } return all_pull; -- cgit v1.2.3