Sleipnir Python API
Loading...
Searching...
No Matches
jormungandr.optimization.OCP Class Reference
Inheritance diagram for jormungandr.optimization.OCP:
jormungandr.optimization.Problem

Public Member Functions

None __init__ (self, int num_states, int num_inputs, datetime.timedelta|float dt, int num_steps, Callable[[VariableMatrix, VariableMatrix], VariableMatrix] dynamics, DynamicsType dynamics_type=DynamicsType.EXPLICIT_ODE, TimestepMethod timestep_method=TimestepMethod.FIXED, TranscriptionMethod transcription_method=TranscriptionMethod.DIRECT_TRANSCRIPTION)
 
None constrain_initial_state (self, float initial_state)
 
None constrain_initial_state (self, int initial_state)
 
None constrain_initial_state (self, Variable initial_state)
 
None constrain_initial_state (self, Annotated[NDArray[numpy.float64], dict(shape=(None, None))] initial_state)
 
None constrain_initial_state (self, VariableMatrix initial_state)
 
None constrain_final_state (self, float final_state)
 
None constrain_final_state (self, int final_state)
 
None constrain_final_state (self, Variable final_state)
 
None constrain_final_state (self, Annotated[NDArray[numpy.float64], dict(shape=(None, None))] final_state)
 
None constrain_final_state (self, VariableMatrix final_state)
 
None for_each_step (self, Callable[[VariableMatrix, VariableMatrix], None] callback)
 
None set_lower_input_bound (self, float lower_bound)
 
None set_lower_input_bound (self, int lower_bound)
 
None set_lower_input_bound (self, Variable lower_bound)
 
None set_lower_input_bound (self, Annotated[NDArray[numpy.float64], dict(shape=(None, None))] lower_bound)
 
None set_lower_input_bound (self, VariableMatrix lower_bound)
 
None set_upper_input_bound (self, float upper_bound)
 
None set_upper_input_bound (self, int upper_bound)
 
None set_upper_input_bound (self, Variable upper_bound)
 
None set_upper_input_bound (self, Annotated[NDArray[numpy.float64], dict(shape=(None, None))] upper_bound)
 
None set_upper_input_bound (self, VariableMatrix upper_bound)
 
None set_min_timestep (self, datetime.timedelta|float min_timestep)
 
None set_max_timestep (self, datetime.timedelta|float max_timestep)
 
VariableMatrix X (self)
 
VariableMatrix U (self)
 
VariableMatrix dt (self)
 
VariableMatrix initial_state (self)
 
VariableMatrix final_state (self)
 
- Public Member Functions inherited from jormungandr.optimization.Problem
Variable decision_variable (self)
 
VariableMatrix decision_variable (self, int rows, int cols=1)
 
VariableMatrix symmetric_decision_variable (self, int rows)
 
None minimize (self, Variable cost)
 
None minimize (self, VariableMatrix cost)
 
None minimize (self, float cost)
 
None maximize (self, Variable objective)
 
None maximize (self, VariableMatrix objective)
 
None maximize (self, float objective)
 
None subject_to (self, EqualityConstraints constraint)
 
None subject_to (self, InequalityConstraints constraint)
 
ExpressionType cost_function_type (self)
 
ExpressionType equality_constraint_type (self)
 
ExpressionType inequality_constraint_type (self)
 
ExitStatus solve (self, **kwargs)
 
None add_callback (self, Callable[[IterationInfo], bool] callback)
 
None clear_callbacks (self)
 

Detailed Description

This class allows the user to pose and solve a constrained optimal
control problem (OCP) in a variety of ways.

The system is transcripted by one of three methods (direct
transcription, direct collocation, or single-shooting) and additional
constraints can be added.

In direct transcription, each state is a decision variable constrained
to the integrated dynamics of the previous state. In direct
collocation, the trajectory is modeled as a series of cubic
polynomials where the centerpoint slope is constrained. In single-
shooting, states depend explicitly as a function of all previous
states and all previous inputs.

