4.3.1 Simulated Annealing Algorithm and Energy Function
Originally, the idea behind the foundation of simulated annealing, SA, stands on ideas came from physics and it resembles the idea of the solid physical annealing (Kirkpatrick, Gelatt and Vecchi, 1983). But why such a physical problem would be even of an interest? To know the answer, understand the mechanism of coercing a solid into a low energy-state where the solid became in a highly ordered state. To achieve this, the material is heated (annealed) and then cooled very slowly and very carefully coming into a thermal equilibrium at each state (temperature level) until it freezes and reaches its good state. Similarly, simulated annealing, at each stage (temperature level), uses the Metropolis algorithm that simulates the behavior of the controlled cooling operations to solve any possible optimization problem and gives a solution that is taken from a bad, unsolved, and unordered state into a highly optimized, good and desirable state.
In other words, the SA algorithm behaves like the natural phenomenon by searching and exploring (perturbing) the solution search space (energy landscape) looking for optimizing the energy function (cost/objective function) of the problem. SA starts working on an initial solution by setting an initial high (artificial) temperature and, during its work, the temperature is reduced gradually until it reaches the freezing point (Mansour and Timani, 2007).
Therefore, the initial semi-random solution, that we ended up with after performing the constructive generation step using controlled randomization, will be the initial solution our adapted SA algorithm will start with in order to fix the hard conflicts only while ignoring completely the soft constraints. In our approach, SA is used to solve the teacher conflicts (TC), the curriculum conflicts (CC) as well as the time availability conflicts which we allow their violation again at this step in order not to restrict or limit the search space for the correction of TC and CC. The main
reason because we are targeting to have a solution that will be more scalable than the one Muller (2008, 2009) got using Iterative Forward Search and not only to get a feasible solution for small problems. Our algorithm will work on large problems as well as on small problems; unlike Muller’s work in which he is simply doing an exhaustive search that will not work for large problems (2008, 2009). Figure 4.3 shows our simulated annealing algorithm that is adapted to solve CCTP. Let energy function for SA is:
OF=E =
φ
*STC +ψ
*SCC +ω
*SAvailwhere
φ
=50,ψ
=1, andω
=1. 1. Calculate the initial temperature T0 and set Ti = T0; 2. Calculate the freezing temperature Tf ; 3. Set bestSolution = initialsolution; 4. Set currentSolution = null; 5. while (Ti > Tf and not converged) do a. Save bestSolution in currentSolution b. repeat (10*LecturesNum* WorkingDaysNumber * SlotsPerDay ) times i. Set energy value of currentSolution in Ecurrent ii. Perturb();iii. Save solution in perturbedSolution having energy value Eperturbed iv. Calculate ΔOF = Eperturbed ‐ Ecurrent
v. if ( ΔOF < 0 ) then
update() & currentSolution= perturbedSolution; /* accept */
else if (0 < randomNum() < e‐ΔOF/Ti) then
update() & currentSolution= perturbedSolution; /* accept */ else reject_purturbation(); end repeat c. save_best_solution_found_sofar() in bestSolution; d. Ti = θ * Ti; end while 6. Final solution = best solution found so far;
Figure 4.3: SA Algorithm for solving hard constraints violations in CCTP
4.3.2 The Metropolis Algorithm and the Perturbation Function
At each iteration of the Metropolis step, the function perturb() is called. The perturbation method is performed by selecting two lectures randomly from the
Metropolis Algorithm
current solution and it swaps their content on condition that the selected lectures have different periods’ values and they belong to different courses as shown in Figure 4.4 because the teacher conflicts and the curriculum conflicts are affected by the periods room and not by the room and if we swapped two lectures with the same period, this will not affect he hard constraints penalties; Swap (P1, R1) of lecture L1 with (P2, R2)
of lecture L2. We accept this swap only if it does not violate the room hard
constraints and leave no lecture unassigned. We allowed the violation of time availability hard constraint again as we previously mentioned.
Figure 4.4: Perturbation Operation of our Simulated Annealing algorithm
Once the perturb() method is called, the change in OF (Energy) value is calculated and the acceptance criterion is checked. If the new change decreased the OF value (the hard constraints violations), then the perturbation move is accepted and the current solution is set to the newly perturbed solution. On the other hand, if the move lead to the increase of ΔOF, it will be accepted only with am probability
∆
. This will lead to accepting a number of uphill moves helping the system in escaping any premature convergence into a bad local minimum-energy state (the advantage of using Monte-Carlo algorithm). As temperature Ti goes smaller, the
probability of accepting uphill moves will go less as well and at near-freezing temperatures, uphill moves will not be accepted any more (Mansour and Timani, 2007). This procedure is repeated 10*LecturesNum*WorkingDaysNumber*
SlotsPerDay times for each change in temperature and after it a thermal equilibrium
infeasibility problem of our first solution and after this phase, the output will be a feasible solution.
4.3.3 The Cooling Schedule
Let T0 to be the initial temperature that leads to a high initial probability for
accepting uphill moves which is equal to 0.93 (Mansour and Timani, 2007). On the other hand, the freezing temperature, Tf, is the point at which the probability of
accepting those moves become very small (2-30) and almost make them impossible to be reached and it allows only downhill moves; Tf = . . In this work, the cooling
schedule to be used is: T(i+1)= θ*T(i) where θ=0.95 according to Mansour and
Timani in 2007. Figure 4.5 shows the pseudo code for the algorithm used to generate
T0.