@@ -21,7 +21,7 @@ def __init__(self, configuration, numberOfCrossoverPoints=2, mutationSize=2, cro
21
21
mutationProbability )
22
22
23
23
self ._chromlen , self ._minValue , self ._alpha , self ._pa = 0 , 0 , .9 , .25
24
- self ._f1 , self . _f2 , self . _loudness , self ._rate = None , None , None , None
24
+ self ._loudness , self ._rate = None , None
25
25
26
26
self ._gBest = None
27
27
self ._position = [[]]
@@ -41,8 +41,6 @@ def initialize(self, population):
41
41
population [i ] = prototype .makeNewFromPrototype (positions )
42
42
if i < 1 :
43
43
self ._chromlen = len (positions )
44
- self ._f1 = np .zeros (self ._chromlen , dtype = float )
45
- self ._f2 = np .zeros (self ._chromlen , dtype = float )
46
44
self ._rate = np .zeros (populationSize , dtype = float )
47
45
self ._loudness = np .zeros (populationSize , dtype = float )
48
46
self ._position = np .zeros ((populationSize , self ._chromlen ), dtype = float )
@@ -55,8 +53,7 @@ def initialize(self, population):
55
53
def updatePositions (self , population ):
56
54
mean = np .mean (self ._loudness )
57
55
currentGeneration , prototype = self ._currentGeneration , self ._prototype
58
- f1 , f2 , gBest = self ._f1 , self ._f2 , self ._gBest
59
- maxValues , minValue = self ._maxValues , self ._minValue
56
+ gBest , maxValues , minValue = self ._gBest , self ._maxValues , self ._minValue
60
57
position , rate , loudness = self ._position , self ._rate , self ._loudness
61
58
62
59
localBest = prototype .makeNewFromPrototype ()
@@ -74,9 +71,9 @@ def updatePositions(self, population):
74
71
r4 = np .random .randint (0 , populationSize )
75
72
76
73
for j in range (self ._chromlen ):
77
- f1 [ j ] = ((minValue - maxValues [j ]) * currentGeneration / 𝛽1 + maxValues [j ]) * beta
78
- f2 [ j ] = ((maxValues [j ] - minValue ) * currentGeneration / 𝛽2 + minValue ) * beta
79
- position [i , j ] = gBest [j ] + f1 [ j ] * (position [r1 ][j ] - position [r2 ][j ]) + f2 [ j ] * (position [r3 ][j ] - position [r3 ][j ])
74
+ f1 = ((minValue - maxValues [j ]) * currentGeneration / 𝛽1 + maxValues [j ]) * beta
75
+ f2 = ((maxValues [j ] - minValue ) * currentGeneration / 𝛽2 + minValue ) * beta
76
+ position [i , j ] = gBest [j ] + f1 * (position [r1 ][j ] - position [r2 ][j ]) + f2 * (position [r3 ][j ] - position [r3 ][j ])
80
77
81
78
if rand > rate [i ]:
82
79
𝜀 = np .random .uniform (low = - 1 , high = 1 )
0 commit comments