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)