【发布时间】:2018-08-23 23:17:32
【问题描述】:
我希望在 Pyomo 中创建一个简单的指标变量。假设我有一个变量 x,如果 x > 0,此指标函数将取值 1,否则取值为 0。
这是我尝试过的方法:
model = ConcreteModel()
model.A = Set(initialize=[1,2,3])
model.B = Set(initialize=['J', 'K'])
model.x = Var(model.A, model.B, domain = NonNegativeIntegers)
model.ix = Var(model.A, model.B, domain = Binary)
def ix_indicator_rule(model, a, b):
return model.ix[a, b] == int(model.x[a, b] > 0)
model.ix_constraint = Constraint(model.A, model.B,
rule = ix_indicator_rule)
我收到的错误消息类似于Avoid this error by using Pyomo-provided math functions,根据this link 可以在pyomo.environ 找到...但我不知道该怎么做。我试过使用validate_PositiveValues(),像这样:
def ix_indicator_rule(model, a, b):
return model.ix[a, b] == validate_PositiveValues(model.x[a, b])
model.ix_constraint = Constraint(model.A, model.B,
rule = ix_indicator_rule)
没有运气。任何帮助表示赞赏!
【问题讨论】:
标签: pyomo