L
Loane Sharp
Hi there
I have a two-dimensional array with 53 "rows" and 11 "columns". The array
values are either "1" or "0", indicating whether a person is working ("1")
or not-working ("0") during each of 11 hourly shifts in a day. The 53 rows
represent different ways in which a person could work. For instance,
concatenating one row of the array yields a string of "01111000000", which
indicates that a person is scheduled to work 4 consecutive hours (ie. the 4
"1"s) from the second hour of the day (ie. the position of the first "1", in
this case 9am). The 53 permutations are not complete: some have been
excluded since they don't represent a realistic work pattern. For example,
the string "01010101010" represents too uneven a pattern of work, while the
string "01000000010" presents too big a stretch between the person's two
shifts.
Two questions arise:
Firstly, how can I use a VBA procedure to generate all possible permutations
for two, three, four and more people? (Am I right to say that the total
number of permutations for n people is 53^n? If so, then the number of
permutations expands rapidly: 53; 2,809; 148,877; 7,890,481; and so on.
Nonetheless I need to write the different permutations out.)
Secondly, how do I generate only the distinct permutations? For instance, in
the case n=2, there are 2,809 (=53^2) permutations but there are only 1,481
(=53+52+51+50+...+1) distinct permutations. If I'm right, to get only the
distinct permutations, I add the values in each "row" of the original array
(ie. case n=1) to each row in the array for case n=k, omitting the case k=n.
Any suggestions would be gratefully appreciated!
Best regards
Loane
I have a two-dimensional array with 53 "rows" and 11 "columns". The array
values are either "1" or "0", indicating whether a person is working ("1")
or not-working ("0") during each of 11 hourly shifts in a day. The 53 rows
represent different ways in which a person could work. For instance,
concatenating one row of the array yields a string of "01111000000", which
indicates that a person is scheduled to work 4 consecutive hours (ie. the 4
"1"s) from the second hour of the day (ie. the position of the first "1", in
this case 9am). The 53 permutations are not complete: some have been
excluded since they don't represent a realistic work pattern. For example,
the string "01010101010" represents too uneven a pattern of work, while the
string "01000000010" presents too big a stretch between the person's two
shifts.
Two questions arise:
Firstly, how can I use a VBA procedure to generate all possible permutations
for two, three, four and more people? (Am I right to say that the total
number of permutations for n people is 53^n? If so, then the number of
permutations expands rapidly: 53; 2,809; 148,877; 7,890,481; and so on.
Nonetheless I need to write the different permutations out.)
Secondly, how do I generate only the distinct permutations? For instance, in
the case n=2, there are 2,809 (=53^2) permutations but there are only 1,481
(=53+52+51+50+...+1) distinct permutations. If I'm right, to get only the
distinct permutations, I add the values in each "row" of the original array
(ie. case n=1) to each row in the array for case n=k, omitting the case k=n.
Any suggestions would be gratefully appreciated!
Best regards
Loane