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) {
156 if (currentDIM == 1) {
157 if (P->numberOfGenerators() == 2) {
158 double a0 = P->getGenerator(0)->getCoordinate(0);
159 double a1 = P->getGenerator(1)->getCoordinate(0);
163 std::cerr <<
"VolumeOfPolytopes_Rn::compute() double description needed." << std::endl;
168 std::vector<unsigned int> attempt2Simplex;
169 std::vector<unsigned int> listOfOthers;
170 for (
unsigned int i=1; i<P->numberOfGenerators(); ++i)
171 listOfOthers.push_back(i);
176 volComp.
dump(std::cout);
180 catch(std::invalid_argument& e) {
181 std::cout <<
"VolumeOfPolytopes_Rn::compute() : invalid argument exception " << e.what() << std::endl;
184 catch(std::out_of_range& e) {
185 std::cout <<
"VolumeOfPolytopes_Rn::compute() : out of range exception " << e.what() << std::endl;
188 catch(std::ios_base::failure& e) {
189 std::cout <<
"VolumeOfPolytopes_Rn::compute() : in/out exception " << e.what() << std::endl;
193 std::cout <<
"VolumeOfPolytopes_Rn::compute() : unexpected exception caught !" << std::endl;
205 double computeSimplexVolume(
const std::set< boost::shared_ptr<Generator_Rn> >& listOfSimplexVertices)
const;
209 double determinant(boost::numeric::ublas::matrix<double> a)
const;
211 void dump(std::ostream &this_ostream) {
212 std::cout <<
"List of simplices:" << std::endl;
213 unsigned int counter=0;
214 std::vector< PolytopeToSimplexes >::iterator iteSet;
215 {
for (iteSet=_allSimplices.begin(); iteSet!=_allSimplices.end(); ++iteSet) {
216 this_ostream <<
"Simplex number " << counter << std::endl;
217 std::vector< unsigned int >::const_iterator iteVtx;
218 {
for (iteVtx=iteSet->getListOfVerticesToSplit().begin(); iteVtx!=iteSet->getListOfVerticesToSplit().end(); ++iteVtx) {
219 boost::shared_ptr<Generator_Rn> gn = _polytope->getGenerator(*iteVtx);
220 gn->dump( this_ostream );
222 this_ostream << std::endl;
227 void dumpDS(std::ostream &this_ostream)
const {
228 std::cout <<
"Vertices By Facets:" << std::endl;
229 std::vector< std::vector< unsigned int > >::const_iterator iteSet;
230 unsigned int counter=0;
231 {
for (iteSet=_verticesByFacets.begin(); iteSet!=_verticesByFacets.end(); ++iteSet) {
232 this_ostream << counter <<
": ";
233 std::copy(iteSet->begin(), iteSet->end(), std::ostream_iterator<unsigned int>(std::cout,
" "));
234 this_ostream << std::endl;
237 std::cout <<
"Facets By Vertices:" << std::endl;
239 {
for (iteSet=_facetsByVertices.begin(); iteSet!=_facetsByVertices.end(); ++iteSet) {
240 this_ostream << counter <<
": ";
241 std::copy(iteSet->begin(), iteSet->end(), std::ostream_iterator<unsigned int>(std::cout,
" "));
242 this_ostream << std::endl;
248 std::vector< PolytopeToSimplexes >::const_iterator itS;
249 {
for (itS=_allSimplices.begin(); itS!=_allSimplices.end(); ++itS) {
250 itS->dump(this_ostream);
251 this_ostream << std::endl;
276 #endif // VOLUME_POLYTOPES_Rn