如何在C ++中命名约束

时间:2019-01-26 12:47:52

标签: c++ cplex

我已经用c ++编写了代码,然后从那里调用CPLEX来解决MILP问题。我遇到了一些错误,并且为了缩小错误的出处,我想给约束起一个不同的名字。但是,我无法获得有关如何执行此操作的任何信息。我使用IloExpr为约束创建表达式,然后将它们添加到模型中。约束之一的摘要如下所示。这里,x[i][d]是布尔决策变量。请帮助我命名此类约束。

for (i=0;i<I;i++)
    {
        IloExpr not_more_than_one (env);
        for (d=0;d<D;d++)
        {
            not_more_than_one += x[i][d];
        }
        mod.add(not_more_than_one <= 1);
        not_more_than_one.end();
    }

1 个答案:

答案 0 :(得分:-3)

要设置约束名称,您应该使用IloRange。例如,您可以从代码段中替换以下行:

mod.add(not_more_than_one <= 1);

具有:

IloRange cons(env, not_more_than_one, 1, "name of the constraint");
model.add(cons);