Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  CPLEX Error 1006: Error during callback

    Posted Tue August 27, 2019 04:39 PM

    Originally posted by: open_ball


    Hi,

    I am receiving the following error.

    Exception in thread "main" ilog.cplex.CpxException: CPLEX Error  1006: Error during callback.
    
            at ilog.cplex.CplexI.CALL(CplexI.java:4969)
            at ilog.cplex.CplexI.setStatus(CplexI.java:6301)
            at ilog.cplex.CplexI.access$500(CplexI.java:120)
            at ilog.cplex.CplexI$SolveHandle.stop(CplexI.java:2941)
            at ilog.cplex.CplexI.solve(CplexI.java:2964)
            at ilog.cplex.IloCplex.solve(IloCplex.java:10254)
    

    I intend to separate the sub problem into multiple problems. Just to explain what I am doing, I will take the TSP example provided by cplex as a reference. In Neighbor class, here are the changes I am making. Please note that I try my best to keep the example provided as small as possible.

            private static final class Neighbor {
                  private final IloCplex[] cplex;
                  private final IloNumVar[] u;
                  private IloObjective[] obj;
                  
                  public Neighbor(int size) throws IloException {
                     this.cplex = new IloCplex[size];
                     this.u = new IloNumVar[size];
                             for(int i=0; i< size ; i++) {
                                     u[i] = cplex[i].numVar(0.0, Double.POSITIVE_INFINITY,
                                         IloNumVarType.Float);
                                     this.obj[i] = cplex[i].minimize();                     
                                 cplex[i].setOut(null);
                                 cplex[i].add(u[i]);               
                                 cplex[i].add(obj[i]);
                             }
                             
                             //Create dual constraints
                             
                            public IloRange[] separate(IloNumVar[] x, IloNumVar[] estObj, double[] xSol, double[] Z) throws IloException {
                            
                            IloRange[] cut = new IloRange[size];
                            for(int i=0; i< size ; i++) {
                                     cut[i] =null;
                                     cplex[i].remove(obj[i]);                               
                            }
                            for (int i = 0; i < size; i++) { 
                            IloLinearNumExpr objExpr = cplex[i].linearNumExpr();
                            //fill objExpr
                              obj[i] = cplex[i].minimize(objExpr);
                              cplex[i].add(obj[i]);
                              cplex[i].solve();
                             IloCplex.Status status = cplex[i].getStatus();
                             IloLinearNumExpr expr = cplex[i].linearNumExpr();
                             if (status == IloCplex.Status.Optimal) {
                                     if (zMaster[i] > cplex[i].getObjValue() + 0.0001) {                               
                                // create the cut                                     
                                   cut[i] = (IloRange) cplex[i].le(estObj[i],expr);
                                    
                                     }
                             }else {
                                 // An unexpected status occurred -- report it but do nothing.
                                 System.err.println("\n!!! Unexpected subproblem solution status: "
                                                    + status + "\n");
                               }
    

    These are the changes I made and the problem occurs in the callback function. The place where I receive the exact error is;

                  // teardown
                     if (context.inThreadDown()) {                        
                             neighbors[threadNo] = null;                     
                         return;
                      }
    

    Right before the return keyword, I get the error. Can anyone help me out?


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CPLEX Error 1006: Error during callback

    Posted Tue August 27, 2019 05:03 PM

    It's hard to say what is going wrong exactly. Could it be that you're getting an ArrayIndexOutOfBounds exception from the neighbors array? I suggest that you wrap your code in the callback invoke method in a try/catch block to see if you can get specific information about the exception that is being thrown there.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CPLEX Error 1006: Error during callback

    Posted Wed August 28, 2019 03:45 PM

    Originally posted by: open_ball


    Hi,

    Thanks for the recommendation. I guess the error occurs when I try to define the variable in Neighbor class. In the constructor, after I initialize variable u,

    this.u = new IloNumVar[size];
    

    I get into the for loop and and associate each u[i] with one cplex object.

    for(int i=0; i< size ; i++) {
             u[i] = cplex[i].numVar(0.0, Double.POSITIVE_INFINITY, IloNumVarType.Float);
    

    This is the part I am receiving the error, but I am not quite sure what I am doing wrong.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CPLEX Error 1006: Error during callback

    Posted Wed August 28, 2019 04:09 PM

    Please show us the full exception message that you get from within the invoke method. Your invoke method should look something like this:

    public void invoke(IloCplex.Callback.Context context) throws IloException {
       try {
         // Your callback code here.
       } catch (Exception e) {
          System.out.println("Exception from callback: " + e);
          throw e;
       }
    }
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: CPLEX Error 1006: Error during callback

    Posted Wed August 28, 2019 04:24 PM

    Originally posted by: open_ball


    Hi,

    I get Null Pointer exception.

    Exception from callback: java.lang.NullPointerException
    Exception in thread "main" ilog.cplex.CpxException: CPLEX Error  1006: Error during callback.
    
            at ilog.cplex.CplexI.CALL(CplexI.java:4969)
            at ilog.cplex.CplexI.setStatus(CplexI.java:6301)
            at ilog.cplex.CplexI.access$500(CplexI.java:120)
            at ilog.cplex.CplexI$SolveHandle.stop(CplexI.java:2941)
            at ilog.cplex.CplexI.solve(CplexI.java:2964)
            at ilog.cplex.IloCplex.solve(IloCplex.java:1025)
    

    When I debug my code, I can see that the exception takes place here at

    u[i] = cplex[i].numVar(0.0, Double.POSITIVE_INFINITY,IloNumVarType.Float);
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: CPLEX Error 1006: Error during callback

    Posted Wed August 28, 2019 04:38 PM

    As far as I can tell, you still haven't show us the exception from within the callback, but at least you've given us a bit more information.

     

    My guess is that you haven't initialized the cplex array properly. When you create it with this.cplex = new IloCplex[size]; you get an array of null objects. You have to initialize each of those slots with new IloCplex instances, like so:

    for (int i = 0; i < size; i++) {
       cplex[i] = new IloCplex();
    }
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: CPLEX Error 1006: Error during callback

    Posted Tue September 03, 2019 03:26 PM

    Originally posted by: open_ball


    Hi Ryan,

    I did what you suggested within the callback as

    public void invoke(IloCplex.Callback.Context context) throws IloException {
       try {
         // Your callback code here.
       } catch (Exception e) {
          System.out.println("Exception from callback: " + e);
          throw e;
       }
    }
    

    and just shared the exception message that I received. 

    Anyway, you were right. Once I initialize each cplex object individually, it worked.  Would you mind explaining me why  this.cplex = new IloCplex[size]; does not initialize the cplex array properly? I'm sorry if this is more like a Java related question.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: CPLEX Error 1006: Error during callback

    Posted Tue September 03, 2019 03:53 PM

    You are correct: that's a Java question. When you declare an array of objects in Java, Java allocates space for pointers to the objects and sets the entries of the array to NULL. You then have to assign objects to the array slots (and, if necessary, create them). In your case, inside the loop you would need to set cplex[i] = new IloCplex().


    #CPLEXOptimizers
    #DecisionOptimization