Biorbd Release_1.13.0
Loading...
Searching...
No Matches
BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt Class Reference

The actual implementation of the Static Optimization problem. More...

#include <StaticOptimizationIpopt.h>

Inheritance diagram for BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt:
BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpoptLinearized

Public Member Functions

 StaticOptimizationIpopt (Model &model, const rigidbody::GeneralizedCoordinates &Q, const rigidbody::GeneralizedVelocity &Qdot, const rigidbody::GeneralizedTorque &torqueTarget, const utils::Vector &activationInit, bool useResidual=true, unsigned int pNormFactor=2, int verbose=0, double eps=1e-8)
 Construct an Ipopt static optimization problem.
virtual ~StaticOptimizationIpopt ()
 Destroy class properly.
virtual bool get_nlp_info (Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, IndexStyleEnum &index_style)
 Get info about the NLP.
virtual bool get_bounds_info (Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
 Return the bounds for my problem.
virtual bool get_starting_point (Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
 Return the starting point for the algorithm.
virtual bool eval_f (Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
 Compute the objective value from a set of variables.
virtual bool eval_grad_f (Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
 Return the gradient of the objective.
virtual bool eval_g (Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
 Method to return the constraint residuals.
virtual bool eval_jac_g (Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
 Return the jacobian of contraints.
virtual void finalize_solution (Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
 Finalize the optimization.
utils::Vector finalSolution () const
 Return the final solution.
utils::Vector finalResidual () const
 Return the final residual.

Protected Member Functions

void dispatch (const Ipopt::Number *x)
 To dispatch the variables into biorbd format.

Protected Attributes

Model & m_model
 The model.
std::shared_ptr< unsigned int > m_nbQ
 The number of generalized coordinates.
std::shared_ptr< unsigned int > m_nbQdot
 The number of generalized velocities.
std::shared_ptr< unsigned int > m_nbMus
 The number of muscles.
std::shared_ptr< unsigned int > m_nbDof
 The number of degrees of freedom.
std::shared_ptr< unsigned int > m_nbTorque
 The number of torques to match.
std::shared_ptr< unsigned int > m_nbTorqueResidual
 The number of torque residual.
std::shared_ptr< double > m_eps
 Precision of the finite differentiate.
std::shared_ptr< utils::Vector > m_activations
 The activations.
std::shared_ptr< rigidbody::GeneralizedCoordinates > m_Q
 The generalized coordinates.
std::shared_ptr< rigidbody::GeneralizedVelocity > m_Qdot
 The generalized velocities.
std::shared_ptr< rigidbody::GeneralizedTorque > m_torqueTarget
 The torque to match.
std::shared_ptr< utils::Vector > m_torqueResidual
 The torque residual.
std::shared_ptr< double > m_torquePonderation
 The torque ponderation.
std::shared_ptr< std::vector< std::shared_ptr< State > > > m_states
 The muscle states.
std::shared_ptr< unsigned int > m_pNormFactor
 The p-norm factor.
std::shared_ptr< int > m_verbose
 Verbose level of IPOPT.
std::shared_ptr< utils::Vector > m_finalSolution
 The final solution.
std::shared_ptr< utils::Vector > m_finalResidual
 The final residual.

Static Protected Attributes

static const double m_activationLowerBound = 0.0001
 Minimal muscle activation.
static const double m_activationUpperBound = 0.9999
 Maximal muscle activation.

Detailed Description

The actual implementation of the Static Optimization problem.

Definition at line 29 of file StaticOptimizationIpopt.h.

Constructor & Destructor Documentation

◆ StaticOptimizationIpopt()

internal_forces::muscles::StaticOptimizationIpopt::StaticOptimizationIpopt ( Model & model,
const rigidbody::GeneralizedCoordinates & Q,
const rigidbody::GeneralizedVelocity & Qdot,
const rigidbody::GeneralizedTorque & torqueTarget,
const utils::Vector & activationInit,
bool useResidual = true,
unsigned int pNormFactor = 2,
int verbose = 0,
double eps = 1e-8 )

Construct an Ipopt static optimization problem.

Parameters
modelThe musculoskeletal Model
QThe generalized coordinates
QdotThe generalized velocities
torqueTargetThe generalized torque target
activationInitThe initial activation
useResidualIf use residual torque, if set to false, the optimization will fail if the model is not strong enough
pNormFactorThe p-norm to perform
verboseLevel of IPOPT verbose you want
epsThe precision to perform the finite diffentiation

Definition at line 24 of file StaticOptimizationIpopt.cpp.

◆ ~StaticOptimizationIpopt()

internal_forces::muscles::StaticOptimizationIpopt::~StaticOptimizationIpopt ( )
virtual

Destroy class properly.

Definition at line 79 of file StaticOptimizationIpopt.cpp.

Member Function Documentation

◆ dispatch()

void internal_forces::muscles::StaticOptimizationIpopt::dispatch ( const Ipopt::Number * x)
protected

To dispatch the variables into biorbd format.

Parameters
xvariables

Definition at line 372 of file StaticOptimizationIpopt.cpp.

◆ eval_f()

bool internal_forces::muscles::StaticOptimizationIpopt::eval_f ( Ipopt::Index n,
const Ipopt::Number * x,
bool new_x,
Ipopt::Number & obj_value )
virtual

Compute the objective value from a set of variables.

Parameters
nThe number of variables
xThe values of the variables
new_xIf the variables were modified by IPOPT
obj_valueThe actual value of the objective function
Returns
Return the presence of that function

Definition at line 171 of file StaticOptimizationIpopt.cpp.

◆ eval_g()

bool internal_forces::muscles::StaticOptimizationIpopt::eval_g ( Ipopt::Index n,
const Ipopt::Number * x,
bool new_x,
Ipopt::Index m,
Ipopt::Number * g )
virtual

Method to return the constraint residuals.

Parameters
nThe number of variables
xThe values of the variables
new_xIf the variables were modified by IPOPT
mThe number of constraints
gThe actual contraints residual
Returns
Return the presence of that function

Reimplemented in BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpoptLinearized.

Definition at line 213 of file StaticOptimizationIpopt.cpp.

◆ eval_grad_f()

bool internal_forces::muscles::StaticOptimizationIpopt::eval_grad_f ( Ipopt::Index n,
const Ipopt::Number * x,
bool new_x,
Ipopt::Number * grad_f )
virtual

Return the gradient of the objective.

Parameters
nThe number of variables
xThe values of the variables
new_xIf the variables were modified by IPOPT
grad_fThe gradient vector of the objective function
Returns
Return the presence of that function

Definition at line 190 of file StaticOptimizationIpopt.cpp.

◆ eval_jac_g()

bool internal_forces::muscles::StaticOptimizationIpopt::eval_jac_g ( Ipopt::Index n,
const Ipopt::Number * x,
bool new_x,
Ipopt::Index m,
Ipopt::Index nele_jac,
Ipopt::Index * iRow,
Ipopt::Index * jCol,
Ipopt::Number * values )
virtual

Return the jacobian of contraints.

Parameters
nThe number of variables
xThe values of the variables
new_xIf the variables were modified by IPOPT
mThe number of constraints
nele_jacNumber of elements in the jacobian matrix
iRowiterator on the rows of the jacobian
jColiterator on the columns of the jacobian
valuesThe actual constraint jacobian
Returns
Return the presence of that function

Reimplemented in BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpoptLinearized.

Definition at line 242 of file StaticOptimizationIpopt.cpp.

◆ finalize_solution()

void internal_forces::muscles::StaticOptimizationIpopt::finalize_solution ( Ipopt::SolverReturn status,
Ipopt::Index n,
const Ipopt::Number * x,
const Ipopt::Number * z_L,
const Ipopt::Number * z_U,
Ipopt::Index m,
const Ipopt::Number * g,
const Ipopt::Number * lambda,
Ipopt::Number obj_value,
const Ipopt::IpoptData * ip_data,
Ipopt::IpoptCalculatedQuantities * ip_cq )
virtual

Finalize the optimization.

Parameters
statusThe status of the optimization
nNumber of variables
xOptimal solution
z_LOptimal lower bound of z (ignored result)
z_UOptimal upper bound of z (ignored result)
mnumber of constraints
gResidual at solution
lambdaLagrange multipliers at solution
obj_valueObjective function value at solution
ip_dataNot used results
ip_cqNot used results

Definition at line 323 of file StaticOptimizationIpopt.cpp.

◆ finalResidual()

utils::Vector internal_forces::muscles::StaticOptimizationIpopt::finalResidual ( ) const

Return the final residual.

Returns
The final residual (zeros if finalize_solution was not called, e.g. if IPOPT aborted)

Definition at line 367 of file StaticOptimizationIpopt.cpp.

◆ finalSolution()

utils::Vector internal_forces::muscles::StaticOptimizationIpopt::finalSolution ( ) const

Return the final solution.

Returns
The final solution (the initial activations if finalize_solution was not called, e.g. if IPOPT aborted)

Definition at line 362 of file StaticOptimizationIpopt.cpp.

◆ get_bounds_info()

bool internal_forces::muscles::StaticOptimizationIpopt::get_bounds_info ( Ipopt::Index n,
Ipopt::Number * x_l,
Ipopt::Number * x_u,
Ipopt::Index m,
Ipopt::Number * g_l,
Ipopt::Number * g_u )
virtual

Return the bounds for my problem.

Parameters
nNumber of variables
x_lLower bounds of the variables
x_uUpper bounds of the variables
mNumber of constraints
g_lLower bounds of the constraints
g_uUpper bounds of the constraints
Returns
Return the presence of that function

Definition at line 109 of file StaticOptimizationIpopt.cpp.

◆ get_nlp_info()

bool internal_forces::muscles::StaticOptimizationIpopt::get_nlp_info ( Ipopt::Index & n,
Ipopt::Index & m,
Ipopt::Index & nnz_jac_g,
Ipopt::Index & nnz_h_lag,
IndexStyleEnum & index_style )
virtual

Get info about the NLP.

Parameters
nNumber of variables
mNumber of constraints
nnz_jac_gDimension of the constraint jacobian
nnz_h_lagDimension of the constraint hessian
index_styleFormatting of the matrix (C-Style)
Returns
Return the presence of that function

Definition at line 81 of file StaticOptimizationIpopt.cpp.

◆ get_starting_point()

bool internal_forces::muscles::StaticOptimizationIpopt::get_starting_point ( Ipopt::Index n,
bool init_x,
Ipopt::Number * x,
bool init_z,
Ipopt::Number * z_L,
Ipopt::Number * z_U,
Ipopt::Index m,
bool init_lambda,
Ipopt::Number * lambda )
virtual

Return the starting point for the algorithm.

Parameters
nNumber of variables
init_xIf variables are initialized. That variable must be true
xThe initial values for the variables (output)
init_zIf z parameters are initialized. That variable must be false
z_LLower bound of z (ignored output)
z_UUpper bound of z (ignored output)
mNumber of constraints
init_lambdaIf lambda parameters are initialized. That variable must be false
lambdaInitial values of lagrange multipliers (ignored output)
Returns
Return the presence of that function

Definition at line 138 of file StaticOptimizationIpopt.cpp.

Member Data Documentation

◆ m_activationLowerBound

const double internal_forces::muscles::StaticOptimizationIpopt::m_activationLowerBound = 0.0001
staticprotected

Minimal muscle activation.

Definition at line 228 of file StaticOptimizationIpopt.h.

◆ m_activations

std::shared_ptr<utils::Vector> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_activations
protected

The activations.

Definition at line 242 of file StaticOptimizationIpopt.h.

◆ m_activationUpperBound

const double internal_forces::muscles::StaticOptimizationIpopt::m_activationUpperBound = 0.9999
staticprotected

Maximal muscle activation.

Definition at line 229 of file StaticOptimizationIpopt.h.

◆ m_eps

std::shared_ptr<double> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_eps
protected

Precision of the finite differentiate.

Definition at line 241 of file StaticOptimizationIpopt.h.

◆ m_finalResidual

std::shared_ptr<utils::Vector> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_finalResidual
protected

The final residual.

Definition at line 256 of file StaticOptimizationIpopt.h.

◆ m_finalSolution

std::shared_ptr<utils::Vector> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_finalSolution
protected

The final solution.

Definition at line 255 of file StaticOptimizationIpopt.h.

◆ m_model

Model& BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_model
protected

The model.

Definition at line 231 of file StaticOptimizationIpopt.h.

◆ m_nbDof

std::shared_ptr<unsigned int> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_nbDof
protected

The number of degrees of freedom.

Definition at line 237 of file StaticOptimizationIpopt.h.

◆ m_nbMus

std::shared_ptr<unsigned int> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_nbMus
protected

The number of muscles.

Definition at line 236 of file StaticOptimizationIpopt.h.

◆ m_nbQ

std::shared_ptr<unsigned int> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_nbQ
protected

The number of generalized coordinates.

Definition at line 233 of file StaticOptimizationIpopt.h.

◆ m_nbQdot

std::shared_ptr<unsigned int> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_nbQdot
protected

The number of generalized velocities.

Definition at line 235 of file StaticOptimizationIpopt.h.

◆ m_nbTorque

std::shared_ptr<unsigned int> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_nbTorque
protected

The number of torques to match.

Definition at line 238 of file StaticOptimizationIpopt.h.

◆ m_nbTorqueResidual

std::shared_ptr<unsigned int> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_nbTorqueResidual
protected

The number of torque residual.

Definition at line 240 of file StaticOptimizationIpopt.h.

◆ m_pNormFactor

std::shared_ptr<unsigned int> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_pNormFactor
protected

The p-norm factor.

Definition at line 253 of file StaticOptimizationIpopt.h.

◆ m_Q

std::shared_ptr<rigidbody::GeneralizedCoordinates> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_Q
protected

The generalized coordinates.

Definition at line 244 of file StaticOptimizationIpopt.h.

◆ m_Qdot

std::shared_ptr<rigidbody::GeneralizedVelocity> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_Qdot
protected

The generalized velocities.

Definition at line 246 of file StaticOptimizationIpopt.h.

◆ m_states

std::shared_ptr<std::vector<std::shared_ptr<State> > > BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_states
protected

The muscle states.

Definition at line 252 of file StaticOptimizationIpopt.h.

◆ m_torquePonderation

std::shared_ptr<double> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_torquePonderation
protected

The torque ponderation.

Definition at line 250 of file StaticOptimizationIpopt.h.

◆ m_torqueResidual

std::shared_ptr<utils::Vector> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_torqueResidual
protected

The torque residual.

Definition at line 249 of file StaticOptimizationIpopt.h.

◆ m_torqueTarget

std::shared_ptr<rigidbody::GeneralizedTorque> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_torqueTarget
protected

The torque to match.

Definition at line 248 of file StaticOptimizationIpopt.h.

◆ m_verbose

std::shared_ptr<int> BIORBD_NAMESPACE::internal_forces::muscles::StaticOptimizationIpopt::m_verbose
protected

Verbose level of IPOPT.

Definition at line 254 of file StaticOptimizationIpopt.h.


The documentation for this class was generated from the following files: