• No results found

Description and Application of Genetic Algorithm

N/A
N/A
Protected

Academic year: 2021

Share "Description and Application of Genetic Algorithm"

Copied!
61
0
0

Loading.... (view fulltext now)

Full text

(1)

Description and Application of Genetic

Algorithm

MIN WANG

Thesis for the Master of Science Degree (two years) in Mathematical Modeling and Simulation

30 credit points (30 ECTS credits) April 2012

Blekinge Institute of Technology School of Engineering

(2)

Abstract

Genetic Algorithm (GA) as a class of Evolutionary Algorithm (EA) is a search algorithm based on the mechanics of natural selection and natural genetics. This dissertation presents the description, solving procedures and application of GA. The definitions of selection, crossover and mutation operators are given in details and an application based on GA in Time Table Problem (TTP) is performed in a new way.

Due to its high capability of overall search, GA is particularly appropriate for solving timetabling and scheduling problems. TTP (Time Table Problem) which belongs to NP-hard problem is a special problem concerning resource management. In this dissertation, a new chromosome coding is designed in order to solve TTP more effectively. And the result presented by MATLAB will converge to a steady condition.

(3)

Acknowledgement

It is a pleasure to express my gratitude to all those who gave me the possibility to complete this thesis.

Firstly, I owe my deepest gratitude to my dear professor Elisabeth Rakus-Andersson. Her kindness, patience, rigorous academic attitude and profound knowledge inspire me. The entire process of this dissertation from topic selection and design plan until completion cannot be accomplished without her meticulous guidance.

Next, I would like to show my sincere appreciation to Mohammad Havaei. He helped me to edit the MATLAB program and put forward many valuable suggestions to my thesis.

Furthermore, I am grateful to professor Nail Ibragimov, Claes Jogréus, Mattias Dahl, Raisa Khamitova, Mattias Eriksson and other professors and managers. During two years of master education, I grasp much precious knowledge.

(4)

Contents

Table list ... 6

Figure list ... 7

1. Introduction ... 9

2. Background ... 10

3. Description of genetic algorithm ... 11

3.1 Some definitions ... 11

3.2 Solving steps ... 12

3.2.1 Flow-process diagram of GA ... 12

3.2.2 Initialization ... 14

3.2.3 Evaluation of fitness function ... 14

3.2.4 Selection ... 16

3.2.5 Crossover ... 19

3.2.6 Mutation ... 20

3.2.7 Obtaining new generation ... 20

3.2.8 Stopping criterion ... 21

3.2.9 Getting the best result ... 22

4. Application of the genetic algorithm to make a university courses schedule ... 22

4.1 TTP-model ... 22

4.1.1 Time ... 23

(5)

4.1.3 Professor ... 24 4.1.4 Lecture (Course) ... 24 4.1.5 Class ... 24 4.2 Constraints ... 25 4.2.1 Hard constraints ... 25 4.2.2 Soft constraints ... 25 4.3 Solving procedures ... 26

4.3.1 Creating initialization code based on 5 hard-constraints 27 4.3.2 Formulating the fitness function according to 3 soft-constraints ... 42

4.3.3 Solving TTP by GA ... 49

4.4 Result ... 50

5 Conclusion and further work ... 57

(6)

Table list

Table 4.3.2-1 Preference degree of utilization of rooms Table 4.3.2-2 Preference of timeslot

Table 4.3.2-3 Preference of time length degree of courses Table 4.4-1 The parameter list

(7)

Figure list

Figure 3.2.1-1 Solving procedures of GA

Figure 3.2.4-1 Pie graph of an example of roulette wheel

Figure 4.3.1-1 Matrix 𝐶~𝑁 = [𝑎𝑖,𝑗]𝐸×20𝐵

Figure 4.3.1-2 An example showing H1

Figure 4.3.1-3 More than 2 classes’ situation in H1 Figure 4.3.1-4 H2 constraint

Figure 4.3.1-5 H3 constraint

Figure 4.3.1-6 Matrix 𝑁~𝑀 = [𝑏𝑠,𝑡]20𝐵×𝐷

Figure 4.3.1-7 H4 constraint

Figure 4.3.1-8 H4 constraint (in detail) Figure 4.3.1-9 An example of H4 Figure 4.3.1-10 H5 constraint

Figure 4.3.1-11 Matrix 𝐶~𝑁~𝑀 = [𝑐𝑝,𝑞]20𝐵𝐸×𝐷

Figure 4.3.1-12Initialization

Figure 4.3.1-13The relationship between 𝑎𝑖,𝑗 and 𝑐𝑝,𝑞

Figure 4.3.1-14The relationship between 𝑏𝑠,𝑡 and 𝑐𝑝,𝑞

Figure 4.3.2-1 S1 constraint (matrix 𝐷 = [𝑑𝛼,𝛽]𝐸×𝐵)

Figure 4.3.2-2 Find the positions of 𝑎𝑖,𝛽𝜔 = 1

(8)

Figure 4.3.3-1 Crossover

Figure 4.4-1 3D graph of the result

Figure 4.4-2 The largest fitness value of each iteration population and regression line

(9)

1. Introduction

Genetic Algorithm (GA) is a class of Evolutionary Algorithm (EA) which generates solutions to optimization problems using techniques inspired by natural evolution, such as inheritance, mutation, selection, and crossover. It is a search algorithm based on the mechanics of natural selection and natural genetics to solve usually mathematical optimization of search algorithm in computational algorithm (Chu & Beasley, 1995).

The idea of GA comes from the natural rule (Davis, 1991). Each organism lives with specific features coded in genes which are stored in chromosomes. They are allowed to transfer their genes to create new generations, and this process is called crossover. During reproduction, mutation possible occurs which expresses in changing one gene in chromosome of offspring. The offspring which can fit to the environment better will be left. GA imitates this hereditary procedure in the mathematical way, which means that after selection, crossover and mutation, the best result whose fitness is highest will be obtained.

(10)

This dissertation is going to introduce this interesting method by applying the genetic algorithm to solve a time table problem (TTP). The author builds up a new model to analyze TTP. This model merges two matrices to create the code of chromosomes. In this way, the methodology to solve this problem becomes more rational. The problem will be simplified as the model only uses binary code with 0 and 1.

2. Background

John Holland firstly put forward GA in 1960s (Wikipedia, 2010), when he worked on the studies of cellular automata with his colleagues and his students at the University of Michigan. GA became popular through his book Adaptation in Natural and Artificial Systems (Holland, 1975). The research of GA was limited to the theoretical part until the First International Conference on Genetic Algorithm, which was held in Pittsburgh, Pennsylvania in the mid-1980s. As the development of computer programs and the demand of practical application grew, GA becomes more popular within practical application.

(11)

been developed rapidly. Most of Fortune 500 companies apply GA to making a time list, data analysis, the future trend forecast, budget, and solving other combinatorial optimization problems.

3. Description of genetic algorithm

3.1 Some definitions

Let us introduce the important definitions cited after the book “Computational Intelligence” written by Leszek Rutkowski (Rutkowski, 2005).

Definition 3.1.1:

Population is a set of individuals of a specified size. Definition 3.1.2:

Individuals of a population are sets of “task parameters” coded in the form of chromosomes.

Definition 3.1.3:

Chromosomes (chains or code sequences) are ordered sequences of genes.

Definition 3.1.4:

Gene (“feature”, ”sign”, ”detector”) is a single element in the genotype. Definition 3.1.5:

(12)

(can be one chromosome). Definition 3.1.6:

Phenotype is a set of values corresponding to a given genotype, which is a decoded structure.

Definition 3.1.7:

Fitness function (“adaptation function”, “evaluation function”) which measures fitness of adaptation of a given individual to the environment. The function allows evaluating the degree of fitness of particular individuals in the population. Basing on this degree we select the individuals that fit best.

Definition 3.1.8:

The new generation (“the offspring generations”) is a newly created population of individuals.

3.2 Solving steps

3.2.1 Flow-process diagram of GA

(13)

Figure 3.2.1-1 Solving procedures of GA

NO

Initiation-selection of the initial population of chromosomes

Stopping criterion

Evaluation of the fitness of chromosomes in the population START Creation of a new population Application of genetic operators

Selection of chromosomes of the “best” Presentation chromosome

STOP

(14)

3.2.2 Initialization

An initial population consists of random selection of a demanded number of individuals. Every individual is represented by chromosomes coded in a determined length of sequence of digits, letters or other showing ways.

Example 3.2.2-1:

Usually, we use binary sequences to create the codes of chromosomes such as

𝑐ℎ1 = [01010101], 𝑐ℎ2 = [10010100]

3.2.3 Evaluation of fitness function

The fitness function is used to measure adaptability of chromosomes and usually need to be maximized. The form of the fitness function depends on the real problem. And a suitable transform seems necessary when we face to a minimum optimization problem.

Example 3.2.3-1:

A minimum optimization problem is given as below,

min 𝑓 = 2𝑥, x ≥ 0.

Usually we make a reciprocal transformation to change this minimum problem into a maximum problem, such as

max 𝐹 = 1

1 + 𝑓 =

(15)

Here we use 1+𝑓1 instead of 1𝑓 in case 𝑓 = 0 . Therefore the maximum function 𝐹 can be treated as the fitness function of this problem.

After determining the fitness function of solved problem, we calculate the evaluation of each chromosome according to the fitness function. The higher the value of the function is, the better result of the solved maximization problem is got.

Example 3.2.3-2:

Calculate the evaluations of the fitness function 𝑓 = 𝑥2+ 3 which

we wish to maximize for two chromosomes 𝑐ℎ1 = [0100], 𝑐ℎ2 =

[1010].

Due to 𝑐ℎ1 = [0100] is a binary sequence, so the chromosome

𝑐ℎ1 = [0100] is corresponding to

𝑥1 = 23∙ 0 + 22∙ 1 + 21∙ 0 + 20∙ 0 = 4

Thus the evaluation of this chromosome is

𝑓1 = 𝑥2+ 3 = 42+ 3 = 19

The same steps to calculate the evaluation of 𝑐ℎ2 = [1010]

𝑥2 = 23∙ 1 + 22∙ 0 + 21∙ 1 + 20∙ 0 = 10

𝑓2 = 𝑥2+ 3 = 102+ 3 = 103

We can see that 𝑓2 = 103 is larger than 𝑓1 = 19 , so the

(16)

3.2.4 Selection

After calculating the evaluation of every chromosome, we should choose the same number of chromosomes as in the previous population to create the next generation. This selection takes place in accordance with the natural selection rule that the better parents will have better offspring. Parents are chosen according to their fitness. Thus the chromosomes which have highest evaluation should have the most of the chances to be selected to create new offspring. The selection can be done by many methods, such as roulette wheel selection, Boltzmann selection, tournament selection, rank selection, steady state selection and some others (Obitko, 1998).

(17)

Example 3.2.4-1:

Assume that we want to find the maximum value of the function:

𝑦 = 2𝑥, 𝑥 ∈ [0,31]

We start with drawing the initial populations as following numbers from [0, 31]: 16, 21, 6, 30, 14 and 2.

If we use the numbers’ binary codes as their chromosomes, we obtain

𝑐ℎ1 = [10000], 𝑐ℎ2 = [10101], 𝑐ℎ3 = [00110],

𝑐ℎ4 = [11110], 𝑐ℎ5 = [01110], 𝑐ℎ6 = [00010].

According to the fitness function, we get the evaluations of chromosomes as following,

𝑓1 = 2 ∙ 16 = 32, 𝑓2 = 2 ∙ 21 = 42, 𝑓3 = 2 ∙ 6 = 12,

𝑓4 = 2 ∙ 30 = 60, 𝑓5 = 2 ∙ 14 = 28, 𝑓6 = 2 ∙ 2 = 4.

Now we apply roulette wheel method to select chromosomes. The sum of fitness function values of all of chromosomes is

𝐹 = 𝑓1 + 𝑓2+ 𝑓3+ 𝑓4+ 𝑓5+ 𝑓6 = 178

Then we get the sectors of roulette wheel showed in percentage.

𝜗1 =𝑓1 𝐹 = 32 178 = 0.18, 𝜗2 = 𝑓2 𝐹 = 42 178 = 0.23, 𝜗3 =𝑓3 𝐹 = 12 178 = 0.07, 𝜗4 = 𝑓4 𝐹 = 60 178 = 0.34, 𝜗5 =𝑓5 𝐹 = 28 178 = 0.16, 𝜗6 = 𝑓6 𝐹 = 4 178= 0.02.

(18)

Figure 3.2.4-1 Pie graph of an example of roulette wheel

If we assign an interval [0, 100) to the whole roulette wheel, the

sector of 𝑐ℎ1 belongs to the interval [0, 18), as same, the sector of

𝑐ℎ2 is between [18, 41) and so on. We can see that the chromosome

whose fitness is higher has a larger area of the roulette wheel, and then this chromosome will have more chance to be selected.

Now we choose numbers from interval [0, 100) randomly to help us to select the parents’ chromosomes. Assume that 6 numbers are drawn as following: 89, 14, 19, 73, 47 and 53.

According to Figure 3.2.4-1, we know that number 89 is in the

interval [82, 98) which means that 𝑐ℎ5 is selected. In the same way,

14 ∈ [0, 18) → 𝑐ℎ1, 19 ∈ [18, 41) → 𝑐ℎ2, 73 ∈ [48, 82) → 𝑐ℎ4,

47 ∈ [41, 48) → 𝑐ℎ3, 53 ∈ [48, 82) → 𝑐ℎ4.

We find the following chromosomes have been selected,

(19)

𝑐ℎ5, 𝑐ℎ1, 𝑐ℎ2, 𝑐ℎ4, 𝑐ℎ3, 𝑐ℎ4.

3.2.5 Crossover

In natural world, the genes of children are from both of their parents. In order to imitate this situation, we do crossover of chromosomes of selected parents to generate offspring.

Crossover just happens between two chromosomes (one couple), so the first stage of crossover is arranging the chromosomes of selected parents’ population in pairs which is made randomly.

After that, we should decide the crossover point. If the length of each chromosome is L (i.e., for ch = [10000] , the length of this

chromosome is L=5), we draw a random number 𝑙𝑘, which belongs

to interval [1, L-1]. Then the genes of parents are exchanged from the

gene on position 𝑙𝑘. As a result a pair of offspring is created.

Example 3.2.5-1:

If L=8, 𝑙𝑘 = 5 is drawing, then the crossover happens as following:

In classical GA, crossover is almost always present, thus we give a

pretty high crossover rate 𝑃𝐶𝑟𝑜𝑠𝑠𝑜𝑣𝑒𝑟, which is generally in the

interval [0.5, 1]. For each pair of parents we randomly draw a value of

A pair of parents A pair of offspring

𝑐ℎ1 = [10001 𝟎𝟏𝟎]

𝑐ℎ2 = [01000 𝟏𝟎𝟎]

𝑐ℎ1′ = [10001 𝟏𝟎𝟎]

𝑐ℎ2′ = [01000 𝟎𝟏𝟎]

(20)

a crossover probability 𝑃𝑐 for this pair. If this probability is less than 𝑃𝐶𝑟𝑜𝑠𝑠𝑜𝑣𝑒𝑟 then crossover happens in pair.

3.2.6 Mutation

Different from crossover, mutation occurs quite rarely in GA,

therefore we give a very small mutation rate 𝑃𝑀, which is often in the

interval [0, 0.1]. Every gene should be given a random mutation

probability 𝑃𝑚. If the drawn probability is less than or equal to 𝑃𝑀,

then this gene value should be changed to opposite value (in binary code case, from 0 to 1, or from 1 to 0), which means that mutation occurs.

