-
Notifications
You must be signed in to change notification settings - Fork 6
/
ti_problem.py
45 lines (42 loc) · 1.43 KB
/
ti_problem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import numpy as np
from public import glo,util
import geatpy as ea
NUM_ELE =glo.NUM_ELE
class MyProblem(ea.Problem):
def __init__(self):
name = 'MyProblem'
M = 1
maxormins = [1]
self.var_set = np.arange(0,NUM_ELE,1)
Dim = 5
varTypes = [1] * Dim
lb = [0, 0, 0, 0, 0]
ub = [(NUM_ELE-1), (NUM_ELE-1), (NUM_ELE-1), (NUM_ELE-1), (NUM_ELE-1)]
lbin = [1] * Dim
ubin = [1] * Dim
ea.Problem.__init__(self,
name,
M,
maxormins,
Dim,
varTypes,
lb,
ub,
lbin,
ubin)
def evalVars(self, Vars):
Vars = Vars.astype(np.int32)
x1 = self.var_set[Vars[:, [0]]]
x2 = self.var_set[Vars[:, [1]]]
x3 = self.var_set[Vars[:, [2]]]
x4 = self.var_set[Vars[:, [3]]]
x5 = self.var_set[Vars[:, [4]]]
r = np.zeros(len(x1)).tolist()
for i in range(len(x1)):
lst = [int(x1[i]),int(x2[i]),int(x3[i]),int(x4[i])]
set_lst = set(lst)
if len(set_lst) == len(lst):
r[i] = [util.tis_function5(x1[i], x2[i], x3[i], x4[i],x5[i])]
else:
r[i] = [1000]
return np.array(r)