CPLEX 将系数为零 objective 的变量设置为正值
CPLEX sets variable with zero objective coefficient to positive value
我需要阻止 CPLEX 这样做,但不知道如何做。
- 我有一个小问题,它是一个 MIP。
- 在objective.
中有一个系数为零的变量x
- 所有约束都是"less than or equal to"-约束。
- x 仅在约束矩阵中出现非负系数。
- CPLEX returns x 设置为正值的解决方案,这很奇怪,因为它没有提高 objective 函数值,并且在约束矩阵中,x只有"takes away capacity".
模型在迭代过程中求解多次。在每次迭代中,objective 都会发生变化。因此,我检查了上一次迭代的模型和解决方案,发现 x 当时系数为负,并设置为正值。我得出结论,这种行为一定与 CPLEX 的某种热启动有关。
如何预防?
我宁愿不将具有正系数的变量添加到objective,因为有很多。
下面是 Java 中的示例:
IloCplex cplex = new IloCplex();
/* Variables */
IloNumVar x = cplex.intVar(0, Integer.MAX_VALUE, "x");
/* Objectiv */
IloLinearNumExpr objExpr = cplex.linearNumExpr();
objExpr.addTerm(1.0, x);
IloObjective objective = cplex.addMaximize();
objective.setExpr(objExpr);
/* Constraints */
IloLinearNumExpr expr = cplex.linearNumExpr();
expr.addTerm(1.0, x);
cplex.addLe(expr, 2.5);
System.out.println(cplex.getModel().toString());
cplex.solve();
System.out.println("x = " + cplex.getValue(x) + "\n"); // x = 2.0
objective.clearExpr();
IloLinearNumExpr newObjexpr = cplex.linearNumExpr();
objective.setExpr(newObjexpr);
System.out.println(cplex.getModel().toString());
cplex.solve();
System.out.println("x = " + cplex.getValue(x) + "\n"); // x = 2.0
尝试
cplex.setParam(IloCplex.Param.Advance, 0);
我需要阻止 CPLEX 这样做,但不知道如何做。
- 我有一个小问题,它是一个 MIP。
- 在objective. 中有一个系数为零的变量x
- 所有约束都是"less than or equal to"-约束。
- x 仅在约束矩阵中出现非负系数。
- CPLEX returns x 设置为正值的解决方案,这很奇怪,因为它没有提高 objective 函数值,并且在约束矩阵中,x只有"takes away capacity".
模型在迭代过程中求解多次。在每次迭代中,objective 都会发生变化。因此,我检查了上一次迭代的模型和解决方案,发现 x 当时系数为负,并设置为正值。我得出结论,这种行为一定与 CPLEX 的某种热启动有关。
如何预防?
我宁愿不将具有正系数的变量添加到objective,因为有很多。
下面是 Java 中的示例:
IloCplex cplex = new IloCplex();
/* Variables */
IloNumVar x = cplex.intVar(0, Integer.MAX_VALUE, "x");
/* Objectiv */
IloLinearNumExpr objExpr = cplex.linearNumExpr();
objExpr.addTerm(1.0, x);
IloObjective objective = cplex.addMaximize();
objective.setExpr(objExpr);
/* Constraints */
IloLinearNumExpr expr = cplex.linearNumExpr();
expr.addTerm(1.0, x);
cplex.addLe(expr, 2.5);
System.out.println(cplex.getModel().toString());
cplex.solve();
System.out.println("x = " + cplex.getValue(x) + "\n"); // x = 2.0
objective.clearExpr();
IloLinearNumExpr newObjexpr = cplex.linearNumExpr();
objective.setExpr(newObjexpr);
System.out.println(cplex.getModel().toString());
cplex.solve();
System.out.println("x = " + cplex.getValue(x) + "\n"); // x = 2.0
尝试
cplex.setParam(IloCplex.Param.Advance, 0);