Template Class ShootingProblemTpl

Class Documentation

template<typename _Scalar>
class ShootingProblemTpl

This class encapsulates a shooting problem.

A shooting problem encapsulates the initial state \(\mathbf{x}_{0}\in\mathcal{M}\), a set of running action models and a terminal action model for a discretized trajectory into \(T\) nodes. It has three main methods - calc, calcDiff and rollout. The first computes the set of next states and cost values per each node \(k\). Instead, calcDiff updates the derivatives of all action models. Finally, rollout integrates the system dynamics. This class is used to decouple problem formulation and resolution.

Public Types

typedef ActionModelAbstractTpl<Scalar> ActionModelAbstract
typedef ActionDataAbstractTpl<Scalar> ActionDataAbstract
typedef MathBaseTpl<Scalar> MathBase
typedef MathBase::VectorXs VectorXs

Public Functions

ShootingProblemTpl(const VectorXs &x0, const std::vector<std::shared_ptr<ActionModelAbstract>> &running_models, std::shared_ptr<ActionModelAbstract> terminal_model)

Initialize the shooting problem and allocate its data.

Parameters:
  • x0[in] Initial state

  • running_models[in] Running action models (size \(T\))

  • terminal_model[in] Terminal action model

ShootingProblemTpl(const VectorXs &x0, const std::vector<std::shared_ptr<ActionModelAbstract>> &running_models, std::shared_ptr<ActionModelAbstract> terminal_model, const std::vector<std::shared_ptr<ActionDataAbstract>> &running_datas, std::shared_ptr<ActionDataAbstract> terminal_data)

Initialize the shooting problem (models and datas)

Parameters:
  • x0[in] Initial state

  • running_models[in] Running action models (size \(T\))

  • terminal_model[in] Terminal action model

  • running_datas[in] Running action datas (size \(T\))

  • terminal_data[in] Terminal action data

ShootingProblemTpl(const ShootingProblemTpl<Scalar> &problem)

Initialize the shooting problem.

~ShootingProblemTpl()
Scalar calc(const std::vector<VectorXs> &xs, const std::vector<VectorXs> &us)

Compute the cost and the next states.

For each node \(k\), and along the state \(\mathbf{x_{s}}\) and control \(\mathbf{u_{s}}\) trajectory, it computes the next state \(\mathbf{x}_{k+1}\) and cost \(l_{k}\).

Parameters:
  • xs[in] time-discrete state trajectory \(\mathbf{x_{s}}\) (size \(T+1\))

  • us[in] time-discrete control sequence \(\mathbf{u_{s}}\) (size \(T\))

Returns:

The total cost value \(l_{k}\)

Scalar calcDiff(const std::vector<VectorXs> &xs, const std::vector<VectorXs> &us)

Compute the derivatives of the cost and dynamics.

For each node \(k\), and along the state \(\mathbf{x_{s}}\) and control \(\mathbf{u_{s}}\) trajectory, it computes the derivatives of the cost \((\mathbf{l}_{\mathbf{x}}, \mathbf{l}_{\mathbf{u}}, \mathbf{l}_{\mathbf{xx}}, \mathbf{l}_{\mathbf{xu}}, \mathbf{l}_{\mathbf{uu}})\) and dynamics \((\mathbf{f}_{\mathbf{x}}, \mathbf{f}_{\mathbf{u}})\).

Parameters:
  • xs[in] time-discrete state trajectory \(\mathbf{x_{s}}\) (size \(T+1\))

  • us[in] time-discrete control sequence \(\mathbf{u_{s}}\) (size \(T\))

Returns:

The total cost value \(l_{k}\)

void rollout(const std::vector<VectorXs> &us, std::vector<VectorXs> &xs)

Integrate the dynamics given a control sequence.

Parameters:
  • xs[in] time-discrete state trajectory \(\mathbf{x_{s}}\) (size \(T+1\))

  • us[in] time-discrete control sequence \(\mathbf{u_{s}}\) (size \(T\))

std::vector<VectorXs> rollout_us(const std::vector<VectorXs> &us)

Integrate the dynamics given a control sequence.

Parameters:

us[in] time-discrete control sequence \(\mathbf{u_{s}}\) (size \(T\))

Returns:

the time-discrete state trajectory \(\mathbf{x_{s}}\) (size \(T+1\))

