Skip to content

Commit ad25bbc

Browse files
authored
Merge pull request #150 from control-toolbox/135-general-configurable-problems
Configurable problems
2 parents 2430104 + 7c212bf commit ad25bbc

File tree

117 files changed

+3303
-1858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+3303
-1858
lines changed

docs/make.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ repo_url = "github.com/control-toolbox/OptimalControlProblems.jl"
9191
# ==============================
9292
# --- Generate Problems Documentation ---
9393
# ==============================
94-
draft = true # If true, code blocks in markdown are not executed
94+
draft = false # If true, code blocks in markdown are not executed
9595
exclude_from_draft=Symbol[
9696
# :beam # example: exclude beam from draft docs
9797
]
@@ -135,7 +135,10 @@ with_problems_browser() do browser_file # generates the problems browser and rem
135135
"Get a problem" => "tutorial-get.md",
136136
"Solve a problem" => "tutorial-solve.md",
137137
],
138-
"Developers" => ["Add a problem" => "dev-add.md", "API" => "dev-api.md"],
138+
"Developers" => [
139+
"Add a problem" => "dev-add.md",
140+
"API" => "dev-api.md",
141+
],
139142
],
140143
plugins=[links],
141144
)

docs/problems.jl

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ function draft_meta(draft::Union{Bool,Nothing})
55
if isnothing(draft)
66
return ""
77
elseif draft
8-
return """```@meta\nDraft = true\n```"""
8+
return """```@meta\nDraft = true\n```\n"""
99
else
10-
return """```@meta\nDraft = false\n```"""
10+
return """```@meta\nDraft = false\n```\n"""
1111
end
1212
end
1313

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

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

