How to make a timetable using genetic algorithms

advertisement

HOW TO MAKE A TIMETABLE

USING GENETIC ALGORITHMS

Introduction with an example

BACKGROUND

 First step: Think what kind of requirements there are for the timetable

• For example number of students, classes and classrooms, size of classrooms, equipments in classrooms etc.

 Second step: Divide these requirements by their importance

Hard requirements: for example a teacher or student group can have only one class at a time, a classroom must have enough seats to all students, a classroom must have all the equipments the class requires. If one is broken, then the timetable is infeasible!!

Soft requirements (can be broken): for example preferred classroom or time of class by teachers, distribution of classes for student groups or teachers.

 All the requirements above depend of course on the situation

BACKGROUND

 In the following example only hard requirements are implemented. They are:

• A teacher can have only one class at a time,

• A student group can have only one class at a time

• A classroom must have enough seats to all students

• A class should be scheduled exactly once

OBJECTS/CLASSES

 Next step is to consider the objects that are needed in the programming. They can be for example:

• Teacher (Id, name, list of classes etc)

• Students group (Id, name, number of students, a list of classes, etc)

• Classroom (Id, name, number of seats, etc)

• Course (Id, name, id)

• Class (Reference to the course to which the class belongs, a reference to the teacher and to the student group, number of seats required in a classroom)

CHROMOSOME

 Classes (genes) are located in chromosomes (timetables)

 we need a slot for each hour, for every room and for every day.

 In the following example:

• We assume that all classes are 75 min long, cannot begin before 8.15 am, and should finish before or at 16 pm (so max 5 lessons/day), and working days are from Monday to Friday (5 days total)

• We can use a table with a size 5*5*number_of_rooms.

CHROMOSOME

 One slot in the example (timetable[time][day][roomId]:

FITNESS

 The timetables should also store its so called fitness value

 As previously mentioned, in the example only hard requirements are used to calculate the fitness of a timetable.

 Each class can have (integer) points from 0 to 4 points.

• If a class is located in a classroom with enough available seats we increment its score.

• If a teacher has no other classes at the time, we increment the class's score once again.

• If a student group has no other classes at the time, we increment the class's score once again.

• The last thing that we check is if every class is scheduled exactly once. If class is not scheduled at all, we find a empty slot and put the class in it. If it is scheduled more than once, we delete all “extra” classes from the timetable (so from this the class will always get one point!)

FITNESS

 The total score of a timetable is the sum of points of all classes.

 The fitness value is calculated as (total score of timetable)/(number_of_classes*4)

 The fitness values are represented by floating point numbers between 0 to 1.

LET’S BEGIN THE PROGRAMMING

 First we create the population and a few timetables (for example randomly) to start the process

 Then we evaluate the fitness value of each timetable created so far

 If no timetable reaches fitness value , we move on to the Genetic Algorithm

GENETIC ALGORITHM

 First we must:

• consider how many timetables are going to survive

• organize the timetables by their fitness value

 GA operations:

• Selection

• Crossover

• Mutation

• Evaluation of the offspring and re-organisation of all the survived ones

• If solution is not found, we will start all over

SELECTION

 There are many ways of doing the selection of two member of the population (parents).

There can or cannot be a favoritism etc.

 Basic idea: parts of a good solution are also good building block i.e. using them we can highly probably build better and better solutions. (Alander)

CROSSOVER

 There are also many different ways of doing the crossover.

 For example there can be a fixed crossover rate. If so, we pick a random number between 0 to 1 and if the crossover rate is bigger than the random number, we do the crossover operation to the selected parents.

 A single point crossover:

 After crossover we have 2 ”children”

MUTATION

 Usually there are some fixed mutation rate (for example 0.01).

 For each class (a slot in the timetable) we pick a random number between 0 and 1. If the mutation rate is bigger than the random number, we randomly choose another class from the current timetable and swap it with the current class

RESULT

 The main goal is to find a timetable that has fitness value 1.

RESULT

 Sometimes it can take too long or can be even be impossible (?!) to find the most optimal solution.

 There can be a fixed number of maximum trials and after that we just accept the situation and pick the best one found so far

Download