Skip to content

Commit

Permalink
v0.9.0 (#142)
Browse files Browse the repository at this point in the history
* prepare v0.9.0 (todo: comment local init and its export)

* comment local init and its export

* local tests ok, removed _ for OptimalControlInit

* renamed box dim to range

* solve appears in api doc, listed under commonsolve

* v0.9.0
  • Loading branch information
PierreMartinon authored Jul 3, 2024
1 parent d7c21a9 commit ffdabc9
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 267 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CTSolveExt = ["NLPModelsIpopt", "HSL"]

[compat]
ADNLPModels = "0.8"
CTBase = "0.10"
CTBase = "0.11"
DocStringExtensions = "0.9"
HSL = "0.4"
julia = "1.10"
3 changes: 0 additions & 3 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[compat]
julia = "1.9"
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using HSL
using JLD2
using JSON3
using Plots
using CommonSolve

DocMeta.setdocmeta!(CTBase, :DocTestSetup, :(using CTBase); recursive = true)
DocMeta.setdocmeta!(CTDirect, :DocTestSetup, :(using CTDirect); recursive = true)
Expand Down
11 changes: 1 addition & 10 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@

```@index
Pages = ["api.md"]
Modules = [CTDirect]
Modules = [CTDirect, CommonSolve]
Order = [:module, :constant, :type, :function, :macro]
```

## Available methods

```@example
using CTDirect
available_methods()
```

## Documentation

```@autodocs
Expand All @@ -23,8 +16,6 @@ Order = [:module, :constant, :type, :function, :macro]
Private = false
```

<! -- manually add docstrings from package extensions -->
<! -- does not work for solve which is not in CTDirect -->
```@docs
solve
save_OCP_solution
Expand Down
2 changes: 1 addition & 1 deletion ext/CTSolveExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function CommonSolve.solve(docp::DOCP;
else
# use given initial guess
ocp = docp.ocp
x0 = CTDirect.DOCP_initial_guess(docp, _OptimalControlInit(init, state_dim=ocp.state_dimension, control_dim=ocp.control_dimension, variable_dim=ocp.variable_dimension))
x0 = CTDirect.DOCP_initial_guess(docp, OptimalControlInit(init, state_dim=ocp.state_dimension, control_dim=ocp.control_dimension, variable_dim=ocp.variable_dimension))

docp_solution = ipopt(nlp, x0=x0, print_level=print_level, mu_strategy=mu_strategy, sb="yes", linear_solver=linear_solver; kwargs...)
end
Expand Down
4 changes: 1 addition & 3 deletions src/CTDirect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include("solution.jl")
include("solve.jl")

# re exports
export solve # CommonSolve
export solve # from CommonSolve, extended in CTSolveExt

# exports
export available_methods
Expand All @@ -39,6 +39,4 @@ export export_OCP_solution
export read_OCP_solution
export OCP_Solution_discrete

export _OptimalControlInit #temp, later from CTBase

end
12 changes: 6 additions & 6 deletions src/problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ function variables_bounds(docp)

# state box
offset = 0
if dim_state_box(ocp) > 0
if dim_state_range(ocp) > 0
for i in 0:N
for j in 1:dim_state_box(ocp)
for j in 1:dim_state_range(ocp)
indice = docp.state_box[2][j]
l_var[offset+indice] = docp.state_box[1][j]
u_var[offset+indice] = docp.state_box[3][j]
Expand All @@ -190,9 +190,9 @@ function variables_bounds(docp)

# control box
offset = (N+1) * docp.dim_NLP_x
if dim_control_box(ocp) > 0
if dim_control_range(ocp) > 0
for i in 0:N
for j in 1:dim_control_box(ocp)
for j in 1:dim_control_range(ocp)
indice = docp.control_box[2][j]
l_var[offset+indice] = docp.control_box[1][j]
u_var[offset+indice] = docp.control_box[3][j]
Expand All @@ -203,8 +203,8 @@ function variables_bounds(docp)

# variable box
offset = (N+1) * (docp.dim_NLP_x + docp.dim_NLP_u)
if dim_variable_box(ocp) > 0
for j in 1:dim_variable_box(ocp)
if dim_variable_range(ocp) > 0
for j in 1:dim_variable_range(ocp)
indice = docp.variable_box[2][j]
l_var[offset+indice] = docp.variable_box[1][j]
u_var[offset+indice] = docp.variable_box[3][j]
Expand Down
8 changes: 4 additions & 4 deletions src/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ function OCPSolutionFromDOCP_raw(docp, T, X, U, v, P;
end

# box constraints multipliers
if dim_state_box(ocp) > 0
if dim_state_range(ocp) > 0
# remove additional state for lagrange cost
mbox_x_l = ctinterpolate(T, matrix2vec(mult_state_box_lower[:,1:ocp.state_dimension], 1))
mbox_x_u = ctinterpolate(T, matrix2vec(mult_state_box_upper[:,1:ocp.state_dimension], 1))
sol.infos[:mult_state_box_lower] = t -> mbox_x_l(t)
sol.infos[:mult_state_box_upper] = t -> mbox_x_u(t)
end
if dim_control_box(ocp) > 0
if dim_control_range(ocp) > 0
mbox_u_l = ctinterpolate(T, matrix2vec(mult_control_box_lower, 1))
mbox_u_u = ctinterpolate(T, matrix2vec(mult_control_box_upper, 1))
sol.infos[:mult_control_box_lower] = t -> mbox_u_l(t)
sol.infos[:mult_control_box_upper] = t -> mbox_u_u(t)
end
if dim_variable_box(ocp) > 0
if dim_variable_range(ocp) > 0
sol.infos[:mult_variable_box_lower] = mult_variable_box_lower
sol.infos[:mult_variable_box_upper] = mult_variable_box_upper
end
Expand Down Expand Up @@ -193,7 +193,7 @@ function parse_DOCP_solution(docp, solution, multipliers_constraints, multiplier
mult_state_box_upper[i,:] = vget_state_at_time_step(mult_U, docp, i-1)
mult_control_box_upper[i,:] = vget_control_at_time_step(mult_U, docp, i-1)
end
if dim_variable_box(ocp) > 0
if dim_variable_range(ocp) > 0
mult_variable_box_lower = get_variable(mult_L, docp)
mult_variable_box_upper = get_variable(mult_U, docp)
end
Expand Down
4 changes: 2 additions & 2 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function directTranscription(ocp::OptimalControlModel,
docp = DOCP(ocp, grid_size, time_grid)

# set initial guess
x0 = DOCP_initial_guess(docp, _OptimalControlInit(init, state_dim=ocp.state_dimension, control_dim=ocp.control_dimension, variable_dim=ocp.variable_dimension))
x0 = DOCP_initial_guess(docp, OptimalControlInit(init, state_dim=ocp.state_dimension, control_dim=ocp.control_dimension, variable_dim=ocp.variable_dimension))

# set bounds
docp.var_l, docp.var_u = variables_bounds(docp)
Expand Down Expand Up @@ -67,6 +67,6 @@ function setInitialGuess(docp::DOCP, init)

nlp = getNLP(docp)
ocp = docp.ocp
nlp.meta.x0 .= DOCP_initial_guess(docp, _OptimalControlInit(init, state_dim=ocp.state_dimension, control_dim=ocp.control_dimension, variable_dim=ocp.variable_dimension))
nlp.meta.x0 .= DOCP_initial_guess(docp, OptimalControlInit(init, state_dim=ocp.state_dimension, control_dim=ocp.control_dimension, variable_dim=ocp.variable_dimension))

end
Loading

0 comments on commit ffdabc9

Please sign in to comment.