def simulated_annealing(problem, schedule=exp_schedule()):
current = Node(problem.initial)<EOL>for t in range(sys.maxsize):<EOL><INDENT>T = schedule(t)<EOL>if T == <NUM_LIT:0>:<EOL><INDENT>return current<EOL><DEDENT>neighbors = current.expand(problem)<EOL>if not neighbors:<EOL><INDENT>return current<EOL><DEDENT>next = random.choice(neighbors)<EOL>delta_e = problem.value(next.state) - problem.value(current.state)<EOL>if delta_e > <NUM_LIT:0> or probability(math.exp(delta_e/T)):<EOL><INDENT>current = next<EOL><DEDENT><DEDENT>
[Fig. 4.5]