Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Indicator Constraints

    Posted 04/28/10 05:31 PM

    Originally posted by: Ed Chamberlayne


    This is a follow-up on a July 2009 post.

    Has anyone successfully used indicator constraints in lieu of Big M constraints?

    I'm a little confused on the notation in OPL versus AMPL. What has replaced "==>" that was used in AMPL? Is it "=>" which I thought was greater or equal to as well?

    My previous code was:

    forall (<i,j> in ordlinks, t in 1..T)
            e1p[<i,j>,t] <= maxl(N[i],N[j])*z1[<i,j>,t];
    forall (<i,j> in ordlinks, t in 1..T)
            e1n[<i,j>,t] <= maxl(N[i],N[j])*(1-z1[<i,j>,t]);
    


    where z1 is a binary variable and e1p,e1n are non-negative floats.

    I've since replaced this with:

    forall (<i,j> in ordlinks, t in 1..T)
            z1[<i,j>,t]==1 => e1p[<i,j>,t] <= maxl(N[i],N[j]) && e1n[<i,j>,t]==0;
    forall (<i,j> in ordlinks, t in 1..T)
            z1[<i,j>,t]==0 => e1n[<i,j>,t] <= maxl(N[i],N[j]) && e1p[<i,j>,t]==0;
    


    are these equivalent?

    Thanks,

    Ed
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Indicator Constraints

    Posted 04/30/10 08:52 PM

    Originally posted by: GuangFeng


    "=>" means imply, which is the correct operator to use to write indicator constraints. See OPL 6.3 documentation "Language Reference Manual > OPL, the modeling language > Constraints > Types of constraints > Logical constraints for CPLEX" for more details.

    So you can rewrite

    x1 + x2 + x3 - 1e+9 y <= 0;

    as

    y == 0 => x1 + x2 + x3 == 0;

    The way you used "=>" looks correct, but I will leave it to yourself to judge whether the later formulation is equivalent to your original one.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Indicator Constraints

    Posted 05/03/10 01:05 PM

    Originally posted by: Ed Chamberlayne


    thanks!
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Indicator Constraints

    Posted 05/04/10 04:40 AM

    Originally posted by: SystemAdmin


    Howdy,

    one further remark on this topic. From a theoretical point of view the
    formulations are identical, but yield different CPLEX-models with a
    different runtime behaviour.
    W.r.t to the last example suppose we have
    
    dvar float+ x1 in 0..1; dvar float+ x2 in 0..1; dvar float+ x3 in 0..1; dvar float+ y  in 0..1;   maximize x1+y;
    

    The constraints
    
    subject to 
    { x1 + x2 + x3 - 1e+9 * y <= 0; 
    }
    

    leads to the follwing LP-file
    
    Maximize obj: x1 + y + id21 Subject To id24: x1 - 1000000000 y + x2 + x3 <= 0 Bounds 0 <= x1 <= 1 0 <= y <= 1 id21 = 0 0 <= x2 <= 1 0 <= x3 <= 1 End
    


    Whereas
    
    y == 0 => x1 + x2 + x3 == 0;
    

    leads to
    
    Maximize obj: x1 + y + id23 + 0 x2 + 0 x3 Subject To id3: id22 - id13 <= 0 i1: id22 = 1 <-> y  = 0 i2: id13 = 1 <-> x1 + x2 + x3  = 0 Bounds 0 <= x1 <= 1 0 <= y <= 1 id23 = 0 0 <= id22 <= 1 0 <= id13 <= 1 0 <= x2 <= 1 0 <= x3 <= 1 Binaries id22  id13 End
    


    Thus you loose the Big-M term but pay the price by extra constraints and extra binaries.

    Therefore, it seems not to be clear which formulation will have the better performance.

    Regards
    Norbert
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Indicator Constraints

    Posted 05/04/10 12:22 PM

    Originally posted by: Ed Chamberlayne


    Thanks Norbert. How do you generate the LP file that CPLEX creates from within OPL? I'm curious how my constraints and obj function are being interpreted by CPLEX.

    For my specific problem, the indicator constraints seem to yield better performance but I will test both formulations to be sure.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Indicator Constraints

    Posted 05/05/10 02:56 AM

    Originally posted by: SystemAdmin


    Ed,

    below you will find the complete code that I used ...
    Hope this helps.

    Regards
    Norbert
    int version = 1;
     
    range rng = 1..3;
    dvar float+ x[rng] in 0..1;
    dvar float+ y  in 0..1;
     
     
     maximize x[1]+y;
     subject to
     {
       if(version == 1)
       {
          x[1] + x[2] + x[3] - 1e+9 * y <= 0; // --> TestA.lp
       }
       else
       {
         y == 0 => x[1] + x[2] + x[3] == 0;    // --> TestB.lp
       }
     }
     
    main
    {
       thisOplModel.generate(); 
       if(thisOplModel.version == 1)
           cplex.exportModel("testA.lp");
       else
           cplex.exportModel("testB.lp");
       writeln("model dumped ...");
       cplex.solve();
       for( i in thisOplModel.rng)
          writeln(" x[",i,"] = ",thisOplModel.x[i]);
     
       writeln(" y = ",thisOplModel.y);
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Indicator Constraints

    Posted 05/05/10 09:28 AM

    Originally posted by: Ed Chamberlayne


    Thank you so much trebron | norbert!! I've was trying a few weeks ago to learn how to export the model from CPLEX but was stuck. I'm getting a handle on writing math programs in OPL but I am still challenged at writing the post processing scripts.

    Thanks again,

    Ed
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Indicator Constraints

    Posted 05/05/10 05:45 PM

    Originally posted by: GuangFeng


    Ed, trebron,

    You can also add an OPL settings file to your configuration and changing the value of "Export format" to export the model. You can find some useful documentation http://publib.boulder.ibm.com/infocenter/oplinfoc/v6r3/index.jsp?topic=/ilog.odms.ide.help/Content/Optimization/Documentation/OPL_Studio/_pubskel/globals/eclipse_and_xplatform/ps_opl263.html

    Regarding the efficiency of indicator constraints, indicator constraint formulation does have some additional variables, but the formulation has less risk of numerical issues, and CPLEX presolve can be effective in handling the additional variables. But you are correct that you might want to test both formulations to see which one works better for you, depending on the overall numerical difficulties of the model (instead of focusing too much on the indicator constraints themselves) and other factors.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer