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)
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)
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())
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]))
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')
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]))
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_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))
# 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)
def test_algorithm_info_fine(self): self.assertIsNotNone(GlowwormSwarmOptimization.algorithmInfo())
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)
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)