當前位置: 首頁>>代碼示例>>Python>>正文


Python GPopulation.setMultiThreading方法代碼示例

本文整理匯總了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)
開發者ID:ImpactHorizon,項目名稱:Pyevolve,代碼行數:69,代碼來源:GSimpleGA.py


注:本文中的GPopulation.GPopulation.setMultiThreading方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。