Skip to content

Commit a5546f0

Browse files
committed
Fix bug self.epoch in SCSO
1 parent 2ec7436 commit a5546f0

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

mealpy/swarm_based/SCSO.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ class OriginalSCSO(Optimizer):
1616
1. https://link.springer.com/article/10.1007/s00366-022-01604-x
1717
2. https://www.mathworks.com/matlabcentral/fileexchange/110185-sand-cat-swarm-optimization
1818
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-
2319
Examples
2420
~~~~~~~~
2521
>>> import numpy as np
@@ -57,11 +53,11 @@ def __init__(self, epoch=10000, pop_size=100, **kwargs):
5753
self.epoch = self.validator.check_int("epoch", epoch, [1, 100000])
5854
self.pop_size = self.validator.check_int("pop_size", pop_size, [10, 10000])
5955
self.set_parameters(["epoch", "pop_size"])
60-
self.P = np.arange(1, 361)
6156
self.sort_flag = False
6257

6358
def initialize_variables(self):
6459
self.S = 2 # maximum Sensitivity range
60+
self.P = np.arange(1, 361)
6561

6662
def get_index_roulette_wheel_selection__(self, p):
6763
p = p / np.sum(p)
@@ -75,16 +71,15 @@ def evolve(self, epoch):
7571
Args:
7672
epoch (int): The current iteration
7773
"""
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)
8075
pop_new = []
8176
for idx in range(0, self.pop_size):
8277
r = np.random.rand() * guides_r
8378
R = (2*guides_r)*np.random.rand() - guides_r # controls to transition phases
8479
pos_new = self.pop[idx][self.ID_POS].copy()
8580
for jdx in range(0, self.problem.n_dims):
8681
teta = self.get_index_roulette_wheel_selection__(self.P)
87-
if 0 <= R <= 1:
82+
if -1 <= R <= 1:
8883
rand_pos = np.abs(np.random.rand() * self.g_best[self.ID_POS][jdx] - self.pop[idx][self.ID_POS][jdx])
8984
pos_new[jdx] = self.g_best[self.ID_POS][jdx] - r * rand_pos * np.cos(teta)
9085
else:

run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from mealpy.swarm_based.AGTO import MGTO
2020
from mealpy import EOA, SBO, SMA, SOA, MA, BRO, BSO, CHIO, FBIO, HBO, QSA, SARO, TLO
2121
from mealpy import PSS, ASO, EO, FLA, BFO, GJO, GTO, HHO, MPA, SeaHO, SRSR, AVOA, SA, BSO
22-
from mealpy import GWO
22+
from mealpy import GWO, SCSO
2323

2424
# from mealpy.utils.problem import Problem
2525
from mealpy import Problem
@@ -114,6 +114,7 @@ def fit_func(self, solution):
114114
model = GWO.GWO_WOA(epoch, pop_size)
115115
model = GWO.RW_GWO(epoch, pop_size)
116116
# model = BSO.ImprovedBSO(epoch, pop_size)
117+
model = SCSO.OriginalSCSO(epoch, pop_size)
117118
best_position, best_fitness = model.solve(P1)#, mode="thread", n_workers=4, termination=term_dict1)
118119

119120
print(best_position)

0 commit comments

Comments
 (0)