예제 #1
0
 def planar(self, t: AlgorithmType):
     """Algorithm setup for FPlanar."""
     s = default(t)
     s.update({'max_gen': 10, 'report': 10})
     for p in [F_PLANAR, N_PLANAR]:
         alg = algorithm(t)(p, cast(Setting, s))
         alg.run()
         t_f = alg.history()
         self.assertEqual(10, t_f[1][0] - t_f[0][0])
예제 #2
0
 def case(self, alg: AlgorithmType):
     """Test with an objective function."""
     settings = {'min_fit': 1e-20, 'report': 10}
     obj = TestObj()
     s = default(alg)
     s.update(settings)
     a = algorithm(alg)(obj, s)
     ans = a.run()
     x, y = a.result()
     self.assertTrue(ans < 1e-20, f"{ans}")
     for i in range(4):
         self.assertTrue(x[i] < 1e-10)
     self.assertEqual(y, ans)
예제 #3
0
    def __init__(self, parent: MainWindowBase):
        """Reference names:

        + Iteration collections.
        + Result data.
        + Main window function references.
        """
        super(Optimizer, self).__init__(parent)
        self.setupUi(self)
        self.mech = {}
        self.path = {}
        # Some reference of 'collections'
        self.collections = parent.collections.configure_widget.collections
        self.get_collection = parent.get_configure
        self.input_from = parent.input_from
        self.output_to = parent.output_to
        self.save_reply_box = parent.save_reply_box
        self.project_no_save = parent.project_no_save
        self.merge_result = parent.merge_result
        self.update_ranges = parent.main_canvas.update_ranges
        self.set_solving_path = parent.main_canvas.set_solving_path
        self.get_zoom = parent.main_canvas.get_zoom
        self.prefer = parent.prefer
        # Data and functions
        self.mechanism_data = []
        self.alg_options = default(AlgorithmType.DE)
        # Canvas
        self.preview_canvas = PreviewCanvas(self)
        self.preview_layout.addWidget(self.preview_canvas)
        # Splitter
        self.main_splitter.setStretchFactor(0, 10)
        self.main_splitter.setStretchFactor(1, 100)
        self.canvas_splitter.setSizes([80, 100])
        self.down_splitter.setSizes([20, 80])
        # Table widget column width
        header = self.parameter_list.horizontalHeader()
        header.setSectionResizeMode(QHeaderView.ResizeToContents)
        self.algorithm_options = {}
        for opt in AlgorithmType:
            button = QRadioButton(opt.value, self)
            button.clicked.connect(self.__set_algorithm_default)
            self.algorithm_options[opt] = button
            self.algorithm_layout.addWidget(button)
        self.clear()
예제 #4
0
 def __init__(self, opt: AlgorithmType, settings: Mapping[str, _Value],
              parent: QWidget):
     """Load the settings to user interface."""
     super(AlgorithmOptionDialog, self).__init__(parent)
     self.setupUi(self)
     self.setWindowFlags(self.windowFlags()
                         & ~Qt.WindowContextHelpButtonHint)
     self.setWindowTitle(f"{opt.value} Options")
     self.opt = opt
     self.dft = {
         tag: value
         for tag, value in default(self.opt).items() if tag not in {
             'pop_num', 'report', 'max_gen', 'min_fit', 'max_time',
             'slow_down'
         }
     }
     self.__init_alg_table()
     self.alg_table.setColumnWidth(0, 200)
     self.alg_table.setColumnWidth(1, 90)
     self.__set_args(settings)
예제 #5
0
 def __reset(self) -> None:
     """Reset the settings to default."""
     self.__set_args(default(self.opt))
예제 #6
0
 def __set_algorithm_default(self) -> None:
     """Set the algorithm settings to default."""
     self.alg_options.clear()
     for opt, button in self.algorithm_options.items():
         if button.isChecked():
             self.alg_options.update(default(opt))