Originally posted by: Calvin Sun Hainan
Thanks. Realy smart solution. I never thought about using count in this way. The following is my solution, and it is not efficient.
tuple twoInt {
int a;
int b;
}
twoInt array[1..9] = [<13,1>, <18,1>, <13,1>, <14,1>, <13,1>, <16,1>, <14,1>, <21,1>, <13,1>];
{int} diffValuesInArray = {x.a | x in array};
int countForEachValue[diffValuesInArray] = [d : sum (x in array : x.a == d) x.b | d in diffValuesInArray];
int mode;
execute {
var count = 0;
for (var x in diffValuesInArray) {
if ( count < countForEachValue[x]) {
mode = x;
count = countForEachValue[x];
}
}
#DecisionOptimization#OPLusingCPLEXOptimizer