In [1]:
# ecoding = utf8
import networkx as nx
import pandas as pd
import re
from operator import itemgetter, attrgetter
import matplotlib.pyplot as plt
from collections import defaultdict
import itertools
import numpy as np
import random
import functools

from tools import *
db = MySql(db='LOCAL', db_name='ezhouhub')
DOC_DICT = {
    'sf_eq': "E:\\sf-doc\\鄂州机场项目\E\\方案设备数据\\i_equipment_name_rule.xlsx",
    'self_eq': "D:\doc\sf-doc\doc.sf\ezhouhub\equipmnet_param\新版设备命名规则20171115.xlsx",
    'path': "D:\\Git\\git.jupyter\\jupyter_app\\ipython\\py36_erzhou_input\\data\\path\\"
}

In [4]:
queue_io_df = pd.read_sql_table(table_name='i_queue_io_default', 
                                con=db.sql_con, 
                                columns=['equipment_port_last', 
                                         'equipment_port_next', 
                                         'equipment_type', 
                                         'queue_id', 'parcel_type', 'src_type', 'dest_type'])
# -----------Get Queue Data--------------------

all_queue_data = queue_io_df
small_queue_data = queue_io_df.loc[queue_io_df.parcel_type.isin(['small']),:]
parcel_queue_data = queue_io_df.loc[queue_io_df.parcel_type.isin(['parcel']),:]
# -----------Digraph and Nodes Generate--------
di_graph = nx.DiGraph()


d:\pythonenv\py36_ai_env\lib\site-packages\pymysql\cursors.py:166: Warning: (1366, "Incorrect string value: '\\xD6\\xD0\\xB9\\xFA\\xB1\\xEA...' for column 'VARIABLE_VALUE' at row 480")
  result = self._query(query)

ALL Nodes Views


In [3]:
all_graphs = nx.from_pandas_dataframe(df=queue_io_df, 
                                      source='equipment_port_last', 
                                      target='equipment_port_next',
                                      create_using=di_graph)

all_nodes = list({x for x in map(lambda x : re.split(pattern=r'[0-9]', string=x)[0], all_graphs.nodes())})
print(f"all_nodes length:{len(all_nodes)}\n{sorted(all_nodes, key=itemgetter(0,-1))}")


all_nodes length:24
['ai', 'cdb', 'cdm', 'crm', 'cim', 'cip', 'crp', 'cdp', 'cis', 'cds', 'gi', 'idm', 'iim', 'irm', 'iip', 'irp', 'idp', 'irs', 'iis', 'ids', 'ud', 'ui', 'ur', 'x']

Small Nodes Views


In [4]:
small_graphs = nx.from_pandas_dataframe(df=small_queue_data, 
                                        source='equipment_port_last', 
                                        target='equipment_port_next', 
                                        create_using=di_graph)
small_nodes = list({x for x in map(lambda x : re.split(pattern=r'[0-9]', string=x)[0], small_graphs.nodes())})
print(f"small_nodes length:{len(small_nodes)}\n{sorted(small_nodes, key=itemgetter(0,-1))}")


small_nodes length:13
['cdb', 'crm', 'cdm', 'cim', 'cip', 'gi', 'idm', 'iim', 'irm', 'ud', 'ui', 'ur', 'x']

Parcel Nodes Views


In [5]:
parcel_graphs = nx.from_pandas_dataframe(df=parcel_queue_data, 
                                        source='equipment_port_last', 
                                        target='equipment_port_next', 
                                        create_using=di_graph)
parcel_nodes = list({x for x in map(lambda x : re.split(pattern=r'[0-9]', string=x)[0], parcel_graphs.nodes())})
print(f"parcel_nodes lenght:{len(parcel_nodes)}\n{sorted(parcel_nodes, key=itemgetter(0,-1))}")


parcel_nodes lenght:14
['ai', 'cip', 'crp', 'cdp', 'cds', 'cis', 'gi', 'idp', 'iip', 'irp', 'ids', 'iis', 'irs', 'x']

Erro Data Repair Parcel_Type = Small

  • Small Reg

