time_hist_ppt.append(time_hist) dist_hist_ppt.append(best_hist) print "Parallel Parallel Tempering, run ", i, " complete." solution_spt, histories_spt = serial_parallel_tempering( graph, distance, initial_Xs, initial_temps, iterr, changepath, nswaps, nbefore ) best_hist, time_hist = hist_best(histories_spt[0]) time_hist_spt.append(time_hist) dist_hist_spt.append(best_hist) print "Serial Parallel Tempering, run ", i, " complete." solution_sa, history_sa = simulated_annealing( graph, distance, initial_Xs[0], initial_temps[0], nbefore, iterr, changepath, nswaps, reheat, cool ) best_hist, time_hist = hist_best(history_sa) time_hist_sa.append(time_hist) dist_hist_sa.append(best_hist) print "Simulated Annealing, run ", i, " complete." # Take the mean of each column, save these outputs so they can be plotted and examined without re-running simulations dist_hist_ppt = np.mean(dist_hist_ppt, 0) time_hist_ppt = np.mean(time_hist_ppt, 0) # Save results to plot in plotter.py np.save("../SavedResults/time_hist_ppt.npy", time_hist_ppt) np.save("../SavedResults/dist_hist_ppt.npy", dist_hist_ppt) dist_hist_spt = np.mean(dist_hist_spt, 0)
initial_path = np.random.permutation(size) print "Initial path: " + str(initial_path) print "Initial path length: " + str(distance(graph, initial_path)) + "\n" initial_temp = 2. cool = 0.9 nbefore = 480 nswaps = 1 reheat = np.sqrt(5) # Run simulated annealing print "\nSimulated Annealing\n" for iterr in [10**x for x in [3, 4, 5]]: with Timer() as t: solution, history = simulated_annealing(graph, distance, initial_path, initial_temp, nbefore, iterr, changepath, nswaps, reheat, cool) print "Iterations: {:.2E}".format(iterr) print "Calculated path: " + str(solution) print "Calculated path length: " + str(distance(graph, solution)) print "Time: " + str(t.interval) + "\n" # Reuse copy of initial path for all trials nsystems = 4 initial_paths = [] for i in xrange(nsystems): initial_paths.append(np.asarray(initial_path)) initial_temps = [1., np.sqrt(5), np.sqrt(5)**2, np.sqrt(5)**3]
print "Best path: " + str(bestpath) print "Best path length: " + str(distance(graph, bestpath)) #Initial values, probably need to be tuned initial_path = np.random.permutation(size) initial_temp = 2. cool = 0.9 reanneal = 100 nswaps = 3 # Run simulated annealing print "\nSimulated Annealing\n" for iterr in [10**x for x in [3,4,5]]: with Timer() as t: solution, history = simulated_annealing(graph, distance, initial_path, initial_temp, cool, reanneal, iterr, changepath, nswaps) print "\nIterations: {:.2E}".format(iterr) print "Calculated path: " + str(solution) print "Calculated path length: " + str(distance(graph, solution)) print "Time: " + str(t.interval) # Initial values for parallel tempering nsystems = 3 initial_paths = [np.random.permutation(size) for i in xrange(nsystems)] initial_temps = [1., 5., 10.] nbefore = 100 # Run parallel tempering print "\nParallel Tempering\n" for iterr in [10**x for x in [3,4,5]]: