Program design of a timetable creator
<p>For fun, I want to write a timetable creator in python for schools. I.e. a program where schools can input their rooms, teachers, classes and subjects and some preferences and which will output a timetable for each class/teacher/room. I don't have a problem with the logic behind this (because that is the part I am most interested in), but I do have a problem with the design (due to inexperience in writing something big from scratch). </p>

<p>So assume I have a list of rooms (101, 102, ...), a list of teachers (Mr A, Mrs B, ...), a list of subjects (math, english, ...) and a list of classes (5, 6, ...).</p>

<p>Now some rooms are better suited for different subjects (like 101 is good for math &amp; english, but geography must be in 102, if possible). Of course, every teacher has a certain set of subjects he teaches.</p>

<p>Also, the classes are parted in different groups. I.e. class year 5 is parted in 5-a and 5-b for all subjects except sports (where it may be 5-groupX and 5-groupY) and another subject, where it may be 5-group1, 5-group2 and 5-group3. </p>

<p>It would be nice if someone could give me some advice on how to efficiently save this data / design my classes, so I can write some nice code. </p>

<p>My first guess would be something like (pseude code):</p>

<pre><code>class Room:
    string name     # e.g. r102.name = "102"
    int id          # that should be unique?

class Subject:
    string name     
    int id          
    map RoomPref    # like geography.Roompref[r102.id] = 1.0 
                    # or math.Roompref[r101.id] = 0.75 

class Teacher:  
    list Subjects   # like MrsB.Subjects = {geography.id, math.id}
</code></pre>

<p>etc, etc, but I am not sure if this approach is good and leads to nice code. Especially all the different interconnections pose a problem to me.  (Is assigning different IDs a good solution?)</p>

<p>Advice and/or reading material is welcome.</p>

<p>One difficult part of this problem is that there are numerous relations that make up a schedule. I would think very carefully about how a teacher T teaches a class and she teaches it in room X at 1:30 pm.</p>

<p>For example, in your program, you may want to know when room X is available. To do this, you will want to check your data structures and find room X, then search the list of times that room X is either free or occupied. HOWEVER, in another case, you may want to know whether or not Teacher J teaches math. So you would do a similar lookup and search all the classes that Teacher J teaches.</p>

<p>So my advice is this: you will want to avoid what may initially seem like the easiest option to create a data structure where you create an organization of time slots and then assign teachers and classes to those times. You would likely make quick progress at first, but eventually run into trouble when you realize how difficult it is to use a structure of Class objects to represent a set of relationships.</p>

<p>Instead, try starting with a relational database like mysql. Use references to other tables in order to link data from one table to another instead of writing all the code yourself. There's no need to reinvent the wheel here and try to write a complex class structure to represent what are essentially simple (though possibly highly interconnected) relationships.</p>

python design-patterns design