oemof / oemof-solph

A model generator for energy system modelling and optimisation (LP/MILP).
https://oemof.org
MIT License
282 stars 124 forks source link

Investment limit AttributeError if storage investment only #1076

Open kbrcke opened 1 month ago

kbrcke commented 1 month ago

Hi,

I have an energy system built with oemof solph that comprises amongst other things an three energy storages implemented like this:

_storage = GenericStorage(
            label="STORAGE"+str(i),
            inputs={stor_bus: Flow()},
            outputs={stor_bus: Flow()},
            balanced=True,
            investment=Investment(ep_costs=10)
        )_

es.add(storage)

I want the three energy storages to share an investment limit and implemented this using solph.constraints like this:

model = Model(es)
solph.constraints.investment_limit(model, limit=100)

When solving the system, i get the following error message: AttributeError: 'InvestmentFlowBlock' object has no attribute 'investment_costs'

This only occurs when no flow in the system has an investment assigned to it. My current workaround is to assign at least one investment into flows but with ep_costs = 0. However, I guess this is a solph bug, I wanted to report here.

Cheers, Karo

p-snft commented 1 month ago

Yes, this is a bug. The constraint just assumes that every Investment{Type}Block has investment_costs if it exists. However, this is not the case. My suggested solution would be to follow that assumption and create the variable during initialisation of the InvestmentFlowBlock.