Passed
Push — master ( 955352...262491 )
by Simon
04:37 queued 13s
created

hyperactive.optimizers.constraint   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Constraint.__call__() 0 3 1
A Constraint.__init__() 0 3 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A gfo2hyper() 0 7 2
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
def gfo2hyper(search_space, para):
7
    values_dict = {}
8
    for _, key in enumerate(search_space.keys()):
9
        pos_ = int(para[key])
10
        values_dict[key] = search_space[key][pos_]
11
12
    return values_dict
13
14
15
class Constraint:
16
    def __init__(self, constraint, search_space):
17
        self.constraint = constraint
18
        self.search_space = search_space
19
20
    def __call__(self, para):
21
        para = gfo2hyper(self.search_space, para)
22
        return self.constraint(para)
23