25 #include <boost/numeric/ublas/matrix.hpp>
26 #include <boost/numeric/ublas/matrix_proxy.hpp>
27 #include <boost/numeric/ublas/operation.hpp>
28 #include <boost/numeric/ublas/io.hpp>
47 const std::vector< HalfSpace_Rn* >& commonFacets,
48 const boost::shared_ptr<Generator_Rn>& gen,
49 unsigned int number=0) {
51 unsigned int nbCommonFacet=0;
53 {
for (
unsigned int k=0; k<commonFacets.size(); ++k) {
56 if (nbCommonFacet == commonFacets.size()) {
94 void dump(std::ostream &ofs) {
95 ofs <<
"Real ngb:" << std::endl;
96 std::vector< std::vector< HalfSpace_Rn* > >::const_iterator ite;
98 std::copy((*ite).begin(), (*ite).end(), std::ostream_iterator< HalfSpace_Rn* >(ofs,
" ") );
117 std::cout <<
"Check edges.......... ";
119 bool checkEdgesOK =
true;
124 std::vector< boost::shared_ptr<HalfSpace_Rn> > commonFacets;
127 std::vector<double> edge(RnDIM);
128 for (
unsigned int k=0; k<RnDIM; k++)
129 edge[k] = V1->getCoordinate(k) - V2->getCoordinate(k);
130 unsigned int countFacets = 0;
131 double scalarProduct = 0.;
132 for (
unsigned int l=0; l<commonFacets.size(); l++) {
133 for (
unsigned int n=0; n<RnDIM; n++)
134 scalarProduct = scalarProduct + edge[n]*commonFacets[l]->getCoefficient(n);
136 std::cout <<
"\t### Edge for generators " << i <<
" and " << j <<
" not on facet (";
137 {
for (
unsigned int jj=0; jj<RnDIM; jj++) {
138 std::cout << commonFacets[l]->getCoefficient(jj) <<
" ";
140 std::cout << commonFacets[l]->getSideAsText() <<
" " << commonFacets[l]->getConstant();
142 std::cout <<
") " << std::endl;
143 checkEdgesOK =
false;
149 if (countFacets < RnDIM-1) {
150 std::cout <<
"\t### Edge for generators " << i <<
" and " << j <<
" has not enough facets" << std::endl;
151 checkEdgesOK =
false;
156 if (checkEdgesOK ==
true)
157 std::cout <<
"OK" << std::endl;
166 unsigned int currentNumberOfFacets = (
unsigned int)
dimension()+1;
167 unsigned int currentNumberOfGenerators = (
unsigned int)
dimension()+1;
171 {
for (
unsigned int vtx_count=0; vtx_count<currentNumberOfGenerators; vtx_count++) {
172 boost::shared_ptr<Generator_Rn> VX;
178 {
for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
179 {
for (
unsigned int vtx_count=0; vtx_count<currentNumberOfGenerators; vtx_count++) {
181 if (vtx_count==coord_count && vtx_count<currentNumberOfGenerators-1)
182 getGenerator(vtx_count)->setCoordinate(coord_count, MAX);
184 getGenerator(vtx_count)->setCoordinate(coord_count, MIN);
188 std::vector< boost::shared_ptr<HalfSpace_Rn> > supportFacets;
190 {
for (
unsigned int facet_count=0; facet_count<currentNumberOfFacets-1; facet_count++) {
191 boost::shared_ptr<HalfSpace_Rn> HalfSp(
new HalfSpace_Rn(dim));
192 {
for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
193 if (facet_count == coord_count)
194 HalfSp->setCoefficient(coord_count, 1.);
196 HalfSp->setCoefficient(coord_count, 0.);
198 HalfSp->setConstant(M);
199 supportFacets.push_back(HalfSp);
202 getGenerator(currentNumberOfGenerators-1)->setFacet(HalfSp);
205 boost::shared_ptr<HalfSpace_Rn> oblicHalfSp(
new HalfSpace_Rn(dim));
206 {
for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
207 oblicHalfSp->setCoefficient(coord_count, -1.);
210 supportFacets.push_back(oblicHalfSp);
213 supportFacets.push_back(iteH.
current());
216 std::vector< boost::shared_ptr<HalfSpace_Rn> >::const_iterator itF;
217 {
for (itF=supportFacets.begin(); itF!=supportFacets.end();++itF) {
221 {
for (
unsigned int vtx_count1=0; vtx_count1<currentNumberOfGenerators-1; vtx_count1++) {
222 boost::shared_ptr<Generator_Rn> VX1 =
getGenerator(vtx_count1);
223 VX1->setFacet(oblicHalfSp);
224 {
for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
225 if (VX1->getCoordinate(coord_count) == MIN) {
240 unsigned int currentNumberOfGenerators = (
unsigned int)pow(static_cast<double>(2),
static_cast<int>(dim));
244 for (
unsigned int vtx_count=0; vtx_count<currentNumberOfGenerators; vtx_count++) {
245 boost::shared_ptr<Generator_Rn> VX;
250 for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
252 for (
unsigned int vtx_count=0; vtx_count<currentNumberOfGenerators; vtx_count++) {
253 if (counter >= pow(static_cast<double>(2), static_cast<int>(coord_count))) {
257 getGenerator(vtx_count)->setCoordinate(coord_count, MAX);
262 std::vector< boost::shared_ptr<HalfSpace_Rn> > supportFacets;
264 for (
unsigned int facet_count=0; facet_count<dim; facet_count++) {
265 boost::shared_ptr<HalfSpace_Rn> HalfSp(
new HalfSpace_Rn(dim));
266 for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
267 if (facet_count == coord_count)
268 HalfSp->setCoefficient(coord_count, -1.);
270 HalfSp->setCoefficient(coord_count, 0.);
272 HalfSp->setConstant(M);
273 supportFacets.push_back(HalfSp);
276 for (
unsigned int facet_count=0; facet_count<dim; facet_count++) {
277 boost::shared_ptr<HalfSpace_Rn> HalfSp(
new HalfSpace_Rn(dim));
278 for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
279 if (facet_count == coord_count)
280 HalfSp->setCoefficient(coord_count, 1.);
282 HalfSp->setCoefficient(coord_count, 0.);
284 HalfSp->setConstant(M);
285 supportFacets.push_back(HalfSp);
289 supportFacets.push_back(iteH.
current());
292 std::vector< boost::shared_ptr<HalfSpace_Rn> >::const_iterator itF;
293 {
for (itF=supportFacets.begin(); itF!=supportFacets.end();++itF) {
297 for (
unsigned int vtx_count1=0; vtx_count1<currentNumberOfGenerators; vtx_count1++) {
298 boost::shared_ptr<Generator_Rn> VX1 =
getGenerator(vtx_count1);
299 for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
300 if (VX1->getCoordinate(coord_count) == M)
302 else if (VX1->getCoordinate(coord_count) == -M)
310 const boost::shared_ptr<Generator_Rn_SD>& out,
311 const boost::shared_ptr<Generator_Rn_SD>& in,
312 boost::shared_ptr<Generator_Rn_SD> newV,
double ay,
double az,
double b)
const {
314 double t = (-b-az) / (ay-az);
320 newV->makeDiff(out, in);
321 newV->makeCoefSum(in, newV, 1., t);
328 std::vector<bool> vtxOfB(B->numberOfGenerators());
329 for (
unsigned int i=0; i<vtxOfA.size(); ++i)
331 for (
unsigned int i=0; i<vtxOfB.size(); ++i)
335 {
for (iteGN_A.
begin(); iteGN_A.
end()!=
true; iteGN_A.
next()) {
336 {
for (iteGN_B.begin(); iteGN_B.end()!=
true; iteGN_B.next()) {
337 if (iteGN_A.
current()->isEqual2(iteGN_B.current(), RnDIM, TOL2)) {
339 vtxOfB[ iteGN_B.currentIteratorNumber() ] =
true;
343 bool AinsideB =
true, BinsideA =
true;
344 {
for (
unsigned int i=0; i<vtxOfA.size(); ++i) {
345 if (vtxOfA[i] ==
false) {
350 {
for (
unsigned int i=0; i<vtxOfB.size(); ++i) {
351 if (vtxOfB[i] ==
false) {
356 if (printOnScreen ==
true) {
357 if (AinsideB ==
true)
358 std::cout <<
"The set of vertices of A in included in the set of vertices of B." << std::endl;
359 if (BinsideA ==
true)
360 std::cout <<
"The set of vertices of B in included in the set of vertices of A." << std::endl;
363 return (AinsideB && BinsideA);
368 if (u >= numberOfGenerators())
369 throw std::out_of_range(
"Polytope_Rn::getPrimalCone() index out of range");
371 boost::shared_ptr<PolyhedralCone_Rn> primalCone;
372 boost::shared_ptr<Generator_Rn> vx1 = getGenerator(u);
378 for (
unsigned int i=0; i<vx1->numberOfFacets(); i++) {
379 primalCone->addHalfSpace(vx1->getFacet(i));
381 for (
unsigned int v=0; v<numberOfGenerators(); v++) {
383 boost::shared_ptr<Generator_Rn> vx2 = getGenerator(v);
384 std::vector< boost::shared_ptr<HalfSpace_Rn> > commonFacets;
385 if (checkNeighbours(vx1, vx2, commonFacets) ==
true) {
387 boost::shared_ptr<Generator_Rn> edge12(
new Generator_Rn(dimension()));
388 for (
unsigned int k=0; k<dimension(); k++) {
389 edge12->setCoordinate(k, vx2->getCoordinate(k)-vx1->getCoordinate(k));
392 for (
unsigned int j=0; j<commonFacets.size(); j++) {
393 boost::shared_ptr<HalfSpace_Rn> Fj = commonFacets[j];
394 edge12->setFacet(Fj);
397 primalCone->addGenerator(edge12);
406 boost::shared_ptr<PolyhedralCone_Rn> primalCone;
412 for (
unsigned int i=0; i<vx1->numberOfFacets(); i++) {
413 primalCone->addHalfSpace(vx1->getFacet(i));
417 {
for (iteGN_A.
begin(); iteGN_A.
end()!=
true; iteGN_A.
next()) {
418 boost::shared_ptr<Generator_Rn> vx2 = iteGN_A.
current();
420 std::vector< HalfSpace_Rn* > commonPFacets;
422 std::set< boost::shared_ptr<HalfSpace_Rn> > listOfRedundantHS;
432 boost::shared_ptr<Generator_Rn> edge12(
new Generator_Rn(RnDIM));
433 edge12->makeDiff(vx2, vx1);
435 std::vector< boost::shared_ptr<HalfSpace_Rn> > commonFacets;
438 for (
unsigned int j=0; j<commonFacets.size(); ++j) {
439 boost::shared_ptr<HalfSpace_Rn> Fj = commonFacets[j];
440 edge12->setFacet(Fj);
443 primalCone->addGenerator(edge12);
listOfGeometricObjects< boost::shared_ptr< HalfSpace_Rn > > & getListOfHalfSpaces()
Return the list of half-spaces.
const listOfGeometricObjects< boost::shared_ptr< Generator_Rn > > & getListOfGenerators() const
Return the list of generators.
Class dedicated to degeneration processing when looking for neighbors.
unsigned int _iterator
A runner to iterate through the list of genuine neighbors.
virtual void createTruncatedGenerator(const boost::shared_ptr< Generator_Rn_SD > &in, const boost::shared_ptr< Generator_Rn_SD > &out, boost::shared_ptr< Generator_Rn_SD > newV, double ay, double az, double b=0.) const
This is the intersection vertex in the truncating algorithm, defined by the intersection between an e...
const boost::shared_ptr< Generator_Rn > & getGenerator(unsigned int i) const
Return the i-th generator.
boost::shared_ptr< Generator_Rn > currentNeighbour()
Iterator function.
bool checkEqualityOfVertices(const boost::shared_ptr< Polytope_Rn > &B, bool printOnScreen=false) const
Check whether two V-polytopes are identical Check whether the sets of vertices of A and B are equal...
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.
Model a polyhedral cone using its two equivalent definitions : the convex hull and the half-space int...
bool checkNeighbours(const boost::shared_ptr< Generator_Rn > &V1, const boost::shared_ptr< Generator_Rn > &V2, std::vector< boost::shared_ptr< HalfSpace_Rn > > &commonFacets, const std::set< boost::shared_ptr< HalfSpace_Rn > > &listOfRedundantHS) const
boost::shared_ptr< PolyhedralCone_Rn > getPrimalCone(unsigned int i) const
const GEOMETRIC_OBJECT current()
Return the current geometric element.
std::vector< unsigned int > _pseudoNeighboursNumber
The generator numbers in a global list.
listOfGeometricObjects< boost::shared_ptr< Generator_Rn > > _listOfGenerators
The convex hull of connected points.
void begin()
Move the iterator at the beginning of the list.
void dump(std::ostream &ofs)
Display the content on the stream passed as an argument.
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.
bool addNeighbour(const std::vector< HalfSpace_Rn * > &commonFacets, const boost::shared_ptr< Generator_Rn > &gen, unsigned int number=0)
Tell whether a pseudo neighbor is a genuine one comparing set of half-spaces.
std::vector< std::vector< HalfSpace_Rn * > > _HSPerPseudoNeighbours
For each generator, store all raw pointers on their corresponding half-spaces.
void begin()
Iterator function.
std::vector< boost::shared_ptr< Generator_Rn > > _pseudoNeighbours
The generator smart pointer.
static polito_EXPORT unsigned int getDimension()
Return the dimension of the cartesian space we work in.
A n-coordinates generator, which can be a vertex or an edge whether it is contained by a polytope or ...
virtual void createBoundingBox(double M)
Initialize the truncating algorithm building a M-sized bounding box around the polytope.
bool end()
Iterator function.
This class is designed to run the list of all geometric objects representing a polytope.
virtual bool checkEdges() const
Always true in the polyhedral cone case.
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.
bool checkNeighboursWithHSnumbers(const boost::shared_ptr< Generator_Rn > &V1, const boost::shared_ptr< Generator_Rn > &V2, std::vector< HalfSpace_Rn * > &commonFacets, const std::set< boost::shared_ptr< HalfSpace_Rn > > &listOfRedundantHS, unsigned int topologicalCode=1) const
Check for polytopes that vertices share (n-1) facets. For polyhedral cones, it must check that vector...
virtual void createBoundingSimplex(double M)
Initialize the truncating algorithm building a M-sized simplex around the polytope.
void clear()
Clear the whole list.
void next()
Iterator function.
void push_back(const GEOMETRIC_OBJECT &gn)
Include a new half space in the list.
unsigned int currentGeneratorNumber()
Iterator function.
PolyhedralCone_Rn()
Constructor.
void addGenerator(boost::shared_ptr< Generator_Rn > vx)
Add the given generator.