Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  MIR cut callback info

    Posted 04/11/19 06:19 PM

    Originally posted by: A.Omidi


    Hello everybody,

     

    I want to use an info callback for MIR cut (FlowMIRCutInfoCallback). I have worked on the below contractor in Java:

            static class MIRCuts extends IloCplex.FlowMIRCutInfoCallback {
                    IloCplex _cplex;
    
                    MIRCuts(IloCplex cplex) {
                            _cplex = cplex;
                    }
    
                    public void main() throws IloException {
                            int mircuts = getNMIRs();
                            System.out.println("NBmircuts: " + mircuts);
                    }
            }
    

    Before that, I could run the program I have an error: "The method getNMIRs() is undefined for the type Cplex_Example.MIRCuts".

    Could you please, say that how can I fix this it?

     

    Thanks in advance

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: MIR cut callback info

    Posted 04/12/19 12:29 AM

    The getNMIRcuts() was deprecated in 12.7 and removed in 12.8. Didn't you get a deprecation warning when the code still compiled?

    Use getNcuts() with IloCplex.CutType.MIR instead.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: MIR cut callback info

    Posted 04/12/19 05:20 AM

    Originally posted by: A.Omidi


    Dear Daniel,

    According to your question, it has been mentioned at the CPLEX12.8 user manual and "https://www.ibm.com/support/knowledgecenter/ru/SSSA5P_12.7.1/ilog.odms.cplex.help/refjavacplex/html/ilog/cplex/IloCplex.FlowMIRCutInfoCallback.html".

    I did not get any deprecation warning while compiled code. (I'm using CPLEX12.8 Java Lib on the Eclipse IDE).

    As per your comment, I changed the code as below:

            static class MIRCuts extends IloCplex.FlowMIRCutInfoCallback {
                    
                    MIRCuts(IloCplex model) {
    
                    }
    
                    public void main() throws IloException {
                            int mircuts = IloCplex.CutType.MIR;
                            int cliques = IloCplex.CutType.CliqueCover;
                            int Benders = IloCplex.CutType.Benders;
                            int Covers  = IloCplex.CutType.Cover;
                            int Fracs   = IloCplex.CutType.Frac;
    
                            System.out.println("NBmircuts: " + mircuts);
                            System.out.println("NBcliques: " + cliques);
                            System.out.println("NBbenders: " + Benders);
                            System.out.println("NBCovers:  " + Covers);
                            System.out.println("NBFracs:   " + Fracs);
                    }
            }
    

    When I run the code CPLEX log is mentioned: 

            Nodes                                         Cuts/
       Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap
    
    *     0+    0                            0.0000       54.0000              --- 
          0     0       31.0000     2        0.0000       31.0000        4     --- 
    *     0+    0                           29.0000       31.0000             6.90%
    
    NBmircuts: 5
    NBcliques: 3
    NBbenders: 21
    NBCovers:  0
    NBFracs:   4
    
    NBmircuts: 5
    NBcliques: 3
    NBbenders: 21
    NBCovers:  0
    NBFracs:   4
          0     0        cutoff             29.0000                      4     --- 
    Elapsed time = 0.02 sec. (0.04 ticks, tree = 0.01 MB, solutions = 2)
    
    Root node processing (before b&c):
      Real time             =    0.02 sec. (0.04 ticks)
    Sequential b&c:
      Real time             =    0.00 sec. (0.00 ticks)
                              ------------
    Total (root+branch&cut) =    0.02 sec. (0.04 ticks)
    ------------------------
    Objectiv value: 29.0
    ------------------------
    

    I Have some questions about that.
    1) Why does CPLEX show NB cuts twice? 
    2) Does CPLEX use benders cut automatically on any MIP? (In my case 21 cuts. I have been thinking that it's only used to benders decomposition).

    3) I was wondering if, you could tell me, how can I find any update reference to callbacks type and example of implementing them?

     

    Regards

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: MIR cut callback info

    Posted 04/12/19 07:28 AM
    1. You get the output more than once because the callback is invoked more than once. That is expected since cut separation at the root node takes several rounds.
    2. Your code is wrong. You are just printing the value of numerical constant IloCplex.CutType.Benders. You have to call getNcuts() (as I mentioned in my previous post)
    3. The best option is to look at the examples and the (reference) documentation that ships with CPLEX.

    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: MIR cut callback info

    Posted 04/12/19 05:10 PM

    Originally posted by: A.Omidi


    Hi Daniel, 

    Thanks for your replay.

    What does "value of numerical constant IloCplex.CutType" mean? 

    I try to use "getNcuts()" as below form:

            static class MIRCuts extends IloCplex.MIPInfoCallback {
                    IloCplex _cplex;
                    
                    MIRCuts(IloCplex model) {
                            _cplex = model;
                    }
    
                    public void main() throws IloException {
                            int mir = IloCplex.CutType.MIR;
                            _cplex.getNcuts(mir);
                    }
            }
    

    and installed by the method:

    model.use(new MIRCuts(model));
    

    When I run the code I have below error:

    ilog.cplex.CpxException: CPLEX Error  1804: Calling routines not allowed in informational callback.
    
            at ilog.cplex.CplexI.CALL(CplexI.java:4969)
            at ilog.cplex.CplexI.getNcuts(CplexI.java:5115)
            at ilog.cplex.IloCplex.getNcuts(IloCplex.java:11071)
    

    I try to use "TimeLimitCallback" callback and it works fine but, in the same method for "mircut" it does not work!!!

    Would you please, say that is there any specific way to implement it?

     

    Regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: MIR cut callback info

    Posted 04/13/19 04:12 PM
    1. IloCplex.CutType is basically the equivalent of a Java enumeration. (The Java API for CPLEX does not seem to use actual instances of enum or Enumeration, probably for consistency with C++ and other APIs.) If you look at the documentation for IloCplex.CutType, you will see it is a static class with a bunch of static int fields, such as MIR. Each of those is assigned to an integer value, which is what CPLEX actually uses to select the correct cut type. If you print the value of variable "mir" in line 9 of your code, what you will get is the value of that static int field. Think of it as basically an index.
    2. I believe the error message is due to line 10 in your code. Rather than calling _cplex.getNcuts(mir), just call getNcuts(mir). CPLEX understands that, inside a callback, all functions refer to the solver instance that is invoking the callback. (You don't really need to save the IloCplex instance in the constructor for the callback.)
    3. I'm suspicious of the fact that your callback class is declared with the static modifier. I think you may need to get rid of that, although I'm not positive it will cause an error.

    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: MIR cut callback info

    Posted 04/14/19 01:49 PM

    To expand on Paul's answer:

    • It is fine that the callback class is static.
    • In a callback it is almost always an error to invoke methods of the IloCplex instance that is currently solving the model if these models refer in any way to reporting progress or modifying the model. The callbacks have functions to do this.

    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: MIR cut callback info

    Posted 04/15/19 06:29 AM

    Originally posted by: A.Omidi


    Dear Prof. Rubin,

    Dear Daniel,

    Thanks for your technical support.
    I'm using below form and it works fine.

        static class MIRCuts extends IloCplex.MIPInfoCallback {
            public void main() throws IloException {
                int mir = getNcuts(IloCplex.CutType.MIR);
                System.out.println("Mixed integer rounding cuts applied: " + mir);
            }
        }
    

    when I'm running the model without using the callback, the CPLEX shows below result:

    Root relaxation solution time = 0.00 sec. (3.94 ticks)
    
            Nodes                                         Cuts/
       Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap
    
    *     0+    0                           78.0000       21.0000            73.08%
          0     0       58.1774    36       78.0000       58.1774      281   25.41%
    *     0+    0                           69.0000       58.1774            15.68%
          0     0       58.7209    35       69.0000      Cuts: 30      338   14.90%
    *     0+    0                           68.0000       58.7209            13.65%
          0     0       58.9238    37       68.0000      Cuts: 13      392   13.35%
          0     0       58.9732    37       68.0000    MIRcuts: 9      420   13.27%
    *     0+    0                           67.0000       58.9732            11.98%
          0     0       59.0184    37       67.0000    MIRcuts: 4      437   11.91%
    *     0+    0                           66.0000       59.0184            10.58%
          0     0       59.0185    38       66.0000    MIRcuts: 1      438   10.58%
          0     2       59.0185    38       66.0000       60.5902      438    8.20%
    Elapsed time = 0.73 sec. (47.28 ticks, tree = 0.01 MB, solutions = 5)
    *   636    40      integral     0       65.0000       65.0000     7700    0.00%
    
    Flow cuts applied:  1
    Mixed integer rounding cuts applied:  10
    Gomory fractional cuts applied:  5
    
    Root node processing (before b&c):
      Real time             =    0.72 sec. (47.13 ticks)
    Parallel b&c, 2 threads:
      Real time             =    0.25 sec. (58.10 ticks)
      Sync time (average)   =    0.05 sec.
      Wait time (average)   =    0.00 sec.
                              ------------
    Total (root+branch&cut) =    0.97 sec. (105.23 ticks)
    Objective = 65.0
    

    While I'm running the model using the callback, the CPLEX shows below result:

    Root relaxation solution time = 0.02 sec. (3.94 ticks)
    
            Nodes                                         Cuts/
       Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap
    
    *     0+    0                           78.0000       21.0000            73.08%
          0     0       58.1774    36       78.0000       58.1774      281   25.41%
    Mixed integer rounding cuts applied: 0
    Mixed integer rounding cuts applied: 0
    *     0+    0                           69.0000       58.1774            15.68%
    Mixed integer rounding cuts applied: 0
    Mixed integer rounding cuts applied: 8
          0     0       58.7209    35       69.0000      Cuts: 30      338   14.90%
    Mixed integer rounding cuts applied: 2
    *     0+    0                           68.0000       58.7209            13.65%
    Mixed integer rounding cuts applied: 2
    Mixed integer rounding cuts applied: 2
    Mixed integer rounding cuts applied: 7
          0     0       58.9238    37       68.0000      Cuts: 13      392   13.35%
    Mixed integer rounding cuts applied: 3
    Mixed integer rounding cuts applied: 12
          0     0       58.9732    37       68.0000    MIRcuts: 9      420   13.27%
    Mixed integer rounding cuts applied: 10
    *     0+    0                           67.0000       58.9732            11.98%
    Mixed integer rounding cuts applied: 10
    Mixed integer rounding cuts applied: 14
          0     0       59.0184    37       67.0000    MIRcuts: 4      437   11.91%
    Mixed integer rounding cuts applied: 8
    *     0+    0                           66.0000       59.0184            10.58%
    Mixed integer rounding cuts applied: 8
    Mixed integer rounding cuts applied: 8
    Mixed integer rounding cuts applied: 9
          0     0       59.0185    38       66.0000    MIRcuts: 1      438   10.58%
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
          0     2       59.0185    38       66.0000       60.5902      438    8.20%
    Elapsed time = 0.53 sec. (47.29 ticks, tree = 0.01 MB, solutions = 5)
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    Mixed integer rounding cuts applied: 9
    *   636    40      integral     0       65.0000       65.0000     7700    0.00%
    Mixed integer rounding cuts applied: 10
    

    My question is that: 
    Why does CPLEX show 10 MIR cuts (in the first case without using callback) but, it shows more than 10 cuts in some nodes in the B&B tree log (in the second case)?

     

    Regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: MIR cut callback info

    Posted 04/29/19 01:03 AM

    This is expected. CPLEX may add and remove cuts as it pleases since. Removal happens in case CPLEX finds that a cut is no longer useful (for example because it is never violated or never tight). In that case it makes sense to remove the cut in order to reduce the size of the relaxations that have to be solved. So the number of active cuts can go up and down during the solve (as your log indicates).


    #CPLEXOptimizers
    #DecisionOptimization