Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

How to convert array into tuple

  • 1.  How to convert array into tuple

    Posted Sat December 14, 2019 12:01 PM

    Originally posted by: Mathsg


    Hi, i am having array with 4 index and declared it as a decesion variable. I am interested to extend the size of one index through sub problem but as for i know we cant add new column to an array. i am intersted to declare it as an tuple. can i do it? i have tried it for integer linear programing but it give me wrong solution

     

    i.e., int dvar lemda[i][j][u][v];

    Now i am intersted to declear it like 

    tuple Index {
    int pp;
    int qq;
    int rr;
    int ss;
    }  
    {Index} indeces = ...;
    dvar int gega[indeces];

    but it give me wrong solution as it cant support the one constraint which is

    forall (i in flows, u in nodes, v in nodes)
         Const5:
         sum(p in indeces)p.qq == k[i][u][v];
    i am interested to write it like when i declare it as an array

    forall ( i in flows,  u in nodes, v in nodes)
           Const5:
          sum(j in routes)lemda[i][j][u][v]== k[i][u][v];
    Kindly advice me. thank you


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to convert array into tuple

    Posted Mon December 16, 2019 09:06 AM

    Hi,

    let me share a small example:

    tuple Index {
    int pp;
    int qq;
    int rr;
    int ss;
    }  
    {Index} indeces = {<p,q,r,s> | p in 1..2,q in 1..3,r in 1..2,s in 1..2};

    int v[<p,q,r,s> in indeces]=p+q+r+s;

    // Now let us turn this into a tuple set

    tuple t
    {
      Index i;
      int value;
    }

    {t} tupleset={<<p,q,r,s>,v[<p,q,r,s>]> | <p,q,r,s> in indeces};

    execute
    {
      writeln("tupleset=",tupleset);
    }

    // And now we can grow the tuple set as we like

    execute
    {
      tupleset.add(1,2,10,10,100);
      writeln("tupleset=",tupleset);
    }

     

    gives

     

    tupleset= {<<1 1 1 1> 4> <<1 1 1 2> 5> <<1 1 2 1> 5> <
            <1 1 2 2> 6> <<1 2 1 1> 5> <<1 2 1 2> 6> <
            <1 2 2 1> 6> <<1 2 2 2> 7> <<1 3 1 1> 6> <
            <1 3 1 2> 7> <<1 3 2 1> 7> <<1 3 2 2> 8> <
            <2 1 1 1> 5> <<2 1 1 2> 6> <<2 1 2 1> 6> <
            <2 1 2 2> 7> <<2 2 1 1> 6> <<2 2 1 2> 7> <
            <2 2 2 1> 7> <<2 2 2 2> 8> <<2 3 1 1> 7> <
            <2 3 1 2> 8> <<2 3 2 1> 8> <<2 3 2 2> 9>}
    tupleset= {<<1 1 1 1> 4> <<1 1 1 2> 5> <<1 1 2 1> 5> <
            <1 1 2 2> 6> <<1 2 1 1> 5> <<1 2 1 2> 6> <
            <1 2 2 1> 6> <<1 2 2 2> 7> <<1 3 1 1> 6> <
            <1 3 1 2> 7> <<1 3 2 1> 7> <<1 3 2 2> 8> <
            <2 1 1 1> 5> <<2 1 1 2> 6> <<2 1 2 1> 6> <
            <2 1 2 2> 7> <<2 2 1 1> 6> <<2 2 1 2> 7> <
            <2 2 2 1> 7> <<2 2 2 2> 8> <<2 3 1 1> 7> <
            <2 3 1 2> 8> <<2 3 2 1> 8> <<2 3 2 2> 9> <
            <1 2 10 10> 100>}

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer