Thursday, April 30, 2009

If-then-else in AMPL/Cplex

I´m making my final project working with AMPL and nobody in my university can help me. […] The question is the following: I must take a decision over a variable, DECISION[n]. This variable can be a number between 0 to 64. I want to obtain another variable, RESULT[n], that if the first variable is Zero, the second one is zero too. In the other cases, must be 1. In C language it could be: if DECISION[n] =0 then RESULT[n]=0 (else RESULT[n]=1). i´m working with CPLEX.

E.g. using Cplex indicator constraints:

EQ{n in N}: RESULT[n]=0 ==> DECISION[n]=0 else DECISION[n]>=0.0001;

You really should get advise from your professor. He/she gets paid to help you with this.


  1. I don't know you found your answer by now or not, but this is your solution:

    Result[n] <= M * Decesion[n]
    Decesion[n] <= Result[n] * M

    M should be an arbitrary big value and you should define Decision[n] as a binary value.

  2. Actually M should *not* be an arbitrary large value. One need to put some thought in determining a good value for M. This makes these indicator constraints attractive: there is no need to find a good big-M value.

    To be more precise in your formulation you even need two different values M1 and M2 instead of one.

    You say DECISION is binary, but the poster indicates it is not.