diff options
author | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2020-04-06 23:40:29 +0200 |
---|---|---|
committer | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2020-04-06 23:40:29 +0200 |
commit | 599e910811e1c4c743a61be65e089e798f578d4a (patch) | |
tree | 67114c4b856850b462c8cd0996119ee5da89f051 /src/Collapse/include | |
parent | 076cc203005373ddcb58055af3db604240157601 (diff) |
Remove rips edge list first part
Diffstat (limited to 'src/Collapse/include')
-rw-r--r-- | src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h b/src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h index 786a970a..d7014f2f 100644 --- a/src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h +++ b/src/Collapse/include/gudhi/Flag_complex_sparse_matrix.h @@ -12,8 +12,15 @@ #define FLAG_COMPLEX_SPARSE_MATRIX_H_ #include <gudhi/Rips_edge_list.h> +#include <gudhi/graph_simplicial_complex.h> + #include <boost/functional/hash.hpp> -// #include <boost/graph/adjacency_list.hpp> + +#include <Eigen/Sparse> + +#ifdef GUDHI_USE_TBB +#include <tbb/parallel_sort.h> +#endif #include <iostream> #include <utility> @@ -28,8 +35,6 @@ #include <ctime> #include <fstream> -#include <Eigen/Sparse> - typedef std::size_t Vertex; using Edge = std::pair<Vertex, Vertex>; // This is an ordered pair, An edge is stored with convention of the first // element being the smaller i.e {2,3} not {3,2}. However this is at the level @@ -319,6 +324,35 @@ class Flag_complex_sparse_matrix { } } + template<typename OneSkeletonGraph> + Flag_complex_sparse_matrix(const OneSkeletonGraph& one_skeleton_graph) + : rows(0), + edgeCollapsed(false) { + // Insert all vertices + for (auto v_it = boost::vertices(one_skeleton_graph); v_it.first != v_it.second; ++v_it.first) { + vertices.emplace(*(v_it.first)); + } + // Insert all edges + for (auto edge_it = boost::edges(one_skeleton_graph); + edge_it.first != edge_it.second; ++edge_it.first) { + auto edge = *(edge_it.first); + Vertex u = source(edge, one_skeleton_graph); + Vertex v = target(edge, one_skeleton_graph); + f_edge_vector.push_back({{u, v}, boost::get(Gudhi::edge_filtration_t(), one_skeleton_graph, edge)}); + } + // Sort edges + auto sort_by_filtration = [](const EdgeFilt& edge_a, const EdgeFilt& edge_b) -> bool + { + return (get<1>(edge_a) < get<1>(edge_b)); + }; + +#ifdef GUDHI_USE_TBB + tbb::parallel_sort(f_edge_vector.begin(), f_edge_vector.end(), sort_by_filtration); +#else + std::stable_sort(f_edge_vector.begin(), f_edge_vector.end(), sort_by_filtration); +#endif + } + // Performs edge collapse in a decreasing sequence of the filtration value. Filtered_sorted_edge_list filtered_edge_collapse() { std::size_t endIdx = 0; |