implementation of simulated annealing alogrithm