Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Receiving an error when using getCandidatePoint

    Posted 07/21/19 07:03 PM

    Originally posted by: open_ball


    Hi,

    I take BendersATSP2 as a reference to implement Benders Decomposition. In invoke method, when I use getCandidatePoint to obtain the estimation of dual objective, I receive an error.

    Before adding a lazy cut, I check whether the artificial variable used to estimate dual objective is larger than the actual objective (i.e., maximization). That's why I try to access that value. 

    The code successfully access the value of variables defined in master problem. In the next step, I receive an error. 

    In the main method, I define the artificial variable as: "final IloNumVar estObj =null;" 

    Then, I create the master problem createMasterILP(masterCplex, x , estObj, numNodes, adjacencyList); 

    Lastly, I attach the callback function;           

      int numThreads = masterCplex.getNumCores();    
      final BendersPPINCallback cb = new BendersPPINCallback(x,estObj, adjacencyList, numThreads);
      long contextmask = IloCplex.Callback.Context.Id.Candidate
                    | IloCplex.Callback.Context.Id.ThreadUp
                    | IloCplex.Callback.Context.Id.ThreadDown;
       masterCplex.use(cb, contextmask);
    


                        
         

    This is a code block where I get the values from the candidate point.

                     double[] xSol = new double[numNodes]
                     double Estimation =0;
                     if ( context.inCandidate() ) {
                         if ( !context.isCandidatePoint() ) // The model is always bounded
                            throw new IloException("Unbounded solution");
                         for (int i = 0; i < numNodes; ++i) {                   
                            xSol[i] = context.getCandidatePoint(x[i]);
                         }
                         try {
                             Estimation = context.getCandidatePoint(estObj);
                         }finally {
                             System.err.println("Error is here!");
                         }
    

     

    This is the error that I receive.

    Lazy constraint(s) or lazy constraint callback is present.
        Disabling dual reductions (CPX_PARAM_REDUCE) in presolve.
        Disabling non-linear reductions (CPX_PARAM_PRELINEAR) in presolve.
    
    Root node processing (before b&c):
    Error is here!
      Real time             =    0.00 sec. (0.00 ticks)
    Parallel b&c, 4 threads:
      Real time             =    0.00 sec. (0.00 ticks)
      Sync time (average)   =    0.00 sec.
      Wait time (average)   =    0.00 sec.
                              ------------
    Total (root+branch&cut) =    0.00 sec. (0.00 ticks)
    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)
            at BendersPPIN.main(BendersPPIN.java:218)
    
        
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Receiving an error when using getCandidatePoint

    Posted 07/22/19 05:53 AM

    Can you please wrap your callback into something like

    try {
       // your callback code here
       ...
    }
    catch (Exception e) {
       System.err.println("Exception in callback: " + e.getMessage());
       e.printStackTrace();
       throw e;
    }

    and then post the additional output? That will exactly identify what went wrong and where. It would also be useful if you could add a mapping from line numbers in the exception message to line numbers in your code.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Receiving an error when using getCandidatePoint

    Posted 07/22/19 11:11 AM

    Originally posted by: open_ball


    I actually know where I get the error. The line where I call 

    Estimation = context.getCandidatePoint(estObj);
    

    gives me the error.I did what you recommended and I received NullPointer Exception.

     

    Exception in callback: null
    java.lang.NullPointerException
            at ilog.cplex.IloCplex.var2ind(IloCplex.java:23647)
            at ilog.cplex.CpxCallbackContext.getCandidatePoint(CpxCallbackContext.java:171)
            at ilog.cplex.IloCplex$Callback$Context.getCandidatePoint(IloCplex.java:12626)
            at BendersPPIN$BendersPPINCallback.invoke(BendersPPIN.java:167)
            at ilog.cplex.CplexI.invokeGenericCallback(CplexI.java:7610)
            at ilog.cplex.Cplex.CPXmipopt(Native Method)
            at ilog.cplex.CplexI$SolveHandle.start(CplexI.java:2837)
            at ilog.cplex.CplexI.solve(CplexI.java:2963)
            at ilog.cplex.IloCplex.solve(IloCplex.java:10254)
            at BendersPPIN.main(BendersPPIN.java:222)
    

    In the main function, I define estObj as 

    final IloNumVar estObj = null;
    

    and then pass into the master problem and do the following 

    estObj = mod.numVar(0.0, numNodes-1, "estObj");
    

    I guess the way I initialize  estObj is wrong. Could you please tell me how I should define it properly before passing into the master problem?

     

    Just for now, I defined it as a single element array 

    final IloNumVar[] estObj = new IloNumVar[1];
    

    When I run the code, it compiles without any error. However, there is something odd happening.

    In the callback function, when I print the value of estObj with 

    context.getCandidatePoint(estObj[0])
    

    it gives me zero and then the code stops. However, my problem is maximization and in the first iteration there is no constraint related to estObj. That is why  estObj should get its upper bound. Since it gets the value of zero, it returns me a solution without any iteration. What am I doing wrong?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Receiving an error when using getCandidatePoint

    Posted 07/22/19 11:30 AM

    You NullPointerException seems to indicate that either estObj itself is null or that this variable is not used anywhere in the model. Can you check both?

    In order to force the variable into the model you can do cplex.add(estObj).


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Receiving an error when using getCandidatePoint

    Posted 07/22/19 11:38 AM

    Originally posted by: open_ball


    I guess I identified what is wrong with it. I will update my post based on my finding.

     

    Edit: my problem is solved. Thanks for the help.


    #CPLEXOptimizers
    #DecisionOptimization