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
println("Objective from computed solution: ", objective(sol))
122
-
println("Objective from imported solution: ", objective(sol_jld))
122
+
# println("Objective from imported solution: ", objective(sol_jld))
123
+
# the type of the imported solution is not the same as the original one
124
+
println("Type of the imported solution: ", typeof(sol_jld))
125
+
# the type of the original solution
126
+
println("Type of the original solution: ", typeof(sol))
123
127
```
124
128
129
+
!!! danger "Bug"
130
+
131
+
The `import_ocp_solution` function does not return a solution of the same type as the original one. This is a bug that will be fixed in a future release.
As before, the `Flow` function aims to compute $(x, p)$ from the optimal control problem `ocp` and the control in feedback form `u(t, x, p)`. However, we must indicate that the control depends on $t$, that is it is non-autonomous.
236
+
As before, the `Flow` function aims to compute $(x, p)$ from the optimal control problem `ocp` and the control in feedback form `u(t, x, p)`.
237
+
Since the problem is non-autonomous, we must provide a control law that depends on time.
control_style::Union{NamedTuple,Symbol}, # style: control trajectory
25
-
kwargs..., # other attributes from Plots
26
-
)
27
-
```
28
-
29
-
You can provide additional information to the `plot` function by supplying the optimal control problem: `plot(sol, ocp)`. The function signature when including the optimal control problem is as follows:
30
-
31
-
```julia
32
-
# only sol and model are required
33
-
function Plots.plot(
34
-
sol::CTModels.Solution,
35
-
ocp::CTModels.Model, # optimal control problem
36
-
description::Symbol...;
37
-
layout::Symbol,
38
-
control::Symbol,
39
-
time::Symbol,
40
-
size::Tuple,
41
-
time_style::Union{NamedTuple,Symbol}, # style: vertical time axes
42
-
state_style::Union{NamedTuple,Symbol},
43
-
state_bounds_style::Union{NamedTuple,Symbol}, # style: state bounds
44
-
control_style::Union{NamedTuple,Symbol},
45
-
control_bounds_style::Union{NamedTuple,Symbol}, # style: control bounds
We consider a [LQR example](https://control-toolbox.org/Tutorials.jl/stable/tutorial-lqr-basic.html) and solve the problem for different values of the final time `tf`. Then, we plot the solutions on the same figure using a normalized time $s = (t - t_0) / (t_f - t_0)$, enabled by the keyword argument `time = :normalize` (or `:normalise`) in the `plot` function.
249
+
We consider a [LQR example](https://control-toolbox.org/Tutorials.jl/stable/tutorial-lqr-basic.html) and solve the problem for different values of the final time `tf`. Then, we plot the solutions on the same figure using a normalised time $s = (t - t_0) / (t_f - t_0)$, enabled by the keyword argument `time = :normalize` (or `:normalise`) in the `plot` function.
287
250
288
251
```@example main
289
252
# definition of the problem, parameterised by the final time
On the plot, you can see the lower and upper bounds of the path constraint. Additionally, the dual variable associated with the path constraint is displayed alongside it.
353
315
354
-
You can customize the plot styles. For style options related to the state, costate, and control, refer to the [Basic Concepts](@ref tutorial-plot-basic) section.
316
+
You can customise the plot styles. For style options related to the state, costate, and control, refer to the [Basic Concepts](@ref tutorial-plot-basic) section.
355
317
356
318
```@example main
357
-
plot(sol, ocp;
319
+
plot(sol;
358
320
state_bounds_style = (linestyle = :dash,),
359
321
control_bounds_style = (linestyle = :dash,),
360
322
path_style = (color = :green,),
@@ -369,31 +331,31 @@ plot(sol, ocp;
369
331
You can choose what to plot using the `description` argument. To plot only one subgroup:
370
332
371
333
```julia
372
-
plot(sol, ocp, :state) # plot only the state
373
-
plot(sol, ocp, :costate) # plot only the costate
374
-
plot(sol, ocp, :control) # plot only the control
375
-
plot(sol, ocp, :path) # plot only the path constraint
376
-
plot(sol, ocp, :dual) # plot only the path constraint dual variable
334
+
plot(sol, :state) # plot only the state
335
+
plot(sol, :costate) # plot only the costate
336
+
plot(sol, :control) # plot only the control
337
+
plot(sol, :path) # plot only the path constraint
338
+
plot(sol, :dual) # plot only the path constraint dual variable
377
339
```
378
340
379
341
You can combine elements to plot exactly what you need:
380
342
381
343
```@example main
382
-
plot(sol, ocp, :state, :control, :path)
344
+
plot(sol, :state, :control, :path)
383
345
```
384
346
385
347
Similarly, you can choose what not to plot passing `:none` to the corresponding style.
386
348
387
349
```julia
388
-
plot(sol, ocp; state_style=:none) # do not plot the state
389
-
plot(sol, ocp; costate_style=:none) # do not plot the costate
390
-
plot(sol, ocp; control_style=:none) # do not plot the control
391
-
plot(sol, ocp; path_style=:none) # do not plot the path constraint
392
-
plot(sol, ocp; dual_style=:none) # do not plot the path constraint dual variable
350
+
plot(sol; state_style=:none) # do not plot the state
351
+
plot(sol; costate_style=:none) # do not plot the costate
352
+
plot(sol; control_style=:none) # do not plot the control
353
+
plot(sol; path_style=:none) # do not plot the path constraint
354
+
plot(sol; dual_style=:none) # do not plot the path constraint dual variable
393
355
```
394
356
395
357
For instance, let's plot everything except the dual variable associated with the path constraint.
0 commit comments