void quasiStatic(std::vector<VectorXs> &us, const std::vector<VectorXs> &xs)

Compute the quasic static commands given a state trajectory.

Parameters:
  • us[out] time-discrete control sequence \(\mathbf{u_{s}}\) (size \(T\))

  • xs[in] time-discrete state trajectory \(\mathbf{x_{s}}\) (size \(T+1\))

std::vector<VectorXs> quasiStatic_xs(const std::vector<VectorXs> &xs)

Compute the quasic static commands given a state trajectory.

Parameters:

xs[in] time-discrete state trajectory \(\mathbf{x_{s}}\) (size \(T+1\))

Returns:

the time-discrete quasic static commands \(\mathbf{u_{s}}\) (size \(T\))

void circularAppend(std::shared_ptr<ActionModelAbstract> model, std::shared_ptr<ActionDataAbstract> data)

Circular append of the model and data onto the end running node.

Once we update the end running node, the first running mode is removed as in a circular buffer.

Parameters:
  • model[in] action model

  • data[in] action data

void circularAppend(std::shared_ptr<ActionModelAbstract> model)

Circular append of the model and data onto the end running node.

Once we update the end running node, the first running mode is removed as in a circular buffer. Note that this method allocates new data for the end running node.

Parameters:

model[in] action model

void updateNode(const std::size_t i, std::shared_ptr<ActionModelAbstract> model, std::shared_ptr<ActionDataAbstract> data)

Update the model and data for a specific node.

Parameters:
  • i[in] node index \((0\leq i \lt T+1)\)

  • model[in] action model

  • data[in] action data

void updateModel(const std::size_t i, std::shared_ptr<ActionModelAbstract> model)

Update a model and allocated new data for a specific node.

Parameters:
  • i[in] node index \((0\leq i \lt T+1)\)

  • model[in] action model

template<typename NewScalar>
ShootingProblemTpl<NewScalar> cast() const

Cast the shooting problem to a different scalar type.

It is useful for operations requiring different precision or scalar types.

Template Parameters:

NewScalar – The new scalar type to cast to.

Returns:

ShootingProblemTpl<NewScalar> A shooting problem with the new scalar type.

std::size_t get_T() const

Return the number of running nodes.

const VectorXs &get_x0() const

Return the initial state.

const std::vector<std::shared_ptr<ActionModelAbstract>> &get_runningModels() const

Return the running models.

const std::shared_ptr<ActionModelAbstract> &get_terminalModel() const

Return the terminal model.

const std::vector<std::shared_ptr<ActionDataAbstract>> &get_runningDatas() const

Return the running datas.

const std::shared_ptr<ActionDataAbstract> &get_terminalData() const

Return the terminal data.

void set_x0(const VectorXs &x0_in)

Modify the initial state.

void set_runningModels(const std::vector<std::shared_ptr<ActionModelAbstract>> &models)

Modify the running models and allocate new data.

void set_terminalModel(std::shared_ptr<ActionModelAbstract> model)

Modify the terminal model and allocate new data.

void set_nthreads(const int nthreads)

Modify the number of threads using with multithreading support.

For values lower than 1, the number of threads is chosen by CROCODDYL_WITH_NTHREADS macro

std::size_t get_nx() const

Return the dimension of the state tuple.

std::size_t get_ndx() const

Return the dimension of the tangent space of the state manifold.

std::size_t get_nthreads() const

Return the number of threads.

bool is_updated()

Return only once true is the shooting problem has been changed, otherwise false.

Public Members

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar

Protected Attributes

Scalar cost_

Total cost.

std::size_t T_

number of running nodes

VectorXs x0_

Initial state.

std::shared_ptr<ActionModelAbstract> terminal_model_

Terminal action model.

std::shared_ptr<ActionDataAbstract> terminal_data_

Terminal action data.

std::vector<std::shared_ptr<ActionModelAbstract>> running_models_

Running action model.

std::vector<std::shared_ptr<ActionDataAbstract>> running_datas_

Running action data.

std::size_t nx_

State dimension.

std::size_t ndx_

State rate dimension.

std::size_t nthreads_

Number of threads launch by the multi-threading application

bool is_updated_

Friends

template<class Scalar>
friend std::ostream &operator<<(std::ostream &os, const ShootingProblemTpl<Scalar> &problem)

Print information on the ‘ShootingProblem’.