Skip to content

Commit 7e136ed

Browse files
committed
fix: Fixed GARSReversals wrong nfe count and scores recording
1 parent 957e0c6 commit 7e136ed

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

fliscopt/ga.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,11 @@ def run(self,domain,fitness_function,seed) -> tuple:
444444
costs.sort(reverse=True)
445445
rev += 1
446446
else:
447+
best_cost = sys.maxsize
448+
best_solution=[]
447449
rev += 1
448450
for _ in range(self.step_length - 1):
449451
costs.sort(reverse=True)
450-
nfe = 0
451452
solution = [self.r_init.randint(self.domain[i][0], self.domain[i][1])
452453
for i in range(len(self.domain))]
453454

@@ -460,11 +461,11 @@ def run(self,domain,fitness_function,seed) -> tuple:
460461

461462
nfe += 1
462463
if cost > self.best_cost:
463-
self.best_cost = cost
464-
self.best_solution = solution
464+
best_cost = cost
465+
best_solution = solution
465466

466-
scores.append(self.best_cost)
467-
population.append(self.best_solution)
467+
scores.append(best_cost)
468+
population.append(best_solution)
468469

469470
print(rev) # To print the number of reversals
470471
else:

0 commit comments

Comments
 (0)