31+
VARIABLE_COMPONENTS = isnothing(OptimalControlProblems.metadata(Symbol(PROBLEM))[:variable_name]) ? "" :
32+
"""
33+
The variable components are named:
34+
35+
```@example main
36+
metadata(:$PROBLEM)[:variable_name]
37+
```
38+
"""
39+
3140
documentation=DRAFT * """
3241
# $TITLE
3342
@@ -67,6 +76,35 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
6776
nothing # hide
6877
```
6978
79+
## Metadata
80+
81+
The state components are named:
82+
83+
```@example main
84+
metadata(:$PROBLEM)[:state_name]
85+
```
86+
87+
The control components are named:
88+
89+
```@example main
90+
metadata(:$PROBLEM)[:control_name]
91+
```
92+
93+
$VARIABLE_COMPONENTS
94+
95+
The default values of the parameters are:
96+
97+
```@example main
98+
metadata(:$PROBLEM)[:parameters]
99+
using Printf # hide
100+
println("Parameter = Value") # hide
101+
println("------------------") # hide
102+
for e ∈ pairs(metadata(:$PROBLEM)[:parameters]) # hide
103+
@printf("%6s = ", string(e.first)) # hide
104+
@printf("%11.4e\\n", e.second) # hide
105+
end # hide
106+
```
107+
70108
## Initial guess
71109
72110
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.
@@ -85,8 +123,8 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
85123
# -----------------------------
86124
# Extract dimensions from metadata
87125
# -----------------------------
88-
x_vars = metadata[problem][:state_name]
89-
u_vars = metadata[problem][:control_name]
126+
x_vars = metadata(problem)[:state_name]
127+
u_vars = metadata(problem)[:control_name]
90128
n_states = length(x_vars)
91129
n_controls = length(u_vars)
92130
@@ -179,14 +217,12 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
179217
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.
180218
181219
```@example main
182-
push!(data_pb,
183-
(
184-
Problem=:$PROBLEM,
185-
Grid_Size=metadata[:$PROBLEM][:N],
186-
Variables=get_nvar(nlp_model($PROBLEM(OptimalControlBackend()))),
187-
Constraints=get_ncon(nlp_model($PROBLEM(OptimalControlBackend()))),
188-
)
189-
)
220+
push!(data_pb,(
221+
Problem=:$PROBLEM,
222+
Grid_Size=metadata(:$PROBLEM)[:grid_size],
223+
Variables=get_nvar(nlp_model($PROBLEM(OptimalControlBackend()))),
224+
Constraints=get_ncon(nlp_model($PROBLEM(OptimalControlBackend()))),
225+
))
190226
data_pb # hide
191227
```
192228
@@ -236,24 +272,20 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
236272
237273
```@example main
238274
# from OptimalControl model
239-
push!(data_re,
240-
(
241-
Model=:OptimalControl,
242-
Flag=nlp_oc_sol.status,
243-
Iterations=nlp_oc_sol.iter,
244-
Objective=nlp_oc_sol.objective,
245-
)
246-
)
275+
push!(data_re,(
276+
Model=:OptimalControl,
277+
Flag=nlp_oc_sol.status,
278+
Iterations=nlp_oc_sol.iter,
279+
Objective=nlp_oc_sol.objective,
280+
))
247281
248282
# from JuMP model
249-
push!(data_re,
250-
(
251-
Model=:JuMP,
252-
Flag=termination_status(nlp_jp),
253-
Iterations=barrier_iterations(nlp_jp),
254-
Objective=objective_value(nlp_jp),
255-
)
256-
)
283+
push!(data_re,(
284+
Model=:JuMP,
285+
Flag=termination_status(nlp_jp),
286+
Iterations=barrier_iterations(nlp_jp),
287+
Objective=objective_value(nlp_jp),
288+
))
257289
data_re # hide
258290
```
259291
@@ -294,9 +326,9 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
294326
v_jp = variable(problem, nlp_jp)
295327
i_jp = iterations(problem, nlp_jp)
296328
297-
x_vars = metadata[problem][:state_name]
298-
u_vars = metadata[problem][:control_name]
299-
v_vars = metadata[problem][:variable_name]
329+
x_vars = metadata(problem)[:state_name]
330+
u_vars = metadata(problem)[:control_name]
331+
v_vars = metadata(problem)[:variable_name]
300332
301333
println("┌─ ", string(problem))
302334
println("│")
@@ -365,8 +397,8 @@ function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Uni
365397
ocp_sol = build_ocp_solution(docp, nlp_oc_sol)
366398
367399
# dimensions
368-
n = state_dimension(ocp_sol) # or length(metadata[:$PROBLEM][:state_name])
369-
m = control_dimension(ocp_sol) # or length(metadata[:$PROBLEM][:control_name])
400+
n = state_dimension(ocp_sol) # or length(metadata(:$PROBLEM)[:state_name])
401+
m = control_dimension(ocp_sol) # or length(metadata(:$PROBLEM)[:control_name])
370402
371403
# from OptimalControl solution
372404
plt = plot(

docs/src/assets/Manifest.toml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ uuid = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
1111
version = "0.8.13"
1212

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

1818
[deps.ADTypes.extensions]
1919
ADTypesChainRulesCoreExt = "ChainRulesCore"
@@ -105,9 +105,9 @@ weakdeps = ["HTTP", "JSON"]
105105

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

112112
[deps.CTDirect.extensions]
113113
CTDirectExtADNLP = ["ADNLPModels"]
@@ -137,9 +137,9 @@ version = "0.8.8"
137137

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

144144
[deps.CTModels.extensions]
145145
CTModelsJLD = "JLD2"
@@ -266,9 +266,9 @@ version = "1.16.0"
266266

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

273273
[[deps.DataStructures]]
274274
deps = ["OrderedCollections"]
@@ -437,9 +437,9 @@ version = "1.11.0"
437437

438438
[[deps.FillArrays]]
439439
deps = ["LinearAlgebra"]
440-
git-tree-sha1 = "6a70198746448456524cb442b8af316927ff3e1a"
440+
git-tree-sha1 = "173e4d8f14230a7523ae11b9a3fa9edb3e0efd78"
441441
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
442-
version = "1.13.0"
442+
version = "1.14.0"
443443

444444
[deps.FillArrays.extensions]
445445
FillArraysPDMatsExt = "PDMats"
@@ -470,9 +470,9 @@ version = "1.3.7"
470470

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

478478
[deps.ForwardDiff.extensions]
@@ -550,9 +550,9 @@ version = "2.51.1+0"
550550

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

557557
[[deps.Graphite2_jll]]
558558
deps = ["Artifacts", "JLLWrappers", "Libdl"]
@@ -1171,10 +1171,10 @@ uuid = "21216c6a-2e73-6563-6e65-726566657250"
11711171
version = "1.5.0"
11721172

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

11791179
[[deps.Printf]]
11801180
deps = ["Unicode"]
@@ -1346,9 +1346,9 @@ version = "1.11.0"
13461346

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

13531353
[deps.SparseConnectivityTracer.extensions]
13541354
SparseConnectivityTracerLogExpFunctionsExt = "LogExpFunctions"

0 commit comments

Comments
 (0)