def PlotMultipleRuns(Alg, nruns=20, fname=None):
'''Plot "nruns" runs of a given algorithm to show performance
and variability across runs.'''
if fname:
runs = scipy.genfromtxt(fname)
else:
runs = []
for i in range(nruns):
bestSol, fitHistory = tsp.TSP(200, Alg, 3000, 30, seed=None,
coordfile='tmp.txt')
runs.append(fitHistory)
fname = 'MultRuns-' + str(Alg) + '.txt'
runs = scipy.array(runs)
scipy.savetxt(fname, runs)
# plotting
Xs = scipy.linspace(0, runs.shape[1] * 1000, runs.shape[1])
for i in range(runs.shape[0]):
pl.plot(Xs, runs[i, :])
pl.show()
评论列表
文章目录