Ejemplo n.º 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())
Ejemplo n.º 2
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())
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)

Ejemplo n.º 5
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)