35
35
'COBYLA' : ('COBYLA' , {}),
36
36
}
37
37
38
+
38
39
# Utility function to create a basis of a given size
39
40
def get_basis (name , size , Tf ):
40
41
if name == 'poly' :
@@ -43,14 +44,13 @@ def get_basis(name, size, Tf):
43
44
basis = fs .BezierFamily (size , T = Tf )
44
45
elif name == 'bspline' :
45
46
basis = fs .BSplineFamily ([0 , Tf / 2 , Tf ], size )
47
+ else :
48
+ basis = None
46
49
return basis
47
50
48
51
49
- #
50
- # Optimal trajectory generation with linear quadratic cost
51
- #
52
-
53
- def time_optimal_lq_basis (basis_name , basis_size , npoints ):
52
+ # Assess performance as a function of basis type and size
53
+ def time_optimal_lq_basis (basis_name , basis_size , npoints , method ):
54
54
# Create a sufficiently controllable random system to control
55
55
ntrys = 20
56
56
while ntrys > 0 :
@@ -90,18 +90,20 @@ def time_optimal_lq_basis(basis_name, basis_size, npoints):
90
90
91
91
res = opt .solve_ocp (
92
92
sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
93
- basis = basis ,
93
+ basis = basis , trajectory_method = method ,
94
94
)
95
95
# Only count this as a benchmark if we converged
96
96
assert res .success
97
97
98
98
# Parameterize the test against different choices of integrator and minimizer
99
- time_optimal_lq_basis .param_names = ['basis' , 'size' , 'npoints' ]
99
+ time_optimal_lq_basis .param_names = ['basis' , 'size' , 'npoints' , 'method' ]
100
100
time_optimal_lq_basis .params = (
101
- ['poly' , 'bezier' , 'bspline' ], [8 , 10 , 12 ], [5 , 10 , 20 ])
101
+ [None , 'poly' , 'bezier' , 'bspline' ],
102
+ [4 , 8 ], [5 , 10 ], ['shooting' , 'collocation' ])
102
103
103
104
104
- def time_optimal_lq_methods (integrator_name , minimizer_name ):
105
+ # Assess performance as a function of optimization and integration methods
106
+ def time_optimal_lq_methods (integrator_name , minimizer_name , method ):
105
107
# Get the integrator and minimizer parameters to use
106
108
integrator = integrator_table [integrator_name ]
107
109
minimizer = minimizer_table [minimizer_name ]
@@ -134,17 +136,20 @@ def time_optimal_lq_methods(integrator_name, minimizer_name):
134
136
sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
135
137
solve_ivp_method = integrator [0 ], solve_ivp_kwargs = integrator [1 ],
136
138
minimize_method = minimizer [0 ], minimize_options = minimizer [1 ],
139
+ trajectory_method = method ,
137
140
)
138
141
# Only count this as a benchmark if we converged
139
142
assert res .success
140
143
141
144
# Parameterize the test against different choices of integrator and minimizer
142
- time_optimal_lq_methods .param_names = ['integrator' , 'minimizer' ]
145
+ time_optimal_lq_methods .param_names = ['integrator' , 'minimizer' , 'method' ]
143
146
time_optimal_lq_methods .params = (
144
- ['RK23' , 'RK45' , 'LSODA' ], ['trust' , 'SLSQP' , 'COBYLA' ])
147
+ ['RK23' , 'RK45' , 'LSODA' ], ['trust' , 'SLSQP' , 'COBYLA' ],
148
+ ['shooting' , 'collocation' ])
145
149
146
150
147
- def time_optimal_lq_size (nstates , ninputs , npoints ):
151
+ # Assess performance as a function system size
152
+ def time_optimal_lq_size (nstates , ninputs , npoints , method ):
148
153
# Create a sufficiently controllable random system to control
149
154
ntrys = 20
150
155
while ntrys > 0 :
@@ -181,19 +186,18 @@ def time_optimal_lq_size(nstates, ninputs, npoints):
181
186
182
187
res = opt .solve_ocp (
183
188
sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
189
+ trajectory_method = method ,
184
190
)
185
191
# Only count this as a benchmark if we converged
186
192
assert res .success
187
193
188
194
# Parameterize the test against different choices of integrator and minimizer
189
- time_optimal_lq_size .param_names = ['nstates' , 'ninputs' , 'npoints' ]
190
- time_optimal_lq_size .params = ([1 , 2 , 4 ], [1 , 2 , 4 ], [5 , 10 , 20 ])
195
+ time_optimal_lq_size .param_names = ['nstates' , 'ninputs' , 'npoints' , 'method' ]
196
+ time_optimal_lq_size .params = (
197
+ [2 , 4 ], [2 , 4 ], [10 , 20 ], ['shooting' , 'collocation' ])
191
198
192
199
193
- #
194
200
# Aircraft MPC example (from multi-parametric toolbox)
195
- #
196
-
197
201
def time_discrete_aircraft_mpc (minimizer_name ):
198
202
# model of an aircraft discretized with 0.2s sampling time
199
203
# Source: https://www.mpt3.org/UI/RegulationProblem
0 commit comments