@@ -16,10 +16,6 @@ class OriginalSCSO(Optimizer):
16
16
1. https://link.springer.com/article/10.1007/s00366-022-01604-x
17
17
2. https://www.mathworks.com/matlabcentral/fileexchange/110185-sand-cat-swarm-optimization
18
18
19
- Notes:
20
- 1. The matlab code will not work since the R value always in the range (-1, 1).
21
- 2. The authors make a mistake in matlab code. It should be 0 <= R <= 1 in the If condition
22
-
23
19
Examples
24
20
~~~~~~~~
25
21
>>> import numpy as np
@@ -57,11 +53,11 @@ def __init__(self, epoch=10000, pop_size=100, **kwargs):
57
53
self .epoch = self .validator .check_int ("epoch" , epoch , [1 , 100000 ])
58
54
self .pop_size = self .validator .check_int ("pop_size" , pop_size , [10 , 10000 ])
59
55
self .set_parameters (["epoch" , "pop_size" ])
60
- self .P = np .arange (1 , 361 )
61
56
self .sort_flag = False
62
57
63
58
def initialize_variables (self ):
64
59
self .S = 2 # maximum Sensitivity range
60
+ self .P = np .arange (1 , 361 )
65
61
66
62
def get_index_roulette_wheel_selection__ (self , p ):
67
63
p = p / np .sum (p )
@@ -75,16 +71,15 @@ def evolve(self, epoch):
75
71
Args:
76
72
epoch (int): The current iteration
77
73
"""
78
- t = self .epoch + 1
79
- guides_r = self .S - (self .S * t / self .epoch )
74
+ guides_r = self .S - (self .S * (epoch + 1 ) / self .epoch )
80
75
pop_new = []
81
76
for idx in range (0 , self .pop_size ):
82
77
r = np .random .rand () * guides_r
83
78
R = (2 * guides_r )* np .random .rand () - guides_r # controls to transition phases
84
79
pos_new = self .pop [idx ][self .ID_POS ].copy ()
85
80
for jdx in range (0 , self .problem .n_dims ):
86
81
teta = self .get_index_roulette_wheel_selection__ (self .P )
87
- if 0 <= R <= 1 :
82
+ if - 1 <= R <= 1 :
88
83
rand_pos = np .abs (np .random .rand () * self .g_best [self .ID_POS ][jdx ] - self .pop [idx ][self .ID_POS ][jdx ])
89
84
pos_new [jdx ] = self .g_best [self .ID_POS ][jdx ] - r * rand_pos * np .cos (teta )
90
85
else :
0 commit comments