finished simulated annealing algorithm