Example 3.2.6-1:

We perform mutation on chromosome [01101].

Assume that 𝑃𝑀 = 0.02, the probability of each gene is drawn as

following: 0.34, 0.89, 0.01, 0.50 and 0.78.

We can see that the rate of the third gene is 0.01<𝑃𝑀 = 0.02, so this

gene should be changed from 1 to 0. As a result, after mutation, this chromosome becomes [01001].

3.2.7 Obtaining new generation

(21)

feasible solutions at all. Therefore we need modify them or compel them to satisfy the conditions. After that we obtain new feasible solutions, so called current population, with the same size of their parents’ population.

3.2.8 Stopping criterion

The criterion for stopping the genetic algorithm depends on the specific situation of the application of GA.

Situation 1:

If we get the best result 𝑐ℎ𝑖 after i generations, and we are no longer

get better solution in next generations 𝑖 + 1, 𝑖 + 2, 𝑖 + 3 ⋯, then we can stop the algorithm.

Situation 2:

If we have a desired value 𝑓𝑑of the problem, then the program can be

stopped when we get the approaching result, such as in generation i.

Evaluation 𝑓𝑖 of the selection 𝑐ℎ𝑖 is compared to expected value 𝑓𝑑.

If 𝑓𝑖 − 𝑓𝑑 ≤ 𝜀(𝜀 𝑖𝑠 𝑎 𝑣𝑒𝑟𝑦 𝑠𝑚𝑎𝑙𝑙 𝑛𝑢𝑚𝑏𝑒𝑟, 𝑙𝑖𝑘𝑒 𝜀 = 10−15) , then the

algorithm will be stopped. Situation 3:

(22)

If the stopping criterion is met then the best result is taken, otherwise go back to selection step.

3.2.9 Getting the best result

The stop criterion should be checked when we obtain a new generation. If it is satisfied, then we stop the whole program and output the final answer. Otherwise we will go back to the selection step until we achieve the stop criterion. The best result should be a chromosome which has a highest fitness function value.

4. Application of the genetic algorithm to make a university

courses schedule

Time Table Problem (TTP) as a NP-complete (non-deterministic polynomial-time) problem is a typical portfolio optimization and uncertainty scheduling problem, aiming at solving the resources arrangement between time and space. It has been investigated by many researchers albeit with respect to the timetabling of resources in educational institutions (Cole, 1964) (Wood, 1968). The author creates a new model to deal with TTP by GA.

4.1 TTP-model

(23)

class. In this model, the definition of each element has been given as below.

4.1.1 Time

Time-plot set:T = {𝑡1, 𝑡2, ⋯ , 𝑡𝑎, ⋯ 𝑡𝐴}

1. We suppose that every class has lectures weekly.

2. Professors and students do not have lectures on Saturday and Sunday. 3. The minimum unit of one class-time is two hours, so we separate every

workday into 4 time-plots: 8:00-10:00, 10:00-12:00, 13:00-15:00 and

15:00-17:00. So from the time-plot set, 𝑡1means from 8:00 to 10:00 on

Monday, 𝑡2shows from 10:00 to 12:00 on Monday and so on, and

𝑡𝐴means the last time-plot from 15:00 to 17:00 on Friday. Obviously, we

get A = T = 5 × 4 = 20.

4.1.2 Room (Place)

Room set: R = {𝑟1, 𝑟2, ⋯ , 𝑟𝑏, ⋯ 𝑟𝐵}

Every room has its certain seating capacity, we use |𝑟𝑏 to show the

seating capacity of room 𝑟𝑏.

Time-plots respond to rooms, their Cartesian product is

(24)

4.1.3 Professor

Professor set: P = {𝑝1, 𝑝2, ⋯ , 𝑝𝑐, ⋯ 𝑝𝐶}

Professors are knowledgeable, mostly each professor do not only teach

one course. We suppose that professor 1 (𝑝1) can teach 𝛼1 courses,

professor 2 (𝑝2) can teach 𝛼2 courses, and so on.

4.1.4 Lecture (Course)

Lecture set: L = {𝑙1, 𝑙2, ⋯ , 𝑙𝑑, ⋯ 𝑙𝐷}

We assume that each course is only taught by one professor.

Let us rank the elements of lecture set based on the order of professors.

i.e., professor 1 teaches courses from 𝑙1 to 𝑙𝛼1, then professor 2

teaches courses between 𝑙𝛼1+1 and 𝑙𝛼1+𝛼2 and go on. Then

L =

{𝑙1, 𝑙2, ⋯ 𝑙𝛼1, 𝑙1+𝛼1, ⋯ , 𝑙𝛼1+𝛼2, 𝑙1+𝛼1+𝛼2, ⋯ , 𝑙𝛼1+𝛼2+𝛼3, ⋯ , 𝑙1+∑ 𝛼

𝑖 𝐶−1

𝑖=1 , ⋯ , 𝑙𝐷}

Make Cartesian product of professor set and lecture set, we get

M = P × L = {(𝑝1, 𝑙1), (𝑝1, 𝑙2), ⋯ , (𝑝1, 𝑙𝛼1), (𝑝2, 𝑙𝛼1+1), ⋯ , (𝑝𝐶, 𝑙𝐷)} |M|=|L|=D

4.1.5 Class

Class set: C = {𝑐1, 𝑐2, ⋯ , 𝑐𝑒, ⋯ 𝑐𝐸}

(25)

Each class has a certain number of students, defined by |𝑐𝑒 . Such as

class 4 exactly have |𝑐4 students.

4.2 Constraints

In a real case, each element is corresponding to others. We separate these relationships into two parts: “hard constraints” and “soft constraints”. Hard constraint means the situation that we must be exactly satisfied, otherwise it will be against the logic or the fact. Soft constraint is just our expectation and can be used to evaluate the model. In this model, they are defined as follows.

4.2.1 Hard constraints

1. H1: All allocated rooms are large enough.

2. H2: At the same time, each class cannot have a lecture in more than one room.

3. H3: No omission of classes in the timetable is demanded.

4. H4: At the same time, each professor only can teach one lecture in one classroom.

5. H5: At the same time, every room cannot be arranged for more than one lecture.

4.2.2 Soft constraints

(26)

to the seating capacity of the allocated room.

2. S2: Students’ preference of 4 time-plots of one day is different. For example, the best time to study is in the morning. Therefore we should arrange lectures in the good memory time-plot as well as possible.

3. S3: The proper rest time is necessary. It is better to scatter the lectures of each class.

4.3 Solving procedures

Now we solve this problem by GA by following the steps introduced before. The first step which is very important is initializing code. A matrix is a much better coding type to be chosen than the linear type. And the calculation will be simplified if we use binary numbers as the elements of matrix. Since we have 5 elements, it is very hard to show how the 5 hard conditions are satisfied only in one matrix. So the author uses two

matrices (one is C~N, the other is N~M) to analyze the hard constraints

(27)

4.3.1 Creating initialization code based on 5 hard-constraints

The Matrix 𝐶~𝑁 = [𝑎𝑖,𝑗]𝐸×20𝐵 is given in Figure 4.3.1-1.

