forked from NiaOrg/NiaPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_fpa.py
37 lines (28 loc) · 840 Bytes
/
run_fpa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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
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(10, 20, 10000, 0.5, MyBenchmark())
Best = Algorithm.run()
logger.info(Best)