当前位置: 首页>>代码示例>>Python>>正文


Python Problem.sphere方法代码示例

本文整理汇总了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
开发者ID:rfapo,项目名称:PSO-python,代码行数:29,代码来源:PsoExample.py


注:本文中的Problem.Problem.sphere方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。