Closed CROdominik closed 7 months ago
This should do the trick:
import pyomo.core as pyo
import calliope
model = calliope.Model(...)
model.run(build_only=True)
model._backend_model.dual = pyo.Suffix(direction=pyo.Suffix.IMPORT)
model2 = model.backend.rerun()
then:
print ("Duals")
for c in model._backend_model.component_objects(pyo.Constraint, active=True):
print (" Constraint",c)
for index in c:
print (" ", index, model._backend_model.dual[c[index]])
Doing this in a cleaner way should be considered in discussing #293
Available in v0.7 of #540
Problem description
Obtaining duals is useful in linear optimization problems in order to know e.g. the marginal generation price in a specific timestep. Gurobi has the attribute 'Pi' for this purpose and Pyomo has a pyo.Suffix attribute. Right now, Calliope itself cannot print out duals. Knowing marginal prices at specific timesteps is also very useful for coupling Calliope with different models, and linking of different models is becoming more and more important topic in the energy modelling. The problem is that when I tried to interact with Pyomo, I couldn't obtained the duals as it threw an error.
Steps to reproduce the problem
Any Calliope model:
And then I want to print the duals with the following:
I get the following error:
Alternatively, when I try to print out a specific dual variables via:
I get the error:
Calliope version
Version 0.6.4