Passed
Push — master ( 8465f7...8358a6 )
by Grega
01:08
created

run_dynpmsde   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 0
1
# encoding=utf8
2
# This is temporary fix to import module from parent folder
3
# It will be removed when package is published on PyPI
4
import sys
5
sys.path.append('../')
6
# End of fix
7
8
import random
9
from NiaPy.algorithms.basic import DynNpMultiStrategyDifferentialEvolution
10
from NiaPy.algorithms.basic.de import CrossBest2, CrossCurr2Best1
11
from NiaPy.util import StoppingTask, OptimizationType
12
from NiaPy.benchmarks import Sphere
13
14
#we will run Differential Evolution for 5 independent runs
15
for i in range(5):
16
    task = StoppingTask(D=10, nFES=1000, optType=OptimizationType.MINIMIZATION, benchmark=Sphere())
17
    algo = DynNpMultiStrategyDifferentialEvolution(NP=80, F=0.2, CR=0.7, strategies=(CrossCurr2Best1, CrossBest2), pmax=5)
18
    best = algo.run(task=task)
19
    print('%s -> %s' % (best[0].x, best[1]))
20