def test_dT_impact(xvals, f, nmpc, sim, start=0.1, end=0.8, step=0.02, ymax=200,
sample_size=100, label=None):
"""Used to generate Figure XX of the paper."""
c = raw_input("Did you remove iter/time caps in IPOPT settings? [y/N] ")
if c.lower() not in ['y', 'yes']:
print "Then go ahead and do it."
return
stats = [Statistics() for _ in xrange(len(xvals))]
fails = [0. for _ in xrange(len(xvals))]
pylab.ion()
pylab.clf()
for (i, dT) in enumerate(xvals):
f(dT)
for _ in xrange(sample_size):
nmpc.on_tick(sim)
if 'Solve' in nmpc.nlp.return_status:
stats[i].add(nmpc.nlp.solve_time)
else: # max CPU time exceeded, infeasible problem detected, ...
fails[i] += 1.
yvals = [1000 * ts.avg if ts.avg is not None else 0. for ts in stats]
yerr = [1000 * ts.std if ts.std is not None else 0. for ts in stats]
pylab.bar(
xvals, yvals, width=step, yerr=yerr, color='y', capsize=5,
align='center', error_kw={'capsize': 5, 'elinewidth': 5})
pylab.xlim(start - step / 2, end + step / 2)
pylab.ylim(0, ymax)
pylab.grid(True)
if label is not None:
pylab.xlabel(label, fontsize=24)
pylab.ylabel('Comp. time (ms)', fontsize=20)
pylab.tick_params(labelsize=16)
pylab.twinx()
yfails = [100. * fails[i] / sample_size for i in xrange(len(xvals))]
pylab.plot(xvals, yfails, 'ro', markersize=12)
pylab.plot(xvals, yfails, 'r--', linewidth=3)
pylab.xlim(start - step / 2, end + step / 2)
pylab.ylabel("Failure rate [%]", fontsize=20)
pylab.tight_layout()
评论列表
文章目录