本文整理汇总了Python中GPopulation.GPopulation.setMultiThreading方法的典型用法代码示例。如果您正苦于以下问题:Python GPopulation.setMultiThreading方法的具体用法?Python GPopulation.setMultiThreading怎么用?Python GPopulation.setMultiThreading使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GPopulation.GPopulation
的用法示例。
在下文中一共展示了GPopulation.setMultiThreading方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GSimpleGA
# 需要导入模块: from GPopulation import GPopulation [as 别名]
# 或者: from GPopulation.GPopulation import setMultiThreading [as 别名]
#.........这里部分代码省略.........
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)
:param max_processes: None (default) or an integer value
.. 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.
"""
if type(flag) != BooleanType:
Util.raiseException("Multiprocessing option must be True or False", TypeError)
if type(full_copy) != BooleanType:
Util.raiseException("Multiprocessing 'full_copy' option must be True or False", TypeError)
self.internalPop.setMultiProcessing(flag, full_copy, max_processes)
def setMultiThreading(self, flag=True, max_threads=None):
""" Sets the flag to enable/disable the use of python multithreading 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 **multithreading**
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 **multithreading**
feature.
Pyevolve uses the **multithreading** 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).
Multithreading in general is better than multiprocessing when target data
to compare is big and copying it during process initialization is time
expensive.
:param flag: True (default) or False
:param max_threads: None (default) or an integer value
.. 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 **multithreading** doesn't means
always a better performance.
.. versionadded::
The `setMultiThreading` method.
"""
if type(flag) != BooleanType:
Util.raiseException("Threading option must be True or False", TypeError)