From 71f68e85ea6f1790e906f75961b9cda2e88e8d72 Mon Sep 17 00:00:00 2001 From: Yanina Kolt <43132462+YaniKolt@users.noreply.github.com> Date: Thu, 3 Aug 2023 13:49:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=20?= =?UTF-8?q?=D1=81=20=D0=B4=D0=B8=D1=81=D0=BA=D1=80=D0=B5=D1=82=D0=BD=D1=8B?= =?UTF-8?q?=D0=BC=D0=B8=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=20(#159)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Исправлена загрузка для дискретных параметров, исправлено вычисление M в mixed integer method * Исправлены имена в задачах * Добавлены новые задачи с ограничениями и дискретными параметрами * Удалены задачи * Update mixed_integer_method.py * Update process.py * Update process.py * change solver.py --- iOpt/solver.py | 4 +++ problems/shekel.py | 2 +- problems/shekel4.py | 2 +- problems/stronginc5.py | 2 +- problems/xsquared.py | 2 +- .../method/loadProgress/test_load_progress.py | 36 +++++++++++++++++++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/iOpt/solver.py b/iOpt/solver.py index 62d188ae..e7613496 100644 --- a/iOpt/solver.py +++ b/iOpt/solver.py @@ -114,6 +114,10 @@ def load_progress(self, file_name: str) -> None: Solver.check_parameters(self.problem, self.parameters) self.process.load_progress(file_name=file_name) + if (self.problem.number_of_discrete_variables > 0): + self.process.method.iterations_count = self.process.search_data.get_count() - (len(self.method.GetDiscreteParameters(self.problem)) + 1 ) #-2 + else: self.process.method.iterations_count = self.process.search_data.get_count() - 2 + def refresh_listener(self) -> None: """ Метод оповещения наблюдателей о произошедшем событии diff --git a/problems/shekel.py b/problems/shekel.py index 6c0bc36f..37e6fdb6 100644 --- a/problems/shekel.py +++ b/problems/shekel.py @@ -22,7 +22,7 @@ def __init__(self, function_number: int): :param functionNumber: номер задачи в наборе, :math:`1 <= functionNumber <= 1000` """ super(Shekel, self).__init__() - self.name = Shekel + self.name = "Shekel" self.dimension = 1 self.number_of_float_variables = self.dimension self.number_of_discrete_variables = 0 diff --git a/problems/shekel4.py b/problems/shekel4.py index 2e871df4..aa62886f 100644 --- a/problems/shekel4.py +++ b/problems/shekel4.py @@ -22,7 +22,7 @@ def __init__(self, function_number: int): :param functionNumber: номер задачи в наборе, :math:`1 <= functionNumber <= 3` """ super(Shekel4, self).__init__() - self.name = Shekel4 + self.name = "Shekel4" self.dimension = 4 self.number_of_float_variables = self.dimension self.number_of_discrete_variables = 0 diff --git a/problems/stronginc5.py b/problems/stronginc5.py index a8ca155c..f8f5a0b4 100644 --- a/problems/stronginc5.py +++ b/problems/stronginc5.py @@ -13,7 +13,7 @@ def __init__(self): Конструктор класса Stronginc5 problem. """ super(Stronginc5, self).__init__() - self.name = 'Stronginc5' + self.name = "Stronginc5" self.dimension: int = 5 self.number_of_float_variables = self.dimension self.number_of_discrete_variables = 0 diff --git a/problems/xsquared.py b/problems/xsquared.py index 0a99758e..5d9d0cdf 100644 --- a/problems/xsquared.py +++ b/problems/xsquared.py @@ -12,7 +12,7 @@ class XSquared(Problem): def __init__(self, dimension: int): super(XSquared, self).__init__() - self.name = XSquared + self.name = "XSquared" self.dimension = dimension self.number_of_float_variables = dimension self.number_of_discrete_variables = 0 diff --git a/test/iOpt/method/loadProgress/test_load_progress.py b/test/iOpt/method/loadProgress/test_load_progress.py index 410f29a8..a6a19318 100644 --- a/test/iOpt/method/loadProgress/test_load_progress.py +++ b/test/iOpt/method/loadProgress/test_load_progress.py @@ -53,6 +53,42 @@ def test_Rastrigin2(self): if os.path.isfile(path): os.remove(path) + def test_RastriginInt(self): + self.problem = RastriginInt(5, 2) + self.params = SolverParameters(r=2.5, eps=0.01, iters_limit=50, refine_solution=False) + self.solver = Solver(self.problem, parameters=self.params) + self.sol50 = self.solver.solve() + self.solver.save_progress('RastriginInt_50.json') + + self.params = SolverParameters(r=2.5, eps=0.01, iters_limit=100, refine_solution=False) + self.solver = Solver(self.problem, parameters=self.params) + self.solver.load_progress('RastriginInt_50.json') + self.sol50_100 = self.solver.solve() + self.solver.save_progress('RastriginInt_50_100.json') + + self.params = SolverParameters(r=2.5, eps=0.01, iters_limit=100, refine_solution=False) + self.solver = Solver(self.problem, parameters=self.params) + self.sol100 = self.solver.solve() + self.solver.save_progress('RastriginInt_100.json') + + self.params = SolverParameters(r=2.5, eps=0.01, iters_limit=100, refine_solution=False) + self.solver = Solver(self.problem, parameters=self.params) + self.sol100_ns = self.solver.solve() + + with open('RastriginInt_50_100.json') as json_file: + data1 = json.load(json_file) + + with open('RastriginInt_100.json') as json_file: + data2 = json.load(json_file) + + self.assertEqual(self.sol50_100.best_trials, self.sol100_ns.best_trials) + self.assertEqual(data1, data2) + + pathlist = ['RastriginInt_50.json', 'RastriginInt_50_100.json', 'RastriginInt_100.json'] + for path in pathlist: + if os.path.isfile(path): + os.remove(path) + def test_GKLS(self): self.problem = GKLS(3, 2)