Thanks a lot in advance . trouble in how to generate relationship between two enumerate .
%-------------------------------
enum weeks = {w1,w2,w3,w4};
array[weeks] of 1..10 : weekShiftQty = [4,5,7,4]; % total shift = 20
enum shift = _(1..20);
array[shift] of weeks : shiftWeek = [ % how to generate shiftWeek relationship %
% just like following : calculate shift belog to which week base on weekShiftQty
% shiftWeek[1] = w1 , ... , shiftWeek[4] = w1 ,
% shiftWeek[5] = w2 ,... , shiftWeek[9] = w2 ,
% shiftWeek[10] = w3 ,... , shiftWeek[16] = w3 ,
% shiftWeek[17] = w4 ,... , shiftWeek[20] = w4 ,
| s in shift
];
%-------------------------------
Here's a solution, i.e. using [ w | w in weeks, _ in 1..weekShiftQty[w]]
to generate the shiftWeek
array:
enum weeks = {w1,w2,w3,w4};
array[weeks] of 1..10 : weekShiftQty = [4,5,7,4]; % total shift = 20
enum shift = _(1..20);
array[shift] of weeks: shiftWeek = [
w
| w in weeks,
_ in 1..weekShiftQty[w]
];
output [
"shiftWeek: \(shiftWeek)\n"
];
The output is
shiftWeek: [w1, w1, w1, w1, w2, w2, w2, w2, w2, w3, w3, w3, w3, w3, w3, w3, w4, w4, w4, w4]