炼钢厂发现了被打破的约束。我想向用户展示他们的模型的实际冲突的详细信息。
因此,我想把矩阵的每个约束分解成不同的约束。左撇子和右撇子。示例:
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];
}我稍微更新了它,以拆分约束(请注意: IBMs示例大量使用约束数组的索引。所有这些位置都需要更新)
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发布于 2019-01-31 01:38:34
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");https://stackoverflow.com/questions/54440825
复制相似问题