23 #define HUMOTO_CONFIG_SECTION_ID "SolverParameters" 24 #define HUMOTO_CONFIG_CONSTRUCTOR SolverParameters 25 #define HUMOTO_CONFIG_ENTRIES \ 26 HUMOTO_CONFIG_PARENT_CLASS(humoto::SolverParametersBase) \ 28 HUMOTO_CONFIG_SCALAR_(max_number_of_iterations) \ 29 HUMOTO_CONFIG_SCALAR_(max_cpu_time) \ 31 HUMOTO_CONFIG_MEMBER_CLASS(options_, "QPoasesParameters") 32 #include HUMOTO_CONFIG_DEFINE_ACCESSORS 38 #define HUMOTO_CONFIG_SECTION_ID "QPoasesParameters" 39 #define HUMOTO_CONFIG_CONSTRUCTOR QPoasesParameters 40 #define HUMOTO_CONFIG_ENTRIES \ 41 HUMOTO_CONFIG_ENUM(enableRamping)\ 42 HUMOTO_CONFIG_ENUM(enableFarBounds)\ 43 HUMOTO_CONFIG_ENUM(enableFlippingBounds)\ 44 HUMOTO_CONFIG_ENUM(enableRegularisation)\ 45 HUMOTO_CONFIG_ENUM(enableFullLITests)\ 46 HUMOTO_CONFIG_ENUM(enableNZCTests)\ 47 HUMOTO_CONFIG_SCALAR(enableDriftCorrection)\ 48 HUMOTO_CONFIG_SCALAR(enableCholeskyRefactorisation)\ 49 HUMOTO_CONFIG_ENUM(enableEqualities)\ 50 HUMOTO_CONFIG_SCALAR(terminationTolerance)\ 51 HUMOTO_CONFIG_SCALAR(boundTolerance)\ 52 HUMOTO_CONFIG_SCALAR(boundRelaxation)\ 53 HUMOTO_CONFIG_SCALAR(epsNum)\ 54 HUMOTO_CONFIG_SCALAR(epsDen)\ 55 HUMOTO_CONFIG_SCALAR(maxPrimalJump)\ 56 HUMOTO_CONFIG_SCALAR(maxDualJump)\ 57 HUMOTO_CONFIG_SCALAR(initialRamping)\ 58 HUMOTO_CONFIG_SCALAR(finalRamping)\ 59 HUMOTO_CONFIG_SCALAR(initialFarBounds)\ 60 HUMOTO_CONFIG_SCALAR(growFarBounds)\ 61 HUMOTO_CONFIG_ENUM(initialStatusBounds)\ 62 HUMOTO_CONFIG_SCALAR(epsFlipping)\ 63 HUMOTO_CONFIG_SCALAR(numRegularisationSteps)\ 64 HUMOTO_CONFIG_SCALAR(epsRegularisation)\ 65 HUMOTO_CONFIG_SCALAR(numRefinementSteps)\ 66 HUMOTO_CONFIG_SCALAR(epsIterRef)\ 67 HUMOTO_CONFIG_SCALAR(epsLITests)\ 68 HUMOTO_CONFIG_SCALAR(epsNZCTests)\ 69 HUMOTO_CONFIG_SCALAR(rcondSMin)\ 70 HUMOTO_CONFIG_ENUM(enableInertiaCorrection)\ 71 HUMOTO_CONFIG_ENUM(enableDropInfeasibles)\ 72 HUMOTO_CONFIG_SCALAR(dropBoundPriority)\ 73 HUMOTO_CONFIG_SCALAR(dropEqConPriority)\ 74 HUMOTO_CONFIG_SCALAR(dropIneqConPriority) 75 #include HUMOTO_CONFIG_DEFINE_ACCESSORS 107 max_number_of_iterations_ = 1000;
176 number_of_constraints_,
177 qpOASES::HST_SEMIDEF);
185 qpOASES::real_t max_time = parameters_.max_cpu_time_;
187 qpOASES::real_t *max_time_ptr = NULL;
189 const qpOASES::real_t * lb_ptr = NULL;
190 const qpOASES::real_t * ub_ptr = NULL;
192 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> A_rm;
193 const qpOASES::real_t *A_ptr = NULL;
194 const qpOASES::real_t *lbA_ptr = NULL;
195 const qpOASES::real_t *ubA_ptr = NULL;
197 const qpOASES::real_t *solution_guess_ptr = NULL;
199 qpOASES::Bounds *active_set_bounds_ptr = NULL;
200 qpOASES::Constraints *active_set_constraints_ptr = NULL;
202 qpOASES::returnValue qpoases_return_value;
207 max_time_ptr = &max_time;
216 if (number_of_constraints_ > 0)
228 if (NULL != solution_guess_)
230 solution_guess_ptr = solution_guess_;
234 if (active_set_guess_provided_)
236 active_set_bounds_ptr = &qpoases_active_set_guess_bounds_;
237 active_set_constraints_ptr = &qpoases_active_set_guess_constraints_;
241 int number_of_iterations = parameters_.max_number_of_iterations_;
243 qp_->setOptions (parameters_.options_);
244 qpoases_return_value =
252 number_of_iterations,
256 active_set_bounds_ptr,
257 active_set_constraints_ptr);
260 qp_->getPrimalSolution( solution.
x_.data() );
264 switch (qpoases_return_value)
266 case qpOASES::SUCCESSFUL_RETURN:
269 case qpOASES::RET_MAX_NWSR_REACHED:
289 solution_guess_ = NULL;
290 active_set_guess_provided_ =
false;
302 qp_->getWorkingSetBounds(qpoases_active_set_bounds_.data());
305 if (number_of_constraints_ > 0)
307 qpoases_active_set_constraints_.resize(number_of_constraints_);
308 qp_->getWorkingSetConstraints(qpoases_active_set_constraints_.data());
326 for (std::size_t i = 0; i < number_of_constraints_; ++i)
328 if (qpoases_active_set_constraints_[i] == -1.0)
334 if (qpoases_active_set_constraints_[i] == 0.0)
340 if (qpoases_active_set_constraints_[i] == 1.0)
346 HUMOTO_THROW_MSG(
"Active set returned by qpOASES is incorrectly initialized.");
357 if (qpoases_active_set_bounds_[var_index] == -1.0)
370 if (qpoases_active_set_bounds_[var_index] == 0.0)
376 if (qpoases_active_set_bounds_[var_index] == 1.0)
389 HUMOTO_THROW_MSG(
"Active set returned by qpOASES is incorrectly initialized.");
407 active_set_guess_provided_ =
true;
409 qpoases_active_set_guess_constraints_.init(number_of_constraints_);
411 for (std::size_t i = 0; i < number_of_constraints_; ++i)
418 qpoases_active_set_guess_constraints_.setupConstraint(i, qpOASES::ST_LOWER);
421 qpoases_active_set_guess_constraints_.setupConstraint(i, qpOASES::ST_INACTIVE);
424 qpoases_active_set_guess_constraints_.setupConstraint(i, qpOASES::ST_UPPER);
427 qpoases_active_set_guess_constraints_.setupConstraint(i, qpOASES::ST_LOWER);
437 qpoases_active_set_guess_bounds_.setupAllFree();
446 qpoases_active_set_guess_bounds_.setupBound(var_index, qpOASES::ST_LOWER);
453 qpoases_active_set_guess_bounds_.setupBound(var_index, qpOASES::ST_UPPER);
456 qpoases_active_set_guess_bounds_.setupBound(var_index, qpOASES::ST_LOWER);
469 solution_guess_ = solution_guess.
x_.data();
476 number_of_constraints_ = 0;
478 active_set_guess_provided_ =
false;
480 solution_guess_ = NULL;
519 setParameters(parameters);
532 const std::string &name =
"qpoases")
const 535 qp_problem_.
log(logger, subname);
qpOASES::Constraints qpoases_active_set_guess_constraints_
std::size_t getNumberOfVariables() const
Get total number of variables in the solution vector.
const humoto::constraints::ContainerALU & getGeneralConstraints() const
get container with general constraints
Lower bound is activated.
void reset()
Reset solver.
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="qpoases") const
Log a QP problem.
Constraint is an equality (always active)
Eigen::VectorXd qpoases_active_set_bounds_
std::size_t getNumberOfVariables() const
Returns number of variables in the task.
std::size_t getNumberOfConstraints() const
Returns number of constraints in the task.
#define HUMOTO_GLOBAL_LOGGER_IF_DEFINED
Default configurable base is strict.
humoto::IndexVector & getIndices()
Get indices.
Analog of 'sol_structure' struct in Octave code. [determine_solution_structure.m].
Container of the solution.
void set(const std::size_t level_index, const ConstraintActivationType::Type type)
Set type of all constraints on the given level.
const humoto::constraints::ContainerILU & getSimpleBounds() const
get container with simple bounds
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
Represents log entry name.
int number_of_iterations_
Number of iterations made by the solver.
Active set corresponding to a hierarchy of Constraints.
const Eigen::VectorXd & getSolutionLowerBounds() const
Get LB vector: 'LB <= X'.
const Eigen::VectorXd & getGradient() const
Const accessor.
SolverStatus::Status return_status_
Eigen::VectorXd & getUpperBounds()
Get upper bounds (ub vectors from 'A*x <= ub').
Eigen::MatrixXd & getA()
Get matrix A from general constraints: 'A*x = b', 'lb <= A*x <= ub'.
SolverParameters()
Default constructor.
An optimization problem [initialize_stack.m, simulation_loop.m].
std::size_t getNumberOfConstraints() const
Returns number of constraints in the task.
qpOASES::returnValue qpoases_return_value_
The return value of qpOASES.
int max_number_of_iterations_
Limit on the number of iterations.
QPoasesParameters options_
Parameters for qpOASES.
double max_cpu_time_
Limit on the computation time.
void setActiveSet(const humoto::ActiveSet &active_set, const humoto::OptimizationProblem &hierarchy)
Set active set guess.
void setDefaults()
Initialize to default parameters.
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
const Eigen::VectorXd & getSolutionUpperBounds() const
Get UB vector: 'X <= UB'.
std::size_t number_of_constraints_
Nonzero if constraints are specified.
A QP problem with constraints of a specific type.
void setSolutionGuess(const humoto::Solution &solution_guess)
Set solution guess.
Eigen::VectorXd qpoases_active_set_constraints_
The root namespace of HuMoTo.
void initialize(const humoto::OptimizationProblem &hierarchy, const humoto::SolutionStructure &sol_structure)
Initialize solver.
void initializeActiveSet(humoto::ActiveSet &active_set) const
Initialize active set of the hierarchy.
Parameters of the solver.
Solver(const SolverParameters ¶meters)
Set parameters.
Mixin solver interface (QP solver)
const double * solution_guess_
Guess of the solution.
Solver()
Default constructor (with default parameters)
void solveHierarchy(humoto::Solution &solution, const humoto::OptimizationProblem &hierarchy)
Solve the hierarchy.
bool active_set_guess_provided_
If set the active set is returned.
LogEntryName & add(const char *name)
extends entry name with a subname
qpOASES::Bounds qpoases_active_set_guess_bounds_
The active set guess for qpOASES.
void getActiveSet(humoto::ActiveSet &active_set, const humoto::OptimizationProblem &hierarchy)
Get active set.
Eigen::VectorXd & getLowerBounds()
Get lower bounds (lb/ub vectors from 'lb <= A*x <= ub').
void log(humoto::Logger &logger, const LogEntryName &parent=LogEntryName(), const std::string &name="qp_problem") const
Log a QP problem.
void setDefaults()
Set members to their default values.
Upper bound is activated.
const Eigen::MatrixXd & getHessian() const
Const accessor.
humoto::QPProblem_ILU_ALU qp_problem_
void getQPProblem(QPProblemBase< t_QPConstraints > &qp_problem, const humoto::SolutionStructure &sol_structure, const bool initialize_upper_triangular_part=true) const
Form a QP problem.