How to find the number of elements in set in opl Cplex

16 Views Asked by At

Suppose I have a time-varying set. I want to determine the number of elements in the set at each period. How to do code of the above problem in opl CPLEX. The time-varying set is given below in tuple.

tuple TimeVaryingSet {
int Slot;
{int} values;
}
TimeVaryingSet Damagedlines[Slot] = [
<1,{30,67,17,54,12,49,11,48}>,
<2,{30,67,17,54,12,49,11,48}>,
<3,{17,54,12,49,11,48}>,
<4,{17,54,12,49,11,48}>,
<5,{17,54,12,49,11,48}>,
<6,{12,49,11,48}>,
<7,{11,48}>,
<8,{}>
];

Now I want to create an array that contains the number of elements of the set at each period. Here I have considered 8 time periods. How to do coding of the above problem in opl cplex

1

There are 1 best solutions below

0
Alex Fleischer On

You can use "card"

range Slot=1..8;
tuple TimeVaryingSet {
int Slot;
{int} values;
}
TimeVaryingSet Damagedlines[Slot] = [
<1,{30,67,17,54,12,49,11,48}>,
<2,{30,67,17,54,12,49,11,48}>,
<3,{17,54,12,49,11,48}>,
<4,{17,54,12,49,11,48}>,
<5,{17,54,12,49,11,48}>,
<6,{12,49,11,48}>,
<7,{11,48}>,
<8,{}>
];

int nb[s in Slot]=card(Damagedlines[s].values);

execute
{
  writeln(nb);
}

gives

 [8 8 6 6 6 4 2 0]