In [6]:
def _one_map_reg(df, col, reg):   
    return df[col].map(lambda x : True if reg.search(x)is not None else False)


def reg_map(df, colums, reg):
    if len(colums):
        filter_list = _one_map_reg(df, colums[0], reg)
        for col in colums[1:]:
            filter_list = filter_list | _one_map_reg(df, col, reg)
    return filter_list


reg_nodes = ['equipment_port_next']

In [7]:
# 小件预分拣滑槽
reg_spc = re.compile("^c[idr]b\w*") #['cib', 'crb', 'cdb']
# 小件终分拣滑槽
reg_ssc = re.compile("^c[idr]m\w*")
# 小件导入台
reg_u = re.compile("^u[idr]\w*")
# 小件终分拣导入口
reg_im = re.compile("i[idr]m\w*")
# 小件内部汇流点 30-45 16个国内小件初分拣至终分拣汇流点
# ------------------------------------------------------------!!!应将cdb1-cdb16 换成cdm1-cdm16 链接至x68-x83----!!!
# x68-x83 小件终分拣滑槽至16个汇流点. queue_io 表中错误将cdb1-cdb16的4800个出口链接到x68-x83
reg_x = re.compile("^x(3[0-9]|4[0-5])$")
# ---------------------------------------------------------------小件分拣机外围的x点---------------------------------
# 海关入口至国内拆包台汇流点 gi1-gi10 -> x20-x29 -> ud1-ud10
# 国际小件滑槽至国际预分入口汇流点  cim1->x46->iip7_10
# 路侧小件滑槽至路侧预分拣入口汇流点  crm->x57->irp
# ----------------------------------------------------------错误!!!!------------------
# queue 内存在异常边界:(cip3_23, x3), (cip3_24, x3) 国际预分拣滑槽流至x3,导致小件分拣条数多2条
#       正确的路径为:国际预分拣滑槽至国际终分拣导入 应全部由x1链接 cip-> x1->iis-------------!!!!!

reg_x_out = re.compile("^x(3|2[0-9]|46|57|6[8-9]|7[0-9]|8[0-3])$")
# --------------------------------------------------all small queue---------------
all_small_reg = (reg_map(all_queue_data, reg_nodes, reg_spc) |
                 reg_map(all_queue_data, reg_nodes, reg_ssc) |
                 reg_map(all_queue_data, reg_nodes, reg_u) |
                 reg_map(all_queue_data, reg_nodes, reg_x) |
                 reg_map(all_queue_data, reg_nodes, reg_im) | 
                 reg_map(all_queue_data, reg_nodes, reg_x_out))
queue_io_small_sample = all_queue_data.loc[all_small_reg, :]
queue_io_small_sample.index.size


Out[7]:
242714
  • Parcel Reg

In [8]:
# parcel unload
unload_node_col = ['equipment_port_last']
reg_unload = re.compile("^(a[id]|r)\w*") #['ai', 'ad 'r']
# parcel primary input
reg_parcel_primary_i = re.compile("^i[idr]p\w*")
# parcel primary output c
reg_parcel_primary_c = re.compile("^c[idr]p\w*")
# parcel secondary input
reg_parcel_secondary_i = re.compile("^i[idr]s\w*")
# parcel secondary output
# ----------------------------------------------------!!!!错误---路侧的终分拣滑槽错误的弄成cis, 应为crs
reg_parcel_secondary_c = re.compile("^c[idr]s\w*")
# parcel custom
reg_custom = re.compile("^g[ie]\w*")
# parcel cross ---------------------------------------!!!!错误cip-> (x1-x10) ->iis  应该为cip->x1->iis
#                                                             剔除x3的行数,少算2行数据:cip3_23->x3, cip3_24->x3
reg_parcel_cross = re.compile("^x([1-24-9]|1[0-9]|4[7-9]|5[0-6])$")

all_aprcel_reg = (reg_map(all_queue_data, reg_nodes, reg_parcel_primary_i)|
                  reg_map(all_queue_data, reg_nodes, reg_parcel_primary_c)|
                  reg_map(all_queue_data, reg_nodes, reg_parcel_secondary_i)|
                  reg_map(all_queue_data, reg_nodes, reg_parcel_secondary_c)|
                  reg_map(all_queue_data, reg_nodes, reg_custom)|
                  reg_map(all_queue_data, reg_nodes, reg_parcel_cross))

