Public API
This page lists exported symbols of CTSolvers.DOCP.
From CTSolvers.DOCP
CTSolvers.DOCP [Module]
CTSolvers.DOCP Module
DOCP (Discretized Optimal Control Problem) module.
This module defines the DiscretizedModel type and the associated API to build NLP models and reconstruct OCP solutions via the Optimization and Modelers contracts.
The DOCP layer is the bridge between continuous-time models (from CTModels) and the solver/modeler infrastructure provided by CTSolvers.
AbstractDiscretizer [Abstract Type]
CTSolvers.DOCP.AbstractDiscretizer Type
abstract type AbstractDiscretizer <: CTBase.Strategies.AbstractStrategyAbstract base type for all discretization strategies.
Concrete subtypes implement specific transcription methods (collocation, direct shooting, etc.) and are defined in the package providing the method. A discretizer is a Strategies.AbstractStrategy: it carries validated options and drives discretize to turn an optimal control problem into a CTSolvers.DOCP.DiscretizedModel.
See also: DiscretizedModel, discretize.
DiscretizedModel [Struct]
CTSolvers.DOCP.DiscretizedModel Type
struct DiscretizedModel{TO<:CTModels.Models.AbstractModel, TD<:CTSolvers.DOCP.AbstractDiscretizer, TC<:CTBase.Core.AbstractCache} <: CTSolvers.Optimization.AbstractOptimizationProblemDiscretized optimal control problem ready for NLP solving.
A thin pairing of an optimal control problem with the discretizer that produced it, plus a backend cache. The actual NLP model and OCP solution are produced by multiple dispatch on (DiscretizedModel, modeler) through the build_model / build_solution contract, implemented in the package providing the discretizer (e.g. CTDirect). This mirrors Flow{system, integrator} on the ODE side.
Fields
ocp::TO: The original optimal control problem.discretizer::TD: The discretization strategy used.cache::TC: Backend cache (<: CTBase.Core.AbstractCache), opaque to CTSolvers, populated by the implementing package (e.g. CTDirect'sDOCPCache).
Type parameters
TO <: CTModels.AbstractModelTD <: AbstractDiscretizerTC <: CTBase.Core.AbstractCache
Display
Shown in the REPL as a short tree (problem spaces and times, discretizer options, cache type name) whose length does not depend on the grid size, and by print on one line.
See also: ocp_model, discretize, build_model, build_solution.
discretize [Function]
CTSolvers.DOCP.discretize Function
discretize(
ocp::CTModels.Models.AbstractModel,
discretizer::CTSolvers.DOCP.AbstractDiscretizer
)Discretize an optimal control problem into a CTSolvers.DOCP.DiscretizedModel.
Contract
Must be implemented in the package providing discretizer, dispatching on its concrete type, e.g. CTSolvers.discretize(ocp, ::Collocation) in CTDirect.
Arguments
ocp::CTModels.AbstractModel: The optimal control problem.discretizer::AbstractDiscretizer: The discretization strategy.
Returns
- A
CTSolvers.DOCP.DiscretizedModelwith a populated cache.
See also: build_model, build_solution.
nlp_model [Function]
CTSolvers.DOCP.nlp_model Function
nlp_model(
prob::CTSolvers.DOCP.DiscretizedModel,
initial_guess,
modeler::CTSolvers.Modelers.AbstractNLPModeler
)Build an NLP model from a discretized optimal control problem.
This is a convenience wrapper around build_model that returns only the backend NLP model (the nlp field of the CTSolvers.Optimization.BuiltModel). Use build_model directly when the build-time cache is needed (e.g. before build_solution).
Arguments
prob::DiscretizedModel: The discretized OCPinitial_guess: Initial guess for the NLP solvermodeler: The modeler to use (e.g., Modelers.ADNLP, Modelers.Exa)
Returns
NLPModels.AbstractNLPModel: The NLP model
Example
nlp = nlp_model(docp, initial_guess, modeler)See also: CTSolvers.DOCP.ocp_solution, CTSolvers.Optimization.build_model, CTSolvers.Optimization.BuiltModel
nlp_model(
built::CTSolvers.Optimization.BuiltModel{<:CTSolvers.DOCP.DiscretizedModel}
) -> AnyReturn the NLP model of a built discretized optimal control problem.
Accessor of the CTSolvers.Optimization.BuiltModel returned by build_model for a CTSolvers.DOCP.DiscretizedModel: it returns the NLP that was built, without building anything. A BuiltModel of another problem type has no such method.
Arguments
built::Optimization.BuiltModel{<:DiscretizedModel}: The built model bundle returned bybuild_modelfor aDiscretizedModel
Returns
- The backend NLP model (e.g. an
ADNLPModelor anExaModel), thenlpfield ofbuilt
Throws
MethodError: ifbuiltholds a problem that is not aDiscretizedModel
Example
built = build_model(docp, initial_guess, modeler)
stats = ipopt(nlp_model(built))
sol = ocp_solution(built, stats, modeler)See also: CTSolvers.DOCP.ocp_model, CTSolvers.DOCP.ocp_solution, CTSolvers.Optimization.build_model
ocp_model [Function]
CTSolvers.DOCP.ocp_model Function
ocp_model(
docp::CTSolvers.DOCP.DiscretizedModel
) -> CTModels.Models.AbstractModelExtract the original optimal control problem from a discretized problem.
Arguments
docp::DiscretizedModel: The discretized optimal control problem
Returns
- The original optimal control problem
Example
ocp = ocp_model(docp)See also: CTSolvers.DOCP.DiscretizedModel, CTSolvers.DOCP.nlp_model
ocp_model(
built::CTSolvers.Optimization.BuiltModel{<:CTSolvers.DOCP.DiscretizedModel}
) -> CTModels.Models.AbstractModelReturn the original optimal control problem of a built discretized optimal control problem.
Accessor of the CTSolvers.Optimization.BuiltModel returned by build_model for a CTSolvers.DOCP.DiscretizedModel: same result as ocp_model on the DiscretizedModel it was built from. A BuiltModel of another problem type has no such method.
Arguments
built::Optimization.BuiltModel{<:DiscretizedModel}: The built model bundle returned bybuild_modelfor aDiscretizedModel
Returns
- The original optimal control problem
Throws
MethodError: ifbuiltholds a problem that is not aDiscretizedModel
Example
built = build_model(docp, initial_guess, modeler)
ocp_model(built) === ocp_model(docp) # trueSee also: CTSolvers.DOCP.nlp_model, CTSolvers.DOCP.DiscretizedModel
ocp_solution [Function]
CTSolvers.DOCP.ocp_solution Function
ocp_solution(
built::CTSolvers.Optimization.BuiltModel{<:CTSolvers.DOCP.DiscretizedModel},
model_solution::SolverCore.AbstractExecutionStats,
modeler::CTSolvers.Modelers.AbstractNLPModeler
)Build an optimal control solution from NLP execution statistics.
This is a convenience wrapper around build_solution for the CTSolvers.Optimization.BuiltModel returned by build_model for a CTSolvers.DOCP.DiscretizedModel. A BuiltModel of another problem type has no such method: call build_solution directly for it.
Arguments
built::Optimization.BuiltModel{<:DiscretizedModel}: The built model bundle returned bybuild_modelfor aDiscretizedModelmodel_solution::SolverCore.AbstractExecutionStats: NLP solver outputmodeler: The modeler used for building
Returns
- The OCP solution, as returned by
build_solution
Throws
MethodError: ifbuiltholds a problem that is not aDiscretizedModel
Example
built = build_model(docp, initial_guess, modeler)
sol = ocp_solution(built, nlp_stats, modeler)See also: CTSolvers.DOCP.nlp_model, CTSolvers.Optimization.build_solution, CTSolvers.Optimization.BuiltModel