Topic
  • 7 replies
  • Latest Post - ‏2013-06-20T04:40:06Z by DanielJunglas
Stasik
Stasik
1 Post

Pinned topic NullPointerException while adding an objective

‏2012-05-03T20:52:57Z |
Hi, I got the following:



//init cplex IloCplex cplex = 

new IloCplex(); cplex.setParam(IloCplex.IntParam.Threads, 1); 
//is commodity k,l routed over i and j 
//x ijkl IloIntVar[] x = cplex.boolVarArray(inst.getSize()*inst.getSize()*inst.getSize()*inst.getSize()); 

for (

int i = 0; i < x.length; i++) 
{ x[i] = cplex.boolVar(); 
}   
//is node a hub IloIntVar[] y = cplex.boolVarArray(inst.getSize()); 

for (

int i = 0; i < y.length; i++) 
{ y[i] = cplex.boolVar(); 
}   
//=== FITTNESS FUNCTION === IloLinearNumExpr expr = cplex.linearNumExpr(); 
//first big sum 

for(

int k=0;k<inst.getSize();k++)
{ 

for(

int i=0;i<inst.getSize();i++) 
{ 

for(

int j=0;j<inst.getSize();j++) 
{ 

for(

int l=0;l<inst.getSize();l++) 
{ expr.addTerm(c[i][j][k][l], x[Static.quadToLinear(i, j, k, l, inst.getSize())]); 
} 
} 
} 
} 
//second sum 

for(

int i=0;i<inst.getSize();i++) 
{ expr.addTerm(inst.getFixed(i), y[i]); 
} 
//minimise it cplex.addMinimize(expr);


this snippet crashed in the last line

Exception in thread 
"main" java.lang.NullPointerException at ilog.cplex.CpxNumVar.unmark(CpxNumVar.java:296) at ilog.cplex.CpxLinearExpr.unmarkVars(CpxLinearExpr.java:402) at ilog.cplex.CpxLinearExpr.removeDuplicates(CpxLinearExpr.java:515) at ilog.cplex.CpxLinearExpr.removeDuplicates(CpxLinearExpr.java:489) at ilog.cplex.CpxObjective.setExpr(CpxObjective.java:108) at ilog.cplex.CpxObjective.<init>(CpxObjective.java:362) at ilog.cplex.IloCplexModeler.objective(IloCplexModeler.java:706) at ilog.cplex.IloCplexModeler.addObjective(IloCplexModeler.java:768) at ilog.cplex.IloCplexModeler.addMinimize(IloCplexModeler.java:790) at ExactSolver.main(ExactSolver.java:69)


The interesting part is that crashes start at larger values of inst.getSize(), for 20 and 25 it works as expected, for 40 there is a crash...

