code: def simulated_annealing(problem, schedule=exp_schedule()):
      "[Fig. 4.5]"
      current = Node(problem.initial)
      for t in xrange(sys.maxint):
          T = schedule(t)
          if T == 0:
              return current
          neighbors = current.expand(problem)
          if not neighbors:
              return current
          next = random.choice(neighbors)
          delta_e = problem.value(next.state) - problem.value(current.state)
          if delta_e > 0 or probability(math.exp(delta_e/T)):
              current = nexf simulated_annealing(problem, schedule=exp_schedule()):
      "[Fig. 4.5]"
      current = Node(problem.initial)
      for t in xrange(sys.maxint):
          T = schedule(t)
          if T == 0:
              return current
          neighbors = current.expand(problem)
          if not neighbors:
              return current
          next = random.choice(neighbors)
          delta_e = problem.value(next.state) - problem.value(current.state)
          if delta_e > 0 or probability(math.exp(delta_e/T)):
              current = next
docs: [Fig. 4.5]