Skip to content

Commit 4b090b4

Browse files
committed
foo
1 parent d115e73 commit 4b090b4

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ MINPACK = "4854310b-de5a-5eb6-a2a5-c1dee2bd17f9"
1414
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
1515
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
1616
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
17+
Percival = "01435c0c-c90d-11e9-3788-63660f8fbccc"
1718
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
1819
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
1920
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"

docs/src/tutorial-nlp.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,41 @@ When calling `solve(ocp)` three steps are performed internally:
1111
- then, this DOCP is solved,
1212
- finally, a functional solution of the OCP is rebuilt from the solution of the discretized problem, with [`build_solution`](@ref).
1313

14-
These steps can also be done separately, for instance if you want to use your own NLP solver. Let us load the modules
14+
These steps can also be done separately, for instance if you want to use your own NLP solver.
15+
16+
Let us load the packages.
1517

1618
```@example main
1719
using OptimalControl
1820
using NLPModelsIpopt
1921
using Plots
2022
```
2123

22-
and define a test problem
24+
## Definition of the optimal control problem
25+
26+
We define a test problem
2327

2428
```@example main
2529
@def ocp begin
30+
2631
t ∈ [ 0, 1 ], time
2732
x ∈ R², state
2833
u ∈ R, control
34+
2935
x(0) == [ -1, 0 ]
3036
x(1) == [ 0, 0 ]
37+
3138
ẋ(t) == [ x₂(t), u(t) ]
39+
3240
∫( 0.5u(t)^2 ) → min
41+
3342
end
3443
nothing # hide
3544
```
3645

37-
First let us discretize the problem.
46+
## Discretization and NLP problem
47+
48+
We discretize the problem.
3849

3950
```@example main
4051
docp = direct_transcription(ocp)
@@ -48,22 +59,28 @@ You can extract this raw NLP problem with the [`get_nlp`](@ref) method.
4859
nlp = get_nlp(docp)
4960
```
5061

51-
You could then use the solver of your choice to solve it.
52-
For an example we use the `ipopt` solver from [`NLPModelsIpopt.jl`](https://github.com/JuliaSmoothOptimizers/NLPModelsIpopt.jl) package to solve the NLP problem.
62+
We can now use the solver of our choice to solve it.
63+
64+
## Resolution of the NLP problem
65+
66+
For a first example we use the `ipopt` solver from [`NLPModelsIpopt.jl`](https://github.com/JuliaSmoothOptimizers/NLPModelsIpopt.jl) package to solve the NLP problem.
5367

5468
```@example main
5569
using NLPModelsIpopt
70+
5671
nlp_sol = ipopt(get_nlp(docp); print_level=4, mu_strategy="adaptive", tol=1e-8, sb="yes")
5772
nothing # hide
5873
```
5974

60-
Then we can rebuild and plot an OCP solution (note that the multipliers are optional, but the OCP costate will not be retrieved if the multipliers are not provided).
75+
Then we can rebuild and plot an optimal control problem solution (note that the multipliers are optional, but the OCP costate will not be retrieved if the multipliers are not provided).
6176

6277
```@example main
6378
sol = build_solution(docp, primal=nlp_sol.solution, dual=nlp_sol.multipliers)
6479
plot(sol)
6580
```
6681

82+
## Initial guess
83+
6784
An initial guess, including warm start, can be passed to [`direct_transcription`](@ref) the same way as for `solve`.
6885

6986
```@example main
@@ -76,4 +93,15 @@ It can also be changed after the transcription is done, with [`set_initial_gues
7693
```@example main
7794
set_initial_guess(docp, sol)
7895
nothing # hide
96+
```
97+
98+
For a second example, we use the [`Percival.jl`](https://jso.dev/Percival.jl) to solve the NLP problem
99+
with as initial guess the solution from the first resolution.
100+
101+
```@example main
102+
using Percival
103+
104+
nlp = get_nlp(docp)
105+
output = percival(nlp)
106+
print(output)
79107
```

0 commit comments

Comments
 (0)