Skip to content

Sort optimization #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions FireflyAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,9 @@ def alpha_new(self, a):
delta = 1.0 - math.pow((math.pow(10.0, -4.0) / 0.9), 1.0 / float(a))
return (1 - delta) * self.alpha

def sort_ffa(self): # implementation of bubble sort
for i in range(self.NP):
self.Index[i] = i

for i in range(0, (self.NP - 1)):
j = i + 1
for j in range(j, self.NP):
if (self.I[i] > self.I[j]):
z = self.I[i] # exchange attractiveness
self.I[i] = self.I[j]
self.I[j] = z
z = self.Fitness[i] # exchange fitness
self.Fitness[i] = self.Fitness[j]
self.Fitness[j] = z
z = self.Index[i] # exchange indexes
self.Index[i] = self.Index[j]
self.Index[j] = z
def sort_ffa(self):
self.Index = [i for i in range(self.NP)]
self.I, self.Fitness, self.Index = [list(l) for l in zip(*sorted(zip(self.I, self.Fitness, self.Index)))]

def replace_ffa(self): # replace the old population according to the new Index values
# copy original population to a temporary area
Expand Down