queue_io_parcel_sample = all_queue_data.loc[all_aprcel_reg, :]
queue_io_parcel_sample.index.size
# (queue_io_parcel_sample.loc[queue_io_parcel_sample.equipment_port_next.str.startswith('x'),:].index.size,
# set(queue_io_parcel_sample.loc[queue_io_parcel_sample.equipment_port_next.str.startswith('x'),:
#                              ].equipment_port_last.apply(lambda x : re.split(pattern=r'[0-9]', string=x)[0])))


Out[8]:
38921

修复错误数据


In [9]:
repair_queue_io_data = all_queue_data.copy()
# #---------------------------------------小件cdm 错误的搞成 cdb-------------------------
reg_err_cdb_cdm = re.compile("^x(6[8-9]|7[0-9]|8[0-3])$")
repair_queue_io_data.loc[reg_map(repair_queue_io_data, reg_nodes, reg_err_cdb_cdm), ['equipment_port_last']] = repair_queue_io_data.loc[
    reg_map(repair_queue_io_data, reg_nodes, reg_err_cdb_cdm), ['equipment_port_last']].equipment_port_last.str.replace('cdb', 'cdm')
# #---------------------------------------将cip-x的节点全部替换为x1----------------------
_reg_cip_x_filter = re.compile("^cip\w*")
_reg_cip_x = reg_map(repair_queue_io_data, ['equipment_port_last'], _reg_cip_x_filter) & repair_queue_io_data.equipment_type.isin(['x'])
repair_queue_io_data.loc[_reg_cip_x, ['equipment_port_next']] = 'x1'
# #--------------------------------------将x-iis的所有x节点替换为x1----------------------
_reg_err_x1_iis_filter = re.compile("^iis\w*")
_reg_err_x1_iis = reg_map(repair_queue_io_data, ['equipment_port_next'], _reg_err_x1_iis_filter)
# 修改x-iis 的点
repair_queue_io_data.loc[_reg_err_x1_iis, ['equipment_port_last']] = 'x1'
# 修改队列id
repair_queue_io_data.loc[_reg_err_x1_iis, ['queue_id']] = repair_queue_io_data.loc[
    _reg_err_x1_iis, :].queue_id.str.replace(re.compile("x(10|[0-9])"), "x1")
# #--------------------------------------将gi-x[47,48,49,50,51]-irs汇流点全部换成 x47----------
_reg_err_gi_x_filter = re.compile("^x(4[7-9]|5[0-1])$")
_reg_err_gi_x = reg_map(repair_queue_io_data, ['equipment_port_next'], _reg_err_gi_x_filter)
# gi-x替换47-51 为 47
repair_queue_io_data.loc[_reg_err_gi_x, ['equipment_port_next']] = 'x47'
# x-irs 替换47-51 为 47
_reg_err_x_irs_filter = re.compile("^x(4[7-9]|5[0-1])$")
_reg_err_x_irs = reg_map(repair_queue_io_data, ['equipment_port_last'], _reg_err_x_irs_filter)
repair_queue_io_data.loc[_reg_err_x_irs, ['equipment_port_last']] = 'x47'
# #--------------------------------------将irs至crs错误弄成cis的 换成crs-----------------
_reg_err_iis_crs_filter = re.compile("^irs\w*")
_reg_err_iis_crs = reg_map(repair_queue_io_data, ['equipment_port_last'], _reg_err_iis_crs_filter)
repair_queue_io_data.loc[_reg_err_iis_crs, ['equipment_port_next']] = repair_queue_io_data.loc[
    _reg_err_iis_crs, :].equipment_port_next.str.replace('cis', 'crs')

# df_to_pickle(df=repair_queue_io_data, path_file=DOC_DICT['path'], file_name='i_queue_io.pkl')
# repair_queue_io_data.loc[_reg_err_x_irs, :] #.queue_id #.str.replace(re.compile("x(4[7-9]|5[0-1])"), "x47")

