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/tutorials/dynamic_optimization.md
+20-7Lines changed: 20 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,8 @@
2
2
Systems in ModelingToolkit.jl can be directly converted to dynamic optimization or optimal control problems. In such systems, one has one or more input variables that are externally controlled to control the dynamics of the system. A dynamic optimization solves for the optimal time trajectory of the input variables in order to maximize or minimize a desired objective function. For example, a car driver might like to know how to step on the accelerator if the goal is to finish a race while using the least gas.
3
3
4
4
To begin, let us take a rocket launch example. The input variable here is the thrust exerted by the engine. The rocket state is described by its current height and velocity.
5
-
```julia
5
+
6
+
```@example dynamic_opt
6
7
using ModelingToolkit
7
8
t = ModelingToolkit.t_nounits
8
9
D = ModelingToolkit.D_nounits
@@ -37,19 +38,25 @@ pmap = [
37
38
What we would like to optimize here is the final height of the rocket. We do this by providing a vector of expressions corresponding to the costs. By default, the sense of the optimization is to minimize the provided cost. So to maximize the rocket height at the final time, we write `-h(te)` as the cost.
38
39
39
40
Now we can construct a problem and solve it. Let us use JuMP as our backend here.
Let's plot our final solution and the controller here:
46
-
```julia
48
+
```@example dynamic_opt
49
+
using CairoMakie
50
+
plot(
51
+
plot(jsol.sol, title = "Rocket trajectory"),
52
+
plot(jsol.input_sol, title = "Control trajectory")
53
+
)
47
54
```
48
55
49
56
###### Free final time problems
50
57
There are additionally a class of dynamic optimization problems where we would like to know how to control our system to achieve something in the least time. Such problems are called free final time problems, since the final time is unknown. To model these problems in ModelingToolkit, we declare the final time as a parameter.
Please note that, at the moment, free final time problems cannot support constraints defined at definite time values, like `x(3) ~ 2`.
71
78
72
-
Let's plot our final solution and the controller for the block:
73
-
```julia
79
+
!!! warning
80
+
81
+
The Pyomo collocation methods (LagrangeRadau, LagrangeLegendre) currently are bugged for free final time problems. Strongly suggest using BackwardEuler() for such problems.
82
+
83
+
Let's solve plot our final solution and the controller for the block, using InfiniteOpt as the backend:
**Pyomo** and **InfiniteOpt** each have their own built-in collocation methods.
88
101
1.**InfiniteOpt**: The list of InfiniteOpt collocation methods can be found [in the table on this page](https://infiniteopt.github.io/InfiniteOpt.jl/stable/guide/derivative/). If none is passed in, the solver defaults to `FiniteDifference(Backward())`, which is effectively implicit Euler.
89
-
2.**Pyomo**: The list of Pyomo collocation methods can be found [here](). If none is passed in, the solver defaults to a `LagrangeRadau(3)`.
102
+
2.**Pyomo**: The list of Pyomo collocation methods can be found [at the bottom of this page](https://github.com/SciML/Pyomo.jl). If none is passed in, the solver defaults to a `LagrangeRadau(3)`.
0 commit comments