示例#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
文件: test_fpa.py 项目: tuahk/NiaPy
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
文件: test_fpa.py 项目: tuahk/NiaPy
 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
文件: run_fpa.py 项目: tuahk/NiaPy
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)