-
Notifications
You must be signed in to change notification settings - Fork 6
/
P_objective.py
102 lines (96 loc) · 3.59 KB
/
P_objective.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import numpy as np
from public import glo
from public.util import tis_constraint6,tis_function6,mti,h_tdcs,mti_avoid,h_mti,tdcs_function
import multiprocessing
NUM_ELE = glo.NUM_ELE
Pool_size = 1
def fun_(x):
if glo.type == 'ti':
if tis_constraint6(x):
result = tis_function6(x)
if result[0] > 10:
result = result * result[0]
else:
result = [10000, 10000]
if glo.type == 'mti':
cv_value = h_mti(x)
if cv_value > 0.01:
result = [100000 * cv_value, 100000 * cv_value]
else:
intensity = mti(x)
#print(intensity)
if intensity[0] > 10:
result = intensity * intensity[0]
else:
result = intensity
if glo.type == 'tdcs':
cv_value = h_tdcs(x)
if cv_value > 0.01:
result = [100000 * cv_value, 100000 * cv_value]
else:
result = tdcs_function(x)
if result[0] > 10:
result = result * result[0]
return result
def P_objective(Operation,Problem,M,Input,epoch=0):
[Output, Boundary, Coding] = TES(Operation, Problem, M, Input,epoch)
if Boundary == []:
return Output
else:
return Output, Boundary, Coding
def TES(Operation,Problem,M,Input,epoch):
if glo.type == 'ti':
Boundary = []
Coding = ""
if Operation == "init":
MaxValue = np.ones((1, 6))
MinValue = np.zeros((1, 6))
Population = np.random.uniform(0, 1, size=(Input, 6))
Boundary = np.vstack((MaxValue, MinValue))
Coding = "Real"
return Population, Boundary, Coding
elif Operation == "value":
Population = Input
FunctionValue = np.zeros((Population.shape[0], M))
if Problem == "TEScv2":
p = multiprocessing.Pool(Pool_size)
FunctionValue = np.array(p.map(fun_, Population))
p.close()
p.join()
if glo.type == 'mti':
Boundary = []
Coding = ""
if Operation == "init":
MaxValue = np.ones((1, (NUM_ELE*2)))
MinValue = -np.ones((1, (NUM_ELE*2)))
Population = np.random.uniform(-1, 1, size=(Input, (NUM_ELE*2)))
Boundary = np.vstack((MaxValue, MinValue))
Coding = "Real"
return Population, Boundary, Coding
elif Operation == "value":
Population = Input
FunctionValue = np.zeros((Population.shape[0], M))
if Problem == "TEScv2":
p = multiprocessing.Pool(Pool_size)
FunctionValue = np.array(p.map(fun_, Population))
p.close()
p.join()
if glo.type == 'tdcs':
Boundary = []
Coding = ""
if Operation == "init":
MaxValue = np.ones((1, NUM_ELE))
MinValue = -np.ones((1, NUM_ELE))
Population = np.random.uniform(-1, 1, size=(Input, NUM_ELE))
Boundary = np.vstack((MaxValue, MinValue))
Coding = "Real"
return Population, Boundary, Coding
elif Operation == "value":
Population = Input
FunctionValue = np.zeros((Population.shape[0], M))
if Problem == "TEScv2":
p = multiprocessing.Pool(Pool_size)
FunctionValue = np.array(p.map(fun_, Population))
p.close()
p.join()
return FunctionValue, Boundary, Coding