Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The output of the optimal solution in problems with restrictions has … #180

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/Stronginc3_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

from problems.stronginc3 import Stronginc3
from iOpt.solver import Solver
from iOpt.solver_parametrs import SolverParameters


from iOpt.output_system.listeners.console_outputers import ConsoleOutputListener

if __name__ == "__main__":
"""
Минимизация тестовой функции Стронгина с тримя ограничениями
"""

problem = Stronginc3()

# Формируем параметры решателя
params = SolverParameters(r=2.5, eps=0.01, iters_limit=500)

# Создаем решатель
solver = Solver(problem=problem, parameters=params)

# Добавляем вывод результатов в консоль
cfol = ConsoleOutputListener(mode='result')
solver.add_listener(cfol)

# Решение задачи
sol = solver.solve()

val = problem.calculate(sol.best_trials[0].point, sol.best_trials[0].function_values[3])
2 changes: 1 addition & 1 deletion iOpt/method/index_method_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def calculate_functionals(self, point: SearchDataItem) -> SearchDataItem:
point = self.task.calculate(point, i)
point.set_z(point.function_values[i].value)
point.set_index(i)
if point.get_z() < 0:
if point.get_z() > 0:
return point
point.function_values[number_of_constraints] = FunctionValue(FunctionType.OBJECTIV, 0)
point = self.task.calculate(point, number_of_constraints)
Expand Down
4 changes: 2 additions & 2 deletions iOpt/output_system/outputers/console_outputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def print_best_point_info(self, solution, iters):
else:
best_trial_point = solution.best_trials[0].point.float_variables
best_trial_d_point = solution.best_trials[0].point.discrete_variables
best_trial_value = solution.best_trials[0].function_values[0].value
best_trial_value = solution.best_trials[0].function_values[self.problem.number_of_constraints].value
self.__functions.print_best(
solution.number_of_global_trials,
solution.number_of_local_trials,
Expand All @@ -72,7 +72,7 @@ def print_best_point_info(self, solution, iters):
def print_final_result_info(self, solution: Solution, status: bool):
best_trial_point = solution.best_trials[0].point.float_variables
best_trial_d_point = solution.best_trials[0].point.discrete_variables
best_trial_value = solution.best_trials[0].function_values[0].value
best_trial_value = solution.best_trials[0].function_values[self.problem.number_of_constraints].value
self.__functions.print_result(
status,
solution.number_of_global_trials,
Expand Down
Loading