cplex精简程序发现损坏的约束。我想向用户显示有关其模型实际冲突的详细信息。
因此,我希望将矩阵的每个约束拆分为单独的约束。左撇子和右撇子。示例:
10 <= x1 <= 40
应变成
10 <= x1 <= infinity
-infinity <= x1 <= 40
在数学上是相等的。
IBM关于cplex精简程序(http://www-01.ibm.com/support/docview.wss?uid=swg21429472)的示例使用以下代码来考虑约束:
for (int c1 = 0; c1 < rng.Length; c1++)
{
constraints[c1] = rng[c1];
}
我已经对其进行了少许更新,以拆分约束(请注意:IBM的示例大量使用constraints数组的索引。所有这些位置也需要更新)
for (int c1 = 0; c1 < rng.Length; c1++)
{
constraints[c1] = cplex.Ge(rng[c1].Expr, rng[c1].LB);
}
for (int c1 = 0; c1 < rng.Length; c1++)
{
constraints[rng.Length + c1] = cplex.Le(rng[c1].Expr, rng[c1].UB);
}
这是我使用的模型文件。 (显然,x1的边界与c3和c4冲突。)
Maximize
obj: x1 + 2 x2 + 3 x3
Subject To
c1: x2 + x3 <= 20
c2: x1 - 3 x2 + x3 <= 30
c3: x1 <= 40
c4: x1 >= 40
Bounds
10 <= x1 <= 10
Generals
x1 x2 x3
End
具有拆分约束的代码更新版本将打印出损坏的结果(首先显示左侧,然后显示右侧)。它仅显示x1是冲突的一部分(您自己不能是冲突。它需要一个伙伴!)
Solution status = Infeasible
Model Infeasible, Calling CONFLICT REFINER
Number of SOSs=0
IloRange : -infinity <= (1*x2 + 1*x3) <= infinity
IloRange : -infinity <= (1*x1 - 3*x2 + 1*x3) <= infinity
IloRange : -infinity <= (1*x1) <= infinity
IloRange : 40 <= (1*x1) <= infinity
IloRange : -infinity <= (1*x2 + 1*x3) <= 20
IloRange : -infinity <= (1*x1 - 3*x2 + 1*x3) <= 30
IloRange : -infinity <= (1*x1) <= 40
IloRange : -infinity <= (1*x1) <= infinity
Lower bound of x1
Upper bound of x1
Lower bound of x2
Upper bound of x2
Lower bound of x3
Upper bound of x3
Conflict Refinement process finished: Printing Conflicts
Proved : Upper bound of x1
Conflict Summary:
Constraint conflicts = 0
Variable Bound conflicts = 1
SOS conflicts = 0
Calling FEASOPT
带有双手约束的原始版本会打印出预期的结果(c4和x1是冲突的一部分)
Solution status = Infeasible
Model Infeasible, Calling CONFLICT REFINER
Number of SOSs=0
IloRange c1 : -infinity <= (1*x2 + 1*x3) <= 20
IloRange c2 : -infinity <= (1*x1 - 3*x2 + 1*x3) <= 30
IloRange c3 : -infinity <= (1*x1) <= 40
IloRange c4 : 40 <= (1*x1) <= infinity
Lower bound of x1
Upper bound of x1
Lower bound of x2
Upper bound of x2
Lower bound of x3
Upper bound of x3
Conflict Refinement process finished: Printing Conflicts
Proved : IloRange c4 : 40 <= (1*x1) <= infinity
Proved : Upper bound of x1
Conflict Summary:
Constraint conflicts = 1
Variable Bound conflicts = 1
SOS conflicts = 0
Calling FEASOPT
答案 0 :(得分:0)
RefineConflict的文档对cons
参数规定如下:
一组约束。它们可能是IRange或IAnd在 范围集。只能直接添加到模型的约束 指定。
在修改后的代码段中,您正在向constraints
数组添加尚未未添加到模型的新约束(例如,您使用Ge
方法而不是AddGe
方法。
我想您可以执行以下操作:
cplex.Remove(rng); // First remove the original constraints
for (int c1 = 0; c1 < rng.Length; c1++)
{
IRange tmp = rng[c1];
// Now, add new constraints to the model and save them in the constraints array.
constraints[c1] = cplex.AddGe(tmp.Expr, tmp.LB);
constraints[rng.Length + c1] = cplex.AddLe(tmp.Expr, tmp.UB);
}
您应在调用RefineConflict
之前添加以下行,以确保修改后的模型看起来像您期望的那样:
cplex.ExportModel("modified.lp");