Initializing tuplesets and tuple arrays using OPL script

Technote (FAQ)


Question

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

Answer

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];
execute PREPROCESSING {
  //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
  tX.add(1,t3);
  tX.add(2,t4);
  //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 {
writeln("tAB="+tAB);
writeln("cdArray="+cdArray);
}


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.0.1, 12.5, 12.4, 12.3, 12.2.0.1, 12.2 All Editions

Rate this page:

(0 users)Average rating

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, 12.5.0.1

Operating system(s):

AIX, Linux, Windows

Software edition:

All Editions

Reference #:

1595921

Modified date:

2012-05-22

Translate my page

Machine Translation

Content navigation