-
Notifications
You must be signed in to change notification settings - Fork 1
/
nichec.py
77 lines (69 loc) · 2.38 KB
/
nichec.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
# -*- coding: utf-8 -*-
import random
import math
z = 1.0e-8
Nearzero = 1.0e-15
def get_MaxR(dimension, pointAmount, upper, lower):
production = 1.0
difference = [0.0 for ii in range(dimension)]
for i in range(dimension):
difference[i] = upper[i]-lower[i]
production *= difference[i]
production *= 2*dimension
R = 0.5 * pow(production/(pointAmount * math.pi), 1.0/dimension)
return R
def reduce_radius(k, MaxK, genecount, R, upper, lower): # Modified by JRW, 2018/03/02
production = 1.0
for i in xrange(genecount):
production *= (upper[i] - lower[i])
z1 = z/( production**(1.0/genecount) )
C = R + z1
c = math.sqrt(abs(math.log(C/z1, math.e)))
D = float(MaxK)/c
q = float(k)/D
f = C * math.pow(math.e, -math.pow(q, 2)) - z1
if abs(f) < Nearzero:
f = 0.0
return f
'''def reduce_radius(k, MaxK, genecount, R, upper, lower):
production = 1.0
for i in xrange(genecount):
production *= (upper[i] - lower[i])
z1 = z/( production**(1.0/genecount) )
#R=get_MaxR(gencount,size,pop)
C = R
c = math.sqrt(abs(math.log(C/z1, math.e)))
D = float(MaxK)/c
q = float(k)/D
f = C * math.pow(math.e, -math.pow(q, 2))
if abs(f-z)<Nearzero:
f=z
if abs(f) < Nearzero:
f = 0.0
return f'''
def caculate_nichecount(_pop, _S, _genCount, r, size):#密度目标
sum_pop = []
sum_pop.extend(_pop)
sum_pop.extend(_S)
nonZero = 0
nicheCount = [0.0 for x in range(size)]
for i in range(size):
for j in range (i+1, size):
sum1 = 0.0
for k in range(_genCount):
difference = sum_pop[i]['genes'][k] - sum_pop[j]['genes'][k] #X1i-X2i
sum1 += (difference*difference)
aDist = math.sqrt(sum1)
if(aDist < r):
shareF = 1 - (aDist/r)
nicheCount[i] += shareF
nicheCount[j] += shareF
if nicheCount[i] != 0.0:
nonZero +=1
if len(sum_pop[i]['violation_objectives']) == 2:
sum_pop[i]['violation_objectives'][1] = nicheCount[i]
elif len(sum_pop[i]['violation_objectives']) == 1:
sum_pop[i]['violation_objectives'].append(nicheCount[i])
else :
print "wrong"
#print "nonzero", nonZero