28 #include <boost/shared_ptr.hpp>
29 #include <boost/numeric/ublas/vector.hpp>
30 #include <boost/numeric/ublas/io.hpp>
35 using namespace boost::numeric::ublas;
61 double getCoefficient(
unsigned int i)
const;
63 void setCoefficient(
unsigned int i,
double c);
69 void negate() {_coefficients *= -1.;}
71 int dimension()
const {
return _coefficients.size();}
75 boost::numeric::ublas::vector<double>::const_iterator
begin()
const {
return _coefficients.begin();}
77 boost::numeric::ublas::vector<double>::const_iterator
end()
const {
return _coefficients.end();}
79 const boost::numeric::ublas::vector<double>&
vect()
const {
return _coefficients;}
84 double halfSpaceNorm = std::inner_product(_coefficients.begin(), _coefficients.end(), _coefficients.begin(), 0.);
85 halfSpaceNorm = sqrt(halfSpaceNorm);
86 double scalarProduct = std::inner_product(thisPoint.begin(), thisPoint.end(), _coefficients.begin(), 0.);
87 double distanceToHyperplane = (scalarProduct+_constant) / halfSpaceNorm;
88 return distanceToHyperplane;
92 double scalarProduct = std::inner_product(thisPoint.begin(), thisPoint.end(), _coefficients.begin(), 0.);
93 double distanceToHyperplane = (scalarProduct+_constant) / halfSpaceNorm;
94 return distanceToHyperplane;
98 const boost::numeric::ublas::vector<double>& thisPoint,
99 boost::numeric::ublas::vector<double>& projectedPoint,
100 double halfSpaceNorm)
const {
101 double scalarProduct = std::inner_product(thisPoint.begin(), thisPoint.end(), _coefficients.begin(), 0.);
102 double distanceToHyperplane = (scalarProduct+_constant) / halfSpaceNorm;
103 projectedPoint = thisPoint - distanceToHyperplane*_coefficients;
104 return distanceToHyperplane;
107 virtual void dump(std::ostream &this_ostream)
const {
108 this_ostream <<
"(" << getConstant() <<
", ";
109 unsigned int RnDIM = _coefficients.size();
110 {
for (
unsigned int ii=0; ii<RnDIM; ++ii) {
111 this_ostream << getCoefficient(ii);
113 this_ostream <<
", ";
120 std::cout << std::endl;
125 virtual bool testEmptyness(
const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_IN,
126 const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_OUT,
127 const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_ON) {
129 return (GN_IN.empty());
134 virtual bool testEmptyness(
unsigned int GN_IN,
unsigned int GN_OUT,
unsigned int GN_ON) {
143 virtual void noGeneratorsOUT(std::vector< boost::shared_ptr<Generator_Rn_SD> >& listOfGeneratorSD,
144 const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_ON) {
158 virtual void prepareSetOfGenerators(std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_IN, std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_OUT) {
176 _coefficients = HS.
vect();
178 double halfSpaceNorm = sqrt(std::inner_product(_coefficients.begin(), _coefficients.end(), _coefficients.begin(), 0.));
179 _coefficients = _coefficients / halfSpaceNorm;
180 _constant = _constant / halfSpaceNorm;
197 virtual void dump(std::ostream &this_ostream)
const {
198 this_ostream <<
"(" << getConstant() <<
"; ";
199 unsigned int RnDIM = _coefficients.size();
200 {
for (
unsigned int ii=0; ii<RnDIM; ++ii) {
201 this_ostream << getCoefficient(ii);
203 this_ostream <<
"; ";
210 virtual bool testEmptyness(
const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_IN,
211 const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_OUT,
212 const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_ON) {
214 return ((GN_IN.empty() && GN_ON.empty()) || (GN_OUT.empty() && GN_ON.empty()));
219 virtual bool testEmptyness(
unsigned int GN_IN,
unsigned int GN_OUT,
unsigned int GN_ON) {
221 return ((GN_IN==0 && GN_ON==0) || (GN_OUT==0 && GN_ON==0));
228 virtual void noGeneratorsOUT(std::vector< boost::shared_ptr<Generator_Rn_SD> >& listOfGeneratorSD,
229 const std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_ON) {
231 listOfGeneratorSD = GN_ON;
244 virtual void prepareSetOfGenerators(std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_IN, std::vector< boost::shared_ptr<Generator_Rn_SD> >& GN_OUT) {
246 GN_OUT.insert(GN_OUT.end(), GN_IN.begin(), GN_IN.end());
252 #endif // HALFSPACE_Rn