Upper funding limit - access variable from another class for new constraint in InvestmentFlowBlock

Hi everyone,
I am new to this forum so I hope that I can explain my problem in compliance with the rules here.

I want to add capex funding to each member of the NonConvex_InvestmentFlows. In the investment class of each object, I have defined a “maximum_funding” attribute that represents the maximum capex funding. Then I have included the new attribute in the “options_Investment class”. Furthermore, I have added a new binary variable to the investment_flow_block that states whether the funding may be active or not. I have then adjusted the objective expression like so:

# adjusted investment cost reduced by capex funding   
for i, o in self.NON_CONVEX_INVESTFLOWS:
    investment_costs += (
    self.invest[i, o] * ((m.flows[i, o].investment.ep_costs)-m.flows[i,o].investment.max_funding*self.funding_status[i,o])
      + self.invest_status[i, o]*self.K_status[i, o]* m.flows[i, o].investment.offset
self.investment_costs = Expression(expr=investment_costs)
return investment_costs

I have added the new attribute and the binary variable in the main code instead of just reducing the ep_costs because I want to include an upper funding limit. For that, I have written the following constraint within the Investment_Flow_Block:

# assures that funding is within limits of BEW budget of 100 Mil. €, the funding per technology can only be exactly 40% of total capex or 0
def _funding_rule(block,i,o): 
    for i, o in self.NON_CONVEX_INVESTFLOWS:
        expr+=self.invest[i, o] *(m.flows[i, o].investment.max_funding)*self.funding_status[i,o] 
    return expr <=100000000

Everything is working so far but I want to include the funding of the storage technologies in the upper funding limit as well. However, the storage class has its own objective function and the investment_costs of the storage are calculated within the GenericInvestmentStorageBlock. So far, I have added an additional binary variable in the storage class and included it in the storage objective function, too.
My problem is now to access the funding binary variable of the GenericInvestmentStorageBlock in my upper limit constraint that I have placed in the InvestmentFlowBlock. Is there a way to retrieve the binary variable from the GenericInvestmentStorageBlock and use it within the constraint? Or is there another place where I should formulate the constraint so I can access all binary variables?

I appreciate your help with this very much!



No rules here really, but I just set your programming in python code blocks rather than blockquotes. Welcome too! R

Hi @Kristina,

I don’t really get why you want to access the binary variable. Is there a maxmum number of things that can be funded regardless of the amount of funding?

Regardless of that detail, you can work with the Pyomo model and add additional constraints using that one. An example can be fund at oemof.solph.constraints.equate_variables — oemof.solph 0.5.0 documentation (oemof-solph.readthedocs.io)). I hope, that helps.


1 Like

Hi Patrik,

thanks for your reply. I have implemented the constraint as a completly new constraint file and now it works!

def funding_limit(model,name="funding_limit",upper_limit=100000000): 
    def funding_limit_rule(model):
        for i, o in model.InvestmentFlowBlock.NON_CONVEX_INVESTFLOWS:
            expr+=model.InvestmentFlowBlock.invest[i, o] *(model.flows[i, o].investment.max_funding)*model.InvestmentFlowBlock.funding_status[i,o] #attention currently the storage funding is not included
        for n in model.GenericInvestmentStorageBlock.NON_CONVEX_INVESTSTORAGES:
            expr+=model.GenericInvestmentStorageBlock.invest[n] *n.investment.max_funding*model.GenericInvestmentStorageBlock.funding_status[n]
        return expr <=upper_limit
    setattr(model,name, po.Constraint(rule=funding_limit_rule))

    return model



1 Like