Time discretization

class rtctools.optimization.collocated_integrated_optimization_problem.CollocatedIntegratedOptimizationProblem(**kwargs)[source]

Bases: rtctools.optimization.optimization_problem.OptimizationProblem

Discretizes your model using a mixed collocation/integration scheme.

Collocation means that the discretized model equations are included as constraints between state variables in the optimization problem.


To ensure that your optimization problem only has globally optimal solutions, any model equations that are collocated must be linear. By default, all model equations are collocated, and linearity of the model equations is verified. Working with non-linear models is possible, but discouraged.

Variables:check_collocation_linearity – If True, check whether collocation constraints are linear. Default is True.

A list of states that are integrated rather than collocated.


This is an experimental feature.

Deprecated since version 2.4: Support for integrated states will be removed in a future release.


Configures the implicit function used for time step integration.

Returns:A dictionary of CasADi rootfinder options. See the CasADi documentation for details.

Interpolation method for variable.

Parameters:variable – Variable name.
Returns:Interpolation method for the given variable.
map_options() → Dict[str, Union[str, int]][source]

Returns a dictionary of CasADi map() options.

Option Type Default value
mode ``str` openmp
n_threads int None

The mode option controls the mode of the map() call. Valid values include openmp, thread, and unroll. See the CasADi and documentation for detailed documentation on these modes.

The n_threads option controls the number of threads used when in thread mode.


Not every CasADi build has support for OpenMP enabled. For such builds, the thread mode offers an alternative parallelization mode.


The use of expand=True in solver_options() may negate the parallelization benefits obtained using map().

Returns:A dictionary of options for the map() call used to evaluate constraints on every time stamp.

RTC-Tools discretizes differential equations of the form

\[\dot{x} = f(x, u)\]

using the \(\theta\)-method

\[x_{i+1} = x_i + \Delta t \left[\theta f(x_{i+1}, u_{i+1}) + (1 - \theta) f(x_i, u_i)\right]\]

The default is \(\theta = 1\), resulting in the implicit or backward Euler method. Note that in this case, the control input at the initial time step is not used.

Set \(\theta = 0\) to use the explicit or forward Euler method. Note that in this case, the control input at the final time step is not used.


This is an experimental feature for \(0 < \theta < 1\).

Deprecated since version 2.4: Support for semi-explicit collocation (theta < 1) will be removed in a future release.


List of time stamps for variable (to optimize for).

Parameters:variable – Variable name.
Returns:A list of time stamps for the given variable.