Пример #1
0
    def test_bus_to_sink_outputs_in_results_dataframe(self):
        bus = Bus(uid="bus")
        source = FS(uid="source", outputs=[bus], val=[0.5], out_max=[1])
        sink = Sink(uid="sink", inputs=[bus], val=[1])

        es = self.es
        om = OM(es)
        es.results = om.results()
        es.results[bus][sink] = [0.7]
        rdf = RDF(energy_system=es)
        try:
            eq_(rdf.loc[(slice(None), slice(None), slice(None), "sink"), :
                       ].val[0],
                0.7,
                "Output from bus to sink does not have the correct value.")
        except KeyError:
            self.failed = True
        if self.failed:
            ok_(False,
                "Output from bus to sink does not appear in results dataframe.")

        es.results[bus][bus] = [-1]
        rdf = RDF(energy_system=es)
        try:
            eq_(rdf.loc[(slice(None), slice(None), slice(None), "sink"), :
                       ].val[0],
                0.7,
                "Output from bus to sink does not have the correct value.")
        except KeyError:
            self.failed = True
        if self.failed:
            ok_(False,
                "Output from bus (with duals) to sink " +
                "does not appear in results dataframe.")
Пример #2
0
    def optimize(self, om=None):
        """Start optimizing the energy system using solph.

        Parameters
        ----------
        om : :class:`OptimizationModel <oemof.solph.optimization_model.OptimizationModel>`, optional
            The optimization model used to optimize the :class:`EnergySystem`.
            If not given, an :class:`OptimizationModel
            <oemof.solph.optimization_model.OptimizationModel>` instance local
            to this method is created using the current :class:`EnergySystem`
            instance as an argument.
            You only need to supply this if you want to observe any side
            effects that solving has on the `om`.

        Returns
        -------
        self : :class:`EnergySystem`
        """
        if om is None:
            om = OM(energysystem=self)

        om.solve(solver=self.simulation.solver, debug=self.simulation.debug,
                 verbose=self.simulation.verbose,
                 duals=self.simulation.duals,
                 solve_kwargs=self.simulation.solve_kwargs)

        self.results = om.results()
        return self
    def optimize(self):

        if self.optimization_model is None:
            self.optimization_model = OM(energysystem=self)

        self.optimization_model.solve(
            solver=self.simulation.solver, debug=self.simulation.debug, tee=self.simulation.stream_solver_output
        )
Пример #4
0
    def test_issue_74(self):
        Storage.optimization_options.update({'investment': True})
        bus = Bus(uid="bus")
        store = Storage(uid="store", inputs=[bus], outputs=[bus], c_rate_out=0.1,
                        c_rate_in=0.1)
        sink = Sink(uid="sink", inputs=[bus], val=[1])

        es = self.es
        om = OM(es)
        om.objective.set_value(-1)
        es.results = om.results()

        try:
            es.dump()
        except AttributeError as ae:
            self.failed = ae
        if self.failed:
            ok_(False,
                "EnergySystem#dump should not raise `AttributeError`: \n" +
                " Error message: " + str(self.failed))
class EnergySystem:
    r"""
    """

    def __init__(self, **kwargs):
        ""
        for attribute in ["regions", "entities", "simulation"]:
            setattr(self, attribute, kwargs.get(attribute, {}))
        self.optimization_model = kwargs.get("optimization_model", None)

    # TODO: Condense signature (use Buse)
    def connect(self, code1, code2, media, in_max, out_max, eta, transport_class):
        ""
        if not transport_class == transport.Simple:
            raise (
                TypeError(
                    "Sorry, `EnergySystem.connect` currently only works with"
                    + "a `transport_class` argument of"
                    + str(transport.Simple)
                )
            )
        for reg_out, reg_in in [(code1, code2), (code2, code1)]:
            logging.debug("Creating simple {2} from {0} to {1}".format(reg_out, reg_in, transport_class))
            uid = "_".join([reg_out, reg_in, media])
            self.connections[uid] = transport_class(
                uid=uid,
                outputs=[self.regions[reg_out].buses["_".join(["b", reg_out, media])]],
                inputs=[self.regions[reg_in].buses["_".join(["b", reg_in, media])]],
                out_max={"_".join(["b", reg_out, media]): out_max},
                in_max={"_".join(["b", reg_in, media]): in_max},
                eta=[eta],
            )

    def optimize(self):

        if self.optimization_model is None:
            self.optimization_model = OM(energysystem=self)

        self.optimization_model.solve(
            solver=self.simulation.solver, debug=self.simulation.debug, tee=self.simulation.stream_solver_output
        )