(𝒕𝟏, 𝒓𝟏) (𝒕𝟏, 𝒓𝟐) (𝒕𝒂, 𝒓𝒃) (𝒕𝟐𝟎, 𝒓𝑩) 𝒄𝟏 𝒄𝟐 𝒄𝒊 𝑎𝑖,𝑗 𝒄𝑬 Figure 4.3.1-1 Matrix 𝐶~𝑁 = [𝑎𝑖,𝑗]𝐸×20𝐵 𝑎𝑖,𝑗 = {0 𝑖𝑓 𝑒𝑣𝑒𝑛𝑡 𝑑𝑜𝑒𝑠 𝑛𝑜𝑡 ℎ𝑎𝑝𝑝𝑒𝑛 1 𝑖𝑓 𝑒𝑣𝑒𝑛𝑡 ℎ𝑎𝑝𝑝𝑒𝑛𝑠

where the event means that the class 𝑖 will have a lecture in room 𝑟𝑏

at time 𝑡𝑎.

H1: All allocated rooms are large enough.

If the capacity of the room 𝑘 is smaller than the number of the students of the class 𝑖, this room 𝑘 should not be arranged to this class 𝑖. Thus

the event will not happen, shown by 𝑎𝑖,𝑘 = 0 no matter in which

time-plot. Specifically, we have 20 time-plots, in another words, 20

columns which include room 𝑘 will be found in the matrix C~N.

According to the room set, we have B rooms in total. Thus in every

(28)

which is indicated by 𝑎𝑖,𝑘+𝐵∙𝑚 = 0, (𝑚 = 0, ⋯ ,19) . The sum of 𝑎-values of all of 20 time-plots will be equal to 0 as well. Therefore H1 can be defined by Function 4.3-1.

Function 4.3-1 If |𝑐𝑖|>|𝑟𝑘|, then ∑ 𝑎𝑖,𝑘+𝐵∙𝑚 19 𝑚=0 = 0 Example 4.3.1-1:

If |𝑐3|>|𝑟5|, then in matrix C~N, cells 𝑎3,5, 𝑎3,𝐵+5, ⋯, 𝑎3,5+19𝐵 in row

𝑐3 take the zero values like in Figure 4.3.1-2.

⋯ (𝒕𝟏, 𝒓𝟓) ⋯ (𝒕𝟐, 𝒓𝟓) ⋯ (𝒕𝟏𝟗, 𝒓𝟓) ⋯ (𝒕𝟐𝟎, 𝒓𝟓) ⋯

𝒄𝟑 ⋯ 𝑎3,5=0 ⋯ 𝑎3,𝐵+5=0 ⋯ 𝑎3,5+18𝐵=0 ⋯ 𝑎3,5+19𝐵=0 ⋯

Figure 4.3.1-2 An example showing H1 ∑ 𝑎3,5+𝐵∙𝑚

19

𝑚=0

= 0

Furthermore, maybe in the same time, more than two classes have the same lecture in the same room. So the sum of the number of the students of the classes which have the same lecture should be less than or equal to the capacity of the arranged room.

(29)

Function 4.3-2 ∑ 𝑎𝑖,𝑗 ∙ 𝑐𝑖 𝐸 𝑖=1 ≤ 𝑟 𝑗−[𝑗−1𝐵 ]∙𝐵 j = 1,2, ⋯ ,20B

[ ] is an integer less than, i.e., [5.4]=5

If 𝑎𝑖,𝑗 = 1, it means the class 𝑖 have a lecture, so ∑𝐸𝑖=1𝑎𝑖,𝑗 ∙ 𝑐𝑖

means the sum of the number of the students. We cannot say the

arranged room is room j, since j may be larger than B. We define the

column-group that contain 𝑡1 from the column 1 to B is 𝑡1 block, and

between B+1 to 2B is 𝑡2 block, and etc., thus [𝑗−1𝐵 ] means how many

time-slots blocks we have passed. Then use 𝑗 − [𝑗−1𝐵 ] ∙ 𝐵 to obtain the

number of allocated room. (Here we cannot use [𝐵𝑗]. If 1 ≤ 𝑗 ≤ 𝐵 (in

time-slot 𝑡1), [𝐵𝑗] should equal to 0, then 𝑗 − [𝑗−1𝐵 ] ∙ 𝐵 = 𝑗. But when 𝑗 = 𝐵, [𝑗

𝐵] will get 1, 𝑗 − [

𝑗−1

𝐵 ] ∙ 𝐵 = 0, which is impossible, so we use

[𝑗−1 𝐵 ] instead [ 𝑗 𝐵], in case 𝑗 = 𝑘𝐵, (𝑘 ∈ 𝑁 +).) Example 4.3.1-2:

Assume that we have 10 rooms in total (B=10), at time-plot 𝑡6, class 𝑐4,

(30)

(𝒕𝟔, 𝒓𝟕)

𝒄𝟒 ⋯ 𝑎4,7+5𝐵 = 𝑎4,57 = 1 ⋯

𝒄𝟔 ⋯ 1 ⋯

𝒄𝟗 ⋯ 1 ⋯

Figure 4.3.1-3 More than 2 classes’ situation in H1 So 𝑐4 ∙ 1 + 𝑐6 ∙ 1 + 𝑐9 ∙ 1 ≤ |𝑟7+5𝐵−[6+5𝐵 𝐵 ]∙𝐵| = |𝑟7+5∙10−[ 6+5∙10 10 ]∙10| = |𝑟57−[56 10]∙10| = 𝑟57−50 = 𝑟7 .

H2: At the same time, every one class cannot have a lecture in more than one room. We depict H2 in Figure 4.3.1-4.

(𝒕𝟏, 𝒓𝟏) ⋯ (𝒕𝟏, 𝒓𝑩) (𝒕𝟐, 𝒓𝟏) ⋯ (𝒕𝟐, 𝒓𝑩) ⋯ (𝒕

𝟏+[𝒋−𝟏𝑩 ], 𝒓𝒋−[𝒋−𝟏𝑩 ]∙𝑩) ⋯

𝒄𝒊 𝑎𝑖,1 𝑎𝑖,𝐵 𝑎𝑖,1+𝐵 𝑎𝑖,2𝐵 𝑎𝑖,𝑗 ⋯

Figure 4.3.1-4 H2 constraint

If 𝑎2,1 = 𝑎2,𝐵 = 1, which means in the time 𝑡1 class no.2 has a lecture

in room no.1 and has a lecture in room no. B as well, that is ridiculous. Therefore, for each class, the sum of 𝑎-values of each time-plot block cannot be larger than 1.

(31)

Function 4.3-3 ∑ 𝑎𝑖,𝑗+𝐵∙𝑛 𝐵 𝑗=1 ≤ 1 i = 1,2, ⋯ , E n = 0, ⋯ , 19

H3: No omission of classes in the timetable. We describe H3 in Figure 4.3.1-5.

(𝑡1, 𝑟1) (𝑡1, 𝑟2) ⋯ (𝑡20, 𝑟𝐵)

𝑐𝒊

Figure 4.3.1-5 H3 constraint

If the sum of row no. 𝑖 is 0, it means the class no. 𝑖 does not have any lectures, which is not allowed.

So for each class

(32)

We reveal the Matrix 𝑁~𝑀 = [𝑏𝑠,𝑡]20𝐵×𝐷 in Figure 4.3.1-6. (𝒑𝟏, 𝒍𝟏) ⋯ (𝒑𝟏, 𝒍𝜶𝟏) (𝒑𝟐, 𝒍𝜶𝟏+𝟏) ⋯ (𝒑𝟐, 𝒍𝜶𝟏+𝜶𝟐) ⋯ (𝒑𝒄, 𝒍𝒅) ⋯ (𝒑𝑪, 𝒍𝑫) (𝒕𝟏, 𝒓𝟏) (𝒕𝟏, 𝒓𝟐) (𝒕𝒂, 𝒓𝒃) 𝑏𝑠,𝑡 (𝒕𝟐𝟎, 𝒓𝑩) Figure 4.3.1-6 Matrix 𝑁~𝑀 = [𝑏𝑠,𝑡]20𝐵×𝐷 𝑏𝑠,𝑡 = {1 𝑖𝑓 𝑒𝑣𝑒𝑛𝑡 ℎ𝑎𝑝𝑝𝑒𝑛𝑠 0 𝑖𝑓 𝑒𝑣𝑒𝑛𝑡 𝑑𝑜𝑒𝑠 𝑛𝑜𝑡 ℎ𝑎𝑝𝑝𝑒𝑛

where event means that the professor 𝑝𝑐 will teach lecture 𝑙𝑑 in room

𝑟𝑏 at time 𝑡𝑎.

H4: At the same time, each professor only can teach one lecture in one classroom. H4 is performed in Figure 4.3.1-7 and Figure 4.3.1-8.

(33)

(𝒑𝟏, 𝒍𝟏) ⋯ (𝒑𝟏, 𝒍𝜶𝟏) (𝒑𝟐, 𝒍𝜶𝟏+𝟏) ⋯ (𝒑𝟐, 𝒍𝜶𝟏+𝜶𝟐) ⋯ (𝒕𝟏, 𝒓𝟏) Σ ≤ 1 Σ ≤ 1 ⋯ (𝒕𝟏, 𝒓𝑩) (𝒕𝟐, 𝒓𝟏) Σ ≤ 1 Σ ≤ 1 ⋯ (𝒕𝟐, 𝒓𝑩) ⋯ ⋯ ⋯

Figure 4.3.1-8 H4 constraint (in detail) At first, we introduce two definitions:

1) 𝑏𝑠. means the sum of row s, shown as ∑𝐷𝑡=1𝑏𝑠,𝑡;

2) 𝑏.𝑡 means the sum of column t, shown as ∑20𝐵𝑠=1𝑏𝑠,𝑡.

