From 9f12609a6c5c7d0104f0a517c264a133c52e8a73 Mon Sep 17 00:00:00 2001 From: waterfall-xi <146172962+waterfall-xi@users.noreply.github.com> Date: Sat, 9 Mar 2024 00:32:26 +0800 Subject: [PATCH 1/2] Add reconstruct_objs feature A new feature is added to the iterative process of the optimization algorithm. Users can customize a function and assign it to the Algorithm through kwsargs, call the function in each iteration in run() and update the objs to implement the dynamic objective function in the iteration. --- pymoo/core/algorithm.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pymoo/core/algorithm.py b/pymoo/core/algorithm.py index f3fc071f5..a47a165eb 100644 --- a/pymoo/core/algorithm.py +++ b/pymoo/core/algorithm.py @@ -138,6 +138,9 @@ def setup(self, problem, **kwargs): def run(self): while self.has_next(): + if 'reconstruct_objs_func' in self.__dict__: + new_objs = self.reconstruct_objs_func() + self.problem.objs = new_objs self.next() return self.result() From 1dfe4984b68e3e9d1a3f2dc40aa5df1264d77981 Mon Sep 17 00:00:00 2001 From: waterfall-xi <146172962+waterfall-xi@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:41:18 +0800 Subject: [PATCH 2/2] reconstruct_objs according algorithm self A new feature is added to the iterative process of the optimization algorithm. Users can customize a function and assign it to the Algorithm through kwsargs, call the function in each iteration in run() and update the objs to implement the dynamic objective function in the iteration. reconstruct_objs_func() is required to include the arguement algo and can be used to complete the objs reconstruction using the information in algo. --- pymoo/core/algorithm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pymoo/core/algorithm.py b/pymoo/core/algorithm.py index 04e271b98..c7c3567b1 100644 --- a/pymoo/core/algorithm.py +++ b/pymoo/core/algorithm.py @@ -136,8 +136,7 @@ def setup(self, problem, **kwargs): def run(self): while self.has_next(): if 'reconstruct_objs_func' in self.__dict__: - new_objs = self.reconstruct_objs_func() - self.problem.objs = new_objs + self.problem.objs = self.reconstruct_objs_func(algo=self) self.next() return self.result()