问题
Team Pyomo, I kindly need help with the above-stated error. I have done everything I could, but still can't get my model to work. Below is the formulation of my 'Objective Function', and screenshots of the errors message. Thank you.
Screenshot of the error from the running code at the command prompt:
回答1:
Assuming model.x
and model.d
are declared correctly with 2-D indices, the problem is that you are using double square brackets. The correct way to access a particular index is model.x[i,j]
.
Here are the correct ways to declare model.x
, model.d
, and model.a
.
Assuming model.a
is two dimensional:
model.a = Set(initialize=[(1,1),(1,2),(2,1),(2,2)])
model.d = Param(model.a, default=0)
model.x = Var(model.a)
def _obj_rule(m):
return sum(m.d[i,j]*m.x[i,j] for i,j in m.a)
model.obj = Objective(rule=_obj_rule)
Assuming model.a
is one dimensional:
model.a = Set(initialize=[1,2,3])
model.d = Param(model.a,model.a,default=0)
model.x = Param(model.a,model.a)
def _obj_rule(m):
return sum(m.d[i,j]*m.x[i,j] for i in m.a for j in m.a)
model.obj = Objective(rule=_obj_rule)
Notice that either model.a
is declared as two dimensional or model.x
and model.d
are indexed by model.a
twice. Also notice the slight differences in how the sum in the objective is written.
来源:https://stackoverflow.com/questions/48198946/error-constructing-component-objective-from-data-none-failed-typeerror-flo