summaryrefslogtreecommitdiff
path: root/src/Simplex_tree/example/graph_expansion_with_blocker.cpp
blob: df52bf4333600948380dd9e80d20899ba623cdde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*    This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
 *    See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
 *    Author(s):       Vincent Rouvreau
 *
 *    Copyright (C) 2014 Inria
 *
 *    Modification(s):
 *      - YYYY/MM Author: Description of the modification
 */

#include <gudhi/Simplex_tree.h>

#include <iostream>

using Simplex_tree = Gudhi::Simplex_tree<>;
using Simplex_handle = Simplex_tree::Simplex_handle;

int main(int argc, char* const argv[]) {
  // Construct the Simplex Tree with a 1-skeleton graph example
  Simplex_tree stree;

  stree.insert_simplex({0, 1}, 0.);
  stree.insert_simplex({0, 2}, 1.);
  stree.insert_simplex({0, 3}, 2.);
  stree.insert_simplex({1, 2}, 3.);
  stree.insert_simplex({1, 3}, 4.);
  stree.insert_simplex({2, 3}, 5.);
  stree.insert_simplex({2, 4}, 6.);
  stree.insert_simplex({3, 6}, 7.);
  stree.insert_simplex({4, 5}, 8.);
  stree.insert_simplex({4, 6}, 9.);
  stree.insert_simplex({5, 6}, 10.);
  stree.insert_simplex({6}, 10.);

  stree.expansion_with_blockers(3, [&](Simplex_handle sh) {
    bool result = false;
    std::clog << "Blocker on [";
    // User can loop on the vertices from the given simplex_handle i.e.
    for (auto vertex : stree.simplex_vertex_range(sh)) {
      // We block the expansion, if the vertex '6' is in the given list of vertices
      if (vertex == 6) result = true;
      std::clog << vertex << ", ";
    }
    std::clog << "] ( " << stree.filtration(sh);
    // User can re-assign a new filtration value directly in the blocker (default is the maximal value of boudaries)
    stree.assign_filtration(sh, stree.filtration(sh) + 1.);

    std::clog << " + 1. ) = " << result << std::endl;

    return result;
  });

  std::clog << "********************************************************************\n";
  std::clog << "* The complex contains " << stree.num_simplices() << " simplices";
  std::clog << "   - dimension " << stree.dimension() << "\n";
  std::clog << "* Iterator on Simplices in the filtration, with [filtration value]:\n";
  for (auto f_simplex : stree.filtration_simplex_range()) {
    std::clog << "   "
              << "[" << stree.filtration(f_simplex) << "] ";
    for (auto vertex : stree.simplex_vertex_range(f_simplex)) std::clog << "(" << vertex << ")";
    std::clog << std::endl;
  }

  return 0;
}