从cplex c ++音乐会技术中的模型中删除约束

Removing constraint from a model in cplex c++ concert tech

我有一个约束集

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) 来做到这一点。

在添加到模型并保存在容器中之前,您需要通过 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") 在添加和删除约束后将模型导出到文件,并检查是否删除了约束