Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ repo_url = "github.com/control-toolbox/OptimalControlProblems.jl"
# ==============================
# --- Generate Problems Documentation ---
# ==============================
draft = true # If true, code blocks in markdown are not executed
draft = false # If true, code blocks in markdown are not executed
exclude_from_draft=Symbol[
# :beam # example: exclude beam from draft docs
]
Expand Down Expand Up @@ -135,7 +135,10 @@ with_problems_browser() do browser_file # generates the problems browser and rem
"Get a problem" => "tutorial-get.md",
"Solve a problem" => "tutorial-solve.md",
],
"Developers" => ["Add a problem" => "dev-add.md", "API" => "dev-api.md"],
"Developers" => [
"Add a problem" => "dev-add.md",
"API" => "dev-api.md",
],
],
plugins=[links],
)
Expand Down
100 changes: 66 additions & 34 deletions docs/problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ function draft_meta(draft::Union{Bool,Nothing})
if isnothing(draft)
return ""
elseif draft
return """```@meta\nDraft = true\n```"""
return """```@meta\nDraft = true\n```\n"""
else
return """```@meta\nDraft = false\n```"""
return """```@meta\nDraft = false\n```\n"""
end
end

Expand All @@ -24,10 +24,19 @@ end
# -----------------------------------
function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Union{Bool,Nothing})

TITLE = uppercasefirst(replace(PROBLEM, "_" => " "))
TITLE = "[" * uppercasefirst(replace(PROBLEM, "_" => " ")) * "](@id description-$PROBLEM)"
DRAFT = draft_meta(draft)
LEFT_MARGIN = get_left_margin(Symbol(PROBLEM))

VARIABLE_COMPONENTS = isnothing(OptimalControlProblems.metadata(Symbol(PROBLEM))[:variable_name]) ? "" :
"""
The variable components are named:

```@example main
metadata(:$PROBLEM)[:variable_name]
```
"""

