예제 #1
0
 def test_griewank_works_fine(self):
     de_griewank = DynNpMultiStrategyDifferentialEvolution(NP=10,
                                                           CR=0.5,
                                                           F=0.9,
                                                           seed=self.seed)
     de_griewankc = DynNpMultiStrategyDifferentialEvolution(NP=10,
                                                            CR=0.5,
                                                            F=0.9,
                                                            seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, de_griewank, de_griewankc,
                                          'griewank')
예제 #2
0
 def test_custom_works_fine(self):
     de_custom = DynNpMultiStrategyDifferentialEvolution(NP=40,
                                                         F=0.5,
                                                         CR=0.9,
                                                         seed=self.seed)
     de_customc = DynNpMultiStrategyDifferentialEvolution(NP=40,
                                                          F=0.5,
                                                          CR=0.9,
                                                          seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, de_custom, de_customc,
                                          MyBenchmark())
예제 #3
0
 def test_typeParameters(self):
     d = DynNpMultiStrategyDifferentialEvolution.typeParameters()
     self.assertTrue(d['rp'](10))
     self.assertTrue(d['rp'](10.10))
     self.assertFalse(d['rp'](0))
     self.assertFalse(d['rp'](-10))
     self.assertTrue(d['pmax'](10))
     self.assertFalse(d['pmax'](0))
     self.assertFalse(d['pmax'](-10))
     self.assertFalse(d['pmax'](10.12))
예제 #4
0
 def test_griewank_works_fine(self):
     de_griewank = DynNpMultiStrategyDifferentialEvolution(
         NP=10,
         D=self.D,
         nFES=self.nFES,
         nGEN=self.nGEN,
         CR=0.5,
         F=0.9,
         benchmark='griewank',
         seed=self.seed)
     de_griewankc = DynNpMultiStrategyDifferentialEvolution(
         NP=10,
         D=self.D,
         nFES=self.nFES,
         nGEN=self.nGEN,
         CR=0.5,
         F=0.9,
         benchmark='griewank',
         seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, de_griewank, de_griewankc)
예제 #5
0
 def test_Custom_works_fine(self):
     de_custom = DynNpMultiStrategyDifferentialEvolution(
         D=self.D,
         NP=40,
         nFES=self.nFES,
         nGEN=self.nGEN,
         F=0.5,
         CR=0.9,
         benchmark=MyBenchmark(),
         seed=self.seed)
     de_customc = DynNpMultiStrategyDifferentialEvolution(
         D=self.D,
         NP=40,
         nFES=self.nFES,
         nGEN=self.nGEN,
         F=0.5,
         CR=0.9,
         benchmark=MyBenchmark(),
         seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, de_custom, de_customc)
예제 #6
0
# encoding=utf8
# This is temporary fix to import module from parent folder
# It will be removed when package is published on PyPI
import sys
sys.path.append('../')
# End of fix

import random
from NiaPy.algorithms.basic import DynNpMultiStrategyDifferentialEvolution
from NiaPy.algorithms.basic.de import CrossBest2, CrossCurr2Best1
from NiaPy.util import OptimizationType
from NiaPy.task.task import StoppingTask
from NiaPy.benchmarks import Sphere

#we will run Differential Evolution for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10,
                        nFES=1000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = DynNpMultiStrategyDifferentialEvolution(NP=80,
                                                   F=0.2,
                                                   CR=0.7,
                                                   strategies=(CrossCurr2Best1,
                                                               CrossBest2),
                                                   pmax=5)
    best = algo.run(task=task)
    print('%s -> %s' % (best[0].x, best[1]))
예제 #7
0
 def test_algorithm_info(self):
     self.assertIsNotNone(
         DynNpMultiStrategyDifferentialEvolution.algorithmInfo())