def main(): min_robots = 5 max_robots = min_robots min_depots = 1 max_depots = 1 min_tasks = 20 max_tasks = min_tasks delta_range_start = 300 delta_range_step = 100 # delta_range_end = int(math.ceil(2*100*math.sqrt(2) / # delta_range_step)*delta_range_step) # ~282 delta_range_end = 300 Tmax_range_start = 600 Tmax_range_step = 100 # Tmax_range_end = int(math.ceil(2*100*math.sqrt(2) / # Tmax_range_step)*Tmax_range_step) # ~282 Tmax_range_end = 600 robots_range = list(range(min_robots, max_robots + 1)) depots_range = list(range(min_depots, max_depots + 1)) tasks_range = list(range(min_tasks, max_tasks + 1)) delta_range = list( range(delta_range_start, delta_range_end + delta_range_step, delta_range_step)) Tmax_range = list( range( Tmax_range_start, Tmax_range_end + Tmax_range_step, Tmax_range_step, )) iter_no_list = [0] #1. path_to_data_folder = os.getcwd() # instance_dictionary = {} for r in robots_range: for d in depots_range: for t in tasks_range: for f in delta_range: for tmax in Tmax_range: filePaths = SysPathGenerator(r, d, t, f, tmax) instance_folder_path = filePaths.instance_data_folder_path instance_filename_prefix = filePaths.instance_data_filename_prefix for it in iter_no_list: curr_instance_filename = instance_filename_prefix + \ 'Iter' + str(it) + '.json' file_path = os.path.normpath( instance_folder_path + curr_instance_filename) instance = InstanceReader(curr_instance_filename) instance_data = instance.readData() solver = F7Solver(instance_data) model = solver.solve() solver.write_lp_and_sol_to_disk()
def __init__(self, instance_string, solver_string, path_to_working_dir=os.getcwd()): self.instance = InstanceReader(instance_string) self.instance_data = self.instance.readData() # Now solve the instance, and write the solution to disk solver_selected = self.solver_select(solver_string) solver = solver_selected(self.instance_data) model = solver.solve() solver.write_lp_and_sol_to_disk()
class Job: def __init__(self, instance_string, solver_string, path_to_working_dir=os.getcwd()): self.instance = InstanceReader(instance_string) self.instance_data = self.instance.readData() # Now solve the instance, and write the solution to disk solver_selected = self.solver_select(solver_string) solver = solver_selected(self.instance_data) model = solver.solve() solver.write_lp_and_sol_to_disk() def solver_select(self, solver_string): solver_types = { 'F1': F1Solver, 'F2': F2Solver, 'F3': F3Solver, 'F4': F4Solver, 'F5': F5Solver, 'F6': F6Solver, 'F7': F7Solver, 'F8': F8Solver } solver = solver_types.get(solver_string) return solver
def main(): # instance_prefix = 'R3D2T3F150Tmax600Iter' instance_prefix = 'R3D3T7F150Tmax600Iter' no_of_instances = 5 for i in range(no_of_instances): instance_name = instance_prefix + str(i) instance = InstanceReader(instance_name) sol = Solution_Reader(instance_name) # pprint(sol.nodesInOrder) sol_info = SolutionInformationExtractor(instance, sol) sol_info.recharge_recharge_task_frequency() # print(sol_info.recharge_recharge_count) # print(sol_info.recharge_task_count) # curr_instance_filename = instance_prefix + 'Iter' + str(i) + '.json' # file_path = os.path.normpath(instance_folder_path + curr_instance_filename) distance_travelled = sol_info.distance_travelled_calculator() with open('analysis/data.csv', 'a') as csvFile: writer = csv.writer(csvFile) row = [ instance_name, sol_info.recharge_task_count, sol_info.recharge_recharge_count ] for x in distance_travelled: row.append(x) writer.writerow(row) csvFile.close()
def __init__(self, instance_string): self.instance_string = instance_string self.instance = InstanceReader(instance_string) self.sol = Solution_Reader(instance_string) self.instance_plotter_obj = Instance_Plotter(instance_string) self.solution_plotter_obj = SolutionPlotter(instance_string) self.fig = plt.figure() self.ax = plt.axes(xlim=(0, 100), ylim=(0, 100)) self.ax.grid(True, lw=0.5) plt.title(instance_string) self.line, = self.ax.plot([], [], 'k*', markersize=8) self.edge, = self.ax.plot([], []) self.edge_trace = { k: { 'x': [], 'y': [], 'c': 'w' } for k in self.instance.K } self.expanded_trace = {k: {'x': [], 'y': []} for k in self.instance.K} self.node_list = {k: [] for k in self.instance.K} self.ann_list = [] self.fuel_box = [] self.plot_base()
def solveAll(self): # Generating instance self.generate_instance = Instance_Generator(self.noOfRobots, self.noOfDepots, self.noOfTasks, self.delta, self.T_max, self.no_of_instances, self.seed, path_to_data_folder=os.getcwd()) self.generate_instance.generate_data() filePaths = SysPathGenerator(self.noOfRobots, self.noOfDepots, self.noOfTasks, self.delta, self.T_max) instance_folder_path = filePaths.instance_data_folder_path instance_filename_prefix = filePaths.instance_data_filename_prefix curr_instance_filename = instance_filename_prefix + 'Iter' + str(0) + '.json' instance = InstanceReader(curr_instance_filename) instance_data = instance.readData() for variant in range(1,5): # Basic Formulations solver_selected = self.solver_select("F"+str(variant)) solver = solver_selected(instance_data) model = solver.solve() self.objectiveFunctionValueF1_4.append(model.objVal) solver.write_lp_and_sol_to_disk() # Max Min Obj Function Formulations solver_selected = self.solver_select("F"+str(variant+4)) solver = solver_selected(instance_data) model = solver.solve() self.objectiveFunctionValueF5_8.append(model.objVal) solver.write_lp_and_sol_to_disk() #TODO any other metrics to compare? # Check for sanity : Comparing objective function value print("\nFor formualtions 1 to 4:") if all(x == self.objectiveFunctionValueF1_4[0] for x in self.objectiveFunctionValueF1_4): print("Objective function value matches = ", self.objectiveFunctionValueF1_4[0]) else: print("Objective function value is different for formulation ") print(self.objectiveFunctionValueF1_4) print("\nFor formualtions 5 to 8:") if all(x == self.objectiveFunctionValueF5_8[0] for x in self.objectiveFunctionValueF5_8): print("Objective function value matches = ", self.objectiveFunctionValueF5_8[0]) else: print("Objective function value is different for formulation ") print(self.objectiveFunctionValueF5_8)
def __init__(self, instance_string, path_to_data_folder=os.getcwd()): self.instance_string = instance_string self.instance = InstanceReader(instance_string[2:]) self.sol = Solution_Reader(instance_string) self.instance_plotter_obj = Instance_Plotter(instance_string[2:]) self.compute_path_lengths()
def main(): min_robots = 5 max_robots = 5 min_depots = 3 max_depots = 3 min_tasks = 8 max_tasks = 8 fuel_range_start = 50 # fuel_range_end = int(math.ceil(2*100*math.sqrt(2)/5)*5) fuel_range_end = 50 fuel_range_step = 5 Tmax_range_start = 150 # Tmax_range_end = int(math.ceil(2*100*math.sqrt(2)/10)*10) Tmax_range_end = 150 Tmax_range_step = 10 robots_range = list(range(min_robots, max_robots + 1)) depots_range = list(range(min_depots, max_depots + 1)) tasks_range = list(range(min_tasks, max_tasks + 1)) fuel_range = list( range(fuel_range_start, fuel_range_end + fuel_range_step, fuel_range_step)) Tmax_range = list( range( Tmax_range_start, Tmax_range_end + Tmax_range_step, Tmax_range_step, )) no_of_instances = 5 path_to_data_folder = os.getcwd() # instance_dictionary = {} for r in robots_range: for d in depots_range: for t in tasks_range: for f in fuel_range: for tmax in Tmax_range: instance_folder_path_suffix = \ '/data' + \ '/R' + str(r) + \ '/D' + str(d) + \ '/T' + str(t) + \ '/F' + str(f) + \ '/Tmax' + str(tmax) instance_folder_path = os.path.normpath( path_to_data_folder + instance_folder_path_suffix) instance_filename_prefix = '/R' + str(r) + \ 'D' + str(d) + \ 'T' + str(t) + \ 'F' + str(f) + \ 'Tmax' + str(tmax) for it in range(no_of_instances): curr_instance_filename = instance_filename_prefix + \ 'Iter' + str(it) + '.json' file_path = os.path.normpath( instance_folder_path + curr_instance_filename) instance = InstanceReader(file_path) instance_data = instance.readData() solver = Solver(instance_data) model = solver.solve() solver.write_lp_and_sol_to_disk()
def __init__(self, instance_string, path_to_data_folder=os.getcwd()): InstanceReader.__init__(self, instance_string, path_to_data_folder) self.readData()