6

I have a problem of University Timetable Scheduling which I am trying to solve with Genetic Algorithm. I want to know the best encoding type for this problem that can also help me in satisfying few of the constraints. For this problem, the timetable will have the following structure,

  • There will be a total of 5 days in which the timetable will be scheduled (Monday to Friday).
  • Every day, there will be 5 different slots, and one slot will have one lecture.
  • However, Lab Lectures will be conducted over two consecutive slots.
  • Timetable will also tell the Room Number (or Lab number) of each lecture and also the name of Instructor for every lecture.

Now, the timetable looks something like this, (in the picture, there are multiple slots, but I will be considering only 5 slots instead of dividing the timetable into so many slots)

enter image description here

This is a timetable of only one section. There are around 25 sections in one single timetable.

Now, what I have done is written the data of every course, its section, and its instructor in one file in a format like this,

1
Object Oriented Programming 
CS-3B
Dr Ali Hassan 
,
2
Object Oriented Programming 
SE-3A
Dr Ali Hassan 
,
3
Remote Sensing and GIS 
CS-7F
Dr Tom Baker

And to represent the Timetable, I have made the file like this,

0
1
2 2 9
3 2 9
0
2
2 1 9
3 1 9
0
3
2 5 36
4 1 36
  • 0 is a separator, which separates one object from another.
  • First number is basically the ID of the course. "1" actually represents the first object in my first file (i.e. Object Oriented Programming, CS-3A, Dr. Ali Hassan).
  • Second row represents the first lecture of course (with id = 1) in the timetable. The format is as follows, First number is the day. Second number is the Slot. Third number is the Room Number.. So, in this case, it is saying that the first lecture of course id = 1 will be held on "Tuesday", in the "2nd Slot" and in "Room Number 9".
  • Third row represents the second lecture of the same course.

Now I need to encoding of this timetable. I have opted to go with Binary Encoding for now (obviously, I can shift to others but need to know which and how) and done the encoding like this,

00000001 00000010 00000010 00001001 00000011 00000010 00001001 
00000010 00000010 00000001 00001001 00000011 00000001 00001001 
00000011 00000010 00000101 00100100 00000100 00000001 00100100 
00000100 00000010 00000001 00001101 00000100 00000010 00000110 
00000101 00000010 00000010 00001101 00000011 00000001 00000011 

Since the total number of courses are likely to fall between 200-220 so I went with 8-bit encoding.

Encoding is done in this format,

Course_ID First_Lecture_Day First_Lecture_Slot First_Lecture_Room 2nd_Lec_Day 2nd_Lec_Slot 2nd_Lec_Room

Now, I want to know few things regarding this,

  • Is this encoding the right approach? or should I have done this in any other way?
  • A serious issue with this is this that I have the following two constraints,

ss

  1. Lab Lectures must be conducted in two consecutive slots.
  2. Course Lectures must be conducted on different days, i.e. no course should have both lectures on same day.