We use ∑𝐵𝑠=1𝑏(𝑠+𝑓∙𝐵)., 𝑓 = 0, 1, ⋯ , 19 to show the sum of time-plot

𝑡𝑓+1 block. The first professor can teach 𝛼1 kinds of courses (the

columns which include 𝑝1 are from 1 to 𝛼1), so the sum of the first

professor block is ∑𝛼𝑡=11 𝑏.𝑡. And the second professor can teach 𝛼2

courses (from column 𝛼1 + 1 to 𝛼2), thus the sum is ∑𝛼𝑡=12 𝑏.(𝑡+𝛼1).

Therefore ∑ 𝑏.(𝑡+∑𝛼𝑔

𝑔=0 ), ℎ = 0,1, ⋯ , 𝐶 − 1

𝛼ℎ+1

𝑡=1 means the sum of

professor 𝑝ℎ+1 block. Then we create the function of H4 constraint is as

(34)

Function 4.3-5 ∑ ∑ 𝑏(𝑠+𝑓∙𝐵),(𝑡+∑𝛼𝑔 𝑔=0 ) 𝛼ℎ+1 𝑡=1 𝐵 𝑠=1 ≤ 1 𝑓 = 0,1, ⋯ ,19, ℎ = 0,1, ⋯ , 𝐶 − 1, 𝛼0 = 0 Example 4.3.1-3:

Professor 𝑝4 only can teach one lecture at time 𝑡2 in one room, which

is the sum of 𝑡2− 𝑝4 block should be less than or equal to 1.

In this case, we know that 𝑓 = 1, ℎ = 3,

(35)

⋯ (𝒑𝟒, 𝒍𝟏+𝜶𝟏+𝜶𝟐+𝜶𝟑) ⋯ (𝒑𝟒, 𝒍𝜶𝟏+𝜶𝟐+𝜶𝟑+𝜶𝟒) ⋯ ⋯ (𝒕𝟏, 𝒓𝑩) ⋯ (𝒕𝟐, 𝒓𝟏) ⋯ Σ ≤ 1 (𝒕𝟐, 𝒓𝑩) ⋯ ⋯ Figure 4.3.1-9 An example of H4

H5: At the same time, every room cannot be arranged for more than one lecture. H5 is depicted in Figure 4.3.1-10.

(𝒑𝟏, 𝒍𝟏) ⋯ (𝒑𝟏, 𝒍𝜶𝟏) ⋯ (𝒑𝑪, 𝒍𝑫) (𝒕𝟏, 𝒓𝟏)

Figure 4.3.1-10 H5 constraint

If 𝑏12 = 𝑏16 = 1 which means lecture 2 and lecture 6 both are taught in

room 1 at time-plot 1, that is impossible. Therefore the sum of each row should be less than or equal to 1. We formulate H5 by Function 4.3-6.

(36)

We have already satisfied all of hard constraints, and now we combine

C~N matrix and N~M matrix together, in order to obtain the final initial

chromosome code. The Matrix 𝐶~𝑁~𝑀 = [𝑐𝑝,𝑞]20𝐵𝐸×𝐷 is shown in

Figure 4.3.1-11. (𝒑𝟏, 𝒍𝟏) ⋯ (𝒑𝟏, 𝒍𝜶𝟏) (𝒑𝟐, 𝒍𝜶𝟏+𝟏) ⋯ (𝒑𝟐, 𝒍𝜶𝟏+𝜶𝟐) ⋯ (𝒑𝑪, 𝒍𝑫) (𝒄𝟏, 𝒕𝟏, 𝒓𝟏) (𝒄𝟏, 𝒕𝟏, 𝒓𝟐) 𝑐𝑝,𝑞 (𝒄𝑬, 𝒕𝟐𝟎, 𝒓𝑩) Figure 4.3.1-11 Matrix 𝐶~𝑁~𝑀 = [𝑐𝑝,𝑞]20𝐵𝐸×𝐷

when 𝑐11 = 1, then it shows that professor 𝑝1 will teach class 𝑐1

lecture 𝑙1 in room 𝑟1 at time-plot 𝑡1, which means in matrix C~N

𝑎11 = 1 and in matrix N~M 𝑏11 = 1. If one of 𝑎-value or b-value is 0,

the event will not happen, thus c value should be equal to 0.

The combining function is following:

Function 4.3-7 𝑐𝑝,𝑞 = 𝑎([𝑝−1 20𝐵]+1),(𝑝−[ 𝑝−1 20𝐵]∙20𝐵) ∙ 𝑏(𝑝−[ 𝑝−1 20𝐵]∙20𝐵),𝑞 Example 4.3.1-4:

For 𝑐35,20 in the row 35 and column 20, we should find its position in

matrix C~N~M first and then connect it to matrix C~N and matrix N~M.

(37)

is included from row 1 to row 20B, 𝑐2 is belonging to the rows between

row 20B+1 and row 40B and so on. So use [20𝐵34] + 1 to obtain the order

of class (𝑐[34

20𝐵]+1), same as the number of the row in matrix C~N. From

𝑝 − [𝑝−1

20𝐵] ∙ 20𝐵, we obtain the order of time-room group, same as the

column in matrix N~M. The row of matrix N~M is in accordance with

the column of matrix C~N. And the columns of matrix N~M and matrix

C~N~M are totally the same. Now we know that 𝑐35,20 is

corresponding to 𝑎([34 20𝐵]+1),(35−[ 34 20𝐵]∙20𝐵) and 𝑏(35−[ 34 20𝐵]∙20𝐵),20, only when 𝑎([34 20𝐵]+1),(35−[ 34 20𝐵]∙20𝐵) and 𝑏(35−[ 34

20𝐵]∙20𝐵),20 are both equal to 1,

as a result 𝑐35,20 = 1, otherwise 𝑐35,20 = 0.

Since if and only if 𝑎([𝑝−1

20𝐵]+1),(𝑝−[ 𝑝−1

20𝐵]∙20𝐵) = 1 and 𝑏(𝑝−[ 𝑝−1

20𝐵]∙20𝐵),𝑞 = 1,

then 𝑐𝑝,𝑞 = 1. Thus 𝑐𝑝,𝑞 still satisfies H1, H2, H4, H5 which ask for the

upper bound. An auxiliary condition should be added in case when H3 is broken. Function 4.3-8 ∑ ∑ 𝑐𝑝+𝐾∙20𝐵 20𝐵 𝑝=1 𝐷 𝑞=1 ≥ 1 𝐾 = 0, 1, ⋯ , 𝐸 − 1

So the sum of every class block in matrix C~N~M cannot be equal to 0,

to make sure that no omission of classes happens.

(38)

Initialization of chromosomes

Procedure Initialization (for each chromosome)

