Decision Optimization

 View Only
  • 1.  Python CPLEX API: defining binary decision variables

    Posted Thu May 21, 2020 12:35 PM
    Hello,
    I'm currently trying to understand how to ensure that my binary variables take their values as imposed by my condition. 
    I'm using a low level Python API in matrix format.

    For additional context/example please read the following question on mathexchange: Defining Binary Decision Variables in Python CPLEX API

    Please let me know if my question is clear or if you need further clarification.



    ------------------------------
    Andre Hoffmann
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Python CPLEX API: defining binary decision variables

    Posted Thu May 21, 2020 02:25 PM
    Pardon me, I found the ressource on http://www.yzuda.org/Useful_Links/optimization/if-then-else-01.html to solve my confusion.

    ------------------------------
    Andre Hoffmann
    ------------------------------



  • 3.  RE: Python CPLEX API: defining binary decision variables

    Posted Thu May 21, 2020 02:51 PM
    It sounds like you are looking for indicator constraints.

    Using the CPLEX Python API, you can create/modify/delete indicator constraints using the InidicatorConstraintInterface.

    See also the following examples that are included when you install CPLEX:
    • fixnet.py
    • foodmanu.py
    • diet.py
    • etsp.py


    ------------------------------
    Ryan Kersh
    ------------------------------



  • 4.  RE: Python CPLEX API: defining binary decision variables

    Posted Fri May 22, 2020 04:49 AM
    Exactly this is what I had in mind. Indicator Constraints seem like a much better alternative to Big-M formulations. 


    Thanks for pointing this out!

    ------------------------------
    Andre Hoffmann
    ------------------------------



  • 5.  RE: Python CPLEX API: defining binary decision variables

    Posted Mon May 25, 2020 05:53 AM
    Is my understanding of the command indicator_constraints.add_batch() correct? You submit a collection of constraints and for each constraint you specify a variable that activates the individual constraint.

    ------------------------------
    Andre Hoffmann
    ------------------------------



  • 6.  RE: Python CPLEX API: defining binary decision variables

    Posted Mon May 25, 2020 06:20 AM
    add_batch() is basically a shortcut for this:
    for l, s, r, i, c, n, t in zip(lin_expr, sense, rhs, indvar, complemented, name, indtype):
        cpx.indicator_constraints.add(l, s, r, i, c, n, t)

    So you specify a list of indicator constraints and they are added in one batch. There is no relation between the different constraints. If you have to add many, many constraints then it is faster to add them in batches than to add them individually.


    ------------------------------
    Daniel Junglas
    ------------------------------