def run_draw():
#init = -sys.maxsize # for maximun case
targ = SimAnneal(target_text='max')
init = -sys.maxsize # for maximun case
#init = sys.maxsize # for minimun case
xyRange = [[-2, 2], [-2, 2]]
xRange = [[0, 10]]
t_start = time()
calculate = OptSolution(Markov_chain=1000, result=init, val_nd=[0,0])
output = calculate.soulution(SA_newV=targ.newVar, SA_preV=targ.preVar, SA_juge=targ.juge,
juge_text='max',ValueRange=xyRange, func=func2)
t_end = time()
#print(city_pos)
print('Running %.4f seconds' %(t_end-t_start))
# plot animation
fig = plt.figure()
ax = Axes3D(fig)
xv = np.linspace(xyRange[0][0], xyRange[0][1], 200)
yv = np.linspace(xyRange[1][0], xyRange[1][1], 200)
xv, yv = np.meshgrid(xv, yv)
zv = func2([xv, yv])
ax.plot_surface(xv, yv, zv, rstride=1, cstride=1, cmap='GnBu', alpha=1)
#dot = ax.scatter(0, 0, 0, 'ro')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
x, y, z = output[0][0], output[0][1], output[1]
ax.scatter(x, y, z, c='r', marker='o')
plt.savefig('SA_min0.png')
plt.show()
评论列表
文章目录