Пример #1
0
 def test_custom1_works_fine(self):
     ca_custom = SimulatedAnnealing(seed=self.seed,
                                    coolingMethod=coolLinear)
     ca_customc = SimulatedAnnealing(seed=self.seed,
                                     coolingMethod=coolLinear)
     AlgorithmTestCase.algorithm_run_test(self, ca_custom, ca_customc,
                                          MyBenchmark())
Пример #2
0
 def test_griewank1_works_fine(self):
     ca_griewank = SimulatedAnnealing(NP=40,
                                      seed=self.seed,
                                      coolingMethod=coolLinear)
     ca_griewankc = SimulatedAnnealing(NP=40,
                                       seed=self.seed,
                                       coolingMethod=coolLinear)
     AlgorithmTestCase.algorithm_run_test(self, ca_griewank, ca_griewankc)
Пример #3
0
 def test_griewank_works_fine(self):
     ca_griewank = SimulatedAnnealing(NP=40,
                                      D=self.D,
                                      nGEN=self.nGEN,
                                      nFES=self.nFES,
                                      benchmark=Griewank(),
                                      seed=self.seed)
     ca_griewankc = SimulatedAnnealing(NP=40,
                                       D=self.D,
                                       nGEN=self.nGEN,
                                       nFES=self.nFES,
                                       benchmark=Griewank(),
                                       seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, ca_griewank, ca_griewankc)
Пример #4
0
 def test_custom_works_fine(self):
     ca_custom = SimulatedAnnealing(NP=40,
                                    D=self.D,
                                    nGEN=self.nGEN,
                                    nFES=self.nFES,
                                    benchmark=MyBenchmark(),
                                    seed=self.seed)
     ca_customc = SimulatedAnnealing(NP=40,
                                     D=self.D,
                                     nGEN=self.nGEN,
                                     nFES=self.nFES,
                                     benchmark=MyBenchmark(),
                                     seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, ca_custom, ca_customc)
Пример #5
0
    def __init__(self, algorithm_name, objective, maxfeval, population=30):
        super().__init__(algorithm_name, objective, maxfeval)
        self.algorithm_name = algorithm_name
        self.algo = None  #this is the suggest function from hyperopt
        if algorithm_name not in __all__:
            raise Exception('NiaPy does not have algorithm :' +
                            str(algorithm_name))

        elif self.algorithm_name == 'NiaPyABC':
            self.algo = ArtificialBeeColonyAlgorithm(NP=population, Limit=100)

        elif self.algorithm_name == 'NiaPyBat':
            self.algo = BatAlgorithm(NP=population)

        elif self.algorithm_name == 'NiaPyCuckooSearch':
            self.algo = CuckooSearch(N=population, pa=0.2, alpha=0.5)

        elif self.algorithm_name == 'NiaPyDifferentialEvolution':
            self.algo = DifferentialEvolution(NP=population, F=1, CR=0.8)

        elif self.algorithm_name == 'NiaPyFireflyAlgorithm':
            self.algo = FireflyAlgorithm(NP=population,
                                         alpha=0.5,
                                         betamin=0.2,
                                         gamma=1.0)

        elif self.algorithm_name == 'NiaPyGeneticAlgorithm':
            self.algo = FireflyAlgorithm(NP=population,
                                         Crossover=UniformCrossover,
                                         Mutation=UniformMutation,
                                         Cr=0.45,
                                         Mr=0.9)

        elif self.algorithm_name == 'NiaPyGWO':
            self.algo = GreyWolfOptimizer(NP=population)
        # config
        elif self.algorithm_name == 'NiaPyNelderMead':
            self.algo = NelderMeadMethod()
        # config
        elif self.algorithm_name == 'NiaPyPSO':
            self.algo = ParticleSwarmAlgorithm(NP=population,
                                               C1=2,
                                               C2=2,
                                               w=0.9,
                                               vMin=-1.5,
                                               vMax=1.5)

        # config

        # config
        # config
        elif self.algorithm_name == 'NiaPySimulatedAnnealing':
            self.algo = SimulatedAnnealing(coolingMethod=coolLinear)
Пример #6
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.other import SimulatedAnnealing
from NiaPy.task.task import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere
from NiaPy.algorithms.other.sa import coolLinear

# we will run Simulated Annealing for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10,
                        nGEN=10000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = SimulatedAnnealing(coolingMethod=coolLinear)
    best = algo.run(task=task)
    print(best)
Пример #7
0
 def test_griewank_works_fine(self):
     ca_griewank = SimulatedAnnealing(NP=40, seed=self.seed)
     ca_griewankc = SimulatedAnnealing(NP=40, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, ca_griewank, ca_griewankc)
Пример #8
0
 def test_custom_works_fine(self):
     ca_custom = SimulatedAnnealing(NP=40, seed=self.seed)
     ca_customc = SimulatedAnnealing(NP=40, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, ca_custom, ca_customc,
                                          MyBenchmark())