buses = [bcoal, bgas, boil, blig, b_el, b_th]

# group components
transformers = [pp_coal, pp_lig, pp_gas, pp_oil, pp_chp]
renew_sources = [pv, wind_on]
sinks = [demand_th, demand_el]

components = transformers + renew_sources + sinks
entities = components + buses

simulation = es.Simulation(solver='glpk', timesteps=timesteps,
                           stream_solver_output=True,
                           objective_name='minimize_costs')
energysystem = es.EnergySystem(entities=entities, simulation=simulation)

om = OptimizationModel(energysystem=energysystem)

om.solve(solver='gurobi', debug=True, tee=True, duals=False)
pp.results_to_objects(om)

components = transformers + renew_sources


if __name__ == "__main__":
    def plot_dispatch(bus_to_plot):
        # plotting: later as multiple pdf with pie-charts and topology?
        import numpy as np
        import matplotlib as mpl
        import matplotlib.cm as cm

        plot_data = renew_sources+transformers
Пример #7
0
                         out_max=[40, 30],
                         eta=[0.4, 0.3], opex_fix=0, opex_var=50,
                         co2_var=em_gas)

# group busses
buses = [bcoal, bgas, boil, blig, b_el, b_th]

# group components
transformers = [pp_coal, pp_lig, pp_gas, pp_oil, pp_chp]
renew_sources = [pv, wind_on]
sinks = [demand_th, demand_el]

components = transformers + renew_sources + sinks
entities = components + buses

om = OptimizationModel(energysystem=energy_system)
#
om.solve(solve_kwargs={'tee':True,
                       'keepfiles':False},
         solver_cmdline_options={'min':''})
energy_system.results = om.results()

es_df = tpd.EnergySystemDataFrame(energy_system=energy_system)

# plot
es_df.plot_bus(bus_uid="b_el", bus_type="el", type="input",
               date_from="2012-01-01 00:00:00",
               date_to="2012-01-31 00:00:00", kind='bar',
               title="January 2016", xlabel="Power in MW",
               ylabel="Date", tick_distance=24*7,
               df_plot_kwargs={'stacked':True ,'width':1, 'lw':0.2})
Пример #8
0
        else:
            Regions.connect(ebus_from,
                            ebus_export,
                            in_max=capacity,
                            out_max=capacity,
                            eta=eta_trans,
                            transport_class=transport.Simple)
##############################################################################

############################### FINAL STEPS ##################################
# change uid tuples to strings
for entity in Regions.entities:
    entity.uid = str(entity.uid)

# create optimisation model from Regions instance
om = OptimizationModel(energysystem=Regions)

# add constraints
constraints = hlsb.get_constraint_values(conn_oedb, scenario)
Export_Regions = ('MV', 'ST', 'SN', 'KJ', 'BE')
hlsb.add_constraint_export_minimum(om, Export_Regions, constraints)
hlsb.add_constraint_import_berlin(om, constraints)
hlsb.add_constraint_co2_emissions(om, co2_emissions, constraints)
hlsb.add_constraint_entities_BE(om)

# write LP file
#om.write_lp_file()
# solve problem
om.solve()
# save results to Regions instance
Regions.results = om.results()
Пример #9
0
# demand
demand_el = sink.Simple(uid="demand_el", inputs=[b_el],
                        val=[30, 10, 20, 40, 45, 50, 35, 25, 5, 12])

# Simple Transformer for b_el
pp_coal = transformer.Simple(uid='pp_lig', inputs=[bcoal], outputs=[b_el],
                            in_max=[None],
                            out_max=[10], eta=[0.41],
                            opex_fix=2, opex_var=40)
pp_gas = transformer.Simple(uid='pp_gas', inputs=[bgas], outputs=[b_el],
                            in_max=[None], out_max=[41], eta=[0.45],
                            opex_var=40)

# create optimization model
om = OptimizationModel(energysystem=energy_system)

#
energy_system.optimize(om)

#
# use outputlib to plot
esplot = tpd.DataFramePlot(energy_system=energy_system)
esplot.slice_unstacked(bus_uid="b_el", type="input")
esplot.plot(title="January 2016 Low coal costs",
            stacked=True,
            width=1, lw=0.1,
            kind='bar')
plt.show()

# update variable costs and objective, solve again!