Loading...
Searching...
No Matches
Permutahedral_representation.h
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Siargey Kachanovich
4 *
5 * Copyright (C) 2019 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef PERMUTAHEDRAL_REPRESENTATION_H_
12#define PERMUTAHEDRAL_REPRESENTATION_H_
13
14#include <gudhi/Permutahedral_representation/Permutahedral_representation_iterators.h>
15
16#include <utility> // for std::make_pair
17
18namespace Gudhi {
19
20namespace coxeter_triangulation {
21
37template <class Vertex_, class Ordered_set_partition_>
40
41 public:
43 typedef Vertex_ Vertex;
44
46 typedef Ordered_set_partition_ OrderedSetPartition;
47
57 : vertex_(vertex), partition_(partition) {}
58
63
65 std::size_t dimension() const { return partition_.size() - 1; }
66
68 Vertex& vertex() { return vertex_; }
69
71 const Vertex& vertex() const { return vertex_; }
72
74 OrderedSetPartition& partition() { return partition_; }
75
77 const OrderedSetPartition& partition() const { return partition_; }
78
82 bool operator==(const Permutahedral_representation& other) const {
83 if (dimension() != other.dimension()) return false;
84 if (vertex_ != other.vertex_) return false;
85 for (std::size_t k = 0; k < partition_.size(); ++k)
86 if (partition_[k] != other.partition_[k]) return false;
87 return true;
88 }
89
93 bool operator!=(const Permutahedral_representation& other) const { return !(*this == other); }
94
96 typedef boost::iterator_range<Vertex_iterator> Vertex_range;
100 Vertex_range vertex_range() const { return Vertex_range(Vertex_iterator(*this), Vertex_iterator()); }
101
103 typedef boost::iterator_range<Face_iterator> Face_range;
107 Face_range face_range(std::size_t value_dim) const {
108 return Face_range(Face_iterator(*this, value_dim), Face_iterator());
109 }
110
114 Face_range facet_range() const { return Face_range(Face_iterator(*this, dimension() - 1), Face_iterator()); }
115
117 typedef boost::iterator_range<Coface_iterator> Coface_range;
122 Coface_range coface_range(std::size_t value_dim) const {
123 return Coface_range(Coface_iterator(*this, value_dim), Coface_iterator());
124 }
125
129 Coface_range cofacet_range() const {
130 return Coface_range(Coface_iterator(*this, dimension() + 1), Coface_iterator());
131 }
132
137 bool is_face_of(const Permutahedral_representation& other) const {
138 using Part = typename OrderedSetPartition::value_type;
139
140 if (other.dimension() < dimension()) return false;
141 if (other.vertex_.size() != vertex_.size())
142 std::cerr << "Error: Permutahedral_representation::is_face_of: incompatible ambient dimensions.\n";
143
144 Vertex v_self = vertex_, v_other = other.vertex_;
145 auto self_partition_it = partition_.begin();
146 auto other_partition_it = other.partition_.begin();
147 while (self_partition_it != partition_.end()) {
148 while (other_partition_it != other.partition_.end() && v_self != v_other) {
149 const Part& other_part = *other_partition_it++;
150 if (other_partition_it == other.partition_.end()) return false;
151 for (const auto& k : other_part) v_other[k]++;
152 }
153 if (other_partition_it == other.partition_.end()) return false;
154 const Part& self_part = *self_partition_it++;
155 if (self_partition_it == partition_.end()) return true;
156 for (const auto& k : self_part) v_self[k]++;
157 }
158 return true;
159 }
160
161 private:
162 Vertex vertex_;
163 OrderedSetPartition partition_;
164};
165
172template <class Vertex, class OrderedSetPartition>
173std::ostream& operator<<(std::ostream& os, const Permutahedral_representation<Vertex, OrderedSetPartition>& simplex) {
174 // vertex part
175 os << "(";
176 if (simplex.vertex().empty()) {
177 os << ")";
178 return os;
179 }
180 auto v_it = simplex.vertex().begin();
181 os << *v_it++;
182 for (; v_it != simplex.vertex().end(); ++v_it) os << ", " << *v_it;
183 os << ")";
184
185 // ordered partition part
186 using Part = typename OrderedSetPartition::value_type;
187 auto print_part = [&os](const Part& p) {
188 os << "{";
189 if (p.empty()) {
190 os << "}";
191 }
192 auto p_it = p.begin();
193 os << *p_it++;
194 for (; p_it != p.end(); ++p_it) os << ", " << *p_it;
195 os << "}";
196 };
197 os << " [";
198 if (simplex.partition().empty()) {
199 os << "]";
200 return os;
201 }
202 auto o_it = simplex.partition().begin();
203 print_part(*o_it++);
204 for (; o_it != simplex.partition().end(); ++o_it) {
205 os << ", ";
206 print_part(*o_it);
207 }
208 os << "]";
209 return os;
210}
211
212} // namespace coxeter_triangulation
213
214} // namespace Gudhi
215
216#endif // PERMUTAHEDRAL_REPRESENTATION_H_
Iterator over the k-cofaces of a simplex given by its permutahedral representation.
Definition: Permutahedral_representation_iterators.h:151
Iterator over the k-faces of a simplex given by its permutahedral representation.
Definition: Permutahedral_representation_iterators.h:92
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
Vertex_range vertex_range() const
Returns a range of vertices of the simplex. The type of vertices is Vertex.
Definition: Permutahedral_representation.h:100
const Vertex & vertex() const
Lexicographically-minimal vertex.
Definition: Permutahedral_representation.h:71
Coface_range coface_range(std::size_t value_dim) const
Returns a range of permutahedral representations of cofaces of the simplex.
Definition: Permutahedral_representation.h:122
Face_range facet_range() const
Returns a range of permutahedral representations of facets of the simplex. The dimension of the simpl...
Definition: Permutahedral_representation.h:114
Face_range face_range(std::size_t value_dim) const
Returns a range of permutahedral representations of faces of the simplex.
Definition: Permutahedral_representation.h:107
Permutahedral_representation(const Vertex &vertex, const OrderedSetPartition &partition)
Permutahedral_representation constructor from a vertex and an ordered set partition.
Definition: Permutahedral_representation.h:56
bool is_face_of(const Permutahedral_representation &other) const
Returns true, if the simplex is a face of other simplex.
Definition: Permutahedral_representation.h:137
std::size_t dimension() const
Dimension of the simplex.
Definition: Permutahedral_representation.h:65
OrderedSetPartition & partition()
Ordered set partition.
Definition: Permutahedral_representation.h:74
bool operator==(const Permutahedral_representation &other) const
Equality operator. Returns true if an only if both vertex and the ordered set partition coincide.
Definition: Permutahedral_representation.h:82
Ordered_set_partition_ OrderedSetPartition
Type of the ordered partition.
Definition: Permutahedral_representation.h:46
Coface_range cofacet_range() const
Returns a range of permutahedral representations of cofacets of the simplex. The dimension of the sim...
Definition: Permutahedral_representation.h:129
bool operator!=(const Permutahedral_representation &other) const
Inequality operator. Returns true if an only if either vertex or the ordered set partition are differ...
Definition: Permutahedral_representation.h:93
const OrderedSetPartition & partition() const
Identifying vertex.
Definition: Permutahedral_representation.h:77
Vertex_ Vertex
Type of the vertex.
Definition: Permutahedral_representation.h:43
Permutahedral_representation()
Constructor for an empty permutahedral representation that does not correspond to any simplex.
Definition: Permutahedral_representation.h:62
Iterator over the vertices of a simplex represented by its permutahedral representation.
Definition: Permutahedral_representation_iterators.h:41
std::ostream & operator<<(std::ostream &os, const Permutahedral_representation< Vertex, OrderedSetPartition > &simplex)
Print a permutahedral representation to a stream.
Definition: Permutahedral_representation.h:173