From dda6af124625a4fbcd2524d623ef904b394af001 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 16 Oct 2018 14:33:27 +0000 Subject: Add copyrights Fix cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3959 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 02c873347468e28d50f0c8ac385be988c07c96df --- src/Toplex_map/benchmark/benchmark_tm.cpp | 170 ++++++++++++++++-------------- 1 file changed, 89 insertions(+), 81 deletions(-) (limited to 'src/Toplex_map/benchmark/benchmark_tm.cpp') diff --git a/src/Toplex_map/benchmark/benchmark_tm.cpp b/src/Toplex_map/benchmark/benchmark_tm.cpp index 5f13288c..eedb442b 100644 --- a/src/Toplex_map/benchmark/benchmark_tm.cpp +++ b/src/Toplex_map/benchmark/benchmark_tm.cpp @@ -1,3 +1,25 @@ +/* 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: François Godi, Vincent Rouvreau + * + * Copyright (C) 2018 INRIA + * + * 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 @@ -10,11 +32,10 @@ using namespace Gudhi; typedef Toplex_map::Simplex Simplex; typedef Toplex_map::Vertex Vertex; -typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; +typedef std::pair::Simplex_handle, bool> typePairSimplexBool; class ST_wrapper { - -public: + public: void insert_simplex(const Simplex& tau) { /*std::cout << "insert_simplex - " << simplexTree.num_simplices() << " - "; for (auto v : tau) @@ -24,28 +45,22 @@ public: simplexTree.insert_simplex_and_subfaces(tau); } - bool membership(const Simplex& tau) { - return simplexTree.find(tau) != simplexTree.null_simplex(); - } + bool membership(const Simplex& tau) { return simplexTree.find(tau) != simplexTree.null_simplex(); } Vertex contraction(const Vertex x, const Vertex y) { // TODO (VR): edge contraction is not yet available for Simplex_tree return y; } - std::size_t num_maximal_simplices() { - return simplexTree.num_simplices(); - } + std::size_t num_maximal_simplices() { return simplexTree.num_simplices(); } -private: - Simplex_tree<> simplexTree; - void erase_max(const Simplex& sigma) { - if(membership(sigma)) - simplexTree.remove_maximal_simplex(simplexTree.find(sigma)); - } + private: + Simplex_tree<> simplexTree; + void erase_max(const Simplex& sigma) { + if (membership(sigma)) simplexTree.remove_maximal_simplex(simplexTree.find(sigma)); + } }; - int n = 300; int nb_insert_simplex1 = 3000; @@ -54,76 +69,69 @@ int nb_contraction = 300; int nb_insert_simplex2 = 3000; int nb_membership2 = 400000; -Simplex random_simplex(int n, std::size_t 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; +Simplex random_simplex(int n, std::size_t 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 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 < m; i++) v.push_back(random_simplex(n, dis(gen))); + return v; } -template -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 = 1; 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(); - - if (c3 > 0) - std::cout << c1 << "\t \t" << c2 << "\t \t" << c3 << "\t \t" << K.num_maximal_simplices() << std::endl; - else - std::cout << c1 << "\t \t" << c2 << "\t \tN/A\t \t" << K.num_maximal_simplices() << std::endl; +template +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 = 1; 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(); + + if (c3 > 0) + std::cout << c1 << "\t \t" << c2 << "\t \t" << c3 << "\t \t" << K.num_maximal_simplices() << std::endl; + else + std::cout << c1 << "\t \t" << c2 << "\t \tN/A\t \t" << K.num_maximal_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; +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