21 #ifndef VOLUME_POLYTOPES_Rn
22 #define VOLUME_POLYTOPES_Rn
32 #include <boost/shared_ptr.hpp>
33 #include <boost/numeric/ublas/io.hpp>
34 #include <boost/numeric/ublas/vector.hpp>
35 #include <boost/numeric/ublas/matrix.hpp>
40 using namespace boost::numeric::ublas;
48 std::vector< unsigned int >::const_iterator itEnd = splitPol.end();
49 std::vector< unsigned int >::const_iterator itBeg = splitPol.begin();
52 _listOfVerticesToSplit.insert(_listOfVerticesToSplit.begin(), itBeg, itEnd);
55 PolytopeToSimplexes(
const std::vector< unsigned int >& vtx2plit,
unsigned int apexNb,
unsigned int dim) {
57 _listOfProcessedVertices.push_back( apexNb );
58 _listOfVerticesToSplit = vtx2plit;
61 PolytopeToSimplexes(
const std::vector< unsigned int >& vtx2plit,
const std::vector< unsigned int >& prcVtx,
unsigned int apexNb,
unsigned int dim) {
63 _listOfProcessedVertices = prcVtx;
64 _listOfProcessedVertices.push_back( apexNb );
65 _listOfVerticesToSplit = vtx2plit;
69 return _listOfProcessedVertices;
73 _listOfProcessedVertices = LPV;
77 return _listOfVerticesToSplit;
81 _listOfVerticesToSplit = VTS;
85 _listOfProcessedVertices.push_back(ap);
89 if (_dimension+1 == _listOfVerticesToSplit.size())
95 std::vector< unsigned int > pol;
96 std::vector< unsigned int >::const_iterator it;
97 for (it=_listOfProcessedVertices.begin(); it!=_listOfProcessedVertices.end(); ++it)
99 for (it=_listOfVerticesToSplit.begin(); it!=_listOfVerticesToSplit.end(); ++it)
105 _dimension += _listOfProcessedVertices.size();
106 _listOfProcessedVertices.insert(_listOfProcessedVertices.end(), _listOfVerticesToSplit.begin(), _listOfVerticesToSplit.end());
107 _listOfVerticesToSplit.clear();
114 void dump(std::ostream &this_ostream,
unsigned int shift=0)
const {
115 for (
unsigned int i=0; i<shift; ++i) this_ostream <<
"\t";
116 this_ostream <<
"{" << _dimension <<
":";
117 std::copy(getListOfProcessedVertices().begin(), getListOfProcessedVertices().end(), std::ostream_iterator<unsigned int>(this_ostream,
" "));
118 this_ostream << std::endl;
119 for (
unsigned int i=0; i<shift; ++i) std::cout <<
"\t";
120 std::copy(getListOfVerticesToSplit().begin(), getListOfVerticesToSplit().end(), std::ostream_iterator<unsigned int>(this_ostream,
" "));
121 this_ostream <<
"}" << std::endl;
150 void splitCloudOfVertices(
unsigned int DIM);
153 static double compute(
const boost::shared_ptr<Polytope_Rn> P) {
157 std::vector< unsigned int > attempt2Simplex;
158 std::vector< unsigned int > listOfOthers;
159 for (
unsigned int i=1; i<P->numberOfGenerators(); ++i)
160 listOfOthers.push_back(i);
165 volComp.
dump(std::cout);
169 catch(std::invalid_argument& e) {
170 std::cout <<
"VolumeOfPolytopes_Rn::compute() : invalid argument exception " << e.what() << std::endl;
173 catch(std::out_of_range& e) {
174 std::cout <<
"VolumeOfPolytopes_Rn::compute() : out of range exception " << e.what() << std::endl;
177 catch(std::ios_base::failure& e) {
178 std::cout <<
"VolumeOfPolytopes_Rn::compute() : in/out exception " << e.what() << std::endl;
182 std::cout <<
"VolumeOfPolytopes_Rn::compute() : unexpected exception caught !" << std::endl;
187 void check()
const throw (std::domain_error);
194 double computeSimplexVolume(const std::set< boost::shared_ptr<
Generator_Rn> >& listOfSimplexVertices) const;
198 double determinant(boost::numeric::ublas::matrix<
double> a) const;
200 void dump(std::ostream &this_ostream) {
201 std::cout <<
"List of simplices:" << std::endl;
202 unsigned int counter=0;
203 std::vector< PolytopeToSimplexes >::iterator iteSet;
204 {
for (iteSet=_allSimplices.begin(); iteSet!=_allSimplices.end(); ++iteSet) {
205 this_ostream <<
"Simplex number " << counter << std::endl;
206 std::vector< unsigned int >::const_iterator iteVtx;
207 {
for (iteVtx=iteSet->getListOfVerticesToSplit().begin(); iteVtx!=iteSet->getListOfVerticesToSplit().end(); ++iteVtx) {
208 boost::shared_ptr<Generator_Rn> gn = _polytope->getGenerator(*iteVtx);
209 gn->dump( this_ostream );
211 this_ostream << std::endl;
216 void dumpDS(std::ostream &this_ostream)
const {
217 std::cout <<
"Vertices By Facets:" << std::endl;
218 std::vector< std::vector< unsigned int > >::const_iterator iteSet;
219 unsigned int counter=0;
220 {
for (iteSet=_verticesByFacets.begin(); iteSet!=_verticesByFacets.end(); ++iteSet) {
221 this_ostream << counter <<
": ";
222 std::copy(iteSet->begin(), iteSet->end(), std::ostream_iterator<unsigned int>(std::cout,
" "));
223 this_ostream << std::endl;
226 std::cout <<
"Facets By Vertices:" << std::endl;
228 {
for (iteSet=_facetsByVertices.begin(); iteSet!=_facetsByVertices.end(); ++iteSet) {
229 this_ostream << counter <<
": ";
230 std::copy(iteSet->begin(), iteSet->end(), std::ostream_iterator<unsigned int>(std::cout,
" "));
231 this_ostream << std::endl;
237 std::vector< PolytopeToSimplexes >::const_iterator itS;
238 {
for (itS=_allSimplices.begin(); itS!=_allSimplices.end(); ++itS) {
239 itS->dump(this_ostream);
240 this_ostream << std::endl;
265 #endif // VOLUME_POLYTOPES_Rn
unsigned int dimension() const
std::vector< unsigned int > buildPolytope() const
void switchToFullDimension()
std::vector< unsigned int > _listOfProcessedVertices
The ordered list of vertices as we go down in smaller dimensions spaces.
std::vector< PolytopeToSimplexes > _allSimplices
List to store all the simplices partitioning the polytope.
void dump(std::ostream &this_ostream, unsigned int shift=0) const
unsigned int _numberOfFacets
The number of facets of the current polytope.
std::vector< unsigned int > _listOfVerticesToSplit
The ordered list of vertices to be split in lower dimensions.
std::vector< std::vector< unsigned int > > _verticesByFacets
The ordered list of all vertices stored by facets.
unsigned int _dimension
The current dimension space we work in.
const std::vector< unsigned int > & getListOfVerticesToSplit() const
void dumpDS(std::ostream &this_ostream) const
boost::shared_ptr< Polytope_Rn > _polytope
The current polytope we are working on.
Split a polytope into simplices to compute its volume. Two Algorithms for Determining Volumes of C...
void addProcessedVertex(unsigned int ap)
unsigned int _numberOfVertices
The number of vertices of the current polytope.
static polito_EXPORT unsigned int getDimension()
Return the dimension of the cartesian space we work in.
double _volume
The volume of the polytope.
static double compute(const boost::shared_ptr< Polytope_Rn > P)
Return the volume of the given polytope P.
A n-coordinates generator, which can be a vertex or an edge whether it is contained by a polytope or ...
std::vector< std::vector< unsigned int > > _facetsByVertices
The ordered list of all facets stored by vertices.
const std::vector< unsigned int > & getListOfProcessedVertices() const
double volume()
Sum the volumes of all simplices partitionning the polytope.
unsigned int _dimension
As the algorithm goes down in lower dimensions, we want to store the starting space dimension...
void splitCloudOfVertices(unsigned int DIM)
PolytopeToSimplexes(const std::vector< unsigned int > &vtx2plit, const std::vector< unsigned int > &prcVtx, unsigned int apexNb, unsigned int dim)
PolytopeToSimplexes(const std::vector< unsigned int > &vtx2plit, unsigned int apexNb, unsigned int dim)
void dump(std::ostream &this_ostream)
PolytopeToSimplexes(const std::vector< unsigned int > &splitPol, unsigned int dim)
void setListOfProcessedVertices(const std::vector< unsigned int > &LPV)
void setListOfVerticesToSplit(const std::vector< unsigned int > &VTS)
bool checkSimplex() const
void dumpAllSimplices(std::ostream &this_ostream) const