Skip to content

Commit

Permalink
Загрузка для задач с дискретными параметрами (#159)
Browse files Browse the repository at this point in the history
* Исправлена загрузка для дискретных параметров, исправлено вычисление M в mixed integer method

* Исправлены имена в задачах

* Добавлены новые задачи с ограничениями и дискретными параметрами

* Удалены задачи

* Update mixed_integer_method.py

* Update process.py

* Update process.py

* change solver.py
  • Loading branch information
YaniKolt committed Aug 3, 2023
1 parent 51e95c6 commit 71f68e8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
4 changes: 4 additions & 0 deletions iOpt/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Метод оповещения наблюдателей о произошедшем событии
Expand Down
2 changes: 1 addition & 1 deletion problems/shekel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion problems/shekel4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion problems/stronginc5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion problems/xsquared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions test/iOpt/method/loadProgress/test_load_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 71f68e8

Please sign in to comment.