IBM Support

Dynamic tuple set array initialization and population using OPL script

Question & Answer


Question

How do I dynamically initialize and populate tuple set arrays using OPL script?

Answer

Here's a sample to dynamically initialize and populate a tuple set array indexed over another tuple set:


tuple TIndex{
  key int id;
}
tuple TIndexedArray{
  key int id;
  key int value;
}
{TIndex} index;
{TIndexedArray} indexedArray[index];
execute {
  var i, j, k, ti;
  for (i=0; i<5; i++){
    index.add(i);
  }
  for (i=0;i<5;i++){    
    ti = index.get(i);
    for(j=0;j<2;j++){
    k = 10*i+j;
    indexedArray[ti].add(j,k);
    }    
  }
  writeln("index="+index);
  writeln("indexedArray="+indexedArray);
}  

Users need to aware about the concepts of 'lazy initialization' in OPL. Care must be taken that the indexer tuple set is completely populated before touching the dependant tuple set array. More about the pitfalls of lazy initialization can be found in the here.

[{"Product":{"code":"SSSA5P","label":"IBM ILOG CPLEX Optimization Studio"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Area:ILOG Script for OPL\/OPL Script","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"12.2;12.3;12.4;6.0;6.0.1;6.1;6.1.1;6.2;6.3","Edition":"All Editions","Line of Business":{"code":"LOB10","label":"Data and AI"}},{"Product":{"code":"SSSA5P","label":"IBM ILOG CPLEX Optimization Studio"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Area:ILOG Script for OPL\/OPL Script","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"12.4;12.3;12.2.0.1;12.2","Edition":"All Editions","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 June 2018

UID

swg21616064