Explicit ODEs are integrated using RK4.

For explicit ODEs, the function must be in the form dx/dt = f(t, x,
u). For discrete state transition functions, the function must be in
the form xₖ₊₁ = f(t, xₖ, uₖ).

Direct collocation requires an explicit ODE. Direct transcription and
single-shooting can use either an ODE or state transition function.

https://underactuated.mit.edu/trajopt.html goes into more detail on
each transcription method.

Constructor & Destructor Documentation

◆ __init__()

None jormungandr.optimization.OCP.__init__ (   self,
int  num_states,
int  num_inputs,
datetime.timedelta | float  dt,
int  num_steps,
Callable[[VariableMatrix, VariableMatrix], VariableMatrix]  dynamics,
DynamicsType   dynamics_type = DynamicsType.EXPLICIT_ODE,
TimestepMethod   timestep_method = TimestepMethod.FIXED,
TranscriptionMethod   transcription_method = TranscriptionMethod.DIRECT_TRANSCRIPTION 
)
Build an optimization problem using a system evolution function
(explicit ODE or discrete state transition function).

Parameter ``num_states``:
    The number of system states.

Parameter ``num_inputs``:
    The number of system inputs.

Parameter ``dt``:
    The timestep for fixed-step integration.

Parameter ``num_steps``:
    The number of control points.

Parameter ``dynamics``:
    Function representing an explicit or implicit ODE, or a discrete
    state transition function. - Explicit: dx/dt = f(x, u, *) -
    Implicit: f([x dx/dt]', u, *) = 0 - State transition: xₖ₊₁ = f(xₖ,
    uₖ)

Parameter ``dynamics_type``:
    The type of system evolution function.

Parameter ``timestep_method``:
    The timestep method.

Parameter ``transcription_method``:
    The transcription method.

Reimplemented from jormungandr.optimization.Problem.

Member Function Documentation

◆ constrain_final_state() [1/5]

None jormungandr.optimization.OCP.constrain_final_state (   self,
Annotated[NDArray[numpy.float64], dict(shape=(None, None))]  final_state 
)

◆ constrain_final_state() [2/5]

None jormungandr.optimization.OCP.constrain_final_state (   self,
float  final_state 
)
Utility function to constrain the final state.

Parameter ``final_state``:
    the final state to constrain to.

◆ constrain_final_state() [3/5]

None jormungandr.optimization.OCP.constrain_final_state (   self,
int  final_state 
)

◆ constrain_final_state() [4/5]

None jormungandr.optimization.OCP.constrain_final_state (   self,
Variable  final_state 
)

◆ constrain_final_state() [5/5]

None jormungandr.optimization.OCP.constrain_final_state (   self,
VariableMatrix  final_state 
)

◆ constrain_initial_state() [1/5]

None jormungandr.optimization.OCP.constrain_initial_state (   self,
Annotated[NDArray[numpy.float64], dict(shape=(None, None))]  initial_state 
)

◆ constrain_initial_state() [2/5]

None jormungandr.optimization.OCP.constrain_initial_state (   self,
float  initial_state 
)
Utility function to constrain the initial state.

Parameter ``initial_state``:
    the initial state to constrain to.

◆ constrain_initial_state() [3/5]

None jormungandr.optimization.OCP.constrain_initial_state (   self,
int  initial_state 
)

◆ constrain_initial_state() [4/5]

None jormungandr.optimization.OCP.constrain_initial_state (   self,
Variable  initial_state 
)

◆ constrain_initial_state() [5/5]

None jormungandr.optimization.OCP.constrain_initial_state (   self,
VariableMatrix  initial_state 
)

◆ dt()

VariableMatrix jormungandr.optimization.OCP.dt (   self)
Get the timestep variables. After the problem is solved, this will
contain the timesteps corresponding to the optimized trajectory.