Step1: generate matrix C~N and matrix N~M randomly, 𝑎𝑖,𝑗and 𝑏𝑠,𝑡

equals to 0 or 1

Step2: check H1, H2, H3 in matrix C~N, check H4, H5 in matrix N~M, if they are satisfied, go to step 3, else, go back to step1

Step3: combine matrix C~N and matrix N~M to be matrix C~N~M Figure 4.3.1-12 Initialization

Modify

From the combining function, we will know that if one of 𝑎-value and

𝑏-value is equal to 0 then the corresponding c-value 𝑐𝑝,𝑞 = 0. But

actually if 𝑐𝑝,𝑞 = 0 which means none of class will have lectures in that

room at that time, therefore the real 𝑎([𝑝−1

20𝐵]+1),(𝑝−[ 𝑝−1

20𝐵]∙20𝐵) value and

𝑏(𝑝−[𝑝−1

20𝐵]∙20𝐵),𝑞 value should both be equal to 0. For instance if 𝑎11 =

1(which means 𝑐1 have a lecture in 𝑟1 at 𝑡1) and ∑𝐶𝑡=1𝑏1,𝑡 = 0(𝑏1. =

0 which means none of professors will teach lectures in 𝑟1 at 𝑡1), after

calculation or observing the table we get ∑𝐶𝑞=1𝑐1,𝑞 = 0 (𝑐1. = 0) which

means that 𝑐1 does not have any lectures in 𝑟1 at 𝑡1, so the real 𝑎11

is 0. Then we need to correct the matrix C~N and matrix N~M. In

accordance with the logic, if 𝑐𝑝,𝑞 = 1, then

𝑎

([𝑝−120𝐵]+1),(𝑝−[𝑝−120𝐵]∙20𝐵) = 1 𝑎𝑛𝑑 𝑏(𝑝−[𝑝−120𝐵]∙20𝐵),𝑞 = 1.

(39)

𝑎([𝑝−1

20𝐵]+1),(𝑝−[𝑝−120𝐵]∙20𝐵) = 0 𝑎𝑛𝑑 𝑏(𝑝−[𝑝−120𝐵]∙20𝐵),𝑞 = 0.

We use 𝑎𝑖,𝑗′ to show the new 𝑎-value after modification, and define

𝑏𝑠,𝑡 as the new 𝑏-value after modification.

After comparing with matrix C~N and matrix C~N~M, we try to find

the relation of 𝑎𝑖,𝑗 and 𝑐𝑝,𝑞, shown by Figure 4.3.1-13.

(𝒕𝟏, 𝒓𝟏) 𝑵𝒋 (𝒕𝟐𝟎, 𝒓𝑩) 𝒄𝟏 𝒄𝒊 𝑎𝑖,𝑗 𝒄𝑬 (𝒑𝟏, 𝒍𝟏) (𝒑𝑪, 𝒍𝑫) (𝒄𝟏, 𝒕𝟏, 𝒓𝟏) (𝒄𝒊, 𝑵𝒋) 𝑐𝑗+(𝑖−1)∙20𝐵,𝑞 (𝒄𝑬, 𝒕𝟐𝟎, 𝒓𝑩)

Figure 4.3.1-13 The relationship between 𝑎𝑖,𝑗 and 𝑐𝑝,𝑞

(40)

Matrix C~N includes class, room and time-plot. These three elements

are the same as in the contents of each row in matrix C~N~M.

Therefore the 𝑎-value 𝑎𝑖,𝑗 is corresponding to the sum of the whole

row (𝑐𝑖, 𝑁𝑗) of matrix C~N~M. We thus know that matrix C~N~M

satisfies H2 and H4, so ∑𝐷𝑞=1𝑐𝑝,𝑞 ≤ 1, 𝑝 = 1, 2, ⋯ , 20𝐵𝐸 to insure that

the new 𝑎𝑖,𝑗′ is a binary number.

After modification Function 4.3-9 𝑎𝑖,𝑗= ∑ 𝑐 𝑗+(𝑖−1)∙20𝐵,𝑞 𝐷 𝑞=1

Then we modify the matrix N~M, the comparison between matrix N~M

(41)

(𝒑𝟏, 𝒍𝟏) 𝑴𝒕 (𝒑𝑪, 𝒍𝑫) (𝒕𝟏, 𝒓𝟏) 𝐍𝒔 𝑏𝑠,𝑡 (𝒕𝟐𝟎, 𝒓𝑩) (𝒑𝟏, 𝒍𝟏) ⋯ 𝑴𝒕 ⋯ (𝒑𝑪, 𝒍𝑫) (𝒄𝟏, 𝑵𝑺) 𝑐𝑠,𝑡 (𝒄𝟐, 𝑵𝑺) 𝑐𝑠+20𝐵,𝑡 ⋯ (𝒄𝑬, 𝑵𝑺) 𝑐𝑠+(𝐸−1)∙20𝐵,𝑡

Figure 4.3.1-14 The relationship between 𝑏𝑠,𝑡 and 𝑐𝑝,𝑞

If the event will not happen at 𝑁𝑆, then ∑𝐸−1𝑛=0𝑐𝑠+20𝐵∙𝑛,𝑡 = 0 and

𝑏𝑠,𝑡 = 0 as well.

If one class or more than one class have the same lecture at 𝑁𝑆, then

∑𝐸−1𝑐𝑠+20𝐵∙𝑛,𝑡

𝑛=0 ≥ 1. Since 𝑏𝑠,𝑡 is a binary number, we apply 𝜃 function.

After modification

𝜃(Σ) = 𝑏𝑠,𝑡

(42)

