Skip to content

Commit f9ccfce

Browse files
authored
Add files via upload
1 parent 80d2b59 commit f9ccfce

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

algorithm/Cso.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,24 @@ def updatePosition2(self, population):
8181
populationSize = self._populationSize
8282
for i in range(populationSize):
8383
d1, d2 = np.random.randint(0, 5, 2)
84+
changed = False
8485
for j in range(self._chromlen):
8586
r = np.random.rand()
8687
if r < self._pa:
88+
changed = True
8789
self._current_position[i, j] += random.random() * (current_position[d1, j] - current_position[d2, j])
88-
self._current_position[i] = self.optimum(self._current_position[i], population[i])
90+
91+
if changed:
92+
self._current_position[i] = self.optimum(self._current_position[i], population[i])
93+
94+
95+
def reform(self):
96+
random.seed(round(time() * 1000))
97+
np.random.seed(int(time()))
98+
if self._crossoverProbability < 95:
99+
self._crossoverProbability += 1.0
100+
elif self._pa < .5:
101+
self._pa += .01
89102

90103

91104
def replacement(self, population):

0 commit comments

Comments
 (0)