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-mpc.md
+68-71Lines changed: 68 additions & 71 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
# Navigation problem, MPC approach
2
2
3
-
```@meta
4
-
Draft = false
5
-
```
6
-
7
3
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:
8
4
9
5
```math
@@ -14,11 +10,11 @@ We consider a ship in a constant current $w=(w_x,w_y)$, where $\|w\|<1$. The [he
14
10
\end{array}
15
11
```
16
12
17
-
The state variables represent:
13
+
The state and control variables represent:
18
14
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)
15
+
- the ship's position in the plane $(x, y)$
16
+
- the heading angle $\theta$ (direction of the ship's velocity relative to the x-axis)
17
+
- the angular velocity $u$ (rate of change of the heading angle)
22
18
23
19
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
20
@@ -68,6 +64,7 @@ function current(x, y) # current as a function of position
Copy file name to clipboardExpand all lines: docs/src/tutorial-nlp.md
+21-31Lines changed: 21 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
# [NLP and DOCP manipulations](@id tutorial-nlp)
2
2
3
3
```@meta
4
-
Draft = false
4
+
Draft = true
5
5
CurrentModule = OptimalControl
6
6
```
7
7
8
-
We describe here some more advanced operations related to the discretized optimal control problem. When calling `solve(ocp)`, three steps are performed internally:
8
+
We describe here low-level operations related to the discretized optimal control problem. The standard way to solve an OCP is to call `solve(ocp)`, available in three modes of increasing abstraction:
9
9
10
-
1. The OCP is discretized into a DOCP (discretized optimal control problem)
11
-
2. An NLP (nonlinear programming) model is built from the DOCP
12
-
3. The NLP is solved, and a functional solution of the OCP is rebuilt from the NLP solution
10
+
-**Descriptive mode**: `solve(ocp; grid_size=100, ...)` — highest level, uses symbols and plain values (see [basic usage](@extref OptimalControl manual-solve))
11
+
-**Explicit mode**: `solve(ocp; discretizer=disc, modeler=mod, solver=sol)` — uses strategy instances as keyword arguments, missing components are filled in automatically (see [explicit mode](@extref OptimalControl manual-solve-explicit))
12
+
-**Canonical mode**: `solve(ocp, init, disc, mod, solv)` — all components passed as positional arguments
13
13
14
-
These steps can also be done manually, which gives you more control over the solving process. This is useful when you want to:
14
+
This tutorial goes one level below the canonical mode and exposes its elementary steps manually. This is useful when you want to:
15
15
16
-
- Use your own NLP solver
16
+
- Use your own NLP solver directly
17
17
- Access and inspect the NLP model
18
18
- Benchmark different components separately
19
19
- Fine-tune each step of the resolution
@@ -51,7 +51,7 @@ We now perform the resolution step by step, using OptimalControl strategy instan
51
51
52
52
### Step 1: Build the initial guess
53
53
54
-
First, we build an initial guess for the problem. Here we pass `nothing` to use the default initialization.
54
+
First, we build an initial guess for the problem. Here we pass `nothing` to use the default initialization. For more options (constant values, time-dependent functions, warm start from a previous solution), see the [initial guess documentation](@extref OptimalControl manual-initial-guess) and the `@init` macro.
The `nlp` is an `ADNLPModel` (from the NLPModels ecosystem) representing the discretized nonlinear programming problem.
83
+
The `nlp` is an `ADNLPModel` (from the NLPModels ecosystem) representing the discretized nonlinear programming problem. The full list of options for each strategy (`Collocation`, `ADNLP`, etc.) is described in [Strategy options](@extref OptimalControl manual-solve-strategy-options).
Note that MadNLP can also be used via the OptimalControl wrapper `OptimalControl.MadNLP(...)`, just like `OptimalControl.Ipopt(...)` above. The full list of available solvers is given in the [explicit mode documentation](@extref OptimalControl manual-solve-explicit).
118
+
117
119
### Step 5: Build the OCP solution
118
120
119
121
Finally, we build the optimal control solution from the NLP solution and plot it. Note that the multipliers from the NLP solver are used to compute the costate.
@@ -123,40 +125,28 @@ sol = ocp_solution(docp, nlp_sol, modeler)
123
125
plot(sol)
124
126
```
125
127
126
-
## All-in-one with explicit strategies
128
+
## Canonical solve
127
129
128
-
All the steps above can also be performed in a single `solve`call by passing the strategy instances explicitly:
130
+
All the steps above are exactly what the canonical `solve`performs internally. They can be condensed into a single call:
129
131
130
132
```@example main-nlp
131
133
sol = solve(ocp, init, discretizer, modeler, solver; display=false)
132
134
plot(sol)
133
135
```
134
136
135
-
This is the explicit mode of `solve`, which gives you full control over each component while keeping the interface simple. See the [explicit mode documentation](@extref OptimalControl manual-solve-explicit) for more details.
137
+
This is the **canonical mode** of `solve` (Layer 3): all components are fully specified and passed as positional arguments — no defaults, no auto-completion. The two higher-level modes sit above this:
138
+
139
+
-**Explicit mode** — pass strategy instances as keyword arguments; missing components are resolved automatically: `solve(ocp; discretizer=disc, modeler=mod, solver=sol)`. See [explicit mode](@extref OptimalControl manual-solve-explicit).
140
+
-**Descriptive mode** — pass plain values and symbols; everything is built internally: `solve(ocp; grid_size=100, tol=1e-8)`. See [basic usage](@extref OptimalControl manual-solve).
136
141
137
142
## Initial guess and warm start
138
143
139
-
An initial guess can be passed at different stages of the process.
144
+
For a detailed presentation of all the ways to build an initial guess — constant values, time-dependent functions, warm start from a previous solution, or using the `@init` macro — see the [initial guess documentation](@extref OptimalControl manual-initial-guess).
140
145
141
-
If you have a previous solution, you can use it to warm-start a new resolution:
146
+
In the step-by-step approach, the initial guess is passed to `nlp_model` via `build_initial_guess`. In canonical mode, it is passed as a positional argument:
0 commit comments