In [11]:
repair_queue_io_data.loc[_reg_err_iis_crs, :].tail(2) #.equipment_port_next.apply(lambda x: x[0:4]).tolist()


Out[11]:
equipment_port_last equipment_port_next equipment_type queue_id parcel_type src_type dest_type
265098 irs5_9 crs5_8 c irs5_cis5 parcel R R
265099 irs5_9 crs5_9 c irs5_cis5 parcel R R

In [15]:
re_all_graphs = nx.from_pandas_dataframe(df=repair_queue_io_data, 
                                         source='equipment_port_last', 
                                         target='equipment_port_next',
                                         create_using=di_graph)
# #---------------------------------parcel 基础路由规划-------------------
# ----------------------------剔除:{u, c[idr]b, x, i[idr]m}--------------
# u nodes
small_u_nodes = [i for i in re_all_graphs.nodes() if reg_u.search(i) is not None]
# x30-x45 nodes
small_inner_x_nodes = [i for i in re_all_graphs.nodes() if reg_x.search(i) is not None]
# c[idr]b nodes
small_presort_c_nodes = [i for i in re_all_graphs.nodes() if reg_spc.search(i) is not None]
# i[idr]m nodes
small_secondary_i_nodes = [i for i in re_all_graphs.nodes() if reg_im.search(i) is not None]
# ---------------------------卸货区, 装货区nodes ------------------------
unload_nodes = [i for i in re_all_graphs.nodes() if reg_unload.search(i) is not None]
reload_nodes = [i for i in re_all_graphs.nodes() if reg_parcel_secondary_c.search(i) is not None]

base_graphs = re_all_graphs.subgraph(
list(set(re_all_graphs.nodes())-
     set(small_u_nodes)-
     set(small_presort_c_nodes)-
     set(small_inner_x_nodes)-
     set(small_secondary_i_nodes)))
base_graph_nodes = list({x for x in map(lambda x : re.split(pattern=r'[0-9]', string=x)[0], base_graphs.nodes())})
print(f"parcel nodes: {len(base_graphs.nodes())}")
print(f"base_graph_nodes lenght:{len(base_graph_nodes)}\n{sorted(base_graph_nodes, key=itemgetter(0,-1))}")


parcel nodes: 9570
base_graph_nodes lenght:18
['ai', 'crm', 'cdm', 'cim', 'cip', 'crp', 'cdp', 'crs', 'cds', 'cis', 'gi', 'idp', 'iip', 'irp', 'ids', 'iis', 'irs', 'x']

In [16]:
base_paths = get_all_simple_paths(base_graphs, unload_nodes, reload_nodes)
# ------------------ai-crs---------------------------------------------------
ai_nodes_str = 'ai'+str(random.randint(1,7))+'_'+ str(random.randint(1,36))
crs_nodes_str = 'crs'+str(random.randint(1,5))+'_'+str(random.randint(1,50))
# ------------------ai-cis---------------------------------------------------
cis_nodes_str = 'cis'+str(random.randint(1,13))+'_'+str(random.randint(1,56))
# ------------------ai-cds---------------------------------------------------
cds_nodes_str = 'cds'+str(random.randint(1,16))+'_'+str(random.randint(1,56))
#  ========================================= path ==============================
path_data = defaultdict(list)
path_key_value = (ai_nodes_str, cis_nodes_str)
path_data[path_key_value]=list(get_key_path(base_paths, path_key_value))
path_key_value, path_data[path_key_value]


Out[16]:
(('ai3_21', 'cis5_23'),
 [['ai3_21', 'iip4_7', 'cip4_23', 'x1', 'iis5_1_8', 'cis5_23'],
  ['ai3_21', 'iip4_7', 'cip4_23', 'x1', 'iis5_2_8', 'cis5_23'],
  ['ai3_21', 'iip4_7', 'cip4_24', 'x1', 'iis5_1_8', 'cis5_23'],
  ['ai3_21', 'iip4_7', 'cip4_24', 'x1', 'iis5_2_8', 'cis5_23']])

