Menu

Getting NullPointerException somewhere inside a call to s.minimize()

Help
2013-07-11
2015-11-09
  • Randy J. Ray

    Randy J. Ray - 2013-07-11

    I'm a fairly new choco user (and not even a very seasoned Java programmer). I've written a small program to do graph-coloring as a CP problem (as a class assignment for the Coursera class on Discrete Optimization). It works fine on most of the input data sets, but on the largest of the homework sets I get a NPE in thread "main". There is no reporting of where within minimize() this is happening. The line being reported as the source of the exception is the actual line where I call minimize:

    boolean solved = solver.minimize(solver.getVar(objective), true);
    

    Note that the NPE does not come immediately. It happens after minimize() has run a while. It's possible that it runs the full amount of time I've given it (20 minutes) before throwing the NPE, so it may be originating somewhere in the construction of the solution.

    I'm kind of at a loss as to how to trace this... the documentation on the built-in logging is rather sparse.

    I can provide the full code and input data to anyone on the choco team who wants to run it, if it would help.

    Randy

     
  • Charles Prud'homme

    Hi Randy,

    Please provide us either the entire exception trace or the full code.

    Charles

     
  • Randy J. Ray

    Randy J. Ray - 2013-07-11

    Unfortunately, the exception trace is not helpful:

    > java -Xmx8g -cp .:choco-solver-2.1.5.jar Solver -file=data/gc_1000_5
    Exception in thread "main" java.lang.NullPointerException
            at Solver.solve(Solver.java:154)
            at Solver.main(Solver.java:32)
    

    I've put the code in a gist on github: https://gist.github.com/rjray/5980271

    I've put the data-file that causes the NPE here: http://www.blackperl.com/gc_1000_5

    Call it like above, after compiling:

    > javac -cp .:choco-solver-2.1.5.jar Solver.java
    > java <heap size option> -cp .:choco-solver-2.1.5.jar Solver -file=<data>
    

    I have a 16Gb MacBook Pro, so I set the heap to 8G via -Xmx8g option. This will need significant heap, since it is creating 1001 variables and about 260000 constraints.

    Randy

     
  • Arnaud Malapert

    Arnaud Malapert - 2013-07-12

    Hello,

    solver.minimize returns a Boolean which is null because the solver did not find any solution to your problem's instance.

    BR

     
  • Randy J. Ray

    Randy J. Ray - 2013-07-12

    Are you sure? Why would it return a null rather than false? Perhaps I don't understand the auto-boxing as well as I thought...

    I'll try setting the timeout to a higher length of time and see if that makes a difference...

     
  • Arnaud Malapert

    Arnaud Malapert - 2013-07-12

    It is consistent with the following test.

    ~~~~~~~~~~
    public static void main(String[] args) {
    Boolean ob = Boolean.TRUE;
    boolean b = ob;
    System.out.println(b);
    ob = Boolean.FALSE;
    b = ob;
    System.out.println(b);
    ob = null;
    b = ob;
    }
    ~~~~~~~~~~~~

    It means that the solver is not able to decide if the problem is SAT or not.

    BR

     
  • Randy J. Ray

    Randy J. Ray - 2013-07-13

    Thanks, I went back and found the part of the docs that I hadn't read yet, which explained it like you did above. I'm just new-enough to Java that I hadn't thought about Boolean having effectively three possible return values instead of two :-).

     
  • Anonymous

    Anonymous - 2015-11-09

    Hi,
    please how can i maximize the sum of variable by choco 2.1.5
    Best regards

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.