4 #include "ocra/optim/FunctionProperties.h" 24 SubtractionFunction::SubtractionFunction(Function* f,
const Vector& v)
25 : Function(f->getVariable(), f->getDimension(), f->getType(), f->getConvexityProperty(),
26 f->getContinuityProperty(), f->canComputeHessian(), f->canComputeGradient())
27 , _f1(f), _v2(v), _f2(NULL), _case(1)
33 SubtractionFunction::SubtractionFunction(
const Vector& v, Function* f)
35 f->getContinuityProperty(), f->canComputeHessian(), f->canComputeGradient())
36 , _f2(f), _v1(v), _f1(NULL), _case(2)
68 throw std::runtime_error(
"[ocra::SubtractionFunction::changeV]: no vector involved in this SubtractionFunction");
71 _v2.copyValuesFrom(v);
75 _v1.copyValuesFrom(v);
88 _value.copyValuesFrom(_f1->getValues());
89 CML_axpy(-1., _f2->getValues(), _value);
92 _value.copyValuesFrom(_v2);
93 CML_axpy(1., _f1->getValues(), _value);
96 _value.copyValuesFrom(_v1);
97 CML_axpy(-1., _f2->getValues(), _value);
108 _gradient.copyValuesFrom(_f1->getGradients());
109 for (cfl_size_t i=0; i<_gradient.get_ncols(); ++i)
111 VectorWrap gradientColumn = _gradient.getColumnAsVector(i);
112 CML_axpy(-1., _f2->getGradients().getColumnAsVector(i), gradientColumn);
116 _gradient.copyValuesFrom(_f1->getGradients());
119 _gradient.copyValuesFrom(_f2->getGradients());
120 _gradient.scalarMultInPlace(-1.);
131 for (cfl_size_t i=0; i<_dimension; ++i)
133 (
const_cast<Matrix*
>(_hessians[i]))->copyValuesFrom(*_f1->getHessian(i));
134 for (cfl_size_t j=0; j<_gradient.get_ncols(); ++j)
136 VectorWrap f2HessianColumn = (
const_cast<Matrix*
>(_f2->getHessian(i)))->getColumnAsVector(j);
137 VectorWrap hessianIColumn = (
const_cast<Matrix*
>(_hessians[i]))->getColumnAsVector(j);
138 CML_axpy(-1., f2HessianColumn, hessianIColumn);
143 for (cfl_size_t i=0; i<_dimension; ++i)
144 (const_cast<Matrix*>(_hessians[i]))->copyValuesFrom(*_f1->getHessian(i));
147 for (cfl_size_t i=0; i<_dimension; ++i)
149 (
const_cast<Matrix*
>(_hessians[i]))->copyValuesFrom(*_f2->getHessian(i));
150 (
const_cast<Matrix*
>(_hessians[i]))->scalarMultInPlace(-1.);
162 _Jdot.copyValuesFrom(_f1->getJdot());
163 for (cfl_size_t i=0; i<_Jdot.get_ncols(); ++i)
165 VectorWrap gradientColumn = _Jdot.getColumnAsVector(i);
166 CML_axpy(-1., _f2->getJdot().getColumnAsVector(i), gradientColumn);
170 _Jdot.copyValuesFrom(_f1->getJdot());
173 _Jdot.copyValuesFrom(_f2->getJdot());
174 _Jdot.scalarMultInPlace(-1.);
185 _JdotXdot.copyValuesFrom(_f1->getJdotXdot());
186 CML_axpy(-1., _f2->getJdotXdot(), _JdotXdot);
189 _JdotXdot.copyValuesFrom(_v2);
190 CML_axpy(1., _f1->getJdotXdot(), _JdotXdot);
193 _JdotXdot.copyValuesFrom(_v1);
194 CML_axpy(-1., _f2->getJdotXdot(), _JdotXdot);
205 void SubtractionFunction::initHessian(
void)
207 for (cfl_size_t i=0; i<_dimension; ++i)
208 _hessians[i] =
new Matrix(_x->getSize(), _x->getSize());
virtual void doUpdateSize(void)
virtual void computeJdot(void) const
int getOppositeConvexityProperty(const Function &f)
virtual void computeJdotXdot(void) const
void changeV(const Vector &v)
virtual void computeGradient(void) const
virtual void computeHessian(void) const
virtual void computeValue(void) const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
virtual ~SubtractionFunction()
Declaration file of the SubtractionFunction class.