def cal_path(self): hwy_data = HwyDataMng.instance() target_facils = hwy_data.get_hwy_forward_branches(self.node_id, self.road_code, self.road_point, self.updown, self.inout) pathes = [] if target_facils: for target in target_facils: target_node = target.node_id hwy_data.load_link_by_expand_box(self.G, self.node_id, target_node) pathes = self.G.all_paths_jct(self.node_id, target_node) if pathes: self._add_path(pathes, target, 'JCT') hwy_data = HwyDataMng.instance() hwy_graph = hwy_data.get_graph() # 判断目标点落在高速上 if target_node in hwy_graph: print ('Target JCT is on HWY. node_id=%s,name=%s' % (target_node, target.facil_name)) # 讲算其他JCT路径 self.cal_other_jct_path()
def _get_sv_link_bwd_fwd_ic(self, link_id, s_node, e_node, one_way): '''辅路的前、后方设施''' bwd_ic_nos = set() fwd_ic_nos = set() if one_way == ONE_WAY_POSITIVE: bwd_ic_nos = self._get_sv_link_bwd_ic_no(s_node) fwd_ic_nos = self._get_sv_link_fwd_ic_no(e_node) elif one_way == ONE_WAY_RERVERSE: bwd_ic_nos = self._get_sv_link_bwd_ic_no(e_node) fwd_ic_nos = self._get_sv_link_fwd_ic_no(s_node) else: self.log.error('No Forward/Backward IC No for service Road. ' 'link_id=%s.' % link_id) return [], [] if self._is_in_hwy_mapping(link_id): # 取得已有前后方设施 hwy_data = HwyDataMng.instance() old_bwd_nos = hwy_data.get_mapping_bwd_ic(link_id) old_fwd_nos = hwy_data.get_mapping_fwd_ic(link_id) if old_bwd_nos: bwd_ic_nos = bwd_ic_nos.union(old_bwd_nos) fwd_ic_nos = set() elif old_fwd_nos: bwd_ic_nos = set() fwd_ic_nos = fwd_ic_nos.union(old_fwd_nos) else: pass return self.__get_ic_link_fb_ic(list(bwd_ic_nos), list(fwd_ic_nos))
def _get_toll_facil(self, node_id, road_code, road_seq): hwy_data = HwyDataMng.instance() toll_facils = hwy_data.get_toll_facil(node_id) for toll_facil in toll_facils: if (toll_facil.road_code == road_code and toll_facil.road_point == road_seq): return toll_facil
def __init__(self, node_id, road_code, road_point, updown, facilcls, inout, facil_name, toll_flag=IC_TYPE_TRUE): ''' Constructor ''' self.node_id = node_id self.road_code = road_code self.road_point = road_point self.updown = updown self.facilcls = facilcls self.inout = inout self.facil_name = facil_name # {(path):(facil_info, path_type)}, path_type: UTURN, JCT, IC, SAPA self.pathes_dict = {} # self.uturn_pathes_dict = {} self.toll_flag = toll_flag hwy_data = HwyDataMng.instance() if toll_flag: self.G = hwy_data.get_graph() else: self.G = hwy_data.get_graph_no_toll()
def cal_ic_path(self): '''SA出口到IC所在位置''' hwy_data = HwyDataMng.instance() same_facils = hwy_data.get_same_facil(self.road_code, self.road_point, self.updown, self.inout) for same in same_facils: ic_types = (IC_TYPE_IC, IC_TYPE_SMART_IC, IC_TYPE_RAMP) if (same.facilcls not in ic_types or same.node_id == self.node_id or same.inout != self.inout): continue hwy_ic = HwyIcOutPath(self.node_id, same.road_code, same.road_point, same.updown, same.facilcls, same.inout, same.facil_name) same_path = [] has_sapa_ic = False hwy_ic.cal_path() for path, val in hwy_ic.pathes_dict.iteritems(): target_facil_info, path_type = val if target_facil_info: target_node = target_facil_info.node_id else: target_node = path[-1] same_path = self.G.all_paths_ic_out(same.node_id, target_node) # IC出口到IC所在位置,必须是通的 if same_path: self._add_path([path], target_facil_info, path_type) has_sapa_ic = True if has_sapa_ic: ic_path_sapa = ('亀山PA', ) # 有IC路径的SAPA if self.facil_name not in ic_path_sapa: print('SaPa have IC Out. node=%s, name=%s' % (self.node_id, self.facil_name))
def _get_sv_link_road_info(self, link_id, s_node, e_node, one_way): '''辅路的前、后方设施''' if self._is_in_hwy_mapping(link_id): # 已经在Mapping表, 用已有的道路属性(通常是无效值) hwy_data = HwyDataMng.instance() road_kind, road_no = hwy_data.get_mapping_road_info(link_id) return road_kind, road_no bwd_road_infos = set() fwd_road_infos = set() if one_way == ONE_WAY_POSITIVE: bwd_road_infos = self._get_sv_link_bwd_road_info(s_node) fwd_road_infos = self._get_sv_link_fwd_road_info(e_node) elif one_way == ONE_WAY_RERVERSE: bwd_road_infos = self._get_sv_link_bwd_road_info(e_node) fwd_road_infos = self._get_sv_link_fwd_road_info(s_node) else: self.log.error('无道路情报') return (ROAD_ATTR_NONE, INVALID_ROAD_NO) # 道路情报大于1 if len(bwd_road_infos) > 1 or len(fwd_road_infos) > 1: return (ROAD_ATTR_NONE, INVALID_ROAD_NO) # 前后道路情报不同 if bwd_road_infos != fwd_road_infos: return (ROAD_ATTR_NONE, INVALID_ROAD_NO) else: if not bwd_road_infos: # 空 return (ROAD_ATTR_NONE, INVALID_ROAD_NO) else: return bwd_road_infos.pop()
def cal_ic_path(self): '''SA入口到IC所在位置''' hwy_data = HwyDataMng.instance() same_facils = hwy_data.get_same_facil(self.road_code, self.road_point, self.updown, self.inout) for same in same_facils: ic_types = (IC_TYPE_IC, IC_TYPE_SMART_IC, IC_TYPE_RAMP) if (same.facilcls not in ic_types or same.node_id == self.node_id): continue hwy_ic = HwyIcInPath(self.node_id, same.road_code, same.road_point, same.updown, same.facilcls, same.inout, same.facil_name) hwy_ic.cal_path() same_path = [] has_sapa_ic = False for path, val in hwy_ic.pathes_dict.iteritems(): target_facil_info, path_type = val target_node = target_facil_info.node_id same_path = self.G.all_paths_ic_in(same.node_id, target_node) # IC入口到IC所在位置,必须是通的 # case: road_code=301060, road_seq=30, direction_c=2 if same_path: self._add_path([path], target_facil_info, path_type) has_sapa_ic = True if has_sapa_ic: ic_path_sapa = ('亀山PA',) if self.facil_name not in ic_path_sapa: print ('SaPa have IC In. node=%s, name=%s' % (self.node_id, self.facil_name))
def cal_ic_path(self): self.log.info('Calculating IC Path.') self.CreateTable2('mid_hwy_ic_path') sqlcmd = ''' SELECT node_id, road_code, road_seq, facilclass_c, direction_c as updown, inout_c, name_kanji FROM mid_road_hwynode_middle_nodeid where "tollclass_c" = 0 and "tollfunc_c" = 0 and hwymode_f = 1 order by road_code, direction_c, road_seq, objectid ''' self.pg.connect1() data = self.pg.get_batch_data2(sqlcmd) hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() no_toll_graph = hwy_data.get_graph_no_toll() for hwynode_info in data: node_id = hwynode_info[0] road_code = hwynode_info[1] road_point = hwynode_info[2] facil_cls = hwynode_info[3] updown = hwynode_info[4] inout = hwynode_info[5] facil_name = hwynode_info[6] if (node_id not in G or not G.in_edges(node_id) or not G.out_edges(node_id)): if node_id in no_toll_graph: # print 'No toll:', node_id toll_flag = IC_DEFAULT_VAL else: self.log.warning('Not in No_Toll HWY. node_id=%s' % node_id) continue else: # print 'Toll:', node_id toll_flag = IC_TYPE_TRUE ic_path = None ic_path = HwyFacilPathFactory.create_facil_path( self, toll_flag, node_id, road_code, road_point, updown, facil_cls, inout, facil_name) if ic_path: ic_path.cal_path() ic_path.cal_uturn_path() self.__insert_ic_path(ic_path) if not ic_path.pathes_dict and facil_cls != IC_TYPE_IC: if facil_cls in (IC_TYPE_PA, IC_TYPE_SA): pass else: name = ic_path.facil_name self.log.warning( 'No Path for node=%s,type=%s,name=%s' % (node_id, facil_cls, name)) else: pass self.pg.commit1() self.CreateIndex2('mid_hwy_ic_path_s_road_code_' 's_road_point_s_updown_s_node_id_idx') self.CreateIndex2('mid_hwy_ic_path_t_road_code_' 't_road_point_t_updown_t_node_id_idx')
def _sort_facils_backward(self, curr_facil_infos, ic_list): '''后方有相同设施,尽量排前面''' if len(ic_list) == 0: return [], [] hwy_data = HwyDataMng.instance() prev_road_point = hwy_data.get_prev_road_point(curr_facil_infos[0]) ic_idx = len(ic_list) - 1 while ic_idx >= 0: if ic_list[ic_idx].road_point == prev_road_point: break ic_idx -= 1 rst_ic_list = [] bwd_ic_counts = [] # 两个相同设施之间有几个设施 backward_ic_list = ic_list[ic_idx + 1:] temp_facil_infos = list(curr_facil_infos) ic_count = -1 while backward_ic_list: last_facil = backward_ic_list.pop() ic_count += 1 for facil in temp_facil_infos: if last_facil.road_point == facil.road_point: bwd_ic_counts.append(ic_count) rst_ic_list.append(facil) temp_facil_infos.remove(facil) break return rst_ic_list, bwd_ic_counts
def cal_path(self): hwy_data = HwyDataMng.instance() target_facils = hwy_data.get_hwy_forward_branches(self.node_id, self.road_code, self.road_point, self.updown, self.inout) pathes = [] if target_facils: for target in target_facils: # if (target.facil_name != self.facil_name and # target.facilcls == self.facilcls): # print ('JCT Name different, node=%s,name=%s,' # 'target_node=%s, target_name=%s' # % (self.node_id, self.facil_name, # target.node_id, target.facil_name)) target_node = target.node_id pathes = self.G.all_paths_jct(self.node_id, target_node) if pathes: # pathes = sorted(pathes, key=len) self._add_path(pathes, target, 'JCT') if not target_facils: print ('No Branch for node%s' % self.node_id) # 讲算其他JCT路径 # 数据中存前方JCT给少的情况,如[鳥栖JCT,road_code=204020,road_seq=180] self.cal_other_jct_path()
def _get_same_sapa(self, ic_no, node_id): '''取得并列,且同点的SAPA。''' hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() if not G.is_sapa(node_id): return None, None # backward bwd_ic_no = ic_no - 1 while bwd_ic_no: bwd_ic_no, facility_id, facil_list = hwy_data.get_ic(bwd_ic_no) same_node_flg = False for facil in facil_list: if facil.node_id == node_id: same_node_flg = True if facil.facilcls in (IC_TYPE_SA, IC_TYPE_PA): return bwd_ic_no, facil if not same_node_flg: break bwd_ic_no -= 1 # forward fwd_ic_no = ic_no + 1 while True: fwd_ic_no, facility_id, facil_list = hwy_data.get_ic(fwd_ic_no) if not fwd_ic_no: break same_node_flg = False for facil in facil_list: if facil.node_id == node_id: same_node_flg = True if facil.facilcls in (IC_TYPE_SA, IC_TYPE_PA): return fwd_ic_no, facil if not same_node_flg: break fwd_ic_no += 1 return None, None
def cal_path(self): hwy_data = HwyDataMng.instance() target_facils = self.get_target_facils() pathes = [] if target_facils: for target in target_facils: target_node = target.node_id pathes = self.G.all_paths_sapa(self.node_id, target_node) pathes = self._delete_same_roadcode_path(pathes, self.road_code) self._add_path(pathes, target, 'SAPA') else: # print 'No target node, node_id=%s' % self.node_id pathes = self.G.all_paths_2_sapa_in(self.node_id) for path in pathes: target_node = path[-1] facils = hwy_data.get_hwy_facils_by_nodeid(target_node, self.facilcls) # 同侧(同上下行), 同road_code for facil_info in facils: if (self.road_code == facil_info.road_code and self.facilcls == facil_info.facilcls and self.updown == facil_info.updown): temp_pathes = self._delete_same_roadcode_path([path], self.road_code) self._add_path(temp_pathes, facil_info, 'SAPA') self.cal_jct_path() self.cal_ic_path()
def _get_facils(self, node_id, ic_nos): facils = [] ic_list = [] hwy_data = HwyDataMng.instance() for ic_no in sorted(set(ic_nos)): ic_no, facility_id, facil_list = hwy_data.get_ic(ic_no) for facil in facil_list: if facil.node_id == node_id: # 按设施各别排序: SA > PA > JCT > Ramp > IC > SmartIC ic_idx = 0 while ic_idx < len(facils): if facil.facilcls < facils[ic_idx].facilcls: break elif facil.facilcls == facils[ic_idx].facilcls: # 取得二者中的父设施 parent = self._get_parent_facil( facils[ic_idx], facil) if parent == facil: break else: pass ic_idx += 1 facils.insert(ic_idx, facil) ic_list.insert(ic_idx, ic_no) return ic_list, facils
def get_target_facils(self): hwy_data = HwyDataMng.instance() targets = hwy_data.get_hwy_in_facils(self.road_code, self.road_point, self.updown, self.inout) return targets
def get_target_facils(self): hwy_data = HwyDataMng.instance() pos_infos = hwy_data.get_pos_infos(self.road_code, self.road_point, self.updown, self.facilcls, self.inout) return pos_infos
def _make_temp_add_info_no_toll(self): self.pg.connect1() hwy_data = HwyDataMng.instance() for facility_id, facil_info in hwy_data.get_no_toll_facil_infos(): ic_info_no_toll = HwyICInfoNoToll(facility_id, facil_info) ic_info_no_toll.get_path_info() ic_info_no_toll.set_node_add_info() self.__insert_temp_add_info(ic_info_no_toll, IC_DEFAULT_VAL) self.pg.commit1()
def _make_main_link_mapping(self): hwy_data = HwyDataMng.instance() data = self.__get_main_path() self.pg.connect1() for info in data: road_code = info[0] updown = info[1] node_lid = info[2] link_lid = info[3] dispcls = info[4] min_ic_nos = info[5] # 点上的最小设施号 max_ic_nos = info[6] # 点上的最大设施号 cycle_flag = info[7] tile_ids = info[8] road_kind = hwy_data.get_road_kind(road_code, updown) road_no = hwy_data.get_road_no(road_code) backward_ic = None # 后方 forward_ic = None # 前方 section_maps = [] # 上个设施到下个设施之间的link road_maps = [] # 整条道路的Link for node, link, displayclass, min_ic, max_ic, tile_id in \ zip(node_lid, link_lid, dispcls, min_ic_nos, max_ic_nos, tile_ids): tile_id = convert_tile_id(tile_id) # 14层tile转成高层tile if min_ic and section_maps and not backward_ic: self.log.error('在第一个设施后方有本线link. roadcode=%s' % road_code) if min_ic and backward_ic: # 环形的最后一个设施(JCT OUT)到第一个设施(JCT IN), 之间的Link, 不收录 # 因为,后面的IC link会收录。 if cycle_flag and node == node_lid[0]: # print road_code, len(section_maps) section_maps = [] break forward_ic = min_ic link_map = HwyLinkMapping(road_kind, 1, road_no, displayclass, link, None, backward_ic, PATH_TYPE_MAIN, tile_id) section_maps.append(link_map) for link_map in section_maps: link_map.forward_ic_no = forward_ic road_maps.append(link_map) section_maps = [] if max_ic: backward_ic = max_ic else: print 'Error' continue if max_ic: backward_ic = max_ic if link: link_map = HwyLinkMapping(road_kind, 1, road_no, displayclass, link, None, backward_ic, PATH_TYPE_MAIN, tile_id) section_maps.append(link_map) self.__insert_mapping(road_maps) self.pg.commit1()
def _make_ic_link_mapping(self): '''Ramp, SAPA, JCT Link的mapping''' self.log.info('Start Make IC Link Mapping.') self.__make_ic_link_temp_mapping() self.pg.connect1() hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() data = self.__get_forward_backward_ic() for fb_info in data: link_id = fb_info[0] bwd_ic_nos = fb_info[1] fwd_ic_nos = fb_info[2] bwd_node_ids = fb_info[3] fwd_node_ids = fb_info[4] displayclass = fb_info[5] tile_id = convert_tile_id(fb_info[6]) self.link_type = fb_info[7] self.link_id = link_id if not bwd_ic_nos and not fwd_ic_nos: #self.log.error('1. No Backward/Forward IC for link=%s' # % link_id) continue #print link_id bwd_ic_list, bwd_facil_list = self._get_ic_facils( bwd_ic_nos, bwd_node_ids) fwd_ic_list, fwd_facil_list = self._get_ic_facils( fwd_ic_nos, fwd_node_ids) road_code, updown = self.__get_ic_link_road_code( bwd_facil_list, fwd_facil_list) if road_code: road_no = hwy_data.get_road_no(road_code) road_kind = hwy_data.get_road_kind(road_code, updown) else: road_no = INVALID_ROAD_NO road_kind = ROAD_ATTR_NONE bwd_ics, fwd_ics = self.__get_ic_link_fb_ic( bwd_ic_list, fwd_ic_list) if not bwd_ics and not fwd_ics: self.log.error('2. No Backward/Forward IC for link=%s' % link_id) continue link_maps = [] for bwd_ic, fwd_ic in zip(bwd_ics, fwd_ics): # 前后设施都为空——通常是无料区间 if not bwd_ic and not fwd_ic: self.log.error('3. No Backward/Forward IC for link=%s' % link_id) continue link_map = HwyLinkMapping(road_kind, len(bwd_ics), road_no, displayclass, link_id, fwd_ic, bwd_ic, PATH_TYPE_IC, tile_id) link_maps.append(link_map) self._insert_mapping(link_maps) self.pg.commit1()
def _get_link_tile_id(self, node_id, link_id, tile_id_14): if tile_id_14: return convert_tile_id(tile_id_14) hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() if node_id not in G: return None tile_id_14 = G.get_out_link_tile(node_id, link_id) if not tile_id_14: tile_id_14 = G.get_in_link_tile(node_id, link_id) return convert_tile_id(tile_id_14)
def _get_out_link(self, node_id): out_link_id = None hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() out_linkids = G.get_outlinkids(node_id) if out_linkids: if len(out_linkids) > 1: self.log.error('OutLink Number > 1. node_id=%s' % node_id) else: out_link_id = out_linkids[0] return out_link_id
def _exist_same_jct(self): '''当前JCT存在并列的JCT设施''' jct_num = 0 hwy_data = HwyDataMng.instance() facil_infos = hwy_data.get_hwy_facils_by_nodeid(self.node_id) for facil_info in facil_infos: if facil_info.facilcls == IC_TYPE_JCT: jct_num += 1 if jct_num > 1: return True else: return False
def cal_path(self): hwy_data = HwyDataMng.instance() target_facils = self.get_target_facils() pathes = [] if target_facils: for target in target_facils: target_node = target.node_id hwy_data.load_link_by_expand_box(self.G, self.node_id, target_node) pathes = self.G.all_paths_sapa(self.node_id, target_node) # 删除本线删路径 pathes = self._delete_same_roadcode_path( pathes, self.road_code) self._add_path(pathes, target, 'SAPA') hwy_data = HwyDataMng.instance() hwy_graph = hwy_data.get_graph() # 目标点落在高速上 if target_node in hwy_graph: print('Target SAPA is on HWY. node_id=%s,name=%s' % (target_node, target.facil_name)) else: print 'No target node, node_id=%s' % self.node_id
def cal_path(self): target_facils = self.get_target_facils() hwy_data = HwyDataMng.instance() for target in target_facils: target_node = target.node_id hwy_data.load_link_by_expand_box(self.G, self.node_id, target_node) pathes = [] if self.node_id != target_node: pathes = self.G.all_paths_ic_in(self.node_id, target_node) else: print 'node_id == target_node. node_id=%s' % self.node_id for path in pathes: self._add_path([path], target, 'IC')
def cal_uturn_path(self): hwy_data = HwyDataMng.instance() # 取得对面的设施 opp_facils = hwy_data.get_hwy_opposite_in_facils(self.road_code, self.road_point, self.updown) for opposite_facil in opp_facils: pathes = self.G.all_paths_uturn(self.node_id, opposite_facil.node_id) if pathes: # 求link最短的路径 pathes = sorted(pathes, key=len) self._add_path(pathes[0:1], opposite_facil, 'UTURN')
def get_ic_list(self, road_code, updown, node_list, cycle_flag): hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() ic_group = [] # 一个点上的所有设施做为一个元素 for node_idx in range(0, len(node_list)): node_id = node_list[node_idx] if node_idx == 0 or node_idx == len(node_list) - 1: # 起末点,不做边界点 boundary_flag = False else: # 判断第十层Tile边界 boundary_flag = self.is_hwy_tile_boundary(node_id, road_code) if boundary_flag: boundary_facil_info = HwyFacilInfo(road_code, HWY_INVALID_FACIL_ID, IC_TYPE_INVALID, updown, node_id, INOUT_TYPE_NONE, '(Tile境界)') boundary_facil_info.boundary_flag = boundary_flag toll_flag = G.is_toll(node_id) if G.is_hwy_node(node_id) or toll_flag: in_out = G.get_inout_type(node_id) if in_out == INOUT_TYPE_OUT and boundary_flag: # 出口时,边界点放在施设前面 # 边界单独成一组,没和同点的其他设施一起 ic_group.append([boundary_facil_info]) if toll_flag: # 同时也又有收费站 self.log.error('Exist Out Facil and Toll.') # get facilities of this node facil_infos = hwy_data.get_hwy_facils_by_nodeid(node_id) # 对当前点的多个设施进行排序 facil_infos = self._sort_facils(facil_infos) ic_group.append(facil_infos) if ((in_out != INOUT_TYPE_OUT or toll_flag ) # 入口、收费站时,边界点放在施设后面 and boundary_flag): # 边界单独成一组,没和同点的其他设施一起 ic_group.append([boundary_facil_info]) elif boundary_flag: # 边界 ic_group.append([boundary_facil_info]) ic_list = [] # ## 重排头尾设施 # 第一个设施(同个点上可能有多个) ic_list += self._sort_start_facils(ic_group[0], cycle_flag) # 最后一个设施(同个点上可能有多个) ic_group[-1] = self._sort_end_facils(ic_group[-1], cycle_flag) for ic_group_idx in range(1, len(ic_group) - 1): # 依据前后设施给同个点上的设施再排序(就近原则) ic_list += self._sort_facils_by_fb(ic_group, ic_list, ic_group_idx) ic_list += ic_group[-1] return ic_list
def _get_toll_tile_id(self, toll_nodes): tile_ids = set() hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() for nodeid in toll_nodes: out_tiles = G.get_out_tile(nodeid) if len(out_tiles) > 1: self.log.warning('Out Tile > 1. toll_node_id=%s' % nodeid) for tile_id_14 in out_tiles: tile_id = convert_tile_id(tile_id_14) tile_ids.add(tile_id) tile_ids = list(tile_ids) tile_ids.sort() return tile_ids
def _is_on_no_toll_main_link(self, node_id): '''点在无料区间本线上。''' hwy_data = HwyDataMng.instance() no_toll_G = hwy_data.get_graph_no_toll() # 无料区间 if node_id not in no_toll_G: return False # inlink是有料高速本线 for parent, node, data in no_toll_G.in_edges_iter(node_id, True): if data.get('road_code') > ROAD_CODE_NO_TOLL: return True for parent, node, data in no_toll_G.out_edges_iter(node_id, True): if data.get('road_code') > ROAD_CODE_NO_TOLL: return True return False
def get_ic_list(self, road_code, updown, node_list, boundary_flag_list, cycle_flag): hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() ic_group = [] # 一个点上的所有设施做为一个元素 for node_idx in range(0, len(node_list)): node_id = node_list[node_idx] if (not cycle_flag and (node_idx == 0 or node_idx == len(node_list))): # 非环形的起末点,不做边界点 boundary_flag = False else: b_flag = boundary_flag_list[node_idx] boundary_flag = self.is_hwy_tile_boundary( node_id, road_code, b_flag) if boundary_flag: boundary_facil_info = HwyFacilInfo(road_code, HWY_INVALID_FACIL_ID, IC_TYPE_INVALID, updown, node_id, INOUT_TYPE_NONE, '(Tile境界)') boundary_facil_info.boundary_flag = boundary_flag toll_flag = G.is_toll(node_id) if G.is_hwy_node(node_id) or toll_flag: in_out = G.get_inout_type(node_id) # 出口时,边界点放在施设前面 if (in_out == INOUT_TYPE_OUT) and boundary_flag: ic_group.append([boundary_facil_info]) # get facilities of this node facil_infos = hwy_data.get_hwy_facils_by_nodeid(node_id) # 对当前点的多个设施进行排序 facil_infos = self._sort_facils(facil_infos) ic_group.append(facil_infos) # 入口时,边界点放在施设后面 if (in_out == INOUT_TYPE_IN or toll_flag) and boundary_flag: ic_group.append([boundary_facil_info]) elif boundary_flag: # 边界 ic_group.append([boundary_facil_info]) ic_list = [] # ## 重排头尾设施 # 第一个设施(同个点上可能有多个) ic_list += self._sort_start_facils(ic_group[0], cycle_flag) # 最后一个设施(同个点上可能有多个) ic_group[-1] = self._sort_end_facils(ic_group[-1], cycle_flag) for ic_group_idx in range(1, len(ic_group) - 1): # 依据前后设施给同个点上的设施再排序(就近原则) ic_list += self._sort_facils_by_fb(ic_group, ic_list, ic_group_idx) ic_list += ic_group[-1] return ic_list
def _Do(self): self.CreateTable2('mid_hwy_main_link_path') data = self.__get_data() hwy_data = HwyDataMng.instance() G = hwy_data.get_graph() self.pg.connect1() import networkx as nx for hwy_info in data: road_code = hwy_info[0] updown = hwy_info[1] nodes = hwy_info[2] linecls = hwy_info[3] max_roadpoint = hwy_info[4][-1] # 通过当前road_code任取一点,求整条Highway路径 path = [] for node in nodes: try: path = G.dfs_path(node, road_code) except nx.NetworkXError: continue if path: break for node in nodes: if node not in G: continue if node not in path: self.log.warning('Node=%s not in path.' 'roadcode=%s,updown=%s' % (node, road_code, updown)) cycle_flag = self._is_cycle(path) # 环线 if cycle_flag: if not self.adjust_path_for_cycle(road_code, updown, path): self.log.error('Move start Facility to first Failed.' 'roadcode=%s, updown=%s' % (road_code, updown)) for node_cnt in xrange(0, len(path)): if node_cnt > 0: linkid = G.get_linkid(path[node_cnt - 1], path[node_cnt]) else: linkid = None self.__insert_path( (road_code, updown, path[node_cnt], linkid, node_cnt, int(cycle_flag), linecls)) self.pg.commit1() self.CreateIndex2('mid_hwy_main_link_path_link_id_idx') self.CreateIndex2('mid_hwy_main_link_path_node_id_idx') return 0
def _is_unique_toll(self, toll_facil): '''本线料金所番号是唯一的''' hwy_data = HwyDataMng.instance() # 对侧有相同番号的料金所 updown = toll_facil.updown ^ UPDOWN_TYPE_COMMON facils = hwy_data.get_hwy_facils(toll_facil.road_code, toll_facil.road_point, updown, INOUT_TYPE_NONE) if facils: return False # 同侧相同番号的料金所 facils = hwy_data.get_hwy_facils(toll_facil.road_code, toll_facil.road_point, toll_facil.updown, INOUT_TYPE_NONE) if facils: if len(facils) == 1: return True return False