Please help me.
Updated on 2012-05-05T06:27:55Z at 2012-05-05T06:27:55Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    754 Posts

    Re: NullPointerException while adding an objective

    ‏2012-05-05T06:27:55Z  
    Is it possible that you are close to the memory limit when this exception occurs?
    Could you run your code through a debugger and see if an OutOfMemoryError or some other exception was thrown right before the NullPointerException occurs?
  • Chris122334441324134
    3 Posts

    Re: NullPointerException while adding an objective

    ‏2013-06-18T14:34:23Z  
    Is it possible that you are close to the memory limit when this exception occurs?
    Could you run your code through a debugger and see if an OutOfMemoryError or some other exception was thrown right before the NullPointerException occurs?

    I have the same problem. Here is the stack trace:

    Thread [main] (Suspended (exception NullPointerException)) 
     owns: Class<T> (ilog.cplex.CpxLinearExpr) (id=180) 
     CpxLinearNumExpr(CpxLinearExpr).unmarkVars() line: 392 
     CpxLinearExpr.removeDuplicates(CpxLinearExpr) line: 506 
     CpxLinearNumExpr(CpxLinearExpr).removeDuplicates() line: 478 
     CpxObjective.setExpr(IloNumExpr) line: 119 
     Subproblem.setObjective(MasterProblem) line: 305 

     

    No OutOfMemoryError appeared before. Any help?
     

  • DanielJunglas
    DanielJunglas
    137 Posts

    Re: NullPointerException while adding an objective

    ‏2013-06-18T14:49:43Z  

    I have the same problem. Here is the stack trace:

    Thread [main] (Suspended (exception NullPointerException)) 
     owns: Class<T> (ilog.cplex.CpxLinearExpr) (id=180) 
     CpxLinearNumExpr(CpxLinearExpr).unmarkVars() line: 392 
     CpxLinearExpr.removeDuplicates(CpxLinearExpr) line: 506 
     CpxLinearNumExpr(CpxLinearExpr).removeDuplicates() line: 478 
     CpxObjective.setExpr(IloNumExpr) line: 119 
     Subproblem.setObjective(MasterProblem) line: 305 

     

    No OutOfMemoryError appeared before. Any help?
     

    What version of CPLEX do you use?

    When you say that no OutOfMemoryError appeared: did you check this with a debugger or was it just that no such error appeared in your program? In older versions of CPLEX this NullPointerException may have appeared when CPLEX tried to recover from an OutOfMemoryError. In these cases you would not see the OutOfMemoryError in your application.

  • Chris122334441324134
    3 Posts

    Re: NullPointerException while adding an objective

    ‏2013-06-18T15:33:35Z  

    What version of CPLEX do you use?

    When you say that no OutOfMemoryError appeared: did you check this with a debugger or was it just that no such error appeared in your program? In older versions of CPLEX this NullPointerException may have appeared when CPLEX tried to recover from an OutOfMemoryError. In these cases you would not see the OutOfMemoryError in your application.

    Version: 12.2

    I checked with a debugger, break point on caught and uncaught exceptions (OutOfMemoryError), there were none

    Should not be a memory issue. I used the same models for bigger instances.

    Updated on 2013-06-18T15:38:41Z at 2013-06-18T15:38:41Z by Chris122334441324134
  • DanielJunglas
    DanielJunglas
    137 Posts

    Re: NullPointerException while adding an objective

    ‏2013-06-19T14:12:05Z  

    Version: 12.2

    I checked with a debugger, break point on caught and uncaught exceptions (OutOfMemoryError), there were none

    Should not be a memory issue. I used the same models for bigger instances.

    That is an old version of CPLEX you are using. Any chance you can upgrade so something more recent (like 12.5.0.1)?

    Could you show us your complete code? If not here then maybe directly to me: daniel(dot)junglas(at)de(dot)ibm(dot)com.

  • Chris122334441324134
    3 Posts

    Re: NullPointerException while adding an objective

    ‏2013-06-19T15:06:15Z  

    That is an old version of CPLEX you are using. Any chance you can upgrade so something more recent (like 12.5.0.1)?

    Could you show us your complete code? If not here then maybe directly to me: daniel(dot)junglas(at)de(dot)ibm(dot)com.

    Yes I can update. I resolved the error in the meantime though. Null Pointer Exception was in fact corret, as I was really adding a null variable to the expression. Just wondering why the Exception is not thrown at 

    expression.addTerm(Double, null);

    THX for the answers!

    expression.addTerm(coefficientX,

  • DanielJunglas
    DanielJunglas
    137 Posts

    Re: NullPointerException while adding an objective

    ‏2013-06-20T04:40:06Z  

    Yes I can update. I resolved the error in the meantime though. Null Pointer Exception was in fact corret, as I was really adding a null variable to the expression. Just wondering why the Exception is not thrown at 

    expression.addTerm(Double, null);

    THX for the answers!

    expression.addTerm(coefficientX,

    addTerm(double coef, IloNumVar var) just stores var in a container for later use, it does not check for null. That is why the exception is "delayed".