Skip to content

Commit

Permalink
added default args tol and max_iter; commented tutorials moved to Opt… (
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMartinon authored Jul 4, 2024
1 parent cae404f commit be1e9b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ makedocs(
size_threshold_ignore = ["api-ctbase.md"]),
pages = [
"Introduction" => "index.md",
"Tutorial" => "tutorial.md",
"Continuation" => "continuation.md",
#"Tutorial" => "tutorial.md",
#"Continuation" => "continuation.md",
"API" => "api.md",
"Developers" => "dev-api.md",
]
Expand Down
10 changes: 7 additions & 3 deletions ext/CTSolveExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function CommonSolve.solve(docp::DOCP;
display::Bool=CTDirect.__display(),
print_level::Integer=CTDirect.__print_level_ipopt(),
mu_strategy::String=CTDirect.__mu_strategy_ipopt(),
max_iter::Integer=CTDirect.__max_iter(),
tol::Real=CTDirect.__tol(),
linear_solver::String=CTDirect.__linear_solver(),
kwargs...)

Expand All @@ -38,13 +40,13 @@ function CommonSolve.solve(docp::DOCP;
nlp = getNLP(docp)
if isnothing(init)
# use initial guess embedded in the DOCP
docp_solution = ipopt(nlp, print_level=print_level, mu_strategy=mu_strategy, sb="yes", linear_solver=linear_solver; kwargs...)
docp_solution = ipopt(nlp, print_level=print_level, mu_strategy=mu_strategy, tol=tol, max_iter=max_iter, sb="yes", linear_solver=linear_solver; kwargs...)
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))

docp_solution = ipopt(nlp, x0=x0, print_level=print_level, mu_strategy=mu_strategy, sb="yes", linear_solver=linear_solver; kwargs...)
docp_solution = ipopt(nlp, x0=x0, print_level=print_level, mu_strategy=mu_strategy, tol=tol, max_iter=max_iter, sb="yes", linear_solver=linear_solver; kwargs...)
end

# return DOCP solution
Expand All @@ -65,14 +67,16 @@ function CommonSolve.solve(ocp::OptimalControlModel,
display::Bool=CTDirect.__display(),
print_level::Integer=CTDirect.__print_level_ipopt(),
mu_strategy::String=CTDirect.__mu_strategy_ipopt(),
max_iter::Integer=CTDirect.__max_iter(),
tol::Real=CTDirect.__tol(),
linear_solver::String=CTDirect.__linear_solver(),
kwargs...)

# build discretized OCP
docp = directTranscription(ocp, description, init=init, grid_size=grid_size, time_grid=time_grid)

# solve DOCP (NB. init is already embedded in docp)
docp_solution = solve(docp, display=display, print_level=print_level, mu_strategy=mu_strategy, linear_solver=linear_solver; kwargs...)
docp_solution = solve(docp, display=display, print_level=print_level, mu_strategy=mu_strategy, tol=tol, max_iter=max_iter, linear_solver=linear_solver; kwargs...)

# build and return OCP solution
return OCPSolutionFromDOCP(docp, docp_solution)
Expand Down
4 changes: 3 additions & 1 deletion src/CTDirect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ using ADNLPModels # docp model with AD
using LinearAlgebra # norm
using CommonSolve: solve

# Other declarations
# Other declarations (+++ sort among modules)
const __grid_size_direct() = 100
const __print_level_ipopt = CTBase.__print_level_ipopt
const __mu_strategy_ipopt = CTBase.__mu_strategy_ipopt
const __tol() = 1e-8
const __max_iter() = 1000
const __display = CTBase.__display
const nlp_constraints! = CTBase.nlp_constraints!
const matrix2vec = CTBase.matrix2vec
Expand Down

0 comments on commit be1e9b0

Please sign in to comment.