Adaptive Simulated Annealing: A Near-optimal Connection between Sampling and Counting