Simulated annealing for optimization of graphs and sequences