1
|
|
|
# This is temporary fix to import module from parent folder |
2
|
|
|
# It will be removed when package is published on PyPI |
3
|
|
|
import sys |
4
|
|
|
sys.path.append('../') |
5
|
|
|
# End of fix |
6
|
|
|
|
7
|
|
|
import logging |
8
|
|
|
import NiaPy |
9
|
|
|
|
10
|
|
|
logging.basicConfig() |
11
|
|
|
logger = logging.getLogger('examples') |
12
|
|
|
logger.setLevel('INFO') |
13
|
|
|
|
14
|
|
|
|
15
|
|
View Code Duplication |
class MyBenchmark(object): |
|
|
|
|
16
|
|
|
def __init__(self): |
17
|
|
|
self.Lower = -5.12 |
18
|
|
|
self.Upper = 5.12 |
19
|
|
|
|
20
|
|
|
def function(self): |
21
|
|
|
def evaluate(D, sol): |
22
|
|
|
val = 0.0 |
23
|
|
|
for i in range(D): |
24
|
|
|
val = val + sol[i] * sol[i] |
25
|
|
|
return val |
26
|
|
|
return evaluate |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
algorithms = ['BatAlgorithm', |
30
|
|
|
'DifferentialEvolution', |
31
|
|
|
'FireflyAlgorithm', |
32
|
|
|
'FlowerPollinationAlgorithm', |
33
|
|
|
'GreyWolfOptimizer', |
34
|
|
|
'ArtificialBeeColonyAlgorithm', |
35
|
|
|
'GeneticAlgorithm', |
36
|
|
|
'ParticleSwarmAlgorithm', |
37
|
|
|
'HybridBatAlgorithm', |
38
|
|
|
'SelfAdaptiveDifferentialEvolution'] |
39
|
|
|
benchmarks = ['ackley', 'alpine1', 'alpine2', 'chungReynolds', |
40
|
|
|
'csendes', 'griewank', 'happyCat', 'pinter', |
41
|
|
|
'quing', 'quintic', 'rastrigin', 'ridge', |
42
|
|
|
'rosenbrock', 'salomon', 'schumerSteiglitz', 'schwefel', |
43
|
|
|
'schwefel221', 'schwefel222', 'sphere', 'step', |
44
|
|
|
'step2', 'step3', 'stepint', 'styblinskiTang', |
45
|
|
|
'sumSquares', 'whitley', MyBenchmark()] |
46
|
|
|
|
47
|
|
|
NiaPy.Runner(10, 40, 1000, 3, algorithms, benchmarks).run(export='json', verbose=True) |
48
|
|
|
|