Passed
Pull Request — master (#25)
by Grega
03:04
created

Utility   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 6
Bugs 2 Features 1
Metric Value
c 6
b 2
f 1
dl 0
loc 45
rs 10
wmc 27

1 Method

Rating   Name   Duplication   Size   Complexity  
F get_benchmark() 0 42 27
1
"""Implementation of benchmarks utility function."""
2
3
from . import Rastrigin, Rosenbrock, Griewank, Sphere, Ackley, Schwefel
0 ignored issues
show
Unused Code introduced by
The import Schwefel seems to be unused.
Loading history...
4
5
__all__ = ['Utility']
6
7
8
# pylint: disable=too-many-return-statements
9
class Utility:
10
11
    # pylint: disable=too-many-return-statements
12
    @staticmethod
13
    def get_benchmark(benchmark, LowerBound=None, UpperBound=None):
14
        if not isinstance(benchmark, ''.__class__):
15
            return benchmark
16
        else:
17
            if benchmark == 'rastrigin':
18
                if UpperBound is None and LowerBound is None:
19
                    return Rastrigin()
20
                elif UpperBound is not None and LowerBound is not None:
21
                    return Rastrigin(LowerBound, UpperBound)
22
                else:
23
                    raise TypeError('Upper and Lower value must be defined!')
24
            elif benchmark == 'rosenbrock':
25
                if UpperBound is None and LowerBound is None:
26
                    return Rosenbrock()
27
                elif UpperBound is not None and LowerBound is not None:
28
                    return Rosenbrock(LowerBound, UpperBound)
29
                else:
30
                    raise TypeError('Upper and Lower value must be defined!')
31
            elif benchmark == 'griewank':
32
                if UpperBound is None and LowerBound is None:
33
                    return Griewank()
34
                elif UpperBound is not None and LowerBound is not None:
35
                    return Griewank(LowerBound, UpperBound)
36
                else:
37
                    raise TypeError('Upper and Lower value must be defined!')
38
            elif benchmark == 'sphere':
39
                if UpperBound is None and LowerBound is None:
40
                    return Sphere()
41
                elif UpperBound is not None and LowerBound is not None:
42
                    return Sphere(LowerBound, UpperBound)
43
                else:
44
                    raise TypeError('Upper and Lower value must be defined!')
45
            elif benchmark == 'ackley':
46
                if UpperBound is None and LowerBound is None:
47
                    return Ackley()
48
                elif UpperBound is not None and LowerBound is not None:
49
                    return Ackley(LowerBound, UpperBound)
50
                else:
51
                    raise TypeError('Upper and Lower value must be defined!')
52
            else:
53
                raise TypeError('Passed benchmark is not defined!')
54