本文整理汇总了Python中GPopulation.GPopulation.sort方法的典型用法代码示例。如果您正苦于以下问题:Python GPopulation.sort方法的具体用法?Python GPopulation.sort怎么用?Python GPopulation.sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GPopulation.GPopulation
的用法示例。
在下文中一共展示了GPopulation.sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: your_func
# 需要导入模块: from GPopulation import GPopulation [as 别名]
# 或者: from GPopulation.GPopulation import sort [as 别名]
#.........这里部分代码省略.........
.. versionadded:: 0.6
The `setMigrationAdapter` method.
"""
self.migrationAdapter = migration_adapter
if self.migrationAdapter is not None:
self.migrationAdapter.setGAEngine(self)
def setDBAdapter(self, dbadapter=None):
""" Sets the DB Adapter of the GA Engine
:param dbadapter: one of the :mod:`DBAdapters` classes instance
.. warning:: the use the of a DB Adapter can reduce the speed performance of the
Genetic Algorithm.
"""
if (dbadapter is not None) and (not isinstance(dbadapter, DBBaseAdapter)):
Util.raiseException("The DB Adapter must be a DBBaseAdapter subclass", TypeError)
self.dbAdapter = dbadapter
def setPopulationSize(self, size):
""" Sets the population size, calls setPopulationSize() of GPopulation
:param size: the population size
.. note:: the population size must be >= 2
"""
if size < 2:
Util.raiseException("population size must be >= 2", ValueError)
self.internalPop.setPopulationSize(size)
def setSortType(self, sort_type):
""" Sets the sort type, Consts.sortType["raw"]/Consts.sortType["scaled"]
Example:
>>> ga_engine.setSortType(Consts.sortType["scaled"])
:param sort_type: the Sort Type
"""
if sort_type not in Consts.sortType.values():
Util.raiseException("sort type must be a Consts.sortType type", TypeError)
self.internalPop.sortType = sort_type
def setMutationRate(self, rate):
""" Sets the mutation rate, between 0.0 and 1.0
:param rate: the rate, between 0.0 and 1.0
"""
if (rate>1.0) or (rate<0.0):
Util.raiseException("Mutation rate must be >= 0.0 and <= 1.0", ValueError)
self.pMutation = rate
def setCrossoverRate(self, rate):
""" Sets the crossover rate, between 0.0 and 1.0
:param rate: the rate, between 0.0 and 1.0
"""
if (rate>1.0) or (rate<0.0):
Util.raiseException("Crossover rate must be >= 0.0 and <= 1.0", ValueError)
self.pCrossover = rate