Originally posted by: SystemAdmin
I am trying to use CPLEX to model a particular problem and then test for a series of conditions after I have solved my model. For some reason I am getting a NullPointerException. I have created a test example that demonstrates this problem (see below). When I run the same example using CP Optimizer it does not throw any Exception and I get the correct answer.
Is this a issue with the CPLEX solver or are there some configuration parameters I am not setting?
Respectfully,
Alex
CPLEX 12.1 Code:
import ilog.concert.IloException;
import ilog.concert.IloIntVar;
import ilog.cplex.IloCplex;
public class Test {
public static void main(String[] _args) throws IloException {
IloCplex cplex=new IloCplex();
IloIntVar a=cplex.intVar(1,Integer.MAX_VALUE);
cplex.add(a);
if (cplex.solve()) {
System.out.println("a="+cplex.getValue(a));
System.out.println("t="+cplex.getValue(cplex.ge(a,0)));
}
}
};
Output:
Tried aggregator 1 time.
MIP Presolve eliminated 0 rows and 1 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec.
a=1.0
Exception in thread "main" java.lang.NullPointerException
at ilog.cplex.CpxNumVar.getVarIndexValue(CpxNumVar.java:268)
at ilog.cplex.EvalVisitor.visitNumVar(EvalVisitor.java:32)
at ilog.cplex.CpxNumVar.accept(CpxNumVar.java:68)
at ilog.cplex.IloCplex.getValue(IloCplex.java:6083)
at Test.main(Test.java:13)
IBM ILOG CPLEX Teaching Edition.
CP Optimizer 2.3 Code:
import ilog.concert.IloException;
import ilog.concert.IloIntVar;
import ilog.cp.IloCP;
public class Test {
public static void main(String[] _args) throws IloException {
IloCP cp=new IloCP();
IloIntVar a=cp.intVar(1,Integer.MAX_VALUE);
cp.add(a);
if (cp.solve()) {
System.out.println("a="+cp.getValue(a));
System.out.println("t="+cp.getValue(cp.ge(a,0)));
}
}
};
Output:
! ----------------------------------------------------------------------------
! Satisfiability problem - 1 variable, 0 constraints
! Initial process time : 0.00s (0.00s extraction + 0.00s propagation)
! . Log search space : 31.0 (before), 31.0 (after)
! . Memory usage : 315.4 Kb (before), 315.4 Kb (after)
! ----------------------------------------------------------------------------
! Branches Non-fixed Branch decision
* 1 0.00s _int0 = 1
! ----------------------------------------------------------------------------
! Solution status : Terminated normally, solution found
! Number of branches : 1
! Number of fails : 0
! Total memory usage : 348.2 Kb (331.4 Kb CP Optimizer + 16.8 Kb Concert)
! Time spent in solve : 0.00s (0.00s engine + 0.00s extraction)
! Search speed (br. / s) : 100.0
! ----------------------------------------------------------------------------
a=1.0
t=1.0
#CPLEXOptimizers#DecisionOptimization