Teacher constraint: either first or last hour

Started by Davide G. M. Salvetti, September 05, 2011, 06:41:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Davide G. M. Salvetti

Hi,
first of all thank you for FET!

I would like to set a per teacher constraint along this lines: a teacher should do either the first or the last hour, but not both (i.e., if a teacher did the first hour, she should be free at the last one, and viceversa).

I see one way to set it would be to tell FET a teacher shouldn't do more than n-1 hours per day, but then FET doesn't count gaps, which does not suit me (I could add fictious activity for the gaps, but I would like not to predetermine the actual number of gaps).

Another way I see would be to tell FET that in each particular day the teacher is not available at firt or last hour, but in this way I have to manually chose the days: for a few teachers this can be done, but if the teachers with this constraint are numerous one could run into not easily spotted not enough teachers for first of last hour all constraint considered situations.

Do you have other solutions?

Thanks!

Liviu Lalescu

#1
QuoteHi,
first of all thank you for FET!

I would like to set a per teacher constraint along this lines: a teacher should do either the first or the last hour, but not both (i.e., if a teacher did the first hour, she should be free at the last one, and viceversa).

I see one way to set it would be to tell FET a teacher shouldn't do more than n-1 hours per day, but then FET doesn't count gaps, which does not suit me (I could add fictious activity for the gaps, but I would like not to predetermine the actual number of gaps).

I don't understand this, I think it cannot work.

Quote

Another way I see would be to tell FET that in each particular day the teacher is not available at firt or last hour, but in this way I have to manually chose the days: for a few teachers this can be done, but if the teachers with this constraint are numerous one could run into not easily spotted not enough teachers for first of last hour all constraint considered situations.

Do you have other solutions?

Thanks!

Yes, I think I have perfect solutions.

1.  a) For each teacher, add an activity split into n_days_per_week subactivities/components, min days between subactivities = 1 with 100% weight. Preferred time slots for this activity = first or last hour, each day (so, allowed 2*n_days_per_week slots). Or better, preferred slot for subactivity j = first hour or last hour of day j (no min days constraints needed in this case, and generation might be a bit faster). If you don't care about teachers' gaps (if your .fet file does not contain max gaps constraints per day/week for teachers), that's all. If you care about teachers' gaps, you have point (b), below:

    b) Make a "copy" of all teachers and their activities, but the copy of activities should NOT include any students (a lot of work). Teacher T is real, teacher T' is fake. Then, add max gaps constraints individually, only for teacher T (and the rest of real ones). For teacher T', add the special activities of point (a). Then, add many constraints activities same starting time, for each corresponding pair of activities of teachers T and T' (a lot of work).

2. Modification of FET sources, an easy change. No additional changes to the .fet file. The only drawback is that not all people can benefit, since I am reluctant to add this constraint to the official FET. Let me know if you want the code (I think it is a matter of less than a page of code, maybe only a few lines of code). If other users ask me such a constraint, I might consider adding it to the official FET.

I think (2) is faster than (1), but I am not sure if much faster or even if it is observable.

Please let me know.

Davide G. M. Salvetti

Quote
Quote
I would like to set a per teacher constraint along this lines: a teacher should do either the first or the last hour, but not both (i.e., if a teacher did the first hour, she should be free at the last one, and viceversa).

...

Do you have other solutions?

...

Yes, I think I have perfect solutions.

1.  a) For each teacher, add an activity split into n_days_per_week subactivities/components, min days between subactivities = 1 with 100% weight. Preferred time slots for this activity = first or last hour, each day (so, allowed 2*n_days_per_week slots). Or better, preferred slot for subactivity j = first hour or last hour of day j (no min days constraints needed in this case, and generation might be a bit faster). If you don't care about teachers' gaps (if your .fet file does not contain max gaps constraints per day/week for teachers), that's all. If you care about teachers' gaps, you have point (b), below:


Oh, thanks, nice idea, but I do care about teachers' gaps, so I think I will go with the next solution.

Quote

    b) Make a "copy" of all teachers and their activities, but the copy of activities should NOT include any students (a lot of work). Teacher T is real, teacher T' is fake. Then, add max gaps constraints individually, only for teacher T (and the rest of real ones). For teacher T', add the special activities of point (a). Then, add many constraints activities same starting time, for each corresponding pair of activities of teachers T and T' (a lot of work).


Now, I see that it is a lot of work, but with this marvelous shadow teachers trick you opened up a world to me!  Many thanks!  It would be less work if the constraint interface was scriptable: if I had a scriptable API which allowed me to parse the fet file and programmatically add activities and constraints it would be easy to automate; maybe this would be a work for XSLT, which unfortunately I don't grok very much.  In any case, I can probably use Emacs to automate at least part of the work, the XML .fet file is text, after all.

Quote

2. Modification of FET sources, an easy change. No additional changes to the .fet file. The only drawback is that not all people can benefit, since I am reluctant to add this constraint to the official FET. Let me know if you want the code (I think it is a matter of less than a page of code, maybe only a few lines of code). If other users ask me such a constraint, I might consider adding it to the official FET.

I think (2) is faster than (1), but I am not sure if much faster or even if it is observable.

Please let me know.

I would love to have a teacher constraint allowing me to state this and that (or all) teachers should stay at school no more than n hours, gaps or non gaps.

If you would be so kind to code it, I'd gladly accept!

Thanks!

Liviu Lalescu

#3
Quote

I would love to have a teacher constraint allowing me to state this and that (or all) teachers should stay at school no more than n hours, gaps or non gaps.

If you would be so kind to code it, I'd gladly accept!

Thanks!

OK, done, it was easier than I thought (second request is a simplification of the original code). Of course, I did not add separate constraints, this would be a lot of work. Only generation code.

Note: second request might be done with official FET, I think, like that: for each allowed gap of each teacher, add a duration 1 activity. Though it may not work if you can allow too many gaps.

I attach 3 files: 1) original, 2) exclusive or first or second hour (only your first request), 3) both requests.

Please use (3).

For variant (2) I am sure it is correct. If variant (3) gives impossible timetables, please let me know (I tested, it seems to work, but it is a bit trickier).

To make it work, you have more possibilities:

a) I prefer this one: modify src.pro, the entry for generate.cpp, make it generate_salvetti.cpp. Remove generate.cpp (for safety that you don't use it), remove tmp/generate.o, type qmake and make. Or make from a clean start (make distclean or unpack the FET archive from zero and make the first changes).

b) Or rename generate_salvetti.cpp to generate.cpp and overwrite it, then modify it a bit and save it ("touch the file" is the expression). Then recompile. I don't like this solution, cause you may be deceived this is the official FET.

I hope it works, please let me know.

Liviu Lalescu

#4
The new snapshot (2011-09-27, see Snapshots section here on forum - if it is not available it means that the new FET version was released), contains a new constraint, activities occupy max time slots from selection. Please see the announcement on Snapshots section and let me know if this solves your necessity that a teacher should have hours first XOR (exclusive or) last hour, each day (you need to add n_days constraints for each teacher).