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
question from:https://stackoverflow.com/questions/66052604/pyomo-defining-a-variable-using-a-maximum-of-other-variables