OpenSim Moco  0.4.0
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
OpenSim::MocoTropterSolver Class Reference

Description

Solve the MocoProblem using the tropter direct collocation library.

tropter is a free and open-source C++ library that supports computing the Jacobian and Hessian via either automatic differentiation or finite differences, and uses IPOPT for solving the nonlinear optimization problem.

This class allows you to configure tropter's settings.

Supported optimization solvers

The following optimization solvers can be specified for the optim_solver property:

Using this solver in C++ requires that a tropter shared library is available, but tropter header files are not required. No tropter symbols are exposed in Moco's interface.

Inheritance diagram for OpenSim::MocoTropterSolver:
OpenSim::MocoDirectCollocationSolver OpenSim::MocoSolver

#include <Moco/Moco/MocoTropterSolver.h>

Classes

class  ExplicitTropterProblem
 
class  ImplicitTropterProblem
 
class  OCProblem
 Internal tropter optimal control problem. More...
 
class  TropterProblemBase
 

Public Member Functions

 OpenSim_DECLARE_PROPERTY (optim_jacobian_approximation, std::string, "When using IPOPT, 'finite-difference-values' for Jacobian " "calculations " "by the solver, or 'exact' for Jacobian calculations by " "tropter (default).")
 
 OpenSim_DECLARE_PROPERTY (optim_sparsity_detection, std::string, "Trajectory used to detect sparsity pattern of Jacobian/Hessian; " "'random' (default) or 'initial-guess'")
 
 OpenSim_DECLARE_OPTIONAL_PROPERTY (exact_hessian_block_sparsity_mode, std::string, "'dense' for dense blocks on the Hessian diagonal, or " "'sparse' for sparse blocks on the Hessian diagonal, detected from " "the " "optimal control problem. If using an 'exact' Hessian " "approximation, this " "property must be set. Note: this option only takes effect when " "using " "IPOPT.")
 
Specifying an initial guess
MocoTrajectory createGuess (const std::string &type="bounds") const
 Create a guess that you can edit and then set using setGuess(). More...
 
void setGuess (MocoTrajectory guess)
 The number of time points in the trajectory does not need to match num_mesh_intervals; the trajectory will be interpolated to the correct size. More...
 
void setGuess (const std::string &type)
 Use this convenience function if you want to choose the type of guess used, but do not want to modify it first. More...
 
void setGuessFile (const std::string &file)
 This clears any previously-set guess, if any. More...
 
void clearGuess ()
 Clear the stored guess and the guess_file if any.
 
const MocoTrajectorygetGuess () const
 Access the guess, loading it from the guess_file if necessary. More...
 
- Public Member Functions inherited from OpenSim::MocoDirectCollocationSolver
 OpenSim_DECLARE_PROPERTY (num_mesh_intervals, int, "The number of uniformly-sized mesh intervals for the problem " "(default: " "100). If a non-uniform mesh exists, the non-uniform mesh is used " "instead.")
 
 OpenSim_DECLARE_PROPERTY (verbosity, int, "0 for silent. 1 for only Moco's own output. " "2 for output from CasADi and the underlying solver (default: 2).")
 
 OpenSim_DECLARE_PROPERTY (transcription_scheme, std::string, "'trapezoidal' for trapezoidal transcription, or 'hermite-simpson' " "(default) for separated Hermite-Simpson transcription.")
 
 OpenSim_DECLARE_PROPERTY (interpolate_control_midpoints, bool, "If the transcription scheme is set to 'hermite-simpson', then " "enable this property to constrain the control values at mesh " "interval midpoints to be linearly interpolated from the control " "values at the mesh interval endpoints. Default: true.")
 
 OpenSim_DECLARE_PROPERTY (multibody_dynamics_mode, std::string, "Multibody dynamics are expressed as 'explicit' (default) or " "'implicit' differential equations.")
 
 OpenSim_DECLARE_PROPERTY (optim_solver, std::string, "The optimization solver to use (default: ipopt).")
 
 OpenSim_DECLARE_PROPERTY (optim_max_iterations, int, "Maximum number of iterations in the optimization solver " "(-1 for solver's default).")
 
 OpenSim_DECLARE_PROPERTY (optim_convergence_tolerance, double, "Tolerance used to determine if the objective is minimized " "(-1 for solver's default)")
 
 OpenSim_DECLARE_PROPERTY (optim_constraint_tolerance, double, "Tolerance used to determine if the constraints are satisfied " "(-1 for solver's default)")
 
 OpenSim_DECLARE_PROPERTY (optim_hessian_approximation, std::string, "When using IPOPT, 'limited-memory' (default) for quasi-Newton, or " "'exact' for full " "Newton.")
 
 OpenSim_DECLARE_PROPERTY (optim_ipopt_print_level, int, "IPOPT's verbosity (see IPOPT documentation).")
 
 OpenSim_DECLARE_OPTIONAL_PROPERTY (enforce_constraint_derivatives, bool, "'true' (default) or 'false', whether or not derivatives of " "kinematic constraints are enforced as path constraints in the " "optimal control problem.")
 
 OpenSim_DECLARE_PROPERTY (minimize_lagrange_multipliers, bool, "If enabled, a term minimizing the weighted, squared sum of " "any existing Lagrange multipliers is added to the optimal control " "problem. This may be useful for imposing uniqueness in the " "Lagrange multipliers when not enforcing model kinematic " "constraint derivatives or when the constraint Jacobian is " "singular. To set the weight for this term use the " "'lagrange_multiplier_weight' property. Default: false")
 
 OpenSim_DECLARE_PROPERTY (lagrange_multiplier_weight, double, "If the 'minimize_lagrange_multipliers' property is enabled, this " "defines the weight for the cost term added to the optimal control " "problem. Default: 1")
 
 OpenSim_DECLARE_PROPERTY (velocity_correction_bounds, MocoBounds, "For problems where model kinematic constraint derivatives are " "enforced, set the bounds on the slack variables performing the " "velocity correction to project the model coordinates back onto " "the constraint manifold. Default: [-0.1, 0.1]")
 
 OpenSim_DECLARE_PROPERTY (implicit_multibody_acceleration_bounds, MocoBounds, "Bounds on acceleration variables in implicit dynamics mode. " "Default: [-1000, 1000]")
 
 OpenSim_DECLARE_PROPERTY (implicit_auxiliary_derivative_bounds, MocoBounds, "Bounds on derivative variables for components with auxiliary " "dynamics in implicit form. Default: [-1000, 1000]")
 
