Issue
double valorFuncionObjetivo = 0;
IloCplex cplex = new IloCplex();
IloNumVar[][][] x = new IloNumVar[Map.NumPersM][Map.NumHrsM][Map.NumTrab];
for (int i = 0; i < Map.NumPersM; i++) {
for (int j = 0; j < Map.NumHrsM; j++) {
for (int k = 0; k < Map.NumTrab; k++) {
x[i][j][k] = cplex.boolVar();
}
}
}
IloLinearNumExpr funcion_objetivo = cplex.linearNumExpr();
for (int j = 0; j < Map.NumHrsM; j++) {
for (int k = 0; k < Map.NumTrab; k++) {
for (int i = 0; i < Map.NumPersM; i++) {
funcion_objetivo.addTerm(x[i][j][k],Map.Demandas[j][k].Prioridad);
}
funcion_objetivo.setConstant(-(Map.Demandas[j][k].Prioridad)*Map.Demandas[j][k].Min_personas);
}
}
cplex.addMinimize( funcion_objetivo);
Restricciones(Map, cplex, x);
cplex.setParam(IloCplex.Param.MIP.Display, 0);
if (cplex.solve()) {
valorFuncionObjetivo = cplex.getValue(funcion_objetivo);
System.out.println("Valor de la funcion objetivo: " + valorFuncionObjetivo);
} else {
System.out.println("No tiene soluciĆ³n");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void Restricciones(Mapa Map, IloCplex cplex, IloNumVar[][][] x) {
try {
for (int i = 0; i < Map.NumPersM; i++) {
IloLinearNumExpr expr1 = cplex.linearNumExpr();
for (int j = 0; j < Map.NumHrsM; j++) {
for (int k=0; k < Map.NumTrab; k++) {
expr1.addTerm(1, x[i][j][k]);
}
}
if(Map.Personas[i].Tipo_contrato == 1) {
cplex.addEq(expr1, Map.Turnos[1].Horas_turno-1);
}
else {
cplex.addEq(expr1, Map.Turnos[3].Horas_turno);
}
}... //there are more constraints
I'm using cplex in java. I just implemented a program that I have proved first in cplex and runs ok. But I'm trying to implement it in java and it doesn't work well,it says the objetive value is zero and LP Presolve eliminated 96 rows and 0 columns: this is de console answer:
Established Conexion
Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de2ae
CPXPARAM_MIP_Display 0
Tried aggregator 1 time.
LP Presolve eliminated 96 rows and 0 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec. (0.01 ticks)
Valor de la funcion objetivo: 0.0
Solution
You mentioned that you, "proved first in cplex". I think this means that you have run a model file using the CPLEX interactive. Or, perhaps you have used the OPL IDE. Either way, I find that the easiest way to fix issues like this is to export both models to LP format and compare them. In your Java program you can do this by adding the following line of code just before calling the solve
method:
cplex.exportModel("test.lp");
See the documentation here.
Answered By - rkersh