diff options
author | fgodi <fgodi@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-05-25 14:02:14 +0000 |
---|---|---|
committer | fgodi <fgodi@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-05-25 14:02:14 +0000 |
commit | 9db309ff6abbcd2ba3ebbc74fa387b55d9660789 (patch) | |
tree | cb6be4026428c665846a7410d3dabc39fe00a7d4 | |
parent | fe56bdfec68dc9994c4c72ac3e70a6c1c1f42891 (diff) |
save
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bottleneckDistance@1199 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 00868265725afaf47ed8292c0d6f7cff235a016f
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Bipartite_graphs_matching/example/basic.cpp | 42 | ||||
-rw-r--r-- | src/Bipartite_graphs_matching/include/gudhi/Planar_neighbors_finder.h | 11 | ||||
-rw-r--r-- | src/Bipartite_graphs_matching/test/bottleneck_unit_test.cpp | 37 |
4 files changed, 46 insertions, 46 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 54165c59..0f031a49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ if(MSVC) # Turn off some VC++ warnings SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wpedantic -Wsign-compare") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -std=c++11 -Wall -Wpedantic -Wsign-compare") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") endif() diff --git a/src/Bipartite_graphs_matching/example/basic.cpp b/src/Bipartite_graphs_matching/example/basic.cpp index 772bcd4a..797968cc 100644 --- a/src/Bipartite_graphs_matching/example/basic.cpp +++ b/src/Bipartite_graphs_matching/example/basic.cpp @@ -23,8 +23,48 @@ #include "../include/gudhi/Graph_matching.h" #include <iostream> +#include <chrono> +#include <fstream> + using namespace Gudhi::bipartite_graph_matching; + +double upper_bound = 400.; // any real >0 + +int main(){ + std::ofstream objetfichier; + objetfichier.open("results.csv", std::ios::out); + + for(int n =50; n<=1000; n+=100){ + std::uniform_real_distribution<double> unif1(0.,upper_bound); + std::uniform_real_distribution<double> unif2(upper_bound/1000.,upper_bound/100.); + std::default_random_engine re; + std::vector< std::pair<double, double> > v1, v2; + for (int i = 0; i < n; i++) { + double a = unif1(re); + double b = unif1(re); + double x = unif2(re); + double y = unif2(re); + v1.emplace_back(std::min(a,b), std::max(a,b)); + v2.emplace_back(std::min(a,b)+std::min(x,y), std::max(a,b)+std::max(x,y)); + if(i%5==0) + v1.emplace_back(std::min(a,b),std::min(a,b)+x); + if(i%3==0) + v2.emplace_back(std::max(a,b),std::max(a,b)+y); + } + + std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); + double b = bottleneck_distance(v1,v2); + std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); + + typedef std::chrono::duration<int,std::milli> millisecs_t; + millisecs_t duration(std::chrono::duration_cast<millisecs_t>(end-start)); + objetfichier << n << ";" << duration.count() << ";" << b << std::endl; + } + objetfichier.close(); +} + +/* int main() { std::vector< std::pair<double,double> > v1, v2; @@ -40,4 +80,4 @@ int main() { std::cout << "Bottleneck distance = " << b << std::endl; -} +}*/ 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 abb14e29..8231409c 100644 --- a/src/Bipartite_graphs_matching/include/gudhi/Planar_neighbors_finder.h +++ b/src/Bipartite_graphs_matching/include/gudhi/Planar_neighbors_finder.h @@ -82,7 +82,7 @@ public: void remove(int v_point_index); /** \internal \brief Can the point given as parameter be returned ? */ bool contains(int v_point_index) const; - /** \internal \brief Provide and remove a V point near to the U point given as parameter, null_point_index() if there isn't such a point. */ + /** \internal \brief Provide a V point near to the U point given as parameter, null_point_index() if there isn't such a point. */ int pull_near(int u_point_index); /** \internal \brief Provide and remove all the V points near to the U point given as parameter. */ virtual std::shared_ptr< std::list<int> > pull_all_near(int u_point_index); @@ -110,6 +110,7 @@ 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); @@ -135,7 +136,6 @@ 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(); @@ -186,12 +186,8 @@ inline int Cgal_pnf::pull_near(int u_point_index){ std::vector<double> w = {1., 1.}; K_neighbor_search search(kd_t, u_point, 0., true, Distance(0, 2, w)); auto it = search.begin(); - if(it==search.end() || G::distance(u_point_index, it->first.point_index) > r){ - for(auto itc=contents.cbegin(); itc != contents.cend(); itc++) - if(G::distance(u_point_index, *itc) <= r) - std::cout << G::distance(u_point_index, *itc) << " ! > " << r << std::endl; + if(it==search.end() || G::distance(u_point_index, it->first.point_index) > r) return null_point_index(); - } return it->first.point_index; } @@ -200,6 +196,7 @@ inline std::shared_ptr< std::list<int> > 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; diff --git a/src/Bipartite_graphs_matching/test/bottleneck_unit_test.cpp b/src/Bipartite_graphs_matching/test/bottleneck_unit_test.cpp index d53a5a3c..7c1d5614 100644 --- a/src/Bipartite_graphs_matching/test/bottleneck_unit_test.cpp +++ b/src/Bipartite_graphs_matching/test/bottleneck_unit_test.cpp @@ -4,9 +4,6 @@ #include <random> #include "../include/gudhi/Graph_matching.h" -#include <chrono> -#include <fstream> - using namespace Gudhi::bipartite_graph_matching; int n1 = 81; // a natural number >0 @@ -166,37 +163,3 @@ BOOST_AUTO_TEST_CASE(global){ } BOOST_CHECK(bottleneck_distance(v1, v2) <= upper_bound/100.); } - -/* -BOOST_AUTO_TEST_CASE(chrono) { - std::ofstream objetfichier; - objetfichier.open("results.csv", std::ios::out); - - for(int n =50; n<=1000; n+=100){ - std::uniform_real_distribution<double> unif1(0.,upper_bound); - std::uniform_real_distribution<double> unif2(upper_bound/1000.,upper_bound/100.); - std::default_random_engine re; - std::vector< std::pair<double, double> > v1, v2; - for (int i = 0; i < n; i++) { - double a = unif1(re); - double b = unif1(re); - double x = unif2(re); - double y = unif2(re); - v1.emplace_back(std::min(a,b), std::max(a,b)); - v2.emplace_back(std::min(a,b)+std::min(x,y), std::max(a,b)+std::max(x,y)); - if(i%5==0) - v1.emplace_back(std::min(a,b),std::min(a,b)+x); - if(i%3==0) - v2.emplace_back(std::max(a,b),std::max(a,b)+y); - } - - std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); - double b = bottleneck_distance(v1,v2); - std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); - - typedef std::chrono::duration<int,std::milli> millisecs_t; - millisecs_t duration(std::chrono::duration_cast<millisecs_t>(end-start)); - objetfichier << n << ";" << duration.count() << ";" << b << std::endl; - } - objetfichier.close(); -}*/ |