Suppose we have a table with 8 rows and 30 (or 31) columns.
We have to label each cell with G and N, respecting the following rules (sometimes some other constraint is added )
- Each column (i.e. each day) must have exactly one G and one N, eventually in the same cell (GN)
- Each row must have exactly g G and n N, where g and n are given input values, usually in {3,4} [of course sum(g)==sum(n)==30(31)]
- The cells containing xx are forbidden for both N and G; xg are forbidden for G and xn are forbidden for N
- For each row, 3 consecutive days with G (or with N) for the same row are forbidden
- For each row, 3 days with GN are forbidden (preferably only one GN, except for row r, âwhoâ prefer as many GNs as possible)
- For each row you canât have G following a N
- Canât have 3 cells ( N or G) during the weeks end in the same row
PS
I solved the practical problem in an âartisanalâ way, but Iâm curious to know if this falls into some category that is treated by some package or in any case algorithms suitable for this type of problem are known
I attach an example of an input table
gio ven sab dom lun mar mer gio ven sab dom lun mar mer gio ven sab dom lun mar mer gio ven sab dom lun mar mer gio ven
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 g n
R1 xx xx xx xx xx xx 4 3
R2 xx xx xx xx xx xx xx xg xx xx xx xx xx xx 4 4
R3 xx xg xx xx xx xx xx xx xx xx xx xx xx xx xg xx xx xx xx xx xx xx 4 4
R4 xg xg xx xx xx xx xx xx xx xx 4 3
R5 xx xx xx xx xg xg xg xx xx xx xx xx xx xx xx xx xx xx xx xx xx 3 4
R6 xx xx xx xx xn xg xn xx xx xn xn xx xn xx xx xx xn xn xn 4 4
R7 xx xx xx xx xx xx xx xx xx xx xx 3 4
R8 xx xx xx xx xx xx xx xx xx xx xx xx xx xx 4 4