Cost Functions and Objectives

This page details the functions related to building and evaluating cost functions and objectives.

Quadratic Cost Functions

TrajectoryOptimization.QuadraticCostType
mutable struct QuadraticCost{TQ, TR, TH, Tq, Tr, T} <: CostFunction

Cost function of the form 1/2xₙᵀ Qf xₙ + qfᵀxₙ + ∫ ( 1/2xᵀQx + 1/2uᵀRu + xᵀHu + q⁠ᵀx + rᵀu ) dt from 0 to tf R must be positive definite, Q and Qf must be positive semidefinite

Constructor use any of the following constructors:

QuadraticCost(Q, R, H, q, r, c)
QuadraticCost(Q, R; H, q, r, c)
QuadraticCost(Q, q, c)

Any optional or omitted values will be set to zero(s).

source
TrajectoryOptimization.LQRCostFunction
LQRCost(Q, R, xf)
LQRCost(Q, R, xf, uf; checks)

Cost function of the form $(x-x_f)^T Q (x_x_f) + u^T R u$ R must be positive definite, Q must be positive semidefinite

source

Indexed Cost Functions

Missing docstring.

Missing docstring for IndexedCost. Check Documenter's build log for details.

Adding Cost Functions

Right now, TrajectoryOptimization supports addition of QuadraticCosts, but extensions to general cost function addition should be straightforward, as long as the cost function all have the same state and control dimensions.

Adding quadratic cost functions:

n,m = 4,5
Q1 = Diagonal(@SVector [1.0, 1.0, 1.0, 1.0, 0.0])
R1 = Diagonal(@SVector [1.0, 0.0, 0.0, 0.0, 0.0, 0.0])
Q2 = Diagonal(@SVector [1.0, 1.0, 1.0, 1.0, 2.0])
R2 = Diagonal(@SVector [0.0, 1.0, 1.0, 1.0, 1.0, 1.0])
cost1 = QuadraticCost(Q1, R1)
cost2 = QuadraticCost(Q2, R2)
cost3 = cost1 + cost2
# cost3 is equivalent to QuadraticCost(Q1+Q2, R1+R2)

CostExpansion Type

The CostExpansion type stores the pieces of the second order Taylor expansion of the cost for the entire trajectory, stored as vectors of Static Vectors or Static Matrices. e.g. to get the Hessian with respect to x at knotpoint 5 you would use E.xx[5].

Missing docstring.

Missing docstring for CostExpansion. Check Documenter's build log for details.

Objective

TrajectoryOptimization.ObjectiveType
struct Objective{C} <: TrajectoryOptimization.AbstractObjective

Objective: stores stage cost(s) and terminal cost functions

Constructors:

Objective(cost, N)
Objective(cost, cost_term, N)
Objective(costs::Vector{<:CostFunction}, cost_term)
Objective(costs::Vector{<:CostFunction})
source
TrajectoryOptimization.costMethod
cost(obj::Objective, Z::Traj)::Float64
cost(obj::Objective, dyn_con::DynamicsConstraint{Q}, Z::Traj)

Evaluate the cost for a trajectory. Calculate the cost gradient for an entire trajectory. If a dynamics constraint is given, use the appropriate integration rule, if defined.

source
Missing docstring.

Missing docstring for cost_gradient. Check Documenter's build log for details.

TrajectoryOptimization.cost_gradient!Function
Qx,Qu = cost_gradient(cost::CostFunction, z::KnotPoint)

Get Qx, Qu pieces of gradient of cost function, multiplied by dt

source
cost_gradient!(E::CostExpansion, obj::Objective, Z::Traj)
cost_gradient!(E::CostExpansion, obj::Objective, dyn_con::DynamicsConstraint{Q}, Z::Traj)

Calculate the cost gradient for an entire trajectory. If a dynamics constraint is given, use the appropriate integration rule, if defined.

source
Missing docstring.

Missing docstring for cost_hessian. Check Documenter's build log for details.

TrajectoryOptimization.cost_hessian!Function
Qxx,Quu,Qux = cost_hessian(cost::CostFunction, z::KnotPoint)

Get Qxx, Quu, Qux pieces of Hessian of cost function, multiplied by dt

source
cost_hessian!(E::CostExpansion, obj::Objective, Z::Traj)

Calculate the cost Hessian for an entire trajectory

source