@@ -23,19 +23,21 @@ def init_FA(self):
23
23
for i in range (self .n ):
24
24
for j in range (self .D ):
25
25
self .populationArray [i ][j ] = rand .uniform (self .Lb , self .Ub )
26
- self .functionArray [i ] = func (self .populationArray [i ][ 0 ] , self .populationArray [ i ][ 1 ] )
26
+ self .functionArray [i ] = self . func (self .populationArray [i ,:] , self .D )
27
27
28
28
def update (self , i , j ):
29
29
scale = self .Ub - self .Lb
30
- r = (self .populationArray [i ][0 ] - self .populationArray [j ][0 ])** 2 + (self .populationArray [i ][1 ] - self .populationArray [j ][1 ])** 2
30
+ r = 0
31
+ for k in range (self .D ):
32
+ r += (self .populationArray [i ][k ] - self .populationArray [j ][k ])** 2
31
33
beta = self .beta0 * math .exp (- self .gamma * r )
32
34
for k in range (self .D ):
33
35
steps = (self .alpha * self .theta )* (rand .random () - 0.5 )* scale
34
36
self .tmpArray [k ] = self .populationArray [i ][k ] + beta * (self .populationArray [j ][k ] - self .populationArray [i ][k ]) + steps
35
- if (func (self .tmpArray [ 0 ] , self .tmpArray [ 1 ] ) < self .functionArray [i ]):
37
+ if (self . func (self .tmpArray , self .D ) < self .functionArray [i ]):
36
38
for k in range (self .D ):
37
39
self .populationArray [i ][k ] = self .tmpArray [k ]
38
- self .functionArray [i ] = func (self .tmpArray [ 0 ] , self .tmpArray [ 1 ] )
40
+ self .functionArray [i ] = self . func (self .tmpArray , self .D )
39
41
40
42
def doRun (self ):
41
43
self .init_FA ()
@@ -45,5 +47,6 @@ def doRun(self):
45
47
for j in range (self .n ):
46
48
if (self .functionArray [i ] > self .functionArray [j ] and i != j ):
47
49
self .update (i ,j )
50
+ print (self .populationArray )
48
51
print (self .functionArray )
49
52
return self .functionArray .min ()
0 commit comments