Originally posted by: J5JK_chao_lei
>
> What is the type of the exception you get? Could you provide the full exception message?
The whole exception message shows like:
Exception in thread
"main" java.lang.NullPointerException at ilog.cplex.CpxNumVar.getVarIndexValue(CpxNumVar.java:268) at ilog.cplex.IloCplex$MIPInfoCallback.getIndex(IloCplex.java:11624) at ilog.cplex.IloCplex$ControlCallback.getValue(IloCplex.java:13017) at MIP.BDNDP$BendersLazyConsCallback.main(BDNDP.java:45) at ilog.cplex.CpxCallback.callmain(CpxCallback.java:143) at ilog.cplex.CpxCutCallbackFunction.callIt(CpxCutCallbackFunction.java:44) at ilog.cplex.Cplex.CPXmipopt(Native Method) at ilog.cplex.CplexI.solve(CplexI.java:2291) at ilog.cplex.IloCplex.solve(IloCplex.java:9306) at MIP.BDNDP.main(BDNDP.java:458)
> Are you sure that the IloNumVar instance for which you invoke getValue()
> - is initialized (not null)
> - is part of the model that CPLEX is solving when the callback is invoked? I guess you solve a master model M and in the callback a slave model S. If you invoke the getValue(x) method of the callback then x must be contained in M. If x is only contained in S then you have to invoke the getValue() method on the IloCplex instance that solved S.
Here the code that I created the master problem:
static
void createMaster(IloModeler model, Data data, IloIntVar[][] x, IloNumVar z)
throws IloException
{
int i, j;
int numNodes = data.numNodes;
double[][] arcCost = data.arcCost;
//Create the variables z = model.numVar(-Double.MAX_VALUE, Double.MAX_VALUE); model.add(z);
for (i = 0; i < numNodes; ++i)
{
for (j = 0; j < numNodes; ++j)
{ x[i][j] = model.boolVar(); model.add(x[i][j]);
} x[i][i].setUB(0);
}
//Model the objective function IloLinearNumExpr objExpr = model.linearNumExpr(); objExpr.addTerm(z, 1.);
for (i = 0; i < numNodes; ++i)
{
for (j = 0; j < numNodes; ++j)
{ objExpr.addTerm(x[i][j], arcCost[i][j]);
}
} model.addMinimize(objExpr);
//Model the constraints
for (i = 0; i < numNodes; ++i)
{
for (j = 0; j < numNodes; ++j)
{ IloLinearNumExpr expr = model.linearNumExpr(); expr.addTerm(x[i][j], 1.); expr.addTerm(x[j][i], 1.); model.addLe(expr, 1.);
}
}
}
After this master been solved, I want to get the value of
z in
LazyConstraintCallback, however, it didn't work.
Is that right for me to define a variable
z but use it only in the objective function in CPLEX?
#DecisionOptimization#MathematicalProgramming-General