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-basic-example-f.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,8 @@ starting from the condition $x(0) = (-1, 0)$ and with the goal to reach the targ
28
28
[Double integrator: energy minimisation](https://control-toolbox.org/docs/ctproblems/stable/problems/double_integrator_energy.html#DIE)
29
29
for the analytical solution and details about this problem.
30
30
31
-
First, we need to import the `OptimalControl.jl` package to define and solve the optimal control problem. We also need to import the `Plots.jl` package to plot the solution.
31
+
First, we need to import the `OptimalControl.jl` package to define the optimal control problem and `NLPModelsIpopt.jl` to solve it.
32
+
We also need to import the `Plots.jl` package to plot the solution.
Copy file name to clipboardExpand all lines: docs/src/tutorial-basic-example.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,8 @@ starting from the condition $x(0) = (-1, 0)$ and with the goal to reach the targ
28
28
[Double integrator: energy minimisation](https://control-toolbox.org/docs/ctproblems/stable/problems/double_integrator_energy.html#DIE)
29
29
for the analytical solution and details about this problem.
30
30
31
-
First, we need to import the `OptimalControl.jl` package to define and solve the optimal control problem. We also need to import the `Plots.jl` package to plot the solution.
31
+
First, we need to import the `OptimalControl.jl` package to define the optimal control problem and `NLPModelsIpopt.jl` to solve it.
32
+
We also need to import the `Plots.jl` package to plot the solution.
Copy file name to clipboardExpand all lines: docs/src/tutorial-double-integrator.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,8 @@ a line without fricton.
19
19
<img src="./assets/chariot.png" style="display: block; margin: 0 auto 20px auto;" width="300px">
20
20
```
21
21
22
-
First, we need to import the `OptimalControl.jl` package to define and solve the optimal control problem. We also need to import the `Plots.jl` package to plot the solution.
22
+
First, we need to import the `OptimalControl.jl` package to define the optimal control problem and `NLPModelsIpopt.jl` to solve it.
23
+
We also need to import the `Plots.jl` package to plot the solution.
Copy file name to clipboardExpand all lines: docs/src/tutorial-initial-guess.md
+27-15
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,20 @@
4
4
CurrentModule = OptimalControl
5
5
```
6
6
7
-
We present in this tutorial the different possibilities to provide an initial guess to solve an optimal control problem using the [`solve`](@ref) command. For the illustrations, we define the following optimal control problem.
7
+
We present in this tutorial the different possibilities to provide an initial guess to solve an
8
+
optimal control problem using the [`solve`](@ref) command.
9
+
10
+
First, we need to import the `OptimalControl.jl` package to define the optimal control problem and `NLPModelsIpopt.jl` to solve it.
11
+
We also need to import the `Plots.jl` package to plot the solution.
8
12
9
13
```@example main
10
14
using OptimalControl
11
15
using NLPModelsIpopt
12
16
using Plots
13
17
```
14
18
19
+
For the illustrations, we define the following optimal control problem.
20
+
15
21
```@example main
16
22
t0 = 0
17
23
tf = 10
@@ -36,8 +42,6 @@ This will default to initialize all variables to 0.1.
36
42
```@example main
37
43
# solve the optimal control problem without initial guess
38
44
sol = solve(ocp, display=false)
39
-
40
-
# print the number of iterations
41
45
println("Number of iterations: ", sol.iterations)
42
46
nothing # hide
43
47
```
@@ -48,10 +52,12 @@ Let us plot the solution of the optimal control problem.
48
52
plot(sol, size=(600, 450))
49
53
```
50
54
51
-
Note that the following formulations are equivalent
55
+
Note that the following formulations are equivalent to not giving an initial guess.
56
+
52
57
```@example main
53
58
sol = solve(ocp, display=false, init=nothing)
54
59
println("Number of iterations: ", sol.iterations)
60
+
55
61
sol = solve(ocp, display=false, init=())
56
62
println("Number of iterations: ", sol.iterations)
57
63
nothing # hide
@@ -65,20 +71,23 @@ Except when initializing from a solution, the arguments are to be passed as a na
65
71
We first illustrate the constant initial guess, using vectors or scalars according to the dimension.
66
72
67
73
```@example main
68
-
# solve the optimal control problem with initial guess
74
+
# solve the optimal control problem with initial guess with constant values
69
75
sol = solve(ocp, display=false, init=(state=[-0.2, 0.1], control=-0.2, variable=0.05))
70
-
71
-
# print the number of iterations
72
76
println("Number of iterations: ", sol.iterations)
73
77
nothing # hide
74
78
```
75
79
76
80
Partial initializations are also valid, as shown below. Note the ending comma when a single argument is passed (tuple).
77
81
```@example main
82
+
# initialisation only on the state
78
83
sol = solve(ocp, display=false, init=(state=[-0.2, 0.1],))
79
84
println("Number of iterations: ", sol.iterations)
85
+
86
+
# initialisation only on the control
80
87
sol = solve(ocp, display=false, init=(control=-0.2,))
81
88
println("Number of iterations: ", sol.iterations)
89
+
90
+
# initialisation only on the state and the variable
82
91
sol = solve(ocp, display=false, init=(state=[-0.2, 0.1], variable=0.05))
83
92
println("Number of iterations: ", sol.iterations)
84
93
nothing # hide
@@ -92,10 +101,7 @@ For the state and control, we can also provide functions of time as initial gues
92
101
x(t) = [ -0.2t, 0.1t ]
93
102
u(t) = -0.2t
94
103
95
-
# solve the optimal control problem with initial guess
96
104
sol = solve(ocp, display=false, init=(state=x, control=u, variable=0.05))
97
-
98
-
# print the number of iterations
99
105
println("Number of iterations: ", sol.iterations)
100
106
nothing # hide
101
107
```
@@ -107,49 +113,55 @@ For the values to be interpolated both matrices and vectors of vectors are allow
107
113
Simple vectors are also allowed for variables of dimension 1.
sol = solve(ocp, display=false, init=(time=time_vec, state=x_vec, control=u_vec, variable=0.05))
115
-
116
122
println("Number of iterations: ", sol.iterations)
117
123
nothing # hide
118
124
```
119
125
120
126
Note: in the free final time case, the given time grid should be consistent with the initial guess provided for the final time (in the optimization variables).
121
127
122
128
## Mixed initial guess
129
+
123
130
The constant, functional and vector initializations can be mixed, for instance as
131
+
124
132
```@example main
133
+
# we can mix constant values with functions of time
125
134
sol = solve(ocp, display=false, init=(state=[-0.2, 0.1], control=u, variable=0.05))
126
135
println("Number of iterations: ", sol.iterations)
127
-
nothing # hide
128
136
137
+
# wa can mix every possibility
129
138
sol = solve(ocp, display=false, init=(time=time_vec, state=x_vec, control=u, variable=0.05))
130
139
println("Number of iterations: ", sol.iterations)
131
140
nothing # hide
132
141
```
133
142
134
143
## Solution as initial guess (warm start)
144
+
135
145
Finally, we can use an existing solution to provide the initial guess.
136
146
The dimensions of the state, control and optimization variable must coincide.
137
147
This particular feature allows an easy implementation of discrete continuations.
148
+
138
149
```@example main
139
150
# generate the initial solution
140
151
sol_init = solve(ocp, display=false)
141
152
142
153
# solve the problem using solution as initial guess
143
154
sol = solve(ocp, init=sol_init, display=false)
144
-
145
-
# print the number of iterations
146
155
println("Number of iterations: ", sol.iterations)
147
156
nothing # hide
148
157
```
149
158
150
-
Note that you can also manually pick and choose which data to reuse from a solution, by recovering the functions ```sol.state```, ```sol.control``` and the values ```sol.variable```.
159
+
Note that you can also manually pick and choose which data to reuse from a solution, by recovering the
160
+
functions ```sol.state```, ```sol.control``` and the values ```sol.variable```.
151
161
For instance the following formulation is equivalent to the ```init=sol``` one.
162
+
152
163
```@example main
164
+
# use a previous solution to initialise picking information
153
165
sol = solve(ocp, display=false, init=(state=sol.state, control=sol.control, variable=sol.variable))
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)
64
+
65
+
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).
66
+
57
67
```@example main
58
68
sol = build_solution(docp, primal=nlp_sol.solution, dual=nlp_sol.multipliers)
59
69
plot(sol)
60
70
```
61
71
62
-
An initial guess, including warm start, can be passed to *direct_transcription* the same way as for *solve*
72
+
An initial guess, including warm start, can be passed to `direct_transcription` the same way as for `solve`.
73
+
63
74
```@example main
64
75
docp = direct_transcription(ocp, init=sol)
65
76
nothing # hide
66
77
```
67
-
and it can also be changed after the transcription is done, with *set_initial_guess*
78
+
79
+
It can also be changed after the transcription is done, with `set_initial_guess`.
80
+
68
81
```@example main
69
82
set_initial_guess(docp, sol)
70
83
nothing # hide
71
84
```
72
85
73
-
Back to the function *solve*, passing an explicit initial guess to
74
-
-*solve(ocp)* will transmit it to *direct_transcription*, therefore the resulting DOCP will have the initial guess embedded in it.
75
-
-*solve(docp)* will override the initial guess in the DOCP and used the given one instead, without modifying the DOCP.
86
+
Back to the function `solve`, passing an explicit initial guess to
87
+
88
+
-`solve(ocp)` will transmit it to `direct_transcription`, therefore the resulting DOCP will have the initial guess embedded in it.
89
+
-`solve(docp)` will override the initial guess in the DOCP and used the given one instead, without modifying the DOCP.
0 commit comments