Pyomo - 析取编程 - 传递 BigM 后缀
Pyomo - Disjunctive Programming - Passing a BigM Suffix
我正在 Pyomo 中实现析取编程问题。在析取中,我有非凸非线性约束。因此我不能直接使用 BigM 转换。我必须传递带有 bigM 值的后缀。这是我的代码片段:
m = ConcreteModel()
m.Block1 = Block()
#... Here some variables and other constraints are defined.
# Defining the rule for the disjunct:
def _d(disjunct, flag):
m = disjunct.parent_block()
if flag:
# Here 2 constraints are valid
disjunct.c1 = Constraint(expr=x1==0)
disjunct.c2 = Constraint(expr=x2==0)
else:
# Here 7 constraints are valid
disjunct.c1 = Constraint(expr=y1==0)
disjunct.c2 = Constraint(expr=y2==0)
disjunct.c3 = Constraint(expr=y3==0)
...
# Define the disjunct:
m.Block1.d1 = Disjunct([0,1], rule=_d)
# Define the disjunction
def _c1(model):
return [model.d1[0], model.d1[1]]
m.Block1.c1 = Disjunction(rule=_c1)
# Applying the transformation:
TransformationFactory('gdp.bigm').apply_to(m)
我必须为 bigM 传递后缀,但不知道该怎么做。另外,对于不同的约束,如何使用不同的 bigM 值来做到这一点?
期待您的帮助。
对于线性约束,Pyomo 可以自动为您计算出合适的 big-M 值。对于非线性约束,您需要添加:
m.BigM = Suffix(direction=Suffix.LOCAL)
m.BigM[m.Block1.d1[0].c1] = your_value_here
请注意,还可以使用不同的方式来表达析取,这可能会让您更轻松。如果我想清楚,我个人最喜欢选项 2,如果我想更简洁,我个人最喜欢选项 3:http://pyomo.readthedocs.io/en/latest/modeling_extensions/gdp.html
我正在 Pyomo 中实现析取编程问题。在析取中,我有非凸非线性约束。因此我不能直接使用 BigM 转换。我必须传递带有 bigM 值的后缀。这是我的代码片段:
m = ConcreteModel()
m.Block1 = Block()
#... Here some variables and other constraints are defined.
# Defining the rule for the disjunct:
def _d(disjunct, flag):
m = disjunct.parent_block()
if flag:
# Here 2 constraints are valid
disjunct.c1 = Constraint(expr=x1==0)
disjunct.c2 = Constraint(expr=x2==0)
else:
# Here 7 constraints are valid
disjunct.c1 = Constraint(expr=y1==0)
disjunct.c2 = Constraint(expr=y2==0)
disjunct.c3 = Constraint(expr=y3==0)
...
# Define the disjunct:
m.Block1.d1 = Disjunct([0,1], rule=_d)
# Define the disjunction
def _c1(model):
return [model.d1[0], model.d1[1]]
m.Block1.c1 = Disjunction(rule=_c1)
# Applying the transformation:
TransformationFactory('gdp.bigm').apply_to(m)
我必须为 bigM 传递后缀,但不知道该怎么做。另外,对于不同的约束,如何使用不同的 bigM 值来做到这一点?
期待您的帮助。
对于线性约束,Pyomo 可以自动为您计算出合适的 big-M 值。对于非线性约束,您需要添加:
m.BigM = Suffix(direction=Suffix.LOCAL)
m.BigM[m.Block1.d1[0].c1] = your_value_here
请注意,还可以使用不同的方式来表达析取,这可能会让您更轻松。如果我想清楚,我个人最喜欢选项 2,如果我想更简洁,我个人最喜欢选项 3:http://pyomo.readthedocs.io/en/latest/modeling_extensions/gdp.html