def main(): maps_file = '../input/stores.xlsx' initial_solution_file = '../results/4-simulated_annealing.xls' output_file = '../results/5-ant_coloy_opt.xls' print("[INFO] Reading store information from: {}".format(maps_file)) maps = Maps(maps_file) print("[INFO] Reading initial solution from: {}".format(initial_solution_file)) schedule = Schedule() valid_solution = schedule.read_from_xls(initial_solution_file, maps) if not valid_solution: print("[ERROR] Abort: initial solution contains invalid route(s)") return False else: print("[INFO] Start ACO to optimize each route") aco = ACO(maps) aco.optimize_all(schedule) print("[INFO] ACO best schedule score: {}".format(schedule.total_distance)) print("[INFO] Export solution to: {}".format(output_file)) ## Printing and drawing solution # for k in schedule.routes: # print(schedule.routes[k]) # schedule.draw(maps) schedule.export_to_xls(output_file, maps)
def main(): maps_file = '../input/stores.xlsx' initial_solution_file = '../results/1-nearest_neighbors.xls' output_file = '../results/2-two_edge_exchange.xls' print("[INFO] Reading store information from: {}".format(maps_file)) maps = Maps(maps_file) print("[INFO] Reading initial solution from: {}".format( initial_solution_file)) schedule = Schedule() valid_solution = schedule.read_from_xls(initial_solution_file, maps) if not valid_solution: print("[ERROR] Abort: initial solution contains invalid route(s)") return False else: print("[INFO] Initialise neighbors for 2-edge exchange") tex = TwoEdgeExchange(schedule, maps) print("[INFO] Start improving with 2-edge exchange") log = tex.solve() print("[INFO] 2-edge exchange best score: {:.2f}".format( schedule.total_distance)) print("[INFO] Export solution to: {}".format(output_file)) schedule.export_to_xls(output_file, maps)
def main(): maps_file = '../input/stores.xlsx' initial_solution_file = '../results/3-tabu_search.xls' output_file = '../results/4-simulated_annealing.xls' print("[INFO] Reading store information from: {}".format(maps_file)) maps = Maps(maps_file) print("[INFO] Reading initial solution from: {}".format(initial_solution_file)) schedule = Schedule() valid_solution = schedule.read_from_xls(initial_solution_file, maps) if not valid_solution: print("[ERROR] Abort: initial solution contains invalid route(s)") return False else: random.seed(1337) print("[INFO] Start Simulated Annealing") ## I use this configuration to get the result, ## but it will take 1 hour to run # config = { # "steps": 50000, # "Tmax": 10, # "Tmin": 1, # "updates": 100 # } # configuration used to test config = { "steps": 1000, "Tmax": 5, "Tmin": 1, "updates": 10 } sima = VRPAnnealer(schedule, maps, config) tex, e = sima.anneal() print("[INFO] Simulated Annealing best schedule score: {}".format(e)) print("[INFO] Export solution to: {}".format(output_file)) tex.schedule.export_to_xls(output_file, maps)
def main(): maps_file = '../input/stores.xlsx' initial_solution_file = '../results/2-two_edge_exchange.xls' output_file = '../results/3-tabu_search.xls' print("[INFO] Reading store information from: {}".format(maps_file)) maps = Maps(maps_file) print("[INFO] Reading initial solution from: {}".format( initial_solution_file)) schedule = Schedule() valid_solution = schedule.read_from_xls(initial_solution_file, maps) if not valid_solution: print("[ERROR] Abort: initial solution contains invalid route(s)") return False else: print("[INFO] Start improving schedule with Tabu Search") ts = TabuSearch(schedule, maps, tabu_period=50) ## I use this configuration to get the result, ## but it will take approx. 1 hour to run # if not ts.solve(max_iter=5000, max_no_improvement=100): # return False # configuration used for testing if not ts.solve(max_iter=100, max_no_improvement=None): return False schedule = ts.best_schedule print("[INFO] Tabu search best score: {:.2f}".format( schedule.total_distance)) ## Plotting score for each iterations # plt.plot(ts.log) # plt.show() print("[INFO] Export solution to: {}".format(output_file)) schedule.export_to_xls(output_file, maps) return True