from platypus import NSGAII, Problem, Real, Archive
# We can subclass other kinds of Archive instead if needed.
class LoggingArchive(Archive):
def __init__(self, *args, **kwargs):
super().__init__(*args, *kwargs)
self.log = []
def add(self, solution):
super().add(solution)
self.log.append(solution)
log_archive = LoggingArchive()
# copy the example from the platypus README
def schaffer(x):
return [x[0]**2, (x[0]-2)**2]
problem = Problem(1, 2)
problem.types[:] = Real(-10, 10)
problem.function = schaffer
# here we tell the optimizer to use the archive we chose.
algorithm = NSGAII(problem, archive = log_archive)
algorithm.run(10)
print(log_archive.log[:5]) # print the first 5 solutions in the log
Originally posted by @Wbec in https://github.com/Project-Platypus/Platypus/issues/71#issuecomment-513524660