Now, I can resolve the 2nd issue by implementing it in the fitness function (I assume. I haven't yet went there but I am thinking that I can solve this issue there)

However, I do not know how can I solve the first issue? Is there any particular way in which I can instruct the Genetic Algorithm to ALWAYS keep the lab lectures in consecutive slots? For example, I use another bit in my Binary Encoding, like maybe this,

00000001 00000010 00000010 00001001 00000011 00000010 00001001 00000000

00000010 00000010 00000001 00001001 00000011 00000001 00001001 00000001

Where the last bit will tell whether the course is of lab or of course.. And depending upon that bit, if you are changing the lecture slots, then if the lab bit is on, then change both the lecture slots so that they stay with each other and hence, lab is conducted over consecutive slots? How can I make sure of this? Can anyone guide me, please?

And also if any other approach I should have used in the Encoding Process for Genetic Algorithm? Thank you.

Awais Shahid
  • 117
  • 4
  • 15
  • There is a conference about your problem: https://www.sportscheduling.ugent.be/ITC2021/ but they shifted their focus to sports time tabling. You might want to look into other techniques, here is a paper of how to solve course time tabling with ASP: https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/anor/BanbaraIKOSSTW19.pdf – Max Ostrowski Oct 12 '21 at 10:04
  • @MaxOstrowski Thank you so much for the response. Can you also kindly tell me how do I find the solutions (or the steps) every group who submitted the solution in this conference? And yes, I will also look into that technique of ASP. Thank you for that, it would also be of great help. Right now, however, I want to focus on Genetic Algorithm and then use other techniques as well on this same problem and then compare which one gives the better results. – Awais Shahid Oct 12 '21 at 19:44
  • Unfortunately I don't know. I think the results for this year are not yet published, maybe you can find some links for last year conference or by googling the participants? Sorry that I'm not of greater help. Good luck. – Max Ostrowski Oct 13 '21 at 07:33
  • You are adamant on a genetic algorithm solution? If your scale is small have you tried writing out an optimization function that describes everything you want and applying an integer solver (which would produce an optimal solution in an unbounded amount of time?) – ldog Oct 19 '21 at 21:05
  • @ldog No, I don't have to "necessarry" use the Genetic Algorithm. But it is just this that we have been working on Genetic Algorithm and have made a roadmap for this, which is why I would want to do this problem with Genetic Algorithm but it doesn't mean we can't try anything else. I think I will look into this Integer Solver as well for this problem. I did look it up a bit, but I don't think it is easier to apply than Genetic Algorithm, lol :/ – Awais Shahid Oct 21 '21 at 13:46

1 Answers1

3

If your lab rooms are different from your normal rooms then you should be solving lab and normal courses separately.

If you want a course to always use the same room than you don't need to encode the room twice just use a bit mask for the multiple slots that the course will take up.

[Course Id][Room Id][Slot Bit Mask]

[Course Id] is a byte 1-255

[Room Id] is a byte, assuming less than 256 rooms

[Slot Bit Mask] is a UInt32 bit mask, gives you 32 slots but you only need to use 25 (5 days * 5 slots/day)

[Course Id] and [Room Id] correspond to your separate lists of Normal and Lab, Courses and Rooms.

[Slot Bit Mask] for Normal Courses is constrained to 2^n (n = 0-24) BitwiseOr 2^m (m = 0-24), where Floor(n / 5) != Floor(m / 5). This equates to 2 unique days a week, 1 slot per day.

[Slot Bit Mask] for Lab Courses is constrained to 3 * 2^n (n = 0-3, 5-8, 10-13, 15-18, 20-23), where Floor(n / 5) != Floor(m / 5). This equates to 1 day per week, 2 consecutive slots per day. edit only need 1 lab day

Your fitness function is just the error score. An Error is when [Room Id A] == [Room Id B] AND ([Slot Bit Mask A] BitwiseAnd [Slot Bit Mask B]) > 0. Fitness = (Total - Error) / Total.

EDIT Example encoding:

Course Id = 1, Room Id = 2, Normal Course Slots = Monday 3rd slot and Friday the 4th slot. Monday 3rd slot (2^n, n = 2). Friday 4th slot (2^m, m = 23). Floor(n / 5) = 0 and Floor(m / 5) = 4, since 0 and 4 are not equal its a valid Normal Course Slot Bit Mask.

Slot Bit Mask UInt32 Bit Index 31 to Bit Index 0

(ZZZZZZZ5 43215432 15432154 32154321)

(0000000F FFFFTTTT TWWWWWTT TTTMMMMM)

Full encoding Course, Room, Slot

00000001b 00000010b 00000000 10000000 00000000 00000100b

Louis Ricci
  • 20,804
  • 5
  • 48
  • 62
  • Thank you so much for the reply. May I ask few questions if possible for you? First, by solving labs and courses separately, you mean to say that I should run Genetic algorithms two times, first time it will schedule Labs and then it will schedule courses, right? That will definitely work (as much as I understand from my problem point of view), thank you! Secondly, I want to know why to use Uint32 bit mask? Wouldn't my way of encoding not work? Thirdly, by 24 bits, you mean to say that my the bit mask to represent day and slot for my course/lab should be of 24 bits long? (instead of 32?) – Awais Shahid Oct 21 '21 at 13:38
  • Fourthly, can you please elaborate how would that bit mask equates to 2 uniques day per week, 1 slot per day when solving course problem? I am trying to figure it out for the past few hours but could not get the logic behind it and same for the Lab issue (Also, the labs don't need to be scheduled on 2 days, they just have to be scheduled on one day per week but on 2 consecutive slots... That kinda simplifies things for me I guess). – Awais Shahid Oct 21 '21 at 13:41
  • My idea is to use similar bit masking as I have explained in my post for "Labs" problem, however the slots will be changed to only "four".. If the lab is scheduled on first slot, then it would equate to "first two slots". If scheduled on 2nd slot, then it would equate to "2nd and 3rd slot" and so on.. Labs can't be scheduled on "5th" slot because I don't have a 6th slot. However, courses can be (so for the genetic algorithm when used for courses, will have slots from 1 to 5). – Awais Shahid Oct 21 '21 at 13:42
  • However, in this logic of mine, I would require the help of Loss function to schedule course lectures on 2 different days in this case. This loss function is, I think, not required in your logic so using your logic would be the better approach but I am unable to fully understand it :/ (Sorry for so many comments, it is because of the characters limit on each comment) – Awais Shahid Oct 21 '21 at 13:44
  • 2
    @TalhaAyub 1. Yes solve them separately then merge the results. 2. UInt32 give you enough space to work with thats all. 3. I never said "24bits" anywhere in my answer; I was using Power-Of-2 notation to show the constraints for the bit masks. 2^0 (two to the power of 0 or 2^n where n=0) equals 1 which is the bit with index 0 (00000001b), a byte has bit indexes 0 to 7. I added an edit with an example encoding. 4. See (3). – Louis Ricci Oct 22 '21 at 15:25
  • Ok thank you very much, I understand it a lot better now than before. I just have one more question (sorry for asking so many questions). How/Where do I check that condition Floor (n/5) != Floor (m/5)? Will I be checking this in the Loss Function? If the Floor (n/5) is not equal to Floor(m/5) so the Slot Bit Mask is not valid (of 1 particular course) and hence increase the loss function value for that specific solution? And this will be checked for all the courses? – Awais Shahid Oct 24 '21 at 13:53
  • @TalhaAyub you check those conditions when you initially set the random Bit Masks or when your genetic algo evolves them. For performance you should make a lookup table of all of the valid bit masks a Normal and Lab course can have and use that lookup table – Louis Ricci Oct 26 '21 at 14:01
  • Ok, so basically even genetic algo is evolving, the new bits being generated (from crossover and mutation) will not be "totally" random but instead, we can put "condition" on them that every single of them has to be present in that lookup table of ours which contain all the valid Bit Masks. I got it, thank you very much for all the help you have provided here! Learned a lot of new things as well! – Awais Shahid Oct 26 '21 at 15:43