void setMesh (const std::vector< double > &mesh)
 Sets the mesh to a, usually non-uniform, user-defined list of mesh points to sample. More...
 
- Public Member Functions inherited from OpenSim::MocoSolver
 MocoSolver (const MocoProblem &problem)
 This calls resetProblem() with the provided problem.
 

Static Public Member Functions

static void printOptimizationSolverOptions (std::string solver="ipopt")
 Print the available options for the underlying optimization solver.
 

Protected Member Functions

std::shared_ptr< const TropterProblemBase< double > > createTropterProblem () const
 
std::unique_ptr< tropter::DirectCollocationSolver< double > > createTropterSolver (std::shared_ptr< const TropterProblemBase< double >> ocp) const
 
MocoSolution solveImpl () const override
 
void checkGuess (const MocoTrajectory &guess) const
 Check that the provided guess is compatible with the problem and this solver. More...
 
- Protected Member Functions inherited from OpenSim::MocoDirectCollocationSolver
 OpenSim_DECLARE_PROPERTY (guess_file, std::string, "A MocoTrajectory file storing an initial guess.")
 
 OpenSim_DECLARE_LIST_PROPERTY (mesh, double, "Usually non-uniform, user-defined list of mesh points to sample. " "Takes precedence over uniform mesh with num_mesh_intervals.")
 
void constructProperties ()
 

Member Function Documentation

◆ checkGuess()

void OpenSim::MocoTropterSolver::checkGuess ( const MocoTrajectory guess) const
protected

Check that the provided guess is compatible with the problem and this solver.

◆ createGuess()

MocoTrajectory OpenSim::MocoTropterSolver::createGuess ( const std::string &  type = "bounds") const

Create a guess that you can edit and then set using setGuess().

The types of guesses available are:

  • bounds: variable values are the midpoint between the variables' bounds (the value for variables with ony one bound is the specified bound). This is the default type.
  • random: values are randomly generated within the bounds.
  • time-stepping: see MocoSolver::createGuessTimeStepping().
    Note
    Calling this method does not set an initial guess to be used in the solver; you must call setGuess() or setGuessFile() for that.
    Precondition(s):
    You must have called resetProblem().

◆ getGuess()

const MocoTrajectory& OpenSim::MocoTropterSolver::getGuess ( ) const

Access the guess, loading it from the guess_file if necessary.

This throws an exception if you have not set a guess (or guess file). If you have not set a guess (or guess file), this returns an empty guess, and when solving, we will generate a guess using bounds.

◆ setGuess() [1/2]

void OpenSim::MocoTropterSolver::setGuess ( MocoTrajectory  guess)

The number of time points in the trajectory does not need to match num_mesh_intervals; the trajectory will be interpolated to the correct size.

If you have updated the problem since the solver was initialized, you may need to invoke MocoSolver::resetProblem() for the provided guess to be recognized as compatible with the problem. This clears the guess_file, if one exists.

◆ setGuess() [2/2]

void OpenSim::MocoTropterSolver::setGuess ( const std::string &  type)
inline

Use this convenience function if you want to choose the type of guess used, but do not want to modify it first.

◆ setGuessFile()

void OpenSim::MocoTropterSolver::setGuessFile ( const std::string &  file)

This clears any previously-set guess, if any.

The file is not loaded until solving or if you call getGuess(). Set to an empty string to clear the guess file.


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