Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Complemented parameter in CPLEX indicator constraint

  • 1.  Complemented parameter in CPLEX indicator constraint

    Posted Sat December 30, 2017 12:09 AM

    Originally posted by: BerkUstun


    I'm currently trying to solve a MIP with indicator constraints using in the CPLEX 12.8.0 Python API.

    I'm having some trouble understanding how set the complemented parameter for the mip.indicator_constraints.add function.

    The online documentation for the Python API describes the parameter as:

    complemented : whether the constraint is active when the variable indvar is equal to 0 or 1: default is 0.

    But this is somewhat different from the documentation for the C API, which describes it as:

     Boolean value that specifies whether the indicator variable is complemented. The linear constraint must be satisfied when the indicator takes a value of 1 (one) if the indicator is not complemented, and similarly, the linear constraint must be satisfied when the indicator takes a value of 0 (zero) if the indicator is complemented

    Just to make sure that I have it right, take this example, where complemented = 0:

    
    # mip.indicator_constraints.add(indvar="x1",
    #                               complemented=0,
    #                               rhs=1.0,
    #                               sense="G",
    #                               lin_expr=cplex.SparsePair(ind=["x2"], val=[2.0]),
    #                               name="ind1")
    

    Does this mean:

     

    - if "x1 = 0"  then the constraint "2*x2 >= 1.0" must be active

    - if "x1 = 1" then the constraint "2*x2 >= 1.0" could either be active or inactive?

     

    Or rather?

     

    - if "x1 = 1"  then the constraint "2*x2 >= 1.0" must be active

    - if "x1 = 0" then the constraint "2*x2 >= 1.0" could either be active or inactive?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Complemented parameter in CPLEX indicator constraint

    Posted Sat December 30, 2017 04:37 AM

    Hi

    you have a small example foodmanu.py 

     

     

    implements a solution to the food production planning problem, well known from the modeling textbook of H. P. Williams; this implementation uses indicator constraints and semi-continuous variables.

     

     

    And for your question if complemented  is zéro then second option

     

    regards

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Complemented parameter in CPLEX indicator constraint

    Posted Sat December 30, 2017 11:11 PM

    Originally posted by: EdKlotz


    As Alex said, it means the second.

    - if "x1 = 1"  then the constraint "2*x2 >= 1.0" must be active

    - if "x1 = 0" then the constraint "2*x2 >= 1.0" could either be active or inactive?

    Writing out an LP file from the Python API probably would have provided the answer.   However, your experience here makes me suspect the documentation on the Python side could be clarified.   It says:

    complemented : whether the constraint is active when the variable indvar is equal to 0 or 1: default is 0.

    By "default is 0" the docs mean that the default for the complemented parameter it 0, not that the default for the constraint being active is associated with the indvar being 0.   Was that what prompted you to ask about the inconsistency between the Python and C API docs?   If so, would the following have been better?

     

    complemented : whether the constraint is active when the variable indvar is equal to 0 or 1: default parameter value is 0 (indicator variable equal to 1)

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Complemented parameter in CPLEX indicator constraint

    Posted Tue January 02, 2018 10:38 AM

    Originally posted by: BerkUstun


    Thanks for this!

     

    My misunderstanding was not from the description of the default value but rather the first sentence. It doesn't clearly state what complemented = True means, or what complemented = False means.

     

    I think what would have helped is something similar to the description in the C documentation like:

     

    complemented : Set as 0 if the indicator constraint is active when indvar = 1. Set as 1 if the indicator constraint is active when indvar =0. Default is 0.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Complemented parameter in CPLEX indicator constraint

    Posted Wed January 03, 2018 05:18 PM

    Originally posted by: EdKlotz


    > complemented : set to 1 if the indicator constraint is active when indivar = 1, and to 0 if the indicator constraint is active when indvar =0. Default is 0.

     

    Didn't you just reverse it?   If complemented is 0, then the indicator constraint is active when the indvar is 1.   You just wrote the opposite.   So either you are still confused, or I am newly confused, and either way I think we can conclude that there are too many different 1s and 0s floating around here.   

     

    With that in mind, along with your comments, let's try something where we explain the default use case first, since I bet 98% of our users use that and don't care about changing this to a non default value.   So those readers can stop reading after the first sentence below, and only those who need to complement need read the second sentence:

     

    "complemented : Default value of 0 instructs CPLEX to interpret indicator constraint as active when the indicator variable is 1.  Set to complemented to 1 to instruct CPLEX that the indicator constraint is active when indvar =0. "

     

    Does that work for you?


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Complemented parameter in CPLEX indicator constraint

    Posted Wed January 03, 2018 05:39 PM

    Originally posted by: BerkUstun


    Whoops! Sorry that was a typo on my behalf.

    I edited my response so that folks won't be confused if they find this post in the future.

    Either way, the description you wrote is much better / clearer.

    Thank you again for your help!

     


    #CPLEXOptimizers
    #DecisionOptimization