-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from control-toolbox/init_CTDirect
v0.8.0
- Loading branch information
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "CTBase" | ||
uuid = "54762871-cc72-4466-b8e8-f6c8b58076cd" | ||
authors = ["Olivier Cots <[email protected]>"] | ||
version = "0.7.12" | ||
version = "0.8.0" | ||
|
||
[deps] | ||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
$(TYPEDSIGNATURES) | ||
Initialization of the OCP solution that can be used when solving the discretized problem DOCP. | ||
# Constructors: | ||
- `OCPInit()`: default initialization | ||
- `OCPInit(x_init, u_init, v_init)`: constant vector and/or function handles | ||
- `OCPInit(sol)`: from existing solution | ||
# Examples | ||
```julia-repl | ||
julia> init = OCPInit() | ||
julia> init = OCPInit(x_init=[0.1, 0.2], u_init=0.3) | ||
julia> init = OCPInit(x_init=[0.1, 0.2], u_init=0.3, v_init=0.5) | ||
julia> init = OCPInit(x_init=[0.1, 0.2], u_init=t->sin(t), v_init=0.5) | ||
julia> init = OCPInit(sol) | ||
``` | ||
""" | ||
mutable struct OCPInit | ||
|
||
state_init::Function | ||
control_init::Function | ||
variable_init::Union{Nothing, ctVector} | ||
costate_init::Function | ||
multipliers_init::Union{Nothing, ctVector} | ||
info::Symbol | ||
|
||
# warm start from solution | ||
function OCPInit(sol::OptimalControlSolution) | ||
|
||
init = new() | ||
init.info = :from_solution | ||
init.state_init = t -> sol.state(t) | ||
init.control_init = t -> sol.control(t) | ||
init.variable_init = sol.variable | ||
#+++ add costate and scalar multipliers | ||
|
||
return init | ||
end | ||
|
||
# constant / functional init with explicit arguments | ||
function OCPInit(; state::Union{Nothing, ctVector, Function}=nothing, control::Union{Nothing, ctVector, Function}=nothing, variable::Union{Nothing, ctVector}=nothing) | ||
|
||
init = new() | ||
init.info = :constant_or_function | ||
init.state_init = (state isa Function) ? t -> state(t) : t -> state | ||
init.control_init = (control isa Function) ? t -> control(t) : t -> control | ||
init.variable_init = variable | ||
#+++ add costate and scalar multipliers | ||
|
||
return init | ||
end | ||
|
||
# version with arguments as collection/iterable | ||
# (may be fused with version above ?) | ||
function OCPInit(init) | ||
|
||
x_init = :state ∈ keys(init) ? init[:state] : nothing | ||
u_init = :control ∈ keys(init) ? init[:control] : nothing | ||
v_init = :variable ∈ keys(init) ? init[:variable] : nothing | ||
return OCPInit(state=x_init, control=u_init, variable=v_init) | ||
|
||
end | ||
|
||
end |