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

hyperactive.optimizers.constraint.gfo2hyper()   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
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