politopix  5.0.0
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-2021 : Delos Vincent
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU 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 General Public License for more details.
13 //
14 // You should have received a copy of the GNU 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
29 
33  for (iteHSB.begin(); iteHSB.end()!=true; iteHSB.next()) {
34  double halfSpaceNorm =
35  std::inner_product(iteHSB.current()->begin(), iteHSB.current()->end(), iteHSB.current()->begin(), 0.);
36  halfSpaceNorm = sqrt(halfSpaceNorm);
37  double scalarProduct =
38  std::inner_product(thisPoint.begin(), thisPoint.end(), iteHSB.current()->begin(), 0.);
39  double distanceToHyperplane = (scalarProduct+iteHSB.current()->getConstant()) / halfSpaceNorm;
40  if (distanceToHyperplane < -Rn::getTolerance())
41  return HalfSpace_Rn::hs_OUT;
42  else if (distanceToHyperplane < Rn::getTolerance())
43  thisState = HalfSpace_Rn::hs_ON;
44  }
45  return thisState;
46 }
47 
49  const boost::shared_ptr<Generator_Rn>& point,
50  const boost::shared_ptr<HalfSpace_Rn>& halfSpace,
51  double halfSpaceNorm) const {
52  if (!point)
53  throw std::invalid_argument(std::string("Invalid point in PolyhedralCone_Rn::checkPoint()"));
54  if (!halfSpace)
55  throw std::invalid_argument(std::string("Invalid half space in PolyhedralCone_Rn::checkPoint()"));
56 
57  double scalarProduct =
58  std::inner_product(point->begin(), point->end(), halfSpace->begin(), 0.);
59  double distanceToHyperplane = (scalarProduct+halfSpace->getConstant()) / halfSpaceNorm;
60  if (distanceToHyperplane > Rn::getTolerance()) {
61  return HalfSpace_Rn::hs_IN;
62  }
63  else if (distanceToHyperplane < -Rn::getTolerance()) {
64  return HalfSpace_Rn::hs_OUT;
65  }
66  else {
67  return HalfSpace_Rn::hs_ON;
68  }
69 }
70 
71 bool PolyhedralCone_Rn::checkDuplicateGenerators(unsigned int& a, unsigned int& b) {
72  bool dup=false;
73  double TOL=Rn::getTolerance();
74  unsigned int RnDIM=dimension();
76  iteGN1(_listOfGenerators);
77  {for (iteGN1.begin(); iteGN1.end()!=true; iteGN1.next()) {
79  iteGN2(_listOfGenerators);
80  {for (iteGN2.begin(); iteGN2.end()!=true; iteGN2.next()) {
81  if (iteGN1.current() != iteGN2.current()) {
82  double dist=0.;
83  bool goNext=false;
84  {for (unsigned int j=0; j<RnDIM; j++) {
85  double distj = fabs(iteGN1.current()->getCoordinate(j)-iteGN2.current()->getCoordinate(j));
86  if (distj > TOL) {
87  goNext = true;
88  break;
89  }
90  dist = dist + distj*distj;
91  }}
92  if (dist<TOL && goNext==false) {
93  dup = true;
94  a = iteGN1.currentIteratorNumber();
95  b = iteGN2.currentIteratorNumber();
96  std::cout << "@ same vertices (a=" << a << ", b=" << b <<")" << std::endl;
97  std::cout << "### V" << a << " = (";
98  {for (unsigned int ii=0; ii<RnDIM; ii++) {
99  std::cout << iteGN1.current()->getCoordinate(ii);
100  if (ii != RnDIM-1)
101  std::cout << ", ";
102  }}
103  std::cout << ")" << std::endl << "{ ";
104  {for (unsigned int ii=0; ii<iteGN1.current()->numberOfFacets(); ii++) {
105  std::cout << "(";
106  {for (unsigned int jj=0; jj<RnDIM; jj++) {
107  std::cout << iteGN1.current()->getFacet(ii)->getCoefficient(jj) << " ";
108  if (jj == RnDIM-1)
109  std::cout << iteGN1.current()->getFacet(ii)->getSideAsText() << " " << -iteGN1.current()->getFacet(ii)->getConstant();
110  }}
111  std::cout << ") ";
112  }}
113  std::cout << "}" << std::endl;
114  std::cout << "### V" << b << " = (";
115  {for (unsigned int ii=0; ii<RnDIM; ii++) {
116  std::cout << iteGN2.current()->getCoordinate(ii);
117  if (ii != RnDIM-1)
118  std::cout << ", ";
119  }}
120  std::cout << ")" << std::endl << "{ ";
121  {for (unsigned int ii=0; ii<iteGN2.current()->numberOfFacets(); ii++) {
122  std::cout << "(";
123  {for (unsigned int jj=0; jj<RnDIM; jj++) {
124  std::cout << iteGN2.current()->getFacet(ii)->getCoefficient(jj) << " ";
125  if (jj == RnDIM-1)
126  std::cout << iteGN2.current()->getFacet(ii)->getSideAsText() << " " << -iteGN2.current()->getFacet(ii)->getConstant();
127  }}
128  std::cout << ") ";
129  }}
130  std::cout << "}" << std::endl;
131  }
132  }
133  }}
134  }}
135  return dup;
136 }
137 
138 boost::shared_ptr<HalfSpace_Rn> PolyhedralCone_Rn::addHalfSpace(boost::shared_ptr<HalfSpace_Rn> hs, bool check) {
139  if (check == false) {
141  return hs;
142  }
144  for (iteHS.begin(); iteHS.end()!=true; iteHS.next()) {
145  unsigned int i=0;
146  bool equal=true;
147  while (i<dimension() && equal==true) {
148  if (fabs(iteHS.current()->getCoefficient(i) - hs->getCoefficient(i)) > Rn::getTolerance())
149  equal = false;
150  i++;
151  }
152  if (equal == true)
153  return iteHS.current();
154  }
155  // The half-space has not been found in list so insert it.
157  return hs;
158 }
159 
160 const boost::shared_ptr<HalfSpace_Rn>& PolyhedralCone_Rn::getHalfSpace(unsigned int i) const {
161  if (i < numberOfHalfSpaces())
162  return _listOfHalfSpaces[i];
163  else {
164  std::string errorMessage = Point_Rn::concatStrings(i, "PolyhedralCone_Rn::getHalfSpace_Rn");
165  throw std::out_of_range(errorMessage);
166  }
167 }
168 
169 void PolyhedralCone_Rn::removeHalfSpaceFromListAndGenerators(const boost::shared_ptr<HalfSpace_Rn>& hs) {
170  if (!hs)
171  throw std::invalid_argument(std::string("Invalid generator G in PolyhedralCone_Rn::removeHalfSpaceFromListAndGenerators()"));
172  unsigned int i=0;
174  for (iteHS.begin(); iteHS.end()!=true && iteHS.current()!=hs; iteHS.next()) {
175  i++;
176  }
177  removeHalfSpace(i);
179  for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
180  for (unsigned int j=0; j<iteGN.current()->numberOfFacets(); ++j) {
181  if (iteGN.current()->getFacet(j) == hs) {
182  iteGN.current()->removeFacet(j);
183  break;
184  }
185  }
186  }
187 }
188 
189 // CONVEX HULL
190 
191 const boost::shared_ptr<Generator_Rn>& PolyhedralCone_Rn::getGenerator(unsigned int i) const {
192  if (i < numberOfGenerators())
193  return _listOfGenerators[i];
194  else {
195  std::string errorMessage = Point_Rn::concatStrings(i, "PolyhedralCone_Rn::getGenerator");
196  throw std::out_of_range(errorMessage);
197  }
198 }
199 
200 unsigned int PolyhedralCone_Rn::getGeneratorNumber(boost::shared_ptr<Generator_Rn> G) const {
201  if (!G)
202  throw std::invalid_argument(std::string("Invalid generator G in PolyhedralCone_Rn::getGeneratorNumber(G)"));
203  if (_listOfGenerators.size() == 0)
204  throw std::out_of_range(std::string("Non allocated array of generators in PolyhedralCone_Rn::getGeneratorNumber(G)"));
205 
206  unsigned int i=0;
208  for (iteGN.begin(); iteGN.end()!=true && iteGN.current()!=G; iteGN.next()) {
209  i++;
210  }
211  if (iteGN.end()==true) {
212  std::ostringstream stream_;
213  stream_ << "Generator G ";
214  G->dump(stream_);
215  stream_ << " is not stored in array in PolyhedralCone_Rn::getGeneratorNumber(G)";
216  std::string valString = stream_.str();
217  throw std::out_of_range(valString);
218  }
219  return i;
220 }
221 
222 // DUMP POLYHEDRON
223 
224 void PolyhedralCone_Rn::dump(std::ostream &this_ostream) const {
225 
226  if (_listOfHalfSpaces.size() == 0 && _listOfGenerators.size() == 0)
227  return;
228  this_ostream << std::endl << "#POLYTOPE" << std::endl;
229  this_ostream << dimension() << " ";
230  this_ostream << _listOfHalfSpaces.size() << " ";
231  this_ostream << _listOfGenerators.size() << std::endl;
232  this_ostream << std::endl;
233 
234  if (_listOfHalfSpaces.size() != 0) {
236  {for (iteHS.begin(); iteHS.end()!=true; iteHS.next()) {
237  this_ostream << iteHS.current()->getConstant() << "\t";
238  {for (unsigned int j=0; j<dimension(); j++) {
239  this_ostream << iteHS.current()->getCoefficient(j) << "\t";
240  }}
241  this_ostream << iteHS.current()->getSideAsText() << "\t0." << std::endl;
242  }}
243  this_ostream << std::endl;
244  }
245 
246  if (_listOfGenerators.size() != 0) {
248  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
249  {for (unsigned int j=0; j<dimension(); j++) {
250  this_ostream << iteGN.current()->getCoordinate(j) << "\t";
251  }}
252  this_ostream << std::endl;
253  }}
254  this_ostream << std::endl;
255  }
256 
257  if (_listOfHalfSpaces.size() != 0 && _listOfGenerators.size() != 0) {
259  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
260  {for (unsigned int j=0; j<_listOfGenerators[iteGN.currentIteratorNumber()]->numberOfFacets(); j++) {
261  //this_ostream << getGeneratorNumber(_listOfGenerators[i]->getNeighbourGenerator(j)) << "\t";
262  boost::shared_ptr<HalfSpace_Rn> F = iteGN.current()->getFacet(j);
263  this_ostream << F << " " << std::endl;
264  //this_ostream << getFacetNumber(F) << "\t";
265  //this_ostream << "(";
266  //{for (unsigned int jj=0; jj<Rn::getDimension(); jj++) {
267  //this_ostream << F->getCoefficient(jj) << " ";
268  //if (jj == Rn::getDimension()-1)
269  //this_ostream << F->getSideAsText() << " " << -F->getConstant();
270  //}}
271  //this_ostream << ") " << std::endl;
272  }}
273  this_ostream << std::endl;
274  }}
275  this_ostream << std::endl;
276  }
277 }
278 
279 void PolyhedralCone_Rn::dumpScilab(std::ostream &this_ostream) const {
280  if (_listOfHalfSpaces.size() == 0 && _listOfGenerators.size() == 0)
281  return;
282  unsigned int currentDimension = dimension();
283  this_ostream << std::endl << "#" << std::endl;
284  this_ostream << currentDimension << " ";
285  this_ostream << _listOfHalfSpaces.size() << " ";
286  this_ostream << _listOfGenerators.size() << std::endl;
287  this_ostream << std::endl;
288 
289  {for (unsigned int i=0; i<currentDimension; ++i) {
290  if (_listOfGenerators.size() != 0) {
291  this_ostream << "x" << i+1 << " = [ ";
293  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
294  this_ostream << iteGN.current()->getCoordinate(i) << " ";
295  }}
296  this_ostream << "]" << std::endl;
297  }
298  }}
299  this_ostream << std::endl;
300 }
301 
302 // ALGORITHM
303 
304 boost::shared_ptr<PolyhedralCone_Rn> PolyhedralCone_Rn::computeDualPolyhedralCone() const {
305  boost::shared_ptr<PolyhedralCone_Rn> dualCone;
306  dualCone.reset(new PolyhedralCone_Rn());
307 
308  // Temp array to store constraints.
309  std::vector< boost::shared_ptr<HalfSpace_Rn> > HSvect;
311  // Facets block //
313  for (unsigned int i=0; i<numberOfGenerators(); i++) {
314  boost::shared_ptr<HalfSpace_Rn> HS;
315  HS.reset(new HalfSpace_Rn(dimension()));
316  HS->setConstant(0.);
317  // The normal vector
318  for (unsigned int coord_count=0; coord_count<dimension(); coord_count++) {
319  HS->setCoefficient(coord_count, getGenerator(i)->getCoordinate(coord_count));
320  }
321  dualCone->addHalfSpace(HS);
322  HSvect.push_back(HS);
323  }
324 
326  // Generators block //
328  boost::shared_ptr<Generator_Rn> VX;
330  for (iteHSA.begin(); iteHSA.end()!=true; iteHSA.next()) {
331  VX.reset(new Generator_Rn(dimension()));
332  for (unsigned int coord_count=0; coord_count<dimension(); coord_count++) {
333  VX->setCoordinate(coord_count, iteHSA.current()->getCoefficient(coord_count));
334  }
335  dualCone->addGenerator(VX);
336  }
337 
339  // Facets per vertex block //
341  // {Fi1, Fi2, ... }
342  //for (unsigned int i=0; i<dualCone->numberOfGenerators(); i++) {
343  for (iteHSA.begin(); iteHSA.end()!=true; iteHSA.next()) {
345  iteGN(_listOfGenerators);
346  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
347  //for (unsigned int vtx_count=0; vtx_count<numberOfGenerators(); vtx_count++) {
348  // The first generator in the dual corresponds to the first facet in the primal.
349  for (unsigned int j=0; j<iteGN.current()->numberOfFacets(); j++) {
350  boost::shared_ptr<HalfSpace_Rn> Fj = iteGN.current()->getFacet(j);
351  if (iteHSA.current() == Fj)
352  dualCone->getGenerator(iteHSA.currentIteratorNumber())->setFacet(HSvect[iteGN.currentIteratorNumber()]);
353  }
354  }}
355  }
356  //}
357 
358  return dualCone;
359 }
360 
362  const boost::shared_ptr<Generator_Rn_SD>& currentGeneratorOut,
363  const boost::shared_ptr<Generator_Rn_SD>& currentGeneratorIn,
364  boost::shared_ptr<Generator_Rn_SD> newV, double ay, double az, double) const {
365  // For polyhedral cones.
366  //for (unsigned int k=0; k<Rn::getDimension(); k++) {
367  //double yi = currentGeneratorOut->getCoordinate(k);
368  //double zi = currentGeneratorIn->getCoordinate(k);
369  //newV->setCoordinate(k, az*yi/(az-ay) - ay*zi/(az-ay));
370  //}
371  // Final operation to compare connection facets in Minkowski sums.
372  //newV->normalize();
373  double coef1 = az/(az-ay);
374  double coef2 =-ay/(az-ay);
375  newV->makeCoefSum(currentGeneratorOut, currentGeneratorIn, coef1, coef2);
376  return coef1;
377 }
378 
379 // void PolyhedralCone_Rn::createTruncatedGenerator(
380 // const Generator_Rn_SD& currentGeneratorOut, const Generator_Rn_SD& currentGeneratorIn,
381 // Generator_Rn_SD& newV, double ay, double az, double) const {
382 // // For polyhedral cones.
383 // //for (unsigned int k=0; k<Rn::getDimension(); k++) {
384 // //double yi = currentGeneratorOut->getCoordinate(k);
385 // //double zi = currentGeneratorIn->getCoordinate(k);
386 // //newV->setCoordinate(k, az*yi/(az-ay) - ay*zi/(az-ay));
387 // //}
388 // // Final operation to compare connection facets in Minkowski sums.
389 // //newV->normalize();
390 // double coef1 = az/(az-ay);
391 // double coef2 =-ay/(az-ay);
392 // newV.makeCoefSum(currentGeneratorOut, currentGeneratorIn, coef1, coef2);
393 // }
394 
395 bool PolyhedralCone_Rn::isIncluded(const boost::shared_ptr<PolyhedralCone_Rn>& B) const {
396  //std::cout << Rn::getDimension() << " " << numberOfHalfSpaces() << " " << numberOfGenerators() << std::endl;
398  {for (iteHS_B.begin(); iteHS_B.end()!=true; iteHS_B.next()) {
399  double halfSpaceNorm = std::inner_product(iteHS_B.current()->begin(), iteHS_B.current()->end(), iteHS_B.current()->begin(), 0.);
400  halfSpaceNorm = sqrt(halfSpaceNorm);
402  {for (iteGN_A.begin(); iteGN_A.end()!=true; iteGN_A.next()) {
403  HalfSpace_Rn::State currentState = checkPoint(iteGN_A.current(), iteHS_B.current(), halfSpaceNorm);
404  if (currentState == HalfSpace_Rn::hs_OUT)
405  return false;
406  }}
407  }}
408  return true;
409 }
410 
412  double TOL = Rn::getTolerance();
414  {for (iteGN.begin(); iteGN.end()!=true; iteGN.next()) {
415  boost::numeric::ublas::vector<double> averagePoint(dimension());
416  for (unsigned i=0; i<averagePoint.size(); ++i)
417  averagePoint(i) = 0.;
418  bool isVeryClose = true;
419  {for (unsigned int j=0; j<iteGN.current()->numberOfFacets(); j++) {
420  boost::shared_ptr<HalfSpace_Rn> HS = iteGN.current()->getFacet(j);
421  boost::numeric::ublas::vector<double> projectedPoint;
422  double halfSpaceNorm = norm_2(HS->vect());
423  //halfSpaceNorm = sqrt(halfSpaceNorm);
424  double disPoint2Hyp = HS->computeDistancePointHyperplane(iteGN.current()->vect(), projectedPoint, halfSpaceNorm);
425  //std::cout << "d" << iteGN.currentIteratorNumber() << " = " << disPoint2Hyp << std::endl;
426  if (disPoint2Hyp > 0.25*TOL || disPoint2Hyp < -0.25*TOL)
427  isVeryClose = false;
428  averagePoint += projectedPoint;
429  }}
430  if (isVeryClose == false) {
431  averagePoint /= iteGN.current()->numberOfFacets();
432  iteGN.current()->setCoordinates(averagePoint);
433  }
434  }}
435 }
436 
437 bool PolyhedralCone_Rn::checkEquality(const boost::shared_ptr<PolyhedralCone_Rn>& B, bool getFaceMapping) const {
438  bool res1, res2;
439  std::cout << "Check generators of A inside the half-spaces of B ..... ";
440  res1 = checkGenerators( _listOfGenerators, B->_listOfHalfSpaces, true);
441  std::cout << "Check generators of B inside the half-spaces of A ..... ";
442  res2 = checkGenerators(B->_listOfGenerators, _listOfHalfSpaces, true);
443  if (getFaceMapping && res1 && res2) {
444  //# Dimension NumberOfHalfspaces NumberOfGenerators # Dimension NumberOfHalfspaces NumberOfGenerators
445  //3 6 8 3 6 8
446  //# HALFSPACES : a0 + a1.x1 + ... + an.xn >= 0. # HALFSPACES : a0 + a1.x1 + ... + an.xn >= 0.
447  //1 1 0 0 1 -1 0 0
448  //1 0 1 0 1 0 0 1
449  //1 0 0 1 1 0 -1 0
450  //1 -1 0 0 1 0 1 0
451  //1 0 -1 0 1 0 0 -1
452  //1 0 0 -1 1 1 0 0
453  //
454  //Mapping Va <-> Vb
455  //0 <-> 5
456  //1 <-> 1
457  //2 <-> 4
458  //3 <-> 0
459  //4 <-> 7
460  //5 <-> 3
461  //6 <-> 6
462  //7 <-> 2
463  //Mapping Fa <=> Fb
464  //0 <=> 5
465  //1 <=> 3
466  //2 <=> 1
467  //3 <=> 0
468  //4 <=> 2
469  //5 <=> 4
470  double TOL = Rn::getTolerance();
471  std::vector<int> VaVb( _listOfGenerators.size());
472  std::vector<int> VbVa(B->_listOfGenerators.size());
473  std::cout << "Mapping Va <-> Vb" << std::endl;
474  {
476  {for (iteGN_A_.begin(); iteGN_A_.end()!=true; iteGN_A_.next()) {
477  bool eq = false;
479  {for (iteGN_B_.begin(); iteGN_B_.end()!=true && eq==false; iteGN_B_.next()) {
480  double dist = iteGN_B_.current()->distanceFrom(*iteGN_A_.current());
481  if (dist < TOL) {
482  eq = true;
483  VaVb[iteGN_A_.currentIteratorNumber()] = iteGN_B_.currentIteratorNumber();
484  VbVa[iteGN_B_.currentIteratorNumber()] = iteGN_A_.currentIteratorNumber();
485  std::cout << iteGN_A_.currentIteratorNumber() << " <-> " << iteGN_B_.currentIteratorNumber() << std::endl;
486  }
487  }}
488  }}
489  }
490  std::cout << "Mapping Fa <=> Fb" << std::endl;
491  std::vector< std::vector<int> > FacetsOfB_WithGeneratorOfB(B->_listOfHalfSpaces.size());
493  {for (iteHS_B.begin(); iteHS_B.end()!=true; iteHS_B.next()) {
494  double halfSpaceNorm =
495  std::inner_product(iteHS_B.current()->begin(), iteHS_B.current()->end(), iteHS_B.current()->begin(), 0.);
496  halfSpaceNorm = sqrt(halfSpaceNorm);
498  {for (iteGN_B_.begin(); iteGN_B_.end()!=true; iteGN_B_.next()) {
499  HalfSpace_Rn::State currentState = checkPoint(iteGN_B_.current(), iteHS_B.current(), halfSpaceNorm);
500  if (currentState == HalfSpace_Rn::hs_ON)
501  FacetsOfB_WithGeneratorOfB[ iteHS_B.currentIteratorNumber() ].push_back( iteGN_B_.currentIteratorNumber() );
502  }}
503  }}
504  std::vector< std::vector<int> > FacetsOfA_WithGeneratorOfB(_listOfHalfSpaces.size());
506  {for (iteHS_A.begin(); iteHS_A.end()!=true; iteHS_A.next()) {
507  double halfSpaceNorm =
508  std::inner_product(iteHS_A.current()->begin(), iteHS_A.current()->end(), iteHS_A.current()->begin(), 0.);
509  halfSpaceNorm = sqrt(halfSpaceNorm);
511  {for (iteGN_B_.begin(); iteGN_B_.end()!=true; iteGN_B_.next()) {
512  HalfSpace_Rn::State currentState = checkPoint(iteGN_B_.current(), iteHS_A.current(), halfSpaceNorm);
513  if (currentState == HalfSpace_Rn::hs_ON)
514  FacetsOfA_WithGeneratorOfB[ iteHS_A.currentIteratorNumber() ].push_back( iteGN_B_.currentIteratorNumber() );
515  }}
516  }}
517  //Sort all arrays.
518  std::vector< std::vector<int> >::iterator itV = FacetsOfB_WithGeneratorOfB.begin();
519  {for (; itV!=FacetsOfB_WithGeneratorOfB.end(); ++itV) {
520  std::sort(itV->begin(), itV->end());
521  }}
522  itV = FacetsOfA_WithGeneratorOfB.begin();
523  {for (; itV!=FacetsOfA_WithGeneratorOfB.end(); ++itV) {
524  std::sort(itV->begin(), itV->end());
525  }}
526  //std::cout << "Size of FacetsOfA_WithGeneratorOfB = " << FacetsOfA_WithGeneratorOfB.size() << std::endl;//@
527  //{for (std::vector< std::vector<int> >::const_iterator iteFacetA = FacetsOfA_WithGeneratorOfB.begin();
528  // iteFacetA != FacetsOfA_WithGeneratorOfB.end(); ++iteFacetA) {
529  //std::copy(iteFacetA->begin(), iteFacetA->end(), std::ostream_iterator<unsigned int>(std::cout, " ") );
530  //std::cout << std::endl;
531  //}}
532  //std::cout << "Size of FacetsOfB_WithGeneratorOfB = " << FacetsOfB_WithGeneratorOfB.size() << std::endl;//@
533  //{for (std::vector< std::vector<int> >::const_iterator iteFacetB = FacetsOfB_WithGeneratorOfB.begin();
534  // iteFacetB != FacetsOfB_WithGeneratorOfB.end(); ++iteFacetB) {
535  //std::copy(iteFacetB->begin(), iteFacetB->end(), std::ostream_iterator<unsigned int>(std::cout, " ") );
536  //std::cout << std::endl;
537  //}}
538 
539  {for (std::vector< std::vector<int> >::const_iterator iteFacetA = FacetsOfA_WithGeneratorOfB.begin();
540  iteFacetA != FacetsOfA_WithGeneratorOfB.end(); ++iteFacetA) {
541  const std::vector<int>& currentGeneratorsOfB = *iteFacetA;
542  std::vector<int> equivalentGeneratorsOfA(currentGeneratorsOfB.size());
543  //std::vector<int>::const_iterator iteGN;
544  {for (unsigned int i=0; i<currentGeneratorsOfB.size(); ++i) {
545  equivalentGeneratorsOfA[i] = VbVa[currentGeneratorsOfB[i]];
546  }}
547  std::sort(equivalentGeneratorsOfA.begin(), equivalentGeneratorsOfA.end());
548  //std::copy(equivalentGeneratorsOfA.begin(), equivalentGeneratorsOfA.end(), std::ostream_iterator<unsigned int>(std::cout, " ") );
549  std::vector< std::vector<int> >::const_iterator iteFacetB =
550  std::find(FacetsOfB_WithGeneratorOfB.begin(), FacetsOfB_WithGeneratorOfB.end(), currentGeneratorsOfB);
551  int d1 = iteFacetA - FacetsOfA_WithGeneratorOfB.begin();
552  int d2 = iteFacetB - FacetsOfB_WithGeneratorOfB.begin();
553  std::cout << d1 << " <=> " << d2 << std::endl;
554  }}
555  }
556  return (res1 || res2);
557  }
558 
HalfSpace_Rn::hs_OUT
@ hs_OUT
Definition: HalfSpace_Rn.h:47
Point_Rn::end
vector< double >::const_iterator end() const
Definition: Point_Rn.h:66
PolyhedralCone_Rn::getHalfSpace
const boost::shared_ptr< HalfSpace_Rn > & getHalfSpace(unsigned int i) const
Return the i-th half-space.
Definition: PolyhedralCone_Rn.cpp:160
listOfGeometricObjects::push_back
void push_back(const GEOMETRIC_OBJECT &gn)
Include a new half space in the list.
Definition: GeometricObjectIterator_Rn.h:47
HalfSpace_Rn::hs_IN
@ hs_IN
Definition: HalfSpace_Rn.h:46
PolyhedralCone_Rn::createTruncatedGenerator
virtual double 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...
Definition: PolyhedralCone_Rn.cpp:361
PolyhedralCone_Rn::relocateGenerators
void relocateGenerators()
Definition: PolyhedralCone_Rn.cpp:411
PolyhedralCone_Rn::addHalfSpace
boost::shared_ptr< HalfSpace_Rn > addHalfSpace(boost::shared_ptr< HalfSpace_Rn > hs, bool check=false)
Add the current half-space in its list.
Definition: PolyhedralCone_Rn.cpp:138
PolyhedralCone_Rn::getGenerator
const boost::shared_ptr< Generator_Rn > & getGenerator(unsigned int i) const
Return the i-th generator.
Definition: PolyhedralCone_Rn.cpp:191
PolyhedralCone_Rn::checkEquality
bool checkEquality(const boost::shared_ptr< PolyhedralCone_Rn > &B, bool getFaceMapping=false) const
Definition: PolyhedralCone_Rn.cpp:437
PolyhedralCone_Rn.h
PolyhedralCone_Rn::numberOfHalfSpaces
unsigned int numberOfHalfSpaces() const
Get the total number of half-spaces.
Definition: PolyhedralCone_Rn.h:95
PolyhedralCone_Rn::dump
virtual void dump(std::ostream &this_ostream) const
Dump the polyhedral structure on the stream passed as an argument.
Definition: PolyhedralCone_Rn.cpp:224
PolyhedralCone_Rn::removeHalfSpace
void removeHalfSpace(unsigned int j)
Remove the half-space number j from its list.
Definition: PolyhedralCone_Rn.h:104
constIteratorOfListOfGeometricObjects::current
const GEOMETRIC_OBJECT current()
Return the current geometric element.
Definition: GeometricObjectIterator_Rn.h:177
PolyhedralCone_Rn::checkPoint
HalfSpace_Rn::State checkPoint(const Point_Rn &thisPoint) const
Check a point state against the whole polyhedron.
Definition: PolyhedralCone_Rn.cpp:30
constIteratorOfListOfGeometricObjects::currentIteratorNumber
int currentIteratorNumber() const
Return the current position in the list.
Definition: GeometricObjectIterator_Rn.h:192
PolyhedralCone_Rn::removeHalfSpaceFromListAndGenerators
void removeHalfSpaceFromListAndGenerators(const boost::shared_ptr< HalfSpace_Rn > &hs)
Remove the half-space given as parameter from its list and from all generators.
Definition: PolyhedralCone_Rn.cpp:169
PolyhedralCone_Rn::computeDualPolyhedralCone
boost::shared_ptr< PolyhedralCone_Rn > computeDualPolyhedralCone() const
Create the intersection edge in the truncating algorithm. It is defined by the intersection between a...
Definition: PolyhedralCone_Rn.cpp:304
constIteratorOfListOfGeometricObjects::end
bool end() const
Tell whether we have reached the end of the list.
Definition: GeometricObjectIterator_Rn.h:174
HalfSpace_Rn
A half-space whose frontier is a linear (n-1) dimension space. _constant + _coefficients[0]....
Definition: HalfSpace_Rn.h:40
Rn.h
PolyhedralCone_Rn::checkGenerators
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....
Definition: PolyhedralCone_Rn.h:523
Point_Rn
Creation of a n-coordinate geometric point designed to be shared by its neighbour faces.
Definition: Point_Rn.h:34
constIteratorOfListOfGeometricObjects
This class is designed to run the list of all geometric objects representing a polytope.
Definition: GeometricObjectIterator_Rn.h:142
Generator_Rn
A n-coordinates generator, which can be a vertex or an edge whether it is contained by a polytope or ...
Definition: Generator_Rn.h:39
HalfSpace_Rn::State
State
Definition: HalfSpace_Rn.h:44
Point_Rn::begin
vector< double >::const_iterator begin() const
Definition: Point_Rn.h:64
PolyhedralCone_Rn::getGeneratorNumber
unsigned int getGeneratorNumber(boost::shared_ptr< Generator_Rn > G) const
For a given generator, return its list index.
Definition: PolyhedralCone_Rn.cpp:200
constIteratorOfListOfGeometricObjects::begin
void begin()
Move the iterator at the beginning of the list.
Definition: GeometricObjectIterator_Rn.h:150
PolyhedralCone_Rn::dimension
virtual unsigned int dimension() const
Return the space dimension.
Definition: PolyhedralCone_Rn.h:65
PolyhedralCone_Rn::isIncluded
bool isIncluded(const boost::shared_ptr< PolyhedralCone_Rn > &B) const
Test whether the current polytope V-description is inside the polytope B H-description.
Definition: PolyhedralCone_Rn.cpp:395
PolyhedralCone_Rn::numberOfGenerators
unsigned int numberOfGenerators() const
Give the total number of generators.
Definition: PolyhedralCone_Rn.h:143
listOfGeometricObjects::size
unsigned int size() const
Get the total number of stored elements.
Definition: GeometricObjectIterator_Rn.h:64
Point_Rn::concatStrings
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
PolyhedralCone_Rn::_listOfHalfSpaces
listOfGeometricObjects< boost::shared_ptr< HalfSpace_Rn > > _listOfHalfSpaces
The list of half-spaces defining the polyhedron.
Definition: PolyhedralCone_Rn.h:856
HalfSpace_Rn::hs_ON
@ hs_ON
Definition: HalfSpace_Rn.h:45
PolyhedralCone_Rn::dumpScilab
void dumpScilab(std::ostream &this_ostream) const
Dump the generators on on the stream passed as an argument for outputting in Scilab.
Definition: PolyhedralCone_Rn.cpp:279
constIteratorOfListOfGeometricObjects::next
void next()
Move the iterator one step forward.
Definition: GeometricObjectIterator_Rn.h:153
Rn::getTolerance
static polito_EXPORT double getTolerance()
Give the minimum distance between two points.
Definition: Rn.cpp:31
PolyhedralCone_Rn::_listOfGenerators
listOfGeometricObjects< boost::shared_ptr< Generator_Rn > > _listOfGenerators
The convex hull of connected points.
Definition: PolyhedralCone_Rn.h:858
PolyhedralCone_Rn::checkDuplicateGenerators
bool checkDuplicateGenerators(unsigned int &a, unsigned int &b)
Make sure no duplicate generators are stored.
Definition: PolyhedralCone_Rn.cpp:71
PolyhedralCone_Rn::PolyhedralCone_Rn
PolyhedralCone_Rn()
Constructor.
Definition: PolyhedralCone_Rn.h:53