21 #ifndef UPDDOUBLEDESCRIPTION_Rn
22 #define UPDDOUBLEDESCRIPTION_Rn
54 std::vector< boost::shared_ptr<Generator_Rn_SD> > listOfGenSD;
58 poly->getListOfGeneratorsSD(listOfGenSD);
60 unsigned int nbHyp = 0, nbProcessHyp = 0;
61 {
for (ite.begin(); ite.end()!=
true; ite.next()) {
62 const boost::shared_ptr<HalfSpace_Rn>& currentHalfSpace = ite.current();
63 boost::shared_ptr<Hyperplane_Rn> currentHyp = boost::dynamic_pointer_cast<Hyperplane_Rn>(currentHalfSpace);
66 if (ite.currentIteratorNumber() < truncationStep)
80 poly->setListOfGeneratorsSD(listOfGenSD);
97 REDUNDANCY_PROCESSING redproc,
101 std::vector< boost::shared_ptr<Generator_Rn_SD> > listOfGenSD;
105 poly->getListOfGeneratorsSD(listOfGenSD);
107 unsigned int nbHyp = 0, nbProcessHyp = 0;
108 {
for (ite.begin(); ite.end()!=
true; ite.next()) {
109 const boost::shared_ptr<HalfSpace_Rn>& currentHalfSpace = ite.current();
110 boost::shared_ptr<Hyperplane_Rn> currentHyp = boost::dynamic_pointer_cast<Hyperplane_Rn>(currentHalfSpace);
113 if (ite.currentIteratorNumber() < truncationStep)
128 unsigned int nbRes=0;
129 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGenSD;
130 {
for (iteGenSD=listOfGenSD.begin(); iteGenSD!=listOfGenSD.end(); ++iteGenSD) {
134 unsigned int nbOp1 = (*iteGenSD)->getGeneratorNumber();
155 poly->setListOfGeneratorsSD(listOfGenSD);
174 std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_list,
175 const boost::shared_ptr<HalfSpace_Rn>& currentHalfSpace,
176 std::vector<double>& GN_IN_sp,
177 std::vector<double>& GN_OUT_sp,
178 std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_IN,
179 std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_OUT,
180 std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_ON)
182 int GeneratorNumber=0;
184 double halfSpaceNorm =
185 std::inner_product(currentHalfSpace->begin(), currentHalfSpace->end(), currentHalfSpace->begin(), 0.);
186 halfSpaceNorm = sqrt(halfSpaceNorm);
187 std::vector< boost::shared_ptr<Generator_Rn_SD> >::iterator iteGN;
188 for (iteGN=GN_list.begin(); iteGN!=GN_list.end(); ++iteGN) {
190 double scalarProduct =
191 std::inner_product((*iteGN)->begin(), (*iteGN)->end(), currentHalfSpace->begin(), 0.);
194 unsigned int RnDIM=currentHalfSpace->dimension();
195 std::cout.precision(15);
196 std::cout <<
"# V" << GeneratorNumber <<
" = [";
197 {
for (
unsigned int ii=0; ii<RnDIM; ii++) {
198 std::cout << (*iteGN)->getCoordinate(ii);
202 std::cout <<
"]" << std::endl <<
"{ ";
203 {
for (
unsigned int ii=0; ii<(*iteGN)->numberOfFacets(); ii++) {
204 std::cout << (*iteGN)->getFacet(ii) <<
" ";
206 std::cout <<
"}" << std::endl;
207 std::cout <<
"dotP = " << scalarProduct;
208 std::cout <<
", dist = " << (scalarProduct+currentHalfSpace->getConstant()) / halfSpaceNorm;
211 double distanceToHyperplane = (scalarProduct+currentHalfSpace->getConstant()) / halfSpaceNorm;
212 if (distanceToHyperplane > TOL) {
213 GN_IN.push_back((*iteGN));
214 GN_IN_sp.push_back(scalarProduct);
216 else if (distanceToHyperplane < -TOL) {
217 GN_OUT.push_back((*iteGN));
218 GN_OUT_sp.push_back(scalarProduct);
221 GN_ON.push_back((*iteGN));
225 if (distanceToHyperplane > TOL)
227 else if (distanceToHyperplane < -TOL)
238 bool compute(POLYHEDRON poly, ITERATOR iteHS,
int truncationStep, std::vector< boost::shared_ptr<Generator_Rn_SD> >& listOfGenSD) {
240 std::vector<double> GN_IN_sp;
241 std::vector<double> GN_OUT_sp;
243 std::vector< boost::shared_ptr<Generator_Rn_SD> > GN_IN;
244 std::vector< boost::shared_ptr<Generator_Rn_SD> > GN_OUT;
245 std::vector< boost::shared_ptr<Generator_Rn_SD> > GN_ON;
246 std::vector< boost::shared_ptr<Generator_Rn_SD> > GN_new;
248 std::vector< boost::shared_ptr<HalfSpace_Rn> > redundantHS;
249 int halfspaceNumber=truncationStep, generatorNumber=0;
250 unsigned int RnDIM=poly->dimension();
254 std::cout << std::endl <<
"UpdDoubleDescription::compute(" << truncationStep <<
")" << std::endl;
260 generatorNumber = poly->numberOfGenerators();
261 iteHS.setStep(truncationStep);
262 {
for (iteHS.begin(); iteHS.end()!=
true; iteHS.next()) {
263 const boost::shared_ptr<HalfSpace_Rn>& currentHalfSpace = iteHS.current();
264 boost::shared_ptr<Hyperplane_Rn> currentHyp = boost::dynamic_pointer_cast<Hyperplane_Rn>(currentHalfSpace);
271 double halfSpaceNorm = std::inner_product(currentHalfSpace->begin(), currentHalfSpace->end(), currentHalfSpace->begin(), 0.);
272 halfSpaceNorm = sqrt(halfSpaceNorm);
273 std::cout <<
"Facet number " << halfspaceNumber << std::endl;
274 std::cout <<
"H" << halfspaceNumber <<
" = ";
275 currentHalfSpace->dump(std::cout);
276 std::cout <<
", norm=" << halfSpaceNorm;
277 std::cout << std::endl;
281 computeVertexStates(listOfGenSD, currentHalfSpace, GN_IN_sp, GN_OUT_sp, GN_IN, GN_OUT, GN_ON);
285 if (currentHalfSpace->testEmptyness(GN_IN, GN_OUT, GN_ON)) {
288 std::cout <<
"Truncation is empty or flat." << std::endl;
296 if (GN_OUT.empty() ==
true) {
298 redundantHS.push_back(currentHalfSpace);
304 currentHalfSpace->noGeneratorsOUT(listOfGenSD, GN_ON);
306 std::cout <<
"VX_OUT= " << GN_OUT.size() << std::endl;
307 std::cout <<
"VX_IN = " << GN_IN.size() << std::endl;
308 std::cout <<
"VX_ON = " << GN_ON.size() << std::endl;
309 std::cout <<
"redundantHS = " << redundantHS.size() << std::endl;
310 std::cout <<
"============================================" << std::endl;
313 else if (GN_IN.empty() !=
true) {
318 unsigned int count_OUT=0;
319 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_OUT;
320 {
for (iteGN_OUT=GN_OUT.begin(); iteGN_OUT!=GN_OUT.end(); ++iteGN_OUT, ++count_OUT) {
321 unsigned int count_IN=0;
322 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_IN;
323 {
for (iteGN_IN=GN_IN.begin(); iteGN_IN!=GN_IN.end(); ++iteGN_IN, ++count_IN) {
324 std::vector< unsigned int > commonPFacets;
341 unsigned int count_ON=0;
342 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_ON;
343 {
for (iteGN_ON=GN_ON.begin(); iteGN_ON!=GN_ON.end(); ++iteGN_ON, ++count_ON) {
344 std::vector< unsigned int > commonPFacets;
362 unsigned int count_ON1=0;
363 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_ON1;
364 {
for (iteGN_ON1=GN_ON.begin(); iteGN_ON1!=GN_ON.end(); ++iteGN_ON1, ++count_ON1) {
365 unsigned int count_IN=0;
366 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_IN;
367 {
for (iteGN_IN=GN_IN.begin(); iteGN_IN!=GN_IN.end(); ++iteGN_IN, ++count_IN) {
368 std::vector< unsigned int > commonPFacets;
384 unsigned int count_ON2=0;
385 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_ON2;
386 {
for (iteGN_ON2=GN_ON.begin(); iteGN_ON2!=GN_ON.end(); ++iteGN_ON2, ++count_ON2) {
387 std::vector< unsigned int > commonPFacets;
388 if (iteGN_ON1 != iteGN_ON2 &&
407 for (newGeneratorsTool.
begin(); newGeneratorsTool.
end()!=
true; newGeneratorsTool.
next()) {
415 const boost::shared_ptr<Generator_Rn_SD>& currentGeneratorIn = GN_IN[newGeneratorsTool.
currentGenInNumber()];
416 const boost::shared_ptr<Generator_Rn_SD>& currentGeneratorOut = GN_OUT[newGeneratorsTool.
currentGenOutNumber()];
420 poly->createTruncatedGenerator(currentGeneratorOut, currentGeneratorIn, newV, ay, az, currentHalfSpace->getConstant());
422 std::vector< unsigned int > commonFacets;
425 newV->setAllFacets(commonFacets);
431 std::set< unsigned int > setOfFacets;
432 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_ON_eq;
433 {
for (iteGN_ON_eq=GN_ON.begin(); iteGN_ON_eq!=GN_ON.end() && notEq==
true; ++iteGN_ON_eq) {
434 if ((*iteGN_ON_eq)->isEqual2(newV, RnDIM, TOL2)) {
438 newV->exportFacets(setOfFacets);
439 (*iteGN_ON_eq)->exportFacets(setOfFacets);
440 (*iteGN_ON_eq)->importFacets(setOfFacets);
441 (*iteGN_ON_eq)->orderFacets();
444 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_NEW_eq;
445 {
for (iteGN_NEW_eq=GN_new.begin(); iteGN_NEW_eq!=GN_new.end() && notEq==
true; ++iteGN_NEW_eq) {
446 if ((*iteGN_NEW_eq)->isEqual2(newV, RnDIM, TOL2)) {
449 newV->setFacet(halfspaceNumber);
450 newV->exportFacets(setOfFacets);
451 (*iteGN_NEW_eq)->exportFacets(setOfFacets);
452 (*iteGN_NEW_eq)->importFacets(setOfFacets);
453 (*iteGN_NEW_eq)->orderFacets();
457 newV->setFacet(halfspaceNumber);
458 GN_new.push_back(newV);
460 std::cout <<
"New Generator = [";
461 newV->save(std::cout);
462 std::cout <<
"] GeneratorIN [";
463 currentGeneratorIn->save(std::cout);
464 std::cout <<
"], VX_IN_sp=" << az <<
" GeneratorOUT [";
465 currentGeneratorOut->save(std::cout);
466 std::cout <<
"], VX_OUT_sp=" << ay << std::endl;
471 std::cout <<
"No new Generator as [";
472 newV->save(std::cout);
473 std::cout <<
"] is equal to a previous one." << std::endl;
479 std::cout <<
"VX_OUT= " << GN_OUT.size() << std::endl;
480 std::cout <<
"VX_IN = " << GN_IN.size() << std::endl;
481 std::cout <<
"VX_ON = " << GN_ON.size() << std::endl;
482 std::cout <<
"redundantHS = " << redundantHS.size() << std::endl;
483 std::cout <<
"============================================" << std::endl;
489 currentHalfSpace->prepareSetOfGenerators(GN_IN, GN_OUT);
492 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_ON;
493 for (iteGN_ON=GN_ON.begin(); iteGN_ON!=GN_ON.end(); ++iteGN_ON) {
494 (*iteGN_ON)->setFacet(halfspaceNumber);
500 GN_IN.push_back(*iteGN_ON);
506 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_new;
507 for (iteGN_new=GN_new.begin(); iteGN_new!=GN_new.end(); ++iteGN_new) {
509 GN_IN.push_back(*iteGN_new);
517 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_OUT;
518 for (iteGN_OUT=GN_OUT.begin(); iteGN_OUT!=GN_OUT.end(); ++iteGN_OUT) {
563 const boost::shared_ptr<Generator_Rn>& genIn,
564 const boost::shared_ptr<Generator_Rn>& genOut,
565 std::vector< boost::shared_ptr<HalfSpace_Rn> >& commonFacets) {
566 return poly->checkNeighbours(genIn, genOut, commonFacets);
572 const boost::shared_ptr<Generator_Rn_SD>& genIn,
573 const boost::shared_ptr<Generator_Rn_SD>& genOut,
574 std::vector< unsigned int >& commonFacets) {
575 return poly->checkNeighbours(genIn, genOut, commonFacets);
582 const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_ON) {}
587 const boost::shared_ptr<Generator_Rn>& genIn,
588 const boost::shared_ptr<Generator_Rn>& genOut,
589 std::vector< HalfSpace_Rn* >& commonFacets) {
590 return poly->checkNeighbours(genIn, genOut, commonFacets);
615 void dumpSD(std::ostream &this_stream) {}
634 std::vector< unsigned int >&,
635 std::set< unsigned int >& getListOfRedundantHS) {
648 {
for (
unsigned int j=0; j<nbHS; ++j) {
660 {
for (
unsigned int j=0; j<nbHS; ++j) {
661 std::set< unsigned int > genSet;
664 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator constITER_GN;
665 for (constITER_GN=LG.begin(); constITER_GN!=LG.end(); ++constITER_GN) {
666 {
for (
unsigned int j=0; j<(*constITER_GN)->numberOfFacets(); j++) {
667 unsigned int F = (*constITER_GN)->getFacet(j);
678 std::set< unsigned int > genSet;
693 const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_ON) {
694 std::vector< boost::shared_ptr<Generator_Rn_SD> >::const_iterator iteGN_ON;
695 for (iteGN_ON=GN_ON.begin(); iteGN_ON!=GN_ON.end(); ++iteGN_ON)
701 for (
unsigned int l=0; l<GEN->numberOfFacets(); ++l) {
708 for (
unsigned int l=0; l<GEN->numberOfFacets(); ++l) {
717 const boost::shared_ptr<Generator_Rn_SD>& genIn,
718 const boost::shared_ptr<Generator_Rn_SD>& genOut,
719 std::vector< unsigned int >& commonFacets) {
721 std::set_intersection(genIn->facetsBegin(), genIn->facetsEnd(), genOut->facetsBegin(), genOut->facetsEnd(),
722 std::inserter(commonFacets, commonFacets.end()));
733 unsigned int thisRedundantHS,
unsigned int numberOfGeneratorsPerFacetWithoutHyp) {
737 std::vector< boost::shared_ptr<Generator_Rn_SD> >::iterator itGN = listOfGen.begin();
738 while (itGN != listOfGen.end() || allGenForThisRedundantHS.empty() ==
false) {
739 if (allGenForThisRedundantHS.find((*itGN)->getGeneratorNumber()) != allGenForThisRedundantHS.end()) {
742 unsigned int indexOfFacet = 0;
743 while ((*itGN)->getFacet(indexOfFacet) < thisRedundantHS)
745 if ((*itGN)->getFacet(indexOfFacet) == thisRedundantHS) {
746 (*itGN)->removeFacet(indexOfFacet);
749 std::cerr <<
"indexOfGen = " << itGN-listOfGen.begin() << std::endl;
750 std::cerr <<
"indexOfFacet = " << indexOfFacet<< std::endl;
751 std::cerr << (*itGN)->vect() << std::endl;
752 std::cerr <<
"thisRedundantHS = " << thisRedundantHS << std::endl;
753 std::string errorMessage(
"StrongRedundancyProcessing::unhookThisRedundantHalfSpace() Facet not found.");
754 throw std::out_of_range(errorMessage);
756 allGenForThisRedundantHS.erase((*itGN)->getGeneratorNumber() );
758 if ((*itGN)->numberOfFacets() < numberOfGeneratorsPerFacet) {
759 unsigned int genNb = (*itGN)->getGeneratorNumber();
761 for (
unsigned int idFct=0; idFct<(*itGN)->numberOfFacets(); ++idFct) {
768 itGN = listOfGen.erase(itGN);
779 std::cerr << std::endl <<
"Remaining generators: ";
781 std::cerr << std::endl;
782 std::string errorMessage(
"StrongRedundancyProcessing::unhookThisRedundantHalfSpace() Remaining generators.");
783 throw std::domain_error(errorMessage);
809 std::cout <<
"Redundant " << i;
810 std::cout << std::endl;
827 std::vector< std::set< unsigned int > >::const_iterator it_1, it_2;
833 if (it_1->size() > it_2->size()) {
834 if (std::includes(it_1->begin(), it_1->end(), it_2->begin(), it_2->end())) {
839 std::cout <<
"New redundant facet: " << i2 << std::endl;
843 else if (it_1->size() < it_2->size()) {
844 if (std::includes(it_2->begin(), it_2->end(), it_1->begin(), it_1->end())) {
849 std::cout <<
"New redundant facet: " << i1 << std::endl;
869 {
for (iteHS.
begin(), hsNb=0; iteHS.
end()!=
true; iteHS.
next(), ++hsNb) {
874 boost::shared_ptr<Generator_Rn> gen = iteGN.
current();
875 {
for (
int j=gen->numberOfFacets()-1; j>=0; j--) {
876 if (iteHS.
current() == gen->getFacet(j))
886 {
for (iteHS2.
begin(), hsNb=0; iteHS2.
end()!=
true; iteHS2.
next(), ++hsNb) {
899 std::vector< unsigned int > HS2Remove;
900 std::set< unsigned int >::const_iterator it;
903 std::cout << *it <<
" ";
905 HS2Remove.push_back(*it);
907 std::sort(HS2Remove.begin(), HS2Remove.end(), std::greater<unsigned int>());
908 std::vector< unsigned int >::const_iterator it2;
909 {
for (it2=HS2Remove.begin(); it2!=HS2Remove.end(); ++it2) {
911 poly->removeHalfSpace(*it2);
914 std::cout << std::endl;
922 unsigned int minNbFacetsPerGen = poly->neigbourhoodCondition() + 1;
923 std::set< boost::shared_ptr<Generator_Rn> > setToRemove;
927 if (iteGN.
current()->numberOfFacets() < minNbFacetsPerGen) {
928 setToRemove.insert( iteGN.
current() );
932 if (!setToRemove.empty())
933 poly->removeGenerators(setToRemove);
941 for (
unsigned int i=0; i<truncationStep; ++i)
951 unsigned int RnDIM=poly->dimension();
952 this_stream <<
"List of redundant half-spaces :" << std::endl;
956 {
for (iteHS.
begin(), hsNb=0; iteHS.
end()!=
true; iteHS.
next(), ++hsNb) {
958 boost::shared_ptr<HalfSpace_Rn> currentHalfSpace = iteHS.
current();
959 this_stream <<
"H = (" << currentHalfSpace->getConstant() <<
", ";
960 {
for (
unsigned int ii=0; ii<RnDIM; ii++) {
961 this_stream << currentHalfSpace->getCoefficient(ii);
965 this_stream <<
")" << std::endl;
972 std::vector< std::set< unsigned int > >::const_iterator iteGHS;
973 this_stream <<
"*** number(HalfSpace_Rn0) => {Generator_Rn0*, Generator_Rn1*, Generator_Rn2*, ...}" << std::endl;
974 unsigned int counter=0;
976 this_stream << counter <<
" => { ";
977 std::copy(iteGHS->begin(), iteGHS->end(), std::ostream_iterator<unsigned int>(std::cout,
" ") );
978 this_stream <<
"}" << std::endl;
983 this_stream << std::endl;
984 this_stream <<
"*** list of redundant half-spaces : ";
986 this_stream << std::endl;