The question is a bit self explanatory I believe, but just to give a simple example (this is not the entire model of course):
model = AbstractModel()
model.i = Set()
model.j = Set(initialize=model.i)
model.R = Param(model.i)
def lowband(model,i):
return (model.R[i],100)
model.x = Var(model.i, bounds=lowband, within=NonNegativeReals, initialize=0)
model.y = Var(model.i, bounds=lowband, within=NonNegativeReals, initialize=0)
model.W = Var( bounds=(0,100), within=NonNegativeReals, initialize=0)
model.L = Var( bounds=(0,100), within=NonNegativeReals, initialize=0)
def rule_eq1(model,i,j):
if i>j:
return (model.x[i]-model.x[j])**2+(model.y[i]-model.y[j])**2 >=(model.R[i]+model.R[j])**2
else:
return Constraint.Skip;
model.eq1 = Constraint(model.i,model.j,rule=rule_eq1)
I get really annoyed by the variable and parameter names in the constraint declarations because of the model.
part. If after each declaration we do something like:
x = model.x
y = model.y
and so on and use "x" and "y" instead of the original name, it works just fine too. However, the vast majority of pyomo models I see on the internet follow that approach of always using model.
. Is there any good reason for doing this and that I still haven't realised? I think it makes the code writing process worse and it also gets harder to read the code