Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Using multi-dimensional arrays and a one-dimensional "tuple"-array in one constraint

  • 1.  Using multi-dimensional arrays and a one-dimensional "tuple"-array in one constraint

    Posted 09/24/15 06:04 PM

    Originally posted by: CaWa


    Hi,

    I am writing an optimization program with CPLEX Studio IDE 12.6 and I had a question concerning the right handling of tuple arrays.

    I am reading one-dimensional arrays from Excel as input parameters whose  type is a tuple:  tupleType array[X] = ..;

    As decision variables I need to determine a 4-dimensional array: dvar int T[A][B][C][D];

    Now I need to define several constraints concerning T which I formulated as follows:

     

    
    //tuple definition
    
    range X = ...;
    
    
    tuple 
    tupleType { 
     
    int a; 
    int b; 
    int 
    Value;
    }
    tupleType array[X] = ...;
    
    //decision variable
    dvar int T[A][B][C][D] in 0..1;
    
    //constraint
    forall (a 
    in A, b 
    in B, 
    i 
    in X) {
     
     if (array[
    i].a == a && array[
    i].b == 
    b) { 
        sum (c 
    in C, d 
    in D) 
    T[a][b][c][d] == array[
    i].
    Value; 
      } else {
       
    sum (c 
    in C, d 
    in D) 
    T[a][b][c][d] == 0;
     }
    
    }
    

    Does anyone know if I can adress a specific tuple as in the if-clause? Or how do I usually adress a tuple pair?

    Because I need to make sure that the array is zero when the indices aren't the same and contain the value of the tuplepair when the indices are the same.

    Right now it assigns to the whole matrix T[a][b][c][d] 0.

     

    Thanks in advance for your help!

    P.S.: And I was also wondering how I could formulate the decision variable T[a][b][c][d] also as a 1-dim. tuple array but I don't know if that's possible since I don't know the length of the array in advance. Am I right?


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Using multi-dimensional arrays and a one-dimensional "tuple"-array in one constraint

    Posted 10/15/15 08:59 AM

    What exactly do you mean by "Right now it assigns to the whole matrix T[a][b][c][d]=0"? Do you get a constraint "T[a][b][c][d]==0" for each combination of a,b,c,d? Or do the values just happen to be 0 in the solution (which may be feasible depending on the values in array[])? Could you provide the .dat file you are using with your model?

    I think you cannot put a decision variable into a tuple. Would it instead be an option to create a set of tuples and use that set to index the decision variable?

    In any case, note that there is a dedicated forum for questions about OPL. You may get better answers there.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: Using multi-dimensional arrays and a one-dimensional "tuple"-array in one constraint

    Posted 11/05/15 02:47 PM

    Hi,

    slicing is better than if then else:

    range X = 1..3;
     range A=1..3
    ;
    range B=2..4;
    range C=1..2;
    range D=1..2;


    tuple
    tupleType {
     
    int a;
    int b;
    int
    Value;
    }
    tupleType array[i in X] = <i,i+1,i+2>;

    //decision variable
    dvar int+ T[A][B][C][D];

    subject to
    {
    //constraint
    forall (a
    in A, b
    in B,
    i
    in X:(array[
    i].a == a && array[
    i].b ==
    b)) {
     
      {
        sum (c
    in C, d
    in D)
    T[a][b][c][d] == array[
    i].
    Value;
      };
     

     

    }};

    About your PS, you can index a one dimension array by a tuple set

     

    regards


    #DecisionOptimization
    #MathematicalProgramming-General