Decision Optimization

 View Only
  • 1.  Min Index in int Array

    Posted Tue April 02, 2019 08:05 AM

    Originally posted by: trxw


    Hi,

     

    My first post and complete new in this CPLEX world!

    I have a 2D integer array (OrdenDeEntrada[person][instant]) with values 1 or 0 that means if a person is working or not in an instant. I want to build an dexpr which returns the lowest value of the index where we can find the first "1", i.e. time where this person starts working. From another post I manage to build a similar issue but with the exit time (OrdenDeSalida[person][instant] ) but I cannto figure out how to do it for the starting time

     

    dexpr int OrdenDeSalida[i in person] = max(t in instant) (CtaTrabajando[i][t]==1)*t;  // This is the exit order which works fine

    dexpr int OrdenDeEntrada[i in person] = min(t in instant) ((CtaTrabajando[i][t]==1)*(t));  // Returns always 0 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Min Index in int Array

    Posted Tue April 02, 2019 02:31 PM

    Hi

    does the range "instant" contain 0 ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Min Index in int Array

    Posted Tue April 02, 2019 02:59 PM

    Originally posted by: trxw


    No 0. From 1 to 47


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Min Index in int Array

    Posted Tue April 02, 2019 03:37 PM

    hi

    min cannot work because you need 1 for the decision variable and not 0

    let me an example that could help you

    int N=10;
    range instant = 1..N;
    dvar boolean x[instant];

    dexpr int OrdenDeSalida = max(t in instant) (x[t]==1)*t;  // This is the exit order which works fine
    dexpr int OrdenDeEntrada = N+1-max(t in instant) ((x[t]==1)*(N+1-t));   

    subject to
    {
    forall(i in instant) (x[i]==1) == (3<=i<=7);
    }

    execute
    {
    writeln(OrdenDeSalida);
    writeln(OrdenDeEntrada);
    }

    which gives

     

    7
    3

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Min Index in int Array

    Posted Tue April 02, 2019 03:26 PM

    Originally posted by: trxw


    In fact, I find quite hard to operate with this arrays. Maybe I have not defined the right data type or just my ignorance. What I mean is that I need as well to count the number of "1" ending in the CtaTrabajando[person][Instantes] when the last value of the array is 1 (i.e. if a person works on the last instant, I need to count how many "1" are in that last rotation, so how many consecutive "1" are there)

     

    Example:  

    CtaTrabajando[1][Instantes]: 1 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1   Count should be 3

    CtaTrabajando[2][Instantes]  1 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 0   Count should be 0

     

    This is a dexpr so I could use it in a minimize staticLex (MaxTT-MinTT, LastRotation); 

     

    Hope it's clear... Thanks so much


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Min Index in int Array

    Posted Wed April 03, 2019 04:43 AM

    Originally posted by: trxw


    Thank you so much. It works great!!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer