2
2
# Resolution
3
3
4
4
# by order of preference
5
- methods = ()
5
+ algorithmes = ()
6
6
7
7
# descent methods
8
- methods = add (methods, (:direct , :adnlp , :ipopt ))
8
+ algorithmes = add (algorithmes, (:direct , :adnlp , :ipopt ))
9
+
10
+ """
11
+ $(TYPEDSIGNATURES)
12
+
13
+ Return the list of available methods to solve the optimal control problem.
14
+ """
15
+ function Methods ():: Tuple{Tuple{Vararg{Symbol}}}
16
+ return algorithmes
17
+ end
9
18
10
19
"""
11
20
$(TYPEDSIGNATURES)
@@ -16,7 +25,7 @@ Solve the the optimal control problem `ocp` by the method given by the (optional
16
25
17
26
You can pass a partial description.
18
27
If you give a partial description, then, if several complete descriptions contains the partial one,
19
- then, the method with the highest priority is chosen. The higher in the list `OptimalControl.methods` ,
28
+ then, the method with the highest priority is chosen. The higher in the list,
20
29
the higher is the priority.
21
30
22
31
Keyword arguments:
@@ -28,12 +37,14 @@ Keyword arguments:
28
37
29
38
There is only one available method for the moment: a direct method which transforms
30
39
the optimal control problem into a nonlinear programming problem (NLP) solved
31
- by `IPOPT`, thanks to the package `ADNLProblems`. The direct method comes from
32
- the `CTDirect` package.
40
+ by [`Ipopt`](https://coin-or.github.io/Ipopt/), thanks to the package
41
+ [`ADNLPModels`](https://github.com/JuliaSmoothOptimizers/ADNLPModels.jl).
42
+ The direct method comes from the
43
+ [`CTDirect`](https://github.com/control-toolbox/CTDirect.jl) package.
33
44
34
45
!!! tip
35
46
36
- - To see the list of available methods, simply print `OptimalControl.methods `.
47
+ - To see the list of available methods, simply call `Methods() `.
37
48
- You can pass any other option by a pair `keyword=value` according to the chosen method.
38
49
39
50
# Examples
@@ -42,6 +53,14 @@ Keyword arguments:
42
53
julia> sol = solve(ocp)
43
54
julia> sol = solve(ocp, :direct)
44
55
julia> sol = solve(ocp, :direct, :ipopt)
56
+ julia> sol = solve(ocp, :direct, :ipopt, display=false)
57
+ julia> sol = solve(ocp, :direct, :ipopt, display=false, init=sol)
58
+ julia> sol = solve(ocp, init=(state=[-0.5, 0.2],))
59
+ julia> sol = solve(ocp, init=(state=[-0.5, 0.2], control=0.5))
60
+ julia> sol = solve(ocp, init=(state=[-0.5, 0.2], control=0.5, variable=[1, 2]))
61
+ julia> sol = solve(ocp, init=(state=[-0.5, 0.2], control=t->6-12*t))
62
+ julia> sol = solve(ocp, init=(state=t->[-1+t, t*(t-1)], control=0.5))
63
+ julia> sol = solve(ocp, init=(state=t->[-1+t, t*(t-1)], control=t->6-12*t))
45
64
```
46
65
47
66
"""
@@ -51,7 +70,7 @@ function solve(ocp::OptimalControlModel, description::Symbol...;
51
70
kwargs... )
52
71
53
72
#
54
- method = getFullDescription (description, methods )
73
+ method = getFullDescription (description, Methods () )
55
74
56
75
# todo: OptimalControlInit must be in CTBase, it is for the moment in CTDirect
57
76
@@ -60,11 +79,11 @@ function solve(ocp::OptimalControlModel, description::Symbol...;
60
79
elseif init isa CTBase. OptimalControlSolution
61
80
init = OptimalControlInit (init)
62
81
else
63
- init = OptimalControlInit (x_init= init[rg (1 , ocp. state_dimension)],
64
- u_init= init[rg (ocp. state_dimension+ 1 , ocp. state_dimension+ ocp. control_dimension)],
65
- v_init= init[rg (ocp. state_dimension+ ocp. control_dimension+ 1 , lastindex (init))])
82
+ x_init = :state ∈ keys (init) ? init[:state ] : nothing
83
+ u_init = :control ∈ keys (init) ? init[:control ] : nothing
84
+ v_init = :variable ∈ keys (init) ? init[:variable ] : nothing
85
+ init = OptimalControlInit (x_init= x_init, u_init= u_init, v_init= v_init)
66
86
end
67
-
68
87
69
88
# print chosen method
70
89
display ? println (" Method = " , method) : nothing
0 commit comments