Initializing tuplesets and tuple arrays using OPL script

Technote (FAQ)


How do I initialize tuplesets and tuple arrays using OPL script?


The following sample shows one such way to initialize tuplesets and tuple arrays:

tuple tupleAB {
  key int a;
  int b;
//declare tupleset tAB
{tupleAB} tAB = {};
tuple tupleCD{
  key int c;
  int d;
//declare tupleset tCD
{tupleCD} tCD = {};
tuple tupleX{
  key int xA;
  tupleCD t;
//declare tupleset tX
{tupleX} tX = {};
//declare tuple array cdArray
tupleCD cdArray[x in tAB];
  //initialize tAB
  var t1 = tAB.add(1,11);
  var t2 = tAB.add(2,22);
  //initialize tCD
  var t3 = tCD.add(3,33);
  var t4 = tCD.add(4,44);
  //initialize tX
  //initialize cdArray
  //method 1: get the tuple item
  cdArray[tAB.get(1)] = tX.get(tAB.get(1).a).t;
  cdArray[tAB.get(2)] = tX.get(tAB.get(2).a).t;
  //method 2: direct initialization- when you have access to the tuple element
  cdArray[t1] = t3;
  cdArray[t2] = t4;
execute PRINT {

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

Rate this page:

(0 users)Average rating

Add comments

Document information

More support for:

IBM ILOG CPLEX Optimization Studio
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, 12.5,

Operating system(s):

AIX, Linux, Windows

Software edition:

All Editions

Reference #:


Modified date:


Translate my page

Machine Translation

Content navigation