summaryrefslogtreecommitdiff
path: root/src/Toplex_map
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-10-16 13:57:50 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-10-16 13:57:50 +0000
commitc71dce7fe646cd4ca4da5f385cb0d97535e4d941 (patch)
tree237d99233a51b3707d5880a9e81e07280442c31a /src/Toplex_map
parentc882b0478d4b0899005bf6c0e9528a1fc8785cf9 (diff)
Add lazy_toplex_map_unit_test
Class documentation rewrite Fix conventions in code git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3956 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 65f79ee3c0f22157b2cedfc498e5d9c97dd055f6
Diffstat (limited to 'src/Toplex_map')
-rw-r--r--src/Toplex_map/benchmark/chrono.cpp5
-rw-r--r--src/Toplex_map/include/gudhi/Lazy_Toplex_map.h123
-rw-r--r--src/Toplex_map/include/gudhi/Toplex_map.h13
-rw-r--r--src/Toplex_map/test/CMakeLists.txt5
-rw-r--r--src/Toplex_map/test/lazy_toplex_map_unit_test.cpp78
-rw-r--r--src/Toplex_map/test/toplex_map_unit_test.cpp237
6 files changed, 253 insertions, 208 deletions
diff --git a/src/Toplex_map/benchmark/chrono.cpp b/src/Toplex_map/benchmark/chrono.cpp
index de6d701f..e6172c61 100644
--- a/src/Toplex_map/benchmark/chrono.cpp
+++ b/src/Toplex_map/benchmark/chrono.cpp
@@ -107,7 +107,10 @@ void chrono(int n, int d){
end = std::chrono::system_clock::now();
auto c2 = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
- std::cout << c1 << "\t \t" << c2 << "\t \t" << c3 << "\t \t" << K.num_maximal_simplices() << std::endl;
+ 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(){
diff --git a/src/Toplex_map/include/gudhi/Lazy_Toplex_map.h b/src/Toplex_map/include/gudhi/Lazy_Toplex_map.h
index 434fea47..5461c0a3 100644
--- a/src/Toplex_map/include/gudhi/Lazy_Toplex_map.h
+++ b/src/Toplex_map/include/gudhi/Lazy_Toplex_map.h
@@ -6,84 +6,90 @@
namespace Gudhi {
-/** A Lazy_Toplex_map represents the simplicial complex.
- * A "toplex" is a maximal simplex but not all simplices in a LTM are toplices.
- * \ingroup toplex_map */
+/**
+ * \brief Lazy toplex map data structure for representing unfiltered simplicial complexes.
+ *
+ * \details A Toplex_map is an unordered map from vertices to maximal simplices (aka. toplices).
+ * The lazy version is not always up to date as it requires clean operation in order to be.
+ *
+ * \ingroup toplex_map */
class Lazy_Toplex_map {
public:
+ /** Vertex is the type of vertices. */
+ using Vertex = Toplex_map::Vertex;
- /** Vertex is the type of vertices. */
- typedef Toplex_map::Vertex Vertex;
+ /** Simplex is the type of simplices. */
+ using Simplex = Toplex_map::Simplex;
- /** Simplex is the type of simplices. */
- typedef Toplex_map::Simplex Simplex;
+ /** The type of the pointers to maximal simplices. */
+ using Simplex_ptr = Toplex_map::Simplex_ptr;
- /** The type of the pointers to maximal simplices. */
- typedef Toplex_map::Simplex_ptr Simplex_ptr;
+ /** The type of the sets of Simplex_ptr. */
+ using Simplex_ptr_set = Toplex_map::Simplex_ptr_set;
- /** The type of the sets of Simplex_ptr. */
- typedef Toplex_map::Simplex_ptr_set Simplex_ptr_set;
+ /** Adds the given simplex to the complex.
+ * The simplex must not have maximal coface in the complex. */
+ template <typename Input_vertex_range>
+ void insert_independent_simplex(const Input_vertex_range &vertex_range);
- /** Adds the given simplex to the complex.
- * The simplex must not have maximal coface in the complex. */
- template <typename Input_vertex_range>
- void insert_independent_simplex(const Input_vertex_range &vertex_range);
+ /** \brief Adds the given simplex to the complex.
+ * Nothing happens if the simplex has a coface in the complex. */
+ template <typename Input_vertex_range>
+ bool insert_simplex(const Input_vertex_range &vertex_range);
- /** \brief Adds the given simplex to the complex.
- * Nothing happens if the simplex has a coface in the complex. */
- template <typename Input_vertex_range>
- bool 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 <typename Input_vertex_range>
+ void remove_simplex(const Input_vertex_range &vertex_range);
- /** \brief Removes the given simplex and its cofaces from the complex.
- * Its faces are kept inside. */
- template <typename Input_vertex_range>
- void remove_simplex(const Input_vertex_range &vertex_range);
+ /** Does a simplex belong to the complex ? */
+ template <typename Input_vertex_range>
+ bool membership(const Input_vertex_range &vertex_range);
- /** Does a simplex belong to the complex ? */
- template <typename Input_vertex_range>
- bool membership(const Input_vertex_range &vertex_range);
+ /** Do all the facets of a simplex belong to the complex ? */
+ template <typename Input_vertex_range>
+ bool all_facets_inside(const Input_vertex_range &vertex_range);
- /** Do all the facets of a simplex belong to the complex ? */
- template <typename Input_vertex_range>
- bool all_facets_inside(const Input_vertex_range &vertex_range);
+ /** Contracts one edge in the complex.
+ * The edge has to verify the link condition if you want to preserve topology.
+ * Returns the remaining vertex. */
+ Vertex contraction(const Vertex x, const Vertex y);
- /** Contracts one edge in the complex.
- * The edge has to verify the link condition if you want to preserve topology.
- * Returns the remaining vertex. */
- Vertex contraction(const Vertex x, const Vertex y);
-
- /** \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 size;
+ }
/** \brief Number of vertices. */
std::size_t num_vertices() const{
return t0.size();
}
- std::unordered_map<Vertex, std::size_t> gamma0_lbounds;
private:
- template <typename Input_vertex_range>
- void erase_max(const Input_vertex_range &vertex_range);
- template <typename Input_vertex_range>
- Vertex best_index(const Input_vertex_range &vertex_range);
- void clean(const Vertex v);
+ template <typename Input_vertex_range>
+ void erase_max(const Input_vertex_range &vertex_range);
+ template <typename Input_vertex_range>
+ Vertex best_index(const Input_vertex_range &vertex_range);
+ void clean(const Vertex v);
+
+ std::unordered_map<Vertex, std::size_t> gamma0_lbounds;
- std::unordered_map<Vertex, Simplex_ptr_set> t0;
- bool empty_toplex; // Is the empty simplex a toplex ?
+ std::unordered_map<Vertex, Simplex_ptr_set> t0;
+ bool empty_toplex; // Is the empty simplex a toplex ?
- typedef boost::heap::fibonacci_heap<std::pair<std::size_t,Vertex>> PriorityQueue;
- PriorityQueue cleaning_priority;
- std::unordered_map<Vertex, PriorityQueue::handle_type> cp_handles;
+ typedef boost::heap::fibonacci_heap<std::pair<std::size_t,Vertex>> PriorityQueue;
+ PriorityQueue cleaning_priority;
+ std::unordered_map<Vertex, PriorityQueue::handle_type> cp_handles;
- std::size_t get_gamma0_lbound(const Vertex v) const;
+ std::size_t get_gamma0_lbound(const Vertex v) const;
- std::size_t size_lbound = 0;
- std::size_t size = 0;
+ std::size_t size_lbound = 0;
+ std::size_t size = 0;
- const double alpha = 4; //time
- const double betta = 8; //memory
+ const double ALPHA = 4; //time
+ const double BETTA = 8; //memory
};
template <typename Input_vertex_range>
@@ -112,7 +118,7 @@ bool Lazy_Toplex_map::insert_simplex(const Input_vertex_range &vertex_range){
}
if(inserted)
size++;
- if(size > (size_lbound+1) * betta)
+ if(size > (size_lbound+1) * BETTA)
clean(cleaning_priority.top().second);
return inserted;
}
@@ -167,7 +173,7 @@ bool Lazy_Toplex_map::all_facets_inside(const Input_vertex_range &vertex_range){
}
/* Returns the remaining vertex */
-Toplex_map::Vertex Lazy_Toplex_map::contraction(const Vertex x, const Vertex y){
+Lazy_Toplex_map::Vertex Lazy_Toplex_map::contraction(const Vertex x, const Vertex y){
if(!t0.count(x)) return y;
if(!t0.count(y)) return x;
Vertex k, d;
@@ -204,14 +210,14 @@ inline void Lazy_Toplex_map::erase_max(const Input_vertex_range &vertex_range){
}
template <typename Input_vertex_range>
-Toplex_map::Vertex Lazy_Toplex_map::best_index(const Input_vertex_range &vertex_range){
+Lazy_Toplex_map::Vertex Lazy_Toplex_map::best_index(const Input_vertex_range &vertex_range) {
Simplex tau(vertex_range.begin(),vertex_range.end());
std::size_t min = std::numeric_limits<size_t>::max(); Vertex arg_min = -1;
for(const Vertex& v : tau)
if(!t0.count(v)) return v;
else if(t0.at(v).size() < min)
min = t0.at(v).size(), arg_min = v;
- if(min > alpha * get_gamma0_lbound(arg_min))
+ if(min > ALPHA * get_gamma0_lbound(arg_min))
clean(arg_min);
return arg_min;
}
@@ -220,7 +226,6 @@ std::size_t Lazy_Toplex_map::get_gamma0_lbound(const Vertex v) const{
return gamma0_lbounds.count(v) ? gamma0_lbounds.at(v) : 0;
}
-
void Lazy_Toplex_map::clean(const Vertex v){
Toplex_map toplices;
std::unordered_map<int, std::vector<Simplex>> dsorted_simplices;
@@ -246,10 +251,6 @@ void Lazy_Toplex_map::clean(const Vertex v){
insert_simplex(*sptr);
}
-std::size_t Lazy_Toplex_map::num_maximal_simplices() const{
- return size;
-}
-
} //namespace Gudhi
#endif /* LAZY_TOPLEX_MAP_H */
diff --git a/src/Toplex_map/include/gudhi/Toplex_map.h b/src/Toplex_map/include/gudhi/Toplex_map.h
index 7cde8ea1..b7a5db41 100644
--- a/src/Toplex_map/include/gudhi/Toplex_map.h
+++ b/src/Toplex_map/include/gudhi/Toplex_map.h
@@ -10,8 +10,11 @@
namespace Gudhi {
-/** A Toplex_map represents the simplicial complex.
- * A "toplex" is a maximal simplex.
+/**
+ * \brief Toplex map data structure for representing unfiltered simplicial complexes.
+ *
+ * \details A Toplex_map is an unordered map from vertices to maximal simplices (aka. toplices).
+ *
* \ingroup toplex_map */
class Toplex_map {
@@ -100,7 +103,7 @@ protected:
/** \internal The map from vertices to toplices */
std::unordered_map<Toplex_map::Vertex, Toplex_map::Simplex_ptr_set> t0;
- const Toplex_map::Vertex vertex_upper_bound = std::numeric_limits<Toplex_map::Vertex>::max();
+ const Toplex_map::Vertex VERTEX_UPPER_BOUND = std::numeric_limits<Toplex_map::Vertex>::max();
/** \internal Removes a toplex without adding facets after. */
void erase_maximal(const Toplex_map::Simplex_ptr& sptr);
@@ -258,7 +261,7 @@ void Toplex_map::remove_vertex(const Toplex_map::Vertex x){
inline void Toplex_map::erase_maximal(const Toplex_map::Simplex_ptr& sptr){
Simplex sigma(*sptr);
if (sptr->size()==0)
- sigma.insert(vertex_upper_bound);
+ sigma.insert(VERTEX_UPPER_BOUND);
for(const Toplex_map::Vertex& v : sigma){
t0.at(v).erase(sptr);
if(t0.at(v).size()==0) t0.erase(v);
@@ -268,7 +271,7 @@ inline void Toplex_map::erase_maximal(const Toplex_map::Simplex_ptr& sptr){
template <typename Input_vertex_range>
Toplex_map::Vertex Toplex_map::best_index(const Input_vertex_range &vertex_range) const{
std::size_t min = std::numeric_limits<size_t>::max();
- Vertex arg_min = vertex_upper_bound;
+ Vertex arg_min = VERTEX_UPPER_BOUND;
for(const Toplex_map::Vertex& v : vertex_range)
if(!t0.count(v)) return v;
else if(t0.at(v).size() < min)
diff --git a/src/Toplex_map/test/CMakeLists.txt b/src/Toplex_map/test/CMakeLists.txt
index 237cfdad..59517db5 100644
--- a/src/Toplex_map/test/CMakeLists.txt
+++ b/src/Toplex_map/test/CMakeLists.txt
@@ -4,5 +4,8 @@ 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})
-
gudhi_add_coverage_test(Toplex_map_unit_test)
+
+add_executable( Lazy_toplex_map_unit_test lazy_toplex_map_unit_test.cpp )
+target_link_libraries(Lazy_toplex_map_unit_test ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+gudhi_add_coverage_test(Lazy_toplex_map_unit_test)
diff --git a/src/Toplex_map/test/lazy_toplex_map_unit_test.cpp b/src/Toplex_map/test/lazy_toplex_map_unit_test.cpp
new file mode 100644
index 00000000..77d464ae
--- /dev/null
+++ b/src/Toplex_map/test/lazy_toplex_map_unit_test.cpp
@@ -0,0 +1,78 @@
+#include <iostream>
+#include <vector>
+#include <gudhi/Lazy_Toplex_map.h>
+
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "lazy toplex map"
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE(toplex_map) {
+ using Vertex = Gudhi::Lazy_Toplex_map::Vertex;
+
+ Gudhi::Lazy_Toplex_map tm;
+ std::cout << "insert_simplex {1, 2, 3, 4}" << std::endl;
+ std::vector<Vertex> sigma1 = {1, 2, 3, 4};
+ tm.insert_simplex(sigma1);
+ std::cout << "insert_simplex {5, 2, 3, 6}" << std::endl;
+ std::vector<Vertex> sigma2 = {5, 2, 3, 6};
+ tm.insert_simplex(sigma2);
+ std::cout << "insert_simplex {5}" << std::endl;
+ std::vector<Vertex> sigma3 = {5};
+ tm.insert_simplex(sigma3);
+ std::cout << "insert_simplex {4, 5, 3}" << std::endl;
+ std::vector<Vertex> sigma6 = {4, 5, 3};
+ tm.insert_simplex(sigma6);
+ std::cout << "insert_simplex {4, 5, 9}" << std::endl;
+ std::vector<Vertex> sigma7 = {4, 5, 9};
+ tm.insert_simplex(sigma7);
+
+ std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl;
+ BOOST_CHECK(tm.num_maximal_simplices() == 5);
+
+ std::vector<Vertex> sigma4 = {5, 2, 3};
+ std::vector<Vertex> sigma5 = {5, 2, 7};
+ BOOST_CHECK(tm.membership(sigma4));
+ BOOST_CHECK(!tm.membership(sigma5));
+ std::cout << "insert_simplex {5, 2, 7}" << std::endl;
+ tm.insert_simplex(sigma5);
+
+ std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl;
+ BOOST_CHECK(tm.num_maximal_simplices() == 6);
+
+ BOOST_CHECK(tm.membership(sigma5));
+
+ std::cout << "contraction(4,5)" << std::endl;
+ auto r = tm.contraction(4,5);
+ std::cout << "r=" << r << std::endl;
+ BOOST_CHECK(r == 5);
+
+ std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl;
+ BOOST_CHECK(tm.num_maximal_simplices() == 6);
+
+ std::vector<Vertex> sigma8 = {1, 2, 3};
+ std::vector<Vertex> sigma9 = {2, 7};
+
+ sigma8.emplace_back(r);
+ sigma9.emplace_back(r);
+ BOOST_CHECK(!tm.membership(sigma6));
+ BOOST_CHECK(tm.membership(sigma8));
+ BOOST_CHECK(tm.membership(sigma9));
+
+ std::cout << "remove_simplex({2, 7, r = 5})" << std::endl;
+ tm.remove_simplex(sigma9);
+ BOOST_CHECK(!tm.membership(sigma9));
+
+ std::cout << "num_maximal_simplices = " << tm.num_maximal_simplices() << std::endl;
+ BOOST_CHECK(tm.num_maximal_simplices() == 8);
+
+ // {2, 7, 5} is removed, but verify its edges are still there
+ std::vector<Vertex> edge = {2, 7};
+ BOOST_CHECK(tm.membership(edge));
+ edge = {2, 5};
+ BOOST_CHECK(tm.membership(edge));
+ edge = {7, 5};
+ BOOST_CHECK(tm.membership(edge));
+
+}
+
diff --git a/src/Toplex_map/test/toplex_map_unit_test.cpp b/src/Toplex_map/test/toplex_map_unit_test.cpp
index 9ee5dff2..59c104ce 100644
--- a/src/Toplex_map/test/toplex_map_unit_test.cpp
+++ b/src/Toplex_map/test/toplex_map_unit_test.cpp
@@ -1,162 +1,119 @@
#include <iostream>
#include <vector>
-#include <gudhi/Lazy_Toplex_map.h>
+#include <gudhi/Toplex_map.h>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "toplex map"
#include <boost/test/unit_test.hpp>
-#include <boost/mpl/list.hpp>
-using list_of_tested_variants = boost::mpl::list<Gudhi::Toplex_map, Gudhi::Lazy_Toplex_map>;
-
-BOOST_AUTO_TEST_CASE_TEMPLATE(common_toplex_map_functionnalities, Toplex_map, list_of_tested_variants) {
- using Vertex = typename Toplex_map::Vertex;
+BOOST_AUTO_TEST_CASE(toplex_map) {
+ using Vertex = Gudhi::Toplex_map::Vertex;
+ Gudhi::Toplex_map tm;
+ std::cout << "insert_simplex {1, 2, 3, 4}" << std::endl;
std::vector<Vertex> sigma1 = {1, 2, 3, 4};
+ tm.insert_simplex(sigma1);
+ std::cout << "insert_simplex {5, 2, 3, 6}" << std::endl;
std::vector<Vertex> sigma2 = {5, 2, 3, 6};
+ tm.insert_simplex(sigma2);
+ std::cout << "insert_simplex {5}" << std::endl;
std::vector<Vertex> sigma3 = {5};
- std::vector<Vertex> sigma4 = {5, 2, 3};
- std::vector<Vertex> sigma5 = {5, 2, 7};
+ tm.insert_simplex(sigma3);
+ std::cout << "insert_simplex {4, 5, 3}" << std::endl;
std::vector<Vertex> sigma6 = {4, 5, 3};
+ tm.insert_simplex(sigma6);
+ std::cout << "insert_simplex {4, 5, 9}" << std::endl;
std::vector<Vertex> sigma7 = {4, 5, 9};
- std::vector<Vertex> 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 << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
-
- BOOST_CHECK(K.membership(sigma4));
- //BOOST_CHECK(!K.maximality(sigma3));
- BOOST_CHECK(!K.membership(sigma5));
- K.insert_simplex(sigma5);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
-
- BOOST_CHECK(K.membership(sigma5));
- std::vector<Vertex> sigma9 = {1, 2, 3};
- std::vector<Vertex> sigma10 = {2, 7};
- auto r = K.contraction(4,5);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
-
- 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));
-
-}
-
-BOOST_AUTO_TEST_CASE(toplex_map_num_maximal_simplices) {
- using Vertex = Gudhi::Toplex_map::Vertex;
-
- Gudhi::Toplex_map K;
- std::vector<Vertex> sigma1 = {1, 2, 3, 4};
- std::vector<Vertex> sigma2 = {5, 2, 3, 6};
- std::vector<Vertex> sigma3 = {4, 5, 3};
- std::vector<Vertex> sigma4 = {4, 5, 9};
- K.insert_simplex(sigma1);
- K.insert_simplex(sigma2);
- K.insert_simplex(sigma3);
- K.insert_simplex(sigma4);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 4);
-
- std::vector<Vertex> sigma5 = {5, 2, 7};
- K.insert_simplex(sigma5);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 5);
-
- auto r = K.contraction(4,5);
- std::cout << "r=" << r << std::endl;
- BOOST_CHECK(r == 5);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 4);
-
- std::vector<Vertex> sigma6 = {2, 7};
- K.remove_simplex(sigma6);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 4);
-
- K.remove_simplex(sigma2);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 6);
-}
-
-BOOST_AUTO_TEST_CASE(lazy_toplex_map_num_maximal_simplices) {
- using Vertex = Gudhi::Lazy_Toplex_map::Vertex;
-
- Gudhi::Lazy_Toplex_map K;
- std::vector<Vertex> sigma1 = {1, 2, 3, 4};
- std::vector<Vertex> sigma2 = {5, 2, 3, 6};
- std::vector<Vertex> sigma3 = {4, 5, 3};
- std::vector<Vertex> sigma4 = {4, 5, 9};
- K.insert_simplex(sigma1);
- K.insert_simplex(sigma2);
- K.insert_simplex(sigma3);
- K.insert_simplex(sigma4);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 4);
+ tm.insert_simplex(sigma7);
+
+ std::cout << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl;
+ BOOST_CHECK(tm.num_maximal_simplices() == 4);
+ // 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;
+ BOOST_CHECK(tm.maximality(*simplex_ptr));
+ }
+
+ BOOST_CHECK(tm.maximality(sigma1));
+ BOOST_CHECK(tm.maximality(sigma2));
+ BOOST_CHECK(!tm.maximality(sigma3));
+ BOOST_CHECK(tm.maximality(sigma6));
+ BOOST_CHECK(tm.maximality(sigma7));
+ std::vector<Vertex> sigma4 = {5, 2, 3};
std::vector<Vertex> sigma5 = {5, 2, 7};
- K.insert_simplex(sigma5);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 5);
-
- auto r = K.contraction(4,5);
+ BOOST_CHECK(tm.membership(sigma4));
+ BOOST_CHECK(!tm.membership(sigma5));
+ std::cout << "insert_simplex {5, 2, 7}" << std::endl;
+ tm.insert_simplex(sigma5);
+
+ std::cout << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl;
+ BOOST_CHECK(tm.num_maximal_simplices() == 5);
+ // 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;
+ BOOST_CHECK(tm.maximality(*simplex_ptr));
+ }
+
+ BOOST_CHECK(tm.membership(sigma5));
+
+ std::cout << "contraction(4,5)" << std::endl;
+ auto r = tm.contraction(4,5);
std::cout << "r=" << r << std::endl;
BOOST_CHECK(r == 5);
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 5);
-
- std::vector<Vertex> sigma6 = {2, 7};
- K.remove_simplex(sigma6);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 6);
-
- K.remove_simplex(sigma2);
-
- std::cout << "num_maximal_simplices" << K.num_maximal_simplices() << std::endl;
- BOOST_CHECK(K.num_maximal_simplices() == 9);
-
-}
-
-BOOST_AUTO_TEST_CASE(toplex_map_maximality) {
- using Vertex = Gudhi::Toplex_map::Vertex;
+ std::cout << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl;
+ BOOST_CHECK(tm.num_maximal_simplices() == 4);
+ // 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;
+ BOOST_CHECK(tm.maximality(*simplex_ptr));
+ }
+
+ std::vector<Vertex> sigma8 = {1, 2, 3};
+ std::vector<Vertex> sigma9 = {2, 7};
+
+ sigma8.emplace_back(r);
+ sigma9.emplace_back(r);
+ BOOST_CHECK(!tm.membership(sigma6));
+ BOOST_CHECK(tm.membership(sigma8));
+ BOOST_CHECK(tm.membership(sigma9));
+
+ std::cout << "remove_simplex({2, 7, r = 5})" << std::endl;
+ tm.remove_simplex(sigma9);
+ BOOST_CHECK(!tm.membership(sigma9));
+
+ std::cout << "num_maximal_simplices" << tm.num_maximal_simplices() << std::endl;
+ BOOST_CHECK(tm.num_maximal_simplices() == 5);
+ // 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;
+ BOOST_CHECK(tm.maximality(*simplex_ptr));
+ }
+ // {2, 7, 5} is removed, but verify its edges are still there
+ std::vector<Vertex> edge = {2, 7};
+ BOOST_CHECK(tm.membership(edge));
+ edge = {2, 5};
+ BOOST_CHECK(tm.membership(edge));
+ edge = {7, 5};
+ BOOST_CHECK(tm.membership(edge));
- std::vector<Vertex> sigma1 = {1, 2, 3, 4};
- std::vector<Vertex> sigma2 = {5, 2, 3, 6};
- std::vector<Vertex> sigma3 = {5};
- std::vector<Vertex> sigma4 = {4, 5, 3};
- std::vector<Vertex> sigma5 = {4, 5, 9};
-
- 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));
}