本文整理汇总了Python中Problem.Problem.sphere方法的典型用法代码示例。如果您正苦于以下问题:Python Problem.sphere方法的具体用法?Python Problem.sphere怎么用?Python Problem.sphere使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Problem.Problem
的用法示例。
在下文中一共展示了Problem.sphere方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
# 需要导入模块: from Problem import Problem [as 别名]
# 或者: from Problem.Problem import sphere [as 别名]
def search(iterations, population, low_bound, high_bound, max_vel, C1, C2, topology, pso_type):
problem = Problem()
fitness = []
pop = create_population(population)
collection = list(enumerate(pop, start=0))
gbest = update_global_best(pop)
lbest = gbest
fbest = gbest
for ite in xrange(iterations):
for i, particle in collection:
if topology == "local":
lbest = update_local_best(pop, i, lbest)
update_velocity(particle, lbest, max_vel, C1, C2, ite, pso_type)
elif topology == "focal":
fbest = update_local_best(pop, i, fbest)
update_velocity(particle, fbest, max_vel, C1, C2, ite, pso_type)
else:
update_velocity(particle, gbest, max_vel, C1, C2, ite, pso_type)
update_position(particle, low_bound, high_bound)
particle.cost = problem.sphere(particle.position)
update_personal_best(particle)
gbest = update_global_best(pop, gbest)
print "Iteration: ", ite, "Fitness: ", gbest.cost
fitness.append(gbest.cost)
return gbest, fitness