Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  define a binary variable given an integer variable!

    Posted 07/17/19 12:36 AM

    Originally posted by: zab.a


    Hi there

    I am working on modeling a problem where I have a binary variable which is dependent on the values of integer variables of the model 

    I need to define a binary variable in cplex  y[i][j]=1 if x[i]>x[j] , 0 otherwise . where x[i] and x[j] are decision variables

    how to do this?

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: define a binary variable given an integer variable!

    Posted 07/17/19 04:55 AM

    Hi,

    let me share a tiny example in OPL:

    range R=1..4;
    dvar int x[R];
    dvar boolean y[R][R];

    subject to
    {
    forall(ordered i,j in R) y[i][j]==(x[i]>=x[j]);
    }

    regards


    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: define a binary variable given an integer variable!

    Posted 07/17/19 11:58 AM

    Originally posted by: zab.a


    Thank you AlexFleischer for your answer,

    for the constraint :

    I have two issues 

    1-  y[i][j]=1 if (x[i]>x[j]) , "> instesd >=" . but using > gives me error .

    2- i want to exptess the following  in this constarint

    y[i][j]=1 if x[i]>x[j] , where i in range R=1..n,  j=i+1..n 

    i am attaching the code text file

    Thanks in Advance 

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: define a binary variable given an integer variable!

    Posted 07/17/19 12:16 PM

    Hi,

    then you could use an epsilon to use >= for >

    int P[ i in cont]=i;
    int Amax=10;

    //variables

    dvar int+ x[cont];
    dvar boolean y[cont][cont];  


    // model

        // objective function
        
    minimize  sum (i,j in cont) y[i][j];

        // constaints
    subject to {

    forall (i in cont) abs(x[i]-P[i])<=Amax;
    forall ( ordered i,j in cont) y[i][j]==(x[i]>=x[j]+epsilon);

    }

    works fine

     

    regards


    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: define a binary variable given an integer variable!

    Posted 08/02/19 07:46 PM

    Originally posted by: EdKlotz


    Just a quick note on Alex's last response.   If the x variables are integer, which appears to be the case, you should just use epsilon = 1.0.   If they are continuous, then you need to use something smaller, and you need to think carefully about the proper choice given the other coefficients in your model and the feasibility tolerance used (CPLEX's default is 1e-6).


    #DecisionOptimization
    #MathematicalProgramming-General