From 4aeb3fefae35970b83514bbc641281fc7e7ba395 Mon Sep 17 00:00:00 2001 From: Scriptbash <98601298+Scriptbash@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:55:41 -0400 Subject: [PATCH] Write OSTRICH algorithm settings --- qraven/modules/calibration/ostrich.py | 94 ++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/qraven/modules/calibration/ostrich.py b/qraven/modules/calibration/ostrich.py index e25d707..13fbd77 100644 --- a/qraven/modules/calibration/ostrich.py +++ b/qraven/modules/calibration/ostrich.py @@ -303,6 +303,7 @@ def write_input_file(self, dlg): int_params, real_params = self.export_calibration_values(dlg) response_vars = self.get_response_var(dlg) gcop_settings = self.get_gcop_settings(dlg) + algorithm_settings = self.get_algorithm_settings(dlg) self.create_rvp_template(dlg, int_params, real_params) with open(output_file, 'w') as ostin: @@ -370,6 +371,66 @@ def write_input_file(self, dlg): ostin.write(str(value).ljust(20)) ostin.write('\nEndGCOP\n') + if algorithm_settings: + algorithm = dlg.combo_programtype.currentText() + if algorithm == 'BisectionAlgorithm': + tag = 'BisectionAlg' + elif algorithm == 'Fletcher-Reeves': + tag = 'FletchReevesAlg' + elif algorithm == 'Levenberg-Marquardt' or algorithm == 'GML-MS': + tag = 'LevMar' + elif algorithm == 'GridAlgorithm': + tag = 'GridAlg' + elif algorithm == 'Powell': + tag = 'PowellAlg' + elif algorithm == 'Steepest-Descent': + tag = 'SteepDescAlg' + elif algorithm == 'ParticleSwarm': + tag = 'ParticleSwarm' + elif algorithm == 'APPSO': + tag = 'APPSO' + elif algorithm == 'BEERS': + tag = 'BEERS' + elif algorithm == 'BinaryGeneticAlgorithm' or algorithm == 'GeneticAlgorithm': + tag = 'GeneticAlg' + elif algorithm == 'SimulatedAnnealing' or algorithm == 'DiscreteSimulatedAnnealing' or \ + algorithm == 'VanderbiltSimulatedAnnealing': + tag = 'SimulatedAlg' + elif algorithm == 'DDS': + tag = 'DDSAlg' + elif algorithm == 'ParallelDDS': + tag = 'ParallelDDSAlg' + elif algorithm == 'DiscreteDDS': + tag = 'DiscreteDDSAlg' + elif algorithm == 'ShuffledComplexEvolution': + tag = 'SCEUA' + elif algorithm == 'SamplingAlgorithm': + tag = 'SamplingAlg' + elif algorithm == 'DDSAU': + tag = '_DDSAU_Alg' + elif algorithm == 'GLUE': + tag = 'GLUE' + elif algorithm == 'MetropolisSampler': + tag = 'MetropolisSampler' + elif algorithm == 'RejectionSampler': + tag = 'RejectionSampler' + elif algorithm == 'PADDS': + tag = 'PADDSAlg' + elif algorithm == 'ParaPADDS': + tag = 'ParallelPADDSAlg' + elif algorithm == 'SMOOTH': + tag = 'SMOOTH' + + ostin.write('\nBegin' + tag) + for line in algorithm_settings: + ostin.write('\n ') + for value in line: + if value == 'UseParamValues': + pass + else: + ostin.write(str(value).ljust(30)) + ostin.write('\nEnd' + tag + '\n') + def get_basic_config_params(self, dlg): program_type = dlg.combo_programtype.currentText() @@ -686,7 +747,7 @@ def set_algorithm_settings(self, dlg): 'DiscreteSimulatedAnnealing': simulatedalg, 'VanderbiltSimulatedAnnealing': simulatedalg, 'Levenberg-Marquardt': levmar, - 'GML-MS':'', + 'GML-MS': levmar2, 'Powell': powellalg, 'Steepest-Descent': steepdescalg, 'Fletcher-Reeves ': fletchreevesalg, @@ -812,3 +873,34 @@ def get_gcop_settings(self, dlg): if tmp_settings[0] == 'PenaltyFunction': gcop_settings.append(tmp_settings) return gcop_settings + + def get_algorithm_settings(self, dlg): + table = dlg.table_ost_algorithm + rows = table.rowCount() + cols = table.columnCount() + tmp_algorithm_settings = [] + + for row in range(rows): + tmp_settings = [] + for col in range(cols): + current_widget = table.cellWidget(row, col) + if isinstance(current_widget, QLabel): + tmp_settings.append(current_widget.text()) + elif isinstance(current_widget, QLineEdit): + tmp_settings.append(current_widget.text()) + elif isinstance(current_widget, QComboBox): + tmp_settings.append(current_widget.currentText()) + tmp_algorithm_settings.append(tmp_settings) + + algorithm_settings = [] + remove_next = False + # Skips the "ShapingFactor" parameter if the LikelihoodType is Stedinger + for row in tmp_algorithm_settings: + if remove_next: + remove_next = False + continue + if 'Stedinger' in row: + remove_next = True + algorithm_settings.append(row) + + return algorithm_settings