Function 4.3-10 𝑏𝑠,𝑡= 𝜃 (∑ 𝑐 𝑠+20𝐵∙𝑛,𝑡 𝐸−1 𝑛=0 ) (𝜃(𝑥) = {0, 𝑥 ≤ 0 1, 𝑥 > 0)

4.3.2 Formulating the fitness function according to 3 soft-constraints

The soft-constraints can help us evaluate the model.

S1: After making sure that the arranged room is large enough, we should think about the using rate of the room, of course the higher rate the better. Therefore the number of the class students had better is similar to the seating capacity of the allocated room. We classify the rooms into small-sized, middle-sized, and large-sized based on the different seating capacity. And do the same thing with the set of classes. It is very easy to notice that there is a little bit waste if we use a large-sized room for a small-sized class. Preference degree of utilization of rooms is given by Table 4.3.2-1.

Table 4.3.2-1 Preference degree of utilization of rooms

(43)

Assume that classes 𝑐1~𝑐are small-sized, 𝑐ℎ+1~𝑐𝑙 are middle-sized,

𝑐𝑙+1~𝑐𝐸 are large-sized, rooms 𝑟1~𝑟𝑛 are small-sized, 𝑟𝑛+1~𝑟𝑚 are

middle-sized, 𝑟𝑚+1~𝑟𝐵 are large-sized. And in each same size level, the

capacity of rooms should be larger than the number of students. We

create matrix 𝐷 = [𝑑𝛼,𝛽]𝐸×𝐵 shown in Figure 4.3.2-1to reveal S1.

𝒓𝟏 𝒓𝒏 𝒓𝒏+𝟏 𝒓𝒎 𝒓𝒎+𝟏 𝒓𝑩 𝒄𝟏 10 6 2 𝒄𝒉 𝒄𝒉+𝟏 0 10 6 𝒄𝒍 𝒄𝒍+𝟏 0 0 10 𝒄𝑬

Figure 4.3.2-1 S1 constraint (matrix 𝐷 = [𝑑𝛼,𝛽]𝐸×𝐵)

Small-sized Middle-sized Large-sized

(44)

We use 𝑓1 to show the sum of room used degrees of all classes. In S1, a class and a room are the only two elements that have been mentioned,

thus we just need matrix C~N to express 𝑓1 in order to simplify the

calculation. Since 𝑎𝑖,𝑗′ , 𝑗 is from 1 to 20B, but 𝑑𝛼,𝛽, 𝛽 is from 1 to B, the

d-value should multiply the corresponding 𝑎-value of each time-plot.

Then get the sum. So Function 4.3-11 𝑓1 = ∑ ∑ 𝑎𝑖,𝑗′ ∙ 𝑑 𝑖,𝑗−[𝑗−1𝐵 ]∙𝐵 𝐸 𝑖=1 20𝐵 𝑗=1

S2: The best time to study new knowledge is in the morning. And at noon, students are usually sleepy, could not focus on the study. The preference of students in different time-plots is given by Table 4.3.2-2.

(45)

Table 4.3.2-2 Preference of timeslot

Timeslot 𝒕𝟏 𝒕𝟐 𝒕𝟑 𝒕𝟒 𝒕𝟓 𝒕𝟐𝟎

Expected value

12 8 4 6 12 6

We use 𝑓2 to define the sum of timeslot preference degrees of arranged

lectures. Only class element and time-plot element are shown in S2, so

we still use matrix C~N to calculate 𝑓2. The preference degree of

time-plot 𝑡1+4𝑛, 𝑛 = 0, 1, ⋯ ,4 is equal to 12, and the preference

degree of 𝑡2+4𝑛 𝑖𝑠 8 and so on. Then the sum is

Function 4.3-12 𝑓2 = ∑ ∑ ∑(12 ∙ 𝑎𝑖,𝑗+4𝐵∙𝑛+ 8 ∙ 𝑎 𝑖,𝑗+𝐵+4𝐵∙𝑛 ′ + 4 ∙ 𝑎 𝑖,𝑗+2𝐵+4𝐵∙𝑛′ 4 𝑛=0 𝐵 𝑗=1 𝐸 𝑖=1 + 6𝑎𝑖,𝑗+3𝐵+4𝐵∙𝑛)

S3: The lectures of each class should be scattered as best as we can. The time between two lectures cannot be too long or too short. On one side, it is hard to remember the knowledge after long time. And on the other side, if the students have next lecture immediately, usually they will not get it very well.

(46)

Table 4.3.2-3 Preference of time length degree of courses (Zhang & Xing, 2002) Time length between two adjacent lessons 𝒙 1,19 2,3,17,18 4,5,15,16 6,7,13,14 8,9,10,11,12 Expected value 𝐠(𝒙) 0 2 4 10 16 g(𝑥) = { 0, 𝑖𝑓 𝑥 = 1 or 19 2, 𝑖𝑓 𝑥 = 1,2,17 𝑜𝑟 18 4, 𝑖𝑓 𝑥 = 4,5,15 𝑜𝑟 16 10, 𝑖𝑓 𝑥 = 6,7,13 𝑜𝑟 14 16, 𝑖𝑓 𝑥 = 8,9,10,11 𝑜𝑟 12}

𝑥 means the time length between two adjacent lessons, if class 𝑐𝑣

have lectures at time-plot 𝑡𝑚 and 𝑡𝑛, then the time length is

𝑥 = 𝑚 − 𝑛 . For example if 𝑐1 has a lecture at 8:00-10:00 on Monday

(𝑡1), and the next lecture is from 10:00 to 12:00 on Monday (𝑡2), the

time length between these two lectures is 1, then according to Table 4.3.2-3 the expected value is 0.

In the row 𝑖 of matrix [𝑎𝑖𝑗′ ]

𝐸×20𝐵 (the new matrix C~N after

modification, refer to Figure 4.3.1-1), find the positions of 𝑎-values

which are equal to 1 (such as Figure 4.3.2-2), which means the class 𝑐𝑖

has lectures at those time-plots. We define the column of the first

(47)

the time-plot of 𝑎𝑖,𝛽1 is [𝛽1𝐵−1] + 1, and 𝑎𝑖,𝛽2 belongs to the time-plot [𝛽2−1

𝐵 ] + 1. So that class 𝑐𝑖 has a lecture at time-plot 𝑡[𝛽1−1𝐵 ]+1 and the

next lecture is at 𝑡[𝛽2−1 𝐵 ]+1

, thus the time length preference degree of these two lectures is g ([𝛽2𝐵−1] − [𝛽1𝐵−1]). If 𝑐𝑖 has 𝑊 lectures every

week, so 𝑎𝑖,𝛽𝜔 = 1, 𝜔 = 1, ⋯ , 𝑊, (as in Figure 4.3.2-2) the time length

preference degree of 𝑐𝑖 every week is

∑ g ([𝛽𝜔+1 − 1 𝐵 ] − [ 𝛽𝜔 − 1 𝐵 ]) 𝑊−1 𝜔=1 (𝒕𝟒, 𝒓𝟐) (𝒕𝟖, 𝒓𝟔) (𝒕𝟏𝟓, 𝒓𝟑) ⋯ 𝒄𝒊 0 1 0 1 0 1 0

Figure 4.3.2-2 Find the positions of 𝑎𝑖,𝛽𝜔 = 1

Example 4.3.2-1:

Assume that class 𝑐3 has 3 lectures every week, and we have 10 rooms

in total. Lecture 1 is at (𝑡1, 𝑟2), lecture 3 is at (𝑡5, 𝑟6), and lecture 1 is at

(𝑡17, 𝑟3). The schedule table is as in Figure 4.3.2-3,

(48)

So the time length preference degree of class 𝑐3 is ∑ g ([𝛽𝜔+1 − 1 𝐵 ] − [ 𝛽𝜔 − 1 𝐵 ]) 𝑊−1 𝜔=1 = ∑ g ([𝛽𝜔+1− 1 𝐵 ] − [ 𝛽𝜔 − 1 𝐵 ]) 2 𝜔=1 = g ([𝛽2− 1 𝐵 ] − [ 𝛽1− 1 𝐵 ]) + g ([ 𝛽3 − 1 𝐵 ] − [ 𝛽2− 1 𝐵 ]) = g ([46 − 1 10 ] − [ 1 − 1 10 ]) + g ([ 163 − 1 10 ] − [ 46 − 1 10 ]) = g(4 − 0) + g(16 − 4) = g(4) + g(12) = 4 + 16 = 20

Define 𝑓3 as the sum of time length preference degrees of all classes.

Function 4.3-13 𝑓3 = ∑ ∑ g ([𝛽𝜔+1− 1 𝐵 ] − [ 𝛽𝜔 − 1 𝐵 ]) 𝑊−1 𝜔=1 𝐸 𝑖=1

Then we obtain the fitness function as

𝑓 = 𝑓1+ 𝑓2 + 𝑓3

Thus the procedure of fitness is performed as Figure 4.3.2-4. Evaluation of fitness of chromosomes

Procedure fitness (for each chromosome)

Stage1: modify matrix [𝑎𝑖,𝑗]𝐸×20𝐵 based on matrix [𝑐𝑝,𝑞]20𝐵𝐸×𝐷 ,

become matrix [𝑎𝑖,𝑗]𝐸×20𝐵 Stage2: calculate fitness function f

(49)

4.3.3 Solving TTP by GA

Selection

Then we use roulette-wheel method (introduced in chapter 3) to select parents’ chromosomes.

Crossover

Here we declare 𝑃𝐶𝑟𝑜𝑠𝑠𝑜𝑣𝑒𝑟 = 0.75, then we draw a random probability

𝑃𝑐 ∈ [0, 1] for every pair of selected chromosomes. If 𝑃𝑐 ≤ 𝑃𝐶𝑟𝑜𝑠𝑠𝑜𝑣𝑒𝑟,

(50)

After crossover of parents 𝑃𝑎𝑟𝑒𝑛𝑡1 and 𝑃𝑎𝑟𝑒𝑛𝑡2 , we get the

offspring’s chromosomes 𝑂1 and 𝑂2.

Mutation

Here we define 𝑃𝑀 = 0.02, generate a random 𝑃𝑚 ∈ [0,1] for each

element of each offspring’s chromosome. If 𝑃𝑚 ≤ 𝑃𝑀, then the 𝑐 value

will be changed to opposite figure, like:

𝑐𝑝,𝑞: 0 → 1 𝑜𝑟 1 → 0

Obtain new generations

Then we will obtain the new generations. If they satisfy 5 hard constraints then go on, check the stopping criterion. Otherwise, choose new rows and columns to do crossover and mutation again until the offspring’s chromosomes are feasible solutions.

Stopping criterion

Stop after 3000 iterations, to see the result.

4.4 Result

(51)

Table 4.4-1 The parameter list Parameters Value Number of time-slots 20 Number of rooms 5 Number of professors 10 Number of classes 4

Number of lectures of each professor 4

Crossover rate 0.75

Mutation rate 0.02

(52)

We plot 3D graph in Figure 4.4-1.

Figure 4.4-1 3D graph of the result

Fitn

ess

Iteration

(53)

If we take out the largest fitness value of every iteration population and draw a regression line based on these largest values, then they are performed like in Figure 4.4-2.

Figure 4.4-2 The largest fitness value of each iteration population and regression line

As expected, the results will be converged and we obtain the best result which is around 650.

(54)

In order to check the effect of population on the result, we test different population sizes of 20, 30 and 40 with crossover rate 0.75, the result is seen in Figure 4.4-3.

Figure 4.4-3 Comparison with different population sizes

(55)

And if we compare population sizes of 30 with different crossover rates: 0.70, 0.75 and 0.80, we will get the result in Figure 4.4-4.

Figure 4.4-4 Comparison with different crossover rates

As we can see, the result did not change so much with different crossover rates.

By comparing the time consumption with different population sizes as in Table 4.4-2, we find that the whole procedure with larger population size spends longer time to find the best result. And the figure of population-time (plotted in Figure 4.4-5) almost looks like a straight line.

P𝐶 = 0.70

P𝐶 = 0.75

P𝐶 = 0.80

Fitness

(56)

Table 4.4-2 The result of comparison Population Time[Sec] 10 43.1193 20 88.9606 30 133.7512 40 179.7556 50 228.0954 60 269.2885 70 313.9937 80 362.2176 90 426.1943 100 520.9020

(57)

5 Conclusion and further work

This dissertation aims to introduce a very useful optimization method— the genetic algorithm. Besides what is mentioned in this dissertation, there are many extensions, such as multiple selection methods, complicated crossover ways and so on. When we face different practical problems, a suitable selection method should be chosen and instead of one crossover point (which is shown in this dissertation) two or more crossover point can also be used. Furthermore, when depending on the requirement of the question we could adjust mutation rate, for instance, as the addition of the iteration mutation rate becomes smaller to decrease mutation.

The genetic algorithm is particularly appropriate for solving timetabling and scheduling problems, and many scheduling software packages are based on this method. Other application domains of GA include computer-automated design, video game design, test of fuzzy control system, artificial intelligence design, mechatronics design and so on. The application based on GA to make a university time schedule is shown in this dissertation for the sake of popularizing the idea of GA better. Different from other dissertations which solved TTP by GA as well, the author creates a new model with considering that:

(58)

2) More than one class will have a same lecture at the same time in the same room,