small-path

  • small: 小件1路由-分发路由 ai-(ui, ur, ud)

In [42]:
all_small_nodes = get_nodes(re_all_graphs.nodes(), small_reg())

In [305]:
small_first_exclude_nodes = {'cdb_reg': re.compile("^cdb\w*"), 
                             'im_reg': re.compile("^i[idr]m\w*"), 
                             'cm_reg': re.compile("^c[idr]m\w*"),
                             'cs_reg': re.compile("^c[idr]s\w*")}

exclude_node = get_nodes(re_all_graphs.nodes(), small_first_exclude_nodes)
# # 全局 节点
small_fir_sub_nodes = [set(re_all_graphs.nodes()), ]
small_fir_sub_nodes.extend(list(exclude_node.values()))
# 剔除节点
first_small_nodes = reduce_node(small_fir_sub_nodes, 'diff')
small_first_graphs = re_all_graphs.subgraph(list(first_small_nodes))

In [485]:
# 
start_chut_type = 'a'
end_chut_type = 'u'
# 
start_area_type = 'i'
end_area_type = 'i'
# node reg
reg_small_one_start = re.compile(_base_node_reg(start_chut_type, start_area_type,))
reg_small_one_end = re.compile(_base_node_reg(end_chut_type,end_area_type, ))
# start nodes
small_one_start_nodes = get_reg_node(re_all_graphs.nodes(), reg_small_one_start)
small_one_end_nodes = get_reg_node(re_all_graphs.nodes(), reg_small_one_end)

# 输出路径 
small_one_paths = []
small_one_paths = get_all_simple_paths(small_first_graphs, small_one_start_nodes, small_one_end_nodes)
# # 输出测试结果
nodes_pair_test(small_one_paths, small_one_start_nodes, small_one_end_nodes)


总计输入节点:252, 总计截止节点:6
总计输入截止对数:1512
随机选取节点:('ai7_10', 'ui2_2_1'), 随机选取节点路由数:2
ai7_10->iip10_4->cip10_21->ui2_2_1
ai7_10->iip10_4->cip10_22->ui2_2_1
nodes<('ai7_10', 'ui2_2_1')> random path: ['ai7_10', 'iip10_4', 'cip10_22', 'ui2_2_1']
Out[485]:
'ui2_2_1'
  • small: 小件2路由 ud-cdb-idm-cdm, (若有国内到达:需要规划ud-cdb-ge口的国际小件), u[ir]-i[ir]m-c[ir]m

In [ ]:

  • small: 小件3路由 cim-cis, cdm-cds, crm-crs

small-thr-paths


In [484]:
# small-3-paths
start_thr_chut_type = 'c'
mid_thr_type = 'i'
end_thr_chut_type = 'c'

start_area_type = 'd'
mid_aera_type = 'd'
end_area_type = 'd'

start_c_thr_name = 'm'
mid_thr_in_name = 's'
end_thr_chut_name = 's'
# node reg
reg_small_thr_start = re.compile(_base_node_reg(start_thr_chut_type, start_area_type, start_c_thr_name))
reg_small_thr_mid = re.compile(_base_node_reg(mid_thr_type, mid_aera_type, mid_thr_in_name))
reg_small_thr_end = re.compile(_base_node_reg(end_thr_chut_type,end_area_type, end_thr_chut_name))
# start and end nodes
small_thr_start_nodes = get_reg_node(re_all_graphs.nodes(), reg_small_thr_start)
small_thr_end_nodes = get_reg_node(re_all_graphs.nodes(), reg_small_thr_end)

random_end_machine = random.choice(small_thr_end_nodes)
random_mid_machine_id = random_end_machine.split(r'_')[0].replace('c', 'i')

reg_str_mid_machine = f"^{random_mid_machine_id}_\w*"
reg_mid_machine = re.compile(reg_str_mid_machine)


small_thr_mid_nodes = get_reg_node(re_all_graphs.nodes(), reg_mid_machine)

