I am currently working with cplex and am trying to determine the reduced cost of a LP. I am a little puzzled by the results. My current understanding of reduced cost is that it describes the amount by which a objective function coefficient must improve before a variable can be part of the solution (value = 1).
Thus all basic variables ( non-zero in the solution) have reduced costs of zero. I read that variables that are not part of the current solution can also have a reduced cost of zero if they are at one of their limits. Is that true?
The reduced cost of the following LP confuses me:
minimize 100*x1 + 3*x5
0 <= x0, x1, x2, x3, x4, x5, x6, x7, x8
x0 = 1
x0 - x1 - x2 = 0
x3 = 1
x3 - x4 = 0
x1 - x6 = 0
x2 - x7 = 0
-x4 + x5 - x8 = 0
-x5 + x6 + x7 + x8 = 0
If I use cplex to compute the reduced cost, I get the following result.
Objective Value = 3
Solution = [1, 0, 1, 1, 1, 1, 0, 1, 0]
Reduced Cost = [0 0 0 0 0 0 100 0 3]
I don't understand why the variable x1 has reduced cost of zero, it is neither part of the solution nor is it at the upper limit. Should the reduced value of x1 not be 100 as for variable x7. If I increase the value of x1 by one, I get a solution that is 100 (cost) worse, right?
Here, my C++ code:
#include <ilcplex/ilocplex.h>
int main () {
IloEnv env;
IloModel model(env);
IloNumVarArray x(env);
x.add(IloNumVar(env)); //default: between $0$ and $+\infty$
x.add(IloNumVar(env));
x.add(IloNumVar(env));
x.add(IloNumVar(env));
x.add(IloNumVar(env));
x.add(IloNumVar(env));
x.add(IloNumVar(env));
x.add(IloNumVar(env));
x.add(IloNumVar(env));
model.add(x[0] == 1);
model.add(x[0]-x[1]-x[2] == 0);
model.add(x[3] == 1);
model.add(x[3]-x[4] == 0);
model.add(x[1]-x[6] == 0);
model.add(x[2]-x[7] == 0);
model.add(-x[4]+x[5]-x[8] == 0);
model.add(-x[5]+x[6]+x[7]+x[8] == 0);
model.add(IloMinimize(env, 100*x[1] + 3*x[5]));
IloCplex cplex(model);
cplex.solve();
std::cout << "Min=" << cplex.getObjValue() << std::endl;
IloNumArray v(env);
cplex.getReducedCosts(v, x);
std::cout << v << std::endl;
env.end();
}