Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Absolute Variables in Python API

    Posted 06/19/12 07:01 AM

    Originally posted by: pfaut


    HI,

    Is there any way to use the IloAbs absolute value variables in the python api (apart from a manual implementation)?
    And if not:
    Is there any better way apart from splitting the variable into a negative and positive variable and adding integer activity constraints to do so?
    What I would need is abs(x) in the optimization function (which works in c++ (by IloAbs) but not python).
    The only way I know is blowing the whole problem up with loads of additional integer variables by splitting x int x_pos and x_neg:
    i.e. x + z would become x_pos - x_neg + z
    while having the additional constraints:
    (1) eps * y+ <= x_pos <= x_max * y+
    (2) y-*eps <= x_neg <= -x_min * y-
    (3) y- + y+ <=1
    with a small eps and y+ and y- as integer variables.
    Where (1) ensures, that if y+ = 1 then x_pos is larger than epsilon and if y+ = 0 x_pos is = 0
    (2) ensures, that if y- = 1 then x_neg is larger than epsilon and if y- = 0 x_neg is = 0
    (3) ensures that EITHER y+ is 1 or y- is 1, so that x is either positive or negative or 0 (if both are zero)
    However this adds an awful lot of additional constraints...
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Absolute Variables in Python API

    Posted 06/19/12 05:36 PM

    Originally posted by: SystemAdmin


    If the only place you need abs(x) is in the objective, and if you are minimizing a positive multiple of abs(x) (along with the rest of the objective), then you can split each integer x into the sum of two nonnegative float variables, without introducing any new integer variables.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Absolute Variables in Python API

    Posted 06/24/12 02:30 PM

    Originally posted by: SystemAdmin


    I'm sorry, these modeling devices for absolute values are not available in the Python API. I have added your request to the wishlist.
    One thing you could do is:
    1. Write up the constraint in C++ Concert.
    2. Export the model to a file in LP format.
    3. Inspect the LP file to learn how CPLEX translated your constraint into something that does not require an IloAbs() construct (CPLEX translates absolute value constraints into indicator constraints).
    4. Manually implement the translation that CPLEX does.
    For example, a constraint like
    |x| >= 1
    

    is translated to
    id3: id5 >= 1
     c1:  x - x1 + x2  = 0
     c2:  id5 - x1 - x2  = 0
     i1: x3 = 1 -> x1 <= 0
     i2: x3 = 0 -> x2 <= 0
    Bounds
     0 <= x <= 1
     0 <= x3 <= 1
    Binaries
     x3 
    End
    

    (id5, x1, x2, x3 are additional variables that are created in the translation). I think that is roughly what you suggested yourself but using indicator variables might be simpler than using epsilons and/or maximum values.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Absolute Variables in Python API

    Posted 06/25/12 04:12 AM

    Originally posted by: pfaut


    Ok,

    I had not given the indicator interface a proper look, as I just did not notice it for some reason. And yes it is a little better than my suggestion in using only one binary to obtain the absolute value and not 2 binary variables.

    One thing I am wondering about however (but maybe thats just because there is only an excerpt of the total problem:
    why does cplex add the 0 <= x <= 1 constraint ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Absolute Variables in Python API

    Posted 06/25/12 05:06 AM

    Originally posted by: SystemAdmin


    CPLEX always uses 0/1 bounds for binary variables. That is were the bounds for x3 come from. For x I had added the bounds to the problem before I did the transformation. These are just the bounds with which I created the variable in Concert. Sorry about the confusion.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Absolute Variables in Python API

    Posted 06/25/12 05:38 AM

    Originally posted by: pfaut


    Thanks for the clarification, I assumed this was the reason for the bounds, but as they were so similar to the x3 constraints I was a little puzzled.
    #CPLEXOptimizers
    #DecisionOptimization