Apologies in advance if this is simple - which I suspect it is - as I've searched and failed to find an example of this!
I am constructing an energy system dispatch model in Pyomo, and have a version of this running. I am defining a new variable, "SystemShortRunMarginalCost", which should be defined as the maximum of "ActiveShortRunMarginalCostByGenerator", as follows:
def SystemShortRunMarginalCost_rule(model,h):
max(model.ActiveShortRunMarginalCostByGenerator[g,h] for g in model.GeneratorName) == SystemShortRunMarginalCost[h]
model.SystemShortRunMarginalCostHourly = Constraint(model.Hour, rule=SystemShortRunMarginalCost_rule)
Is there some basic syntax I'm missing here? I get the following error message:
ERROR: Rule failed when generating expression for constraint
SystemShortRunMarginalCostHourly with index 1: NameError: name
'SystemShortRunMarginalCost' is not defined
ERROR: Constructing component 'SystemShortRunMarginalCostHourly' from
data=None failed:
NameError: name 'SystemShortRunMarginalCost' is not defined
[ 0.10] Pyomo Finished
ERROR: Unexpected exception while running model:
name 'SystemShortRunMarginalCost' is not defined
Thanks.
UPDATED
So I have now added amended the objective function as suggested, and amended the constraint code as follows:
def SystemShortRunMarginalCost_rule(model,g,h):
return SystemShortRunMarginalCost[h] >= model.ActiveShortRunMarginalCostByGenerator[g,h]
model.SystemShortRunMarginalCostHourly = Constraint(model.GeneratorName, model.Hour, rule=SystemShortRunMarginalCost_rule)
I now get a different error, as follows:
ERROR: Rule failed when generating expression for constraint
SystemShortRunMarginalCostHourly with index ('Wind1', 1): NameError: name
'SystemShortRunMarginalCost' is not defined
ERROR: Constructing component 'SystemShortRunMarginalCostHourly' from
data=None failed:
NameError: name 'SystemShortRunMarginalCost' is not defined
[ 0.11] Pyomo Finished
ERROR: Unexpected exception while running model:
name 'SystemShortRunMarginalCost' is not defined
I have solved this problem by post-processing the Pyomo results to calculate the marginal SRMC and average cost outputs. My original question was trying to acquire these outputs by creating new variables in the Pyomo problem itself, but that proved challenging, as noted above. I'm still not 100% sure whether that was possible or not, but post-processing in my VBA code (which I've used to convert the JSON output from Pyomo to a CSV format) has worked just fine!