CPLEX C++演唱技术中模型的约束去除

CPLEX C++演唱技术中模型的约束去除,c++,cplex,C++,Cplex,我有一个约束集 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 - C

我有一个约束集

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不工作。在这种情况下,如何使用ILORAGEMARRAY PROTECTIONNV执行此操作

在添加到模型之前,需要通过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.exportModelmodel.lp在添加和删除约束后将模型导出到文件,并检查约束是否已删除

如果强化[t][j]不依赖于u,为什么需要第三个循环?使用t*强化[t][j]会更容易吗?或者这是个错误,这是个错误。这是那个时期的总和。现在我已经改变了。请帮我回答。非常感谢先生的帮助