Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Indicator constraint definition in the CPLEX Python API

    Posted Wed February 21, 2018 10:44 AM

    Originally posted by: Skapur


    Good afternoon,

    I am using CPLEX through the Python API and I'm trying to define some indicator constraints for a mixed-integer linear programming problem. The constraints I'm trying to setup in LP file format are similar to this:

    v1_indicator = 0 <-> v1 = 0

    v1_indicator = 1 <-> v1 >= 1

    There are other variables v2,v3, etc... to be constrained in this manner and I'm minimizing the sum of these binary indicators. However, when using the add method in the indicator_constraints sub-interface, the LP file shows constraints with only a forward arrow. After successive optimizations, I'm finding that the solutions contain some indicators that are set to 1 despite their associated variables being 0. All of the solutions display and 'optimal' status.

    The constraints built by the API do not result in the double <-> arrow in LP format, rather coming as a single -> arrow. I have also loaded a modified LP with the double arrows and the solutions come out as expected. Is it possible to generate such constraints with the Python API?

    I should also add I implemented a similar problem using the Java library with the IfThen function and the results are correct. Is there any Python equivalent?

     

    Thanks in advance!


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Indicator constraint definition in the CPLEX Python API

    Posted Wed February 21, 2018 11:34 AM

    Correct, the API lets you create only -> implications. This is because <-> implications are shaky. Usually for the <- direction CPLEX has to state strict inequality in some form. Since strict inequality is not supported in the theory of linear programming, CPLEX has to replace that by "less than or equal" and an epsilon. Instead of creating one <-> constraint you can create two indicator constraints. If both sides of the implication are integral then it should be easy to translate strict inequality that is required into one direction into something like <=. If one of the sides is continuous then you have to come up with a good epsilon for that.

    The Java interface is more high-level and an IfThen() constraint is translated to a series of indicator constraints. Usually it is not a good idea to try to emulate this. In most cases you can do better by directly using indicator constraints as described above.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Indicator constraint definition in the CPLEX Python API

    Posted Wed February 21, 2018 01:01 PM

    Originally posted by: Skapur


    Thank you very much for the reply. I was starting to think I had missed something!

     

    I don't think in my case it would be simple to add an "opposing" indicator constraint since v would either be 0 or any value above 1. I can't think of how to implement this just with indicator constraints and linear algebra is definitely not my greatest strength...

    I ended up replicating the constraints built by Java API which solved the problem. Although this may not be recommended, the resulting constraints amount to something like this (based on what I originally posted):

    v_indicator + a = 1

    b - a >= 0

    c - v_indicator = 0

    d - c >= 0

    b = 1 -> v = 0

    d = 1 -> v >= 1

    a,b,c and d are binary variables

    There's surely a better way to implement this using pure indicator constraints but for the time being, this is good enough for me.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Indicator constraint definition in the CPLEX Python API

    Posted Wed February 21, 2018 01:24 PM

    If you v-variables are either 0 or any value above 1, did you consider using semi-integer or semi-continuous variables? These variables implement exactly that: The variable is either 0 or >= some bound. See for example here.


    #CPLEXOptimizers
    #DecisionOptimization