コード例 #1
0
 def test_create_tree_expr(self):
     ui_data = UIData(model=self.m)
     # Make a tree with constraints
     data_model = ComponentDataModel(parent=None,
                                     ui_data=ui_data,
                                     components=(Expression, ),
                                     columns=["name", "value"])
     # There should be one root item
     assert (len(data_model.rootItems) == 1)
     assert (data_model.rootItems[0].data == self.m)
     # The children should be in the model construction order,
     # and the indexes are sorted
     children = data_model.rootItems[0].children
     assert (children[0].data == self.m.b1)
     assert (children[0].children[0].data == self.m.b1.e1)
     ui_data.calculate_expressions()
     # Check the data display role The rows in the tree should be:
     #   0. Model
     #     0. b1,
     #       0. e1, value
     root_index = data_model.index(0, 0)
     b1_index = data_model.index(0, 0, parent=root_index)
     e1_index0 = data_model.index(0, 0, parent=b1_index)
     e1_index1 = data_model.index(0, 1, parent=b1_index)
     assert (data_model.data(e1_index0) == "b1.e1")
     assert (abs(data_model.data(e1_index1) - 3.0) < 0.0001)
コード例 #2
0
 def test_create_tree_con(self):
     ui_data = UIData(model=self.m)
     # Make a tree with constraints
     data_model = ComponentDataModel(parent=None,
                                     ui_data=ui_data,
                                     components=(Constraint, ),
                                     columns=["name", "active"])
     # There should be one root item
     assert (len(data_model.rootItems) == 1)
     assert (data_model.rootItems[0].data == self.m)
     # The children should be in the model construction order,
     # and the indexes are sorted
     children = data_model.rootItems[0].children
     assert (children[0].data == self.m.b1)
     assert (children[1].data == self.m.c1)
     assert (children[2].data == self.m.c2)
     # Check the data display role The rows in the tree should be:
     #   0. Model
     #     0. c1, True
     #     1. c2, True
     #     2. b1, True
     root_index = data_model.index(0, 0)
     assert (data_model.data(root_index) == "tm")
     idx = data_model.index(0, 0, parent=root_index)
     assert (data_model.data(idx) == "b1")
     idx = data_model.index(0, 1, parent=root_index)
     assert (data_model.data(idx) == True)
     idx = data_model.index(1, 0, parent=root_index)
     assert (data_model.data(idx) == "c1")
     idx = data_model.index(2, 0, parent=root_index)
     assert (data_model.data(idx) == "c2")
コード例 #3
0
 def test_expr_calc(self):
     cdi = ComponentDataItem(parent=None,
                             ui_data=UIData(model=self.m),
                             o=self.m.b1.e1)
     cdi.ui_data.calculate_expressions()
     self.assertAlmostEqual(cdi.get("value"), 3)
     self.assertIsInstance(cdi.get("expr"), str)  # test get expr str
コード例 #4
0
ファイル: test_data_model_item.py プロジェクト: vova292/pyomo
 def test_cons_calc_upper_div0(self):
     cdi = ComponentDataItem(
         parent=None, ui_data=UIData(model=self.m), o=self.m.c8)
     cdi.ui_data.calculate_constraints()
     # the ui lists the upper and lower attributes as ub and lb
     # this was originally so I could easily combine variables and
     # constarints in the same view, but I split them up, so may want
     # to reconsider that choise in the future. This is to remind myself
     # why I'm getting "ub" and not "upper"
     self.assertEqual(cdi.get("ub"), "Divide_by_0")
コード例 #5
0
    def test_update_tree_expr(self):
        ui_data = UIData(model=self.m)
        # Make a tree with constraints
        data_model = ComponentDataModel(parent=None,
                                        ui_data=ui_data,
                                        components=(Expression, ),
                                        columns=["name", "value"])

        self.m.newe = Expression(expr=self.m.x[0] + self.m.x[1])

        data_model._update_tree()

        # There should be one root item
        assert (len(data_model.rootItems) == 1)
        assert (data_model.rootItems[0].data == self.m)
        # The children should be in the model construction order,
        # and the indexes are sorted
        children = data_model.rootItems[0].children
        assert (children[0].data == self.m.b1)
        assert (children[0].children[0].data == self.m.b1.e1)
        ui_data.calculate_expressions()
        # Check the data display role The rows in the tree should be:
        #   0. Model
        #     0. b1,
        #       0. e1, value
        root_index = data_model.index(0, 0)
        b1_index = data_model.index(0, 0, parent=root_index)
        e1_index0 = data_model.index(0, 0, parent=b1_index)
        e1_index1 = data_model.index(0, 1, parent=b1_index)
        assert (data_model.data(e1_index0) == "b1.e1")
        assert (abs(data_model.data(e1_index1) - 3.0) < 0.0001)
        # Check that in the update the new expression was added
        found = False
        for i in children:
            if id(i.data) == id(self.m.newe):
                found = True
                break
        assert (found)
