Pyomo-析取编程-传递BigM后缀

时间:2018-06-22 14:24:16

标签: pyomo

我正在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值来完成此操作?

期待您的帮助。

1 个答案:

答案 0 :(得分:1)

对于线性约束,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