23 , mesh_pts(new int, 1)
25 , _allObjectivesProvideAGradient(true)
33 _objectives.push_back(&obj);
35 _allObjectivesProvideAGradient = _allObjectivesProvideAGradient && obj.canCompute<
PARTIAL_X>();
40 for(
size_t i = 0; i < _objectives.size(); ++i)
42 if(&_objectives[i]->getFunction() == &
obj)
53 _objectives.erase(std::find(_objectives.begin(), _objectives.end(), &
obj));
54 nf = std::min(1, (
int)_objectives.size());
55 _allObjectivesProvideAGradient =
true;
56 for (
size_t i=0; i<_objectives.size(); ++i)
57 _allObjectivesProvideAGradient = _allObjectivesProvideAGradient && obj.canCompute<
PARTIAL_X>();
88 addBounds_(constraint);
93 addBounds_(constraint);
98 ocra_assert(constraint.isInequality() &&
"How queer! A bound constraint that is no inequality...");
100 _bounds.push_back(&constraint);
105 removeBounds_(constraint);
110 removeBounds_(constraint);
115 ocra_assert(constraint.isInequality() &&
"How queer! A bound constraint that is no inequality...");
117 _bounds.erase(std::find(_bounds.begin(), _bounds.end(), &constraint));
173 if (pbVar.getSize() != ref.
getSize())
174 throw std::runtime_error(
"[FSQPSolver::set_x0] problem variable and reference variable don't have the same size");
175 std::vector<int> mapping;
176 pbVar.getRelativeMappingOf(ref, mapping);
177 if (mapping.size()<pbVar.getSize())
178 throw std::runtime_error(
"[FSQPSolver::set_x0] problem variable and reference variable don't have the same children");
180 this->x0.resize(x0.size());
181 for (
int i=0; i<pbVar.getSize(); ++i)
182 this->x0[mapping[i]] = x0[i];
188 mode = (mode/10)*10+type;
193 mode -= (mode/10)%10;
199 mode -= (mode/100)%100;
205 ocra_assert(m==100 || m==101 || m==110 || m==111 || m==200 || m==201 || m==210 || m==211);
214 iprint = (iprint/10)*10+m;
219 int assert_cond = iprint%10>=2;
221 iprint = 10*N+(iprint%10);
226 int assert_cond = option>=0 && option%10< 4;
258 this->udelta = udelta;
268 return static_cast<eFsqpAlgo>((mode/10)%10);
334 ocra_assert(j==1 &&
"in this implementation we only consider a unique objective function (possibly the sum of several functions)");
335 checkNewX(nparam, x);
337 for (
size_t i=0; i<_objectives.size(); ++i)
338 *fj += _objectives[i]->getWeight() * _objectives[i]->getValue(0);
343 checkNewX(nparam, x);
349 ocra_assert(j==1 &&
"in this implementation we only consider a unique objective function (possibly the sum of several functions)");
350 checkNewX(nparam, x);
353 if (_allObjectivesProvideAGradient)
355 for (
size_t i=0; i<_objectives.size(); ++i)
366 checkNewX(nparam, x);
367 std::pair<GenericConstraint*, int> p = _constraints[j-1];
397 const_cast<int*>(mesh_pts.data()),
406 const_cast<double*>(bl.data()),
407 const_cast<double*>(bu.data()),
409 const_cast<double*
>(f.data()),
410 const_cast<double*>(g.data()),
411 const_cast<double*>(lambda.data()),
432 void FSQPSolver::resize()
435 nineqn = _constraints.
nineqn();
436 nineq = _constraints.
nineq();
437 neqn = _constraints.
neqn();
438 neq = _constraints.
neq();
439 const int sg = std::max(1, nineq+neq);
440 const int sl = nparam+1+sg;
442 _buffer.
resize(2*nparam+sg+sl);
448 bl.setConstant(-bigbnd);
449 bu.setConstant(+bigbnd);
452 void FSQPSolver::updateBounds()
454 for (
size_t i=0; i<_bounds.size(); ++i)
457 const std::vector<int>& mapping =
findMapping(cstr->getVariable());
463 eReturnInfo FSQPSolver::translateReturnInfo()
const 477 default:
ocra_assert(
false &&
"this should never happen");
481 void FSQPSolver::checkNewX(
int nparam,
double* x)
499 MatrixXd A1(1,1); A1 << 1;
500 VectorXd b1(1); b1 << -3;
504 MatrixXd A2(1,2); A2 << 3,1 ;
505 VectorXd b2(1); b2 << 0;
509 MatrixXd A3(2,2); A3 << 2,1,-0.5,1 ;
510 VectorXd b3(2); b3 << 0, 1;
523 std::cout <<
"sol = " << std::endl << solver.
solve().
solution << std::endl << std::endl;
529 VectorXd lz(1); lz << 1;
530 VectorXd uz(1); uz << 2;
533 std::cout <<
"sol = " << std::endl << solver.
solve().
solution << std::endl << std::endl;
537 VectorXd ut(2); ut << -4,-1;
542 QuadraticFunction objFunc2(t, Matrix2d::Identity(), Vector2d::Constant(2.71828),0);
545 std::cout <<
"sol = " << std::endl << solver.
solve().
solution << std::endl << std::endl;
550 std::cout <<
"sol = " << std::endl << solver.
solve().
solution << std::endl << std::endl;
576 _value[0] = s*(1.12*x[0] + .13167*x[0]*x[2] - 0.00667*x[0]*x[2]*x[2]) + a*x[1] ;
580 _jacobian(0,0) = s*(1.12+.13167*x[2]-0.00667*x[2]*x[2]);
582 _jacobian(0,2) = s*(.13167*x[0]-2*0.00667*x[0]*x[2]);
606 _value[0] = 98000*x[0]/(x[1]*x[3]+1000*x[0])-x[2];
610 double v = x[1]*x[3]+1000*x[0];
612 _jacobian(0,0) = 98000*(v-1000*x[0])/v2;
613 _jacobian(0,1) = -98000*x[0]*x[3]/v2;
615 _jacobian(0,3) = -98000*x[0]*x[1]/v2;
636 _value[0] = (x[1]+x[2])/x[0]-x[3];
641 _jacobian(0,0) = -(x[1]+x[2])/x2;
642 _jacobian(0,1) = _jacobian(0,2) = 1/x[0];
677 MatrixXd Pf = MatrixXd::Zero(10,10); Pf(3,6)=Pf(6,3)=-0.063;
678 VectorXd qf(10); qf << 5.04, 0.035, 10, 0, 3.36, 0, 0, 0, 0, 0;
681 VectorXd b1(1); b1<<35.82;
684 Matrix2d A24; A24(0,0)=3;A24(1,0)=-3; A24(0,1)=-a; A24(1,1)=1/a;
687 VectorXd b3(1); b3<<-35.82;
692 Matrix3d P6 = Matrix3d::Zero(); P6(2,2)=-0.076;
697 Matrix3d P8 = Matrix3d::Zero(); P8(2,2)=0.076;
700 VectorXd b9(1); b9<<0;
706 VectorXd l(10); l << 1.e-5,1.e-5,1.e-5,1.e-5,1.e-5,85,90,3,1.2,145;
707 VectorXd u(10); u << 2000,16000,120,5000,2000,93,95,12,4,162;
729 VectorXd x_init(10); x_init << 1745,12000,110,3048,1974,89.2,92.8,8,3.6,145;
730 VectorXd sol(10); sol << 1698.096,15818.73,54.10228,3031.226,2000,90.11537,95,10.49336,1.561636,153.53535;
733 IOFormat fullFmt(FullPrecision, 0,
", ",
"\n",
"",
"",
"",
"");
void removeBounds(BoundConstraint &constraint)
void internalAddConstraint(const GenericConstraint &constraint)
void addConstraint(LinearConstraint &constraint)
void setVariableValue(const VectorXd &value)
eFsqpProblemType getA() const
void addCompressedByCol(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > const &_out, const std::vector< int > &mapping, double scale, bool reverseMapping)
void addBounds(BoundConstraint &constraint)
void updateJacobian() const
void setInfinity(double infinity)
void constr(int nparam, int j, double *x, double *gj, void *cd)
void clearLinearInequalityConstraints()
void internalRemoveConstraint(const GenericConstraint &constraint)
Declaration file of the FSQPSolver class.
void updateJacobian() const
virtual void gradob(int nparam, int j, double *x, double *gradfj, void *cd)
void cfsqp(int nparam, int nf, int nfsr, int nineqn, int nineq, int neqn, int neq, int ncsrl, int ncsrn, int *mesh_pts, int mode, int iprint, int miter, int *inform, double bigbnd, double eps, double epseqn, double udelta, double *bl, double *bu, double *x, double *f, double *g, double *lambda, OFSQPProblem &problem, void *cd)
void internalAddObjective(const GenericObjective &objective)
double setEqnViol() const
void setC(eFsqpEvaluationDomainPolicy type)
Pb114G5(Variable &x, double s, double a)
OptimizationResult _result
const OptimizationResult & solve()
const std::vector< int > & findMapping(Variable &var)
void clearInequalityConstraints()
void setA(eFsqpProblemType type)
void uncompressByCol(const MatrixBase< Derived1 > &in, MatrixBase< Derived2 > const &_out, const std::vector< int > &mapping, double scale, bool reverseMapping)
double getValue(int i) const
void addConstraint(LinearConstraint &constraint)
void setPrintOption(int option)
void internalRemoveObjective(const GenericObjective &objective)
void gradob(int nparam, int j, double *x, double *gradfj, void *cd)
void updateJacobian() const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Map< VectorXd > VectorMap
void clearLinearEqualityConstraints()
Variable & getProblemVariable()
void removeConstraint(LinearConstraint &constraint)
double getInfinity() const
eFsqpEvaluationDomainPolicy
void printValuesAtSolution()
void obj(int nparam, int j, double *x, double *fj, void *cd)
eFsqpEvaluationDomainPolicy getC() const
void addObjective(GenericObjective &obj)
void removeConstraint(LinearConstraint &constraint)
int getPrintOption() const
This class represents a variable in a mathematical sense.
const ScalarMultMatrixXdRow getGradient(int i) const
virtual void gradcn(int nparam, int j, double *x, double *gradgj, void *cd)
void gradcn(int nparam, int j, double *x, double *gradgj, void *cd)
Map< MatrixXd > MatrixMap
void clearNonLinearInequalityConstraints()
const OptimizationResult & getLastResult() const
void clearNonLinearEqualityConstraints()
void intersectBounds(const DiagonalLinearConstraint &bounds, const std::vector< int > &mapping, VectorBase1 &bl, VectorBase2 &bu)
void setPrintMode(eFsqpPrintOption m)
CompositeVariable & add(Variable &child)
Attach/detach the child to/from this node.
void removeObjective(Function &obj)
eFsqpPrintOption getPrintMode() const
A concatenation of base variables and other composite variables.
void set_x0(const VectorXd &x0, const Variable &ref)
virtual void onObjectiveResize(int timestamp)
#define ocra_assert(ocra_expression)
void setB(eFsqpAlgo type)
Implements a basic variable.
ptr_type allocate(size_t n)
virtual void onConstraintResize(int timestamp)
void clearEqualityConstraints()