Shaped 1x(num_steps+1), although the last timestep is unused in the
trajectory.

Returns:
    The timestep variable matrix.

◆ final_state()

VariableMatrix jormungandr.optimization.OCP.final_state (   self)
Convenience function to get the final state in the trajectory.

Returns:
    The final state of the trajectory.

◆ for_each_step()

None jormungandr.optimization.OCP.for_each_step (   self,
Callable[[VariableMatrix, VariableMatrix], None]  callback 
)
Set the constraint evaluation function. This function is called
`num_steps+1` times, with the corresponding state and input
VariableMatrices.

Parameter ``callback``:
    The callback f(x, u) where x is the state and u is the input
    vector.

◆ initial_state()

VariableMatrix jormungandr.optimization.OCP.initial_state (   self)
Convenience function to get the initial state in the trajectory.

Returns:
    The initial state of the trajectory.

◆ set_lower_input_bound() [1/5]

None jormungandr.optimization.OCP.set_lower_input_bound (   self,
Annotated[NDArray[numpy.float64], dict(shape=(None, None))]  lower_bound 
)

◆ set_lower_input_bound() [2/5]

None jormungandr.optimization.OCP.set_lower_input_bound (   self,
float  lower_bound 
)
Convenience function to set a lower bound on the input.

Parameter ``lower_bound``:
    The lower bound that inputs must always be above. Must be shaped
    (num_inputs)x1.

◆ set_lower_input_bound() [3/5]

None jormungandr.optimization.OCP.set_lower_input_bound (   self,
int  lower_bound 
)

◆ set_lower_input_bound() [4/5]

None jormungandr.optimization.OCP.set_lower_input_bound (   self,
Variable  lower_bound 
)

◆ set_lower_input_bound() [5/5]

None jormungandr.optimization.OCP.set_lower_input_bound (   self,
VariableMatrix  lower_bound 
)

◆ set_max_timestep()

None jormungandr.optimization.OCP.set_max_timestep (   self,
datetime.timedelta | float  max_timestep 
)
Convenience function to set an upper bound on the timestep.

Parameter ``max_timestep``:
    The maximum timestep.

◆ set_min_timestep()

None jormungandr.optimization.OCP.set_min_timestep (   self,
datetime.timedelta | float  min_timestep 
)
Convenience function to set a lower bound on the timestep.

Parameter ``min_timestep``:
    The minimum timestep.

◆ set_upper_input_bound() [1/5]

None jormungandr.optimization.OCP.set_upper_input_bound (   self,
Annotated[NDArray[numpy.float64], dict(shape=(None, None))]  upper_bound 
)

◆ set_upper_input_bound() [2/5]

None jormungandr.optimization.OCP.set_upper_input_bound (   self,
float  upper_bound 
)
Convenience function to set an upper bound on the input.

Parameter ``upper_bound``:
    The upper bound that inputs must always be below. Must be shaped
    (num_inputs)x1.

◆ set_upper_input_bound() [3/5]

None jormungandr.optimization.OCP.set_upper_input_bound (   self,
int  upper_bound 
)

◆ set_upper_input_bound() [4/5]

None jormungandr.optimization.OCP.set_upper_input_bound (   self,
Variable  upper_bound 
)

◆ set_upper_input_bound() [5/5]

None jormungandr.optimization.OCP.set_upper_input_bound (   self,
VariableMatrix  upper_bound 
)

◆ U()

VariableMatrix jormungandr.optimization.OCP.U (   self)
Get the input variables. After the problem is solved, this will
contain the inputs corresponding to the optimized trajectory.

Shaped (num_inputs)x(num_steps+1), although the last input step is
unused in the trajectory.

Returns:
    The input variable matrix.

◆ X()

VariableMatrix jormungandr.optimization.OCP.X (   self)
Get the state variables. After the problem is solved, this will
contain the optimized trajectory.

Shaped (num_states)x(num_steps+1).

Returns:
    The state variable matrix.

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