politopix  4.1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PolyhedralCone_Rn.cpp
Go to the documentation of this file.
1 // politopix allows to make computations on polytopes such as finding vertices, intersecting, Minkowski sums, ...
2 // Copyright (C) 2011-2016 : Delos Vincent
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
19 // I2M (UMR CNRS 5295 / University of Bordeaux)
20 
21 #include <math.h>
22 #include <sstream>
23 #include <iostream>
24 #include "Rn.h"
25 #include "PolyhedralCone_Rn.h"
26 
27 
28 // HALF-SPACES
32  for (iteHSB.begin(); iteHSB.end()!=true; iteHSB.next()) {
33  double halfSpaceNorm =
34  std::inner_product(iteHSB.current()->begin(), iteHSB.current()->end(), iteHSB.current()->begin(), 0.);
35  halfSpaceNorm = sqrt(halfSpaceNorm);
36  double scalarProduct =
37  std::inner_product(thisPoint.begin(), thisPoint.end(), iteHSB.current()->begin(), 0.);
38  double distanceToHyperplane = (scalarProduct+iteHSB.current()->getConstant()) / halfSpaceNorm;
39  if (distanceToHyperplane < -Rn::getTolerance())
40  return HalfSpace_Rn::hs_OUT;
41  else if (distanceToHyperplane < Rn::getTolerance())
42  thisState = HalfSpace_Rn::hs_ON;
43  }
44  return thisState;
45 }
46 
48  const boost::shared_ptr<Generator_Rn>& point,
49  const boost::shared_ptr<HalfSpace_Rn>& halfSpace,
50  double halfSpaceNorm) const {
51  if (!point)
52  throw std::invalid_argument(std::string("Invalid point in PolyhedralCone_Rn::checkPoint()"));
53  if (!halfSpace)
54  throw std::invalid_argument(std::string("Invalid half space in PolyhedralCone_Rn::checkPoint()"));
55 
56  double scalarProduct =
57  std::inner_product(point->begin(), point->end(), halfSpace->begin(), 0.);
58  double distanceToHyperplane = (scalarProduct+halfSpace->getConstant()) / halfSpaceNorm;
59  if (distanceToHyperplane > Rn::getTolerance()) {
60  return HalfSpace_Rn::hs_IN;
61  }
62  else if (distanceToHyperplane < -Rn::getTolerance()) {
63  return HalfSpace_Rn::hs_OUT;
64  }
65  else {
66  return HalfSpace_Rn::hs_ON;
67  }
68 }
69 
70 bool PolyhedralCone_Rn::checkDuplicateGenerators(unsigned int& a, unsigned int& b) {
71  bool dup=false;
72  double TOL=Rn::getTolerance();
73  unsigned int RnDIM=dimension();
75  iteGN1(_listOfGenerators);
76  {for (iteGN1.begin(); iteGN1.end()!=true; iteGN1.next()) {
78  iteGN2(_listOfGenerators);
79  {for (iteGN2.begin(); iteGN2.end()!=true; iteGN2.next()) {
80  if (iteGN1.current() != iteGN2.current()) {
81  double dist=0.;
82  bool goNext=false;
83  {for (unsigned int j=0; j<RnDIM; j++) {
84  double distj = fabs(iteGN1.current()->getCoordinate(j)-iteGN2.current()->getCoordinate(j));
85  if (distj > TOL) {
86  goNext = true;
87  break;
88  }
89  dist = dist + distj*distj;
90  }}
91  if (dist<TOL && goNext==false) {
92  dup = true;
93  a = iteGN1.currentIteratorNumber();
94  b = iteGN2.currentIteratorNumber();
95  std::cout << "@ same vertices (a=" << a << ", b=" << b <<")" << std::endl;
96  std::cout << "### V" << a << " = (";
97  {for (unsigned int ii=0; ii<RnDIM; ii++) {
98  std::cout << iteGN1.current()->getCoordinate(ii);
99  if (ii != RnDIM-1)
100  std::cout << ", ";
101  }}
102  std::cout << ")" << std::endl << "{ ";
103  {for (unsigned int ii=0; ii<iteGN1.current()->numberOfFacets(); ii++) {
104  std::cout << "(";
105  {for (unsigned int jj=0; jj<RnDIM; jj++) {
106  std::cout << iteGN1.current()->getFacet(ii)->getCoefficient(jj) << " ";
107  if (jj == RnDIM-1)
108  std::cout << iteGN1.current()->getFacet(ii)->getSideAsText() << " " << -iteGN1.current()->getFacet(ii)->getConstant();
109  }}
110  std::cout << ") ";
111  }}
112  std::cout << "}" << std::endl;
113  std::cout << "### V" << b << " = (";
114  {for (unsigned int ii=0; ii<RnDIM; ii++) {
115  std::cout << iteGN2.current()->getCoordinate(ii);
116  if (ii != RnDIM-1)
117  std::cout << ", ";
118  }}
119  std::cout << ")" << std::endl << "{ ";
120  {for (unsigned int ii=0; ii<iteGN2.current()->numberOfFacets(); ii++) {
121  std::cout << "(";
122  {for (unsigned int jj=0; jj<RnDIM; jj++) {
123  std::cout << iteGN2.current()->getFacet(ii)->getCoefficient(jj) << " ";
124  if (jj == RnDIM-1)
125  std::cout << iteGN2.current()->getFacet(ii)->getSideAsText() << " " << -iteGN2.current()->getFacet(ii)->getConstant();
126  }}
127  std::cout << ") ";
128  }}
129  std::cout << "}" << std::endl;
130  }
131  }
132  }}
133  }}
134  return dup;
135 }
136 
137 boost::shared_ptr<HalfSpace_Rn> PolyhedralCone_Rn::addHalfSpace(boost::shared_ptr<HalfSpace_Rn> hs, bool check) {
138  if (check == false) {
140  return hs;
141  }
143  for (iteHS.begin(); iteHS.end()!=true; iteHS.next()) {
144  unsigned int i=0;
145  bool equal=true;
146  while (i<dimension() && equal==true) {
147  if (fabs(iteHS.current()->getCoefficient(i) - hs->getCoefficient(i)) > Rn::getTolerance())
148  equal = false;
149  i++;
150  }
151  if (equal == true)
152  return iteHS.current();
153  }
154  // The half-space has not been found in list so insert it.
156  return hs;
157 }
158 
159 const boost::shared_ptr<HalfSpace_Rn>& PolyhedralCone_Rn::getHalfSpace(unsigned int i) const throw (std::out_of_range) {
160  if (i < numberOfHalfSpaces())
161  return _listOfHalfSpaces[i];
162  else {
163  std::string errorMessage = Point_Rn::concatStrings(i, "PolyhedralCone_Rn::getHalfSpace_Rn");
164  throw std::out_of_range(errorMessage);
165  }
166 }
167 
168 void PolyhedralCone_Rn::removeHalfSpaceFromListAndGenerators(const boost::shared_ptr<HalfSpace_Rn>& hs) throw (std::invalid_argument) {
169  if (!hs)
170  throw std::invalid_argument(std::string("Invalid generator G in PolyhedralCone_Rn::removeHalfSpaceFromListAndGenerators()"));
171  unsigned int i=0;
173  for (iteHS.begin(); iteHS.end()!=true && iteHS.current()!=hs; iteHS.next()) {
174  i++;
175  }
176  removeHalfSpace(i);
178  for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
179  for (unsigned int j=0; j<iteGN.current()->numberOfFacets(); ++j) {
180  if (iteGN.current()->getFacet(j) == hs) {
181  iteGN.current()->removeFacet(j);
182  break;
183  }
184  }
185  }
186 }
187 
188 // CONVEX HULL
189 
190 const boost::shared_ptr<Generator_Rn>& PolyhedralCone_Rn::getGenerator(unsigned int i) const throw (std::out_of_range) {
191  if (i < numberOfGenerators())
192  return _listOfGenerators[i];
193  else {
194  std::string errorMessage = Point_Rn::concatStrings(i, "PolyhedralCone_Rn::getGenerator");
195  throw std::out_of_range(errorMessage);
196  }
197 }
198 
199 unsigned int PolyhedralCone_Rn::getGeneratorNumber(boost::shared_ptr<Generator_Rn> G) const throw (std::out_of_range,std::invalid_argument) {
200  if (!G)
201  throw std::invalid_argument(std::string("Invalid generator G in PolyhedralCone_Rn::getGeneratorNumber(G)"));
202  if (_listOfGenerators.size() == 0)
203  throw std::out_of_range(std::string("Non allocated array of generators in PolyhedralCone_Rn::getGeneratorNumber(G)"));
204 
205  unsigned int i=0;
207  for (iteGN.begin(); iteGN.end()!=true && iteGN.current()!=G; iteGN.next()) {
208  i++;
209  }
210  if (iteGN.end()==true) {
211  std::ostringstream stream_;
212  stream_ << "Generator G ";
213  G->dump(stream_);
214  stream_ << " is not stored in array in PolyhedralCone_Rn::getGeneratorNumber(G)";
215  std::string valString = stream_.str();
216  throw std::out_of_range(valString);
217  }
218  return i;
219 }
220 
221 // CHECK POLYHEDRON
222 
223 void PolyhedralCone_Rn::dump(std::ostream &this_ostream) const {
224 
225  if (_listOfHalfSpaces.size() == 0 && _listOfGenerators.size() == 0)
226  return;
227  this_ostream << std::endl << "#POLYTOPE" << std::endl;
228  this_ostream << dimension() << " ";
229  this_ostream << _listOfHalfSpaces.size() << " ";
230  this_ostream << _listOfGenerators.size() << std::endl;
231  this_ostream << std::endl;
232 
233  if (_listOfHalfSpaces.size() != 0) {
235  {for (iteHS.begin(); iteHS.end()!=true; iteHS.next()) {
236  this_ostream << iteHS.current()->getConstant() << "\t";
237  {for (unsigned int j=0; j<dimension(); j++) {
238  this_ostream << iteHS.current()->getCoefficient(j) << "\t";
239  }}
240  this_ostream << iteHS.current()->getSideAsText() << "\t0." << std::endl;
241  }}
242  this_ostream << std::endl;
243  }
244 
245  if (_listOfGenerators.size() != 0) {
247  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
248  {for (unsigned int j=0; j<dimension(); j++) {
249  this_ostream << iteGN.current()->getCoordinate(j) << "\t";
250  }}
251  this_ostream << std::endl;
252  }}
253  this_ostream << std::endl;
254  }
255 
256  if (_listOfHalfSpaces.size() != 0 && _listOfGenerators.size() != 0) {
258  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
259  {for (unsigned int j=0; j<_listOfGenerators[iteGN.currentIteratorNumber()]->numberOfFacets(); j++) {
260  //this_ostream << getGeneratorNumber(_listOfGenerators[i]->getNeighbourGenerator(j)) << "\t";
261  boost::shared_ptr<HalfSpace_Rn> F = iteGN.current()->getFacet(j);
262  this_ostream << F << " " << std::endl;
263  //this_ostream << getFacetNumber(F) << "\t";
264  //this_ostream << "(";
265  //{for (unsigned int jj=0; jj<Rn::getDimension(); jj++) {
266  //this_ostream << F->getCoefficient(jj) << " ";
267  //if (jj == Rn::getDimension()-1)
268  //this_ostream << F->getSideAsText() << " " << -F->getConstant();
269  //}}
270  //this_ostream << ") " << std::endl;
271  }}
272  this_ostream << std::endl;
273  }}
274  this_ostream << std::endl;
275  }
276 }
277 
278 // ALGORITHM
279 
281  const boost::shared_ptr<PolyhedralCone_Rn>&,
282  const boost::shared_ptr<PolyhedralCone_Rn>&) {
283 }
284 
285 boost::shared_ptr<PolyhedralCone_Rn> PolyhedralCone_Rn::computeDualPolyhedralCone() const {
286  boost::shared_ptr<PolyhedralCone_Rn> dualCone;
287  dualCone.reset(new PolyhedralCone_Rn());
288 
289  // Temp array to store constraints.
290  std::vector< boost::shared_ptr<HalfSpace_Rn> > HSvect;
292  // Facets block //
294  for (unsigned int i=0; i<numberOfGenerators(); i++) {
295  boost::shared_ptr<HalfSpace_Rn> HS;
296  HS.reset(new HalfSpace_Rn(dimension()));
297  HS->setConstant(0.);
298  // The normal vector
299  for (unsigned int coord_count=0; coord_count<dimension(); coord_count++) {
300  HS->setCoefficient(coord_count, getGenerator(i)->getCoordinate(coord_count));
301  }
302  dualCone->addHalfSpace(HS);
303  HSvect.push_back(HS);
304  }
305 
307  // Generators block //
309  boost::shared_ptr<Generator_Rn> VX;
311  for (iteHSA.begin(); iteHSA.end()!=true; iteHSA.next()) {
312  VX.reset(new Generator_Rn(dimension()));
313  for (unsigned int coord_count=0; coord_count<dimension(); coord_count++) {
314  VX->setCoordinate(coord_count, iteHSA.current()->getCoefficient(coord_count));
315  }
316  dualCone->addGenerator(VX);
317  }
318 
320  // Facets per vertex block //
322  // {Fi1, Fi2, ... }
323  //for (unsigned int i=0; i<dualCone->numberOfGenerators(); i++) {
324  for (iteHSA.begin(); iteHSA.end()!=true; iteHSA.next()) {
326  iteGN(_listOfGenerators);
327  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
328  //for (unsigned int vtx_count=0; vtx_count<numberOfGenerators(); vtx_count++) {
329  // The first generator in the dual corresponds to the first facet in the primal.
330  for (unsigned int j=0; j<iteGN.current()->numberOfFacets(); j++) {
331  boost::shared_ptr<HalfSpace_Rn> Fj = iteGN.current()->getFacet(j);
332  if (iteHSA.current() == Fj)
333  dualCone->getGenerator(iteHSA.currentIteratorNumber())->setFacet(HSvect[iteGN.currentIteratorNumber()]);
334  }
335  }}
336  }
337  //}
338 
339  return dualCone;
340 }
341 
343  const boost::shared_ptr<Generator_Rn_SD>& currentGeneratorOut,
344  const boost::shared_ptr<Generator_Rn_SD>& currentGeneratorIn,
345  boost::shared_ptr<Generator_Rn_SD> newV, double ay, double az, double) const {
346  // For polyhedral cones.
347  //for (unsigned int k=0; k<Rn::getDimension(); k++) {
348  //double yi = currentGeneratorOut->getCoordinate(k);
349  //double zi = currentGeneratorIn->getCoordinate(k);
350  //newV->setCoordinate(k, az*yi/(az-ay) - ay*zi/(az-ay));
351  //}
352  // Final operation to compare connection facets in Minkowski sums.
353  //newV->normalize();
354  double coef1 = az/(az-ay);
355  double coef2 =-ay/(az-ay);
356  newV->makeCoefSum(currentGeneratorOut, currentGeneratorIn, coef1, coef2);
357 }
358 
359 bool PolyhedralCone_Rn::isIncluded(const boost::shared_ptr<PolyhedralCone_Rn>& B) const {
360  //std::cout << Rn::getDimension() << " " << numberOfHalfSpaces() << " " << numberOfGenerators() << std::endl;
362  {for (iteHS_B.begin(); iteHS_B.end()!=true; iteHS_B.next()) {
363  double halfSpaceNorm = std::inner_product(iteHS_B.current()->begin(), iteHS_B.current()->end(), iteHS_B.current()->begin(), 0.);
364  halfSpaceNorm = sqrt(halfSpaceNorm);
366  {for (iteGN_A.begin(); iteGN_A.end()!=true; iteGN_A.next()) {
367  HalfSpace_Rn::State currentState = checkPoint(iteGN_A.current(), iteHS_B.current(), halfSpaceNorm);
368  if (currentState == HalfSpace_Rn::hs_OUT)
369  return false;
370  }}
371  }}
372  return true;
373 }
374 
376  double TOL = Rn::getTolerance();
378  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
379  boost::numeric::ublas::vector<double> averagePoint(dimension());
380  for (unsigned i=0; i<averagePoint.size(); ++i)
381  averagePoint(i) = 0.;
382  bool isVeryClose = true;
383  {for (unsigned int j=0; j<iteGN.current()->numberOfFacets(); j++) {
384  boost::shared_ptr<HalfSpace_Rn> HS = iteGN.current()->getFacet(j);
385  boost::numeric::ublas::vector<double> projectedPoint;
386  double halfSpaceNorm = norm_2(HS->vect());
387  //halfSpaceNorm = sqrt(halfSpaceNorm);
388  double disPoint2Hyp = HS->computeDistancePointHyperplane(iteGN.current()->vect(), projectedPoint, halfSpaceNorm);
389  //std::cout << "d" << iteGN.currentIteratorNumber() << " = " << disPoint2Hyp << std::endl;
390  if (disPoint2Hyp > 0.25*TOL || disPoint2Hyp < -0.25*TOL)
391  isVeryClose = false;
392  averagePoint += projectedPoint;
393  }}
394  if (isVeryClose == false) {
395  averagePoint /= iteGN.current()->numberOfFacets();
396  iteGN.current()->setCoordinates(averagePoint);
397  }
398  }}
399 }
400 
401 bool PolyhedralCone_Rn::checkEquality(const boost::shared_ptr<PolyhedralCone_Rn>& B, bool getFaceMapping) const {
402  bool res1, res2;
403  std::cout << "Check generators of A inside the half-spaces of B ..... ";
404  res1 = checkGenerators( _listOfGenerators, B->_listOfHalfSpaces, true);
405  std::cout << "Check generators of B inside the half-spaces of A ..... ";
406  res2 = checkGenerators(B->_listOfGenerators, _listOfHalfSpaces, true);
407  if (getFaceMapping && res1 && res2) {
408  //# Dimension NumberOfHalfspaces NumberOfGenerators # Dimension NumberOfHalfspaces NumberOfGenerators
409  //3 6 8 3 6 8
410  //# HALFSPACES : a0 + a1.x1 + ... + an.xn >= 0. # HALFSPACES : a0 + a1.x1 + ... + an.xn >= 0.
411  //1 1 0 0 1 -1 0 0
412  //1 0 1 0 1 0 0 1
413  //1 0 0 1 1 0 -1 0
414  //1 -1 0 0 1 0 1 0
415  //1 0 -1 0 1 0 0 -1
416  //1 0 0 -1 1 1 0 0
417  //
418  //Mapping Va <-> Vb
419  //0 <-> 5
420  //1 <-> 1
421  //2 <-> 4
422  //3 <-> 0
423  //4 <-> 7
424  //5 <-> 3
425  //6 <-> 6
426  //7 <-> 2
427  //Mapping Fa <=> Fb
428  //0 <=> 5
429  //1 <=> 3
430  //2 <=> 1
431  //3 <=> 0
432  //4 <=> 2
433  //5 <=> 4
434  double TOL = Rn::getTolerance();
435  std::vector<int> VaVb( _listOfGenerators.size());
436  std::vector<int> VbVa(B->_listOfGenerators.size());
437  std::cout << "Mapping Va <-> Vb" << std::endl;
438  {
440  {for (iteGN_A_.begin(); iteGN_A_.end()!=true; iteGN_A_.next()) {
441  bool eq = false;
443  {for (iteGN_B_.begin(); iteGN_B_.end()!=true && eq==false; iteGN_B_.next()) {
444  double dist = iteGN_B_.current()->distanceFrom(*iteGN_A_.current());
445  if (dist < TOL) {
446  eq = true;
447  VaVb[iteGN_A_.currentIteratorNumber()] = iteGN_B_.currentIteratorNumber();
448  VbVa[iteGN_B_.currentIteratorNumber()] = iteGN_A_.currentIteratorNumber();
449  std::cout << iteGN_A_.currentIteratorNumber() << " <-> " << iteGN_B_.currentIteratorNumber() << std::endl;
450  }
451  }}
452  }}
453  }
454  std::cout << "Mapping Fa <=> Fb" << std::endl;
455  std::vector< std::vector<int> > FacetsOfB_WithGeneratorOfB(B->_listOfHalfSpaces.size());
457  {for (iteHS_B.begin(); iteHS_B.end()!=true; iteHS_B.next()) {
458  double halfSpaceNorm =
459  std::inner_product(iteHS_B.current()->begin(), iteHS_B.current()->end(), iteHS_B.current()->begin(), 0.);
460  halfSpaceNorm = sqrt(halfSpaceNorm);
462  {for (iteGN_B_.begin(); iteGN_B_.end()!=true; iteGN_B_.next()) {
463  HalfSpace_Rn::State currentState = checkPoint(iteGN_B_.current(), iteHS_B.current(), halfSpaceNorm);
464  if (currentState == HalfSpace_Rn::hs_ON)
465  FacetsOfB_WithGeneratorOfB[ iteHS_B.currentIteratorNumber() ].push_back( iteGN_B_.currentIteratorNumber() );
466  }}
467  }}
468  std::vector< std::vector<int> > FacetsOfA_WithGeneratorOfB(_listOfHalfSpaces.size());
470  {for (iteHS_A.begin(); iteHS_A.end()!=true; iteHS_A.next()) {
471  double halfSpaceNorm =
472  std::inner_product(iteHS_A.current()->begin(), iteHS_A.current()->end(), iteHS_A.current()->begin(), 0.);
473  halfSpaceNorm = sqrt(halfSpaceNorm);
475  {for (iteGN_B_.begin(); iteGN_B_.end()!=true; iteGN_B_.next()) {
476  HalfSpace_Rn::State currentState = checkPoint(iteGN_B_.current(), iteHS_A.current(), halfSpaceNorm);
477  if (currentState == HalfSpace_Rn::hs_ON)
478  FacetsOfA_WithGeneratorOfB[ iteHS_A.currentIteratorNumber() ].push_back( iteGN_B_.currentIteratorNumber() );
479  }}
480  }}
481  //Sort all arrays.
482  std::vector< std::vector<int> >::iterator itV = FacetsOfB_WithGeneratorOfB.begin();
483  {for (; itV!=FacetsOfB_WithGeneratorOfB.end(); ++itV) {
484  std::sort(itV->begin(), itV->end());
485  }}
486  itV = FacetsOfA_WithGeneratorOfB.begin();
487  {for (; itV!=FacetsOfA_WithGeneratorOfB.end(); ++itV) {
488  std::sort(itV->begin(), itV->end());
489  }}
490  //std::cout << "Size of FacetsOfA_WithGeneratorOfB = " << FacetsOfA_WithGeneratorOfB.size() << std::endl;//@
491  //{for (std::vector< std::vector<int> >::const_iterator iteFacetA = FacetsOfA_WithGeneratorOfB.begin();
492  // iteFacetA != FacetsOfA_WithGeneratorOfB.end(); ++iteFacetA) {
493  //std::copy(iteFacetA->begin(), iteFacetA->end(), std::ostream_iterator<unsigned int>(std::cout, " ") );
494  //std::cout << std::endl;
495  //}}
496  //std::cout << "Size of FacetsOfB_WithGeneratorOfB = " << FacetsOfB_WithGeneratorOfB.size() << std::endl;//@
497  //{for (std::vector< std::vector<int> >::const_iterator iteFacetB = FacetsOfB_WithGeneratorOfB.begin();
498  // iteFacetB != FacetsOfB_WithGeneratorOfB.end(); ++iteFacetB) {
499  //std::copy(iteFacetB->begin(), iteFacetB->end(), std::ostream_iterator<unsigned int>(std::cout, " ") );
500  //std::cout << std::endl;
501  //}}
502 
503  {for (std::vector< std::vector<int> >::const_iterator iteFacetA = FacetsOfA_WithGeneratorOfB.begin();
504  iteFacetA != FacetsOfA_WithGeneratorOfB.end(); ++iteFacetA) {
505  const std::vector<int>& currentGeneratorsOfB = *iteFacetA;
506  std::vector<int> equivalentGeneratorsOfA(currentGeneratorsOfB.size());
507  //std::vector<int>::const_iterator iteGN;
508  {for (unsigned int i=0; i<currentGeneratorsOfB.size(); ++i) {
509  equivalentGeneratorsOfA[i] = VbVa[currentGeneratorsOfB[i]];
510  }}
511  std::sort(equivalentGeneratorsOfA.begin(), equivalentGeneratorsOfA.end());
512  //std::copy(equivalentGeneratorsOfA.begin(), equivalentGeneratorsOfA.end(), std::ostream_iterator<unsigned int>(std::cout, " ") );
513  std::vector< std::vector<int> >::const_iterator iteFacetB =
514  std::find(FacetsOfB_WithGeneratorOfB.begin(), FacetsOfB_WithGeneratorOfB.end(), currentGeneratorsOfB);
515  int d1 = iteFacetA - FacetsOfA_WithGeneratorOfB.begin();
516  int d2 = iteFacetB - FacetsOfB_WithGeneratorOfB.begin();
517  std::cout << d1 << " <=> " << d2 << std::endl;
518  }}
519  }
520  return (res1 || res2);
521  }
522 
Creation of a n-coordinate geometric point designed to be shared by its neighbour faces...
Definition: Point_Rn.h:34
const boost::shared_ptr< Generator_Rn > & getGenerator(unsigned int i) const
Return the i-th generator.
unsigned int size() const
Get the total number of genuine facets.
HalfSpace_Rn::State checkPoint(const Point_Rn &thisPoint) const
Check a point state against the whole polyhedron.
void removeHalfSpaceFromListAndGenerators(const boost::shared_ptr< HalfSpace_Rn > &hs)
Remove the half-space given as parameter from its list and from all generators.
int currentIteratorNumber() const
Return the current position in the list.
A half-space whose frontier is a linear (n-1) dimension space. _constant + _coefficients[0].x1 + ... + _coefficients[n-1].xn >= 0.
Definition: HalfSpace_Rn.h:37
bool checkDuplicateGenerators(unsigned int &a, unsigned int &b)
Make sure no duplicate generators are stored.
bool checkGenerators(const listOfGeometricObjects< boost::shared_ptr< Generator_Rn > > &listGenA, const listOfGeometricObjects< boost::shared_ptr< HalfSpace_Rn > > &listHSB, bool check_all=false) const
Check the number of facets per generator and make sure it is compliant with its current constraints...
virtual void createTruncatedGenerator(const boost::shared_ptr< Generator_Rn_SD > &y, const boost::shared_ptr< Generator_Rn_SD > &z, boost::shared_ptr< Generator_Rn_SD > newG, double ay, double az, double b=0.) const
Create the intersection edge in the truncating algorithm. It is defined by the intersection between a...
const boost::shared_ptr< HalfSpace_Rn > & getHalfSpace(unsigned int i) const
Return the i-th generator.
boost::shared_ptr< HalfSpace_Rn > addHalfSpace(boost::shared_ptr< HalfSpace_Rn > hs, bool check=false)
Add the current half-space in its list.
const GEOMETRIC_OBJECT current()
Return the current geometric element.
listOfGeometricObjects< boost::shared_ptr< Generator_Rn > > _listOfGenerators
The convex hull of connected points.
void begin()
Move the iterator at the beginning of the list.
virtual void computeMinkowskiSum(const boost::shared_ptr< PolyhedralCone_Rn > &A, const boost::shared_ptr< PolyhedralCone_Rn > &B)
Compute the Minkowski sum of two polyhedral cones.
vector< double >::const_iterator begin() const
Definition: Point_Rn.h:64
unsigned int numberOfGenerators() const
Give the total number of generators.
static polito_EXPORT double getTolerance()
Give the minimum distance between two points.
Definition: Rn.cpp:31
bool end() const
Tell whether we have reached the end of the list.
A n-coordinates generator, which can be a vertex or an edge whether it is contained by a polytope or ...
Definition: Generator_Rn.h:38
static std::string concatStrings(int i, const std::string &functionName)
Useful function to provide error message to the exception mechanism.
Definition: Point_Rn.cpp:79
This class is designed to run the list of all geometric objects representing a polytope.
bool checkEquality(const boost::shared_ptr< PolyhedralCone_Rn > &B, bool getFaceMapping=false) const
unsigned int getGeneratorNumber(boost::shared_ptr< Generator_Rn > G) const
For a given generator, return its list index.
void next()
Move the iterator one step forward.
virtual unsigned int dimension() const
Return the space dimension.
listOfGeometricObjects< boost::shared_ptr< HalfSpace_Rn > > _listOfHalfSpaces
The list of half-spaces defining the polytope.
vector< double >::const_iterator end() const
Definition: Point_Rn.h:66
void dump(std::ostream &this_ostream) const
Dump the polyhedral structure on std::cout.
boost::shared_ptr< PolyhedralCone_Rn > computeDualPolyhedralCone() const
Build the dual polyhedral cone of the current one whose edge are orthogonal to the primal and vice-ve...
void push_back(const GEOMETRIC_OBJECT &gn)
Include a new half space in the list.
PolyhedralCone_Rn()
Constructor.
bool isIncluded(const boost::shared_ptr< PolyhedralCone_Rn > &B) const
Test whether the current polytope V-description is inside the polytope B H-description.