Пример #1
0
class FPATestCase(TestCase):
    def setUp(self):
        self.fpa_custom = FlowerPollinationAlgorithm(10, 20, 10000, 0.5,
                                                     MyBenchmark())

        self.fpa_griewank = FlowerPollinationAlgorithm(10, 20, 10000, 0.5,
                                                       'griewank')

    def test_custom_works_fine(self):
        self.assertTrue(self.fpa_custom.run())

    def test_griewank_works_fine(self):
        self.assertTrue(self.fpa_griewank.run())
Пример #2
0
 def test_griewank_works_fine(self):
     fpa_griewank = FlowerPollinationAlgorithm(D=self.D,
                                               NP=20,
                                               nFES=self.nFES,
                                               nGEN=self.nGEN,
                                               p=0.5,
                                               benchmark='griewank',
                                               seed=self.seed)
     fpa_griewankc = FlowerPollinationAlgorithm(D=self.D,
                                                NP=20,
                                                nFES=self.nFES,
                                                nGEN=self.nGEN,
                                                p=0.5,
                                                benchmark='griewank',
                                                seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fpa_griewank, fpa_griewankc)
Пример #3
0
 def test_custom_works_fine(self):
     fpa_custom = FlowerPollinationAlgorithm(NP=10,
                                             D=self.D,
                                             nFES=self.nFES,
                                             nGEN=self.nGEN,
                                             p=0.5,
                                             benchmark=MyBenchmark(),
                                             seed=self.seed)
     fpa_customc = FlowerPollinationAlgorithm(NP=10,
                                              D=self.D,
                                              nFES=self.nFES,
                                              nGEN=self.nGEN,
                                              p=0.5,
                                              benchmark=MyBenchmark(),
                                              seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fpa_custom, fpa_customc)
Пример #4
0
 def test_type_parameters(self):
     d = FlowerPollinationAlgorithm.typeParameters()
     self.assertTrue(d['NP'](10))
     self.assertFalse(d['NP'](-10))
     self.assertFalse(d['NP'](0))
     self.assertTrue(d['beta'](10))
     self.assertFalse(d['beta'](0))
     self.assertFalse(d['beta'](-10))
     self.assertTrue(d['p'](0.5))
     self.assertFalse(d['p'](-0.5))
     self.assertFalse(d['p'](1.5))
Пример #5
0
class FPATestCase(TestCase):
    def setUp(self):
        self.fpa_custom = FlowerPollinationAlgorithm(NP=10,
                                                     D=20,
                                                     nFES=1000,
                                                     p=0.5,
                                                     benchmark=MyBenchmark())
        self.fpa_griewank = FlowerPollinationAlgorithm(D=10,
                                                       NP=20,
                                                       nFES=1000,
                                                       p=0.5,
                                                       benchmark='griewank')
        self.fpa_beta_griewank = FlowerPollinationAlgorithm(
            D=10, NP=20, nFES=1000, p=0.5, beta=1.2, benchmark='griewank')

    def test_custom_works_fine(self):
        self.assertTrue(self.fpa_custom.run())

    def test_griewank_works_fine(self):
        self.assertTrue(self.fpa_griewank.run())

    def test_griewank_works_fine_with_beta(self):
        self.assertTrue(self.fpa_beta_griewank.run())
Пример #6
0
 def setUp(self):
     self.fpa_custom = FlowerPollinationAlgorithm(NP=10,
                                                  D=20,
                                                  nFES=1000,
                                                  p=0.5,
                                                  benchmark=MyBenchmark())
     self.fpa_griewank = FlowerPollinationAlgorithm(D=10,
                                                    NP=20,
                                                    nFES=1000,
                                                    p=0.5,
                                                    benchmark='griewank')
     self.fpa_beta_griewank = FlowerPollinationAlgorithm(
         D=10, NP=20, nFES=1000, p=0.5, beta=1.2, benchmark='griewank')
Пример #7
0
from NiaPy.algorithms.basic import FlowerPollinationAlgorithm

# we will run 10 repetitions of Grey Wolf Optimizer against Pinter benchmark function
for i in range(20):
    # first parameter takes dimension of problem
    # second parameter is population size
    # third parameter takes the number of function evaluations
    # fourth parameter is benchmark function
    algorithm = FlowerPollinationAlgorithm(10, 20 , 10000,0.5, 'pinter')

    # running algorithm returns best found minimum
    best = algorithm.run()

    # printing best minimum
    print(best)
Пример #8
0
 def test_griewank_works_fine_with_beta(self):
     fpa_beta_griewank = FlowerPollinationAlgorithm(NP=20, p=0.5, beta=1.2, seed=self.seed)
     fpa_beta_griewankc = FlowerPollinationAlgorithm(NP=20, p=0.5, beta=1.2, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fpa_beta_griewank, fpa_beta_griewankc)
Пример #9
0
 def test_custom_works_fine(self):
     fpa_custom = FlowerPollinationAlgorithm(NP=10, p=0.5, seed=self.seed)
     fpa_customc = FlowerPollinationAlgorithm(NP=10, p=0.5, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fpa_custom, fpa_customc, MyBenchmark())
Пример #10
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

import random
from NiaPy.algorithms.basic import FlowerPollinationAlgorithm
from NiaPy.task.task import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

#we will run Flower Pollination Algorithm for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10, nFES=10000, optType=OptimizationType.MINIMIZATION, benchmark=Sphere())
    algo = FlowerPollinationAlgorithm(NP=20, p=0.5)
    best = algo.run(task=task)
    print(best)

Пример #11
0
    def setUp(self):
        self.fpa_custom = FlowerPollinationAlgorithm(10, 20, 10000, 0.5,
                                                     MyBenchmark())

        self.fpa_griewank = FlowerPollinationAlgorithm(10, 20, 10000, 0.5,
                                                       'griewank')
Пример #12
0
import random
import logging
from NiaPy.algorithms.basic import FlowerPollinationAlgorithm

logging.basicConfig()
logger = logging.getLogger('examples')
logger.setLevel('INFO')

# For reproducive results
random.seed(1234)


class MyBenchmark(object):
    def __init__(self):
        self.Lower = -11
        self.Upper = 11

    def function(self):
        def evaluate(D, sol):
            val = 0.0
            for i in range(D):
                val = val + sol[i] * sol[i]
            return val
        return evaluate

    
for i in range(10):
    Algorithm = FlowerPollinationAlgorithm(NP=10, D=20, nFES=10000, p=0.5, benchmark=MyBenchmark())
    Best = Algorithm.run()
    logger.info(Best)
Пример #13
0
from NiaPy.algorithms.basic import FlowerPollinationAlgorithm

logging.basicConfig()
logger = logging.getLogger('examples')
logger.setLevel('INFO')

# For reproducive results
random.seed(1234)


class MyBenchmark(object):
    def __init__(self):
        self.Lower = -11
        self.Upper = 11

    def function(self):
        def evaluate(D, sol):
            val = 0.0
            for i in range(D):
                val = val + sol[i] * sol[i]
            return val

        return evaluate


for i in range(10):
    Algorithm = FlowerPollinationAlgorithm(10, 20, 10000, 0.5, MyBenchmark())
    Best = Algorithm.run()

    logger.info(Best)