SIMULATED ANNEALING FUNCTION