コード例 #6
0
ファイル: ui.py プロジェクト: vova292/pyomo
    def __init__(self, *args, **kwargs):
        model = self.model = kwargs.pop("model", None)
        main = self.model = kwargs.pop("main", None)
        self.testing = kwargs.pop("testing", False)
        flags = kwargs.pop("flags", 0)
        self.ui_data = UIData(model=model)
        super(MainWindow, self).__init__(*args, **kwargs)
        self.setupUi(self)
        self.setCentralWidget(self.mdiArea)

        self._refresh_list = []
        self.variables = None
        self.constraints = None
        self.expressions = None
        self.parameters = None
        self.residuals = None

        self.update_model()

        self.ui_data.updated.connect(self.update_model)
        # Set menu actions (remember the menu items are defined in the ui file)
        # you can edit the menus in qt-designer
        self.actionModel_Selector.triggered.connect(self.show_model_select)
        self.ui_data.exec_refresh.connect(self.refresh_on_execute)
        self.actionRestart_Variable_View.triggered.connect(
            self.variables_restart)
        self.actionRestart_Constraint_View.triggered.connect(
            self.constraints_restart)
        self.actionRestart_Parameter_View.triggered.connect(
            self.parameters_restart)
        self.actionRestart_Expression_View.triggered.connect(
            self.expressions_restart)
        self.actionRestart_Residual_Table.triggered.connect(
            self.residuals_restart)
        self.actionInformation.triggered.connect(self.model_information)
        self.actionCalculateConstraints.triggered.connect(
            self.ui_data.calculate_constraints)
        self.actionCalculateExpressions.triggered.connect(
            self.ui_data.calculate_expressions)
        self.actionTile.triggered.connect(self.mdiArea.tileSubWindows)
        self.actionCascade.triggered.connect(self.mdiArea.cascadeSubWindows)
        self.actionTabs.triggered.connect(self.toggle_tabs)
        self._dialog = None  #dialog displayed so can access it easier for tests
        self._dialog_test_button = None  # button clicked on dialog in test mode
        self.mdiArea.setViewMode(QMdiArea.TabbedView)
コード例 #7
0
 def test_create_tree_var(self):
     ui_data = UIData(model=self.m)
     # Defaults to variables and two columns name and value
     data_model = ComponentDataModel(parent=None, ui_data=ui_data)
     # There should be one root item
     assert (len(data_model.rootItems) == 1)
     assert (data_model.rootItems[0].data == self.m)
     # The children should be in the model construction order,
     # and the indexes are sorted
     children = data_model.rootItems[0].children
     assert (children[0].data == self.m.z)
     assert (children[1].data == self.m.x)
     assert (children[2].data == self.m.b1)
     # Check the data display role The rows in the tree should be:
     #   0. Model
     #     0. z
     #       0. z[0], 2
     #       1. z[1], 2
     #       2. z[2], 2
     #    1. x
     #       0. x[0], 2
     #       1. x[1], 1
     #    2. b1
     root_index = data_model.index(0, 0)
     assert (data_model.data(root_index) == "tm")
     zidx = data_model.index(0, 0, parent=root_index)
     assert (data_model.data(zidx) == "z")
     xidx = data_model.index(1, 0, parent=root_index)
     assert (data_model.data(xidx) == "x")
     b1idx = data_model.index(2, 0, parent=root_index)
     assert (data_model.data(b1idx) == "b1")
     idx = data_model.index(0, 0, parent=zidx)
     assert (data_model.data(idx) == "z[0]")
     idx = data_model.index(0, 1, parent=zidx)
     assert (abs(data_model.data(idx) - 2.0) < 0.0001)
     idx = data_model.index(1, 0, parent=zidx)
     assert (data_model.data(idx) == "z[1]")
     idx = data_model.index(1, 1, parent=zidx)
     assert (abs(data_model.data(idx) - 2.0) < 0.0001)
コード例 #8
0
 def test_cons_calc(self):
     cdi = ComponentDataItem(parent=None,
                             ui_data=UIData(model=self.m),
                             o=self.m.c3)
     cdi.ui_data.calculate_constraints()
     self.assertAlmostEqual(cdi.get("residual"), 2)
コード例 #9
0
 def test_expr_calc_value_None(self):
     cdi = ComponentDataItem(parent=None,
                             ui_data=UIData(model=self.m),
                             o=self.m.b1.e3)
     cdi.ui_data.calculate_expressions()
     self.assertIsNone(cdi.get("value"))
コード例 #10
0
 def test_expr_calc_div0(self):
     cdi = ComponentDataItem(parent=None,
                             ui_data=UIData(model=self.m),
                             o=self.m.b1.e2)
     cdi.ui_data.calculate_expressions()
     self.assertEqual(cdi.get("value"), "Divide_by_0")
コード例 #11
0
 def test_cons_calc_value_None(self):
     cdi = ComponentDataItem(parent=None,
                             ui_data=UIData(model=self.m),
                             o=self.m.c7)
     cdi.ui_data.calculate_constraints()
     self.assertIsNone(cdi.get("value"))
コード例 #12
0
 def test_cons_calc_div0(self):
     cdi = ComponentDataItem(parent=None,
                             ui_data=UIData(model=self.m),
                             o=self.m.c4)
     cdi.ui_data.calculate_constraints()
     self.assertEqual(cdi.get("value"), "Divide_by_0")