本文整理匯總了Python中GPopulation.GPopulation.setMultiProcessing方法的典型用法代碼示例。如果您正苦於以下問題:Python GPopulation.setMultiProcessing方法的具體用法?Python GPopulation.setMultiProcessing怎麽用?Python GPopulation.setMultiProcessing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類GPopulation.GPopulation
的用法示例。
在下文中一共展示了GPopulation.setMultiProcessing方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: your_func
# 需要導入模塊: from GPopulation import GPopulation [as 別名]
# 或者: from GPopulation.GPopulation import setMultiProcessing [as 別名]
#.........這裏部分代碼省略.........
def setInteractiveMode(self, flag=True):
""" Enable/disable the interactive mode
:param flag: True or False
.. versionadded: 0.6
The *setInteractiveMode* method.
"""
if type(flag) != BooleanType:
Util.raiseException("Interactive Mode option must be True or False", TypeError)
self.interactiveMode = flag
def __repr__(self):
""" The string representation of the GA Engine """
ret = "- GSimpleGA\n"
ret += "\tGP Mode:\t\t %s\n" % self.getGPMode()
ret += "\tPopulation Size:\t %d\n" % (self.internalPop.popSize,)
ret += "\tGenerations:\t\t %d\n" % (self.nGenerations,)
ret += "\tCurrent Generation:\t %d\n" % (self.currentGeneration,)
ret += "\tMutation Rate:\t\t %.2f\n" % (self.pMutation,)
ret += "\tCrossover Rate:\t\t %.2f\n" % (self.pCrossover,)
ret += "\tMinimax Type:\t\t %s\n" % (Consts.minimaxType.keys()[Consts.minimaxType.values().index(self.minimax)].capitalize(),)
ret += "\tElitism:\t\t %s\n" % (self.elitism,)
ret += "\tElitism Replacement:\t %d\n" % (self.nElitismReplacement,)
ret += "\tDB Adapter:\t\t %s\n" % (self.dbAdapter,)
for slot in self.allSlots:
ret+= "\t" + slot.__repr__()
ret+="\n"
return ret
def setMultiProcessing(self, flag=True, full_copy=False):
""" Sets the flag to enable/disable the use of python multiprocessing module.
Use this option when you have more than one core on your CPU and when your
evaluation function is very slow.
Pyevolve will automaticly check if your Python version has **multiprocessing**
support and if you have more than one single CPU core. If you don't have support
or have just only one core, Pyevolve will not use the **multiprocessing**
feature.
Pyevolve uses the **multiprocessing** to execute the evaluation function over
the individuals, so the use of this feature will make sense if you have a
truly slow evaluation function (which is commom in GAs).
The parameter "full_copy" defines where the individual data should be copied back
after the evaluation or not. This parameter is useful when you change the
individual in the evaluation function.
:param flag: True (default) or False
:param full_copy: True or False (default)
.. warning:: Use this option only when your evaluation function is slow, so you'll
get a good tradeoff between the process communication speed and the
parallel evaluation. The use of the **multiprocessing** doesn't means
always a better performance.
.. note:: To enable the multiprocessing option, you **MUST** add the *__main__* check
on your application, otherwise, it will result in errors. See more on the
`Python Docs <http://docs.python.org/library/multiprocessing.html#multiprocessing-programming>`__
site.
.. versionadded:: 0.6
The `setMultiProcessing` method.