Add costs to objective function

Hallo everyone,

For my research, I set up an energy system model with multiple sectors. I am still quite new to OEMOF and need help for my problem.

After setting up my energysystem, I created additional model constraints by adding Pyomo blocks with the constraints and additional variable. This works fine for me.
Now I have the situation that one of these variables causes costs that must be summed to the total costs. In summary I have this model:

New variable with constraint and costs:
Var_new = Var_model1 + Var_model2

C_new = Var_new*c_new

New total costs:
minimize(C_total,new) = minimize(C_total + C_new).

Question:
How can I include these new costs in my model objective function?
Creating additional blocks could be a solution, but I was thinking of a simpler way by just adding costs to the objective function (also with the view that creating additional blocks might not work in all cases).

I hope my problem was understandable and that you could help me.

Best, Matthias

1 Like

Hi Matthias,

Sadly I do not have an answer, as I am new to OEMOF too. But I have the same question, so I want to share my interest in case you find a solution or if someone else can share it with us (if it exists).

Best wishes, Mauricio.

Dear Matthias,

the oemof.solph Model is an extende pyomo.Concrete Model. We store the objective function at: model.objective. The attribute objective is a pyomo Expression, which means you can simply add any such Expression to it.

expr = sum(model.you_variable[i,o,t] * your_costs[t] for i,o in model.YOUINDEX for t in model.TIMESTEPS)
model.objective += expr 
model.solve()

I can not be more specific, as I don’t now what the name of your variable and its index is. I assumed that you have a timeindex and something like the oemof flow logic (from, to)…
Hope this helps!

Thank you a lot. This is exactly what I needed.
I did not know that it can be done by simple pyomo expression addition.

Best, Matthias