34 std::cout <<
"Check edges.......... ";
36 bool checkEdgesOK =
true;
41 std::vector< boost::shared_ptr<HalfSpace_Rn> > commonFacets;
44 std::vector<double> edge(RnDIM);
45 for (
unsigned int k=0; k<RnDIM; k++)
46 edge[k] = V1->getCoordinate(k) - V2->getCoordinate(k);
47 unsigned int countFacets = 0;
48 double scalarProduct = 0.;
49 for (
unsigned int l=0; l<commonFacets.size(); l++) {
50 for (
unsigned int n=0; n<RnDIM; n++)
51 scalarProduct = scalarProduct + edge[n]*commonFacets[l]->getCoefficient(n);
53 std::cout <<
"\t### Edge for generators " << i <<
" and " << j <<
" not on facet (";
54 {
for (
unsigned int jj=0; jj<RnDIM; jj++) {
55 std::cout << commonFacets[l]->getCoefficient(jj) <<
" ";
57 std::cout << commonFacets[l]->getSideAsText() <<
" " << commonFacets[l]->getConstant();
59 std::cout <<
") " << std::endl;
66 if (countFacets < RnDIM-1) {
67 std::cout <<
"\t### Edge for generators " << i <<
" and " << j <<
" has not enough facets" << std::endl;
73 if (checkEdgesOK ==
true)
74 std::cout <<
"OK" << std::endl;
83 unsigned int currentNumberOfFacets = (
unsigned int)
dimension()+1;
84 unsigned int currentNumberOfGenerators = (
unsigned int)
dimension()+1;
88 {
for (
unsigned int vtx_count=0; vtx_count<currentNumberOfGenerators; vtx_count++) {
89 boost::shared_ptr<Generator_Rn> VX;
95 {
for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
96 {
for (
unsigned int vtx_count=0; vtx_count<currentNumberOfGenerators; vtx_count++) {
98 if (vtx_count==coord_count && vtx_count<currentNumberOfGenerators-1)
99 getGenerator(vtx_count)->setCoordinate(coord_count, MAX);
101 getGenerator(vtx_count)->setCoordinate(coord_count, MIN);
105 std::vector< boost::shared_ptr<HalfSpace_Rn> > supportFacets;
107 {
for (
unsigned int facet_count=0; facet_count<currentNumberOfFacets-1; facet_count++) {
108 boost::shared_ptr<HalfSpace_Rn> HalfSp(
new HalfSpace_Rn(dim));
109 {
for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
110 if (facet_count == coord_count)
111 HalfSp->setCoefficient(coord_count, 1.);
113 HalfSp->setCoefficient(coord_count, 0.);
115 HalfSp->setConstant(M);
116 supportFacets.push_back(HalfSp);
119 getGenerator(currentNumberOfGenerators-1)->setFacet(HalfSp);
122 boost::shared_ptr<HalfSpace_Rn> oblicHalfSp(
new HalfSpace_Rn(dim));
123 {
for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
124 oblicHalfSp->setCoefficient(coord_count, -1.);
127 supportFacets.push_back(oblicHalfSp);
130 supportFacets.push_back(iteH.
current());
133 std::vector< boost::shared_ptr<HalfSpace_Rn> >::const_iterator itF;
134 {
for (itF=supportFacets.begin(); itF!=supportFacets.end();++itF) {
138 {
for (
unsigned int vtx_count1=0; vtx_count1<currentNumberOfGenerators-1; vtx_count1++) {
139 boost::shared_ptr<Generator_Rn> VX1 =
getGenerator(vtx_count1);
140 VX1->setFacet(oblicHalfSp);
141 {
for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
142 if (VX1->getCoordinate(coord_count) == MIN) {
157 unsigned int currentNumberOfGenerators = (
unsigned int)pow(
static_cast<double>(2),
static_cast<int>(dim));
161 for (
unsigned int vtx_count=0; vtx_count<currentNumberOfGenerators; vtx_count++) {
162 boost::shared_ptr<Generator_Rn> VX;
167 for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
169 for (
unsigned int vtx_count=0; vtx_count<currentNumberOfGenerators; vtx_count++) {
170 if (counter >= pow(
static_cast<double>(2),
static_cast<int>(coord_count))) {
174 getGenerator(vtx_count)->setCoordinate(coord_count, MAX);
179 std::vector< boost::shared_ptr<HalfSpace_Rn> > supportFacets;
181 for (
unsigned int facet_count=0; facet_count<dim; facet_count++) {
182 boost::shared_ptr<HalfSpace_Rn> HalfSp(
new HalfSpace_Rn(dim));
183 for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
184 if (facet_count == coord_count)
185 HalfSp->setCoefficient(coord_count, -1.);
187 HalfSp->setCoefficient(coord_count, 0.);
189 HalfSp->setConstant(M);
190 supportFacets.push_back(HalfSp);
193 for (
unsigned int facet_count=0; facet_count<dim; facet_count++) {
194 boost::shared_ptr<HalfSpace_Rn> HalfSp(
new HalfSpace_Rn(dim));
195 for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
196 if (facet_count == coord_count)
197 HalfSp->setCoefficient(coord_count, 1.);
199 HalfSp->setCoefficient(coord_count, 0.);
201 HalfSp->setConstant(M);
202 supportFacets.push_back(HalfSp);
206 supportFacets.push_back(iteH.
current());
209 std::vector< boost::shared_ptr<HalfSpace_Rn> >::const_iterator itF;
210 {
for (itF=supportFacets.begin(); itF!=supportFacets.end();++itF) {
214 for (
unsigned int vtx_count1=0; vtx_count1<currentNumberOfGenerators; vtx_count1++) {
215 boost::shared_ptr<Generator_Rn> VX1 =
getGenerator(vtx_count1);
216 for (
unsigned int coord_count=0; coord_count<dim; coord_count++) {
217 if (VX1->getCoordinate(coord_count) == M)
219 else if (VX1->getCoordinate(coord_count) == -M)
227 const boost::shared_ptr<Generator_Rn_SD>& out,
228 const boost::shared_ptr<Generator_Rn_SD>& in,
229 boost::shared_ptr<Generator_Rn_SD> newV,
double ay,
double az,
double b)
const {
231 double t = (-b-az) / (ay-az);
237 newV->makeDiff(out, in);
238 newV->makeCoefSum(in, newV, 1., t);
246 std::vector<bool> vtxOfB(B->numberOfGenerators());
247 for (
unsigned int i=0; i<vtxOfA.size(); ++i)
249 for (
unsigned int i=0; i<vtxOfB.size(); ++i)
253 {
for (iteGN_A.
begin(); iteGN_A.
end()!=
true; iteGN_A.
next()) {
254 {
for (iteGN_B.
begin(); iteGN_B.
end()!=
true; iteGN_B.
next()) {
255 if (iteGN_A.
current()->isEqual2(iteGN_B.
current(), RnDIM, TOL2)) {
261 bool AinsideB =
true, BinsideA =
true;
262 {
for (
unsigned int i=0; i<vtxOfA.size(); ++i) {
263 if (vtxOfA[i] ==
false) {
268 {
for (
unsigned int i=0; i<vtxOfB.size(); ++i) {
269 if (vtxOfB[i] ==
false) {
274 if (printOnScreen ==
true) {
275 if (AinsideB ==
true)
276 std::cout <<
"The set of vertices of A in included in the set of vertices of B." << std::endl;
277 if (BinsideA ==
true)
278 std::cout <<
"The set of vertices of B in included in the set of vertices of A." << std::endl;
281 return (AinsideB && BinsideA);
286 throw std::out_of_range(
"Polytope_Rn::getPrimalCone() index out of range");
289 boost::shared_ptr<PolyhedralCone_Rn> primalCone;
295 for (
unsigned int i=0; i<vx1->numberOfFacets(); i++) {
296 primalCone->addHalfSpace(vx1->getFacet(i));
299 std::vector<unsigned int>::const_iterator ngb;
300 for (ngb=allNgb.begin(); ngb!=allNgb.end(); ngb++) {
301 boost::shared_ptr<Generator_Rn> vx2 =
getGenerator(*ngb);
303 boost::shared_ptr<Generator_Rn> edge12(
new Generator_Rn(RnDIM));
304 edge12->makeDiff(vx2, vx1);
306 std::vector< boost::shared_ptr<HalfSpace_Rn> > commonFacets;
309 for (
unsigned int j=0; j<commonFacets.size(); ++j) {
310 boost::shared_ptr<HalfSpace_Rn> Fj = commonFacets[j];
311 edge12->setFacet(Fj);
314 primalCone->addGenerator(edge12);
320 boost::shared_ptr<Polytope_Rn>
Polytope_Rn::sum(
const boost::shared_ptr<Polytope_Rn>& pol2sum) {
321 boost::shared_ptr<Polytope_Rn> currentSum(
new Polytope_Rn());
322 boost::shared_ptr<Polytope_Rn> operand1(
this);
324 currentSum->checkTopologyAndGeometry();
329 boost::shared_ptr<Polytope_Rn> C(
new Polytope_Rn()), A(
this);
332 for (iteHS0.
begin(); iteHS0.
end()!=
true; iteHS0.
next()) {
333 C->addGenerator(iteHS0.
current());
337 for (iteHS1.
begin(); iteHS1.
end()!=
true; iteHS1.
next()) {
338 C->addHalfSpace(iteHS1.
current());
342 for (iteHS2.
begin(); iteHS2.
end()!=
true; iteHS2.
next()) {
343 C->addHalfSpace(iteHS2.
current());
345 unsigned int truncationStep = A->numberOfHalfSpaces();
350 boost::shared_ptr<Polytope_Rn>,
353 DD(C, lexmin_ite, truncationStep);
354 C->checkTopologyAndGeometry();
358 boost::shared_ptr<CappedPolytope_Rn>
CappedPolytope_Rn::sum(
const boost::shared_ptr<CappedPolytope_Rn>& pol2sum,
double bb_size) {
359 std::set< unsigned int > newCaps;
360 boost::shared_ptr<Polytope_Rn> C(
new Polytope_Rn());
361 boost::shared_ptr<Polytope_Rn> A(this->
_polytope);
363 boost::shared_ptr<CappedPolytope_Rn> finalSum(
new CappedPolytope_Rn(C, newCaps) );
368 std::set< unsigned int > newCaps;
369 boost::shared_ptr<Polytope_Rn> C(
new Polytope_Rn());
370 boost::shared_ptr<Polytope_Rn> A(this->
_polytope);
372 boost::shared_ptr<CappedPolytope_Rn> finalSum(
new CappedPolytope_Rn(C, newCaps) );
397 cube->addHalfSpace(iteHS1.
current());
408 unsigned int truncationStep = 2*
_polytope->dimension();
410 boost::shared_ptr<Polytope_Rn>,
413 DD(
_polytope, lexmin_ite, truncationStep);
418 unsigned int polFacetNb = 0;
419 for (allPolHS.
begin(); allPolHS.
end()!=
true; allPolHS.
next()) {
420 bool isEqual =
false;
421 for (allCubeHS.
begin(); allCubeHS.
end()!=
true; allCubeHS.
next()) {
433 boost::shared_ptr<Polytope_Rn> loadedPolytope(
new Polytope_Rn());
435 for (allPolHS.
begin(); allPolHS.
end()!=
true; allPolHS.
next()) {
437 loadedPolytope->addHalfSpace(allPolHS.
current());