本文整理匯總了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