diff --git a/iOpt/method/method.py b/iOpt/method/method.py index e8bc57f..ec56b10 100644 --- a/iOpt/method/method.py +++ b/iOpt/method/method.py @@ -142,6 +142,7 @@ def first_iteration(self, calculator: Calculator = None) -> list[SearchDataItem] if calculator is None: for item in items: self.calculate_functionals(item) + self.update_optimum(item) else: calculator.calculate_functionals_for_items(items) diff --git a/iOpt/method/mixed_integer_method.py b/iOpt/method/mixed_integer_method.py index 528f778..7fa7959 100644 --- a/iOpt/method/mixed_integer_method.py +++ b/iOpt/method/mixed_integer_method.py @@ -140,6 +140,7 @@ def first_iteration(self, calculator: Calculator = None) -> list[SearchDataItem] if calculator is None: for item in items: self.calculate_functionals(item) + self.update_optimum(item) else: calculator.calculate_functionals_for_items(items) @@ -246,7 +247,8 @@ def calculate_m(self, curr_point: SearchDataItem, left_point: SearchDataItem) -> else: other_point = None break - if other_point is not None and other_point.get_index() >= 0: + if other_point is not None and other_point.get_index() >= 0 \ + and other_point.get_discrete_value_index() == curr_point.get_discrete_value_index(): # print(index) m = abs(other_point.function_values[index].value - curr_point.get_z()) / \ self.calculate_delta(other_point, curr_point, self.dimension) @@ -262,7 +264,8 @@ def calculate_m(self, curr_point: SearchDataItem, left_point: SearchDataItem) -> other_point = None break - if other_point is not None and other_point.get_index() >= 0: + if other_point is not None and other_point.get_index() >= 0 \ + and other_point.get_discrete_value_index() == curr_point.get_discrete_value_index(): m = max(m, abs(curr_point.get_z() - other_point.function_values[index].value) / \ self.calculate_delta(curr_point, other_point, self.dimension)) diff --git a/iOpt/solver.py b/iOpt/solver.py index b1c2396..1bf4c48 100644 --- a/iOpt/solver.py +++ b/iOpt/solver.py @@ -60,6 +60,7 @@ def solve(self) -> Solution: solv_with_timeout = timeout(seconds=self.parameters.timeout * 60)(self.process.solve) try: solv_with_timeout() + sol = self.get_results() except Exception as exc: print(exc) sol = self.get_results() diff --git a/iOpt/solver_parametrs.py b/iOpt/solver_parametrs.py index d4fb5a0..a62b09f 100644 --- a/iOpt/solver_parametrs.py +++ b/iOpt/solver_parametrs.py @@ -15,7 +15,8 @@ def __init__(self, refine_solution: bool = False, start_point: Point = [], number_of_parallel_points: int = 1, - timeout: int = -1 + timeout: int = -1, + proportion_of_global_iterations: float = 0.95 ): r""" Конструктор класса SolverParameters @@ -34,12 +35,14 @@ def __init__(self, :param start_point: точка начального приближения к решению. :param number_of_parallel_points: число параллельно вычисляемых испытаний. :param timeout: ограничение на время вычислений в минутах. + :param proportion_of_global_iterations: доля глобальных итераций в поиске при использовании локальном метода """ self.eps = eps self.r = r self.iters_limit = iters_limit + self.proportion_of_global_iterations = proportion_of_global_iterations if refine_solution: - self.global_method_iteration_count = int(self.iters_limit * 0.95) + self.global_method_iteration_count = int(self.iters_limit * self.proportion_of_global_iterations) self.local_method_iteration_count = self.iters_limit - self.global_method_iteration_count else: self.global_method_iteration_count = self.iters_limit @@ -51,3 +54,4 @@ def __init__(self, self.start_point = start_point self.number_of_parallel_points = number_of_parallel_points self.timeout = timeout +