Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  User Cut Callbacks

    Posted 06/02/17 02:17 PM

    Originally posted by: story_


    Hi,

    I am trying to add a user cut using callbacks in Java API. I am solving a minimization MIP, to which I know a good lower bound. Thus I would like to add the following type of constraint to speed up the improvement of the best bound: objective function >= my lower bound. However, as I have never used callbacks before, I am unsure on how to express the objective function. So far I have got: 

    static class addbestboundcut extends IloCplex.UserCutCallback {
        public void main() throws IloException {
        IloLinearNumExpr obj;
        obj = *how can I express the variables and coefficients in the objective function as a linear expression?*
        add(obj,"G",mybestbound);
            }
        }

    I am also using "obj" as a IloLinearNumExpr to define the objective function of the model under the main block.

    Many thanks for your help.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: User Cut Callbacks

    Posted 06/02/17 03:16 PM

    First of all: why do you want to add this in a cut callback? Is your lower bound only computed while the CPLEX solve is already running? If not then you could add this via IloCplex.addUserCut() or even as a hard constraint via IloCplex.add().

    If you already setup 'obj' for defining the objective then the best strategy to get this into the callback would be to pass it to the callback constructor and then store it in a field of the class. Then you can add the cut via

    add(cplex.Ge(obj, mybestbound));

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: User Cut Callbacks

    Posted 06/05/17 07:28 AM

    Originally posted by: story_


    Hi,

    Thanks for your response - I have mybestbound in hand before calling CPLEX solve (which is obtained through some heuristic I have). I tried adding this as a hard constraint in the form: cplex.addGe(obj, mybestbound), however doing so seems to worsen the performance significantly. I wanted to check how callbacks would perform after having a look at: https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014633570

    I would be very grateful to see an example for how an expression as "obj" can be passed to the callback constructor, as I have never worked with callbacks before.

    Thank you.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: User Cut Callbacks

    Posted 06/07/17 02:23 AM

    I doubt that using a callback will make any difference.

    Passing an object to a callback constructor is the same as passing an object to any other class's constructor. There is nothing special or CPLEX specific here. Just plain Java.

    In any case, here is an (untested) code snippet that passes the expression used as objective function to a callback instance:

    import ilog.cplex.*;
    import ilog.concert.*;
    
    public final class ObjToCallback {
       private static final class Callback extends IloCplex.UserCutCallback {
          private final double mybound;
          private final IloCplex cplex;
          private final IloNumExpr expr;
          public Callback(double mybound, IloCplex cplex, IloNumExpr expr) {
             this.mybound = mybound;
             this.cplex = cplex;
             this.expr = expr;
          }
          protected void main() throws IloException {
             // Do something with expr here
             if ( getValue(expr) < mybound )
                add(cplex.ge(expr, mybound), IloCplex.CutManagement.UseCutFilter);
          }
       }
       public static void main(String[] args) throws IloException {
          final IloCplex cplex = new IloCplex();
          try {
             IloNumVar x = cplex.numVar(0, Double.POSITIVE_INFINITY, "x");
             IloNumVar y = cplex.numVar(0, Double.POSITIVE_INFINITY, "y");
             IloNumExpr sum = cplex.sum(x, y);
             cplex.addMinimize(sum);
             Callback callback = new Callback(0.0, cplex, sum);
             cplex.use(callback);
          }
          finally {
             cplex.end();
          }
       }
    }
    

     


    #CPLEXOptimizers
    #DecisionOptimization