Topic
  • 4 replies
  • Latest Post - ‏2013-11-12T19:53:15Z by AlexFleischer
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic accessing an specific element of a tuple which is an array to modify it

‏2013-03-20T15:51:32Z |
Hi,

I want to access an specific element of a tuple.

My tuple has a structure like:

range Products = 1..5;

tuple sset {
key int id;
int presence Products ; // presence is an array of Products
}

{sset} ssetbas = ...;
and I initialize ssetbas by:

ssetbas = {
<0, 1, 1, 0, 0, 0>
<1, 1, 0, 55, 0, 0>
};

I am wondering for example how I can access the 3th item in the second row (id =1) which is 55.
I mean by which syntax in script I can retrieve the element which is 55?
Updated on 2013-03-27T18:35:24Z at 2013-03-27T18:35:24Z by SystemAdmin
  • AlexFleischer
    AlexFleischer
    2075 Posts

    Re: accessing an specific element of a tuple which is an array to modify it

    ‏2013-03-27T11:54:54Z  
    Hi

    range Products = 1..5;
     
    tuple sset {
    key int id;
    int presence[Products] ; // presence is an array of Products
    }
     
    {sset} ssetbas = ...;
     
    execute
    {
     writeln(Opl.item(ssetbas,1).presence[3]); 
    }
    


    regards
    Updated on 2014-03-26T05:50:06Z at 2014-03-26T05:50:06Z by AlexFleischer
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: accessing an specific element of a tuple which is an array to modify it

    ‏2013-03-27T18:35:24Z  
    Hi

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">range Products = 1..5; tuple sset { key int id; int presence[Products] ; // presence is an array of Products } {sset} ssetbas = ...; execute { writeln(Opl.item(ssetbas,1).presence[3]); } </pre>

    regards
    Thank you Alex!
  • ikucukkoc
    ikucukkoc
    47 Posts

    How to modify a tuple? Need Urgent Help Please??

    ‏2013-11-12T17:11:50Z  
    Hi

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">range Products = 1..5; tuple sset { key int id; int presence[Products] ; // presence is an array of Products } {sset} ssetbas = ...; execute { writeln(Opl.item(ssetbas,1).presence[3]); } </pre>

    regards

    Dear SystemAdmin

    I am using CPLEX and I need to preprocess data before the optimisation.

    In simplified version, I have a tuple "TaskTimes" as below and l need to modify the last column of every row by multiplying with a constant value, say 5.

    Sample.mod file

    tuple task { 
      int h; 
      string j; 
      int i; //
      string x; 
      float pt; 
    }

    {task} TaskTimes = ...;

     

    Sample.dat file:

    TaskTimes = {

    <1 A 1 L 3>,
    <1 A 2 R 3>,
    <1 A 3 E 0>,
    <1 A 4 L 2>,
    <1 A 5 E 2>,
    };

    Consequently; I should obtain following tuple:

    TaskTimes = {

    <1 A 1 L 15>,
    <1 A 2 R 15>,
    <1 A 3 E 0>,
    <1 A 4 L 10>,
    <1 A 5 E 10>,
    };

    Your prompt help and support is highly acknowledged.

    Many thanks.

    Best Regards

    Ibrahim

        
  • AlexFleischer
    AlexFleischer
    2075 Posts

    Re: How to modify a tuple? Need Urgent Help Please??

    ‏2013-11-12T19:53:15Z  
    • ikucukkoc
    • ‏2013-11-12T17:11:50Z

    Dear SystemAdmin

    I am using CPLEX and I need to preprocess data before the optimisation.

    In simplified version, I have a tuple "TaskTimes" as below and l need to modify the last column of every row by multiplying with a constant value, say 5.

    Sample.mod file

    tuple task { 
      int h; 
      string j; 
      int i; //
      string x; 
      float pt; 
    }

    {task} TaskTimes = ...;

     

    Sample.dat file:

    TaskTimes = {

    <1 A 1 L 3>,
    <1 A 2 R 3>,
    <1 A 3 E 0>,
    <1 A 4 L 2>,
    <1 A 5 E 2>,
    };

    Consequently; I should obtain following tuple:

    TaskTimes = {

    <1 A 1 L 15>,
    <1 A 2 R 15>,
    <1 A 3 E 0>,
    <1 A 4 L 10>,
    <1 A 5 E 10>,
    };

    Your prompt help and support is highly acknowledged.

    Many thanks.

    Best Regards

    Ibrahim

        

    Hi,

     

    could

    {task} TaskTimes2 = {<e.h,e.j,e.i,e.x,5*e.pt> | e in TaskTimes};
    execute
    {
     
      TaskTimes2;
     
     
    }

     

    help ?

     

    regards