我用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();
}
发布于 2019-01-26 05:05:24
为了设置约束名,应该使用IloRange。例如,您可以从代码片段中替换以下行:
mod.add(not_more_than_one <= 1);
通过以下方式:
IloRange cons(env, not_more_than_one, 1, "name of the constraint");
model.add(cons);
https://stackoverflow.com/questions/54378485
复制相似问题