24 #include <boost/shared_ptr.hpp>
46 static boost::shared_ptr<Polytope_Rn>
create() {
return boost::shared_ptr<Polytope_Rn>(
new Polytope_Rn); }
69 bool checkEqualityOfVertices(
const boost::shared_ptr<Polytope_Rn>& B,
bool printOnScreen =
false)
const;
74 const boost::shared_ptr<Generator_Rn_SD>& in,
75 const boost::shared_ptr<Generator_Rn_SD>& out,
76 boost::shared_ptr<Generator_Rn_SD> newV,
double ay,
double az,
double b=0.)
const;
78 boost::shared_ptr<PolyhedralCone_Rn> getPrimalCone(
unsigned int u,
const std::vector<unsigned int>& allNgb)
const;
82 boost::shared_ptr<PolyhedralCone_Rn> getPrimalCone(
unsigned int i)
const;
84 boost::shared_ptr<Polytope_Rn> sum(
const boost::shared_ptr<Polytope_Rn>& pol2sum) ;
86 boost::shared_ptr<Polytope_Rn> intersect(
const boost::shared_ptr<Polytope_Rn>& pol2intersect) ;
88 bool isIncluded(
const boost::shared_ptr<Polytope_Rn>& B)
const {
90 {
for (iteHS_B.
begin(); iteHS_B.
end()!=
true; iteHS_B.
next()) {
91 double halfSpaceNorm = std::inner_product(iteHS_B.
current()->begin(), iteHS_B.
current()->end(), iteHS_B.
current()->begin(), 0.);
92 halfSpaceNorm = sqrt(halfSpaceNorm);
94 {
for (iteGN_A.
begin(); iteGN_A.
end()!=
true; iteGN_A.
next()) {
103 bool isIncluded(
const boost::shared_ptr<Polytope_Rn>& B,
double& minmaxDistance)
const {
106 double maxDist = std::numeric_limits<double>::min();
107 double minDist = std::numeric_limits<double>::max();
109 {
for (iteHS_B.
begin(); iteHS_B.
end()!=
true; iteHS_B.
next()) {
110 double halfSpaceNorm = std::inner_product(iteHS_B.
current()->begin(), iteHS_B.
current()->end(), iteHS_B.
current()->begin(), 0.);
111 halfSpaceNorm = sqrt(halfSpaceNorm);
113 {
for (iteGN_A.
begin(); iteGN_A.
end()!=
true; iteGN_A.
next()) {
114 double scalarProduct = std::inner_product(iteGN_A.
current()->begin(), iteGN_A.
current()->end(), iteHS_B.
current()->begin(), 0.);
115 double distanceToHyperplane = (scalarProduct+iteHS_B.
current()->getConstant()) / halfSpaceNorm;
118 if (distanceToHyperplane < -TOL) {
121 double opp = -distanceToHyperplane;
127 if (distanceToHyperplane < 0.)
128 distanceToHyperplane = -distanceToHyperplane;
129 if (distanceToHyperplane < minDist)
130 minDist = distanceToHyperplane;
136 minmaxDistance = maxDist;
140 minmaxDistance = minDist;
144 std::string
getName()
const {
return std::string(
"Polytope");}
166 void setPolytope(boost::shared_ptr<Polytope_Rn> pol) {_polytope = pol;}
174 {
for (
unsigned int i=0; i<_polytope->numberOfHalfSpaces(); ++i) {
175 if (_operandCaps.find(i) == _operandCaps.end())
176 _prismaticPolyhedron->addHalfSpace( _polytope->getHalfSpace(i) );
178 return _prismaticPolyhedron;
184 for (
unsigned int i=0; i<_polytope->numberOfHalfSpaces(); ++i) {
185 _polytope->getHalfSpace(i)->setConstant(cst);
188 if (_prismaticPolyhedron) {
189 for (
unsigned int i=0; i<_prismaticPolyhedron->numberOfHalfSpaces(); ++i) {
190 _prismaticPolyhedron->getHalfSpace(i)->setConstant(cst);
198 if (fctNb >= _polytope->numberOfHalfSpaces())
199 throw std::out_of_range(
"CappedPolytope_Rn::resetConstantOfGivenHalfSpace() polytope index out of range");
200 _polytope->getHalfSpace(fctNb)->setConstant(cst);
202 if (_prismaticPolyhedron) {
203 if (fctNb >= _prismaticPolyhedron->numberOfHalfSpaces())
204 throw std::out_of_range(
"CappedPolytope_Rn::resetConstantOfGivenHalfSpace() prismaticPolyhedron index out of range");
205 _prismaticPolyhedron->getHalfSpace(fctNb)->setConstant(cst);
211 boost::shared_ptr<CappedPolytope_Rn> sum(
const boost::shared_ptr<CappedPolytope_Rn>& pol2sum,
double bb_size=1000.) ;
214 void sum(
const std::vector< boost::shared_ptr<CappedPolytope_Rn> >& allPolytopes0) {
215 std::vector< boost::shared_ptr<CappedPolytope_Rn> > allPolytopes = allPolytopes0;
216 {
for (
unsigned int i=0; i<allPolytopes.size()-1; ++i) {
218 currentSum = allPolytopes[i]->sum(allPolytopes[i+1]);
220 if (i == allPolytopes.size()-2) {
221 _operandCaps = currentSum->_operandCaps;
222 _polytope = currentSum->_polytope;
225 allPolytopes[i+1] = currentSum;
229 void intersect(
const std::vector< boost::shared_ptr<CappedPolytope_Rn> >& allPolytopes0) {
230 std::vector< boost::shared_ptr<CappedPolytope_Rn> > allPolytopes = allPolytopes0;
231 {
for (
unsigned int i=0; i<allPolytopes.size()-1; ++i) {
233 currentInt = allPolytopes[i]->intersect(allPolytopes[i+1]);
235 if (i == allPolytopes.size()-2) {
236 _operandCaps = currentInt->_operandCaps;
237 _polytope = currentInt->_polytope;
240 allPolytopes[i+1] = currentInt;
244 boost::shared_ptr<CappedPolytope_Rn> intersect(
const boost::shared_ptr<CappedPolytope_Rn>& pol2intersect) ;
246 bool isIncluded(
const boost::shared_ptr<CappedPolytope_Rn>& B)
const {
return _polytope->isIncluded(B->_polytope); }
253 static bool isIncluded(
const boost::shared_ptr<CappedPolytope_Rn>& firstBody,
const boost::shared_ptr<CappedPolytope_Rn>& secondBody,
double& minmaxDistance) {
254 return firstBody->_polytope->isIncluded(secondBody->_polytope, minmaxDistance);
257 int scalingFactor(
double factor);
261 void save(
const std::string& pathA);
263 void load(
const std::string& pathA,
double bb_size=10000.);
265 void dump(std::ostream ¤t_ostream)
const {
266 current_ostream << std::endl <<
"#CAPPED FACETS:" << std::endl;
267 std::copy(_operandCaps.begin(), _operandCaps.end(), std::ostream_iterator<unsigned int>(current_ostream,
" ") );
268 current_ostream << std::endl;
269 _polytope->dump(current_ostream);
272 static std::string
getName() {
return std::string(
"CappedPolytope");}
287 #endif // POLYTOPE_Rn