# exclude nodes
small_thr_exclude_nodes = {'a_reg': re.compile("^(a[id]r)\w*"), 
                             'g_reg': re.compile("^g[ie]\w*"), 
                             'j_reg': re.compile("^j[id]\w*"),
                             'u_reg': re.compile("^u[idr]\w*"), 
                             'cdb': re.compile("^cdb\w*"), 
                             'im': re.compile("i[idr]m\w*")}

thr_exclude_node = get_nodes(re_all_graphs.nodes(), small_thr_exclude_nodes)
# # 全局 节点
small_thr_sub_nodes = [set(re_all_graphs.nodes()), ]
small_thr_sub_nodes.extend(list(thr_exclude_node.values()))
# 剔除节点
thr_small_nodes = reduce_node(small_thr_sub_nodes, 'diff')
small_thr_graphs = re_all_graphs.subgraph(list(thr_small_nodes))

# 输出路径 
small_thr_paths = []
small_thr_paths = get_all_simple_paths(small_thr_graphs, small_thr_start_nodes, small_thr_mid_nodes)
small_four_paths = get_all_simple_paths(small_thr_graphs, small_thr_mid_nodes, small_thr_end_nodes)
# 输出测试结果
end_nodes = nodes_pair_test(small_thr_paths, small_thr_start_nodes, small_thr_mid_nodes)
# 
nodes_pair_test(small_four_paths, [end_nodes], [random_end_machine])


总计输入节点:4800, 总计截止节点:16
总计输入截止对数:76800
随机选取节点:('cdm14_191', 'ids5_2_4'), 随机选取节点路由数:1
cdm14_191->x81->idp26_2->cdp26_5->x8->ids5_2_4
nodes<('cdm14_191', 'ids5_2_4')> random path: ['cdm14_191', 'x81', 'idp26_2', 'cdp26_5', 'x8', 'ids5_2_4']
总计输入节点:1, 总计截止节点:1
总计输入截止对数:14336
随机选取节点:('ids5_2_4', 'cds5_41'), 随机选取节点路由数:1
ids5_2_4->cds5_41
nodes<('ids5_2_4', 'cds5_41')> random path: ['ids5_2_4', 'cds5_41']
Out[484]:
'cds5_41'

In [480]:



总计输入节点:4800, 总计截止节点:16
总计输入截止对数:76800
随机选取节点:('cdm12_85', 'ids4_1_8'), 随机选取节点路由数:1
cdm12_85->x79->idp19_2->cdp19_4->x7->ids4_1_8
nodes<('cdm12_85', 'ids4_1_8')> random path: ['cdm12_85', 'x79', 'idp19_2', 'cdp19_4', 'x7', 'ids4_1_8']
总计输入节点:1, 总计截止节点:1
总计输入截止对数:14336
随机选取节点:('ids4_1_8', 'cds4_37'), 随机选取节点路由数:1
ids4_1_8->cds4_37
nodes<('ids4_1_8', 'cds4_37')> random path: ['ids4_1_8', 'cds4_37']
Out[480]:
'cds4_37'

small fourth paths


In [342]:
# small-3-paths
start_thr_chut_type = 'i'
end_thr_chut_type = 'c'

start_area_type = 'd'
end_area_type = 'd'

start_c_thr_name = 's'
end_thr_chut_name = 's'
# node reg
reg_small_thr_start = re.compile(_base_node_reg(start_thr_chut_type, start_area_type, start_c_thr_name))
reg_small_thr_end = re.compile(_base_node_reg(end_thr_chut_type,end_area_type, end_thr_chut_name))
# start and end nodes
small_thr_start_nodes = get_reg_node(re_all_graphs.nodes(), reg_small_thr_start)
small_thr_end_nodes = get_reg_node(re_all_graphs.nodes(), reg_small_thr_end)

# exclude nodes
small_thr_exclude_nodes = {'a_reg': re.compile("^(a[id]r)\w*"), 
                             'g_reg': re.compile("^g[ie]\w*"), 
                             'j_reg': re.compile("^j[id]\w*"),
                             'u_reg': re.compile("^u[idr]\w*"), 
                             'cdb': re.compile("^cdb\w*"), 
                             'im': re.compile("i[idr]m\w*")}

