cplex sos 类型 1 添加

cplex sos type 1 add

所以只有一个简单的问题 - 我正在尝试在 CPLEX 中实现 SOS 类型 1 问题。

当我查看文档时,我看到了添加函数

add(self, type='1', SOS=SparsePair(ind = [0], val = [0.0]), name='')
Adds a special ordered set constraint to the problem.

在此处找到 https://www.ibm.com/support/knowledgecenter/en/SSSA5P_12.7.0/ilog.odms.cplex.help/refpythoncplex/html/cplex._internal._subinterfaces.SOSInterface-class.html#add

当我查看文档时,我了解除了 val 之外的所有内容。我对这个 SOS1 问题的想法是,你实际上是在添加约束(假设所有变量都是二进制 {0,1},即所有变量的总和小于或等于 1。也就是说,要么所有变量都是0 或者最多有一个 1。那么既然它是一个总和,那么 val 权重都是 1?它会是什么?我提到这个是因为我找到了一段源代码,它使这些权重为 25,18,如下所示

def setproblemdata(p):
    p.objective.set_sense(p.objective.sense.maximize)

    p.linear_constraints.add(rhs=[20.0, 30.0, 0.0], senses="LLE")

    obj = [1.0, 2.0, 3.0, 1.0]
    lb = [0.0, 0.0, 0.0, 2.0]
    ub = [40.0, cplex.infinity, cplex.infinity, 3.0]
    cols = [[[0, 1], [-1.0, 1.0]],
            [[0, 1, 2], [1.0, -3.0, 1.0]],
            [[0, 1], [1.0, 1.0]],
            [[0, 2], [10.0, -3.5]]]

    p.variables.add(obj=obj, lb=lb, ub=ub, columns=cols,
                    types="CIII", names=["0", "1", "2", "3"])
    p.SOS.add(type="1", SOS=[["2", "3"], [25.0, 18.0]])

    p.order.set([(1, 8, p.order.branch_direction.up),
                 ("3", 7, p.order.branch_direction.down)])
    p.order.write("mipex3.ord")

    return

让我引用 CPLEX documentation

Members of an SOS should be given unique weights that in turn define the order of the variables in the set. (These unique weights are also called reference row values.) Each of those ways of declaring SOS members allows you to specify weights.