Exemplo n.º 1
0
class EFWATestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.efwa_custom = EnhancedFireworksAlgorithm(D=self.D,
                                                      nFES=1000,
                                                      n=10,
                                                      C_a=2,
                                                      C_r=0.5,
                                                      benchmark=MyBenchmark())
        self.efwa_griewank = EnhancedFireworksAlgorithm(D=self.D,
                                                        nFES=1000,
                                                        n=10,
                                                        C_a=5,
                                                        C_r=0.5,
                                                        benchmark=Griewank())

    def test_custom_works_fine(self):
        fun = MyBenchmark().function()
        x = self.efwa_custom.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)

    def test_griewank_works_fine(self):
        fun = Griewank().function()
        x = self.efwa_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
Exemplo n.º 2
0
 def test_griewank_works_fine(self):
     fwa_griewank = EnhancedFireworksAlgorithm(n=10,
                                               C_a=5,
                                               C_r=0.5,
                                               seed=self.seed)
     fwa_griewankc = EnhancedFireworksAlgorithm(n=10,
                                                C_a=5,
                                                C_r=0.5,
                                                seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fwa_griewank, fwa_griewankc)
Exemplo n.º 3
0
 def test_custom_works_fine(self):
     fwa_custom = EnhancedFireworksAlgorithm(n=10,
                                             C_a=2,
                                             C_r=0.5,
                                             seed=self.seed)
     fwa_customc = EnhancedFireworksAlgorithm(n=10,
                                              C_a=2,
                                              C_r=0.5,
                                              seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fwa_custom, fwa_customc,
                                          MyBenchmark())
Exemplo n.º 4
0
 def setUp(self):
     self.D = 40
     self.efwa_custom = EnhancedFireworksAlgorithm(D=self.D,
                                                   nFES=1000,
                                                   n=10,
                                                   C_a=2,
                                                   C_r=0.5,
                                                   benchmark=MyBenchmark())
     self.efwa_griewank = EnhancedFireworksAlgorithm(D=self.D,
                                                     nFES=1000,
                                                     n=10,
                                                     C_a=5,
                                                     C_r=0.5,
                                                     benchmark=Griewank())
Exemplo n.º 5
0
 def test_custom_works_fine(self):
     fwa_custom = EnhancedFireworksAlgorithm(D=self.D,
                                             nFES=self.nFES,
                                             nGEN=self.nGEN,
                                             n=10,
                                             C_a=2,
                                             C_r=0.5,
                                             benchmark=MyBenchmark(),
                                             seed=self.seed)
     fwa_customc = EnhancedFireworksAlgorithm(D=self.D,
                                              nFES=self.nFES,
                                              nGEN=self.nGEN,
                                              n=10,
                                              C_a=2,
                                              C_r=0.5,
                                              benchmark=MyBenchmark(),
                                              seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fwa_custom, fwa_customc)
Exemplo n.º 6
0
 def test_griewank_works_fine(self):
     fwa_griewank = EnhancedFireworksAlgorithm(D=self.D,
                                               nFES=self.nFES,
                                               nGEN=self.nGEN,
                                               n=10,
                                               C_a=5,
                                               C_r=0.5,
                                               benchmark=Griewank(),
                                               seed=self.seed)
     fwa_griewankc = EnhancedFireworksAlgorithm(D=self.D,
                                                nFES=self.nFES,
                                                nGEN=self.nGEN,
                                                n=10,
                                                C_a=5,
                                                C_r=0.5,
                                                benchmark=Griewank(),
                                                seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fwa_griewank, fwa_griewankc)
Exemplo n.º 7
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

from NiaPy.algorithms.basic import EnhancedFireworksAlgorithm
from NiaPy.task import StoppingTask
from NiaPy.benchmarks import Sphere

# we will run Fireworks Algorithm for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10, nGEN=100, benchmark=Sphere())
    algo = EnhancedFireworksAlgorithm(N=70, Ainit=0.1, Afinal=0.9)
    best = algo.run(task)
    print('%s -> %s' % (best[0], best[1]))

# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
Exemplo n.º 8
0
def plot_example(D=10, nFES=50000, nGEN=100000, seed=None, optType=OptimizationType.MINIMIZATION, optFunc=MinMB, **kn):
	task = TaskConvPlot(D=D, nFES=nFES, nGEN=nGEN, optType=optType, benchmark=optFunc())
	algo = EnhancedFireworksAlgorithm(seed=None, task=task)
	best = algo.run()
	logger.info('%s %s' % (best[0], best[1]))
	input('Press [enter] to continue')
Exemplo n.º 9
0
def simple_example(runs=10, D=10, nFES=50000, nGEN=10000, seed=None, optType=OptimizationType.MINIMIZATION, optFunc=MinMB, **kn):
	for i in range(runs):
		algo = EnhancedFireworksAlgorithm(D=D, nFES=nFES, optType=optType, benchmark=optFunc())
		best = algo.run()
		logger.info('%s %s' % (best[0], best[1]))