I need to stop CPLEX from doing that and do not know how.
- I have a min problem and it is a MIP.
- There is a variable x with coefficient zero in the objective.
- All constraints are "less than or equal to"-constraints.
- x appears only with non-negative coefficients in the constraint matrix.
- CPLEX returns a solution where x is set to a positive value, which is strange because it does not improve the objective function value, and in the constraint matrix, x only "takes away capacity".
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