A teacher works n hours max days per week

Started by enricodn, February 21, 2026, 05:48:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

enricodn

Hi guys,
I am sure that this problem has a solution, but I cannot find anything similar in the forum.
I made timetable for my Italian school. My constraints are very simple; for all teachers: max 5 hours daily, max 5 days per week, min 2 hours daily, min 5 days per week, max 1 gap daily, max 3 gaps per week. Every day is 6 hours long for students: from 8:00 to 14:00.

The software is great and everything is ok but now I need one more constraint for teachers: every teacher must work 6 hours (including 1 gap) for max 2 days per week. In fact, considering my constraints, it can happen that a teacher works a total of 6 hours (from 8:00 to 14:00) for 3 days (including 3 gaps) and I want to avoid this for educational reasons.
This means, in other words, that a teacher can start at 8:00 and end at 14:00 for no more than 2 times a week.

Is it possible to do that? And how? I hope to explain my problem clearly.

Thank you very much.

Liviu Lalescu

Hello, enricodn, and welcome to the forum!

Unfortunately, maybe your problem has not an exact/perfect solution. But, we might use tricks:

1) There is teacher(s) max span per day, allowing 1 day of exception of +1. Unfortunately, in the program code it was already very difficult to add the option of one exception day - for two days it might be too complicated to code.

2) There is also the constraint teacher(s) interval max days per week. You might want to consider this for instance to ensure that from 1st to 2nd hour the teacher(s) work only 3 days per week.

3) Try to think of the relatively new constraints teachers occupy max sets of time slots from selection. You might add more such constraints, for each tuple of 3 days. Combinations of 6 by 3 is 20 I think, so 20 constraints to add. For Monday, Tuesday, Wednesday: add all 6 slots of the first and the last hours of each day (the numbers in the spin boxes of the constraint are 1..6), max occupied = 5.

Maybe (3) is perfect, but you need to check it practically. Please let me know!

enricodn

Hallo Liviu,
thank you for your fast reply. I will try the 3rd trick in the next days and I will let you know.
See you soon  :)

Vangelis Karafillidis


enricodn

Hello Liviu,
I used your trick and it works! Then, I made combinations of 6 by 3, for a total of 20, using the constraint "all teachers interval max days per week", max occupied = 5. I also made another test for combinations of 6 by 2 (15 combinations) to limit to max 1 day each teacher works from 1st hour to last hour (max occupied = 3). Even if this is a very strong constraint, it also works! Very good job! Great! Thank you again for your precious trick.  ;D

Liviu Lalescu

#5
I am glad it works, enricodn  :) . Thank you for your feedback!

Note: for teachers max 1 day from first to last hour, you could use teachers max span per day = 5, allow one day of exception of +1.

Edit: Note 2: I don't know if you used correctly teachers interval max days per week in your approach.