Decision Optimization

Expand all | Collapse all

cplex opl map tuple set to a int set

  • 1.  cplex opl map tuple set to a int set

    Posted Sun July 19, 2020 08:00 AM
    Hello,

    please advise regarding a mapping of int set and a tuple set.

    Suppose, I have an int set of 5 scenarios:
    {int} S={1,2,3,4,5};

    I also have a tuple set "orders"consisting of 10 tuples:
    tuple Orders{ 
    key int tuple_id; 
    int from_node; 
    int to_node; 
    }
    {Orders} orders= {<1,1,2>, <2,1,3>, <3,1,2>, <4,1,2>, <5,1,2>, <6,1,2>, <7,1,2>, <8,1,2>, <9,1,2>, <10,1,2>};

    How could I map every two orders from "{DamandData} orders " to each scenario?
    So that, for eaxmple, S=1 corresponds to orders <1,1,2>, <2,1,3> , S=2 to <3,1,2>, <4,1,2> and so on?

    I will be gratefull for any advice.
    Thank you
    BR,Irina

    ------------------------------
    Irina
    ------------------------------


  • 2.  RE: cplex opl map tuple set to a int set

    Posted Sun July 19, 2020 04:40 PM
    Hi,

    you could start with

    {int} S={1,2,3,4,5};
    
    
    tuple Orders{ 
    key int tuple_id; 
    int from_node; 
    int to_node; 
    }
    {Orders} orders= {<1,1,2>, <2,1,3>, <3,1,2>, <4,1,2>, <5,1,2>, <6,1,2>, <7,1,2>, <8,1,2>, <9,1,2>, <10,1,2>};
    
    {Orders} ordersPerScen[i in S]={ item(orders,(i-1)*2) } union { item(orders,(i-1)*2+1) };
    
    execute
    {
      writeln(ordersPerScen);
    }​


    which gives

    [{<1 1 2> <2 1 3>} {<3 1 2> <4 1 2>} {<5 1 2> <6 1 2>} {
            <7 1 2> <8 1 2>} {<9 1 2> <10 1 2>}]
    ​

    regards

    ------------------------------
    ALEX FLEISCHER
    ------------------------------