Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problem about benders decomposition via LazyConstraintCallback

    Posted 09/21/11 04:20 AM

    Originally posted by: J5JK_chao_lei


    Hello

    I was trying to implement Bender's decomposition using LazyConstraintCallback. However, it always pop up the error as following, when the program uses getValue function in the main function of BendersLazyConsCallback class, to get a variable value from master problem :

    
    at ilog.cplex.CpxNumVar.getVarIndexValue(CpxNumVar.java:268) at ilog.cplex.IloCplex$MIPInfoCallback.getIndex(IloCplex.java:11624) at ilog.cplex.IloCplex$ControlCallback.getValue(IloCplex.java:13017)
    


    This value is actually the objective value of dual of subproblem, with this value that I can test whether to add an optimality cut or not.

    I don't know how the error happens and I am really appreciate helpful comments.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Problem about benders decomposition via LazyConstraintCallback

    Posted 09/21/11 05:59 AM

    Originally posted by: SystemAdmin


    What is the type of the exception you get? Could you provide the full exception message?
    Are you sure that the IloNumVar instance for which you invoke getValue()
    • is initialized (not null)
    • is part of the model that CPLEX is solving when the callback is invoked? I guess you solve a master model M and in the callback a slave model S. If you invoke the getValue(x) method of the callback then x must be contained in M. If x is only contained in S then you have to invoke the getValue() method on the IloCplex instance that solved S.

    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: Problem about benders decomposition via LazyConstraintCallback

    Posted 09/22/11 02:04 AM

    Originally posted by: J5JK_chao_lei


    > dju358 wrote:
    > What is the type of the exception you get? Could you provide the full exception message?
    The whole exception message shows like:

    
    Exception in thread 
    "main" java.lang.NullPointerException at ilog.cplex.CpxNumVar.getVarIndexValue(CpxNumVar.java:268) at ilog.cplex.IloCplex$MIPInfoCallback.getIndex(IloCplex.java:11624) at ilog.cplex.IloCplex$ControlCallback.getValue(IloCplex.java:13017) at MIP.BDNDP$BendersLazyConsCallback.main(BDNDP.java:45) at ilog.cplex.CpxCallback.callmain(CpxCallback.java:143) at ilog.cplex.CpxCutCallbackFunction.callIt(CpxCutCallbackFunction.java:44) at ilog.cplex.Cplex.CPXmipopt(Native Method) at ilog.cplex.CplexI.solve(CplexI.java:2291) at ilog.cplex.IloCplex.solve(IloCplex.java:9306) at MIP.BDNDP.main(BDNDP.java:458)
    


    > Are you sure that the IloNumVar instance for which you invoke getValue()
    > - is initialized (not null)
    > - is part of the model that CPLEX is solving when the callback is invoked? I guess you solve a master model M and in the callback a slave model S. If you invoke the getValue(x) method of the callback then x must be contained in M. If x is only contained in S then you have to invoke the getValue() method on the IloCplex instance that solved S.

    Here the code that I created the master problem:
    
    
    
    static 
    
    void createMaster(IloModeler model, Data data, IloIntVar[][] x, IloNumVar z) 
    
    throws IloException 
    { 
    
    int i, j; 
    
    int numNodes = data.numNodes; 
    
    double[][] arcCost = data.arcCost;   
    //Create the variables z = model.numVar(-Double.MAX_VALUE, Double.MAX_VALUE); model.add(z);   
    
    for (i = 0; i < numNodes; ++i) 
    { 
    
    for (j = 0; j < numNodes; ++j) 
    { x[i][j] = model.boolVar(); model.add(x[i][j]); 
    } x[i][i].setUB(0); 
    } 
    //Model the objective function IloLinearNumExpr objExpr = model.linearNumExpr(); objExpr.addTerm(z, 1.); 
    
    for (i = 0; i < numNodes; ++i) 
    { 
    
    for (j = 0; j < numNodes; ++j) 
    { objExpr.addTerm(x[i][j], arcCost[i][j]); 
    } 
    } model.addMinimize(objExpr);   
    //Model the constraints 
    
    for (i = 0; i < numNodes; ++i) 
    { 
    
    for (j = 0; j < numNodes; ++j) 
    { IloLinearNumExpr expr = model.linearNumExpr(); expr.addTerm(x[i][j], 1.); expr.addTerm(x[j][i], 1.); model.addLe(expr, 1.); 
    } 
    }   
    }
    


    After this master been solved, I want to get the value of z in LazyConstraintCallback, however, it didn't work.
    Is that right for me to define a variable z but use it only in the objective function in CPLEX?
    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: Problem about benders decomposition via LazyConstraintCallback

    Posted 09/22/11 02:32 AM

    Originally posted by: SystemAdmin


    I think your problem is as follows: I suppose you have the following code:
    
    
    
    static 
    
    void createMaster(IloModeler model, Data data, IloIntVar[][] x, IloNumVar z) 
    
    throws IloException 
    { ... 
    //Create the variables z = model.numVar(-Double.MAX_VALUE, Double.MAX_VALUE); model.add(z); ... 
    }   
    
    void someOtherFunction() 
    { ... IloNumVar z; createMaster(model, data, x, z); ... 
    }
    

    and after you called createMaster() from someOtherFunction() you expect 'z' in someOtherFunction() to be initialized. However, it is not. The assignment that you perform to 'z' in createMaster() are not visible to someOtherFunction() so 'z' will still be null in someOtherFunction().
    Can you attempt to change your code like this:
    
    
    
    static IloNumVar createMaster(IloModeler model, Data data, IloIntVar[][] x) 
    
    throws IloException 
    { ... 
    //Create the variables IloNumVar z = model.numVar(-Double.MAX_VALUE, Double.MAX_VALUE); model.add(z); ... 
    
    return z; 
    }   
    
    void someOtherFunction() 
    { ... IloNumVar z = createMaster(model, data, x); ... 
    }
    

    This should initialize 'z' properly.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: Problem about benders decomposition via LazyConstraintCallback

    Posted 09/24/11 04:30 AM

    Originally posted by: J5JK_chao_lei


    Hi, Daniel

    I follow your instruction and it worked out. Thanks a lot!
    #DecisionOptimization
    #MathematicalProgramming-General