3535 'COBYLA' : ('COBYLA' , {}),
3636}
3737
38+
3839# Utility function to create a basis of a given size
3940def get_basis (name , size , Tf ):
4041 if name == 'poly' :
@@ -43,14 +44,13 @@ def get_basis(name, size, Tf):
4344 basis = fs .BezierFamily (size , T = Tf )
4445 elif name == 'bspline' :
4546 basis = fs .BSplineFamily ([0 , Tf / 2 , Tf ], size )
47+ else :
48+ basis = None
4649 return basis
4750
4851
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 ):
5454 # Create a sufficiently controllable random system to control
5555 ntrys = 20
5656 while ntrys > 0 :
@@ -90,18 +90,20 @@ def time_optimal_lq_basis(basis_name, basis_size, npoints):
9090
9191 res = opt .solve_ocp (
9292 sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
93- basis = basis ,
93+ basis = basis , trajectory_method = method ,
9494 )
9595 # Only count this as a benchmark if we converged
9696 assert res .success
9797
9898# 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' ]
100100time_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' ])
102103
103104
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 ):
105107 # Get the integrator and minimizer parameters to use
106108 integrator = integrator_table [integrator_name ]
107109 minimizer = minimizer_table [minimizer_name ]
@@ -134,17 +136,20 @@ def time_optimal_lq_methods(integrator_name, minimizer_name):
134136 sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
135137 solve_ivp_method = integrator [0 ], solve_ivp_kwargs = integrator [1 ],
136138 minimize_method = minimizer [0 ], minimize_options = minimizer [1 ],
139+ trajectory_method = method ,
137140 )
138141 # Only count this as a benchmark if we converged
139142 assert res .success
140143
141144# 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' ]
143146time_optimal_lq_methods .params = (
144- ['RK23' , 'RK45' , 'LSODA' ], ['trust' , 'SLSQP' , 'COBYLA' ])
147+ ['RK23' , 'RK45' , 'LSODA' ], ['trust' , 'SLSQP' , 'COBYLA' ],
148+ ['shooting' , 'collocation' ])
145149
146150
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 ):
148153 # Create a sufficiently controllable random system to control
149154 ntrys = 20
150155 while ntrys > 0 :
@@ -181,19 +186,18 @@ def time_optimal_lq_size(nstates, ninputs, npoints):
181186
182187 res = opt .solve_ocp (
183188 sys , timepts , x0 , traj_cost , constraints , terminal_cost = term_cost ,
189+ trajectory_method = method ,
184190 )
185191 # Only count this as a benchmark if we converged
186192 assert res .success
187193
188194# 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' ])
191198
192199
193- #
194200# Aircraft MPC example (from multi-parametric toolbox)
195- #
196-
197201def time_discrete_aircraft_mpc (minimizer_name ):
198202 # model of an aircraft discretized with 0.2s sampling time
199203 # Source: https://www.mpt3.org/UI/RegulationProblem
0 commit comments