I am making a timetabling application. The important classes are:
Period
id: int
clazz: Clazz
SubjectTeacher
subject: String
teacher: String
clazz: Clazz
AllocablePeriods: List<Period>
Here is example data, where Jane and John teach at one class, and Jane in another class.
{sub435, Jane-Algebra-Class1, {1,2,3,4,5,6,7,8}}
{sub124, Jane-Calculus-Class2, {9,10,11,12,13,14,15,16}}
{sub875, John-English-Class1, {1,2,3,4,5,6,7}} //he cannot take #8
My objective is to detect possible swaps for each SubjectTeacher. For example, in the above example, Jane-Algebra-Class1 and John-English-Class1 have potential swaps
{1,Jane-Algebra-Class1,John-English-Class1}
{2,Jane-Algebra-Class1,John-English-Class1}
...
{7,Jane-Algebra-Class1,John-English-Class1}
What is a good algorithm/technique to detect all possible swaps for all SubjectTeachers?
I would expect that the number of
AllocablePeriodsis relatively small. Then what you can do is iterate over all teachers, iterate over all their periods and add each such period to a Map mapping a period identifier to the teachers that can teach during this period:After this cycle you will have in
periodTeachersMapfor every period all the teachers that can teach in it. If you want the pairs themselves you can easily construct them from the List. I hope this will help you.