Hi,
at https://www.ibm.com/developerworks/community/forums/html/topic?id=1a9f94fb-8ca7-4ac1-aaef-786c44e8ee31&ps=25
I explained how to convert an OPL tuple set into a python list.
And since then I got some questions about how to do the same with arrays.
So let me share an example:
execute
{
// turn an OPL array into a python list
function getPythonListOfArray(_array)
{
var quote="\"";
var nextline="\\\n";
var res="[";
for(var i in _array)
{
var value=_array[i];
if (typeof(value)=="string") res+=quote;
res+=value;
if (typeof(value)=="string") res+=quote;
res+=",";
//res+=nextline; // if you need one item per line, uncomment this line
}
res+="]";
return res;
}
}
string s[1..3]=["A","B","C"];
int i[1..10]=[8,7,1,2,3,7,8,1,6,-3];
execute
{
writeln(getPythonListOfArray(s));
writeln(getPythonListOfArray(i));
}
gives
["A","B","C",]
[8,7,1,2,3,7,8,1,6,-3,]
regards
#DecisionOptimization#OPLusingCPLEXOptimizer