11#ifndef PERMUTAHEDRAL_REPRESENTATION_PERMUTAHEDRAL_REPRESENTATION_ITERATORS_H_
12#define PERMUTAHEDRAL_REPRESENTATION_PERMUTAHEDRAL_REPRESENTATION_ITERATORS_H_
14#include <gudhi/Permutahedral_representation/Size_range.h>
15#include <gudhi/Permutahedral_representation/Ordered_set_partition_iterator.h>
16#include <gudhi/Permutahedral_representation/Integer_combination_iterator.h>
17#include <gudhi/Permutahedral_representation/Combination_iterator.h>
18#include <gudhi/Permutahedral_representation/face_from_indices.h>
19#include <boost/iterator/iterator_facade.hpp>
27namespace coxeter_triangulation {
38template <
class Permutahedral_representation>
40 :
public boost::iterator_facade<Vertex_iterator<Permutahedral_representation>,
41 typename Permutahedral_representation::Vertex const, boost::forward_traversal_tag> {
43 friend class boost::iterator_core_access;
48 using value_t = Vertex;
50 bool equal(
Vertex_iterator const& other)
const {
return (is_end_ && other.is_end_); }
52 value_t
const& dereference()
const {
return value_; }
55 std::size_t d = value_.size();
60 for (std::size_t j = 0; j < d; j++) value_[j]--;
66 if (++o_it_ == o_end_) is_end_ =
true;
74 is_end_(o_it_ == o_end_) {}
79 typename Ordered_partition::const_iterator o_it_, o_end_;
90template <
class Permutahedral_representation>
91class Face_iterator :
public boost::iterator_facade<Face_iterator<Permutahedral_representation>,
92 Permutahedral_representation const, boost::forward_traversal_tag> {
96 friend class boost::iterator_core_access;
101 bool equal(
Face_iterator const& other)
const {
return (is_end_ && other.is_end_); }
103 value_t const& dereference()
const {
return value_; }
106 if (++c_it_ == c_end_) {
113 void update_value() {
115 value_ = face_from_indices<Permutahedral_representation>(simplex_, *c_it_);
123 c_it_(l_ + 1, k_ + 1),
125 value_({Vertex(simplex.
vertex().size()), Ordered_partition(k + 1)}) {
148template <
class Permutahedral_representation>
150 :
public boost::iterator_facade<Coface_iterator<Permutahedral_representation>, Permutahedral_representation const,
151 boost::forward_traversal_tag> {
155 friend class boost::iterator_core_access;
160 bool equal(
Coface_iterator const& other)
const {
return (is_end_ && other.is_end_); }
162 value_t const& dereference()
const {
return value_; }
166 for (; i < k_ + 1; i++) {
167 if (++(o_its_[i]) != o_end_)
break;
170 if (++i_it_ == i_end_) {
175 for (uint j = 0; j < k_ + 1; j++)
176 o_its_.emplace_back(simplex_.
partition()[j].size(), (*i_it_)[j] + 1);
178 for (uint j = 0; j < i; j++) o_its_[j].reinitialize();
182 void update_value() {
184 for (
auto& p : value_.
partition()) p.clear();
186 for (; u_ <= (*i_it_)[k_]; u_++) {
187 auto range = (*o_its_[k_])[u_];
188 if (std::find(range.begin(), range.end(), t_) != range.end())
break;
191 for (uint j = u_ + 1; j <= (*i_it_)[k_]; j++, i++)
192 for (uint b : (*o_its_[k_])[j]) {
197 for (uint h = 0; h < k_; h++)
198 for (uint j = 0; j <= (*i_it_)[h]; j++, i++) {
199 for (uint b : (*o_its_[h])[j]) value_.
partition()[i].push_back(simplex_.
partition()[h][b]);
201 for (uint j = 0; j <= u_; j++, i++)
202 for (uint b : (*o_its_[k_])[j]) value_.
partition()[i].push_back(simplex_.
partition()[k_][b]);
204 for (
auto& part : value_.
partition()) std::sort(part.begin(), part.end());
210 d_(simplex.
vertex().size()),
213 i_it_(l_ - k_, k_ + 1, Size_range<Ordered_partition>(simplex.
partition())),
215 value_({Vertex(d_), Ordered_partition(l_ + 1)}) {
217 for (; j < simplex_.
partition()[k_].size(); j++)
222 if (j == simplex_.
partition()[k_].size()) {
223 std::cerr <<
"Coface iterator: the argument simplex is not a permutahedral representation\n";
227 for (uint i = 0; i < k_ + 1; i++)
228 o_its_.emplace_back(simplex_.
partition()[i].size(), (*i_it_)[i] + 1);
242 std::vector<Ordered_set_partition_iterator> o_its_;
Iterator over the k-cofaces of a simplex given by its permutahedral representation.
Definition: Permutahedral_representation_iterators.h:151
Class that allows the user to generate combinations of k elements in a set of n elements....
Definition: Combination_iterator.h:28
Iterator over the k-faces of a simplex given by its permutahedral representation.
Definition: Permutahedral_representation_iterators.h:92
Class that allows the user to generate combinations of k elements in a set of n elements....
Definition: Integer_combination_iterator.h:29
Class that allows the user to generate set partitions of a set {0,...,n-1} in k parts.
Definition: Ordered_set_partition_iterator.h:49
A class that stores the permutahedral representation of a simplex in a Coxeter triangulation or a Fre...
Definition: Permutahedral_representation.h:38
Vertex & vertex()
Lexicographically-minimal vertex.
Definition: Permutahedral_representation.h:68
std::size_t dimension() const
Dimension of the simplex.
Definition: Permutahedral_representation.h:65
OrderedSetPartition & partition()
Ordered set partition.
Definition: Permutahedral_representation.h:74
Ordered_set_partition_ OrderedSetPartition
Type of the ordered partition.
Definition: Permutahedral_representation.h:46
Vertex_ Vertex
Type of the vertex.
Definition: Permutahedral_representation.h:43
Iterator over the vertices of a simplex represented by its permutahedral representation.
Definition: Permutahedral_representation_iterators.h:41
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14