我想定义三角函数,该三角函数从像这样的变量中获取值:
model.Vc = Set(initialize = Vc)
model.a = Param(model.Vc , initialize = a)
model.b = Param(model.Vc , initialize = b)
model.W = Var(model.Vc , within = PositiveReals)
model.Mu = Param(model.Vc , mutable = True)
model.alpha = Param(model.Vc , mutable = True)
def Mu_Func(model,j):
model.alpha[j] = (model.a[j] + model.b[j]) / 2
if value(model.W[j] <= model.a[j]):
return model.Mu[j] == 0
if value(model.W[j] < alpha) and value(model.W[j] >model.a[j]):
return model.Mu[j] == (model.W[j]-model.a[j])/(model.alpha[j]-model.a[j])
if value(model.W[j] == model.alpha[j]):
return model.Mu[j] == 1
if value(model.W[j] < model.b[j]) and value(model.W[j] > model.alpha[j]):
return model.Mu[j] == (model.b[j]-model.W[j]) /(model.b[j]-model.alpha[j])
if value(model.W[j] >= model.b[j]):
return model.Mu[j] == 0
model.Mu_F = Constraint(model.Vc , rule = Mu_Func)
def Obj3_rule(model):
return sum(model.Mu[j] for j in model.Vc)
但是我收到类似这样的错误
ValueError:未初始化的NumericValue对象W [1]没有值
我该如何解决这个问题?另外,当我运行不带三角函数的模型时,我得到W值:
W[1] = 480 , W[2] = 480 , W[3] = 780 , ...