Passed
Push — master ( d165b2...cea3b5 )
by Grega
01:07
created

runner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 17.54 %

Importance

Changes 0
Metric Value
eloc 41
dl 10
loc 57
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A MyBenchmark.__init__() 2 2 1
A MyBenchmark.function() 6 6 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
# 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
from NiaPy import Runner
9
from NiaPy.algorithms.basic import (
10
    GreyWolfOptimizer,
11
    ParticleSwarmAlgorithm
12
)
13
from NiaPy.benchmarks import (
14
    Benchmark,
15
    Ackley,
16
    Griewank,
17
    Sphere,
18
    HappyCat
19
)
20
21
22
"""Example demonstrating the use of NiaPy Runner."""
23
24 View Code Duplication
class MyBenchmark(Benchmark):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
25
	def __init__(self):
26
		Benchmark.__init__(self, -10, 10)
27
28
	def function(self):
29
		def evaluate(D, sol):
30
			val = 0.0
31
			for i in range(D): val += sol[i] ** 2
32
			return val
33
		return evaluate
34
35
runner = Runner(
36
    D=40,
37
    nFES=100,
38
    nRuns=2,
39
    useAlgorithms=[
40
        GreyWolfOptimizer(),
41
        "FlowerPollinationAlgorithm",
42
        ParticleSwarmAlgorithm(),
43
        "HybridBatAlgorithm",
44
        "SimulatedAnnealing",
45
        "CuckooSearch"],
46
    useBenchmarks=[
47
        Ackley(),
48
        Griewank(),
49
        Sphere(),
50
        HappyCat(),
51
        "rastrigin",
52
        MyBenchmark()
53
    ]
54
)
55
56
runner.run(export='dataframe', verbose=True)
57