Added optimization code (simulated annealing)