Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d65bf8

Browse files
authored
Merge pull request#799 from murrayrm/fix_horizon-19Nov2022
Add collocation method for optimal control problems
2 parents8c764d0 +dd5e42d commit9d65bf8

File tree

6 files changed

+545
-312
lines changed

6 files changed

+545
-312
lines changed

‎benchmarks/optimal_bench.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'COBYLA': ('COBYLA', {}),
3636
}
3737

38+
3839
# Utility function to create a basis of a given size
3940
defget_basis(name,size,Tf):
4041
ifname=='poly':
@@ -43,14 +44,13 @@ def get_basis(name, size, Tf):
4344
basis=fs.BezierFamily(size,T=Tf)
4445
elifname=='bspline':
4546
basis=fs.BSplineFamily([0,Tf/2,Tf],size)
47+
else:
48+
basis=None
4649
returnbasis
4750

4851

49-
#
50-
# Optimal trajectory generation with linear quadratic cost
51-
#
52-
53-
deftime_optimal_lq_basis(basis_name,basis_size,npoints):
52+
# Assess performance as a function of basis type and size
53+
deftime_optimal_lq_basis(basis_name,basis_size,npoints,method):
5454
# Create a sufficiently controllable random system to control
5555
ntrys=20
5656
whilentrys>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
assertres.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']
100100
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'])
102103

103104

104-
deftime_optimal_lq_methods(integrator_name,minimizer_name):
105+
# Assess performance as a function of optimization and integration methods
106+
deftime_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
assertres.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']
143146
time_optimal_lq_methods.params= (
144-
['RK23','RK45','LSODA'], ['trust','SLSQP','COBYLA'])
147+
['RK23','RK45','LSODA'], ['trust','SLSQP','COBYLA'],
148+
['shooting','collocation'])
145149

146150

147-
deftime_optimal_lq_size(nstates,ninputs,npoints):
151+
# Assess performance as a function system size
152+
deftime_optimal_lq_size(nstates,ninputs,npoints,method):
148153
# Create a sufficiently controllable random system to control
149154
ntrys=20
150155
whilentrys>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
assertres.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-
197201
deftime_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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp