|
Algorithm 4. Pseudo-code of the tabu search algorithm. |
|
Tabu_Search procedure; |
| /input: n—problem size, |
| / p—current solution, Ξ—difference matrix |
| /output: p•—the best found solution (along with the corresponding difference matrix) |
| /parameters: τ—total number of tabu search iterations, h—tabu tenure, α—randomization coefficient, |
| / Lidle_iter—idle iterations limit |
|
| begin |
| clear tabu list TabuList and hash table HashTable; |
| p•: = p; k: = 1; k′: = 1; secondary_memory_index: = 0; improved: = FALSE; |
| while (k ≤ τ) or (improved = TRUE) then begin / main cycle |
| Δ′min: = ∞; Δ″min: = ∞; u′: = 1; v′: = 1; |
| for
i: = 1 to
n − 1 do
|
| for
j: = i + 1 to
n
do begin / n(n − 1)/2 neighbours of p are scanned |
| Δ: = Ξ(i, j); |
| forbidden: = iif(((TabuList(i, j) ≥ k) and (HashTable((z(p) + Δ) mod
HashSize) = TRUE) and
|
| (random() ≥ α)), TRUE, FALSE); |
| aspired := iif(z(p) + Δ < z(p•), TRUE, FALSE); |
| if ((Δ < Δ′min) and (forbidden = FALSE)) or (aspired = TRUE) then begin
|
| if Δ < Δ′min
then begin Δ″min: = Δ′min; u″: = u′; v″: = v′; Δ′min: = Δ; u′: = i; v′: = j; endif
|
| else if Δ < Δ″min
then begin Δ″min: = Δ; u″: = i; v″: = j; endif
|
| endif
|
| endfor; |
| if Δ″min < ∞ then begin / archiving second solution, Ξ, u″, v″ |
| secondary_memory_index: = secondary_memory_index + 1; Γ(secondary_memory_index) ← p, Ξ, u″, v″ |
| endif; |
| if Δ′min < ∞
|
| ; |
| recalculate the values of the matrix Ξ; |
| if
z(p) < z(p•) then begin
p•: = p; k′: = k
endif; / the best so far solution is memorized |
| TabuList(u′, v′): = k + h; / the elements p(u′), p(v′) become tabu |
| HashTable((z(p) + Δ) mod
HashSize): = TRUE |
| endif; |
| improved: = iif(Δ′min < 0, TRUE, FALSE); |
| if (improved = FALSE) and (k − k′ > Lidle_iter) and (k < τ − Lidle_iter) then begin
|
| / retrieving solution from the secondary memory |
| random_access_index: = random(β × secondary_memory_index, secondary_memory_index); |
| p, Ξ, u″, v″ ← Γ(random_access_index); |
| ; |
| recalculate the values of the matrix Ξ; |
| clear tabu list TabuList; |
| TabuList(u″, v″): = k + h; / the elements p(u″), p(v″) become tabu |
| k′: = k
|
| endif; |
| k: = k + 1 |
| endwhile
|
|
end. |