You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/tutorial-mam.md
+1-5Lines changed: 1 addition & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,5 @@
1
1
# Minimal Action Method using Optimal Control
2
2
3
-
```@meta
4
-
Draft = false
5
-
```
6
-
7
3
The Minimal Action Method (MAM) is a numerical technique for finding the most probable transition pathway between stable states in stochastic dynamical systems. It achieves this by minimizing an action functional that represents the path's deviation from the deterministic dynamics, effectively identifying the path of least resistance through the system's landscape.
8
4
9
5
This tutorial demonstrates how to implement MAM as an optimal control problem, using the classical Maier-Stein model as a benchmark example.
@@ -145,7 +141,7 @@ function continuation_mam(Ts; init_guess=init)
We consider a ship in a constant current $w=(w_x,w_y)$, where $\|w\|<1$.
4
-
The [heading angle](https://en.wikipedia.org/wiki/Heading) is controlled, leading to the following differential equations:
3
+
```@meta
4
+
Draft = false
5
+
```
6
+
7
+
We consider a ship in a constant current $w=(w_x,w_y)$, where $\|w\|<1$. The [heading angle](https://en.wikipedia.org/wiki/Heading) is controlled, leading to the following differential equations:
5
8
6
9
```math
7
10
\begin{array}{rcl}
@@ -11,7 +14,17 @@ The [heading angle](https://en.wikipedia.org/wiki/Heading) is controlled, leadin
11
14
\end{array}
12
15
```
13
16
14
-
The angular velocity is limited and normalized: $\|u(t)\| \leq 1$. There are boundary conditions at the initial time $t=0$ and at the final time $t=t_f$, on the position $(x,y)$ and on the angle $\theta$. The objective is to minimize the final time. This topic stems from a collaboration between the University Côte d'Azur and the French company [CGG](https://www.cgg.com), which is interested in optimal maneuvers of very large ships for marine exploration.
17
+
The state variables represent:
18
+
19
+
- $(x, y)$: the ship's position in the plane
20
+
- $\theta$: the heading angle (direction of the ship's velocity relative to the x-axis)
21
+
- $u$: the angular velocity (rate of change of the heading angle)
22
+
23
+
The angular velocity is limited and normalized: $\|u(t)\| \leq 1$. There are boundary conditions at the initial time $t=0$ and at the final time $t=t_f$, on the position $(x,y)$ and on the angle $\theta$. The objective is to minimize the final time.
24
+
25
+
The condition $\|w\|<1$ ensures that the ship can always make progress against the current, since the ship's own velocity has unit magnitude.
26
+
27
+
This topic stems from a collaboration between the University Côte d'Azur and the French company [CGG](https://www.cgg.com), which is interested in optimal maneuvers of very large ships for marine exploration.
15
28
16
29
```@raw html
17
30
<img
@@ -23,7 +36,7 @@ The angular velocity is limited and normalized: $\|u(t)\| \leq 1$. There are bou
23
36
>
24
37
```
25
38
26
-
## Data
39
+
## Data
27
40
28
41
```@example main-mpc
29
42
using LinearAlgebra
@@ -42,6 +55,9 @@ xf = 4.
42
55
yf = 7.
43
56
θf = -π/2
44
57
58
+
# Current model: combines a constant base current with a position-dependent perturbation.
59
+
# The parameter ε controls the magnitude of the spatial variation, while the base
60
+
# current w = [0.6, 0.4] represents the mean flow direction.
45
61
function current(x, y) # current as a function of position
46
62
ε = 1e-1
47
63
w = [ 0.6, 0.4 ]
@@ -52,8 +68,15 @@ function current(x, y) # current as a function of position
52
68
end
53
69
return w
54
70
end
71
+
```
55
72
56
-
#
73
+
!!! note "Plotting utility functions"
74
+
75
+
```@raw html
76
+
<details><summary>Click to unfold the plotting functions.</summary>
We consider a constant current and we solve a first time the problem.
223
+
We consider a constant current, and we solve a first time the problem. The current is evaluated at the initial position and assumed to remain constant throughout the trajectory.
The trajectory shows the ship's path when assuming the current is constant and equal to its value at the initial position.
262
+
226
263
## Simulation of the Real System
227
264
228
265
In the previous simulation, we assumed that the current is constant. However, from a practical standpoint, the current depends on the position $(x, y)$. Given a current model, provided by the function `current`, we can simulate the actual trajectory of the ship, as long as we have the initial condition and the control over time.
<details><summary>Click to unfold the simulation code.</summary>
271
+
```
272
+
230
273
```@example main-mpc
231
274
function realistic_trajectory(tf, t0, x0, y0, θ0, u, current; abstol=1e-12, reltol=1e-12, saveat=[])
232
275
@@ -254,6 +297,10 @@ end
254
297
nothing # hide
255
298
```
256
299
300
+
```@raw html
301
+
</details>
302
+
```
303
+
257
304
```@example main-mpc
258
305
# Realistic trajectory
259
306
t, x, y, θ = realistic_trajectory(tf, t0, x0, y0, θ0, u, current)
@@ -279,10 +326,27 @@ plot(plt_q, plt_u;
279
326
)
280
327
```
281
328
329
+
Note that the final position (shown in red) differs from the target position (shown in orange). This discrepancy occurs because the control was computed assuming a constant current, but the actual current varies with position. The ship drifts due to the unmodeled spatial variation of the current.
330
+
282
331
## MPC Approach
283
332
284
333
In practice, we do not have the actual current data for the entire trajectory in advance, which is why we will regularly recalculate the optimal control. The idea is to update the optimal control at regular time intervals, taking into account the current at the position where the ship is located. We are therefore led to solve a number of problems with constant current, with this being updated regularly. This is an introduction to the so-called Model Predictive Control (MPC) methods.
285
334
335
+
The MPC algorithm works as follows:
336
+
337
+
1. At each iteration, measure the current at the ship's current position
338
+
2. Solve an optimal control problem assuming this current is constant over the entire remaining trajectory
339
+
3. Apply the optimal control for a fixed time step `Δt`
340
+
4. Simulate the ship's motion using the actual position-dependent current
341
+
5. Update the ship's position and repeat until reaching the target
342
+
343
+
The parameters are:
344
+
345
+
-`Nmax`: maximum number of MPC iterations (safety limit)
346
+
-`ε`: convergence tolerance - the algorithm stops when within this distance of the target
347
+
-`Δt`: prediction horizon - how long to apply each computed control before re-planning
348
+
-`P`: number of discretization points for the optimal control solver
349
+
286
350
```@example main-mpc
287
351
function MPC(t0, x0, y0, θ0, xf, yf, θf, current)
288
352
@@ -356,6 +420,15 @@ nothing # hide
356
420
357
421
## Display
358
422
423
+
The final plot shows:
424
+
425
+
- The complete MPC trajectory (blue) composed of segments from each iteration
426
+
- Starting points of each segment (orange) where re-planning occurs
427
+
- The final position reached (red) - note that it is much closer to the target than in the constant-current simulation
428
+
- The control profile (right) showing the piecewise re-planning strategy
429
+
430
+
The MPC approach successfully compensates for the spatial variation of the current by continuously updating the control based on local current measurements.
0 commit comments