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;
48 const boost::shared_ptr<Generator_Rn>& point,
49 const boost::shared_ptr<HalfSpace_Rn>& halfSpace,
50 double halfSpaceNorm)
const {
52 throw std::invalid_argument(std::string(
"Invalid point in PolyhedralCone_Rn::checkPoint()"));
54 throw std::invalid_argument(std::string(
"Invalid half space in PolyhedralCone_Rn::checkPoint()"));
56 double scalarProduct =
57 std::inner_product(point->begin(), point->end(), halfSpace->begin(), 0.);
58 double distanceToHyperplane = (scalarProduct+halfSpace->getConstant()) / halfSpaceNorm;
76 {
for (iteGN1.
begin(); iteGN1.
end()!=
true; iteGN1.
next()) {
79 {
for (iteGN2.
begin(); iteGN2.
end()!=
true; iteGN2.
next()) {
83 {
for (
unsigned int j=0; j<RnDIM; j++) {
84 double distj = fabs(iteGN1.
current()->getCoordinate(j)-iteGN2.
current()->getCoordinate(j));
89 dist = dist + distj*distj;
91 if (dist<TOL && goNext==
false) {
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);
102 std::cout <<
")" << std::endl <<
"{ ";
103 {
for (
unsigned int ii=0; ii<iteGN1.
current()->numberOfFacets(); ii++) {
105 {
for (
unsigned int jj=0; jj<RnDIM; jj++) {
106 std::cout << iteGN1.
current()->getFacet(ii)->getCoefficient(jj) <<
" ";
108 std::cout << iteGN1.
current()->getFacet(ii)->getSideAsText() <<
" " << -iteGN1.
current()->getFacet(ii)->getConstant();
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);
119 std::cout <<
")" << std::endl <<
"{ ";
120 {
for (
unsigned int ii=0; ii<iteGN2.
current()->numberOfFacets(); ii++) {
122 {
for (
unsigned int jj=0; jj<RnDIM; jj++) {
123 std::cout << iteGN2.
current()->getFacet(ii)->getCoefficient(jj) <<
" ";
125 std::cout << iteGN2.
current()->getFacet(ii)->getSideAsText() <<
" " << -iteGN2.
current()->getFacet(ii)->getConstant();
129 std::cout <<
"}" << std::endl;
138 if (check ==
false) {
160 if (i < numberOfHalfSpaces())
161 return _listOfHalfSpaces[i];
164 throw std::out_of_range(errorMessage);
170 throw std::invalid_argument(std::string(
"Invalid generator G in PolyhedralCone_Rn::removeHalfSpaceFromListAndGenerators()"));
179 for (
unsigned int j=0; j<iteGN.
current()->numberOfFacets(); ++j) {
180 if (iteGN.
current()->getFacet(j) == hs) {
181 iteGN.
current()->removeFacet(j);
191 if (i < numberOfGenerators())
192 return _listOfGenerators[i];
195 throw std::out_of_range(errorMessage);
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)"));
210 if (iteGN.
end()==
true) {
211 std::ostringstream stream_;
212 stream_ <<
"Generator G ";
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);
227 this_ostream << std::endl <<
"#POLYTOPE" << std::endl;
231 this_ostream << std::endl;
236 this_ostream << iteHS.
current()->getConstant() <<
"\t";
237 {
for (
unsigned int j=0; j<
dimension(); j++) {
238 this_ostream << iteHS.
current()->getCoefficient(j) <<
"\t";
240 this_ostream << iteHS.
current()->getSideAsText() <<
"\t0." << std::endl;
242 this_ostream << std::endl;
248 {
for (
unsigned int j=0; j<
dimension(); j++) {
249 this_ostream << iteGN.
current()->getCoordinate(j) <<
"\t";
251 this_ostream << std::endl;
253 this_ostream << std::endl;
261 boost::shared_ptr<HalfSpace_Rn> F = iteGN.
current()->getFacet(j);
262 this_ostream << F <<
" " << std::endl;
272 this_ostream << std::endl;
274 this_ostream << std::endl;
281 const boost::shared_ptr<PolyhedralCone_Rn>&,
282 const boost::shared_ptr<PolyhedralCone_Rn>&) {
286 boost::shared_ptr<PolyhedralCone_Rn> dualCone;
290 std::vector< boost::shared_ptr<HalfSpace_Rn> > HSvect;
295 boost::shared_ptr<HalfSpace_Rn> HS;
299 for (
unsigned int coord_count=0; coord_count<
dimension(); coord_count++) {
300 HS->setCoefficient(coord_count,
getGenerator(i)->getCoordinate(coord_count));
302 dualCone->addHalfSpace(HS);
303 HSvect.push_back(HS);
309 boost::shared_ptr<Generator_Rn> VX;
311 for (iteHSA.
begin(); iteHSA.
end()!=
true; iteHSA.
next()) {
313 for (
unsigned int coord_count=0; coord_count<
dimension(); coord_count++) {
314 VX->setCoordinate(coord_count, iteHSA.
current()->getCoefficient(coord_count));
316 dualCone->addGenerator(VX);
324 for (iteHSA.
begin(); iteHSA.
end()!=
true; iteHSA.
next()) {
330 for (
unsigned int j=0; j<iteGN.
current()->numberOfFacets(); j++) {
331 boost::shared_ptr<HalfSpace_Rn> Fj = iteGN.
current()->getFacet(j);
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 {
354 double coef1 = az/(az-ay);
355 double coef2 =-ay/(az-ay);
356 newV->makeCoefSum(currentGeneratorOut, currentGeneratorIn, coef1, coef2);
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()) {
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());
388 double disPoint2Hyp = HS->computeDistancePointHyperplane(iteGN.
current()->vect(), projectedPoint, halfSpaceNorm);
390 if (disPoint2Hyp > 0.25*TOL || disPoint2Hyp < -0.25*TOL)
392 averagePoint += projectedPoint;
394 if (isVeryClose ==
false) {
395 averagePoint /= iteGN.
current()->numberOfFacets();
396 iteGN.
current()->setCoordinates(averagePoint);
403 std::cout <<
"Check generators of A inside the half-spaces of B ..... ";
405 std::cout <<
"Check generators of B inside the half-spaces of A ..... ";
407 if (getFaceMapping && res1 && res2) {
436 std::vector<int> VbVa(B->_listOfGenerators.size());
437 std::cout <<
"Mapping Va <-> Vb" << std::endl;
440 {
for (iteGN_A_.
begin(); iteGN_A_.
end()!=
true; iteGN_A_.
next()) {
443 {
for (iteGN_B_.
begin(); iteGN_B_.
end()!=
true && eq==
false; iteGN_B_.
next()) {
444 double dist = iteGN_B_.
current()->distanceFrom(*iteGN_A_.
current());
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()) {
465 FacetsOfB_WithGeneratorOfB[ iteHS_B.currentIteratorNumber() ].push_back( iteGN_B_.
currentIteratorNumber() );
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()) {
478 FacetsOfA_WithGeneratorOfB[ iteHS_A.currentIteratorNumber() ].push_back( iteGN_B_.
currentIteratorNumber() );
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());
486 itV = FacetsOfA_WithGeneratorOfB.begin();
487 {
for (; itV!=FacetsOfA_WithGeneratorOfB.end(); ++itV) {
488 std::sort(itV->begin(), itV->end());
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());
508 {
for (
unsigned int i=0; i<currentGeneratorsOfB.size(); ++i) {
509 equivalentGeneratorsOfA[i] = VbVa[currentGeneratorsOfB[i]];
511 std::sort(equivalentGeneratorsOfA.begin(), equivalentGeneratorsOfA.end());
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;
520 return (res1 || res2);
Creation of a n-coordinate geometric point designed to be shared by its neighbour faces...
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.
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
unsigned int numberOfGenerators() const
Give the total number of generators.
static polito_EXPORT double getTolerance()
Give the minimum distance between two points.
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 ...
static std::string concatStrings(int i, const std::string &functionName)
Useful function to provide error message to the exception mechanism.
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
void relocateGenerators()
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.