Timetabling with Genetic Algorithms

Size: px
Start display at page:

Download "Timetabling with Genetic Algorithms"

Transcription

1 Timetabling with Genetic Algorithms NADIA NEDJAH AND LUIZA DE MACEDO MOURELLE Department of de Systems Engineering and Computation, State University of Rio de Janeiro São Francisco Xavier, 524, 5 O. Andar, Rio de Janeiro, BRAZIL Abstract:- Genetic algorithms are generally used to solve NP-complete problems, which include scheduling problem in academic institutions. Scheduling consists of assigning offered courses to available time periods so that the students satisfaction factor is maximised while preserving the unbreakable academic rules such as two distinct courses cannot be scheduled during the same period of time because the same lecturer ministers the corresponding courses. In this paper, we present an application of genetic algorithms to a generic scheduling problem. The necessary algorithmic solution is described together with some empirical observations about the Key-Words:- Scheduling problem, genetic algorithms, mutation, crossover. 1 Introduction 2 Principles of genetic algorithms Evolutionary algorithms are computer-based solving systems, which use evolutionary computational models as key element in their design and implementation. A variety of evolutionary algorithms have been proposed. The major ones are genetic algorithms [4]. They have a conceptual base of simulating the evolution of individual structures via the Darwinian natural selection process. The process depends on the performance of the individual structures as defined by its environment. Genetic algorithms are well suited to provide an efficient solution of NP-complete problems [2]. Scheduling problem in academic institutions is an example of such problems. It consists of efficiently arranging a set of courses into class periods. The obtained schedule should maximise the students satisfaction factor while preserving the academic unbreakable rules such as two distinct courses cannot be scheduled during the same period of time because the same lecturer ministers the corresponding courses. It is practically impossible to exhaustively consider and evaluate all possible schedules. The number of such schedules is exponential in the number of courses and time periods. In this paper, we present an application of genetic algorithms to a generic scheduling problem. We first explain the individual encoding used. Then we describe the necessary algorithmic solution together with some empirical observations about the Finally, we draw some conclusions about the experience. Genetic algorithms maintain a population of individuals that evolve according to selection rules and other genetic operators, such as mutation and recombination. Each individual receives a measure of fitness. Selection focuses on high fitness individuals. Mutation and recombination provide general heuristics that simulate the reproduction or crossover process. Those operators attempt to perturb the characteristics of the parent individuals as to generate distinct offspring individuals. Genetic algorithms are implemented through the following algorithm described by Fig. 1, wherein parameters populationsize, fit and genum are the population maximum size, the expected fitness of the returned individual and the maximum number of generation allowed respectively. individual GA(populationSize,fit,geNum){ fitness[populationsize]; generation = 0; population = initialpopulation(); do parents = select(population); population= reproduce(parents); fitness = evaluate(population); generation= generation + 1; while(fitness[i]<fit, i population) and (generation < genum); return fittestindividual(population); Fig. 1: Genetic algorithms basic cycle.

2 In Algorithm 1, Function intialpopulation returns a valid random set of individuals that would compose the population of first generation, function evaluate returns the fitness of a given population storing the result into fitness. Function select chooses according to some random criterion, the individuals that should be used to generate the population of the next generation and function reproduction implements the crossover and the mutation process to actually yield the new population. 3 Application to scheduling problem The scheduling problem consists of finding an arrangement of courses in a number of class periods so that we maximise the satisfaction factor of students. Prior to the beginning of the term, a student is asked to submit a list of courses in order of preference he or she pretends to attend. A schedule is valid when it attends to the faculty rules and it is judged efficient when it is valid schedule and minimise the number of courses, which are requested by the same student and scheduled in the same period of time. 3.1 Individual Encoding Encoding of individuals is one of the implementation decisions one has to take in order to use genetic algorithms. It very depends on the nature of the problem to solve. There are several representations that have been used with success: binary encoding which is the most common mainly because it was used in the first works on genetic algorithms, represents an individual as a string of bits; permutation encoding mainly used in ordering problem, encodes an individual as a sequence of integer; value encoding represents an individual as a sequence of values that are some evaluation of some aspect of the problem [5, 6]. In our implementation, an individual represents a schedule, i.e. set of assignment of courses to class periods. We use the permutation encoding wherein the integer number represents a course number and the entry number represents the class period. Let n be the number of different courses to be scheduled and the m number of periods of time, the encoding of Fig. 2 represents an individual for n = 6 and m = 3, wherein courses number 3 and 5 are assigned to the first period, courses number 1 and 4 are scheduled into the second period while courses number 2 and 6 are scheduled into the third period. period Fig. 2: Schedule encoding 3.2 The genetic algorithm Consider the algorithm of Fig. 1. The evolution of the genetic algorithm described needs data about the lecturer assignment, the student preferences and the number of possible class periods. Besides the parameters populationsize, fit and genum which represent the population maximum size, the fitness of the expected result and the maximum number of generation allowed, the genetic algorithm has several other parameters, which can be adjust by the user so that the result is up to his or her expectation. The selection is performed using some selection probabilities and the reproduction, as it is subdivided into crossover and mutation processes, depends on the kind of crossover and the mutation rate and degree to be used Selection The selection function returns two populations: one represents the population of first parents, which is parents[][1] and the other consists of the population of second parents, which is parents[][2]. Whenever no individual that attends to the selection criteria is encountered, the last individual of the population is then chosen. Note that the population from which the parents are selected is sorted in decreasing order with respect to the fitness function, which will be described later on. population[]select(population pop) { population[] parents[2]; for i = 1 to popultionsize { n1 = random(0,1); n2 = random(0,1); for j = 1 to populationsize do if SelectProb[j] n1 then parents[i][1] = pop[j]; else if SelectProb[j] n2 then parents[i][2]=pop[j]; return parents; Fig. 3: Selection function algorithm. The selection probability array is set up at initialisation step Reproduction Given the parents populations, the reproduction proceeds using replacement as a reproduction scheme, i.e. offspring replace their parents in the next generation. Obtaining offspring that share some traits with their corresponding parents is performed by the crossover function. There are several types of crossover schemes. These will be presented shortly.

3 The newly obtained population can then suffer some mutation, i.e. some of the individuals (schedules) of some of the genes (period numbers). The crossover type, the number of individuals that should mutated and how far these individuals should be altered are set up during the initialisation process of the genetic algorithm. population reproduce(population p1,p2) { return mutate(crossover(p1,p2,type), degree, rate) Fig. 4: Reproduction function algorithm. Crossover There are many ways how to perform crossover and these may depend on the individual encoding used [6]. We present crossover techniques used with permutation representation. Single point crossover consists of choosing randomly one crossover point, then, the part of the integer sequence from beginning of offspring till the crossover point is copied from one parent, the rest is copied from the second parent as depicted in Figure 5(a). Two points crossover consists of selecting randomly two crossover points, the part of the integer sequence from beginning of offspring to the first crossover point is copied from one parent, the part from the first to the second crossover point is copied from the second parent and the rest is copied from the first parent as depicted in Figure 5(b). Uniform crossover copies integers randomly from the first or from the second parent. Finally, arithmetic crossover consists of applying some arithmetic operation to yield a new offspring. (a) Single crossover point Mutation Mutation consists of changing some genes of some individuals of the current population. The number of individuals that should be mutated is given by the parameter mutationrate while the parameter mutationdegree states how many genes of a selected individual should be altered. The mutation parameters have to be chosen carefully as if mutation occurs very often then the genetic algorithm would in fact change to random search [1]. The algorithm of Figure 6 describes the mutation procedure used in our genetic algorithm. When either of mutationrate or mutationdegree is null, the population is then kept unchanged, i.e. the population obtained from the crossover procedure represents actually the next generation population. When mutation takes place, two courses are randomised and their assigned periods switched. The randomised courses ought to be distinct and scheduled in different periods. Otherwise, it is clear mutation does not occur. population mutate( population pop, int mutationdegree, int mutationrate ){ if(mutationrate 0)and(mutationDegree 0) then for s = 1 to PopulationSize do { n = random(0,1); if n mutationrate then for i=1 to mutationdegree do { c1 = random(1,coursenum); repeat c2 = random(1,coursenum); until (c1 c2)and (pop[s][c1] pop[s][c2]); swap(pop[s][c1],pop[s][c2]); return pop; Fig. 6: Mutation function algorithm. (b) Single crossover point Fig. 5: Two ways of crossover The single point and two points crossover use randomly selected crossover points to allow variation in the generated offspring and to avoid premature convergence on a local optimum [1, 6]. In our implementation, we tested all fourcrossover strategies. Results are available in the next section Fitness This step of the genetic algorithm allows us to classify the population so that individuals that are more fit are selected more often to contribute in the formation of a new population. The fitness evaluation of schedules is done with respect to two aspects: (i) how much a given schedule adheres to the faculty rules, i.e. two distinct courses cannot be scheduled during the same period of time because they are ministered by the same lecturer; (ii) how much it satisfies the students requirements, i.e.

4 the number of courses that are chosen by the same student but assigned to the same class period need to be minimised. The algorithm of Figure 7 describes the evaluation procedure of fitness used in our genetic algorithm. int evaluate( individual s) { int fitness = 0; for i = 1 to CourseNum-1 do for j = 2 to CourseNum do if (i<j) then { fitness = fitness + SC[i][j]; if s[i]=s[j]and TA[i]=TA[j] then fitness = fitness + weight; return f; Fig. 7: Algorithm of the evaluation function Each student that pretends to register submits a list of courses sorted by order of preference. At initialisation time of the genetic algorithm, a matrix, which is represented by SC is set as described in Figure 8. An entry SC[i][j] with i<j, i.e. from the upper triangle of SC, is the weighted total number of students that chose to course i and j. The penalty WG[p] introduced into the fitness value of an individual increases with the priority p of the course in the student choice list. For instance, assume that two students included course i and j into their choices: for one student course 1 is classified pth and course 2 is qth while for the other student, course 1 is classified rth and course 2 is sth, and these are scheduled into the same class period then SC[i][j] = WG[p]+WG[q]+WG[r]+WG[s]. The algorithm of Figure 8 describes computation of the matrix SG. int[][] ChoiceMatrix(choices C) { int[coursenum-1][coursenum] SC = 0; for i = 1 to StudentNum do for j = 1 to ChoiceNum do for k = j+1 to ChoiceNum do if j<k then SC[j][k]=SC[j][k]+WG[j]+WG[k] else SC[k][j]=SC[k][j]+WG[j]+WG[k] return SC; Fig. 8: Algorithm for setting the matrix SC. In the algorithm of Figure 7, every time two courses that are ministered by the same lecturer are scheduled into the same period, a penalty of weight is added up to the fitness of the individual. 4 Implementation results In applications of genetic algorithms to a practical problem such as time scheduling, it is difficult to predict a priori what combination of settings will produce the best result for the problem. The settings consist of the crossover type, the mutation rate, when mutation does take place, the mutation degree. Here we investigate the impact of different values of these parameters in order to choose the more adequate ones to use in our scheduler. The chart of Figure 9 shows the progress made in the first 150 generations of an execution of the scheduler for 100 courses to be assigned into 8 periods of time. The settings used are: uniform crossover, a mutation rate of 10% and a mutation degree of 1. fitness of the best schedule Genetic algorithm execution generations Fig. 9: Scheduler result curve for populationsize = 150 The scheduler produces suitable results, i.e. schedules using any of the crossover types described in the previous section. However, we found out that the uniform crossover produces good results faster. This was demonstrated using the chart of Figure 10. The obtained conclusion is consistent with the work developed in [1, 2]. fitness of best individual Crossover type impact Single-point Two-point Arithmetic Uniform generations Fig. 10: Comparison of crossover strategies

5 We tested combinations of mutation rate, i.e. how many individuals should be altered once the crossover has taken place, and the mutation degree, i.e. how many courses should be scheduled in different period time. The chart of Figure 11 shows the result of the investigation. From the chart, we can easily conclude that a large mutation degree disrupts the search process. average best fitness Mutation impact Mutation degree = 1 Mutation degree = 5 Mutation degree = 10 0,00 0,02 0,04 0,06 0,08 0,10 mutation rate Fig. 11: Comparison of mutation rates 5 Conclusions In this paper, we presented an application of genetic algorithms to a generic scheduling problem. We first explained how individuals are encoded. Then we described the necessary algorithmic solution. Then we presented some empirical observations about the This application of genetic algorithms to the classical scheduling problem proved to be very useful and effective technique. Very suitable schedulers can be obtained with a little computational effort. A good schedule can be obtained in a 4 to 6 second using a Pentium III with a128 MB of RAM. 6 References [1] DeJong, K. and Spears, W.M., An analysis of the interacting roles of the population size and crossover type in genetic algorithms, In Parallel problem solving from nature, pp , Springer-Verlag, [2] DeJong, K. and Spears, W.M., Using genetic algorithms to solve NP-complete problems, Proceedings of the Third International Conference on Genetic Algorithms, pp , Morgan Kaufmann, [3] Erben, W. and Keppler, J., A genetic algorithm solving a weekly course-timetabling problem, Proceedings of the First International Conference on the Practice and Theory of Automated Timetabling, Edinburgh, pp , [4] Haupt, R.L. and Haupt, S.E., Practical genetic algorithms, John Wiley and Sons, New York, [5] Michalewics, Z., Genetic algorithms + data structures = evolution program, Springer- Verlag, USA, third edition, [6] Neves, J., Rocha, M., Rodrigues, Biscaia, M. and Alves, J., Adaptive strategies and the design evolutionary applications, Proceedings of the Genetic and the Design of Evolutionary Computation Conference, Orlando, Florida, USA, 1999.