Originally posted by: SystemAdmin
I see several issues:
1) if you put 1,2,3 in a cell in Excel, that cell will be treated as a string, not a set of integers. 2) OPL does not support reading arrays of sets from Excel. Here is an extract from the
documentation "The types of data elements supported are the same as for databases, plus arrays with one or two dimensions:
sets with integers, floats, strings, or tuples;
arrays with integers, floats, strings, or tuples with up to two dimensions;
Only tuples with integer, float, and string components are supported."
However, what you're trying to is possible using a little script.
1) read the data from Excel using an array of string.
2) create the array of sets of integers from that array of string
assuming your Excel spreadsheet has 4 cells as you described:
string myArray[1..4] = ...;
{
int
} mySet[1..4]; execute
{
for (var i=1;i<=4;i++)
{ var temp =
new Array(); temp = myArray[i].split(
',');
for (var j=0;j<temp.length;j++) mySet[i].add(temp[j]);
}
}
Another option, if you have one integer per cell in your spreadsheet, and assuming you know the maximum number of elements in your sets would be to
1) read a 2-dimensional array of integers
2) create your array of sets of integers from that first array
Here is an example:
int myArray2[1..4,1..maxSetSize] = ...;
{
int
} mySet2[i in 1..4] =
{myArray2[i][j] | j in 1..maxSetSize : myArray2[i][j] != 0
};
#DecisionOptimization#OPLusingCPLEXOptimizer