• Tidak ada hasil yang ditemukan

Chapter 7 A Genetic Algorithm Approach using a Direct Representation

7.5 Genetic operators for Phase 1

The only genetic operator used is mutation (reasons for not implementing the crossover operator has been discussed in section 5.4.5 in Chapter 5). This study will follow a similar approach to that of studies in the literature (see section 5.4.5 in Chapter 5) where the mutation operators involved swapping teachers (or venues) between positions in the timetable. In the literature, some studies (such as [ABRA91a] and [DIST01]) incorporated hill climbing with their mutation operators. This study will test the mutation operators with (lines 2 to 20 of Algorithm 7.3) and without (lines 21 to 28 of Algorithm 7.3) hill climbing. In hill climbing, an offspring is rejected if its fitness is worse than the fitness of the parent. If the constraint cost is reduced or remains the same, then the swap is deemed successful. Lines 12 to 15 for Algorithm 7.3 reflect this evaluation.

Algorithm 7.3: Mutation operator 1. Obtain parent using selection method

2. If Hill climbing is used 3. {

4. HillClimbingSteps = 0

5. Do

6. {

7. Offspring = Copy Parent

8. For MutLoop = 1 to Swaps

9. {

10. Mutate Offspring

11. Evaluate Fitness of Offspring

12. If (OffspringFitness < PreviousOffspringFitness)

13. Accept swap

14. Else

15. Reject Swap

16. }

17. HillClimbingSteps++

18. }

19. While (ParentFitness < OffspringFitness) AND (HillClimbingSteps < 500) 20. }

21. Else If Hill Climbing is not used 22. {

23. For MutLoop = 1 to Swaps

24. {

25. Mutate Offspring

26. Evaluate Fitness of Offspring

27. }

28. }

29. Add Offspring to new generation

Mutation of the offspring is performed in lines 10 and 25. Sections 7.5.1 to 7.5.3 describe the Phase 1 mutation operators implemented by the genetic algorithm. Section 7.5.4 describes the concept of hill climbing.

7.5.1 Two violation mutation (2V)

This mutation operator searches for two cells that contain hard constraint violations. The two teachers (or venues) are then swapped within the timetable possibly resulting in the removal of hard constraint violations. This implementation was based on the mutation operators used by Di Stefano et al. [DIST01] and Filho et al. [FILH01].

An example of an application of this mutation operator is illustrated in Figure 7.2 and explained below. T1 represents teacher 1 being allocated to class 1 during period 1. While a venue could be involved, it is not represented as it is not part of the example below.

Class

Period 1 2 3 4

1 T1 T2 T3 T4

2 T1 T1 T2 T4

Clash here as T1 allocated to 2 classes

3 T4 T3 T2 T1

4 T3 T4 T1 T2

5 T3 T3 T2 T4

Clash here as T3 allocated to 2 classes

6 T2 T4 T4 T3

Clash here as T4 allocated to 2 classes

Figure 7.2: Finding 2 violations

The timetable segment in Figure 7.2 shows three clashes. In period 2, T1 has been allocated to both classes 1 and 2. In period 5, T3 has been allocated to two classes and in period 6, T4 has been allocated to 2 classes. The mutation operator firstly locates a clash, so it finds any one of the three teacher clashes. In this example, the clash found is in period 2, class 2. The two remaining possible clashes are during periods 5 and 6 where T3 and T4 clash respectively. Any one of the two clashes can be chosen. If T4 in period 6 is chosen as the second clashing tuple, then the contents of this cell and the contents of the first cell with a clash are swapped. This resultant mutation means that T4 moves to period 2 and T1 moves to period 6 (for class 2). This change is shown in Figure 7.3. The above example only reflects clashes but this mutation operator applies to any hard constraint violation. For example, if the availability constraints specify that T2 is not available to teach during period 6, then this is regarded as an availability violation. The constraint violation, once identified, is then swapped with another cell with a hard constraint violation.

Class

Period 1 2 3 4

1 T1 T2 T3 T4

2 T1 T4 T2 T4

Clash here as T4 allocated to 2 classes

3 T4 T3 T2 T1

4 T3 T4 T1 T2

5 T3 T3 T2 T4

Clash here as T3 allocated to 2 classes

6 T2 T1 T4 T3

Figure 7.3: Resultant timetable after 2 violation swap – Example 1

The swap shown in Figure 7.3 will fix the clashing situation in row 6, but the swap will result in a new clash occurring in period 2 where T4 is being allocated to two classes. If T3 in period 5 were to be swapped instead of T4, then the following (Figure 7.4) occurs:

Class

Period 1 2 3 4

1 T1 T2 T3 T4

2 T1 T3 T2 T4

3 T4 T3 T2 T1

4 T3 T4 T1 T2

5 T3 T1 T2 T4

6 T2 T4 T4 T3

Clash here as T4 allocated to 2 classes

Figure 7.4: Resultant timetable after 2 violation swap – Example 2

This is the ideal scenario as the swap has fixed two clashes. The worst case scenario will be for a swap to result in another clash. Note that the swaps only occur within a selected column (class) in order to avoid the movement of teachers to classes that they are not required to teach.

7.5.2 One violation mutation (1V)

This mutation operator, also based on the operators used by [DIST01] and [FILH01], follows the same procedure as 2V mutation with the difference being that only one constraint violation is located rather than two. Once a constraint violation is found, a second timeslot is then randomly chosen. The contents in the second timeslot may or may not result in a hard constraint violation but must be randomly chosen from the same class (column) as the first teacher in order to avoid the allocation of teachers to classes that they are not required to teach. Once chosen, the contents of the two cells are swapped. This results in three possible scenarios:

 Worst Case: A swap results in two constraint violations.

 Middle Case: A constraint violation is removed but causes a new constraint violation in another location.

 Best Case: The second cell chosen has a constraint violation and both violations are removed.

7.5.3 Hill climbing versus non-hill climbing operators

Genetic operators are potentially destructive in that they could continuously result in offspring that are worse than the parents [BANZ98]. Hill climbing will prevent this by only accepting swaps that improve the fitness of the individual. The disadvantage of hill climbing is that it is susceptible to local minima i.e. the algorithm will reach an area of the search space that appears to be promising (heading towards convergence) by ensuring that offspring always improve but instead the algorithm convergences prematurely [BEAS93]. As mentioned in section 5.4, this study will evaluate the use of mutation operators with and without hill climbing.

Similar to the studies by [CERD08] and [RAHO06], when hill climbing is used, it is implemented within the mutation process. While the timetable is being mutated, the currently mutated version is compared to either the parent or the timetable from the previous swap (if this swap has improved fitness). If the fitness of the new version is better than the current version, then the swap is accepted. If the older version has a better fitness then the swap is rejected. A limit is used to prevent the problem of premature convergence (to a local minimum) and to prevent long runtimes when the offspring cannot be further improved (lines 4, 17 and 19 in Algorithm 7.3). The mutation operators with hill climbing are referred to as two violation hill climbing (2VH) and one violation hill climbing (1VH) while the non-hill climbing operators are referred to as two violation non-hill climbing (2VNH) and one violation non-hill climbing (1VNH).