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);
}
| 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:
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.