3) The best time to study is in the morning, and it is very difficult to remember the knowledge in the time-plot 13:00-15:00 since the students are sleepy.

Furthermore the binary matrix is adopted to create initialization code, which is the most effective. The author formulates this new model including 5 hard constraints and 3 soft constraints in a fresh way, so that the solving procedure is more intuitional and easier to be understandable.

And further investigation is necessary regarding the following issues: 1. Rooms can be classified into lecture rooms and labs.

2. Compulsory courses should be taken into consideration. According to the real requirement we compel the corresponding c-value to be 1. 3. In order to check the effectiveness of GA, a comparison with other

algorithms seems necessary.

(59)

References

Chu, P., & Beasley, J. (1995). “A genetic algorithm for the generalized assignment problem”. European Journal of Operational Research.

Davis, L. (1991). “Handbook of Genetic Algorithms”. Van Nostrand Reinhold.

Wikipedia. (2010, 12). Retrieved 12 2011, from WIKIPEDIA: http://en.wikipedia.org/wiki/Genetic_algorithm

John H. Holland (1975). “Adaptation in Natural and Artificial Systems”. A Bradford Book.

Markoff, J. (1990-08-29). “What's the Best Answer? It is Survival of the Fittest”. New York Times.

Rutkowski, L. (2005). “Computational intelligence”. Polish Scientific Publishers PWN.

Obitko, M. (1998, 8). Retrieved 3 2012, from

http://www.obitko.com/tutorials/genetic-algorithms/selection.php

Cole, A. (1964, 7). “The preparation of examination timetables using a small store computer”. Computer Journal, pp. 117-121.

Wood, D. (1968, 11). “A system for computing university examination timetable”. Computer Journal, pp. 41-47.

(60)

Table 4.3.2-1 Preference degree of utilization of rooms Table 4.3.2-2 Preference of timeslot

Table 4.3.2-3 Preference of time length degree of courses Table 4.4-1 The parameter list

Table 4.4-2 The result of comparison Figure 3.2.1-1 Solving procedures of GA

Figure 3.2.4-1 Pie graph of an example of roulette wheel

Figure 4.3.1-1 Matrix 𝐶~𝑁 = [𝑎𝑖,𝑗]𝐸×20𝐵

Figure 4.3.1-2 An example showing H1

Figure 4.3.1-3 More than 2 classes’ situation in H1 Figure 4.3.1-4 H2 constraint

Figure 4.3.1-5 H3 constraint

Figure 4.3.1-6 Matrix 𝑁~𝑀 = [𝑏𝑠,𝑡]20𝐵×𝐷

Figure 4.3.1-7 H4 constraint

Figure 4.3.1-8 H4 constraint (in detail) Figure 4.3.1-9 An example of H4 Figure 4.3.1-10 H5 constraint

Figure 4.3.1-11 Matrix 𝐶~𝑁~𝑀 = [𝑐𝑝,𝑞]20𝐵𝐸×𝐷

Figure 4.3.1-12 Initialization

Figure 4.3.1-13 The relationship between 𝑎𝑖,𝑗 and 𝑐𝑝,𝑞

Figure 4.3.1-14 The relationship between 𝑏𝑠,𝑡 and 𝑐𝑝,𝑞

(61)

Figure 4.3.2-2 Find the positions of 𝑎𝑖,𝛽𝜔 = 1 Figure 4.3.2-3 An example of S3

Figure 4.3.2-4 Fitness Figure 4.3.3-1 Crossover

Figure 4.4-1 3D graph of the result

Figure 4.4-2 The largest fitness value of each iteration population and regression line

References

Related documents

The second pair also takes the interviewer’s question as a prompt to produce expres- sive domain text by describing the meaning in terms of the weakly institutionalised

Haplotypes are inferred using a four step recursive approach, where step one and two were adapted from Qian and Beckmann [6]. The algorithm successively i) infers the parental origin

The dimensions are in the following section named Resources needed to build a sound working life – focusing on working conditions and workers rights, Possibilities for negotiation and

However, in a comment, also published in this journal, Haab, Huang and Whitehead (1999) (henceforth HHW) claim that the results of CEHM do not reject the hypothesis of

14 The rebel governance variables thus allow this thesis to assess three different factors: (1) does the gen- eral presence of rebel governance influences fragmentation, (2) does

As we want to investigate how the Marikana incident was portrayed in the press a critical discourse analysis will provide tools to uncover underlying values within the content and

I denna studie kommer gestaltningsanalysen att appliceras för att urskilja inramningar av moskéattacken i Christchurch genom att studera tre nyhetsmedier, CNN, RT

A method of recommending a connection is to measure different metrics e.g throughput and packet loss for Bluetooth (BT) and each channel on 2.4GHz and 5GHz Wireless Area