diff --git a/iOpt/method/local_optimizer.py b/iOpt/method/local_optimizer.py index 61508f8..ff75cf4 100644 --- a/iOpt/method/local_optimizer.py +++ b/iOpt/method/local_optimizer.py @@ -36,7 +36,7 @@ def evaluate_function(self, y: List[float]) -> float: if self.max_calcs != -1 and self.calcs_count >= self.max_calcs: function_value.value = sys.float_info.max return function_value.value - for i in range(self.task.problem.dimension): + for i in range(self.task.problem.number_of_float_variables): if (y[i] < self.task.problem.lower_bound_of_float_variables[i]) \ or (y[i] > self.task.problem.upper_bound_of_float_variables[i]): function_value.value = sys.float_info.max diff --git a/test/test_solving_test_problems.py b/test/test_solving_test_problems.py index bfe438c..b618c74 100644 --- a/test/test_solving_test_problems.py +++ b/test/test_solving_test_problems.py @@ -1,8 +1,10 @@ import unittest import numpy as np from iOpt.problem import Problem +from iOpt.trial import Point from problems.GKLS import GKLS from problems.rastrigin import Rastrigin +from problems.rastriginInt import RastriginInt from problems.xsquared import XSquared from problems.hill import Hill from problems.shekel import Shekel @@ -15,6 +17,7 @@ from iOpt.solver_parametrs import SolverParameters + class TestSolvingProblems(unittest.TestCase): """setUp method is overridden from the parent class Rastrigin""" @@ -29,7 +32,7 @@ def checkIsSolved(self, problem: Problem, params: SolverParameters, number_of_gl sol = solver.solve() # Проверяем что найденный АГП минимумом соответствуйте априори известному, для этой задачи, с точностью eps - for j in range(problem.dimension): + for j in range(problem.number_of_float_variables): fabsx = np.abs(problem.known_optimum[0].point.float_variables[j] - sol.best_trials[0].point.float_variables[j]) fm = params.eps * (problem.upper_bound_of_float_variables[j] - @@ -38,6 +41,7 @@ def checkIsSolved(self, problem: Problem, params: SolverParameters, number_of_gl # Проверяем что на решение потребовалось правильное число итераций АГП self.assertEqual(sol.number_of_global_trials, number_of_global_trials) + return sol def test_Rastrigin_Solve(self): r = 3.5 @@ -47,6 +51,17 @@ def test_Rastrigin_Solve(self): self.checkIsSolved(problem, params, number_of_global_trials) + def test_RastriginInt_Solve(self): + r = 3.5 + problem = RastriginInt(dimension=5, number_of_discrete_variables=3) + start_point: Point = Point(float_variables=[0.5, 0.5], discrete_variables=['A', 'B', 'A']) + params = SolverParameters(r=r, eps=self.epsVal, iters_limit=100000, start_point=start_point, + number_of_parallel_points=1, refine_solution=True) + number_of_global_trials = 5678 + + sol = self.checkIsSolved(problem, params, number_of_global_trials) + self.assertEqual(sol.number_of_local_trials, 70) + def test_XSquared_Solve(self): r = 3.5 problem = XSquared(1)