【问题标题】:How do we delete a batch of constraints in docplex?我们如何在 docplex 中删除一批约束?
【发布时间】:2021-01-06 13:29:45
【问题描述】:

我使用了约束编号列表或约束名称列表,但这不适用于命令 m.remove_constraints()。

m.add(sumbs[i]

A.append("ct_sum_%d" %i)

然后当我想更改模型时:m.remove_constraints(A)

这样做的正确方法是什么?

【问题讨论】:

    标签: python-3.x cplex docplex


    【解决方案1】:

    Model.add_constraints() 返回新添加的约束列表。

    同样,Model.remove_constraints 采用约束对象的集合,而不是 names ,而不是索引。例如:

    cts = mdl.add_constraints(...)
    mdl.remove_constraints(cts[:3]) # remove the first three
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2021-08-03
      • 2012-12-16
      • 2019-02-04
      • 2013-11-05
      相关资源
      最近更新 更多