Exemplo n.º 1
0
class GSOTestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.gso_custom = GlowwormSwarmOptimization(D=self.D,
                                                    nFES=1000,
                                                    NP=35,
                                                    a=7,
                                                    Rmin=0.1,
                                                    Rmax=3,
                                                    benchmark=MyBenchmark())
        self.gso_griewank = GlowwormSwarmOptimization(D=self.D,
                                                      nFES=1000,
                                                      NP=10,
                                                      a=5,
                                                      Rmin=0.01,
                                                      Rmax=3,
                                                      benchmark=Griewank())

    def test_custom_works_fine(self):
        fun = MyBenchmark().function()
        x = self.gso_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.gso_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):
     gso_griewank = GlowwormSwarmOptimization(NP=10,
                                              a=5,
                                              Rmin=0.01,
                                              Rmax=3,
                                              seed=self.seed)
     gso_griewankc = GlowwormSwarmOptimization(NP=10,
                                               a=5,
                                               Rmin=0.01,
                                               Rmax=3,
                                               seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, gso_griewank, gso_griewankc)
Exemplo n.º 3
0
 def test_custom_works_fine(self):
     gso_custom = GlowwormSwarmOptimization(NP=35,
                                            a=7,
                                            Rmin=0.1,
                                            Rmax=3,
                                            seed=self.seed)
     gso_customc = GlowwormSwarmOptimization(NP=35,
                                             a=7,
                                             Rmin=0.1,
                                             Rmax=3,
                                             seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, gso_custom, gso_customc,
                                          MyBenchmark())
Exemplo n.º 4
0
def logging_example(D=10, nFES=50000):
    task = TaskConvPrint(D=D, nFES=nFES, nGEN=10000, benchmark=MyBenchmark())
    algo = GlowwormSwarmOptimization(n=25,
                                     nt=5,
                                     l0=5,
                                     rho=0.2,
                                     gamma=0.3,
                                     beta=0.05,
                                     s=0.05,
                                     seed=None,
                                     task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
Exemplo n.º 5
0
def plot_example(D=10, nFES=50000):
    task = TaskConvPlot(D=D, nFES=nFES, nGEN=10000, benchmark=MyBenchmark())
    algo = GlowwormSwarmOptimization(n=50,
                                     nt=5,
                                     l0=5,
                                     rho=0.4,
                                     gamma=0.6,
                                     beta=0.08,
                                     s=0.03,
                                     seed=None,
                                     task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
    input('Press [enter] to continue')
Exemplo n.º 6
0
def simple_example(runs=10, D=10, nFES=50000):
    for i in range(runs):
        algo = GlowwormSwarmOptimization(D=D,
                                         nFES=nFES,
                                         n=50,
                                         nt=5,
                                         l0=5,
                                         rho=0.4,
                                         gamma=0.6,
                                         beta=0.08,
                                         s=0.3,
                                         seed=None,
                                         benchmark=MyBenchmark())
        best = algo.run()
        logger.info('%s %s' % (best[0], best[1]))
Exemplo n.º 7
0
 def setUp(self):
     self.D = 40
     self.gso_custom = GlowwormSwarmOptimization(D=self.D,
                                                 nFES=1000,
                                                 NP=35,
                                                 a=7,
                                                 Rmin=0.1,
                                                 Rmax=3,
                                                 benchmark=MyBenchmark())
     self.gso_griewank = GlowwormSwarmOptimization(D=self.D,
                                                   nFES=1000,
                                                   NP=10,
                                                   a=5,
                                                   Rmin=0.01,
                                                   Rmax=3,
                                                   benchmark=Griewank())
Exemplo n.º 8
0
	def test_type_parameters_fine(self):
		d = GlowwormSwarmOptimization.typeParameters()
		self.assertIsNotNone(d.get('n', None))
		self.assertIsNotNone(d.get('l0', None))
		self.assertIsNotNone(d.get('nt', None))
		self.assertIsNotNone(d.get('rho', None))
		self.assertIsNotNone(d.get('gamma', None))
		self.assertIsNotNone(d.get('beta', None))
		self.assertIsNotNone(d.get('s', None))
Exemplo n.º 9
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 GlowwormSwarmOptimization
from NiaPy.task.task import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

# we will run Glowworm Swarm Optimization for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10,
                        nFES=1000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = GlowwormSwarmOptimization()
    best = algo.run(task=task)
    print(best)
Exemplo n.º 10
0
	def test_algorithm_info_fine(self):
		self.assertIsNotNone(GlowwormSwarmOptimization.algorithmInfo())
Exemplo n.º 11
0
	def test_custom_works_fine(self):
		gso_custom = GlowwormSwarmOptimization(D=self.D, nFES=self.nFES, nGEN=self.nGEN, NP=35, a=7, Rmin=0.1, Rmax=3, benchmark=MyBenchmark(), seed=self.seed)
		gso_customc = GlowwormSwarmOptimization(D=self.D, nFES=self.nFES, nGEN=self.nGEN, NP=35, a=7, Rmin=0.1, Rmax=3, benchmark=MyBenchmark(), seed=self.seed)
		AlgorithmTestCase.algorithm_run_test(self, gso_custom, gso_customc)
Exemplo n.º 12
0
	def test_griewank_works_fine(self):
		gso_griewank = GlowwormSwarmOptimization(D=self.D, nFES=self.nFES, nGEN=self.nGEN, NP=10, a=5, Rmin=0.01, Rmax=3, benchmark=Griewank(), seed=self.seed)
		gso_griewankc = GlowwormSwarmOptimization(D=self.D, nFES=self.nFES, nGEN=self.nGEN, NP=10, a=5, Rmin=0.01, Rmax=3, benchmark=Griewank(), seed=self.seed)
		AlgorithmTestCase.algorithm_run_test(self, gso_griewank, gso_griewankc)