Skip to content

Commit 8e25854

Browse files
authored
Merge pull request #102 from control-toolbox/91-doc-problems
Add descriptions of the problems and references
2 parents acb4f06 + 454fa5c commit 8e25854

Some content is hidden

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

64 files changed

+2595
-175
lines changed

docs/make.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ cp(
6969
repo_url = "github.com/control-toolbox/OptimalControlProblems.jl"
7070

7171
#
72-
draft = false
72+
draft = true
7373
exclude_from_draft=Symbol[
7474
# :beam
7575
]
@@ -80,9 +80,11 @@ PROBLEMS_PAGES = generate_documentation_problems(;
8080
makedocs(;
8181
draft=draft, # if draft is true, then the julia code from .md is not executed # debug
8282
# to disable the draft mode in a specific markdown file, use the following:
83-
# ```@meta
84-
# Draft = false
85-
# ```
83+
#=
84+
```@meta
85+
Draft = false
86+
```
87+
=#
8688
#remotes=nothing,
8789
warnonly=:cross_references,
8890
sitename="OptimalControlProblems.jl",

docs/problems.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function generate_documentation(PROBLEM::String; draft::Union{Bool,Nothing})
1+
function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Union{Bool,Nothing})
22
TITLE = uppercasefirst(replace(PROBLEM, "_" => " "))
33

44
DRAFT = if isnothing(draft)
@@ -20,11 +20,11 @@ function generate_documentation(PROBLEM::String; draft::Union{Bool,Nothing})
2020
documentation=DRAFT * """
2121
# $TITLE
2222
23-
We consider the `:$PROBLEM` problem.
23+
$DESCRIPTION
2424
2525
## Packages
2626
27-
First, import all the necessary packages and define the DataFrames to store the data from the model and the resolutions.
27+
Import all necessary packages and define DataFrames to store information about the problem and resolution results.
2828
2929
```@example main
3030
using OptimalControlProblems # to access the Beam model
@@ -57,7 +57,7 @@ function generate_documentation(PROBLEM::String; draft::Union{Bool,Nothing})
5757
5858
### Solve the problem
5959
60-
Import the problem and solve it.
60+
Import the OptimalControl problem and solve it to obtain the solution.
6161
6262
```@example main
6363
# import model
@@ -77,7 +77,7 @@ function generate_documentation(PROBLEM::String; draft::Union{Bool,Nothing})
7777
nothing # hide
7878
```
7979
80-
For numerical comparison with the JuMP model resolution, define:
80+
Compute state, control, objective, and iteration data for comparison:
8181
8282
```@example main
8383
t_oc = time_grid(ocp_sol)
@@ -119,7 +119,7 @@ function generate_documentation(PROBLEM::String; draft::Union{Bool,Nothing})
119119
120120
### Plot the solution
121121
122-
To plot the solution, get the number of states and controls from the metadata:
122+
Visualise states, costates, and controls for the OptimalControl solution:
123123
124124
```@example main
125125
x_vars = OptimalControlProblems.metadata[:$PROBLEM][:state_name]
@@ -194,7 +194,7 @@ function generate_documentation(PROBLEM::String; draft::Union{Bool,Nothing})
194194
195195
### Plot the solution
196196
197-
Add the state, costate, and control from the JuMP model to the plot:
197+
Overlay the JuMP solution on the previous plots:
198198
199199
```@example main
200200
t = time_grid(:$PROBLEM, model_jp) # t0, ..., tN = tf
@@ -219,7 +219,7 @@ function generate_documentation(PROBLEM::String; draft::Union{Bool,Nothing})
219219
220220
## Initial guess
221221
222-
The initial guess (or first iterate) is obtained by fixing `max_iter=0` in the solver:
222+
The initial guess can also be visualised by running the solver with `max_iter=0`.
223223
224224
```@raw html
225225
<details><summary>Unfold to see the code for plotting the initial guess.</summary>
@@ -308,7 +308,7 @@ function generate_documentation(PROBLEM::String; draft::Union{Bool,Nothing})
308308
309309
## Numerical comparison
310310
311-
Next, compare the number of iterations required to obtain the solutions. Also compare the final times, objective values, and the state and costate trajectories in L² norm.
311+
Compare OptimalControl and JuMP solutions in terms of iterations, \$L^2\$ norms, and objective values.
312312
313313
```@raw html
314314
<details><summary>Unfold to get the code of the numerical comparison.</summary>
@@ -448,9 +448,12 @@ function generate_documentation_problems(;
448448
filename = joinpath(@__DIR__, "src", "problems", string(problem) * ".md")
449449
touch(filename)
450450

451+
# get the description
452+
description = read(joinpath(@__DIR__, "..", "ext", "Descriptions", string(problem) * ".md"), String)
453+
451454
# generate the content
452455
draft_problem = problem exclude_from_draft ? false : draft
453-
contents = generate_documentation(string(problem); draft=draft_problem)
456+
contents = generate_documentation(string(problem), description; draft=draft_problem)
454457

455458
# write the content in the file
456459
open(filename, "a") do io

docs/src/assets/Manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.11.6"
44
manifest_format = "2.0"
5-
project_hash = "474bb317741c3e2578ba5be1b92a71a19071c7b7"
5+
project_hash = "e4420c03c5c208c963d869daa22ca1e9ba918652"
66

77
[[deps.ADNLPModels]]
88
deps = ["ADTypes", "ForwardDiff", "LinearAlgebra", "NLPModels", "Requires", "ReverseDiff", "SparseArrays", "SparseConnectivityTracer", "SparseMatrixColorings"]

docs/src/assets/Project.toml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
1515
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
1616

1717
[compat]
18-
Documenter = "1.14"
19-
Ipopt = "1.10"
20-
JuMP = "1.28"
21-
Markdown = "1.11"
18+
CTModels = "0.6"
19+
DataFrames = "1"
20+
Documenter = "1"
21+
DocumenterInterLinks = "1"
22+
ExaModels = "0.9"
23+
Ipopt = "1"
24+
JuMP = "1"
25+
Markdown = "1"
26+
NLPModels = "0.21"
2227
NLPModelsIpopt = "0.10"
23-
OptimalControl = "1.1"
24-
TOML = "1.0"
28+
OptimalControl = "1"
29+
Plots = "1"
30+
TOML = "1"

ext/Descriptions/beam.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
The *beam problem* is a classical benchmark in constrained optimal control. It originates from the Euler–Bernoulli beam model (see Bryson et al. 1963). The system describes the deflection of a clamped flexible beam under an external force. Both the state trajectory $x(\cdot)$ and the control $u(\cdot)$ are decision variables. The aim is to minimise the control effort subject to boundary conditions and a state inequality constraint on the displacement.
2+
3+
The problem can be written as
4+
5+
```math
6+
\min_{x,\,u} J(x,u) = \int_0^1 u(t)^2 \, dt
7+
```
8+
9+
subject to the dynamics
10+
```math
11+
\dot{x}_1(t) = x_2(t), \qquad
12+
\dot{x}_2(t) = u(t),
13+
```
14+
15+
with boundary conditions
16+
```math
17+
x_1(0) = 0, \quad x_1(1) = 0, \qquad
18+
x_2(0) = 1, \quad x_2(1) = -1,
19+
```
20+
21+
and the constraints
22+
```math
23+
-10 \le u(t) \le 5, \qquad
24+
0 \le x_1(t) \le a,
25+
```
26+
27+
where $a$ denotes the maximal admissible deflection (e.g. $a=0.1$ in the current implementation).
28+
29+
### Qualitative behaviour
30+
31+
- If $a \geq 1/4$, the inequality constraint is inactive and the solution is $x(t) = t(1-t)$.
32+
- If $a \in [1/6, 1/4]$, there is a single touch point at $t=1/2$.
33+
- If $a < 1/6$, a boundary arc appears, with the constraint active on an interval.
34+
35+
These features illustrate the role of state inequality constraints in shaping optimal trajectories and controls.
36+
37+
### Characteristics
38+
39+
- Linear–quadratic dynamics and cost.
40+
- Asymmetric control bounds.
41+
- State inequality constraint induces touch points or boundary arcs depending on $a$.
42+
- Widely used as a benchmark in numerical optimal control libraries.
43+
44+
### References
45+
46+
- Bryson, A.E., Denham, W.F., & Dreyfus, S.E. (1963). *Optimal programming problems with inequality constraints I: necessary conditions for extremal solutions*. AIAA Journal.
47+
- BOCOP examples: Clamped Beam problem. [Examples-BOCOP.pdf](https://project.inria.fr/bocop/files/2017/05/Examples-BOCOP.pdf)

ext/Descriptions/bioreactor.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
This problem models a coupled photobioreactor–digester system for methane production.
2+
The system consists of three state variables: the algae concentration $y(t)$, the substrate concentration $s(t)$, and the biomass concentration $b(t)$.
3+
The control variable $u(t)$ represents the input flow rate between the two units.
4+
The dynamics include algal growth driven by light, substrate consumption, and biomass evolution.
5+
The aim is to maximise methane production over a fixed time horizon under biological and operational constraints.
6+
7+
### Problem formulation
8+
9+
We minimise
10+
11+
```math
12+
\min_{y,\,s,\,b,\,u} J(y,s,b,u) = - \frac{1}{\beta+c} \int_0^T \mu_2(s(t))\, b(t)\, dt,
13+
```
14+
15+
subject to the dynamics
16+
```math
17+
\dot{y}(t) = \frac{\mu(t)\, y(t)}{1+y(t)} - (r+u(t))\, y(t),
18+
```
19+
```math
20+
\dot{s}(t) = -\mu_2(s(t))\, b(t) + u(t)\, \beta\big(\gamma y(t) - s(t)\big),
21+
```
22+
```math
23+
\dot{b}(t) = \big(\mu_2(s(t)) - u(t)\, \beta\big)\, b(t),
24+
```
25+
26+
with
27+
- **Light model:** $\mu(t) = \mu_{\text{bar}} \,\max(0,\sin(\tau(t)))^2$, where $\tau(t)$ encodes a periodic day–night cycle,
28+
- **Growth function (Monod law):** $\mu_2(s) = \mu_2^m \,\dfrac{s}{K_s + s}$.
29+
30+
### Constraints
31+
32+
- Control bounds: $0 \leq u(t) \leq 1$,
33+
- State bounds: $y(t) \geq 0,\; s(t) \geq 0,\; b(t) \geq 10^{-3}$,
34+
- Initial conditions: $0.05 \leq y(0) \leq 0.25$, $0.5 \leq s(0) \leq 5$, $0.5 \leq b(0) \leq 3$.
35+
36+
The horizon is fixed to $T = 200$ (rescaled units), corresponding to several day–night periods.
37+
38+
### Qualitative behaviour
39+
40+
The optimal solution exploits the periodic structure of the problem:
41+
during illuminated phases, algal growth is favoured, while in dark phases methane production becomes predominant.
42+
The control exhibits a near bang–bang structure, alternating between minimal and maximal input flows, with possible singular arcs when substrate and biomass reach balanced levels.
43+
The constraints on positivity of the states are typically active for $b(t)$ at the beginning of the process.
44+
45+
### References
46+
47+
- Bayen, T., Mairet, F., Martinon, P., & Sebbah, M. (2014). *Analysis of a periodic optimal control problem connected to microalgae anaerobic digestion*. Optimal Control Applications and Methods. [DOI:10.1002/oca.2127](https://hal.archives-ouvertes.fr/hal-00860570)
48+
- Bayen, T., Mairet, F., Martinon, P., & Sebbah, M. (2013). *Optimising the anaerobic digestion of microalgae in a coupled process*. 13th European Control Conference.
49+
- Barbosa, M.J., & Wijffels, R.H. (2010). *An Outlook on Microalgal Biofuels*. Science, 329, 796–799.
50+
- Betts, J.T. (2001). *Practical methods for optimal control using nonlinear programming*. SIAM.
51+
- BOCOP repository: https://github.com/control-toolbox/bocop/tree/main/bocop

ext/Descriptions/cart_pendulum.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
This problem involves swinging up a pendulum mounted on a cart, a classical **underactuated system**.
2+
The goal is to move the pendulum from its downward equilibrium to the upright position while controlling the horizontal motion of the cart, in **minimum time**.
3+
4+
### System Dynamics
5+
6+
The system has four states and one control:
7+
8+
- $x$ : cart position
9+
- $v$ : cart velocity
10+
- $\theta$ : pendulum angle from downward vertical
11+
- $\omega$ : pendulum angular velocity
12+
- $F_{\rm ex}$ : horizontal force applied to the cart (control)
13+
14+
The dynamics are expressed as
15+
16+
```math
17+
\dot{x} = v
18+
```
19+
20+
```math
21+
\dot{v} = -\frac{1}{J} \, c
22+
```
23+
24+
```math
25+
\dot{\theta} = \omega
26+
```
27+
28+
```math
29+
\dot{\omega} = \alpha(\dot{v})
30+
```
31+
32+
where
33+
34+
```math
35+
\alpha(ddx) = \frac{0.5 \, L \, m}{I + 0.25 \, m L^2} \big(-ddx \cos\theta - g \sin\theta\big)
36+
```
37+
38+
```math
39+
\text{ddCOG} = L \, \omega \, [-\sin\theta, \cos\theta] + \frac{L}{2} \,[\cos\theta, \sin\theta] \, \alpha(ddx) + [ddx,0]
40+
```
41+
42+
```math
43+
\text{FXFY} = m \, \text{ddCOG} + [0, m g]
44+
```
45+
46+
```math
47+
c = -\text{FXFY}_x + F_{\rm ex} - m_{\rm cart} ddx - J ddx
48+
```
49+
50+
Here, $J$ represents the effective mass of the cart, $m$ and $m_{\rm cart}$ are the pendulum and cart masses, $L$ is the pendulum length, and $I$ its moment of inertia. The variable $ddx$ is an auxiliary variable related to the cart acceleration used for the dynamics formulation.
51+
52+
### Boundary Conditions
53+
54+
- **Initial conditions**:
55+
56+
```math
57+
x(0) = 0, \quad \theta(0) = 0, \quad \omega(0) = 0
58+
```
59+
60+
- **Final conditions**:
61+
62+
```math
63+
\theta(T) = \pi, \quad \omega(T) = 0
64+
```
65+
66+
- Cart position and velocity constraints:
67+
68+
```math
69+
|x(t)| \le 1, \quad |v(t)| \le 2
70+
```
71+
72+
- Control limits:
73+
74+
```math
75+
|F_{\rm ex}(t)| \le 5
76+
```
77+
78+
- Time horizon:
79+
80+
```math
81+
T \ge 0.1
82+
```
83+
84+
### Objective
85+
86+
The goal is to **minimize the final time** $T$:
87+
88+
```math
89+
J = T \to \min
90+
```
91+
92+
subject to the dynamics, boundary conditions, and state/control constraints.
93+
94+
### References
95+
96+
- Vanroye, L., Sathya, A., De Schutter, J., & Decré, W. (2023). FATROP: A Fast Constrained Optimal Control Problem Solver for Robot Trajectory Optimization and Control. *arXiv preprint arXiv:2303.16746*. Retrieved from https://arxiv.org/pdf/2303.16746
97+
- Åström, K. J., & Furuta, K. (2000). Swinging up a pendulum by energy control. *Automatica*, 36(2), 287–295.
98+
- Lipp, T., & Boyd, S. (2014). Variations and extensions of the cart-pole swing-up problem. *Stanford University Technical Report*.

0 commit comments

Comments
 (0)