Search code examples
pyomo

Pyomo error: "name 'domain' is not defined"


I have a basic electricity system model that I have built in Pyomo and has been working well. I'm now looking to make it a bit more sophisticated, adding in some additional variables, such as start costs for individual generators.

I pasted below some of the code I have added - I can provide more contextual code if required, but it is only these lines that have been added to trigger this error. The error thrown back by Pyomo is shown in quotes in the header to this query. I have deliberately left in some commenting out of lines, where I simplified the code to try to identify where the issue is. To no avail: I still get an error with the commenting out shown below:

model.StartFuelCost = Param(model.GeneratorName, model.Resource, default=0)
model.GeneratorCommitted = Var(model.GeneratorName, model.Hour, domain=Boolean, initialize=0)
model.GeneratorStart = Var(model.GeneratorName, model.Hour, domain=Boolean, initialize=0)
model.StartFuelCostByGenerator = Var(model.GeneratorName, model.Resource, model.Hour, domain=NonNegativeReals, initialize=0.0)
model.StartFuelCostTotal = Var(model.Resource, model. Hour, domain.NonNegativeReals, initialize=0.0)

...

def GeneratorCommitted_rule(model,g,h):
#    if model.Generation[g,h] > 0:
        return model.GeneratorCommitted[g,h] == 1
#    else:
#        return model.GeneratorCommitted[g,h] == 0
model.SupplyDemand_Calc2 = Constraint(model.GeneratorName, model.Hour, rule=GeneratorCommitted_rule)

# ISSUE: Either need to remove conditionality or pass info from the last time step

def GeneratorStart_rule(model,g,h):
#    if model.Hour > 1:
#        return max(0, model.GeneratorCommitted[g,h] - model.GeneratorCommitted[g,h-1]) == model.GeneratorStart[g,h]
#    else:
        return model.GeneratorCommitted[g,h] == model.GeneratorStart[g,h]
model.SupplyDemand_Calc3 = Constraint(model.GeneratorName, model.Hour, rule=GeneratorStart_rule)

def StartFuelCostByGenerator_rule(model,g,r,h):
    return model.StartFuelCost[g,r] * model.ResourcePrice[r] * model.GeneratorStart[g,h] == model.StartFuelCostByGenerator[g,r,h]
model.Costing_Calc5 = Constraint(model.GeneratorName, model.Resource, model.Hour, rule=StartFuelCostByGenerator_rule)

def StartFuelCostTotal_rule(model,r,h):
    return sum(model.StartFuelCostByGenerator[g,r,h] for g in model.GeneratorName) == model.StartFuelCostTotal[r,h]
model.Costing_Calc6 = Constraint(model.Resource, model.Hour, rule=StartFuelCostTotal_rule)

Solution

  • This is your problem:

    model.StartFuelCostTotal = Var(model.Resource, model. Hour, domain.NonNegativeReals, initialize=0.0)
    

    You have "." (dot) notation there with domain, so it is trying to figure out what this thing is that you call domain... You want to change that to an =.

    In the future, it is much easier (and you are more likely) to get help if you post the actual code with the error trace which says which line contains the error.