thr_exclude_node = get_nodes(re_all_graphs.nodes(), small_thr_exclude_nodes)
# # 全局 节点
small_thr_sub_nodes = [set(re_all_graphs.nodes()), ]
small_thr_sub_nodes.extend(list(thr_exclude_node.values()))
# 剔除节点
thr_small_nodes = reduce_node(small_thr_sub_nodes, 'diff')
small_thr_graphs = re_all_graphs.subgraph(list(thr_small_nodes))

# 输出路径 
small_thr_paths = []
small_thr_paths = get_all_simple_paths(small_thr_graphs, small_thr_start_nodes, small_thr_end_nodes)
# # 输出测试结果
end_nodes = nodes_pair_test(small_thr_paths, small_thr_start_nodes, small_thr_end_nodes)
# small 4 path start nodes
print(f"下一路由起始点: {end_nodes}")


总计输入节点:256, 总计截止节点:896
总计输入截止对数:229376
随机选取节点:('ids11_1_4', 'cds7_39'), 随机选取节点路由数:0
下一路由起始点: None

In [193]:
# 生成随机节点
random_start_node = random_node_gen(machine_name=f'c{area_type}m', 
                                    machine_num=start_machine_num, 
                                    cell_num=start_cell_num, 
                                    one_cell_port_num=start_one_cell_port_num)
random_end_node = random_node_gen(machine_name=f'c{area_type}s', 
                                  machine_num=end_machine_num, 
                                  cell_num=end_cell_num, 
                                  one_cell_port_num=end_one_cell_port_num)
#  ========================================= path ==============================
small_thr_path_data = defaultdict(list)
path_key_value = (random_start_node, random_end_node)
print(path_key_value)
small_thr_path_data[path_key_value]=list(small_thr_paths[path_key_value])
if small_thr_path_data[path_key_value]:
    print(f"nodes<{path_key_value}> random path: {random.choice(small_thr_path_data[path_key_value])}")


('cdm3_5', 'cds1_2_1')

In [ ]:
# ------------------cim---------------------------------------------------
cim_nodes_str = 'cim'+str(random.randint(1,1))+'_'+ str(random.randint(1,300))
# ------------------cdm---------------------------------------------------
cdm_nodes_str = 'cdm'+str(random.randint(1,16))+'_'+ str(random.randint(1,300))
# ------------------crm---------------------------------------------------
crm_nodes_str = 'crm'+str(random.randint(1,1))+'_'+ str(random.randint(1,300))
# -------------------crs---------------------------------------------------
crs_nodes_str = 'crs'+str(random.randint(1,5))+'_'+str(random.randint(1,50))
# -------------------cis----------------------------------------------------
cis_nodes_str = 'cis'+str(random.randint(1,13))+'_'+str(random.randint(1,56))
# ------------------cds---------------------------------------------------
cds_nodes_str = 'cds'+str(random.randint(1,16))+'_'+str(random.randint(1,56))
#  ========================================= path ==============================
small_i_path_data = defaultdict(list)
path_key_value = (cim_nodes_str, cis_nodes_str)
# print(path_key_value)
small_i_path_data[path_key_value]=list(small_thr_paths[path_key_value])
if small_i_path_data[path_key_value]:
    print(f"nodes<{path_key_value}> random path: {random.choice(small_i_path_data[path_key_value])}")

In [20]:
# c[idr]m nodes------小件终分拣滑槽
# 国际侧小件路由:起止点

reg_small_i_c = re.compile("^cim\w*")
reg_reload_i = re.compile("^cis\w*")
# 国内侧小件路由:起止点
reg_small_d_c = re.compile("^cdm\w*")
reg_reload_d = re.compile("^cds\w*")
# 路侧小件路由:起止点
reg_small_r_c = re.compile("^crm\w*")
reg_reload_r = re.compile("^crs\w*")
# start nodes
small_secondary_ci_nodes = [i for i in re_all_graphs.nodes() if reg_small_i_c.search(i) is not None]
small_secondary_cd_nodes = [i for i in re_all_graphs.nodes() if reg_small_d_c.search(i) is not None]
small_secondary_cr_nodes = [i for i in re_all_graphs.nodes() if reg_small_r_c.search(i) is not None]
# end nodes
reload_i_nodes = [i for i in re_all_graphs.nodes() if reg_reload_i.search(i) is not None]
reload_d_nodes = [i for i in re_all_graphs.nodes() if reg_reload_d.search(i) is not None]
reload_r_nodes = [i for i in re_all_graphs.nodes() if reg_reload_r.search(i) is not None]

