Loading...
Searching...
No Matches
Permutahedral_representation.h
/* 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): Siargey Kachanovich
*
* Copyright (C) 2019 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef PERMUTAHEDRAL_REPRESENTATION_H_
#define PERMUTAHEDRAL_REPRESENTATION_H_
#include <gudhi/Permutahedral_representation/Permutahedral_representation_iterators.h>
#include <utility> // for std::make_pair
namespace Gudhi {
namespace coxeter_triangulation {
template <class Vertex_, class Ordered_set_partition_>
class Permutahedral_representation {
typedef Permutahedral_representation<Vertex_, Ordered_set_partition_> Self;
public:
typedef Vertex_ Vertex;
typedef Ordered_set_partition_ OrderedSetPartition;
Permutahedral_representation(const Vertex& vertex, const OrderedSetPartition& partition)
: vertex_(vertex), partition_(partition) {}
Permutahedral_representation() {}
std::size_t dimension() const { return partition_.size() - 1; }
Vertex& vertex() { return vertex_; }
const Vertex& vertex() const { return vertex_; }
OrderedSetPartition& partition() { return partition_; }
const OrderedSetPartition& partition() const { return partition_; }
bool operator==(const Permutahedral_representation& other) const {
if (dimension() != other.dimension()) return false;
if (vertex_ != other.vertex_) return false;
for (std::size_t k = 0; k < partition_.size(); ++k)
if (partition_[k] != other.partition_[k]) return false;
return true;
}
bool operator!=(const Permutahedral_representation& other) const { return !(*this == other); }
typedef Gudhi::coxeter_triangulation::Vertex_iterator<Self> Vertex_iterator;
typedef boost::iterator_range<Vertex_iterator> Vertex_range;
Vertex_range vertex_range() const { return Vertex_range(Vertex_iterator(*this), Vertex_iterator()); }
typedef Gudhi::coxeter_triangulation::Face_iterator<Self> Face_iterator;
typedef boost::iterator_range<Face_iterator> Face_range;
Face_range face_range(std::size_t value_dim) const {
return Face_range(Face_iterator(*this, value_dim), Face_iterator());
}
Face_range facet_range() const { return Face_range(Face_iterator(*this, dimension() - 1), Face_iterator()); }
typedef Gudhi::coxeter_triangulation::Coface_iterator<Self> Coface_iterator;
typedef boost::iterator_range<Coface_iterator> Coface_range;
Coface_range coface_range(std::size_t value_dim) const {
return Coface_range(Coface_iterator(*this, value_dim), Coface_iterator());
}
Coface_range cofacet_range() const {
return Coface_range(Coface_iterator(*this, dimension() + 1), Coface_iterator());
}
bool is_face_of(const Permutahedral_representation& other) const {
using Part = typename OrderedSetPartition::value_type;
if (other.dimension() < dimension()) return false;
if (other.vertex_.size() != vertex_.size())
std::cerr << "Error: Permutahedral_representation::is_face_of: incompatible ambient dimensions.\n";
Vertex v_self = vertex_, v_other = other.vertex_;
auto self_partition_it = partition_.begin();
auto other_partition_it = other.partition_.begin();
while (self_partition_it != partition_.end()) {
while (other_partition_it != other.partition_.end() && v_self != v_other) {
const Part& other_part = *other_partition_it++;
if (other_partition_it == other.partition_.end()) return false;
for (const auto& k : other_part) v_other[k]++;
}
if (other_partition_it == other.partition_.end()) return false;
const Part& self_part = *self_partition_it++;
if (self_partition_it == partition_.end()) return true;
for (const auto& k : self_part) v_self[k]++;
}
return true;
}
private:
Vertex vertex_;
OrderedSetPartition partition_;
};
template <class Vertex, class OrderedSetPartition>
std::ostream& operator<<(std::ostream& os, const Permutahedral_representation<Vertex, OrderedSetPartition>& simplex) {
// vertex part
os << "(";
if (simplex.vertex().empty()) {
os << ")";
return os;
}
auto v_it = simplex.vertex().begin();
os << *v_it++;
for (; v_it != simplex.vertex().end(); ++v_it) os << ", " << *v_it;
os << ")";
// ordered partition part
using Part = typename OrderedSetPartition::value_type;
auto print_part = [&os](const Part& p) {
os << "{";
if (p.empty()) {
os << "}";
}
auto p_it = p.begin();
os << *p_it++;
for (; p_it != p.end(); ++p_it) os << ", " << *p_it;
os << "}";
};
os << " [";
if (simplex.partition().empty()) {
os << "]";
return os;
}
auto o_it = simplex.partition().begin();
print_part(*o_it++);
for (; o_it != simplex.partition().end(); ++o_it) {
os << ", ";
print_part(*o_it);
}
os << "]";
return os;
}
} // namespace coxeter_triangulation
} // namespace Gudhi
#endif // PERMUTAHEDRAL_REPRESENTATION_H_
Gudhi::coxeter_triangulation::Coface_iterator
Iterator over the k-cofaces of a simplex given by its permutahedral representation.
Definition Permutahedral_representation_iterators.h:151
Gudhi::coxeter_triangulation::Face_iterator
Iterator over the k-faces of a simplex given by its permutahedral representation.
Definition Permutahedral_representation_iterators.h:92
Gudhi::coxeter_triangulation::Permutahedral_representation
A class that stores the permutahedral representation of a simplex in a Coxeter triangulation or a Fre...
Definition Permutahedral_representation.h:38
Gudhi::coxeter_triangulation::Permutahedral_representation::vertex
Vertex & vertex()
Lexicographically-minimal vertex.
Definition Permutahedral_representation.h:68
Gudhi::coxeter_triangulation::Permutahedral_representation::vertex_range
Vertex_range vertex_range() const
Returns a range of vertices of the simplex. The type of vertices is Vertex.
Definition Permutahedral_representation.h:100
Gudhi::coxeter_triangulation::Permutahedral_representation::vertex
const Vertex & vertex() const
Lexicographically-minimal vertex.
Definition Permutahedral_representation.h:71
Gudhi::coxeter_triangulation::Permutahedral_representation::coface_range
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
Gudhi::coxeter_triangulation::Permutahedral_representation::facet_range
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
Gudhi::coxeter_triangulation::Permutahedral_representation::face_range
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
Gudhi::coxeter_triangulation::Permutahedral_representation::Permutahedral_representation
Permutahedral_representation(const Vertex &vertex, const OrderedSetPartition &partition)
Permutahedral_representation constructor from a vertex and an ordered set partition.
Definition Permutahedral_representation.h:56
Gudhi::coxeter_triangulation::Permutahedral_representation::is_face_of
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
Gudhi::coxeter_triangulation::Permutahedral_representation::dimension
std::size_t dimension() const
Dimension of the simplex.
Definition Permutahedral_representation.h:65
Gudhi::coxeter_triangulation::Permutahedral_representation::partition
OrderedSetPartition & partition()
Ordered set partition.
Definition Permutahedral_representation.h:74
Gudhi::coxeter_triangulation::Permutahedral_representation::operator==
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
Gudhi::coxeter_triangulation::Permutahedral_representation::OrderedSetPartition
Ordered_set_partition_ OrderedSetPartition
Type of the ordered partition.
Definition Permutahedral_representation.h:46
Gudhi::coxeter_triangulation::Permutahedral_representation::cofacet_range
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
Gudhi::coxeter_triangulation::Permutahedral_representation::operator!=
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
Gudhi::coxeter_triangulation::Permutahedral_representation::partition
const OrderedSetPartition & partition() const
Identifying vertex.
Definition Permutahedral_representation.h:77
Gudhi::coxeter_triangulation::Permutahedral_representation::Vertex
Vertex_ Vertex
Type of the vertex.
Definition Permutahedral_representation.h:43
Gudhi::coxeter_triangulation::Permutahedral_representation::Permutahedral_representation
Permutahedral_representation()
Constructor for an empty permutahedral representation that does not correspond to any simplex.
Definition Permutahedral_representation.h:62
Gudhi::coxeter_triangulation::Vertex_iterator
Iterator over the vertices of a simplex represented by its permutahedral representation.
Definition Permutahedral_representation_iterators.h:41
Gudhi::coxeter_triangulation::operator<<
std::ostream & operator<<(std::ostream &os, const Permutahedral_representation< Vertex, OrderedSetPartition > &simplex)
Print a permutahedral representation to a stream.
Definition Permutahedral_representation.h:173
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14