Completed
Push — master ( cc7745...279fb5 )
by Grega
19s queued 17s
created

run   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 25 %

Importance

Changes 0
Metric Value
eloc 37
dl 12
loc 48
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A MyBenchmark.__init__() 3 3 1
A MyBenchmark.function() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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