CPLEX 将系数为零 objective 的变量设置为正值

CPLEX sets variable with zero objective coefficient to positive value

我需要阻止 CPLEX 这样做,但不知道如何做。

模型在迭代过程中求解多次。在每次迭代中,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);