Skip to main content

Dynamic tuple set array initialization and population using OPL script


Technote (FAQ)


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.


Cross reference information
Segment Product Component Platform Version Edition
Business Integration IBM ILOG CPLEX Optimization Studio Area:ILOG Script for OPL/OPL Script AIX, Linux, Windows 12.4, 12.3, 12.2.0.1, 12.2 All Editions

Rate this page:

(0 users)Average rating

Copyright and trademark information

IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.

Rate this page:


(0 users)Average rating

Add comments

Document information

IBM ILOG OPL-CPLEX Development Bundles

Area:ILOG Script for OPL/OPL Script


Software version:
6.0, 6.0.1, 6.1, 6.1.1, 6.2, 6.3, 12.2, 12.3, 12.4


Operating system(s):
AIX, Linux, Windows


Software edition:
All Editions


Reference #:
1616064


Modified date:
2012-11-14

Translate my page

Content navigation