Completed
Push — master ( aad3b0...602eea )
by Grega
9s
created

Utility   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 5
Bugs 2 Features 0
Metric Value
c 5
b 2
f 0
dl 0
loc 44
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __init__() 0 28 1
A get_benchmark() 0 8 3
A __raiseLowerAndUpperNotDefined() 0 3 1
1
"""Implementation of benchmarks utility function."""
2
3
from . import Rastrigin, Rosenbrock, Griewank, \
4
    Sphere, Ackley, Schwefel, Schwefel221, \
5
    Schwefel222, Whitley, Alpine1, Alpine2, HappyCat, \
6
    Ridge, ChungReynolds, Csendes, Pinter, Qing, Quintic, \
7
    Salomon, SchumerSteiglitz, Step, Step2, Step3, Stepint, SumSquares, StyblinskiTang
8
9
10
__all__ = ['Utility']
11
12
13
class Utility(object):
14
15
    def __init__(self):
16
        self.classes = {
17
            'ackley': Ackley,
18
            'alpine1': Alpine1,
19
            'alpine2': Alpine2,
20
            'chungReynolds': ChungReynolds,
21
            'csendes': Csendes,
22
            'griewank': Griewank,
23
            'happyCat': HappyCat,
24
            'pinter': Pinter,
25
            'quing': Qing,
26
            'quintic': Quintic,
27
            'rastrigin': Rastrigin,
28
            'ridge': Ridge,
29
            'rosenbrock': Rosenbrock,
30
            'salomon': Salomon,
31
            'schumerSteiglitz': SchumerSteiglitz,
32
            'schwefel': Schwefel,
33
            'schwefel221': Schwefel221,
34
            'schwefel222': Schwefel222,
35
            'sphere': Sphere,
36
            'step': Step,
37
            'step2': Step2,
38
            'step3': Step3,
39
            'stepint': Stepint,
40
            'styblinskiTang': StyblinskiTang,
41
            'sumSquares': SumSquares,
42
            'whitley': Whitley
43
        }
44
45
    def get_benchmark(self, benchmark):
46
        if not isinstance(benchmark, ''.__class__):
47
            return benchmark
48
        else:
49
            if benchmark in self.classes:
50
                return self.classes[benchmark]()
51
            else:
52
                raise TypeError('Passed benchmark is not defined!')
53
54
    @classmethod
55
    def __raiseLowerAndUpperNotDefined(cls):
56
        raise TypeError('Upper and Lower value must be defined!')
57