From d8e1da2f6465e3d6baa0c6e921a3cc0b9ce3f2c7 Mon Sep 17 00:00:00 2001 From: fgodi Date: Fri, 13 Oct 2017 09:33:33 +0000 Subject: module toplex_map added git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@2784 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 61f8f8a2d3920dbc30b86dd808a0e316383af137 --- src/Toplex_map/example/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/Toplex_map/example/CMakeLists.txt (limited to 'src/Toplex_map/example/CMakeLists.txt') diff --git a/src/Toplex_map/example/CMakeLists.txt b/src/Toplex_map/example/CMakeLists.txt new file mode 100644 index 00000000..2341fe06 --- /dev/null +++ b/src/Toplex_map/example/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.6) +project(Toplex_map_examples) + +add_executable(chrono chrono.cpp) -- cgit v1.2.3 From a4677295cf1dd3a8e02dd135348b321eae044104 Mon Sep 17 00:00:00 2001 From: fgodi Date: Tue, 21 Nov 2017 18:38:45 +0000 Subject: ... git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@2927 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1b3f9508c2697619d27776a9824defaa02a1420f --- src/Toplex_map/example/CMakeLists.txt | 4 - src/Toplex_map/example/chrono.cpp | 137 ---------------------------------- 2 files changed, 141 deletions(-) delete mode 100644 src/Toplex_map/example/CMakeLists.txt delete mode 100644 src/Toplex_map/example/chrono.cpp (limited to 'src/Toplex_map/example/CMakeLists.txt') diff --git a/src/Toplex_map/example/CMakeLists.txt b/src/Toplex_map/example/CMakeLists.txt deleted file mode 100644 index 2341fe06..00000000 --- a/src/Toplex_map/example/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -project(Toplex_map_examples) - -add_executable(chrono chrono.cpp) diff --git a/src/Toplex_map/example/chrono.cpp b/src/Toplex_map/example/chrono.cpp deleted file mode 100644 index d93d1e1f..00000000 --- a/src/Toplex_map/example/chrono.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include -#include -#include - -#include -#include - -using namespace Gudhi; - -typedef Simplex typeVectorVertex; -typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; - -class ST_wrapper { - -public: - void insert_simplex(const Simplex& tau); - bool membership(const Simplex& tau); - Vertex contraction(const Vertex x, const Vertex y); - std::size_t num_simplices(); - -private: - Simplex_tree<> simplexTree; - void erase_max(const Simplex& sigma); -}; - -void ST_wrapper::insert_simplex(const Simplex& tau){ - simplexTree.insert_simplex_and_subfaces(tau); -} - -bool ST_wrapper::membership(const Simplex& tau) { - return simplexTree.find(tau) != simplexTree.null_simplex(); -} - -void ST_wrapper::erase_max(const Simplex& sigma){ - if(membership(sigma)) - simplexTree.remove_maximal_simplex(simplexTree.find(sigma)); -} - -Vertex ST_wrapper::contraction(const Vertex x, const Vertex y){ - Simplex sx; sx.insert(x); - auto hx = simplexTree.find(sx); - if(hx != simplexTree.null_simplex()) - for(auto h : simplexTree.cofaces_simplex_range(hx,0)){ - auto sr = simplexTree.simplex_vertex_range(h); - Simplex sigma(sr.begin(),sr.end()); - erase_max(sigma); - sigma.erase(x); - sigma.insert(y); - insert_simplex(sigma); - } - return y; -} - -std::size_t ST_wrapper::num_simplices(){ - return simplexTree.num_simplices(); -} - - - -int n = 300; - -int nb_insert_simplex1 = 3000; -int nb_membership1 = 4000; -int nb_contraction = 300; -int nb_insert_simplex2 = 3000; -int nb_membership2 = 400000; - -Simplex random_simplex(int n, int d){ - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, n); - Simplex s; - while(s.size()!=d) - s.insert(dis(gen)); - return s; -} - -std::vector r_vector_simplices(int n, int max_d, int m){ - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(1, max_d); - std::vector v; - for(int i=0; i -void chrono(int n, int d){ - complex_type K; - std::vector simplices_insert_simplex1 = r_vector_simplices(n,d,nb_insert_simplex1); - std::vector simplices_membership1 = r_vector_simplices(n,d,nb_membership1); - std::vector simplices_insert_simplex2 = r_vector_simplices(n - 2*nb_contraction,d,nb_insert_simplex2); - std::vector simplices_membership2 = r_vector_simplices(n - 2*nb_contraction,d,nb_membership2); - std::chrono::time_point start, end; - - for(const Simplex& s : simplices_insert_simplex1) - K.insert_simplex(s); - - for(const Simplex& s : simplices_membership1) - K.membership(s); - - start = std::chrono::system_clock::now(); - for(int i = 0; i<=nb_contraction; i++) - K.contraction(n-2*i,n-2*i-1); - end = std::chrono::system_clock::now(); - auto c3 = std::chrono::duration_cast(end-start).count(); - - start = std::chrono::system_clock::now(); - for(const Simplex& s : simplices_insert_simplex2) - K.insert_simplex(s); - end = std::chrono::system_clock::now(); - auto c1 = std::chrono::duration_cast(end-start).count(); - - start = std::chrono::system_clock::now(); - for(const Simplex& s : simplices_membership2) - K.membership(s); - end = std::chrono::system_clock::now(); - auto c2 = std::chrono::duration_cast(end-start).count(); - - std::cout << c1 << "\t \t" << c2 << "\t \t" << c3 << "\t \t" << K.num_simplices() << std::endl; -} - -int main(){ - for(int d=5;d<=40;d+=5){ - std::cout << "d=" << d << " \t Insertions \t Membership \t Contractions \t Size" << std::endl; - std::cout << "T Map \t \t"; - chrono(n,d); - std::cout << "Lazy \t \t"; - chrono(n,d); - if(d<=15){ - std::cout << "ST \t \t"; - chrono(n,d); - } - std::cout << std::endl; - } -} -- cgit v1.2.3 From e94d787c89a7c9a71c86118bc3e048241e9c5ca1 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 15 May 2018 14:16:45 +0000 Subject: Add examples with Fake_simplex_tree git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3442 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ccdd8f43c0e86a98efd3f9d7e9c7b8728ebd27a7 --- src/Toplex_map/benchmark/CMakeLists.txt | 2 +- src/Toplex_map/example/CMakeLists.txt | 5 +++++ src/Toplex_map/example/Fake_simplex_tree.h | 19 ++++++---------- src/Toplex_map/example/Simple_toplex_map.cpp | 26 +++++++++++++--------- .../example/Toplex_map_from_cliques_of_graph.cpp | 5 ++--- 5 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 src/Toplex_map/example/CMakeLists.txt (limited to 'src/Toplex_map/example/CMakeLists.txt') diff --git a/src/Toplex_map/benchmark/CMakeLists.txt b/src/Toplex_map/benchmark/CMakeLists.txt index e4cfab6f..2c67892c 100644 --- a/src/Toplex_map/benchmark/CMakeLists.txt +++ b/src/Toplex_map/benchmark/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 2.6) -project(Toplex_map_examples) +project(Toplex_map_benchmark) add_executable(toplex_map_chrono chrono.cpp) diff --git a/src/Toplex_map/example/CMakeLists.txt b/src/Toplex_map/example/CMakeLists.txt new file mode 100644 index 00000000..051d7bcd --- /dev/null +++ b/src/Toplex_map/example/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.6) +project(Toplex_map_examples) + +add_executable(Toplex_map_example_simple Simple_toplex_map.cpp) +add_executable(Toplex_map_example_from_cliques_of_graph Toplex_map_from_cliques_of_graph.cpp) diff --git a/src/Toplex_map/example/Fake_simplex_tree.h b/src/Toplex_map/example/Fake_simplex_tree.h index 8187e24e..c3d87e47 100644 --- a/src/Toplex_map/example/Fake_simplex_tree.h +++ b/src/Toplex_map/example/Fake_simplex_tree.h @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -117,39 +118,34 @@ bool Fake_simplex_tree::all_facets_inside(const Input_vertex_range &vertex_range if(!membership(s)) return false; return true; } -/* + std::size_t Fake_simplex_tree::dimension() const { std::size_t max = 0; for(const Simplex& s : max_simplices()) max = std::max(max, s.size()); return max-1; } -*/ + std::size_t Fake_simplex_tree::dimension(Simplex_ptr& sptr) const{ return sptr->size(); } -/* + std::size_t Fake_simplex_tree::num_simplices() const { - //return filtration_simplex_range().size(); return max_simplices().size(); } -*/ + std::size_t Fake_simplex_tree::num_vertices() const { - /* std::unordered_set vertices; for(const Toplex_map::Simplex& s : max_simplices()) for (Toplex_map::Vertex v : s) vertices.emplace(v); return vertices.size(); - */ - return 0; } Toplex_map::Simplex Fake_simplex_tree::simplex_vertex_range(const Simplex& s) const { return s; } -/* std::vector Fake_simplex_tree::max_simplices() const{ std::vector max_s; for(auto kv : toplex_maps) @@ -157,8 +153,7 @@ std::vector Fake_simplex_tree::max_simplices() const{ max_s.emplace_back(*sptr); return max_s; } -*/ -/* + std::vector Fake_simplex_tree::filtration_simplex_range(int d) const{ std::vector m = max_simplices(); std::vector range; @@ -180,7 +175,7 @@ std::vector Fake_simplex_tree::filtration_simplex_range(int std::vector Fake_simplex_tree::skeleton_simplex_range(int d) const{ return filtration_simplex_range(d); -}*/ +} Toplex_map::Vertex Fake_simplex_tree::contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y){ for(auto kv : toplex_maps) diff --git a/src/Toplex_map/example/Simple_toplex_map.cpp b/src/Toplex_map/example/Simple_toplex_map.cpp index 4fa735a6..d383e84b 100644 --- a/src/Toplex_map/example/Simple_toplex_map.cpp +++ b/src/Toplex_map/example/Simple_toplex_map.cpp @@ -21,7 +21,7 @@ */ #include -#include "gudhi/Fake_simplex_tree.h" +#include "Fake_simplex_tree.h" #include #include // for pair @@ -184,10 +184,12 @@ int main(int argc, char * const argv[]) { << " simplices - dimension is " << t_map.dimension() << "\n"; std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; for (auto f_simplex : t_map.filtration_simplex_range()) { - std::cout << " " << "[" << t_map.filtration(f_simplex) << "] "; - for (auto vertex : t_map.simplex_vertex_range(f_simplex)) - std::cout << "(" << vertex << ")"; - std::cout << std::endl; + if (f_simplex.size() > 0) { + std::cout << " " << "[" << t_map.filtration(f_simplex) << "] "; + for (auto vertex : t_map.simplex_vertex_range(f_simplex)) + std::cout << "(" << vertex << ")"; + std::cout << std::endl; + } } // [0.1] 0 // [0.1] 1 @@ -201,13 +203,15 @@ int main(int argc, char * const argv[]) { std::cout << std::endl << std::endl; - std::cout << "Iterator on skeleton:" << std::endl; - for (auto f_simplex : t_map.skeleton_simplex_range()) { - std::cout << " " << "[" << t_map.filtration(f_simplex) << "] "; - for (auto vertex : t_map.simplex_vertex_range(f_simplex)) { - std::cout << vertex << " "; + std::cout << "Iterator on skeleton[1]:" << std::endl; + for (auto f_simplex : t_map.skeleton_simplex_range(1)) { + if (f_simplex.size() > 0) { + std::cout << " " << "[" << t_map.filtration(f_simplex) << "] "; + for (auto vertex : t_map.simplex_vertex_range(f_simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; } - std::cout << std::endl; } return 0; diff --git a/src/Toplex_map/example/Toplex_map_from_cliques_of_graph.cpp b/src/Toplex_map/example/Toplex_map_from_cliques_of_graph.cpp index 3df0cbd9..c43f1b69 100644 --- a/src/Toplex_map/example/Toplex_map_from_cliques_of_graph.cpp +++ b/src/Toplex_map/example/Toplex_map_from_cliques_of_graph.cpp @@ -21,7 +21,7 @@ */ #include -#include "gudhi/Fake_simplex_tree.h" +#include "Fake_simplex_tree.h" #include #include @@ -82,7 +82,7 @@ int main(int argc, char * const argv[]) { std::cout << std::endl << std::endl; std::cout << "Iterator on skeleton:" << std::endl; - for (auto f_simplex : t_map.skeleton_simplex_range()) { + for (auto f_simplex : t_map.skeleton_simplex_range(max_dim)) { std::cout << " " << "[" << t_map.filtration(f_simplex) << "] "; for (auto vertex : t_map.simplex_vertex_range(f_simplex)) { std::cout << vertex << " "; @@ -91,4 +91,3 @@ int main(int argc, char * const argv[]) { } return 0; } -} -- cgit v1.2.3 From 004ff4cfc01d1c8128a2b39092dbfbc25149069d Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 12 Oct 2018 12:42:11 +0000 Subject: Rename num_simplices num_maximal_simplices Make unitary tests working git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3947 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: eddea297f7cf6a0fd172ceaa3fbb28b6e3cb2e63 --- src/Toplex_map/benchmark/CMakeLists.txt | 1 - src/Toplex_map/example/CMakeLists.txt | 5 +- src/Toplex_map/include/gudhi/Lazy_Toplex_map.h | 5 +- src/Toplex_map/include/gudhi/Toplex_map.h | 4 +- src/Toplex_map/test/CMakeLists.txt | 14 +--- src/Toplex_map/test/toplex_map_unit_test.cpp | 109 +++++++++++++++---------- 6 files changed, 77 insertions(+), 61 deletions(-) (limited to 'src/Toplex_map/example/CMakeLists.txt') diff --git a/src/Toplex_map/benchmark/CMakeLists.txt b/src/Toplex_map/benchmark/CMakeLists.txt index 2c67892c..c2f216bc 100644 --- a/src/Toplex_map/benchmark/CMakeLists.txt +++ b/src/Toplex_map/benchmark/CMakeLists.txt @@ -1,4 +1,3 @@ -cmake_minimum_required(VERSION 2.6) project(Toplex_map_benchmark) add_executable(toplex_map_chrono chrono.cpp) diff --git a/src/Toplex_map/example/CMakeLists.txt b/src/Toplex_map/example/CMakeLists.txt index 051d7bcd..58185fd5 100644 --- a/src/Toplex_map/example/CMakeLists.txt +++ b/src/Toplex_map/example/CMakeLists.txt @@ -1,5 +1,4 @@ -cmake_minimum_required(VERSION 2.6) project(Toplex_map_examples) -add_executable(Toplex_map_example_simple Simple_toplex_map.cpp) -add_executable(Toplex_map_example_from_cliques_of_graph Toplex_map_from_cliques_of_graph.cpp) +#add_executable(Toplex_map_example_simple Simple_toplex_map.cpp) +#add_executable(Toplex_map_example_from_cliques_of_graph Toplex_map_from_cliques_of_graph.cpp) diff --git a/src/Toplex_map/include/gudhi/Lazy_Toplex_map.h b/src/Toplex_map/include/gudhi/Lazy_Toplex_map.h index 25281998..ea10d390 100644 --- a/src/Toplex_map/include/gudhi/Lazy_Toplex_map.h +++ b/src/Toplex_map/include/gudhi/Lazy_Toplex_map.h @@ -3,7 +3,6 @@ #include #include -#include namespace Gudhi { @@ -67,7 +66,7 @@ public: /** \brief Number of simplices stored. * \ingroup toplex_map */ - std::size_t num_simplices() const; + std::size_t num_maximal_simplices() const; std::unordered_map gamma0_lbounds; @@ -254,7 +253,7 @@ void Lazy_Toplex_map::clean(const Vertex v){ insert_simplex(*sptr); } -std::size_t Lazy_Toplex_map::num_simplices() const{ +std::size_t Lazy_Toplex_map::num_maximal_simplices() const{ return size; } diff --git a/src/Toplex_map/include/gudhi/Toplex_map.h b/src/Toplex_map/include/gudhi/Toplex_map.h index 73d2c63d..5a6c7dbf 100644 --- a/src/Toplex_map/include/gudhi/Toplex_map.h +++ b/src/Toplex_map/include/gudhi/Toplex_map.h @@ -88,7 +88,7 @@ public: /** \brief Number of maximal simplices. * \ingroup toplex_map */ - std::size_t num_simplices() const; + std::size_t num_maximal_simplices() const; std::set unitary_collapse(const Toplex_map::Vertex k, const Toplex_map::Vertex d); @@ -251,7 +251,7 @@ void Toplex_map::remove_vertex(const Toplex_map::Vertex x){ } } -std::size_t Toplex_map::num_simplices() const{ +std::size_t Toplex_map::num_maximal_simplices() const{ return maximal_cofaces(Simplex()).size(); } diff --git a/src/Toplex_map/test/CMakeLists.txt b/src/Toplex_map/test/CMakeLists.txt index 5ed55e97..237cfdad 100644 --- a/src/Toplex_map/test/CMakeLists.txt +++ b/src/Toplex_map/test/CMakeLists.txt @@ -1,14 +1,8 @@ -cmake_minimum_required(VERSION 2.6) project(Toplex_map_tests) -add_executable ( ToplexMapUT toplex_map_unit_test.cpp ) -target_link_libraries(ToplexMapUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +include(GUDHI_test_coverage) +add_executable( Toplex_map_unit_test toplex_map_unit_test.cpp ) +target_link_libraries(Toplex_map_unit_test ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) -# Unitary tests -add_test(NAME ToplexMapUT - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/ToplexMapUT - ${CMAKE_SOURCE_DIR}/src/Toplex_map/test/test.txt - # XML format for Jenkins xUnit plugin - --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/ToplexMapUT.xml --log_level=test_suite --report_level=no) - +gudhi_add_coverage_test(Toplex_map_unit_test) diff --git a/src/Toplex_map/test/toplex_map_unit_test.cpp b/src/Toplex_map/test/toplex_map_unit_test.cpp index c12ad094..2c584c5d 100644 --- a/src/Toplex_map/test/toplex_map_unit_test.cpp +++ b/src/Toplex_map/test/toplex_map_unit_test.cpp @@ -1,54 +1,79 @@ #include -#include +#include +#include #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "toplex map" #include +#include + +using list_of_tested_variants = boost::mpl::list; + +BOOST_AUTO_TEST_CASE_TEMPLATE(common_toplex_map_functionnalities, Toplex_map, list_of_tested_variants) { + using Vertex = typename Toplex_map::Vertex; + + std::vector sigma1 = {1, 2, 3, 4}; + std::vector sigma2 = {5, 2, 3, 6}; + std::vector sigma3 = {5}; + std::vector sigma4 = {5, 2, 3}; + std::vector sigma5 = {5, 2, 7}; + std::vector sigma6 = {4, 5, 3}; + std::vector sigma7 = {4, 5, 9}; + std::vector sigma8 = {1, 2, 3, 6}; + + Toplex_map K; + K.insert_simplex(sigma1); + K.insert_simplex(sigma2); + K.insert_simplex(sigma3); + K.insert_simplex(sigma6); + K.insert_simplex(sigma7); + + std::cout << K.num_maximal_simplices(); + + BOOST_CHECK(K.membership(sigma4)); + //BOOST_CHECK(!K.maximality(sigma3)); + BOOST_CHECK(!K.membership(sigma5)); + K.insert_simplex(sigma5); + + std::cout << K.num_maximal_simplices(); + + BOOST_CHECK(K.membership(sigma5)); + std::vector sigma9 = {1, 2, 3}; + std::vector sigma10 = {2, 7}; + auto r = K.contraction(4,5); + + std::cout << K.num_maximal_simplices(); + + sigma9.emplace_back(r); + sigma10.emplace_back(r); + BOOST_CHECK(!K.membership(sigma6)); + BOOST_CHECK(K.membership(sigma9)); + BOOST_CHECK(K.membership(sigma10)); + K.remove_simplex(sigma10); + BOOST_CHECK(!K.membership(sigma10)); -using namespace Gudhi; - -typedef Toplex_map::Vertex Vertex; - -std::vector sigma1 = {1, 2, 3, 4}; -std::vector sigma2 = {5, 2, 3, 6}; -std::vector sigma3 = {5}; -std::vector sigma4 = {5, 2, 3}; -std::vector sigma5 = {5, 2, 7}; -std::vector sigma6 = {4, 5, 3}; -std::vector sigma7 = {4, 5, 9}; -std::vector sigma8 = {1, 2, 3, 6}; - - -BOOST_AUTO_TEST_CASE(toplexmap) { - Toplex_map K; - K.insert_simplex(sigma1); - K.insert_simplex(sigma2); - K.insert_simplex(sigma3); - K.insert_simplex(sigma6); - K.insert_simplex(sigma7); - BOOST_CHECK(K.membership(sigma4)); - BOOST_CHECK(!K.maximality(sigma3)); - BOOST_CHECK(!K.membership(sigma5)); - K.insert_simplex(sigma5); - std::vector sigma9 = {1, 2, 3}; - std::vector sigma10 = {2, 7}; - auto r = K.contraction(4,5); - sigma9.emplace_back(r); - sigma10.emplace_back(r); - BOOST_CHECK(!K.membership(sigma6)); - BOOST_CHECK(K.membership(sigma9)); - BOOST_CHECK(K.membership(sigma10)); } +BOOST_AUTO_TEST_CASE(toplex_map_maximality) { + using Vertex = Gudhi::Toplex_map::Vertex; + + std::vector sigma1 = {1, 2, 3, 4}; + std::vector sigma2 = {5, 2, 3, 6}; + std::vector sigma3 = {5}; + std::vector sigma4 = {4, 5, 3}; + std::vector sigma5 = {4, 5, 9}; -BOOST_AUTO_TEST_CASE(ftoplexmap) { - Filtered_toplex_map K; - K.insert_simplex_and_subfaces(sigma1, 2.); - K.insert_simplex_and_subfaces(sigma2, 2.); - K.insert_simplex_and_subfaces(sigma6, 1.); - K.insert_simplex_and_subfaces(sigma7, 1.); - BOOST_CHECK(K.filtration(sigma4)==2.); - BOOST_CHECK(K.filtration(sigma3)==1.); + Gudhi::Toplex_map K; + K.insert_simplex(sigma1); + K.insert_simplex(sigma2); + K.insert_simplex(sigma3); + K.insert_simplex(sigma4); + K.insert_simplex(sigma5); + BOOST_CHECK(K.maximality(sigma1)); + BOOST_CHECK(K.maximality(sigma2)); + BOOST_CHECK(!K.maximality(sigma3)); + BOOST_CHECK(K.maximality(sigma4)); + BOOST_CHECK(K.maximality(sigma5)); } -- cgit v1.2.3 From da1d57f361de13f48d606eda427e63c700574f74 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 15 Oct 2018 20:39:12 +0000 Subject: Toplex_map indentation simple toplex map example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3953 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 253f001adf27dbe8318ae12996f32b07e4fab139 --- src/Toplex_map/example/CMakeLists.txt | 1 + src/Toplex_map/example/simple_toplex_map.cpp | 160 +++++++++++++++++++++++++++ src/Toplex_map/include/gudhi/Toplex_map.h | 143 +++++++++++++----------- 3 files changed, 238 insertions(+), 66 deletions(-) create mode 100644 src/Toplex_map/example/simple_toplex_map.cpp (limited to 'src/Toplex_map/example/CMakeLists.txt') diff --git a/src/Toplex_map/example/CMakeLists.txt b/src/Toplex_map/example/CMakeLists.txt index 58185fd5..346d35d0 100644 --- a/src/Toplex_map/example/CMakeLists.txt +++ b/src/Toplex_map/example/CMakeLists.txt @@ -1,4 +1,5 @@ project(Toplex_map_examples) +add_executable(simple_toplex_map simple_toplex_map.cpp) #add_executable(Toplex_map_example_simple Simple_toplex_map.cpp) #add_executable(Toplex_map_example_from_cliques_of_graph Toplex_map_from_cliques_of_graph.cpp) diff --git a/src/Toplex_map/example/simple_toplex_map.cpp b/src/Toplex_map/example/simple_toplex_map.cpp new file mode 100644 index 00000000..0d80f94e --- /dev/null +++ b/src/Toplex_map/example/simple_toplex_map.cpp @@ -0,0 +1,160 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2017 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include +#include // for pair +#include + +int main(int argc, char * const argv[]) { + using Simplex = Gudhi::Toplex_map::Simplex; + Simplex sigma1 = {1, 2, 3}; + Simplex sigma2 = {2, 3, 4, 5}; + + Gudhi::Toplex_map tm; + tm.insert_simplex(sigma1); + tm.insert_simplex(sigma2); + + /* Simplex is: */ + /* 2 4 */ + /* o---o */ + /* /X\5/ */ + /* o---o */ + /* 1 3 */ + + std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; + + // Browse maximal cofaces + Simplex sigma3 = {2, 3}; + std::cout << "Maximal cofaces of {2, 3} are :" << std::endl; + for (auto simplex_ptr : tm.maximal_cofaces(sigma3, 2)) { + for (auto v : *simplex_ptr) { + std::cout << v << ", "; + } + std::cout << std::endl; + } + + // Browse maximal simplices + std::cout << "Maximal simplices are :" << std::endl; + for (auto simplex_ptr : tm.maximal_simplices()) { + for (auto v : *simplex_ptr) { + std::cout << v << ", "; + } + std::cout << std::endl; + } + + Simplex sigma4 = {1, 3}; + assert(tm.membership(sigma4)); + + Gudhi::Toplex_map::Vertex v = tm.contraction(1, 3); + std::cout << "After contraction(1, 3) - " << v << std::endl; + /* Simplex is: */ + /* 2 4 */ + /* o---o */ + /* \5/ */ + /* o */ + /* 3 */ + std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; + + // Browse maximal simplices + std::cout << "Maximal simplices are :" << std::endl; + for (auto simplex_ptr : tm.maximal_simplices()) { + for (auto v : *simplex_ptr) { + std::cout << v << ", "; + } + std::cout << std::endl; + } + + Simplex sigma5 = {3, 4}; + assert(tm.membership(sigma5)); + + v = tm.contraction(3, 4); + std::cout << "After contraction(3, 4) - " << v << std::endl; + /* Simplex is: */ + /* 2 4 */ + /* o---o */ + /* \X/ */ + /* o */ + /* 5 */ + std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; + + // Browse maximal simplices + std::cout << "Maximal simplices are :" << std::endl; + for (auto simplex_ptr : tm.maximal_simplices()) { + for (auto v : *simplex_ptr) { + std::cout << v << ", "; + } + std::cout << std::endl; + } + + tm.insert_simplex(sigma1); + tm.insert_simplex(sigma2); + /* Simplex is: */ + /* 2 4 */ + /* o---o */ + /* /X\5/ */ + /* o---o */ + /* 1 3 */ + tm.remove_simplex(sigma1); + + std::cout << "After remove_simplex(1, 2, 3)" << std::endl; + /* Simplex is: */ + /* 2 4 */ + /* o---o */ + /* / \5/ */ + /* o---o */ + /* 1 3 */ + std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; + + // Browse maximal simplices + std::cout << "Maximal simplices are :" << std::endl; + for (auto simplex_ptr : tm.maximal_simplices()) { + for (auto v : *simplex_ptr) { + std::cout << v << ", "; + } + std::cout << std::endl; + } + + tm.remove_vertex(1); + + std::cout << "After remove_vertex(1)" << std::endl; + /* Simplex is: */ + /* 2 4 */ + /* o---o */ + /* \5/ */ + /* o */ + /* 3 */ + std::cout << "num max simplices = " << tm.num_maximal_simplices() << " - num vertices = " << tm.num_vertices() << std::endl; + + // Browse maximal simplices + std::cout << "Maximal simplices are :" << std::endl; + for (auto simplex_ptr : tm.maximal_simplices()) { + for (auto v : *simplex_ptr) { + std::cout << v << ", "; + } + std::cout << std::endl; + } + + return 0; +} diff --git a/src/Toplex_map/include/gudhi/Toplex_map.h b/src/Toplex_map/include/gudhi/Toplex_map.h index 565415e1..7cde8ea1 100644 --- a/src/Toplex_map/include/gudhi/Toplex_map.h +++ b/src/Toplex_map/include/gudhi/Toplex_map.h @@ -17,79 +17,94 @@ class Toplex_map { public: - /** Vertex is the type of vertices. */ - typedef std::size_t Vertex; - - /** Simplex is the type of simplices. */ - typedef std::set Simplex; - - /** The type of the pointers to maximal simplices. */ - typedef std::shared_ptr Simplex_ptr; - - struct Sptr_hash{ std::size_t operator()(const Toplex_map::Simplex_ptr& s) const; }; - struct Sptr_equal{ std::size_t operator()(const Toplex_map::Simplex_ptr& a, const Toplex_map::Simplex_ptr& b) const; }; - /** The type of the sets of Toplex_map::Simplex_ptr. */ - typedef std::unordered_set Simplex_ptr_set; - - /** \brief Adds the given simplex to the complex. - * Nothing happens if the simplex has a coface in the complex. */ - template - void insert_simplex(const Input_vertex_range &vertex_range); - - /** \brief Removes the given simplex and its cofaces from the complex. - * Its faces are kept inside. */ - template - void remove_simplex(const Input_vertex_range &vertex_range); - - /** Does a simplex belong to the complex ? */ - template - bool membership(const Input_vertex_range &vertex_range) const; - - /** Does a simplex is a toplex ? */ - template - bool maximality(const Input_vertex_range &vertex_range) const; - - /** Gives a set of pointers to the maximal cofaces of a simplex. - * Gives all the toplices if given the empty simplex. - * Gives not more than max_number maximal cofaces if max_number is strictly positive. */ - template - Toplex_map::Simplex_ptr_set maximal_cofaces(const Input_vertex_range &vertex_range, const std::size_t max_number = 0) const; - - /** Contracts one edge in the complex. - * The edge has to verify the link condition if you want to preserve topology. - * Returns the remaining vertex. */ - Toplex_map::Vertex contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y); - - /** Adds the given simplex to the complex. - * The simplex must not have neither maximal face nor coface in the complex. */ - template - void insert_independent_simplex(const Input_vertex_range &vertex_range); + /** Vertex is the type of vertices. */ + using Vertex = std::size_t; + + /** Simplex is the type of simplices. */ + using Simplex = std::set; + + /** The type of the pointers to maximal simplices. */ + using Simplex_ptr = std::shared_ptr; + + struct Sptr_hash { + std::size_t operator()(const Toplex_map::Simplex_ptr& s) const; + }; + + struct Sptr_equal{ + std::size_t operator()(const Toplex_map::Simplex_ptr& a, const Toplex_map::Simplex_ptr& b) const; + }; + + /** The type of the sets of Toplex_map::Simplex_ptr. */ + using Simplex_ptr_set = std::unordered_set; + + /** \brief Adds the given simplex to the complex. + * Nothing happens if the simplex has a coface in the complex. */ + template + void insert_simplex(const Input_vertex_range &vertex_range); + + /** \brief Removes the given simplex and its cofaces from the complex. + * Its faces are kept inside. */ + template + void remove_simplex(const Input_vertex_range &vertex_range); + + /** Does a simplex belong to the complex ? */ + template + bool membership(const Input_vertex_range &vertex_range) const; + + /** Does a simplex is a toplex ? */ + template + bool maximality(const Input_vertex_range &vertex_range) const; + + /** Gives a set of pointers to the maximal cofaces of a simplex. + * Gives all the toplices if given the empty simplex. + * Gives not more than max_number maximal cofaces if max_number is strictly positive. */ + template + Toplex_map::Simplex_ptr_set maximal_cofaces(const Input_vertex_range &vertex_range, const std::size_t max_number = 0) const; + + /** Gives a set of pointers to the maximal simplices. + * Gives not more than max_number maximal cofaces if max_number is strictly positive. */ + Toplex_map::Simplex_ptr_set maximal_simplices(const std::size_t max_number = 0) const { + return maximal_cofaces(Simplex(), max_number); + } - /** \internal Removes a toplex without adding facets after. */ - void erase_maximal(const Toplex_map::Simplex_ptr& sptr); + /** Contracts one edge in the complex. + * The edge has to verify the link condition if you want to preserve topology. + * Returns the remaining vertex. */ + Toplex_map::Vertex contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y); - /** Removes a vertex from any simplex containing it. */ - void remove_vertex(const Toplex_map::Vertex x); + /** Removes a vertex from any simplex containing it. */ + void remove_vertex(const Toplex_map::Vertex x); - /** \brief Number of maximal simplices. */ - std::size_t num_maximal_simplices() const; + /** \brief Number of maximal simplices. */ + std::size_t num_maximal_simplices() const { + return maximal_simplices().size(); + } /** \brief Number of vertices. */ - std::size_t num_vertices() const{ + std::size_t num_vertices() const { return t0.size(); } std::set unitary_collapse(const Toplex_map::Vertex k, const Toplex_map::Vertex d); + /** Adds the given simplex to the complex. + * The simplex must not have neither maximal face nor coface in the complex. */ + template + void insert_independent_simplex(const Input_vertex_range &vertex_range); + protected: - /** \internal Gives an index in order to look for a simplex quickly. */ - template - Toplex_map::Vertex best_index(const Input_vertex_range &vertex_range) const; - - /** \internal The map from vertices to toplices */ - std::unordered_map t0; - - const Toplex_map::Vertex vertex_upper_bound = std::numeric_limits::max(); + /** \internal Gives an index in order to look for a simplex quickly. */ + template + Toplex_map::Vertex best_index(const Input_vertex_range &vertex_range) const; + + /** \internal The map from vertices to toplices */ + std::unordered_map t0; + + const Toplex_map::Vertex vertex_upper_bound = std::numeric_limits::max(); + + /** \internal Removes a toplex without adding facets after. */ + void erase_maximal(const Toplex_map::Simplex_ptr& sptr); + }; // Pointers are also used as key in the hash sets. @@ -240,10 +255,6 @@ void Toplex_map::remove_vertex(const Toplex_map::Vertex x){ } } -std::size_t Toplex_map::num_maximal_simplices() const{ - return maximal_cofaces(Simplex()).size(); -} - inline void Toplex_map::erase_maximal(const Toplex_map::Simplex_ptr& sptr){ Simplex sigma(*sptr); if (sptr->size()==0) -- cgit v1.2.3 From b4ac7c5daefa6a22a513a20119c4fdd8ec926f5e Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 16 Oct 2018 08:25:18 +0000 Subject: Resize map.png Add simple_toplex_map in test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3954 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8899f42427e297b4527147a051adab1f9e8850dd --- src/Toplex_map/doc/map.png | Bin 278692 -> 71815 bytes src/Toplex_map/example/CMakeLists.txt | 5 ++--- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Toplex_map/example/CMakeLists.txt') diff --git a/src/Toplex_map/doc/map.png b/src/Toplex_map/doc/map.png index d1987043..0f9cde2b 100644 Binary files a/src/Toplex_map/doc/map.png and b/src/Toplex_map/doc/map.png differ diff --git a/src/Toplex_map/example/CMakeLists.txt b/src/Toplex_map/example/CMakeLists.txt index 346d35d0..1d54fe87 100644 --- a/src/Toplex_map/example/CMakeLists.txt +++ b/src/Toplex_map/example/CMakeLists.txt @@ -1,5 +1,4 @@ project(Toplex_map_examples) -add_executable(simple_toplex_map simple_toplex_map.cpp) -#add_executable(Toplex_map_example_simple Simple_toplex_map.cpp) -#add_executable(Toplex_map_example_from_cliques_of_graph Toplex_map_from_cliques_of_graph.cpp) +add_executable(Toplex_map_example_simple_toplex_map simple_toplex_map.cpp) +add_test(NAME Toplex_map_example_simple_toplex_map COMMAND $) -- cgit v1.2.3