Exemple #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)
Exemple #2
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]))
Exemple #3
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')
Exemple #4
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]))
Exemple #5
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)