【问题标题】:Removing constraint from a model in cplex c++ concert tech从 cplex c++ 音乐会技术中的模型中删除约束
【发布时间】:2016-02-10 05:43:29
【问题描述】:

我有一个约束集

for(int t = 0; t < NbPeriods; t++){
    for (int j =0; j < NbLocations; j++){
        IloExpr Ct1(env);
        for(int u = 0; u < t; u++){
            Ct1 += Fortified[u][j];
        }
        model.add(Interdicted[t][j] <= 1 - Ct1); 
    } 
}​

经过一些修改后,我必须从模型中删除这个约束集。 model.remove() 不工作。在这种情况下,我该如何使用 IloRangeArray protection(env) 来做到这一点。

【问题讨论】:

  • 如果Fortified[t][j] 不依赖于u,为什么还需要第三个循环?使用t*Fortified[t][j]会更容易吗?或者是错误的。
  • 这是一个错误。这是那个时期的总结。现在我改变了它。请帮我解答。

标签: c++ cplex


【解决方案1】:

您需要先通过IloConstraint 定义约束,然后再添加到模型并保存在容器中(例如IloConstraintArray)。 Cplex 通过名称而不是表达式从模型中删除约束。在你的情况下,

IloConstraintArray cons_array(env);
for(int t = 0; t < NbPeriods; t++){
    for (int j =0; j < NbLocations; j++){
        IloExpr Ct1(env);
        for(int u = 0; u < t; u++){
            Ct1 += Fortified[u][j];
        }
        IloConstraint cons = Interdicted[t][j] <= 1 - Ct1;
        model.add(cons); 
        cons_array.add(cons);
    } 
}​

删除

for (int i = 0; i < NbPeriods*NbLocations; i++)
     model.remove( cons_array[i] );

您也可以在添加和删除约束后使用cplex.exportModel("model.lp") 将模型导出到文件并检查约束是否已删除

【讨论】:

  • 非常感谢您的帮助
猜你喜欢
  • 2017-10-14
  • 1970-01-01
  • 1970-01-01
  • 2017-03-15
  • 2014-06-20
  • 1970-01-01
  • 2022-06-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多