Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Adding a quadratic constraint in If-Then

    Posted 12/28/19 02:08 PM

    Originally posted by: tackoo


    I have a constraint represented as a quadratic function. This function should only be valid if a certain discrete condition is satisfied.

    I tried using if_then() for modeling this behavior but it seems docplex.mp is unable to handle quadratic constraint in if_then() context. I tried writing this quadratic function as piecewise linear, but again if_then() doesn't seem to like PWL functions either. Any recommendations on how I can proceed? I'm trying to do these in Python if this makes any difference. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Adding a quadratic constraint in If-Then

    Posted 12/30/19 08:05 PM

    Originally posted by: EdKlotz


    If then functionality, in any of CPLEX's APIs is fundamentally based on indicator constraints, and at the C API level indicator constraints only operate on linear constraints, not quadratic ones.   Now, the if_then functionality can work around this by creating a linear indicator constraint and then associating the quadratic constraint with that linear constraint.   But that association is likely to give rise to a nonconvex quadratic constraint that CPLEX doesn't currently support.  

     

    I tried modifying the ilofixnet.cpp example that uses IloIfThen to create a quadratic constraint, and I got precisely this behavior, e.g.

     c6:  f(0) + x13  = 1                       // all variables except x15 and x(0) are binary.

     q1: x15 + [ - x(0) ^2 ]  = 0

    ...

     i1:  x14 = 1 <-> x15 =< 11
     i2:  x13 = 1 -> x14  = 1

     

    q1 is a nonconvex quadratic constraint that CPLEX rejects:

    CPLEX Error  5002: 'q1' is not convex.

     

    You did not provide any messages or output from your DoCplex program, but I suspect you encountered essentially the same issue, even if the behavior was slightly different.

     

    What exactly are the conditional quadratic constraints you are trying to express?   Maybe you can model it directly.   In general if you have a binary z and a positive semi definite matrix Q, you can model

     

    z == 1 --> x'Qx <= b

    as

     

    x'Qx + Mz <= b + M

     

    where M is some (hopefully reasonable) upper bound on the maximum possible value x'Qx can attain.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Adding a quadratic constraint in If-Then

    Posted 12/30/19 09:32 PM

    Originally posted by: tackoo


    You are precisely correct about the behavior I am experiencing. I have a similar error message with my Python file when I try to put a quadratic constraint in "then" part. 
     

    I also thought about transforming my constraint without if, but got confused on how to deal with. My then function is multivariate in the form of f(x,y) = ax^2 + bx + cy^2 + dy + exy + f. If part is simple z==1. Any idea on how to model this?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Adding a quadratic constraint in If-Then

    Posted 12/31/19 12:02 AM

    Originally posted by: EdKlotz


     

     

    If you're not sure how to model your quadratic function, in general I'd recommend starting with a simpler quadratic function, like f(x) = x^2, get that working, and gradually add terms after that. 

    Your situation is only slightly different than what I posted previously, because you have a linear term as well as a quadratic term.   So you are looking at

     

    z ==1 --> x'Qx + c'x <= b

     

    and the linearization you want to use is

     

    x'Qx + c'x + Mz<= b + M

     

    In your case, the quadratic part is ax^2  + exy  + cy^2

    and the linear part is

    bx  + dy + f.

    So in DoCplex you add the linear constraint

     

    ax^2  + exy  + cy^2 + bx  + dy + f.+ Mz <= B + M

     

    and it should give you what you want.   Regarding deriving a reasonable bound on f(x,y) that you can use for M, you can use the upper (and possibly lower) bounds on x and y to do that.   I'm doing to assume a, e, c, b, d and f are all >= 0, so that we only need consider the upper bounds.   If some of those values are negative, we'd need to consider lower bounds as well, but the idea is basically the same, namely that if U1 and U2 are the upper bounds on x and y, then

    ax^2  + exy  + cy^2 + bx  + dy + f. <= aU1^2 + eU1*U2 + cU2^2 + bU1 + dU2 + f

     

    Use this bound on your f(x,y) as your big M value.   Hopefully your U1 and U2 bounds, and your a, b, c, d, e and f values are all fairly reasonable, to this value of M is modest, and spares you potential numerical troubles if you pick an arbitrarily large value.   But if not, you can also try solving

     

    max f(x,y)

    s.t.

    <all other constraints in the model>

     

    and hopefully that will give you a tighter value for M.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Adding a quadratic constraint in If-Then

    Posted 01/02/20 11:02 AM

    Originally posted by: tackoo


    Thank you for the detailed explanation. I am now realizing that there are some other differences in my problem setup.

     

    The first difference in my problem is z is not binary. It can rather have integer values 1,2,...,10. And I basically want a,b,c,d,e,f to assume different (known) values based on the integer value of z. I think the way you described above won't work in this case.

     

    Another difference is my RHS is also a == constraint rather than <= you have above. Maybe I can model this == constraint by including both UB and LB in a tight manner, but not sure about this either. 


    #CPLEXOptimizers
    #DecisionOptimization