Christian
Christian

Reputation: 1460

CPLEX sets variable with zero objective coefficient to positive value

I need to stop CPLEX from doing that and do not know how.

The model is solved multiple times in an iterative procedure. In each iteration the objective changes. Hence, I checked the model and solution of the previous iteration and found that x had a negative coefficient then and was set to positive value. I conclude that this behavior must be related to some warm start of CPLEX.

How can that be prevented?

I rather not add the variables with positive coefficients to the objective because there are many.

Here is an example in 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

Upvotes: 1

Views: 1250

Answers (1)

michiruf
michiruf

Reputation: 423

Try

cplex.setParam(IloCplex.Param.Advance, 0);

Upvotes: 2

Related Questions