Ejemplo n.º 1
0
class GSATestCase(TestCase):
    def setUp(self):
        self.gsa_custom = GravitationalSearchAlgorithm(D=10,
                                                       NP=40,
                                                       nFES=1000,
                                                       benchmark=MyBenchmark())
        self.gsa_griewank = GravitationalSearchAlgorithm(NP=10,
                                                         D=40,
                                                         nFES=1000,
                                                         benchmark='griewank')

    def test_Custom_works_fine(self):
        fun = MyBenchmark().function()
        x = self.gsa_custom.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.gsa_custom.task.D, asarray(x[0])),
                               x[1],
                               delta=1e2)

    def test_griewank_works_fine(self):
        fun = Griewank().function()
        x = self.gsa_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.gsa_griewank.task.D, asarray(x[0])),
                               x[1],
                               delta=1e2)
Ejemplo n.º 2
0
 def setUp(self):
     self.gsa_custom = GravitationalSearchAlgorithm(D=10,
                                                    NP=40,
                                                    nFES=1000,
                                                    benchmark=MyBenchmark())
     self.gsa_griewank = GravitationalSearchAlgorithm(NP=10,
                                                      D=40,
                                                      nFES=1000,
                                                      benchmark='griewank')
Ejemplo n.º 3
0
 def test_Custom_works_fine(self):
     gsa_custom = GravitationalSearchAlgorithm(D=self.D,
                                               NP=40,
                                               nFES=self.nFES,
                                               nGEN=self.nGEN,
                                               benchmark=MyBenchmark(),
                                               seed=self.seed)
     gsa_customc = GravitationalSearchAlgorithm(D=self.D,
                                                NP=40,
                                                nFES=self.nFES,
                                                nGEN=self.nGEN,
                                                benchmark=MyBenchmark(),
                                                seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, gsa_custom, gsa_customc)
Ejemplo n.º 4
0
 def test_griewank_works_fine(self):
     gsa_griewank = GravitationalSearchAlgorithm(NP=10,
                                                 D=self.D,
                                                 nFES=self.nFES,
                                                 nGEN=self.nGEN,
                                                 benchmark='griewank',
                                                 seed=self.seed)
     gsa_griewankc = GravitationalSearchAlgorithm(NP=10,
                                                  D=self.D,
                                                  nFES=self.nFES,
                                                  nGEN=self.nGEN,
                                                  benchmark='griewank',
                                                  seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, gsa_griewank, gsa_griewankc)
Ejemplo n.º 5
0
def logging_example(D=10,
                    nFES=50000,
                    seed=None,
                    optType=OptimizationType.MINIMIZATION,
                    optFunc=MinMB):
    task = TaskConvPrint(D=D,
                         nFES=nFES,
                         nGEN=50000,
                         optType=optType,
                         benchmark=optFunc())
    algo = GravitationalSearchAlgorithm(NP=40,
                                        F=0.5,
                                        CR=0.9,
                                        seed=seed,
                                        task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
Ejemplo n.º 6
0
def simple_example(runs=10,
                   D=10,
                   nFES=50000,
                   seed=None,
                   optType=OptimizationType.MINIMIZATION,
                   optFunc=MinMB):
    for i in range(runs):
        algo = GravitationalSearchAlgorithm(D=D,
                                            NP=40,
                                            nFES=nFES,
                                            F=0.5,
                                            CR=0.9,
                                            seed=seed +
                                            1 if seed != None else seed,
                                            optType=optType,
                                            benchmark=optFunc())
        Best = algo.run()
        logger.info('%s %s' % (Best[0], Best[1]))
Ejemplo 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 GravitationalSearchAlgorithm
from NiaPy.util import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

# we will run Gravitational Search Algorithm for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10,
                        nFES=10000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = GravitationalSearchAlgorithm(NP=40)
    best = algo.run(task=task)
    print(best)
Ejemplo n.º 8
0
 def test_Custom_works_fine(self):
     gsa_custom = GravitationalSearchAlgorithm(NP=40, seed=self.seed)
     gsa_customc = GravitationalSearchAlgorithm(NP=40, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, gsa_custom, gsa_customc,
                                          MyBenchmark())
Ejemplo n.º 9
0
 def test_griewank_works_fine(self):
     gsa_griewank = GravitationalSearchAlgorithm(NP=10, seed=self.seed)
     gsa_griewankc = GravitationalSearchAlgorithm(NP=10, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, gsa_griewank, gsa_griewankc)