# i-i-small-2
small_ci_paths = get_all_simple_paths(base_graphs, small_secondary_ci_nodes, reload_i_nodes)
# d-d-small-2
small_cd_paths = get_all_simple_paths(base_graphs, small_secondary_cd_nodes, reload_d_nodes)
# r-r-small-2
small_cr_paths = get_all_simple_paths(base_graphs, small_secondary_cr_nodes, reload_r_nodes)

In [112]:
# ------------------cim---------------------------------------------------
cim_nodes_str = 'cim'+str(random.randint(1,1))+'_'+ str(random.randint(1,300))
# ------------------cdm---------------------------------------------------
cdm_nodes_str = 'cdm'+str(random.randint(1,16))+'_'+ str(random.randint(1,300))
# ------------------crm---------------------------------------------------
crm_nodes_str = 'crm'+str(random.randint(1,1))+'_'+ str(random.randint(1,300))
# -------------------crs---------------------------------------------------
crs_nodes_str = 'crs'+str(random.randint(1,5))+'_'+str(random.randint(1,50))
# -------------------cis----------------------------------------------------
cis_nodes_str = 'cis'+str(random.randint(1,13))+'_'+str(random.randint(1,56))
# ------------------cds---------------------------------------------------
cds_nodes_str = 'cds'+str(random.randint(1,16))+'_'+str(random.randint(1,56))
#  ========================================= path ==============================
small_i_path_data = defaultdict(list)
path_key_value = (cim_nodes_str, cis_nodes_str)
# print(path_key_value)
small_i_path_data[path_key_value]=list(small_thr_paths[path_key_value])
if small_i_path_data[path_key_value]:
    print(f"nodes<{path_key_value}> random path: {random.choice(small_i_path_data[path_key_value])}")

custom import


In [267]:
# gi 关口路由:起止点
reg_gi = re.compile("^gi\w*")
# small类件
reg_gi_small_dr = re.compile("u[dr]\w*")
#

In [126]:
# G = nx.from_pandas_dataframe(repair_queue_io_data.head(10), 'equipment_port_last', 'equipment_port_next', create_using=nx.DiGraph())
G = nx.DiGraph()
# node_df = pd.DataFrame(data=G.nodes())
# node_df = node_df.rename_axis(mapper={0: 'node'}, axis=1)
# node_df = node_df.node.apply(lambda x: x.split('_')[0]).to_frame()
# node_df.node.str.replace('[0-9]*?$',  '')
# sorted(node_df.loc[node_df.node.str.startswith('x'),:].node.tolist())
# nx.draw(G)
# plt.show()
ai_nodes_str, crs_nodes_str
random.randint(1,7)


Out[126]:
2

In [15]:
df_aq_type = pd.read_excel(io=DOC_DICT['self_eq'], )
df_aq_type.loc[df_aq_type.equipment_id.isin(['ui', 'ud', 'ur', 'cib']), :]


Out[15]:
设备类型 设备名称 equipment_id
5 小件拆包供件台 国际小件拆包供件台 ui
6 NaN 国内小件拆包供件台 ud
7 NaN 陆侧小件拆包供件台 ur
15 NaN 国际小件预分滑槽 cib

In [199]:
small_pc_re = re.compile("^c[idr]b\w*$")
xx = True if small_pc_re.search('cib7_8_2') is not None else False
xx


Out[199]:
True

In [33]:
a = {'a':[2,3], 'b': [3,4]}
mm = map(lambda x : x , a.values())
list(mm)


Out[33]:
[[2, 3], [3, 4]]

In [29]:
re.compile("^cip\w*")


Out[29]:
re.compile(r'^cip\w*', re.UNICODE)