def MapWeightAdjust(map_current_temp, agv_current_vertex, agv_current_positions, agv_number, column_number, row_number, vertex_layer_shift, occupied_edge_increased_weight, edge_increased_weight, agv_seq_no, agv_path_segments, current_agv_target_vertex): #处于当前agv5米范围内的agv边权值增加 for i_agv in range(1, agv_number + 1): agv_vertex = agv_current_positions[i_agv - 1] if agv_path_segments[ agv_seq_no - 1] != None and agv_vertex != current_agv_target_vertex: if len(agv_path_segments[agv_seq_no - 1]) <= 1: edge_increased_weight[agv_seq_no - 1] = edge_increased_weight[agv_seq_no - 1] * 1.1 else: edge_increased_weight[agv_seq_no - 1] = edge_increased_weight[agv_seq_no - 1] / 1.05 if edge_increased_weight[agv_seq_no - 1] <= occupied_edge_increased_weight: edge_increased_weight[agv_seq_no - 1] = occupied_edge_increased_weight edge_adjust_weight = edge_increased_weight[agv_seq_no - 1] if int(abs(agv_vertex - agv_current_vertex) // column_number) <= 5 and int( abs(agv_vertex - agv_current_vertex) % column_number) <= 5: AuxiliaryModule.adjust_edge_weight_to_vertex( map_current_temp, column_number, row_number, vertex_layer_shift, agv_vertex, edge_adjust_weight)
def Agv_Motion_Model(agv_path_segments, agv_seq_no, agv_kinematic_parameter, agv_motion_state, grid_step_time, agv_current_positions, agv_info_for_map, column_number): Move_direction = [] MaxSpeed = agv_kinematic_parameter[0] AcceleratedSpeed = agv_kinematic_parameter[1] MaxAngularSpeed = agv_kinematic_parameter[2] AngularAcceleration = agv_kinematic_parameter[3] first_stop_point, target_orientation = decide_first_stop_point( agv_motion_state, Move_direction, agv_path_segments, column_number, agv_seq_no) stop_poin_x, stop_poin_y = AuxiliaryModule.convert_vertex_to_coordinate( column_number, first_stop_point) time_left = agv_translation(agv_motion_state[agv_seq_no - 1], stop_poin_x, stop_poin_y, grid_step_time, MaxSpeed, AcceleratedSpeed, column_number) agv_rotation(agv_motion_state[agv_seq_no - 1], Move_direction, target_orientation, time_left, MaxAngularSpeed, AngularAcceleration) agv_current_positions[agv_seq_no - 1] = AuxiliaryModule.convert_coordinate_to_vertex( column_number, int(round(agv_motion_state[agv_seq_no - 1][0])), int(round(agv_motion_state[agv_seq_no - 1][1]))) agv_info_for_map[agv_seq_no - 1][0] = agv_current_positions[agv_seq_no - 1]
def pod_dislocation_judgement(pod_index, map_nodes, static_shelves, column_num): result = False dislocation_pod_index = None pod_vertex = static_shelves[pod_index] neighbour_vertex = [ pod_vertex - column_num, pod_vertex + column_num, pod_vertex - 1, pod_vertex + 1 ] neighbour_vertex = [ x for x in neighbour_vertex if x not in map_nodes or x in static_shelves.values() ] neighbour_pod_vertex = [ x for x in neighbour_vertex if x in static_shelves.values() ] if len(neighbour_vertex) == 4 and neighbour_pod_vertex: for each_pod in neighbour_pod_vertex: this_pod_neighbour_vertex = [ each_pod - column_num, each_pod + column_num, each_pod - 1, each_pod + 1 ] this_pod_neighbour_vertex = [ x for x in this_pod_neighbour_vertex if x not in static_shelves.values() and x in map_nodes ] if this_pod_neighbour_vertex: dislocation_pod = each_pod dislocation_pod_index = AuxiliaryModule.get_key_by_value( static_shelves, dislocation_pod)[0] result = True break return result, dislocation_pod_index
def drawmap_main(boundary_nodes_x, boundary_nodes_y): sleep_time = 0.2 background(boundary_nodes_x, boundary_nodes_y) filelist = AuxiliaryModule.getAllFileName("./SnapShots/") for name in filelist: curfile = "./SnapShots/" + name agvshelf(curfile) time.sleep(sleep_time)
def get_station_except_edge(column_num): station_except_edge = {} current_path = os.getcwd() config_file_path = current_path + "\config.ini" print('loading config file at path: ' + config_file_path) config_reader = configparser.ConfigParser() config_reader.read(config_file_path) # picking_station_except_edge_num = int( config_reader.get('picking station', 'picking_station_except_edge_num')) for i_picking_station_except in range(1, picking_station_except_edge_num + 1): except_station_edge_string = config_reader.get( 'picking station', 'picking_station_except_edge_' + str(i_picking_station_except)) except_station_edge = except_station_edge_string[ except_station_edge_string.index('(') + 1:except_station_edge_string.index(')')].split(',') start_staion = config_reader.get('picking station', except_station_edge[0]) start_staion_vertex = AuxiliaryModule.convert_coordinate_to_vertex( column_num, int(start_staion[start_staion.index('(') + 1:start_staion.index(')')].split(',')[0]), int(start_staion[start_staion.index('(') + 1:start_staion.index(')')].split(',')[1])) end_staion = config_reader.get('picking station', except_station_edge[1]) end_staion_vertex = AuxiliaryModule.convert_coordinate_to_vertex( column_num, int(end_staion[end_staion.index('(') + 1:end_staion.index(')')].split(',')[0]), int(end_staion[end_staion.index('(') + 1:end_staion.index(')')].split(',')[1])) station_except_edge[start_staion_vertex] = [ start_staion_vertex, end_staion_vertex ] station_except_edge[end_staion_vertex] = [ end_staion_vertex, start_staion_vertex ] return station_except_edge
def waiting_agvs_in_picking_station(out_stations,agv_current_positions,agv_destination_station,agv_current_status,column_number): distance_threhold=7 waiting_agvs={} future_waiting_agvs={} for i_station in range(1,len(out_stations)+1): waiting_agvs[out_stations[i_station - 1]]=[] future_waiting_agvs[out_stations[i_station - 1]]=[] for agv_seq_no in range(1,len(agv_current_status)+1): agv_status=agv_current_status[agv_seq_no-1] if agv_destination_station[agv_seq_no - 1] == out_stations[i_station - 1]: if AuxiliaryModule.wall_street_distance(column_number,out_stations[i_station - 1],agv_current_positions[agv_seq_no-1])<distance_threhold: if 'to in buffer list of station' in agv_status or 'station selection' in agv_status or 'to station' in agv_status or 'picking or replenishing items' in agv_status: waiting_agvs[out_stations[i_station - 1]].append(agv_seq_no) else: if 'to shelves' in agv_status or 'to in buffer list of station' in agv_status or 'in buffer list selection' in agv_status: future_waiting_agvs[out_stations[i_station - 1]].append(agv_seq_no) return waiting_agvs,future_waiting_agvs
def by_dijkstra(current_agv_target_vertex, map_current, column_number, row_number, path_incread_weight_per_agv, vertex_layer_shift, agv_paths, agv_paths_weight_sum, occupied_edge_increased_weight, edge_increased_weight, agv_with_shelves, agv_current_positions, agv_current_status, agv_destination_station, buffer_list_dic, agv_seq_no, static_shelves, agv_number, agv_path_segments): current_agv_current_vertex = agv_current_positions[agv_seq_no - 1] if agv_current_status[agv_seq_no-1] not in 'to out buffer list of station' and agv_current_status[agv_seq_no-1] not in 'to station' \ and agv_current_status[agv_seq_no-1] not in 'picking or replenishing items'and agv_current_status[agv_seq_no-1] not in 'out buffer list selection': if current_agv_current_vertex != current_agv_target_vertex: # 搜路之前先恢复旧路径对权重的影响 old_path = agv_paths[agv_seq_no - 1] old_path_weight_sum = agv_paths_weight_sum[agv_seq_no - 1] AuxiliaryModule.adjust_edge_weight_in_path( map_current, old_path, -path_incread_weight_per_agv) path = None try: map_current_temp = copy.deepcopy(map_current) MapWeightAdjust(map_current_temp, current_agv_current_vertex, agv_current_positions, agv_number, column_number, row_number, vertex_layer_shift, occupied_edge_increased_weight, edge_increased_weight, agv_seq_no, agv_path_segments, current_agv_target_vertex) if agv_seq_no not in agv_with_shelves: path = networkx.dijkstra_path( map_current_temp, source=current_agv_current_vertex, target=current_agv_target_vertex) # xiugai pass # if no exception, means find a path successfully else: # 处理存疑 # try: vertex_of_static_shelves = sorted( list(static_shelves.values())) for each_vertex in vertex_of_static_shelves: AuxiliaryModule.remove_edges_to_vertex( map_current_temp, column_number, row_number, vertex_layer_shift, each_vertex) path = networkx.dijkstra_path( map_current_temp, source=current_agv_current_vertex, target=current_agv_target_vertex) # xiugai pass # if no exception, means find a path successfully # except Exception as e: # path search failed # aaa = [one for one in map_current.nodes()] # aaa = sorted(aaa) # bbb = [one for one in map_current.edges() if one[0] > vertex_layer_shift] # DrawMap.drawmap_for_path_search(map_current,current_agv_current_vertex, current_agv_target_vertex) # path = None except Exception as e: # path search failed path = None print('path is none') # new_weight_sum=path_weight_sum(path,map_current_temp) agv_paths[agv_seq_no - 1] = path # agv_paths_weight_sum[agv_seq_no - 1] = new_weight_sum # if new_weight_sum is not None and old_path_weight_sum is not None and (old_path[0]==path[0]) and (old_path[-1]==path[-1]): # if old_path_weight_sum<=new_weight_sum: # agv_paths[agv_seq_no - 1] = old_path # agv_paths_weight_sum[agv_seq_no - 1] = old_path_weight_sum # agv_paths[agv_seq_no - 1] = path AuxiliaryModule.adjust_edge_weight_in_path( map_current, agv_paths[agv_seq_no - 1], path_incread_weight_per_agv) else: if agv_current_status[ agv_seq_no - 1] in 'out buffer list selection' or agv_current_status[ agv_seq_no - 1] in 'picking or replenishing items': agv_paths[agv_seq_no - 1] = None else: full_path = buffer_list_dic[agv_destination_station[agv_seq_no - 1]] current_location_index = full_path.index( agv_current_positions[agv_seq_no - 1]) agv_paths[agv_seq_no - 1] = full_path[current_location_index:]
def Assign_Tasks_To_AGVs(agv_current_status,picking_task_info,replenishing_task_info,unbooked_static_shelves,static_shelves,agv_current_positions,agv_target_positions,pod_layer_Item,grid_step_time,picking_time_per_item,booked_static_shelves,column_number,moving_shelves,agv_target_pod,pod_status,out_stations,agv_destination_station,agv_seq_no): #按照先补货后拣货的顺序,此逻辑后续可优化 tuple_agv_current_status=list(enumerate(agv_current_status)) agv_seq_no_for_tasks=[x[0]+1 for x in tuple_agv_current_status if x[1]=='Pod Selection' or x[1]=='initial'] waiting_agvs_list,future_waiting_agvs_list=waiting_agvs_in_picking_station(out_stations,agv_current_positions,agv_destination_station,agv_current_status,column_number) try: iteration_count=0 if len(replenishing_task_info)>=1: replenishing_task_info_iterate=[x for x in replenishing_task_info if len(x)>=3] else: replenishing_task_info_iterate=[] if replenishing_task_info_iterate: replenishing_task_info_iterate=[x for x in replenishing_task_info_iterate if [y for y in x[2:] if y in unbooked_static_shelves and y not in pod_status.keys()]] task_assignment_indicator=[] if replenishing_task_info_iterate and agv_seq_no_for_tasks: #一个step由1个AGV补货一次 for each_replenishing_task in replenishing_task_info_iterate: station_x, station_y = AuxiliaryModule.convert_vertex_to_coordinate(column_number, each_replenishing_task[0]) for each_pod in each_replenishing_task[2:]: pod_x, pod_y = AuxiliaryModule.convert_vertex_to_coordinate(column_number,static_shelves[each_pod]) for each_agv in agv_seq_no_for_tasks: agv_point_x, agv_point_y = AuxiliaryModule.convert_vertex_to_coordinate(column_number,agv_current_positions[agv_seq_no - 1]) travel_time = (abs(pod_x - agv_point_x) + abs(pod_y - agv_point_y) + abs(station_x - pod_x) + abs(station_y - pod_y)) / grid_step_time task_assignment_indicator.append([each_replenishing_task[0],each_pod,each_agv,travel_time,each_replenishing_task[1]])#补货台地点,货架号,agv号,搬运时间,补货时间 task_assignment_indicator.sort(key=(lambda x:x[3])) chosen_replen_pod=task_assignment_indicator[0][1] chosen_replen_agv=task_assignment_indicator[0][2] station_vertex=task_assignment_indicator[0][0] etsimated_picking_time=task_assignment_indicator[0][4] booked_static_shelves.append([chosen_replen_agv, chosen_replen_pod, station_vertex, etsimated_picking_time]) # agv号,货架号,站台地点,拣货时间 target_replenishing_task_info=[x for x in replenishing_task_info if x[0]==station_vertex][0] replenishing_task_info.remove(target_replenishing_task_info) target_replenishing_task_info_part1=target_replenishing_task_info[2:] target_replenishing_task_info_part1.remove(chosen_replen_pod) target_replenishing_task_info=target_replenishing_task_info[:2]+target_replenishing_task_info_part1 replenishing_task_info.append(target_replenishing_task_info) agv_target_positions[chosen_replen_agv - 1] = static_shelves[chosen_replen_pod] agv_target_pod[chosen_replen_agv - 1] = chosen_replen_pod if chosen_replen_pod in unbooked_static_shelves: unbooked_static_shelves.remove(chosen_replen_pod) agv_current_status[chosen_replen_agv - 1] = 'to shelves' agv_seq_no_for_tasks.remove(chosen_replen_agv) aaa=len(agv_seq_no_for_tasks) wuhh1=0 if aaa<=5 and aaa>=1: wuhh1=1 picking_task_info_iterate = [x for x in picking_task_info if len(x) >= 4] if picking_task_info_iterate: picking_task_info_iterate = [x for x in picking_task_info_iterate if [y for y in x[3:] if y in unbooked_static_shelves and y not in pod_status.keys()]] # 假如picking_task_info中某一元素中的某一pod被包含在unbooked_static_shelves while agv_seq_no_for_tasks and picking_task_info_iterate: iteration_count=iteration_count+1 if iteration_count>=300: raise myexception("error:the iteration count is over 300") task_assignment_indicator=[] picking_task_info_iterate=[x for x in picking_task_info if len(x)>=4] if picking_task_info_iterate: picking_task_info_iterate=[x for x in picking_task_info_iterate if [y for y in x[3:] if y in unbooked_static_shelves and y not in pod_status.keys()]] #假如picking_task_info中某一元素中的某一pod被包含在unbooked_static_shelves if picking_task_info_iterate: picking_task_info_iterate=rank_array(picking_task_info_iterate,waiting_agvs_list,future_waiting_agvs_list) target_picking_task_info=picking_task_info_iterate[0] target_picking_task_info_temp = copy.deepcopy(target_picking_task_info) station_vertex =target_picking_task_info[0] station_x,station_y=AuxiliaryModule.convert_vertex_to_coordinate(column_number,station_vertex) for each_Index_of_pod in target_picking_task_info[3:]: if each_Index_of_pod in unbooked_static_shelves: items_needed_in_this_pod=get_num_items_met_for_order_in_pod(target_picking_task_info_temp, each_Index_of_pod, pod_layer_Item) pod_x,pod_y=AuxiliaryModule.convert_vertex_to_coordinate(column_number,static_shelves[each_Index_of_pod]) for agv_seq_no in agv_seq_no_for_tasks: agv_point_x,agv_point_y=AuxiliaryModule.convert_vertex_to_coordinate(column_number,agv_current_positions[agv_seq_no-1]) travel_time=(abs(pod_x-agv_point_x)+abs(pod_y-agv_point_y)+abs(station_x-pod_x)+abs(station_y-pod_y))/grid_step_time task_assignment_indicator.append([agv_seq_no,each_Index_of_pod,items_needed_in_this_pod,items_needed_in_this_pod/(travel_time+target_picking_task_info[1])]) task_assignment_indicator=sorted(task_assignment_indicator,key=lambda x:x[3]) chosen_pod=task_assignment_indicator[-1][1] chosen_agv=task_assignment_indicator[-1][0] items_needed=task_assignment_indicator[-1][2] etsimated_picking_time=items_needed * picking_time_per_item booked_static_shelves.append([chosen_agv,chosen_pod,station_vertex,etsimated_picking_time]) #agv号,货架号,站台地点,拣货时间 picking_task_info.remove(target_picking_task_info) get_num_items_needed_in_pod(target_picking_task_info, chosen_pod, pod_layer_Item) target_picking_task_info[1] = int(target_picking_task_info[1] +etsimated_picking_time ) ####################################remove chosen_pod##################################################### target_picking_task_info_part1 = target_picking_task_info[:3] target_picking_task_info_part2 = target_picking_task_info[3:] target_picking_task_info_part2.remove(chosen_pod) target_picking_task_info = target_picking_task_info_part1 + target_picking_task_info_part2 ################################################################################################################ picking_task_info.append(target_picking_task_info) agv_target_positions[chosen_agv - 1]=static_shelves[chosen_pod] agv_target_pod[chosen_agv-1]=chosen_pod if chosen_pod in unbooked_static_shelves: unbooked_static_shelves.remove(chosen_pod) agv_current_status[chosen_agv - 1] = 'to shelves' agv_seq_no_for_tasks.remove(chosen_agv) except Exception as e: print(repr(e)) except myexception as e: print(repr(e))
def main(): # config and map if os.path.exists(os.getcwd()+ "\\"+"SnapShots"): shutil.rmtree(os.getcwd()+ "\\"+"SnapShots") os.mkdir('SnapShots') vertex_layer_shift = ConfigManager.get_vertex_layer_shift() # map_original,map_nodes,node_distance,buffer_list_dic,boundary_nodes_x,boundary_nodes_y = ConfigManager.load_config() #buffer_list_dic:key is station vertex and value is buffer vertex conf = ConfigManager.ConfigPara() # conf.LoadConfigFromFile(map_nodes,buffer_list_dic)# conf.Print() result.background(boundary_nodes_x,boundary_nodes_y) grid_length = conf.grid_length column_number = conf.column_number row_number = conf.row_number agv_number = conf.agv_num agv_maxspeed = conf.agv_maxspeed agv_kinematic_parameter=conf.agv_kinematic picking_time_per_item=conf.picking_time_per_item grid_step_time = grid_length / agv_maxspeed out_stations = conf.out_station replen_stations=conf.replen_stations station_picking_tasks={} station_type={} agv_current_positions = [] agv_path_segments=[] agv_motion_state=[] #x,y,Vx,Vy,r,W agv_current_status = [] agv_target_positions = [] agv_paths = [] agv_paths_weight_sum=[] agv_info_for_map=[] agv_finished_package_count = [] agv_unload_shelves_count=[] agv_wait_times = [] pod_called_count = conf.pod_called_count # 统计各货架搬运次数 pod_called_count_for_replen=conf.pod_called_count_for_replen pod_for_picking_or_replening=[] pods_for_dislocation={} pod_status={} #判断货架是否处于倒腾货架的状态 out_station_package_count = [] agv_destination_station=[] picking_task_info=[] replenishing_task_info=[] vacant=conf.unoccupied_vertex unbooked_vacant=[] agv_target_pod=[] moving_shelves={} #key is agv and value is the shelf it loads static_shelves=conf.initial_static_shelves_vertex #key is the shelf index and value is its location(Vertex) unbooked_static_shelves=copy.deepcopy(list(static_shelves.keys())) booked_static_shelves=[] agv_with_shelves=copy.deepcopy(list(moving_shelves.keys())) other_information={} replenishing_time_per_pod=conf.replenishing_time_per_pod call_interval_by_replen_station=conf.call_interval_by_replen_station edge_increased_weight=[] occupied_edge_increased_weight = 10000 AGV_visit_station_count=0 Average_visit_station_count=0 waiting_counts_in_stations={} Item_pod_Layer=conf.Initial_Item_Layer pod_layer_Item=conf.Initial_Layer_Item Order_Line_selection=conf.Initial_Order_selection num_lines=conf.num_lines simulation_start_time = time.time() # 初始化参数数组 for agv_seq_no in range(1, agv_number + 1): agv_finished_package_count.append(0) agv_unload_shelves_count.append(0) agv_wait_times.append(0) agv_target_pod.append(None) edge_increased_weight.append(occupied_edge_increased_weight) waiting_counts_in_stations[agv_seq_no]=[] for station_no in range(1, len(out_stations) + 1): out_station_package_count.append(0) picking_task_info.append([out_stations[station_no-1],0]) station_type[out_stations[station_no-1]]='拣货台' for station_no in range(1,len(replen_stations)+1): replenishing_task_info.append([replen_stations[station_no-1]]) station_type[replen_stations[station_no-1]]='补货台' # 初始化agv位置 print('intializing agv positions...') for agv_seq_no in range(1, agv_number + 1): while (True): try: random_vertex = random.randint(1, column_number*row_number+1) if (map_original.has_node(random_vertex)==True): conflict_index = agv_current_positions.index(random_vertex) #print('index='+str(conflict_index)+' vertex='+str(random_vertex)) except: break agv_current_positions.append(random_vertex) random_x,random_y=AuxiliaryModule.convert_vertex_to_coordinate(column_number,random_vertex) agv_motion_state.append([random_x,random_y,0,0,0,0]) agv_path_segments.append([random_vertex]) agv_current_status.append('initial') # initial, to in station; receiving package; to out station; dropping package; to charge station; in charge; agv_target_positions.append(random_vertex) agv_paths.append(None) agv_paths_weight_sum.append(None) agv_destination_station.append(None) # 去除agv静态占用的路径,仅移除到达AGV点的方向的路径,从AGV点出发的点无需移除--不懂 path_incread_weight_per_agv = 1 map_current = copy.deepcopy(map_original) for agv_seq_no in range(1, agv_number + 1): agv_info_for_map.append([agv_current_positions[agv_seq_no - 1],'initial']) #-1 means that this agv has not shelf on itself right now # simulate agv moving simulation_total_time = conf.simulation_time # seconds simulation_steps = int(simulation_total_time / grid_step_time) finished_package_count = 0 waiting_count = 0 agv_move_step_count = 0 efficient_info = '' result.write_positions_to_file(column_number, agv_info_for_map,static_shelves,other_information,simulation_start_time) # 初始位置 for step in range(1, simulation_steps): if step%call_interval_by_replen_station==0: SA.replenishing_task_manager(replen_stations, pod_called_count_for_replen, replenishing_task_info,replenishing_time_per_pod) SA.picking_task_manager(Order_Line_selection, Item_pod_Layer, pod_layer_Item,out_stations,column_number, num_lines, static_shelves,unbooked_static_shelves,picking_task_info) #任务货架生成策略,该策略可由客户提供 print(step,':picking_task_manager') CDS.Assign_Tasks_To_AGVs(agv_current_status,picking_task_info,replenishing_task_info,unbooked_static_shelves,static_shelves,agv_current_positions,agv_target_positions,pod_layer_Item,grid_step_time,picking_time_per_item,booked_static_shelves,column_number,moving_shelves,agv_target_pod,pod_status,out_stations,agv_destination_station,agv_seq_no) print(step,':Assign_Picking_Tasks_To_AGVs') CDS.states_update(agv_current_status,agv_current_positions,agv_target_positions,agv_with_shelves,agv_destination_station, unbooked_static_shelves,booked_static_shelves,moving_shelves,static_shelves,agv_seq_no,vertex_layer_shift,vacant,unbooked_vacant,pod_for_picking_or_replening,node_distance,pod_called_count,pod_called_count_for_replen, out_stations,buffer_list_dic,agv_number,pod_layer_Item,station_picking_tasks,picking_time_per_item,grid_step_time,picking_task_info,agv_target_pod,station_type) print(step,':states_update') #for agv_seq_no in agv_no_random_list: # 随机选起始agv可能会造成不必要的等待 for agv_seq_no in range(1, agv_number + 1): # 搜路并移动一步 AGVAGENT.by_dijkstra(agv_target_positions[agv_seq_no - 1],map_current,column_number,row_number, path_incread_weight_per_agv,vertex_layer_shift,agv_paths,agv_paths_weight_sum,occupied_edge_increased_weight,edge_increased_weight, agv_with_shelves,agv_current_positions,agv_current_status,agv_destination_station,buffer_list_dic,agv_seq_no, static_shelves,agv_number,agv_path_segments) AGVAGENT.order_path_segments(agv_paths, agv_path_segments,agv_current_positions, agv_seq_no) AGVAGENT.Agv_Motion_Model(agv_path_segments, agv_seq_no, agv_kinematic_parameter, agv_motion_state, grid_step_time, agv_current_positions, agv_info_for_map, column_number) current_agv_status = agv_current_status[agv_seq_no - 1] if current_agv_status == 'shelves have been unloaded' or current_agv_status == 'initial': agv_current_status[agv_seq_no - 1] = 'Pod Selection' elif current_agv_status == 'to shelves' and (agv_current_positions[agv_seq_no - 1] == agv_target_positions[agv_seq_no - 1] or abs(agv_current_positions[agv_seq_no - 1] - agv_target_positions[agv_seq_no - 1]) == vertex_layer_shift): if agv_target_pod[agv_seq_no - 1]==None: agv_current_status[agv_seq_no - 1] = 'to shelves' elif agv_target_positions[agv_seq_no - 1]==static_shelves[agv_target_pod[agv_seq_no - 1]]: judgement_result,dislocation_pod_index=AGVAGENT.pod_dislocation_judgement(agv_target_pod[agv_seq_no - 1],map_nodes, static_shelves, column_number) if judgement_result: agv_target_positions[agv_seq_no - 1]=static_shelves[dislocation_pod_index] agv_current_status[agv_seq_no - 1] = 'pod dislocation - to dislocation pod' allowed_move_steps=5 #allowed_move_steps for dislocation pod target_pod_x,target_pod_y=AuxiliaryModule.convert_vertex_to_coordinate(column_number,static_shelves[agv_target_pod[agv_seq_no - 1]]) dislocation_pod_x,dislocation_pod_y=AuxiliaryModule.convert_vertex_to_coordinate(column_number,static_shelves[dislocation_pod_index]) temporal_station_destination=buffer_list_dic[out_stations[1]][0] pods_for_dislocation[agv_seq_no]=[agv_target_pod[agv_seq_no - 1],dislocation_pod_index,[target_pod_x,target_pod_y],[dislocation_pod_x,dislocation_pod_y],temporal_station_destination,allowed_move_steps] #value is pod index, pod index, pod location, pod location, temporally destination station. pod_status[agv_target_pod[agv_seq_no - 1]]='pod dislocation' pod_status[dislocation_pod_index]='pod dislocation' else: agv_current_status[agv_seq_no - 1] = 'in buffer list selection' elif agv_target_pod[agv_seq_no - 1] in pod_status.keys(): agv_current_status[agv_seq_no - 1]='to shelves' elif agv_target_pod[agv_seq_no - 1] not in pod_status.keys(): agv_current_status[agv_seq_no - 1]='to shelves' agv_target_positions[agv_seq_no - 1]=static_shelves[agv_target_pod[agv_seq_no - 1]] elif 'pod dislocation' in current_agv_status: AGVAGENT.pod_dislocation(agv_current_positions,agv_target_positions,agv_current_status,pods_for_dislocation,static_shelves,pod_status,agv_with_shelves,column_number,agv_seq_no) elif current_agv_status == 'to in buffer list of station' and (agv_current_positions[agv_seq_no - 1] == agv_target_positions[agv_seq_no - 1] or abs(agv_current_positions[agv_seq_no - 1] - agv_target_positions[ agv_seq_no - 1]) == vertex_layer_shift): agv_current_status[agv_seq_no - 1] = 'station selection' elif agv_current_status[agv_seq_no - 1] == 'to station' and (agv_current_positions[agv_seq_no - 1] == agv_target_positions[agv_seq_no - 1] or abs(agv_current_positions[agv_seq_no - 1] - agv_target_positions[agv_seq_no - 1]) == vertex_layer_shift): agv_current_status[agv_seq_no - 1] = 'picking or replenishing items' elif agv_current_status[agv_seq_no - 1] == 'picking or replenishing items': station_all_picking_info = station_picking_tasks[agv_destination_station[agv_seq_no - 1]] #agv号,货架号,拣货次数 index_picking_info = [station_all_picking_info.index(x) for x in station_all_picking_info if x[0] == agv_seq_no and x[1] == moving_shelves[agv_seq_no][0]][0] if station_picking_tasks[agv_destination_station[agv_seq_no - 1]][index_picking_info][2]<=0.5: agv_current_status[agv_seq_no - 1] = 'out buffer list selection' del station_picking_tasks[agv_destination_station[agv_seq_no - 1]][index_picking_info] AGV_visit_station_count=AGV_visit_station_count+1 Average_visit_station_count=AGV_visit_station_count/(step*grid_step_time) elif current_agv_status == 'to out buffer list of station' and (agv_current_positions[agv_seq_no - 1] == agv_target_positions[agv_seq_no - 1] or abs(agv_current_positions[agv_seq_no - 1] - agv_target_positions[agv_seq_no - 1]) == vertex_layer_shift): if CDS.Assign_tasks_to_station_hopping(moving_shelves,agv_seq_no,picking_task_info,replenishing_task_info,pod_layer_Item,picking_time_per_item,station_type): agv_current_status[agv_seq_no - 1] = 'in buffer list selection' else: agv_current_status[agv_seq_no - 1] = 'Pod Storage Selection' elif agv_current_status[agv_seq_no - 1] == 'to unoccupied spots by static shelves' and (agv_current_positions[agv_seq_no - 1] == agv_target_positions[agv_seq_no - 1] or abs(agv_current_positions[agv_seq_no - 1] - agv_target_positions[agv_seq_no - 1]) == vertex_layer_shift): agv_current_status[agv_seq_no - 1] = 'shelves have been unloaded' haveconditions=[] if current_agv_status=='Picking Pod Selection': status_count=[x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='Picking Pod Selection'] if not status_count: waiting_counts_in_stations[agv_seq_no]=[['Picking Pod Selection',1]] else: status_count=status_count[0] waiting_counts_in_stations[agv_seq_no].remove(status_count) status_count[1]=status_count[1]+1 waiting_counts_in_stations[agv_seq_no].append(status_count) haveconditions = [x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='Picking Pod Selection' and x[1] > 20] if current_agv_status=='to shelves': status_count=[x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='to shelves'] if not status_count: waiting_counts_in_stations[agv_seq_no]=[['to shelves',1]] else: status_count=status_count[0] waiting_counts_in_stations[agv_seq_no].remove(status_count) status_count[1]=status_count[1]+1 waiting_counts_in_stations[agv_seq_no].append(status_count) haveconditions = [x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='to shelves' and x[1] > 300] if current_agv_status=='out buffer list selection': status_count=[x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='out buffer list selection'] if not status_count: waiting_counts_in_stations[agv_seq_no]=[['out buffer list selection',1]] else: status_count=status_count[0] waiting_counts_in_stations[agv_seq_no].remove(status_count) status_count[1]=status_count[1]+1 waiting_counts_in_stations[agv_seq_no].append(status_count) haveconditions = [x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='out buffer list selection' and x[1] > 100] if current_agv_status=='to out buffer list of out station': status_count=[x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='to out buffer list of out station'] if not status_count: waiting_counts_in_stations[agv_seq_no].append(['to out buffer list of out station',1]) else: status_count=status_count[0] waiting_counts_in_stations[agv_seq_no].remove(status_count) status_count[1]=status_count[1]+1 waiting_counts_in_stations[agv_seq_no].append(status_count) haveconditions = [x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='to out buffer list of out station' and x[1] > 100] if current_agv_status=='Pod Storage Selection': status_count=[x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='Pod Storage Selection'] if not status_count: waiting_counts_in_stations[agv_seq_no].append(['Pod Storage Selection',1]) else: status_count=status_count[0] waiting_counts_in_stations[agv_seq_no].remove(status_count) status_count[1]=status_count[1]+1 waiting_counts_in_stations[agv_seq_no].append(status_count) haveconditions = [x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='Pod Storage Selection' and x[1] > 100] if current_agv_status=='to unoccupied spots by static shelves': status_count=[x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='to unoccupied spots by static shelves'] if not status_count: waiting_counts_in_stations[agv_seq_no].append(['to unoccupied spots by static shelves',1]) else: status_count=status_count[0] waiting_counts_in_stations[agv_seq_no].remove(status_count) status_count[1]=status_count[1]+1 waiting_counts_in_stations[agv_seq_no].append(status_count) haveconditions = [x for x in waiting_counts_in_stations[agv_seq_no] if x[0]=='Pod Storage Selection' and x[1] > 300] if current_agv_status=='shelves have been unloaded': for each_status in waiting_counts_in_stations[agv_seq_no]: each_status[1]=0 aaaaa=False if haveconditions: aaaaa=True pass agv_info_for_map[agv_seq_no - 1][1] = agv_current_status[agv_seq_no - 1] other_information['current_agv_status']=agv_current_status[agv_seq_no - 1] other_information['current_agv_target_position'] =str(agv_target_positions[agv_seq_no - 1]) other_information['path']=str(agv_paths[agv_seq_no - 1]) other_information['AGV_Visit_Count_Per_Second']=str(Average_visit_station_count) file_name=result.write_positions_to_file(column_number, agv_info_for_map, static_shelves, other_information,simulation_start_time + grid_step_time * step) result.agvshelf("./SnapShots/"+file_name) # result.efficient_information(simulation_steps,simulation_progress,simulation_progress_time, # simulation_start_time, step, grid_step_time, waiting_count, agv_number, # finished_package_count, conf, out_station_package_count, # efficient_info) result.write_simulation_results_to_file(simulation_total_time,grid_length,agv_number, finished_package_count,waiting_count,agv_move_step_count,conf, simulation_start_time,efficient_info,agv_finished_package_count,agv_wait_times) result.drawmap_main(boundary_nodes_x,boundary_nodes_y)
def pod_selecion_for_picking_station(item_selected, Item_pod_Layer, pod_layer_Item, station, static_shelves, unbooked_static_shelves, columnumber): pod_selected = [] station_x, station_y = AuxiliaryModule.convert_vertex_to_coordinate( columnumber, station) all_pods_info = [] item_selected_temp = copy.deepcopy(item_selected) #[物品编号,物品需求数目] for eachelement in item_selected_temp: all_item_location = Item_pod_Layer['item_' + str(eachelement[0])][1:] for eachpod in all_item_location: The_pods_info = list(x for x in all_pods_info if x[0][0] == eachpod[0]) if len(The_pods_info) == 0: if eachpod[0] in unbooked_static_shelves: pod_x, pod_y = AuxiliaryModule.convert_vertex_to_coordinate( columnumber, static_shelves[eachpod[0]]) station_pod_estimated_distance = abs( pod_x - station_x) + abs(pod_y - station_y) else: station_pod_estimated_distance = 0 NumDesiredItemsInPod = sum( list(x[2] for x in pod_layer_Item[eachpod[0]] if x[1] == 'item_' + str(eachelement[0]))) all_pods_info.append( [[eachpod[0], station_pod_estimated_distance], [eachelement[0], NumDesiredItemsInPod]]) #货架编号,货架站台距离,物品编号,货架中该物品数目 else: item_num_ = [ x[1:] for x in all_pods_info if x[0][0] == eachpod[0] ][0] item_name = list(y[0] for y in item_num_) if eachelement[0] not in item_name: NumDesiredItemsInPod = sum( list(x[2] for x in pod_layer_Item[eachpod[0]] if x[1] == 'item_' + str(eachelement[0]))) IndexDesiredPod = list( all_pods_info.index(x) for x in all_pods_info if x[0][0] == eachpod[0])[0] all_pods_info[IndexDesiredPod].append( [eachelement[0], NumDesiredItemsInPod]) all_pods_info = sorted(all_pods_info, key=lambda x: x[0][1]) NumItemsSelected = len(item_selected_temp) pods_with_one_trip = [ x for x in all_pods_info if get_items_with_adequate_amount( x, item_selected_temp) == NumItemsSelected ] if pods_with_one_trip: return [pods_with_one_trip[0][0][0]] all_pods_info_temp = copy.deepcopy(all_pods_info) for i_numitem in range(1, NumItemsSelected + 1): pods_with_two_trips = [ x for x in all_pods_info if get_items_with_adequate_amount(x, item_selected_temp) == ( NumItemsSelected - i_numitem) ] for first_pod in pods_with_two_trips: all_pods_info_temp.remove(first_pod) for second_pod in all_pods_info_temp: pods_selected = [] pods_selected.append(first_pod) pods_selected.append(second_pod) if AdequateItemsInPods(pods_selected, item_selected_temp): return [first_pod[0][0], second_pod[0][0]] pods_selected = [] for pod in all_pods_info: if HasDesiredItemsInPod(pod, item_selected_temp): pods_selected.append(pod) if IsPodsHaveAdequateItems(pods_selected, item_selected_temp): return [x[0][0] for x in pods_selected] #[货架编号,等效lines数],[货架编号。。。。 return None
def drawmap_for_path_search(current_map, current_vertex, target_vertex): global vertex_layer_shift if vertex_layer_shift is None: vertex_layer_shift = ConfigManager.get_vertex_layer_shift() current_path = os.getcwd() file_path = current_path + "/config.ini" config_reader = configparser.ConfigParser() config_reader.read(file_path) # print('read configuration file: ' + file_path) map_area = AuxiliaryModule.convert_area_coordinates( config_reader.get('map', 'initial_area')) list = {} map_area.setFill("white") listindex = 0 list[listindex] = { "point": map_area, "type": "Rectangl", "colour": "white", "no": 0 } index = 0 list[index]["point"].p1.x = list[index]["point"].p1.x * k + k_shift_x list[index]["point"].p1.y = list[index]["point"].p1.y * k + k_shift_y list[index]["point"].p2.x = list[index]["point"].p2.x * k + k_shift_x list[index]["point"].p2.y = list[index]["point"].p2.y * k + k_shift_y griddingPoint = list[0]["point"] img = np.zeros((int(griddingPoint.p2.y) + map_padding_y, int(griddingPoint.p2.x) + map_padding_x, 3), np.uint8) # fill the image with white img.fill(255) node_number_col_map = int(config_reader.get('map', 'column_number')) for i_edge in [ one for one in current_map.edges() if one[0] < vertex_layer_shift and one[1] < vertex_layer_shift ]: lineclour = colourMap["black"] min_node_x, min_node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, i_edge[0]) max_node_x, max_node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, i_edge[1]) min_node_x = min_node_x * k + k_shift_x max_node_x = max_node_x * k + k_shift_x min_node_y = min_node_y * k + k_shift_y max_node_y = max_node_y * k + k_shift_y cv2.arrowedLine(img, (int(min_node_x), int(min_node_y)), (int(max_node_x), int(max_node_y)), lineclour, 1) for i_edge in [ one for one in current_map.edges() if one[0] > vertex_layer_shift and one[1] > vertex_layer_shift ]: lineclour = colourMap["black"] min_node_x, min_node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, i_edge[0]) max_node_x, max_node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, i_edge[1]) min_node_x = min_node_x * k + k_shift_x max_node_x = max_node_x * k + k_shift_x min_node_y = min_node_y * k + k_shift_y max_node_y = max_node_y * k + k_shift_y cv2.arrowedLine(img, (int(min_node_x), int(min_node_y)), (int(max_node_x), int(max_node_y)), lineclour, 1) node_x, node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, current_vertex) node_x = node_x * k + k_shift_x node_y = node_y * k + k_shift_y cv2.line(img, (int(min_node_x), int(min_node_y)), (int(max_node_x), int(max_node_y)), lineclour, 1) cv2.rectangle(img, (int(node_x) + 2, int(node_y) + 2), (int(node_x) - 2, int(node_y) - 2), colourMap["red"], -2) node_x, node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, target_vertex) node_x = node_x * k + k_shift_x node_y = node_y * k + k_shift_y cv2.line(img, (int(min_node_x), int(min_node_y)), (int(max_node_x), int(max_node_y)), lineclour, 1) cv2.rectangle(img, (int(node_x) + 2, int(node_y) + 2), (int(node_x) - 2, int(node_y) - 2), colourMap["green"], -2) cv2.imshow('MAP', img) cv2.waitKey(0) cv2.destroyAllWindows() pass
def agvshelf(curfile): try: #current_path = os.getcwd() #file_path = current_path + "/SnapShots/2018-4-10_14-49-20_673.txt" config_reader = configparser.ConfigParser() #config_reader.read(file_path) onfig_reader.read(curfile) list, stime, scount = AuxiliaryModule.getAgvShelfInfoFromFile(curfile) for index in range(len(list)): list[index][ "point"].p1.x = list[index]["point"].p1.x * k + k_shift_x list[index][ "point"].p1.y = list[index]["point"].p1.y * k + k_shift_y list[index][ "point"].p2.x = list[index]["point"].p2.x * k + k_shift_x list[index][ "point"].p2.y = list[index]["point"].p2.y * k + k_shift_y global backgroundimg img = backgroundimg.copy() for index in range(len(list)): if list[index]["type"] == "Rectangl_agv": RectanglPoint = list[index]["point"] #print(RectanglPoint, colourMap[list[index]["colour"]]) cv2.rectangle( img, (int(RectanglPoint.p1.x) + 2, int(RectanglPoint.p1.y) + 2), (int(RectanglPoint.p2.x) - 2, int(RectanglPoint.p2.y) - 2), colourMap[list[index]["colour"]], -2) # cv2.circle(img, (447, 63), 63, (0, 0, 255), -1) cv2.putText(img, str(list[index]["no"]), (int(RectanglPoint.p1.x), int(RectanglPoint.p1.y)), chosen_font, k_text, (0, 0, 0), 1, cv2.FILLED) elif list[index]["type"] == "Rectangl_shelf": RectanglPoint = list[index]["point"] cv2.rectangle( img, (int(RectanglPoint.p1.x) + 2, int(RectanglPoint.p1.y) + 2), (int(RectanglPoint.p2.x) - 2, int(RectanglPoint.p2.y) - 2), colourMap[list[index]["colour"]], -2) elif list[index]["type"] == "Circle": # cv2.rectangle(img, (384, 0), (510, 128), (0, 255, 0), 3) RectanglPoint = list[index]["point"] #print(RectanglPoint,int(RectanglPoint.p1.y)) cv2.circle(img, (int(RectanglPoint.p1.x), int(RectanglPoint.p1.y)), 5, colourMap[list[index]["colour"]], -1) cv2.putText(img, list[index]["no"], (int(RectanglPoint.p1.x), int(RectanglPoint.p1.y)), chosen_font, k_text, (0, 0, 0), 1, cv2.FILLED) else: print("负数") size = img.shape aa = size[1] cv2.putText(img, "time:" + stime, (30, size[0] - 40), chosen_font, k_text, colourMap["pink"], 1, cv2.FILLED) cv2.putText(img, "file:" + curfile, (30, size[0] - 20), chosen_font, k_text, colourMap["pink"], 1, cv2.FILLED) cv2.putText(img, "Station_Visit_Count_Per_Second:" + scount, (500, size[0] - 20), chosen_font, k_text, colourMap["pink"], 1, cv2.FILLED) cv2.imshow('MAP', img) if cv2.waitKey(300) == 27: print("exit") raise Exception() # cv2.destroyAllWindows() except Exception as e: print(e) sys.exit(1) # fatal error, need exit the program
def load_config(): try: current_path = os.getcwd() config_file_path = current_path + "\config.ini" print('loading config file at path: ' + config_file_path) config_reader = configparser.ConfigParser() config_reader.read(config_file_path) # global vertex_layer_shift if vertex_layer_shift is None: vertex_layer_shift = get_vertex_layer_shift() column_number = int(config_reader.get('map', 'column_number')) map_grid_length = float(config_reader.get('map', 'grid_length')) agv_MaxSpeed = float(config_reader.get('agv', 'MaxSpeed')) agv_MaxAngularSpeed = float(config_reader.get('agv', 'MaxAngularSpeed')) agv_AngularAcceleration = float( config_reader.get('agv', 'AngularAcceleration')) picking_station_num = int( config_reader.get('picking station', 'picking_station_num')) replen_station_num = int( config_reader.get('replen station', 'replen_station_num')) max_buffer_len_per_in_station = int( config_reader.get('map', 'max_buffer_len_per_in_station')) max_buffer_len_per_out_station = int( config_reader.get('map', 'max_buffer_len_per_out_station')) representative_picking_station = config_reader.get( 'picking station', 'representative_picking_station') buffer_list_dic = {} for i_picking_station in range(1, picking_station_num + 1): if (i_picking_station % 2 == 1): i_picking_station_temp = i_picking_station + 1 else: i_picking_station_temp = i_picking_station picking_station_string = config_reader.get( 'picking station', 'picking_station_' + str(i_picking_station_temp)) picking_station = picking_station_string[ picking_station_string.index('(') + 1:picking_station_string.index(')')].split(',') staion_vertex = AuxiliaryModule.convert_coordinate_to_vertex( column_number, int(picking_station[0]), int(picking_station[1])) buffer_list = [] for i_buffer_in in range(max_buffer_len_per_in_station, -1, -1): buffer_list.append(staion_vertex + column_number * i_buffer_in) for i_buffer_out in range(0, max_buffer_len_per_out_station + 1, 1): buffer_list.append(staion_vertex + column_number * i_buffer_out - 1) if staion_vertex not in buffer_list_dic: buffer_list_dic[staion_vertex] = buffer_list if (staion_vertex - 1) not in buffer_list_dic: buffer_list_dic[staion_vertex - 1] = buffer_list for i_replen_station in range(1, replen_station_num + 1): replen_station_string = config_reader.get( 'replen station', 'replen_station_' + str(i_replen_station)) replen_station = replen_station_string[ replen_station_string.index('(') + 1:replen_station_string.index(')')].split(',') station_vertex = AuxiliaryModule.convert_coordinate_to_vertex( column_number, int(replen_station[0]), int(replen_station[1])) if (station_vertex - column_number) in buffer_list_dic.keys(): buffer_list_dic[station_vertex] = buffer_list_dic[ station_vertex - column_number] else: buffer_list_dic[station_vertex] = [ station_vertex + 1, station_vertex, station_vertex + column_number, station_vertex + column_number + 1 ] Translation_weight = map_grid_length / agv_MaxSpeed rotation_weight = 2 * agv_MaxAngularSpeed / agv_AngularAcceleration if (90 - agv_MaxAngularSpeed / agv_AngularAcceleration * agv_MaxAngularSpeed) > 0: rotation_weight = rotation_weight + ( 90 - agv_MaxAngularSpeed / agv_AngularAcceleration * agv_MaxAngularSpeed) / agv_MaxAngularSpeed map_area = config_reader.get('map', 'initial_area') map_coordinates = convert_area_coordinates(map_area) map = networkx.DiGraph() node_number_col = int(map_coordinates.p2.x - map_coordinates.p1.x + 1) node_number_row = int(map_coordinates.p2.y - map_coordinates.p1.y + 1) node_number = node_number_col * node_number_row map_nodes = [] node_distance = {} boundary_nodes_x = {} boundary_nodes_y = {} for i_col in range(1, node_number_col + 1): for i_row in range(1, node_number_row + 1): current_node = i_col + node_number_col * (i_row - 1) map_nodes.append(current_node) second_layer_node = current_node + vertex_layer_shift map.add_node(current_node) if vertex_layer_shift > 0.1: map.add_node(second_layer_node) map.add_weighted_edges_from([ (current_node, second_layer_node, rotation_weight) ]) map.add_weighted_edges_from([ (second_layer_node, current_node, rotation_weight) ]) if ((i_col % 2 == 1) and (i_row < node_number_row)): neighbor_node_down = current_node + node_number_col map.add_weighted_edges_from([ (current_node, neighbor_node_down, Translation_weight) ]) map.add_weighted_edges_from([ (neighbor_node_down, current_node, Translation_weight) ]) if ((i_col % 2 == 0) and (i_row > 1)): neighbor_node_up = current_node - node_number_col map.add_weighted_edges_from([ (current_node, neighbor_node_up, Translation_weight) ]) map.add_weighted_edges_from([ (neighbor_node_up, current_node, Translation_weight) ]) if ((i_row % 2 == 1) and (i_col > 1)): neighbor_node_left = second_layer_node - 1 map.add_weighted_edges_from([ (second_layer_node, neighbor_node_left, Translation_weight) ]) map.add_weighted_edges_from([ (neighbor_node_left, second_layer_node, Translation_weight) ]) if ((i_row % 2 == 0) and (i_col < node_number_col)): neighbor_node_right = second_layer_node + 1 map.add_weighted_edges_from([ (second_layer_node, neighbor_node_right, Translation_weight) ]) map.add_weighted_edges_from([ (neighbor_node_right, second_layer_node, Translation_weight) ]) except_area_num = int(config_reader.get('map', 'substract_area_num')) for i_area in range(1, except_area_num + 1): except_area = config_reader.get('map', 'substract_area_' + str(i_area)) except_coordiantes = convert_area_coordinates(except_area) ex_num_clo_start = int(except_coordiantes.p1.x) + 1 ex_num_clo_end = int(except_coordiantes.p2.x) + 1 ex_num_row_start = int(except_coordiantes.p1.y) + 1 ex_num_row_end = int(except_coordiantes.p2.y) + 1 for ex_col in range(ex_num_clo_start, ex_num_clo_end + 1): for ex_row in range(ex_num_row_start, ex_num_row_end + 1): ex_node = ex_col + node_number_col * (ex_row - 1) map.remove_node(ex_node) map_nodes.remove(ex_node) if vertex_layer_shift > 0.1: map.remove_node(ex_node + vertex_layer_shift) picking_station_except_edge = get_station_except_edge(column_number) # for edge_except_key in picking_station_except_edge.keys(): # start_point=picking_station_except_edge[edge_except_key][0]+ vertex_layer_shift # end_point=picking_station_except_edge[edge_except_key][1]+ vertex_layer_shift # if (map.has_edge(start_point,end_point)): # map.remove_edge(start_point,end_point) First_node_buffer_list = [] for buffer_list_key in buffer_list_dic.keys(): first_node = buffer_list_dic[buffer_list_key][0] end_node = buffer_list_dic[buffer_list_key][-1] if first_node not in First_node_buffer_list: First_node_buffer_list.append(first_node) node_list = buffer_list_dic[buffer_list_key][1:-1] for each_node in node_list: map.remove_node(each_node) map.remove_node(each_node + vertex_layer_shift) if buffer_list_key < column_number: #只对拣货站做处理 map.remove_edge(end_node + vertex_layer_shift, end_node + vertex_layer_shift - 1) map.remove_edge(end_node + vertex_layer_shift, end_node + vertex_layer_shift + 1) # result.drawmap_for_path_search(map,2,7) # neighbors = [n for n in map.neighbors(10)] print('node_count_total_without_except_area =' + str(map.number_of_nodes())) print('edges_count_total_without_except_area =' + str(map.number_of_edges())) #print('vertex=',map.nodes) station_point = [ int(x) for x in convert_str_coordinates(representative_picking_station) ] for i_node in map_nodes: current_node_x, current_node_y = AuxiliaryModule.convert_vertex_to_coordinate( column_number, i_node) distance = abs(current_node_x - station_point[0]) + abs(current_node_y - station_point[1]) node_distance[i_node] = [distance] get_boundary_nodes(node_number_col, node_number_row, map_nodes, boundary_nodes_x, boundary_nodes_y, picking_station_except_edge) map_nodes.sort() return map, map_nodes, node_distance, buffer_list_dic, boundary_nodes_x, boundary_nodes_y except Exception as e: print( 'Error: failed to read configuration file! File path should be at: ' + config_file_path) print(e) sys.exit(1) # fatal error, need exit the program
def LoadConfigFromFile(self, map_nodes, buffer_list_dic): try: current_path = os.getcwd() config_file_path = current_path + "/config.ini" print('loading config file at path: ' + config_file_path) config_reader = configparser.ConfigParser() config_reader.read(config_file_path) self.agv_num = int(config_reader.get('agv', 'number')) self.agv_maxspeed = float(config_reader.get('agv', 'MaxSpeed')) self.grid_length = float(config_reader.get('map', 'grid_length')) self.column_number = int(config_reader.get('map', 'column_number')) self.row_number = int(config_reader.get('map', 'row_number')) # #self.cost_of_turn_around = float(config_reader.get('agv','cost_of_turn_around')) self.cost_of_put_package = float( config_reader.get('agv', 'cost_of_put_package')) self.cost_of_drop_package = float( config_reader.get('agv', 'cost_of_drop_package')) self.simulation_time = int( config_reader.get('agv', 'simulation_time')) self.max_buffer_len_per_in_station = int( config_reader.get('map', 'max_buffer_len_per_in_station')) self.max_buffer_len_per_out_station = int( config_reader.get('map', 'max_buffer_len_per_out_station')) self.charge_efficient = float( config_reader.get('agv', 'charge_efficient')) self.num_lines = int( config_reader.get('order', 'Num_of_lines_per_order')) self.unoccupied_vertex = copy.deepcopy(map_nodes) self.agv_kinematic.append( float(config_reader.get('agv', 'MaxSpeed'))) self.agv_kinematic.append( float(config_reader.get('agv', 'AcceleratedSpeed'))) self.agv_kinematic.append( float(config_reader.get('agv', 'MaxAngularSpeed'))) self.agv_kinematic.append( float(config_reader.get('agv', 'AngularAcceleration'))) NumItemForOneLayer = int( config_reader.get('pod', 'NumItemForOneLayer')) NumLayers = int(config_reader.get('pod', 'Layers')) pod_num = int(config_reader.get('pod', 'pod_num')) item_num = int( config_reader.get( 'item: Min,Max,Avg,Dev,order possibility,num of layers', 'item_num')) self.picking_time_per_item = int( config_reader.get('picking station', 'picking_time_per_item')) self.replenishing_time_per_pod = int( config_reader.get('replen station', 'replenishing_time_per_pod')) self.call_interval_by_replen_station = int( config_reader.get('replen station', 'call_interval_by_replen_station')) PodFullyFilled = [] PodStatusOfItem = [] DetailedPodStatusOfItem = [] for i_layer in range(1, NumLayers + 1): PodStatusOfItem.append( 0) #this means all layers in a pod is empty DetailedPodStatusOfItem.append([i_layer, 'item', 0 ]) #layer is empty wihout item for i_pod in range(1, pod_num + 1): PodStatusOfItem.append(i_pod) PodStatusOfItemTemp = copy.deepcopy(PodStatusOfItem) PodFullyFilled.append( PodStatusOfItemTemp ) #this means all layers in pod i is empty PodStatusOfItem.remove(i_pod) DetailedPodStatusOfItemTemp = copy.deepcopy( DetailedPodStatusOfItem) self.Initial_Layer_Item[i_pod] = DetailedPodStatusOfItemTemp station_coordinates = config_reader.get( 'pod', 'pod_' + str(i_pod)) point = convert_point_coordinates(station_coordinates) station_vertex = AuxiliaryModule.convert_coordinate_to_vertex( self.column_number, point.x, point.y) # + vertex_layer_shift self.unoccupied_vertex.remove(station_vertex) self.in_station.append(point) self.initial_static_shelves_vertex[i_pod] = station_vertex self.pod_called_count[i_pod] = 0 self.pod_called_count_for_replen[i_pod] = 0 buffer_list = [] next_vertex = station_vertex buffer_list.append(next_vertex) for buffer_index in range( 1, self.max_buffer_len_per_in_station + 1): next_vertex = AuxiliaryModule.get_neighbor_node_down( self.column_number, self.row_number, next_vertex) buffer_list.append(next_vertex) self.in_station_buffer.append(buffer_list) picking_station_num = int( config_reader.get('picking station', 'picking_station_num')) First_node_buffer_list = [] for i_out in range(1, picking_station_num + 1): station_coordinates = config_reader.get( 'picking station', 'picking_station_' + str(i_out)) point = convert_point_coordinates(station_coordinates) station_vertex = AuxiliaryModule.convert_coordinate_to_vertex( self.column_number, point.x, point.y) # + vertex_layer_shift first_node = buffer_list_dic[station_vertex][0] if first_node not in First_node_buffer_list: First_node_buffer_list.append(first_node) for each_node in buffer_list_dic[station_vertex]: self.unoccupied_vertex.remove(each_node) self.out_station.append(station_vertex) buffer_list = [] next_vertex = station_vertex buffer_list.append(next_vertex) for buffer_index in range( 1, self.max_buffer_len_per_out_station + 1): if int(round(point.x)) == 0: next_vertex = AuxiliaryModule.get_neighbor_node_right( self.column_number, self.row_number, next_vertex) elif int(round(point.y)) == 0: next_vertex = AuxiliaryModule.get_neighbor_node_down( self.column_number, self.row_number, next_vertex) buffer_list.append(next_vertex) self.out_station_buffer.append(buffer_list) replenishing_station_num = int( config_reader.get('replen station', 'replen_station_num')) for i_replen in range(1, replenishing_station_num + 1): station_coordinates = config_reader.get( 'replen station', 'replen_station_' + str(i_replen)) point = convert_point_coordinates(station_coordinates) station_vertex = AuxiliaryModule.convert_coordinate_to_vertex( self.column_number, point.x, point.y) # + vertex_layer_shift self.replen_stations.append(station_vertex) for i_item in range(1, item_num + 1): item_info_string = config_reader.get( 'item: Min,Max,Avg,Dev,order possibility,num of layers', 'item_' + str(i_item)) item_info_list = item_info_string[item_info_string.index('(') + 1:item_info_string. index(')')].split(',') Item_Layer_info = [] MinItemsForOneLine = int(item_info_list[0]) MaxItemsForOneLine = int(item_info_list[1]) AvgItemsForOneLine = int(item_info_list[2]) DevItemsForOneLine = float(item_info_list[3]) OrderPossibility = float(item_info_list[4]) NumOfLayers = int(item_info_list[5]) self.Initial_Order_selection.append(OrderPossibility) Item_Layer_info.append([ MinItemsForOneLine, MaxItemsForOneLine, AvgItemsForOneLine, DevItemsForOneLine ]) self.Initial_Item_Layer['item_' + str(i_item)] = Item_Layer_info for i_item_layer in range(1, NumOfLayers + 1): item_filled = False while item_filled == False: fakepod = np.random.randint(1, len(PodFullyFilled) + 1) if 0 in PodFullyFilled[fakepod - 1]: LayerNum = int(PodFullyFilled[fakepod - 1].index(0)) pod = int(PodFullyFilled[fakepod - 1][NumLayers]) PodFullyFilled[fakepod - 1][LayerNum] = 1 self.Initial_Layer_Item[pod][LayerNum] = [ LayerNum + 1, 'item_' + str(i_item), NumItemForOneLayer ] Item_Layer_info.append( [pod, LayerNum + 1, NumItemForOneLayer]) self.Initial_Item_Layer[ 'item_' + str(i_item)] = Item_Layer_info item_filled = True else: del PodFullyFilled[fakepod - 1] except Exception as e: print( 'Error: failed to read configuration file! File path should be at: ' + config_file_path) print(e) sys.exit(1) # fatal error, need exit the program
def background(boundary_nodes_x, boundary_nodes_y): try: current_path = os.getcwd() file_path = current_path + "/config.ini" config_reader = configparser.ConfigParser() config_reader.read(file_path) # print('read configuration file: ' + file_path) map_area = AuxiliaryModule.convert_area_coordinates( config_reader.get('map', 'initial_area')) list = {} map_area.setFill("white") listindex = 0 list[listindex] = { "point": map_area, "type": "Rectangl", "colour": "white", "no": 0 } # i = 0 # while True: # try: # i = i + 1 # substract_area = CoordinateConverter.convert_area_coordinates( # config_reader.get('map', 'substract_area_' + str(i))) # substract_area.setFill("black") # listindex = listindex + 1 # list[listindex] = {"point":substract_area,"type":"Rectangl","colour":"black","no":i} # except Exception as e: # #print(e) # break # i = 0 # while True: # try: # i = i + 1 # substract_area = CoordinateConverter.convert_Rectangl_coordinates( # config_reader.get('package_in_station', 'in_station_' + str(i)), '1') # substract_area.setFill("green") # listindex = listindex + 1 #list[listindex] = substract_area # list[listindex] = {"point": substract_area, "type": "Rectangl", "colour": "green","no":i} # except Exception as e: #print(e) # break i = 0 while True: try: i = i + 1 substract_area = AuxiliaryModule.convert_Rectangl_coordinates( config_reader.get('picking station', 'picking_station_' + str(i)), '1') substract_area.setFill("blue") listindex = listindex + 1 #list[listindex] = substract_area list[listindex] = { "point": substract_area, "type": "Rectangl", "colour": "blue", "no": i } except Exception as e: #print(e) break i = 0 while True: try: i = i + 1 substract_area = AuxiliaryModule.convert_Rectangl_coordinates( config_reader.get('replen station', 'replen_station_' + str(i)), '1') substract_area.setFill("pink") listindex = listindex + 1 #list[listindex] = substract_area list[listindex] = { "point": substract_area, "type": "Rectangl", "colour": "pink", "no": i } except Exception as e: #print(e) break for index in range(len(list)): list[index][ "point"].p1.x = list[index]["point"].p1.x * k + k_shift_x list[index][ "point"].p1.y = list[index]["point"].p1.y * k + k_shift_y list[index][ "point"].p2.x = list[index]["point"].p2.x * k + k_shift_x list[index][ "point"].p2.y = list[index]["point"].p2.y * k + k_shift_y #print(list) #cvmat = cv2.Mat(list[0].p2.y, list[index].p2.x, cv2.CV_8U) #cv2.imshow('frame',cvmat) griddingPoint = list[0]["point"] img = np.zeros((int(griddingPoint.p2.y) + map_padding_y, int(griddingPoint.p2.x) + map_padding_x, 3), np.uint8) # fill the image with white img.fill(255) node_number_col_map = int(config_reader.get('map', 'column_number')) node_number_row_map = int(config_reader.get('map', 'row_number')) count = 0 for i_col in range(1, node_number_col_map + 1): count = count + 1 if (count % 2) == 0: lineclour = colourMap["black"] else: lineclour = colourMap["yellow"] for i_row in range(1, node_number_row_map + 1): current_node = i_col + node_number_col_map * (i_row - 1) if current_node in boundary_nodes_x: Node_array = boundary_nodes_x[current_node] for i_node in range(1, len(Node_array), 2): min_node_x, min_node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, Node_array[i_node - 1]) max_node_x, max_node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, Node_array[i_node]) min_node_x = min_node_x * k + k_shift_x max_node_x = max_node_x * k + k_shift_x min_node_y = min_node_y * k + k_shift_y max_node_y = max_node_y * k + k_shift_y cv2.line(img, (int(min_node_x), int(min_node_y)), (int(min_node_x), int(max_node_y)), lineclour, 1) break count = 0 for i_row in range(1, node_number_row_map + 1): count = count + 1 if (count % 2) == 0: lineclour = colourMap["black"] else: lineclour = colourMap["pink"] for i_col in range(1, node_number_col_map + 1): current_node = i_col + node_number_col_map * (i_row - 1) if current_node in boundary_nodes_y: Node_array = boundary_nodes_y[current_node] for i_node in range(1, len(Node_array), 2): min_node_x, min_node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, Node_array[i_node - 1]) max_node_x, max_node_y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col_map, Node_array[i_node]) min_node_x = min_node_x * k + k_shift_x max_node_x = max_node_x * k + k_shift_x min_node_y = min_node_y * k + k_shift_y max_node_y = max_node_y * k + k_shift_y cv2.line(img, (int(min_node_x), int(min_node_y)), (int(max_node_x), int(min_node_y)), lineclour, 1) break for index in range(1, len(list)): if list[index]["type"] == "Rectangl": RectanglPoint = list[index]["point"] cv2.rectangle( img, (int(RectanglPoint.p1.x) + 2, int(RectanglPoint.p1.y) + 2), (int(RectanglPoint.p2.x) - 2, int(RectanglPoint.p2.y) - 2), colourMap[list[index]["colour"]], -1) #cv2.circle(img, (447, 63), 63, (0, 0, 255), -1) elif list[index]["type"] == "Circle": #cv2.rectangle(img, (384, 0), (510, 128), (0, 255, 0), 3) RectanglPoint = list[index]["point"] #print(RectanglPoint) cv2.circle(img, (int(RectanglPoint.p1.x), int(RectanglPoint.p1.y)), 0.1, colourMap[list[index]["colour"]], -1) else: print("负数") global backgroundimg backgroundimg = img # cv2.imshow('MAP', img) #cv2.destroyAllWindows() except Exception as e: print(e) sys.exit(1) # fatal error, need exit the program
def pod_dislocation(agv_current_positions, agv_target_positions, agv_current_status, pods_for_dislocation, static_shelves, pod_status, agv_with_shelves, column_number, agv_seq_no): agv_status = agv_current_status[agv_seq_no - 1] if agv_status == 'pod dislocation - to dislocation pod': if agv_current_positions[agv_seq_no - 1] != agv_target_positions[agv_seq_no - 1]: pass else: agv_target_positions[agv_seq_no - 1] = pods_for_dislocation[agv_seq_no][-2] del static_shelves[pods_for_dislocation[agv_seq_no][1]] agv_with_shelves.append(agv_seq_no) agv_current_status[agv_seq_no - 1] = 'pod dislocation - move dislocation pod' elif agv_status == 'pod dislocation - move dislocation pod': current_position_x, current_position_y = AuxiliaryModule.convert_vertex_to_coordinate( column_number, agv_current_positions[agv_seq_no - 1]) travel_distance = abs(current_position_x - pods_for_dislocation[agv_seq_no][3][0]) + abs( current_position_y - pods_for_dislocation[agv_seq_no][3][1]) if travel_distance < pods_for_dislocation[agv_seq_no][-1]: pass else: static_shelves[pods_for_dislocation[agv_seq_no] [1]] = agv_current_positions[agv_seq_no - 1] agv_target_positions[agv_seq_no - 1] = static_shelves[ pods_for_dislocation[agv_seq_no][0]] agv_current_status[agv_seq_no - 1] = 'pod dislocation - to target pod' agv_with_shelves.remove(agv_seq_no) elif agv_status == 'pod dislocation - to target pod': if agv_current_positions[agv_seq_no - 1] != agv_target_positions[agv_seq_no - 1]: pass else: agv_target_positions[agv_seq_no - 1] = pods_for_dislocation[agv_seq_no][-2] del static_shelves[pods_for_dislocation[agv_seq_no][0]] agv_current_status[agv_seq_no - 1] = 'pod dislocation - move target pod' agv_with_shelves.append(agv_seq_no) elif agv_status == 'pod dislocation - move target pod': current_position_x, current_position_y = AuxiliaryModule.convert_vertex_to_coordinate( column_number, agv_current_positions[agv_seq_no - 1]) travel_distance = abs(current_position_x - pods_for_dislocation[agv_seq_no][2][0]) + abs( current_position_y - pods_for_dislocation[agv_seq_no][2][1]) if travel_distance < (pods_for_dislocation[agv_seq_no][-1] + 1): pass else: static_shelves[pods_for_dislocation[agv_seq_no] [0]] = agv_current_positions[agv_seq_no - 1] agv_target_positions[agv_seq_no - 1] = static_shelves[ pods_for_dislocation[agv_seq_no][1]] agv_current_status[ agv_seq_no - 1] = 'pod dislocation - to dislocation pod a second time' agv_with_shelves.remove(agv_seq_no) elif agv_status == 'pod dislocation - to dislocation pod a second time': if agv_current_positions[agv_seq_no - 1] != agv_target_positions[agv_seq_no - 1]: pass else: agv_target_positions[ agv_seq_no - 1] = AuxiliaryModule.convert_coordinate_to_vertex( column_number, pods_for_dislocation[agv_seq_no][2][0], pods_for_dislocation[agv_seq_no][2][1]) del static_shelves[pods_for_dislocation[agv_seq_no][1]] agv_current_status[ agv_seq_no - 1] = 'pod dislocation - move dislocation pod to the initial vertex of target pod' agv_with_shelves.append(agv_seq_no) elif agv_status == 'pod dislocation - move dislocation pod to the initial vertex of target pod': if agv_current_positions[agv_seq_no - 1] != agv_target_positions[agv_seq_no - 1]: pass else: static_shelves[pods_for_dislocation[agv_seq_no] [1]] = agv_current_positions[agv_seq_no - 1] agv_target_positions[agv_seq_no - 1] = static_shelves[ pods_for_dislocation[agv_seq_no][0]] agv_current_status[ agv_seq_no - 1] = 'pod dislocation - to target pod a second time' agv_with_shelves.remove(agv_seq_no) elif agv_status == 'pod dislocation - to target pod a second time': if agv_current_positions[agv_seq_no - 1] != agv_target_positions[agv_seq_no - 1]: pass else: agv_current_status[agv_seq_no - 1] = 'in buffer list selection' del pod_status[pods_for_dislocation[agv_seq_no][0]] del pod_status[pods_for_dislocation[agv_seq_no][1]] del static_shelves[pods_for_dislocation[agv_seq_no][0]] static_shelves[pods_for_dislocation[agv_seq_no] [0]] = AuxiliaryModule.convert_coordinate_to_vertex( column_number, pods_for_dislocation[agv_seq_no][3][0], pods_for_dislocation[agv_seq_no][3][1]) del pods_for_dislocation[agv_seq_no]
def Create_out_station(): try: current_path = os.getcwd() config_file_path = current_path + "\config.ini" print('loading config file at path: ' + config_file_path) config_reader = configparser.ConfigParser() config_reader.read(config_file_path) map_area = config_reader.get('map', 'initial_area') map_coordinates = AuxiliaryModule.convert_area_coordinates(map_area) map = networkx.DiGraph() node_number_col = int(map_coordinates.p2.x - map_coordinates.p1.x + 1) node_number_row = int(map_coordinates.p2.y - map_coordinates.p1.y + 1) node_number = node_number_col * node_number_row for i_col in range(1, node_number_col + 1): for i_row in range(1, node_number_row + 1): current_node = i_col + node_number_col * (i_row - 1) map.add_node(current_node) if ((i_col > 1)): neighbor_node_left = current_node - 1 map.add_weighted_edges_from([(neighbor_node_left, current_node, 1)]) map.add_weighted_edges_from([(current_node, neighbor_node_left, 1)]) if ((i_row > 1)): neighbor_node_up = current_node - node_number_col map.add_weighted_edges_from([(neighbor_node_up, current_node, 1)]) map.add_weighted_edges_from([(current_node, neighbor_node_up, 1)]) if ((i_col < node_number_col)): neighbor_node_right = current_node + 1 map.add_weighted_edges_from([(neighbor_node_right, current_node, 1)]) map.add_weighted_edges_from([(current_node, neighbor_node_right, 1)]) if ((i_row < node_number_row)): neighbor_node_down = current_node + node_number_col map.add_weighted_edges_from([(neighbor_node_down, current_node, 1)]) map.add_weighted_edges_from([(current_node, neighbor_node_down, 1)]) except_area_num = int(config_reader.get('map', 'substract_area_num')) for i_area in range(1, except_area_num + 1): except_area = config_reader.get('map', 'substract_area_' + str(i_area)) except_coordiantes = AuxiliaryModule.convert_area_coordinates( except_area) ex_num_clo_start = int(except_coordiantes.p1.x) + 1 ex_num_clo_end = int(except_coordiantes.p2.x) + 1 ex_num_row_start = int(except_coordiantes.p1.y) + 1 ex_num_row_end = int(except_coordiantes.p2.y) + 1 for ex_col in range(ex_num_clo_start, ex_num_clo_end + 1): for ex_row in range(ex_num_row_start, ex_num_row_end + 1): ex_node = ex_col + node_number_col * (ex_row - 1) map.remove_node(ex_node) pos = [] pos.append((-1, -1)) for i_row in range(1, node_number_row + 1): for i_col in range(1, node_number_col + 1): pos.append((i_col, i_row)) networkx.draw(map, pos, node_color='blue', edge_color='red', node_size=10, alpha=1) # 按参数构图 plt.xlim(0, node_number_col + 1) # 设置首界面X轴坐标范围 plt.ylim(0, node_number_row + 1) # 设置首界面Y轴坐标范围 plt.savefig("out_station.png") # plt.show() file_path = current_path + '\out_station.txt' out_file = configparser.ConfigParser() out_file.add_section('out_station') node_index = 1 for i_col in range(1, node_number_col + 1): for i_row in range(1, node_number_row + 1): current_node = i_col + node_number_col * (i_row - 1) if (map.has_node(current_node) == False): continue x, y = AuxiliaryModule.convert_vertex_to_coordinate( node_number_col, current_node) # if(x == 11 and y >= 21 and y <= 37): # continue # if (y == 20 and x <= 11): # continue # if (y == 38 and x <= 11): # continue if (y <= 1): continue left_node = current_node - 1 down_node = current_node + node_number_col right_node = current_node + 1 up_node = current_node - node_number_col if (map.has_edge(current_node, left_node) == False): # x, y = CoordinateConverter.convert_vertex_to_coordinate(node_number_col, current_node) out_file.set('out_station', 'out_station_' + str(node_index), '(' + str(x) + ',' + str(y) + ')') node_index = node_index + 1 continue if (map.has_edge(current_node, down_node) == False): # x, y = CoordinateConverter.convert_vertex_to_coordinate(node_number_col, current_node) out_file.set('out_station', 'out_station_' + str(node_index), '(' + str(x) + ',' + str(y) + ')') node_index = node_index + 1 continue if (map.has_edge(current_node, right_node) == False): # x, y = CoordinateConverter.convert_vertex_to_coordinate(node_number_col, current_node) out_file.set('out_station', 'out_station_' + str(node_index), '(' + str(x) + ',' + str(y) + ')') node_index = node_index + 1 continue if (map.has_edge(current_node, up_node) == False): # x, y = CoordinateConverter.convert_vertex_to_coordinate(node_number_col, current_node) out_file.set('out_station', 'out_station_' + str(node_index), '(' + str(x) + ',' + str(y) + ')') node_index = node_index + 1 continue with open(file_path, 'w') as fw: out_file.write(fw) except Exception as e: print(e) sys.exit(1) # fatal error, need exit the program