summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2019-02-04 08:55:50 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2019-02-04 08:55:50 +0000
commitea4373870233488ece0a38b9eb97b23e50945d71 (patch)
tree7e631f7771bcc8da50c44953bc1fe8acb65eb499 /src/common
parent644076d6f2de7d91a7694c94261c59da14264cd5 (diff)
parent2905296b253588bd43de924d44585f9bfbd45540 (diff)
Merge last trunk modifications
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/cubical_complex_small_fix@4088 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 422db01787f7c105092e7f12b023a7a8e1f7d316
Diffstat (limited to 'src/common')
-rw-r--r--src/common/benchmark/CMakeLists.txt3
-rw-r--r--src/common/benchmark/Graph_simplicial_complex_benchmark.cpp150
-rw-r--r--src/common/include/gudhi/graph_simplicial_complex.h2
-rw-r--r--src/common/include/gudhi/reader_utils.h4
4 files changed, 156 insertions, 3 deletions
diff --git a/src/common/benchmark/CMakeLists.txt b/src/common/benchmark/CMakeLists.txt
new file mode 100644
index 00000000..a3787d6e
--- /dev/null
+++ b/src/common/benchmark/CMakeLists.txt
@@ -0,0 +1,3 @@
+project(common_benchmark)
+
+add_executable(Graph_simplicial_complex_benchmark Graph_simplicial_complex_benchmark.cpp)
diff --git a/src/common/benchmark/Graph_simplicial_complex_benchmark.cpp b/src/common/benchmark/Graph_simplicial_complex_benchmark.cpp
new file mode 100644
index 00000000..825d6cb5
--- /dev/null
+++ b/src/common/benchmark/Graph_simplicial_complex_benchmark.cpp
@@ -0,0 +1,150 @@
+/* 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) 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <gudhi/graph_simplicial_complex.h>
+#include <gudhi/distance_functions.h>
+#include <gudhi/Simplex_tree.h>
+#include <gudhi/Clock.h>
+#include <gudhi/Points_off_io.h>
+
+#include <boost/graph/adjacency_list.hpp>
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <limits> // for numeric limits
+#include <fstream>
+#include <cassert>
+
+
+std::ofstream results_csv("results.csv");
+
+template< typename Adjacency_list, typename ForwardPointRange, typename Distance >
+Adjacency_list proximity_graph_computation(const ForwardPointRange& points, double threshold, Distance distance) {
+ std::vector<std::pair< int, int >> edges;
+ std::vector< double > edges_fil;
+ std::map< int, double > vertices;
+
+ int idx_u, idx_v;
+ double fil;
+ idx_u = 0;
+ for (auto it_u = points.begin(); it_u != points.end(); ++it_u) {
+ idx_v = idx_u + 1;
+ for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) {
+ fil = distance(*it_u, *it_v);
+ if (fil <= threshold) {
+ edges.emplace_back(idx_u, idx_v);
+ edges_fil.push_back(fil);
+ }
+ }
+ ++idx_u;
+ }
+
+ // Points are labeled from 0 to idx_u-1
+ Adjacency_list skel_graph(edges.begin(), edges.end(), edges_fil.begin(), idx_u);
+
+ auto vertex_prop = boost::get(Gudhi::vertex_filtration_t(), skel_graph);
+
+ typename boost::graph_traits<Adjacency_list>::vertex_iterator vi, vi_end;
+ for (std::tie(vi, vi_end) = boost::vertices(skel_graph);
+ vi != vi_end; ++vi) {
+ boost::put(vertex_prop, *vi, 0.);
+ }
+
+ return skel_graph;
+}
+
+template <typename Adjacency_list>
+void benchmark_proximity_graph(const std::string& msg, const std::string& off_file_name) {
+ Gudhi::Points_off_reader<std::vector<double>> off_reader(off_file_name);
+ assert(off_reader.is_valid());
+
+ std::cout << "+ " << msg << std::endl;
+
+ results_csv << "\"nb_points\";"
+ << "\"nb_simplices\";"
+ << "\"compute proximity graph(sec.)\";"
+ << "\"complex_creation_time(sec.)\";"
+ << "\"" << msg << "\";" << std::endl;
+
+ Gudhi::Clock pg_compute_proximity_graph(" benchmark_proximity_graph - compute proximity graph");
+ pg_compute_proximity_graph.begin();
+ // benchmark begin
+ Adjacency_list proximity_graph = proximity_graph_computation<Adjacency_list>(off_reader.get_point_cloud(),
+ std::numeric_limits<double>::infinity(),
+ Gudhi::Euclidean_distance());
+ // benchmark end
+ pg_compute_proximity_graph.end();
+ std::cout << pg_compute_proximity_graph;
+
+ Gudhi::Simplex_tree<> complex;
+ Gudhi::Clock st_create_clock(" benchmark_proximity_graph - complex creation");
+ st_create_clock.begin();
+ // benchmark begin
+ complex.insert_graph(proximity_graph);
+ // benchmark end
+ st_create_clock.end();
+ std::cout << st_create_clock;
+
+ results_csv << off_reader.get_point_cloud().size() << ";" << complex.num_simplices() << ";"
+ << pg_compute_proximity_graph.num_seconds() << ";"
+ << st_create_clock.num_seconds() << ";" << std::endl;
+
+ std::cout << " benchmark_proximity_graph - nb simplices = " << complex.num_simplices() << std::endl;
+}
+
+int main(int argc, char * const argv[]) {
+ std::string off_file_name(argv[1]);
+
+ // The fastest, the less memory used
+ using vecSdirectedS = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
+ boost::property<Gudhi::vertex_filtration_t, double>,
+ boost::property<Gudhi::edge_filtration_t, double>>;
+ benchmark_proximity_graph<vecSdirectedS>("vecSdirectedS", off_file_name);
+
+ using vecSundirectedS = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
+ boost::property<Gudhi::vertex_filtration_t, double>,
+ boost::property<Gudhi::edge_filtration_t, double>>;
+ benchmark_proximity_graph<vecSundirectedS>("vecSundirectedS", off_file_name);
+
+ using vecSbidirectionalS = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
+ boost::property<Gudhi::vertex_filtration_t, double>,
+ boost::property<Gudhi::edge_filtration_t, double>>;
+ benchmark_proximity_graph<vecSbidirectionalS>("vecSbidirectionalS", off_file_name);
+
+ using setSdirectedS = boost::adjacency_list<boost::setS, boost::vecS, boost::directedS,
+ boost::property<Gudhi::vertex_filtration_t, double>,
+ boost::property<Gudhi::edge_filtration_t, double>>;
+ benchmark_proximity_graph<setSdirectedS>("setSdirectedS", off_file_name);
+
+ using setSundirectedS = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS,
+ boost::property<Gudhi::vertex_filtration_t, double>,
+ boost::property<Gudhi::edge_filtration_t, double>>;
+ benchmark_proximity_graph<setSundirectedS>("setSundirectedS", off_file_name);
+
+ using setSbidirectionalS = boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS,
+ boost::property<Gudhi::vertex_filtration_t, double>,
+ boost::property<Gudhi::edge_filtration_t, double>>;
+ benchmark_proximity_graph<setSbidirectionalS>("setSbidirectionalS", off_file_name);
+
+ return 0;
+}
diff --git a/src/common/include/gudhi/graph_simplicial_complex.h b/src/common/include/gudhi/graph_simplicial_complex.h
index 49fe56cc..0d81ca71 100644
--- a/src/common/include/gudhi/graph_simplicial_complex.h
+++ b/src/common/include/gudhi/graph_simplicial_complex.h
@@ -49,7 +49,7 @@ struct vertex_filtration_t {
*
*/
template <typename SimplicialComplexForProximityGraph>
-using Proximity_graph = typename boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS
+using Proximity_graph = typename boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS
, boost::property < vertex_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >
, boost::property < edge_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >>;
diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h
index 26eeb76d..0ee7649d 100644
--- a/src/common/include/gudhi/reader_utils.h
+++ b/src/common/include/gudhi/reader_utils.h
@@ -172,10 +172,10 @@ bool read_simplex(std::istream& in_, std::vector<Vertex_handle>& simplex, Filtra
if (!(in_ >> dim)) return false;
Vertex_handle v;
for (int i = 0; i < dim + 1; ++i) {
- in_ >> v;
+ if (!(in_ >> v)) return false;
simplex.push_back(v);
}
- in_ >> fil;
+ if (!(in_ >> fil)) return false;
in_.ignore((std::numeric_limits<std::streamsize>::max)(), '\n'); // ignore until the carriage return
return true;
}