Example #1
0
class Output(TestCase):
    # solve test problem
    config = mb.get_config('test_model_config.json')
    instance = mb.build_instance(config)
    conn = di.get_sqlite_connection()
    lookup = dv.LookupTables(conn)
    opt = pe.SolverFactory("glpk")
    instance.Cost.deactivate()
    instance.Environmental_Cost_Impact.deactivate()
    opt.solve(instance)

    def test_get_sets_frame(self):
        sets_df = mo.get_sets_frame(self.instance)
        self.assertGreater(len(sets_df), 0)

    def test_get_entity(self):
        # output the variables with and without units
        for v in self.instance.component_objects(pe.Var):
            v_dfr = mo.get_entity(v)
            self.assertIsInstance(v_dfr, pd.DataFrame)
            if len(v_dfr) > 0:
                self.assertGreater(len(v_dfr), 0)
            u_dfr = mo.get_entity(v, self.lookup, units=True)
            self.assertIsInstance(u_dfr, pd.DataFrame)
            if len(u_dfr) > 0:
                self.assertGreater(len(u_dfr), 0)

        # name the unit set for lookup
        flow_dfr = mo.get_entity(self.instance.Flow, self.lookup, units=['P_m'])
        self.assertGreater(len(flow_dfr), 0)

    def test_objectives(self):
        # do the optimisation for each objective
        for i, o in enumerate(self.instance.component_objects(pe.Objective)):
            for j, oo in enumerate(self.instance.component_objects(pe.Objective)):
                if i == j:
                    oo.activate()
                else:
                    oo.deactivate()
            opt = pe.SolverFactory("glpk")
            opt.solve(self.instance)
            o_dfr = mo.get_entity(o)
            self.assertGreater(len(o_dfr), 0)
            ou_dfr = mo.get_entity(o, self.lookup, units=True)
            self.assertGreater(len(ou_dfr), 0)

    def test_get_onset_names(self):
        l = list()
        for o in chain(self.instance.component_objects(pe.Var), self.instance.component_objects(pe.Param)):
            sets = mo.get_onset_names(o)
            l.append(sets)
        self.assertGreater(len(sets), 0)
Example #2
0
class TestLookupTables(TestCase):
    conn = di.get_sqlite_connection()
    lookup = dv.LookupTables(conn)

    def test_get(self):
        pm = self.lookup.get('P_m')
        self.assertEqual(pm.shape[1], 2)
        kpi = self.lookup.get('KPI')
        self.assertEqual(kpi.shape[1], 3)

    def test_get_single_column(self):
        pm = self.lookup.get_single_column('P_m')
        self.assertEqual(pm.shape[1], 1)
Example #3
0
    def test_model_solve(self):

        setting = mqu.system_settings(testing=True)
        config_path = setting['config_path'].joinpath('Lemon_Toy_Model.json')
        config = mb.get_config(config_path)
        instance = mb.build_instance(config)

        # get lookups from db
        conn = di.get_sqlite_connection()
        lookup = dv.LookupTables(conn)

        # setup a model run
        model_solve = ms.ModelSolve(lookup)
        model_solve.concrete_model = instance
        model_solve.resize(800, 600)
        model_solve.show()

        # run the model
        QTest.mouseClick(model_solve.run_button, Qt.LeftButton)

        if 'IGNORE_EXEC' not in os.environ:
            app.exec()

        self.assertIsInstance(model_solve, ms.ModelSolve)
Example #4
0
config_path = setting['config_path'].joinpath('Lemon_Toy_Model.json')
config = mb.get_config(config_path)
spec = mb.create_specification(config['specification'])
instance = mb.build_instance(config)
for i, obj in enumerate(instance.component_objects(pe.Objective)):
    # activate first objective
    if i == 0:
        obj.activate()
    else:
        obj.deactivate()
opt = pe.SolverFactory("glpk")
opt.solve(instance)

# get lookups from db
conn = di.get_sqlite_connection()
lookup = dv.LookupTables(conn)


class ModelViewManagerTest(TestCase):
    def test_init(self):

        # setup a model viewer
        model_view_manager = mv.ModelViewManager(lookup, spec)
        model_view_manager.concrete_model = instance

        model_view_manager.resize(800, 600)
        model_view_manager.show()

        if 'IGNORE_EXEC' not in os.environ:
            app.exec()