Skip to content

Commit 623f5dd

Browse files
authored
Merge pull request #207 from control-toolbox/206-dev-test-all-new-problems-with-gpu
@ocots maybe exclude - robot - mountain car
2 parents 1093342 + f33ddf4 commit 623f5dd

34 files changed

+1619
-64
lines changed

docs/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ If you want to ask a question, feel free to start a discussion [here](https://gi
5151
- [0Yassine0](https://github.com/0Yassine0)
5252
- [Nico77310](https://github.com/Nico77310)
5353
- [frapac](https://github.com/frapac)
54+
- [AmielMetier](https://github.com/AmielMetier)
55+
- [HediChennoufi](https://github.com/HediChennoufi)
5456
- [BOCOP - A collection of examples](https://project.inria.fr/bocop/files/2017/05/Examples-BOCOP.pdf)
5557
- [COPS: Large-Scale Optimization Problems](https://www.mcs.anl.gov/~more/cops) and [COPSBenchmark.jl](https://github.com/MadNLP/COPSBenchmark.jl)
5658

ext/Descriptions/balanced_field.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
The **Aircraft Balanced Field Length Calculation** is a classic aeronautical engineering problem used to determine the minimum runway length required for a safe takeoff or a safe stop in the event of an engine failure.
2+
This implementation focuses on the **takeoff climb** phase with one engine out, starting from the critical engine failure speed $V_1$.
3+
4+
### Mathematical formulation
5+
6+
The problem is to minimise the final range $r(t_f)$ to reach the screen height (usually 35 ft).
7+
The state vector is $x(t) = [r(t), v(t), h(t), \gamma(t)]^ op$ and the control is the angle of attack $\alpha(t)$.
8+
9+
```math
10+
\begin{aligned}
11+
\min_{\alpha, t_f} \quad & r(t_f) \\
12+
ext{s.t.} \quad & \dot{r}(t) = v(t) \cos \gamma(t), \\
13+
& \dot{v}(t) = \frac{T \cos \alpha(t) - D}{m} - g \sin \gamma(t), \\
14+
& \dot{h}(t) = v(t) \sin \gamma(t), \\
15+
& \dot{\gamma}(t) = \frac{T \sin \alpha(t) + L}{m v(t)} - \frac{g \cos \gamma(t)}{v(t)}, \\
16+
& h(t_f) = 10.668 ext{ m (35 ft)}, \\
17+
& \gamma(t_f) = 5^\circ.
18+
\end{aligned}
19+
```
20+
21+
The aerodynamic forces $L$ and $D$ depend on the angle of attack $\alpha$, velocity $v$, and altitude $h$ (ground effect).
22+
23+
### Parameters
24+
25+
The parameters are based on a mid-size jet aircraft (nominal values from Dymos):
26+
27+
| Parameter | Symbol | Value |
28+
|-----------|--------|-------|
29+
| Mass | $m$ | 79015.8 kg |
30+
| Surface | $S$ | 124.7 m² |
31+
| Thrust (1 engine) | $T$ | 120102.0 N |
32+
| Screen height | $h_{tf}$ | 10.668 m |
33+
34+
### Characteristics
35+
36+
- Multi-state nonlinear dynamics,
37+
- Free final time $t_f$,
38+
- Ground effect inclusion in the drag model ($K$ coefficient),
39+
- Control bounds on the angle of attack $\alpha$,
40+
- Boundary conditions representing $V_1$ conditions and final climb requirements.
41+
42+
### References
43+
44+
- **Dymos Documentation**. [*Aircraft Balanced Field Length Calculation*.](https://openmdao.github.io/dymos/examples/balanced_field/balanced_field.html).
45+
Illustrates the full multi-phase BFL calculation using Dymos and OpenMDAO.
46+
47+
- **Betts, J. T. (2010)**. *Practical Methods for Optimal Control and Estimation Using Nonlinear Programming*. SIAM.
48+
Discusses takeoff and landing trajectory optimization in Chapter 6.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
The **Brachistochrone problem** is a classical benchmark in the history of calculus of variations and optimal control.  
2+
It seeks the shape of a curve (or wire) connecting two points $A$ and $B$ within a vertical plane, such that a bead sliding frictionlessly under the influence of uniform gravity travels from $A$ to $B$ in the shortest possible time.  
3+
Originating from the challenge posed by Johann Bernoulli in 1696 [Bernoulli 1696](https://doi.org/10.1002/andp.19163551307), it marks the birth of modern optimal control theory.  
4+
The problem involves nonlinear dynamics where the state includes position and velocity, and the control is the path's angle, with the final time $t_f$ being a decision variable to be minimised.
5+
6+
### Mathematical formulation
7+
8+
The problem can be stated as a free final time optimal control problem:
9+
10+
```math
11+
\begin{aligned}
12+
\min_{u(\cdot), t_f} \quad & J = t_f = \int_0^{t_f} 1 \,\mathrm{d}t \\[1em]
13+
\text{s.t.} \quad & \dot{x}(t) = v(t) \sin u(t), \\[0.5em]
14+
& \dot{y}(t) = v(t) \cos u(t), \\[0.5em]
15+
& \dot{v}(t) = g \cos u(t), \\[0.5em]
16+
& x(0) = x_0, \; y(0) = y_0, \; v(0) = v_0, \\[0.5em]
17+
& x(t_f) = x_f, \; y(t_f) = y_f,
18+
\end{aligned}
19+
```
20+
21+
where $u(t)$ represents the angle of the tangent to the curve with respect to the vertical axis, and $g$ is the gravitational acceleration.
22+
23+
### Qualitative behaviour
24+
25+
This problem is a classic example of **minimum time control** with nonlinear dynamics.  
26+
Unlike the shortest path problem (a straight line), the optimal trajectory balances the need to minimize path length with the need to maximize velocity.
27+
28+
The analytical solution to this problem is a **cycloid**—the curve traced by a point on the rim of a circular wheel as the wheel rolls along a straight line without slipping.  
29+
Specifically:
30+
31+
- **Energy Conservation**: Since the system is conservative and frictionless, the speed at any height $h$ is given by $v = \sqrt{2gh}$ (assuming start from rest). This implies that maximizing vertical drop early in the trajectory increases velocity for the remainder of the path.
32+
- **Concavity**: The optimal curve is concave up. It starts steeply (vertical tangent if $v_0=0$) to gain speed quickly, then flattens out near the bottom before potentially rising again to reach the target.
33+
- **Singularity**: At the initial point, if $v_0=0$, the control is theoretically singular as the bead has no velocity to direct. Numerical solvers often require a small non-zero initial velocity or a robust initial guess to handle this start.
34+
35+
The control $u(t)$ is continuous and varies smoothly to trace the cycloidal arc.
36+
37+
### Characteristics
38+
39+
- **Nonlinear dynamics** involving trigonometric functions of the control.
40+
- **Free final time** problem (time-optimal).
41+
- Analytical solution is a **Cycloid**.
42+
- Historically significant as the first problem solved using techniques that evolved into the Calculus of Variations.
43+
44+
### References
45+
46+
- Bernoulli, J. (1696). *Problema novum ad cujus solutionem Mathematici invitantur*.  
47+
  Acta Eruditorum.  
48+
  The original publication posing the challenge to the mathematicians of Europe, solved by Newton, Leibniz, L'Hôpital, and the Bernoulli brothers.
49+
50+
- Sussmann, H. J., & Willems, J. C. (1997). *300 years of optimal control: from the brachystochrone to the maximum principle*.  
51+
  IEEE Control Systems Magazine. [doi.org/10.1109/37.588108](https://doi.org/10.1109/37.588108)  
52+
  A comprehensive historical review linking the classical Brachistochrone problem to modern optimal control theory and Pontryagin's Maximum Principle.
53+
54+
- Dymos Examples: Brachistochrone. [OpenMDAO/Dymos](https://openmdao.github.io/dymos/examples/brachistochrone/brachistochrone.html)  
55+
  The numerical implementation serving as the basis for the current benchmark formulation.

ext/Descriptions/bryson_denham.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
The **Bryson–Denham problem** is a classic optimal control benchmark involving a state inequality constraint.
2+
It models the movement of a unit mass on a frictionless plane, where the goal is to relocate the mass over a fixed time interval with minimum control effort, while ensuring the position never exceeds a certain limit.
3+
Originally introduced in [Bryson et al. 1963](https://doi.org/10.2514/3.2107), it is a standard test case for evaluating the ability of numerical solvers to handle state-constrained trajectories.
4+
5+
### Mathematical formulation
6+
7+
The problem can be stated as
8+
9+
```math
10+
$$
11+
\begin{aligned}
12+
\min_{x,u} \quad & J(x,u) = \int_0^1 \frac{1}{2} u^2(t) \,\mathrm{d}t \\
13+
\text{s.t.} \quad & \dot{x}_1(t) = x_2(t), \quad \dot{x}_2(t) = u(t), \\
14+
& x_1(0) = 0, \; x_1(1) = 0, \; x_2(0) = 1, \; x_2(1) = -1, \\
15+
& x_1(t) \le a.
16+
\end{aligned}
17+
$$
18+
```
19+
20+
where $x_1$ represents position, $x_2$ velocity, $u$ acceleration (control), and $a$ is the maximum allowable displacement (e.g., $a=1/9$).
21+
22+
### Qualitative behaviour
23+
24+
The problem features a **second-order state constraint** because the control $u$ only appears in the second derivative of the constrained state $x_1$:
25+
26+
```math
27+
$$
28+
\ddot{x}_1(t) = u(t).
29+
$$
30+
```
31+
32+
When the trajectory is on a **boundary arc** ($x_1(t) = a$), the derivatives $\dot{x}_1$ and $\ddot{x}_1$ must be zero. This implies that while the constraint is active, the velocity $x_2$ is zero and the control $u$ is zero:
33+
34+
```math
35+
$$
36+
u(t) = 0.
37+
$$
38+
```
39+
40+
The solution structure changes based on the value of the constraint parameter $a$:
41+
42+
* **Unconstrained Case**: If $a$ is sufficiently large ($a \ge 1/4$), the state constraint is never active.
43+
* **Touch Point**: For a critical value of $a$, the trajectory just touches the boundary $x_1 = a$ at a single point $t=0.5$.
44+
* **Boundary Arc**: For smaller values (e.g., $a=1/9$), the trajectory remains on the boundary for a finite time interval. During this interval, the control vanishes.
45+
46+
### Characteristics
47+
48+
* Linear–quadratic dynamics with a second-order state inequality constraint.
49+
* Demonstrates a "bang-off-bang" control structure where the control is zero on the constraint boundary.
50+
* Used to test the accuracy of state constraint handling and the detection of switching times.
51+
52+
### References
53+
54+
* Bryson, A.E., Denham, W.F., & Dreyfus, S.E. (1963). *Optimal programming problems with inequality constraints I: necessary conditions for extremal solutions*.
55+
AIAA Journal. [doi.org/10.2514/3.2107](https://doi.org/10.2514/3.2107)
56+
* Dymos Documentation: Bryson-Denham Problem. [dymos/examples/bryson_denham](https://openmdao.github.io/dymos/examples/bryson_denham/bryson_denham.html)

ext/Descriptions/mountain_car.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
The **Mountain Car problem** is a classic benchmark in control and reinforcement learning.
2+
It involves an underpowered car that must climb a steep hill to reach a target position.
3+
Because the car's engine is too weak to climb the hill directly, it must first drive away from the goal to gain momentum by oscillating in a valley.
4+
The goal is to reach the target position in **minimum time**.
5+
6+
### Mathematical formulation
7+
8+
The problem can be stated as
9+
10+
```math
11+
\begin{aligned}
12+
\min_{x,v,u,t_f} \quad & J = t_f \\
13+
ext{s.t.} \quad & \dot{x}(t) = v(t), \\
14+
& \dot{v}(t) = a \, u(t) - b \, \cos(c \, x(t)), \\
15+
& x(0) = -0.5, \quad v(0) = 0.0, \\
16+
& x(t_f) = 0.5, \quad v(t_f) \ge 0.0, \\
17+
& -1.2 \le x(t) \le 0.5, \\
18+
& -0.07 \le v(t) \le 0.07, \\
19+
& -1 \le u(t) \le 1, \\
20+
& t_f \ge 0.
21+
\end{aligned}
22+
```
23+
24+
### Parameters
25+
26+
| Parameter | Symbol | Value |
27+
|-----------|--------|-------|
28+
| Power coefficient | $a$ | 0.001 |
29+
| Gravity coefficient | $b$ | 0.0025 |
30+
| Frequency coefficient | $c$ | 3.0 |
31+
| Initial position | $x_0$ | -0.5 |
32+
| Target position | $x_f$ | 0.5 |
33+
34+
### Qualitative behaviour
35+
36+
- The car must oscillate back and forth in the valley to build enough kinetic energy to climb the right hill.
37+
- The optimal strategy typically involves a sequence of full-throttle accelerations in alternating directions (**bang-bang control**).
38+
- The minimum time objective makes the problem sensitive to the initial guess for the final time.
39+
40+
### Characteristics
41+
42+
- Two-dimensional state space (position and velocity),
43+
- Scalar control (effort/acceleration),
44+
- **Free final time** with minimum time objective,
45+
- State constraints (position and velocity bounds),
46+
- Control constraints (bounds on acceleration).
47+
48+
### References
49+
50+
- **Dymos Documentation**. [*The Mountain Car Problem*](https://openmdao.github.io/dymos/examples/mountain_car/mountain_car.html).
51+
Provides a detailed description and implementation of the Mountain Car problem using the Dymos library.
52+
53+
- **OpenAI Gym**. [*MountainCar-v0*](https://gym.openai.com/envs/MountainCar-v0/).
54+
A standard reinforcement learning environment for the Mountain Car problem.
55+
56+
- Moore, A. W. (1990). *Efficient Memory-based Learning for Robot Control*. PhD thesis, University of Cambridge.
57+
Introduces the Mountain Car problem as a benchmark for reinforcement learning and control.

ext/JuMPModels/balanced_field.jl

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
"""
2+
$(TYPEDSIGNATURES)
3+
4+
Constructs and returns a JuMP model for the **Aircraft Balanced Field Length Calculation (Takeoff phase)**.
5+
The model represents the dynamics of the aircraft during takeoff and seeks to minimise the final range.
6+
7+
# Arguments
8+
9+
- `::JuMPBackend`: Specifies the backend for building the JuMP model.
10+
- `grid_size::Int=200`: (Keyword) Number of discretisation steps for the time horizon.
11+
12+
# Returns
13+
14+
- `model::JuMP.Model`: A JuMP model representing the problem.
15+
"""
16+
function OptimalControlProblems.balanced_field(
17+
::JuMPBackend,
18+
args...;
19+
grid_size::Int=grid_size_data(:balanced_field),
20+
parameters::Union{Nothing,NamedTuple}=nothing,
21+
kwargs...,
22+
)
23+
24+
# parameters
25+
params = parameters_data(:balanced_field, parameters)
26+
t0 = params[:t0]
27+
m = params[:m]
28+
g = params[:g]
29+
ρ = params[]
30+
S = params[:S]
31+
CD0 = params[:CD0]
32+
AR = params[:AR]
33+
e = params[:e]
34+
CL0 = params[:CL0]
35+
CL_max = params[:CL_max]
36+
h_w = params[:h_w]
37+
span = params[:span]
38+
α_max = params[:α_max]
39+
T = params[:T]
40+
41+
r_t0 = params[:r_t0]
42+
v_t0 = params[:v_t0]
43+
h_t0 = params[:h_t0]
44+
γ_t0 = params[:γ_t0]
45+
h_tf = params[:h_tf]
46+
γ_tf = params[:γ_tf]
47+
48+
α_min = params[:α_min]
49+
α_max_ctrl = params[:α_max_ctrl]
50+
51+
# Constants
52+
b = span / 2.0
53+
K_nom = 1.0 / (pi * AR * e)
54+
55+
# model
56+
model = JuMP.Model(args...; kwargs...)
57+
58+
# metadata
59+
model[:time_grid] = () -> range(t0, value(model[:tf]), grid_size + 1)
60+
model[:state_components] = ["r", "v", "h", "γ"]
61+
model[:costate_components] = ["∂r", "∂v", "∂h", "∂γ"]
62+
model[:control_components] = ["α"]
63+
model[:variable_components] = ["tf"]
64+
65+
@expression(model, N, grid_size)
66+
67+
# variables
68+
@variables(
69+
model,
70+
begin
71+
r[0:N], (start = r_t0)
72+
v[0:N] 1.0, (start = v_t0 + 10.0)
73+
h[0:N] 0.0, (start = h_tf / 2.0)
74+
γ[0:N], (start = γ_tf)
75+
0 α[0:N] α_max_ctrl, (start = 0.1)
76+
tf 0.1, (start = 10.0)
77+
end
78+
)
79+
80+
# boundary constraints
81+
@constraints(
82+
model,
83+
begin
84+
r[0] == r_t0
85+
v[0] == v_t0
86+
h[0] == h_t0
87+
γ[0] == γ_t0
88+
89+
h[N] == h_tf
90+
γ[N] == γ_tf
91+
end
92+
)
93+
94+
# dynamics
95+
@expressions(
96+
model,
97+
begin
98+
Δt, (tf - t0) / N
99+
100+
q[i = 0:N], 0.5 * ρ * v[i]^2
101+
CL[i = 0:N], CL0 + (α[i] / α_max) * (CL_max - CL0)
102+
L[i = 0:N], q[i] * S * CL[i]
103+
104+
h_eff[i = 0:N], h[i] + h_w
105+
term_h[i = 0:N], 33.0 * abs(h_eff[i] / b)^1.5
106+
K[i = 0:N], K_nom * term_h[i] / (1.0 + term_h[i])
107+
D[i = 0:N], q[i] * S * (CD0 + K[i] * CL[i]^2)
108+
109+
dr[i = 0:N], v[i] * cos(γ[i])
110+
dv[i = 0:N], (T * cos(α[i]) - D[i]) / m - g * sin(γ[i])
111+
dh[i = 0:N], v[i] * sin(γ[i])
112+
dγ[i = 0:N], (T * sin(α[i]) + L[i]) / (m * v[i]) - (g * cos(γ[i])) / v[i]
113+
end
114+
)
115+
116+
@constraints(
117+
model,
118+
begin
119+
∂r[i = 1:N], r[i] == r[i - 1] + 0.5 * Δt * (dr[i] + dr[i - 1])
120+
∂v[i = 1:N], v[i] == v[i - 1] + 0.5 * Δt * (dv[i] + dv[i - 1])
121+
∂h[i = 1:N], h[i] == h[i - 1] + 0.5 * Δt * (dh[i] + dh[i - 1])
122+
∂γ[i = 1:N], γ[i] == γ[i - 1] + 0.5 * Δt * (dγ[i] + dγ[i - 1])
123+
end
124+
)
125+
126+
# objective
127+
@objective(model, Min, r[N])
128+
129+
return model
130+
end

0 commit comments

Comments
 (0)