documentation=DRAFT * """
# $TITLE

Expand Down Expand Up @@ -67,6 +76,35 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
nothing # hide
```

## Metadata

The state components are named:

```@example main
metadata(:$PROBLEM)[:state_name]
```

The control components are named:

```@example main
metadata(:$PROBLEM)[:control_name]
```

$VARIABLE_COMPONENTS

The default values of the parameters are:

```@example main
metadata(:$PROBLEM)[:parameters]
using Printf # hide
println("Parameter = Value") # hide
println("------------------") # hide
for e ∈ pairs(metadata(:$PROBLEM)[:parameters]) # hide
@printf("%6s = ", string(e.first)) # hide
@printf("%11.4e\\n", e.second) # hide
end # hide
```

## Initial guess

Before solving the problem, it is often useful to inspect the initial guess (sometimes called the first iterate). This guess is obtained by running the NLP solver with `max_iter = 0`, which evaluates the problem formulation without performing any optimisation steps.
Expand All @@ -85,8 +123,8 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
# -----------------------------
# Extract dimensions from metadata
# -----------------------------
x_vars = metadata[problem][:state_name]
u_vars = metadata[problem][:control_name]
x_vars = metadata(problem)[:state_name]
u_vars = metadata(problem)[:control_name]
n_states = length(x_vars)
n_controls = length(u_vars)

Expand Down Expand Up @@ -179,14 +217,12 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
Before solving, we can inspect the discretisation details of the problem. The table below reports the number of grid points, decision variables, and constraints associated with the chosen formulation.

```@example main
push!(data_pb,
(
Problem=:$PROBLEM,
Grid_Size=metadata[:$PROBLEM][:N],
Variables=get_nvar(nlp_model($PROBLEM(OptimalControlBackend()))),
Constraints=get_ncon(nlp_model($PROBLEM(OptimalControlBackend()))),
)
)
push!(data_pb,(
Problem=:$PROBLEM,
Grid_Size=metadata(:$PROBLEM)[:grid_size],
Variables=get_nvar(nlp_model($PROBLEM(OptimalControlBackend()))),
Constraints=get_ncon(nlp_model($PROBLEM(OptimalControlBackend()))),
))
data_pb # hide
```

Expand Down Expand Up @@ -236,24 +272,20 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni

```@example main
# from OptimalControl model
push!(data_re,
(
Model=:OptimalControl,
Flag=nlp_oc_sol.status,
Iterations=nlp_oc_sol.iter,
Objective=nlp_oc_sol.objective,
)
)
push!(data_re,(
Model=:OptimalControl,
Flag=nlp_oc_sol.status,
Iterations=nlp_oc_sol.iter,
Objective=nlp_oc_sol.objective,
))

# from JuMP model
push!(data_re,
(
Model=:JuMP,
Flag=termination_status(nlp_jp),
Iterations=barrier_iterations(nlp_jp),
Objective=objective_value(nlp_jp),
)
)
push!(data_re,(
Model=:JuMP,
Flag=termination_status(nlp_jp),
Iterations=barrier_iterations(nlp_jp),
Objective=objective_value(nlp_jp),
))
data_re # hide
```

Expand Down Expand Up @@ -294,9 +326,9 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
v_jp = variable(problem, nlp_jp)
i_jp = iterations(problem, nlp_jp)

x_vars = metadata[problem][:state_name]
u_vars = metadata[problem][:control_name]
v_vars = metadata[problem][:variable_name]
x_vars = metadata(problem)[:state_name]
u_vars = metadata(problem)[:control_name]
v_vars = metadata(problem)[:variable_name]

println("┌─ ", string(problem))
println("│")
Expand Down Expand Up @@ -365,8 +397,8 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
ocp_sol = build_ocp_solution(docp, nlp_oc_sol)

# dimensions
n = state_dimension(ocp_sol) # or length(metadata[:$PROBLEM][:state_name])
m = control_dimension(ocp_sol) # or length(metadata[:$PROBLEM][:control_name])
n = state_dimension(ocp_sol) # or length(metadata(:$PROBLEM)[:state_name])
m = control_dimension(ocp_sol) # or length(metadata(:$PROBLEM)[:control_name])

# from OptimalControl solution
plt = plot(
Expand Down
38 changes: 19 additions & 19 deletions docs/src/assets/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ uuid = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
version = "0.8.13"

[[deps.ADTypes]]
git-tree-sha1 = "60665b326b75db6517939d0e1875850bc4a54368"
git-tree-sha1 = "27cecae79e5cc9935255f90c53bb831cc3c870d7"
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
version = "1.17.0"
version = "1.18.0"

[deps.ADTypes.extensions]
ADTypesChainRulesCoreExt = "ChainRulesCore"
Expand Down Expand Up @@ -105,9 +105,9 @@ weakdeps = ["HTTP", "JSON"]

[[deps.CTDirect]]
deps = ["CTBase", "CTModels", "DocStringExtensions", "HSL", "MKL", "SparseArrays"]
git-tree-sha1 = "1b3aa9b9b9bbb32b90bed66d16998fcb89848c21"
git-tree-sha1 = "223310e80a2c0043c1b8f580349b05f0e79c58dc"
uuid = "790bbbee-bee9-49ee-8912-a9de031322d5"
version = "0.16.3"
version = "0.16.4"

[deps.CTDirect.extensions]
CTDirectExtADNLP = ["ADNLPModels"]
Expand Down Expand Up @@ -137,9 +137,9 @@ version = "0.8.8"

[[deps.CTModels]]
deps = ["CTBase", "DocStringExtensions", "Interpolations", "LinearAlgebra", "MLStyle", "MacroTools", "OrderedCollections", "Parameters", "RecipesBase"]
git-tree-sha1 = "20872a1b453a9b7a94822cc00a22c6741f71cf68"
git-tree-sha1 = "13ff06553d6396590c0b09c9b9a5e0dee058af92"
uuid = "34c4fa32-2049-4079-8329-de33c2a22e2d"
version = "0.6.5"
version = "0.6.6"

[deps.CTModels.extensions]
CTModelsJLD = "JLD2"
Expand Down Expand Up @@ -266,9 +266,9 @@ version = "1.16.0"

[[deps.DataFrames]]
deps = ["Compat", "DataAPI", "DataStructures", "Future", "InlineStrings", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrecompileTools", "PrettyTables", "Printf", "Random", "Reexport", "SentinelArrays", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"]
git-tree-sha1 = "a37ac0840a1196cd00317b57e39d6586bf0fd6f6"
git-tree-sha1 = "c967271c27a95160e30432e011b58f42cd7501b5"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.7.1"
version = "1.8.0"

[[deps.DataStructures]]
deps = ["OrderedCollections"]
Expand Down Expand Up @@ -437,9 +437,9 @@ version = "1.11.0"

[[deps.FillArrays]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "6a70198746448456524cb442b8af316927ff3e1a"
git-tree-sha1 = "173e4d8f14230a7523ae11b9a3fa9edb3e0efd78"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "1.13.0"
version = "1.14.0"

[deps.FillArrays.extensions]
FillArraysPDMatsExt = "PDMats"
Expand Down Expand Up @@ -470,9 +470,9 @@ version = "1.3.7"

[[deps.ForwardDiff]]
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "LogExpFunctions", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions"]
git-tree-sha1 = "f0090eb9f8e9d151563dd2300fc3ca3f76b90fe8"
git-tree-sha1 = "dc41303865a16274ecb8450c220021ce1e0cf05f"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "1.2.0"
version = "1.2.1"
weakdeps = ["StaticArrays"]

[deps.ForwardDiff.extensions]
Expand Down Expand Up @@ -550,9 +550,9 @@ version = "2.51.1+0"

[[deps.Glib_jll]]
deps = ["Artifacts", "GettextRuntime_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Zlib_jll"]
git-tree-sha1 = "35fbd0cefb04a516104b8e183ce0df11b70a3f1a"
git-tree-sha1 = "50c11ffab2a3d50192a228c313f05b5b5dc5acb2"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.84.3+0"
version = "2.86.0+0"

[[deps.Graphite2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
Expand Down Expand Up @@ -1171,10 +1171,10 @@ uuid = "21216c6a-2e73-6563-6e65-726566657250"
version = "1.5.0"

[[deps.PrettyTables]]
deps = ["Crayons", "LaTeXStrings", "Markdown", "PrecompileTools", "Printf", "Reexport", "StringManipulation", "Tables"]
git-tree-sha1 = "1101cd475833706e4d0e7b122218257178f48f34"
deps = ["Crayons", "LaTeXStrings", "Markdown", "PrecompileTools", "Printf", "REPL", "Reexport", "StringManipulation", "Tables"]
git-tree-sha1 = "86e787c2c5e29c1ff9d0b72227bcc29d7d39e14e"
uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
version = "2.4.0"
version = "3.0.8"

[[deps.Printf]]
deps = ["Unicode"]
Expand Down Expand Up @@ -1346,9 +1346,9 @@ version = "1.11.0"

[[deps.SparseConnectivityTracer]]
deps = ["ADTypes", "DocStringExtensions", "FillArrays", "LinearAlgebra", "Random", "SparseArrays"]
git-tree-sha1 = "339efef69fda0cccf14c06a483561527e9169b8f"
git-tree-sha1 = "e49c106eb7c78f55cdfa39e8bddeda24e1e09fce"
uuid = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
version = "1.0.1"
version = "1.0.2"

[deps.SparseConnectivityTracer.extensions]
SparseConnectivityTracerLogExpFunctionsExt = "LogExpFunctions"
Expand Down
Loading
Loading