Completed
Pull Request — master (#22)
by Grega
03:00
created

Utility   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 8
c 4
b 0
f 1
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C get_benchmark() 0 19 8
1
"""Utilities for benchmarks."""
2
3
from . import Rastrigin, Rosenbrock, Griewank, Sphere, Ackley, Schwefel
4
5
__all__ = ['Utility']
6
7
8
class Utility(object):
9
10
    # pylint: disable=too-many-return-statements
11
    @staticmethod
12
    def get_benchmark(benchmark):
13
        if not isinstance(benchmark, ''.__class__):
14
            return benchmark
15
        else:
16
            if benchmark == 'rastrigin':
17
                return Rastrigin()
18
            elif benchmark == 'rosenbrock':
19
                return Rosenbrock()
20
            elif benchmark == 'griewank':
21
                return Griewank()
22
            elif benchmark == 'sphere':
23
                return Sphere()
24
            elif benchmark == 'ackley':
25
                return Ackley()
26
            elif benchmark == 'schwefel':
27
                return Schwefel()
28
            else:
29
                raise TypeError('Passed benchmark is not defined!')
30