@ -0,0 +1,441 @@ | |||
{ | |||
"cells": [ | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 2, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"name": "stdout", | |||
"output_type": "stream", | |||
"text": [ | |||
"41.0\n" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"time_data = \"\"\"\n", | |||
"3h\n", | |||
"0.5h\n", | |||
"3h\n", | |||
"2h\n", | |||
"2h\n", | |||
"4h\n", | |||
"3h\n", | |||
"1.5h\n", | |||
"4h\n", | |||
"3.5h\n", | |||
"2.5h\n", | |||
"2h\n", | |||
"3h\n", | |||
"3h\n", | |||
"2h\n", | |||
"1h\n", | |||
"0h\n", | |||
"0.5h\n", | |||
"0.5h\n", | |||
"\"\"\"\n", | |||
"time_list = time_data.strip().split('\\n')\n", | |||
"total_hours = sum(float(time.replace('h', '')) for time in time_list)\n", | |||
"print(total_hours)" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 3, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"name": "stdout", | |||
"output_type": "stream", | |||
"text": [ | |||
"1. 데이터를 로드합니다.\n", | |||
"1-1. 네트워크가 로드되었습니다.\n", | |||
"1-2. 테이블들이 로드되었습니다.\n", | |||
"1-3. 네트워크의 모든 clean state requirement들을 체크했습니다.\n", | |||
"1-4. 테이블들의 무결성 검사를 완료했습니다.\n" | |||
] | |||
}, | |||
{ | |||
"name": "stderr", | |||
"output_type": "stream", | |||
"text": [ | |||
"이동류정보 불러오는 중: 100%|██████████| 17280/17280 [00:51<00:00, 334.89it/s]\n" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"import sys\n", | |||
"from datetime import datetime\n", | |||
"sys.path.append('../../Scripts')\n", | |||
"from preprocess_daily import DailyPreprocessor\n", | |||
"self = DailyPreprocessor()\n", | |||
"\n", | |||
"# 1. 데이터 준비\n", | |||
"self.load_data()\n", | |||
"\n", | |||
"self.make_match1()\n", | |||
"self.make_match2()\n", | |||
"self.make_match3()\n", | |||
"self.make_match4()\n", | |||
"self.make_match5()" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 4, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"name": "stdout", | |||
"output_type": "stream", | |||
"text": [ | |||
"u00 True\n", | |||
"u20 False\n", | |||
"u30 True\n", | |||
"u31 True\n", | |||
"u32 True\n", | |||
"u60 True\n" | |||
] | |||
}, | |||
{ | |||
"ename": "NameError", | |||
"evalue": "name 'pd' is not defined", | |||
"output_type": "error", | |||
"traceback": [ | |||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |||
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", | |||
"Cell \u001b[1;32mIn[4], line 55\u001b[0m\n\u001b[0;32m 52\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcoord \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcoord[[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minter_no\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mphase_no\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mring_type\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmove_no\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minc_dir\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mout_dir\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minc_angle\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mout_angle\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minc_edge\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mout_edge\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mnode_id\u001b[39m\u001b[38;5;124m'\u001b[39m]]\n\u001b[0;32m 54\u001b[0m \u001b[38;5;66;03m# display(coord)\u001b[39;00m\n\u001b[1;32m---> 55\u001b[0m cmatches \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241m.\u001b[39mconcat(cmatches)\n\u001b[0;32m 56\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmatch6 \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mconcat([\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmatch5, cmatches, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcoord])\u001b[38;5;241m.\u001b[39mdrop_duplicates()\u001b[38;5;241m.\u001b[39msort_values(by\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minter_no\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mnode_id\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mphase_no\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mring_type\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[0;32m 57\u001b[0m \u001b[38;5;66;03m# self.match6.to_csv(os.path.join(self.path_intermediates, 'match6.csv'))\u001b[39;00m\n", | |||
"\u001b[1;31mNameError\u001b[0m: name 'pd' is not defined" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"# self.node2inter = dict(zip(self.inter_node['node_id'], self.inter_node['inter_no']))\n", | |||
"\n", | |||
"# child_ids = self.inter_node[self.inter_node.inter_type=='child'].node_id.unique()\n", | |||
"# ch2pa = {} # child to parent\n", | |||
"# for child_id in child_ids:\n", | |||
"# parent_no = self.inter_node[self.inter_node.node_id==child_id].inter_no.iloc[0]\n", | |||
"# sub_inter_node = self.inter_node[self.inter_node.inter_no==parent_no]\n", | |||
"# ch2pa[child_id] = sub_inter_node[sub_inter_node.inter_type=='parent'].iloc[0].node_id\n", | |||
"# directions = ['북', '북동', '동', '남동', '남', '남서', '서', '북서'] # 정북기준 시계방향으로 8방향\n", | |||
"\n", | |||
"# # 각 uturn node에 대하여 (inc_edge_id, out_edge_id) 부여\n", | |||
"# cmatches = []\n", | |||
"# for _, row in self.uturn.iterrows():\n", | |||
"# child_id = row.child_id\n", | |||
"# parent_id = row.parent_id\n", | |||
"# direction = row.direction\n", | |||
"# condition = row.condition\n", | |||
"# inc_edge_id = row.inc_edge\n", | |||
"# out_edge_id = row.out_edge\n", | |||
"# # match5에서 parent_id에 해당하는 행들을 가져옴\n", | |||
"# cmatch = self.match5.copy()[self.match5.node_id==parent_id] # match dataframe for a child node\n", | |||
"# cmatch = cmatch.sort_values(by=['phase_no', 'ring_type']).reset_index(drop=True)\n", | |||
"# cmatch['node_id'] = child_id\n", | |||
"# cmatch[['inc_edge', 'out_edge']] = np.nan\n", | |||
"\n", | |||
"# # condition 별로 inc_dire, out_dire_A, out_dire_B를 정함\n", | |||
"# ind = directions.index(direction)\n", | |||
"# if condition == \"좌회전시\":\n", | |||
"# inc_dire = direction\n", | |||
"# out_dire_A = out_dire_B = directions[(ind + 2) % len(directions)]\n", | |||
"# elif condition == \"보행신호시\":\n", | |||
"# inc_dire = directions[(ind + 2) % len(directions)]\n", | |||
"# out_dire_A = directions[(ind - 2) % len(directions)]\n", | |||
"# out_dire_B = directions[(ind - 2) % len(directions)]\n", | |||
"# print(child_id, ((cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_A)).any())\n", | |||
"# # (inc_dire, out_dire_A, out_dire_B) 별로 inc_edge_id, out_edge_id를 정함\n", | |||
"# cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_A), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n", | |||
"# cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_B), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n", | |||
"# if condition == '보행신호시':\n", | |||
"# # 이동류번호가 17(보행신호)이면서 유턴노드방향으로 가는 신호가 없으면 (inc_edge_id, out_edge_id)를 부여한다.\n", | |||
"# cmatch.loc[(cmatch.move_no==17) & (cmatch.out_dir!=direction), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n", | |||
"# # 유턴신호의 이동류번호를 19로 부여한다.\n", | |||
"# cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_A), 'move_no'] = 19\n", | |||
"# cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_B), 'move_no'] = 19\n", | |||
"# cmatches.append(cmatch)\n", | |||
"\n", | |||
"# # 각 coordination node에 대하여 (inc_edge_id, out_edge_id) 부여\n", | |||
"# self.coord['inter_no'] = self.coord['parent_id'].map(self.node2inter)\n", | |||
"# self.coord = self.coord.rename(columns={'child_id':'node_id'})\n", | |||
"# self.coord[['inc_dir', 'out_dir', 'inc_angle','out_angle']] = np.nan\n", | |||
"# self.coord['move_no'] = 20\n", | |||
"# self.coord = self.coord[['inter_no', 'phase_no', 'ring_type', 'move_no', 'inc_dir', 'out_dir', 'inc_angle','out_angle', 'inc_edge', 'out_edge', 'node_id']]\n", | |||
"\n", | |||
"# # display(coord)\n", | |||
"# cmatches = pd.concat(cmatches)\n", | |||
"# self.match6 = pd.concat([self.match5, cmatches, self.coord]).drop_duplicates().sort_values(by=['inter_no', 'node_id', 'phase_no', 'ring_type'])\n", | |||
"# # self.match6.to_csv(os.path.join(self.path_intermediates, 'match6.csv'))" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 5, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"ename": "AttributeError", | |||
"evalue": "'DailyPreprocessor' object has no attribute 'match6'", | |||
"output_type": "error", | |||
"traceback": [ | |||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |||
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", | |||
"Cell \u001b[1;32mIn[5], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmatch6\u001b[49m\n", | |||
"\u001b[1;31mAttributeError\u001b[0m: 'DailyPreprocessor' object has no attribute 'match6'" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"self.match6" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"splits 딕셔너리 다시 만들기" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 21, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"name": "stdout", | |||
"output_type": "stream", | |||
"text": [ | |||
"[37 39 55 29 0 0 0 0]\n", | |||
"[37 39 25 59 0 0 0 0]\n", | |||
"[ 37 76 131 160 160 160 160 160]\n", | |||
"[ 37 76 101 160 160 160 160 160]\n", | |||
"[ 37 76 101 131 160]\n", | |||
"[37 39 25 30 29]\n", | |||
"{(1, 1): 37, (2, 2): 39, (3, 3): 25, (3, 4): 55, (4, 4): 29, (4, 5): 59, (5, 5): 0, (6, 6): 0, (7, 7): 0, (8, 8): 0}\n", | |||
"\n", | |||
"[37 39 55 29 0 0 0 0]\n", | |||
"[37 39 25 59 0 0 0 0]\n", | |||
"[ 0 39 55 29 0 0 0 0]\n", | |||
"[ 0 0 55 29 0 0 0 0]\n", | |||
"[ 0 0 30 29 0 0 0 0]\n", | |||
"[ 0 0 30 -1 0 0 0 0]\n", | |||
"[ 0 0 30 -1 -29 0 0 0]\n" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"import numpy as np\n", | |||
"row = self.plan.iloc[0]\n", | |||
"# print(row)\n", | |||
"inter_no = row.inter_no\n", | |||
"start_hour = row.start_hour\n", | |||
"start_minute = row.start_minute\n", | |||
"cycle = row.cycle\n", | |||
"\n", | |||
"dura_A = np.array(row[[f'dura_A{j}' for j in range(1, 9)]])\n", | |||
"dura_B = np.array(row[[f'dura_B{j}' for j in range(1, 9)]])\n", | |||
"\n", | |||
"print(np.array(dura_A))\n", | |||
"print(np.array(dura_B))\n", | |||
"\n", | |||
"cums_A = row[[f'dura_A{j}' for j in range(1,9)]].cumsum()\n", | |||
"cums_B = row[[f'dura_B{j}' for j in range(1,9)]].cumsum()\n", | |||
"\n", | |||
"print(np.array(cums_A))\n", | |||
"print(np.array(cums_B))\n", | |||
"\n", | |||
"detailed_cums = []\n", | |||
"combined_row = np.unique(np.concatenate((cums_A,cums_B)))\n", | |||
"print(combined_row)\n", | |||
"detailed_durations = np.concatenate(([combined_row[0]], np.diff(combined_row)))\n", | |||
"\n", | |||
"print(detailed_durations)\n", | |||
"\n", | |||
"desired_dict = {(1, 1): 37, (2, 2): 39, (3, 3): 25, (3, 4): 55, (4, 4): 29, (4, 5): 59, (5, 5): 0, (6, 6): 0, (7, 7): 0, (8, 8): 0}\n", | |||
"print(desired_dict)\n", | |||
"\n", | |||
"print()\n", | |||
"print(dura_A)\n", | |||
"print(dura_B)\n", | |||
"j = 0\n", | |||
"for i in range(len(detailed_durations)):\n", | |||
" dura_A[j] -= detailed_durations[i]\n", | |||
" print(dura_A)\n", | |||
" j += 1" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 10, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"name": "stdout", | |||
"output_type": "stream", | |||
"text": [ | |||
"[37 39 55 29 0 0 0 0]\n", | |||
"[37 39 25 59 0 0 0 0]\n", | |||
"[ 37 76 131 160 160 160 160 160]\n", | |||
"[ 37 76 101 160 160 160 160 160]\n", | |||
"[ 37 76 101 131 160]\n", | |||
"[37 39 25 30 29]\n", | |||
"{(1, 1): 37, (2, 2): 39, (3, 3): 25, (3, 4): 55, (4, 4): 29, (4, 5): 59, (5, 5): 0, (6, 6): 0, (7, 7): 0, (8, 8): 0}\n" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"import numpy as np\n", | |||
"row = self.plan.iloc[0]\n", | |||
"inter_no = row.inter_no\n", | |||
"start_hour = row.start_hour\n", | |||
"start_minute = row.start_minute\n", | |||
"cycle = row.cycle\n", | |||
"\n", | |||
"dura_A = row[[f'dura_A{j}' for j in range(1, 9)]]\n", | |||
"dura_B = row[[f'dura_B{j}' for j in range(1, 9)]]\n", | |||
"\n", | |||
"print(np.array(dura_A))\n", | |||
"print(np.array(dura_B))\n", | |||
"\n", | |||
"cums_A = row[[f'dura_A{j}' for j in range(1,9)]].cumsum()\n", | |||
"cums_B = row[[f'dura_B{j}' for j in range(1,9)]].cumsum()\n", | |||
"\n", | |||
"print(np.array(cums_A))\n", | |||
"print(np.array(cums_B))\n", | |||
"\n", | |||
"detailed_cums = []\n", | |||
"combined_row = np.unique(np.concatenate((cums_A,cums_B)))\n", | |||
"print(combined_row)\n", | |||
"detailed_durations = np.concatenate(([combined_row[0]], np.diff(combined_row)))\n", | |||
"\n", | |||
"print(detailed_durations)\n", | |||
"\n", | |||
"duration_dict = {}\n", | |||
"# 두 시리즈의 길이가 같다고 가정합니다.\n", | |||
"for i in range(len(dura_A)):\n", | |||
" # A와 B의 현시시간이 같은 경우\n", | |||
" if dura_A[i] == dura_B[i]:\n", | |||
" duration_dict[(i+1, i+1)] = dura_A[i]\n", | |||
" # A와 B의 현시시간이 다른 경우\n", | |||
" else:\n", | |||
" duration_dict[(i+1, i+1)] = min(dura_A[i], dura_B[i])\n", | |||
" duration_dict[(i+1, i+2)] = max(dura_A[i], dura_B[i])\n", | |||
"\n", | |||
"print(duration_dict)\n", | |||
"# cums_A = row[[f'dura_A{j}' for j in range(1,9)]].cumsum()\n", | |||
"# cums_B = row[[f'dura_B{j}' for j in range(1,9)]].cumsum()\n", | |||
"# print(cums_A)\n", | |||
"# print(cums_B)\n", | |||
"# detailed_cums = []\n", | |||
"# combined_row = np.unique(np.concatenate((cums_A,cums_B)))\n", | |||
"# print(combined_row)\n", | |||
"# detailed_durations = np.concatenate(([combined_row[0]], np.diff(combined_row)))\n", | |||
"# print(detailed_durations)" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 38, | |||
"metadata": {}, | |||
"outputs": [], | |||
"source": [ | |||
"# split, isplit : A,B 분리 혹은 통합시 사용될 수 있는 딕셔너리 \n", | |||
"self.splits = {} # splits maps (inter_no, start_hour, start_minute) to split \n", | |||
"for i, row in self.plan.iterrows():\n", | |||
" inter_no = row.inter_no\n", | |||
" start_hour = row.start_hour\n", | |||
" start_minute = row.start_minute\n", | |||
" cycle = row.cycle\n", | |||
" cums_A = row[[f'dura_A{j}' for j in range(1,9)]].cumsum()\n", | |||
" cums_B = row[[f'dura_B{j}' for j in range(1,9)]].cumsum()\n", | |||
" self.splits[(inter_no, start_hour, start_minute)] = {} # split maps (phas_A, phas_B) to k\n", | |||
" k = 0\n", | |||
" for t in range(cycle):\n", | |||
" new_phas_A = len(cums_A[cums_A < t]) + 1\n", | |||
" new_phas_B = len(cums_B[cums_B < t]) + 1\n", | |||
" if k == 0 or ((new_phas_A, new_phas_B) != (phas_A, phas_B)):\n", | |||
" k += 1\n", | |||
" phas_A = new_phas_A\n", | |||
" phas_B = new_phas_B\n", | |||
" self.splits[(inter_no, start_hour, start_minute)][(phas_A, phas_B)] = k\n", | |||
"self.isplits = {} # the inverse of splits\n", | |||
"for i in self.splits:\n", | |||
" self.isplits[i] = {self.splits[i][k]:k for k in self.splits[i]} # isplit maps k to (phas_A, phas_B)\n" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 49, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"data": { | |||
"text/plain": [ | |||
"{(175, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (3, 4): 4, (4, 4): 5},\n", | |||
" (175, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (3, 4): 4, (4, 4): 5},\n", | |||
" (175, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (3, 4): 4, (4, 4): 5},\n", | |||
" (175, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (3, 4): 4, (4, 4): 5},\n", | |||
" (176, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3},\n", | |||
" (176, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3},\n", | |||
" (176, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3},\n", | |||
" (176, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3},\n", | |||
" (177, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (177, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (177, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (177, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (178, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (178, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 3): 4, (4, 4): 5},\n", | |||
" (178, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 3): 4, (4, 4): 5},\n", | |||
" (178, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 3): 4, (4, 4): 5},\n", | |||
" (201, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4, (5, 5): 5},\n", | |||
" (201, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4, (5, 5): 5},\n", | |||
" (201, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4, (5, 5): 5},\n", | |||
" (201, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4, (5, 5): 5},\n", | |||
" (202, 0, 0): {(1, 1): 1, (2, 2): 2},\n", | |||
" (202, 7, 0): {(1, 1): 1, (2, 2): 2},\n", | |||
" (202, 9, 0): {(1, 1): 1, (2, 2): 2},\n", | |||
" (202, 18, 30): {(1, 1): 1, (2, 2): 2},\n", | |||
" (206, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (206, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (206, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (206, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (210, 0, 0): {(1, 1): 1, (1, 2): 2, (2, 2): 3, (3, 3): 4, (4, 4): 5},\n", | |||
" (210, 7, 0): {(1, 1): 1, (1, 2): 2, (2, 2): 3, (3, 3): 4, (4, 4): 5},\n", | |||
" (210, 9, 0): {(1, 1): 1, (1, 2): 2, (2, 2): 3, (3, 3): 4, (4, 4): 5},\n", | |||
" (210, 18, 30): {(1, 1): 1, (1, 2): 2, (2, 2): 3, (3, 3): 4, (4, 4): 5}}" | |||
] | |||
}, | |||
"execution_count": 49, | |||
"metadata": {}, | |||
"output_type": "execute_result" | |||
} | |||
], | |||
"source": [ | |||
"self.splits" | |||
] | |||
} | |||
], | |||
"metadata": { | |||
"kernelspec": { | |||
"display_name": "rts", | |||
"language": "python", | |||
"name": "rts" | |||
}, | |||
"language_info": { | |||
"codemirror_mode": { | |||
"name": "ipython", | |||
"version": 3 | |||
}, | |||
"file_extension": ".py", | |||
"mimetype": "text/x-python", | |||
"name": "python", | |||
"nbconvert_exporter": "python", | |||
"pygments_lexer": "ipython3", | |||
"version": "3.8.10" | |||
} | |||
}, | |||
"nbformat": 4, | |||
"nbformat_minor": 2 | |||
} |
@ -1,548 +0,0 @@ | |||
{ | |||
"cells": [ | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 37, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"name": "stdout", | |||
"output_type": "stream", | |||
"text": [ | |||
"1. 데이터를 로드합니다.\n", | |||
"1-1. 네트워크가 로드되었습니다.\n", | |||
"1-2. 테이블들이 로드되었습니다.\n", | |||
"1-3. 네트워크의 모든 clean state requirement들을 체크했습니다.\n", | |||
"1-4. 테이블들의 무결성 검사를 완료했습니다.\n" | |||
] | |||
}, | |||
{ | |||
"name": "stderr", | |||
"output_type": "stream", | |||
"text": [ | |||
"이동류정보 불러오는 중: 100%|██████████| 17280/17280 [00:13<00:00, 1247.47it/s]\n" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"import sys\n", | |||
"from datetime import datetime\n", | |||
"sys.path.append('../../Scripts')\n", | |||
"from preprocess_daily import DailyPreprocessor\n", | |||
"self = DailyPreprocessor()\n", | |||
"\n", | |||
"# 1. 데이터 준비\n", | |||
"self.load_data()\n", | |||
"\n", | |||
"self.make_match1()\n", | |||
"self.make_match2()\n", | |||
"self.make_match3()\n", | |||
"self.make_match4()\n", | |||
"self.make_match5()" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 36, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"name": "stdout", | |||
"output_type": "stream", | |||
"text": [ | |||
"u00 True\n", | |||
"u20 False\n", | |||
"u30 True\n", | |||
"u31 True\n", | |||
"u32 True\n", | |||
"u60 True\n" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"self.node2inter = dict(zip(self.inter_node['node_id'], self.inter_node['inter_no']))\n", | |||
"\n", | |||
"child_ids = self.inter_node[self.inter_node.inter_type=='child'].node_id.unique()\n", | |||
"ch2pa = {} # child to parent\n", | |||
"for child_id in child_ids:\n", | |||
" parent_no = self.inter_node[self.inter_node.node_id==child_id].inter_no.iloc[0]\n", | |||
" sub_inter_node = self.inter_node[self.inter_node.inter_no==parent_no]\n", | |||
" ch2pa[child_id] = sub_inter_node[sub_inter_node.inter_type=='parent'].iloc[0].node_id\n", | |||
"directions = ['북', '북동', '동', '남동', '남', '남서', '서', '북서'] # 정북기준 시계방향으로 8방향\n", | |||
"\n", | |||
"# 각 uturn node에 대하여 (inc_edge_id, out_edge_id) 부여\n", | |||
"cmatches = []\n", | |||
"for _, row in self.uturn.iterrows():\n", | |||
" child_id = row.child_id\n", | |||
" parent_id = row.parent_id\n", | |||
" direction = row.direction\n", | |||
" condition = row.condition\n", | |||
" inc_edge_id = row.inc_edge\n", | |||
" out_edge_id = row.out_edge\n", | |||
" # match5에서 parent_id에 해당하는 행들을 가져옴\n", | |||
" cmatch = self.match5.copy()[self.match5.node_id==parent_id] # match dataframe for a child node\n", | |||
" cmatch = cmatch.sort_values(by=['phase_no', 'ring_type']).reset_index(drop=True)\n", | |||
" cmatch['node_id'] = child_id\n", | |||
" cmatch[['inc_edge', 'out_edge']] = np.nan\n", | |||
"\n", | |||
" # condition 별로 inc_dire, out_dire_A, out_dire_B를 정함\n", | |||
" ind = directions.index(direction)\n", | |||
" if condition == \"좌회전시\":\n", | |||
" inc_dire = direction\n", | |||
" out_dire_A = out_dire_B = directions[(ind + 2) % len(directions)]\n", | |||
" elif condition == \"보행신호시\":\n", | |||
" inc_dire = directions[(ind + 2) % len(directions)]\n", | |||
" out_dire_A = directions[(ind - 2) % len(directions)]\n", | |||
" out_dire_B = directions[(ind - 2) % len(directions)]\n", | |||
" print(child_id, ((cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_A)).any())\n", | |||
" # (inc_dire, out_dire_A, out_dire_B) 별로 inc_edge_id, out_edge_id를 정함\n", | |||
" cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_A), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n", | |||
" cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_B), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n", | |||
" if condition == '보행신호시':\n", | |||
" # 이동류번호가 17(보행신호)이면서 유턴노드방향으로 가는 신호가 없으면 (inc_edge_id, out_edge_id)를 부여한다.\n", | |||
" cmatch.loc[(cmatch.move_no==17) & (cmatch.out_dir!=direction), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n", | |||
" # 유턴신호의 이동류번호를 19로 부여한다.\n", | |||
" cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_A), 'move_no'] = 19\n", | |||
" cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire_B), 'move_no'] = 19\n", | |||
" cmatches.append(cmatch)\n", | |||
"\n", | |||
"# 각 coordination node에 대하여 (inc_edge_id, out_edge_id) 부여\n", | |||
"self.coord['inter_no'] = self.coord['parent_id'].map(self.node2inter)\n", | |||
"self.coord = self.coord.rename(columns={'child_id':'node_id'})\n", | |||
"self.coord[['inc_dir', 'out_dir', 'inc_angle','out_angle']] = np.nan\n", | |||
"self.coord['move_no'] = 20\n", | |||
"self.coord = self.coord[['inter_no', 'phase_no', 'ring_type', 'move_no', 'inc_dir', 'out_dir', 'inc_angle','out_angle', 'inc_edge', 'out_edge', 'node_id']]\n", | |||
"\n", | |||
"# display(coord)\n", | |||
"cmatches = pd.concat(cmatches)\n", | |||
"self.match6 = pd.concat([self.match5, cmatches, self.coord]).drop_duplicates().sort_values(by=['inter_no', 'node_id', 'phase_no', 'ring_type'])\n", | |||
"# self.match6.to_csv(os.path.join(self.path_intermediates, 'match6.csv'))" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 34, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"data": { | |||
"text/html": [ | |||
"<div>\n", | |||
"<style scoped>\n", | |||
" .dataframe tbody tr th:only-of-type {\n", | |||
" vertical-align: middle;\n", | |||
" }\n", | |||
"\n", | |||
" .dataframe tbody tr th {\n", | |||
" vertical-align: top;\n", | |||
" }\n", | |||
"\n", | |||
" .dataframe thead th {\n", | |||
" text-align: right;\n", | |||
" }\n", | |||
"</style>\n", | |||
"<table border=\"1\" class=\"dataframe\">\n", | |||
" <thead>\n", | |||
" <tr style=\"text-align: right;\">\n", | |||
" <th></th>\n", | |||
" <th>inter_no</th>\n", | |||
" <th>phase_no</th>\n", | |||
" <th>ring_type</th>\n", | |||
" <th>move_no</th>\n", | |||
" <th>inc_dir</th>\n", | |||
" <th>out_dir</th>\n", | |||
" <th>inc_angle</th>\n", | |||
" <th>out_angle</th>\n", | |||
" <th>inc_edge</th>\n", | |||
" <th>out_edge</th>\n", | |||
" <th>node_id</th>\n", | |||
" </tr>\n", | |||
" </thead>\n", | |||
" <tbody>\n", | |||
" <tr>\n", | |||
" <th>0</th>\n", | |||
" <td>175</td>\n", | |||
" <td>1</td>\n", | |||
" <td>A</td>\n", | |||
" <td>8</td>\n", | |||
" <td>남</td>\n", | |||
" <td>북</td>\n", | |||
" <td>179</td>\n", | |||
" <td>004</td>\n", | |||
" <td>-571542797_02</td>\n", | |||
" <td>571500487_01</td>\n", | |||
" <td>i0</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>1</th>\n", | |||
" <td>175</td>\n", | |||
" <td>1</td>\n", | |||
" <td>B</td>\n", | |||
" <td>4</td>\n", | |||
" <td>북</td>\n", | |||
" <td>남</td>\n", | |||
" <td>003</td>\n", | |||
" <td>176</td>\n", | |||
" <td>-571500487_01</td>\n", | |||
" <td>571542797_02</td>\n", | |||
" <td>i0</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>2</th>\n", | |||
" <td>175</td>\n", | |||
" <td>2</td>\n", | |||
" <td>A</td>\n", | |||
" <td>7</td>\n", | |||
" <td>북</td>\n", | |||
" <td>동</td>\n", | |||
" <td>001</td>\n", | |||
" <td>095</td>\n", | |||
" <td>-571500487_01</td>\n", | |||
" <td>571545870_01</td>\n", | |||
" <td>i0</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>3</th>\n", | |||
" <td>175</td>\n", | |||
" <td>2</td>\n", | |||
" <td>B</td>\n", | |||
" <td>3</td>\n", | |||
" <td>남</td>\n", | |||
" <td>서</td>\n", | |||
" <td>179</td>\n", | |||
" <td>270</td>\n", | |||
" <td>-571542797_02</td>\n", | |||
" <td>571510153_01</td>\n", | |||
" <td>i0</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>4</th>\n", | |||
" <td>175</td>\n", | |||
" <td>3</td>\n", | |||
" <td>A</td>\n", | |||
" <td>6</td>\n", | |||
" <td>동</td>\n", | |||
" <td>서</td>\n", | |||
" <td>090</td>\n", | |||
" <td>270</td>\n", | |||
" <td>571545870_02</td>\n", | |||
" <td>571510153_01</td>\n", | |||
" <td>i0</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>...</th>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" <td>...</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>3</th>\n", | |||
" <td>210</td>\n", | |||
" <td>2</td>\n", | |||
" <td>B</td>\n", | |||
" <td>2</td>\n", | |||
" <td>서</td>\n", | |||
" <td>동</td>\n", | |||
" <td>270</td>\n", | |||
" <td>090</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>u60</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>4</th>\n", | |||
" <td>210</td>\n", | |||
" <td>3</td>\n", | |||
" <td>A</td>\n", | |||
" <td>7</td>\n", | |||
" <td>북</td>\n", | |||
" <td>동</td>\n", | |||
" <td>359</td>\n", | |||
" <td>090</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>u60</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>5</th>\n", | |||
" <td>210</td>\n", | |||
" <td>3</td>\n", | |||
" <td>B</td>\n", | |||
" <td>4</td>\n", | |||
" <td>북</td>\n", | |||
" <td>남</td>\n", | |||
" <td>000</td>\n", | |||
" <td>180</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>u60</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>6</th>\n", | |||
" <td>210</td>\n", | |||
" <td>4</td>\n", | |||
" <td>A</td>\n", | |||
" <td>8</td>\n", | |||
" <td>남</td>\n", | |||
" <td>북</td>\n", | |||
" <td>180</td>\n", | |||
" <td>000</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>u60</td>\n", | |||
" </tr>\n", | |||
" <tr>\n", | |||
" <th>7</th>\n", | |||
" <td>210</td>\n", | |||
" <td>4</td>\n", | |||
" <td>B</td>\n", | |||
" <td>3</td>\n", | |||
" <td>남</td>\n", | |||
" <td>서</td>\n", | |||
" <td>180</td>\n", | |||
" <td>270</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>NaN</td>\n", | |||
" <td>u60</td>\n", | |||
" </tr>\n", | |||
" </tbody>\n", | |||
"</table>\n", | |||
"<p>116 rows × 11 columns</p>\n", | |||
"</div>" | |||
], | |||
"text/plain": [ | |||
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n", | |||
"0 175 1 A 8 남 북 179 004 \n", | |||
"1 175 1 B 4 북 남 003 176 \n", | |||
"2 175 2 A 7 북 동 001 095 \n", | |||
"3 175 2 B 3 남 서 179 270 \n", | |||
"4 175 3 A 6 동 서 090 270 \n", | |||
".. ... ... ... ... ... ... ... ... \n", | |||
"3 210 2 B 2 서 동 270 090 \n", | |||
"4 210 3 A 7 북 동 359 090 \n", | |||
"5 210 3 B 4 북 남 000 180 \n", | |||
"6 210 4 A 8 남 북 180 000 \n", | |||
"7 210 4 B 3 남 서 180 270 \n", | |||
"\n", | |||
" inc_edge out_edge node_id \n", | |||
"0 -571542797_02 571500487_01 i0 \n", | |||
"1 -571500487_01 571542797_02 i0 \n", | |||
"2 -571500487_01 571545870_01 i0 \n", | |||
"3 -571542797_02 571510153_01 i0 \n", | |||
"4 571545870_02 571510153_01 i0 \n", | |||
".. ... ... ... \n", | |||
"3 NaN NaN u60 \n", | |||
"4 NaN NaN u60 \n", | |||
"5 NaN NaN u60 \n", | |||
"6 NaN NaN u60 \n", | |||
"7 NaN NaN u60 \n", | |||
"\n", | |||
"[116 rows x 11 columns]" | |||
] | |||
}, | |||
"execution_count": 34, | |||
"metadata": {}, | |||
"output_type": "execute_result" | |||
} | |||
], | |||
"source": [ | |||
"self.match6" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"splits 딕셔너리 다시 만들기" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 53, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"name": "stdout", | |||
"output_type": "stream", | |||
"text": [ | |||
"dura_A1 37\n", | |||
"dura_A2 39\n", | |||
"dura_A3 55\n", | |||
"dura_A4 29\n", | |||
"dura_A5 0\n", | |||
"dura_A6 0\n", | |||
"dura_A7 0\n", | |||
"dura_A8 0\n", | |||
"Name: 0, dtype: int64\n", | |||
"dura_B1 37\n", | |||
"dura_B2 39\n", | |||
"dura_B3 25\n", | |||
"dura_B4 59\n", | |||
"dura_B5 0\n", | |||
"dura_B6 0\n", | |||
"dura_B7 0\n", | |||
"dura_B8 0\n", | |||
"Name: 0, dtype: int64\n" | |||
] | |||
}, | |||
{ | |||
"ename": "NameError", | |||
"evalue": "name 'dura_A' is not defined", | |||
"output_type": "error", | |||
"traceback": [ | |||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |||
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", | |||
"Cell \u001b[1;32mIn[53], line 11\u001b[0m\n\u001b[0;32m 9\u001b[0m duration_dict \u001b[38;5;241m=\u001b[39m {}\n\u001b[0;32m 10\u001b[0m \u001b[38;5;66;03m# 두 시리즈의 길이가 같다고 가정합니다.\u001b[39;00m\n\u001b[1;32m---> 11\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;28mlen\u001b[39m(\u001b[43mdura_A\u001b[49m)):\n\u001b[0;32m 12\u001b[0m \u001b[38;5;66;03m# A와 B의 현시간이 같은 경우\u001b[39;00m\n\u001b[0;32m 13\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m dura_A[i] \u001b[38;5;241m==\u001b[39m dura_B[i]:\n\u001b[0;32m 14\u001b[0m duration_dict[(i\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m, i\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m)] \u001b[38;5;241m=\u001b[39m dura_A[i]\n", | |||
"\u001b[1;31mNameError\u001b[0m: name 'dura_A' is not defined" | |||
] | |||
} | |||
], | |||
"source": [ | |||
"import numpy as np\n", | |||
"row = self.plan.iloc[0]\n", | |||
"inter_no = row.inter_no\n", | |||
"start_hour = row.start_hour\n", | |||
"start_minute = row.start_minute\n", | |||
"cycle = row.cycle\n", | |||
"print(row[[f'dura_A{j}' for j in range(1,9)]])\n", | |||
"print(row[[f'dura_B{j}' for j in range(1,9)]])\n", | |||
"\n", | |||
"\n", | |||
"dura_A = row[[f'dura_A{j}' for j in range(1, 9)]]\n", | |||
"dura_B = row[[f'dura_B{j}' for j in range(1, 9)]]\n", | |||
"\n", | |||
"duration_dict = {}\n", | |||
"# 두 시리즈의 길이가 같다고 가정합니다.\n", | |||
"for i in range(len(dura_A)):\n", | |||
" # A와 B의 현시간이 같은 경우\n", | |||
" if dura_A[i] == dura_B[i]:\n", | |||
" duration_dict[(i+1, i+1)] = dura_A[i]\n", | |||
" # A와 B의 현시간이 다른 경우\n", | |||
" else:\n", | |||
" duration_dict[(i+1, i+1)] = min(dura_A[i], dura_B[i])\n", | |||
" duration_dict[(i+1, i+2)] = max(dura_A[i], dura_B[i])\n", | |||
"\n", | |||
"print(duration_dict)\n", | |||
"# cums_A = row[[f'dura_A{j}' for j in range(1,9)]].cumsum()\n", | |||
"# cums_B = row[[f'dura_B{j}' for j in range(1,9)]].cumsum()\n", | |||
"# print(cums_A)\n", | |||
"# print(cums_B)\n", | |||
"# detailed_cums = []\n", | |||
"# combined_row = np.unique(np.concatenate((cums_A,cums_B)))\n", | |||
"# print(combined_row)\n", | |||
"# detailed_durations = np.concatenate(([combined_row[0]], np.diff(combined_row)))\n", | |||
"# print(detailed_durations)" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 38, | |||
"metadata": {}, | |||
"outputs": [], | |||
"source": [ | |||
"# split, isplit : A,B 분리 혹은 통합시 사용될 수 있는 딕셔너리 \n", | |||
"self.splits = {} # splits maps (inter_no, start_hour, start_minute) to split \n", | |||
"for i, row in self.plan.iterrows():\n", | |||
" inter_no = row.inter_no\n", | |||
" start_hour = row.start_hour\n", | |||
" start_minute = row.start_minute\n", | |||
" cycle = row.cycle\n", | |||
" cums_A = row[[f'dura_A{j}' for j in range(1,9)]].cumsum()\n", | |||
" cums_B = row[[f'dura_B{j}' for j in range(1,9)]].cumsum()\n", | |||
" self.splits[(inter_no, start_hour, start_minute)] = {} # split maps (phas_A, phas_B) to k\n", | |||
" k = 0\n", | |||
" for t in range(cycle):\n", | |||
" new_phas_A = len(cums_A[cums_A < t]) + 1\n", | |||
" new_phas_B = len(cums_B[cums_B < t]) + 1\n", | |||
" if k == 0 or ((new_phas_A, new_phas_B) != (phas_A, phas_B)):\n", | |||
" k += 1\n", | |||
" phas_A = new_phas_A\n", | |||
" phas_B = new_phas_B\n", | |||
" self.splits[(inter_no, start_hour, start_minute)][(phas_A, phas_B)] = k\n", | |||
"self.isplits = {} # the inverse of splits\n", | |||
"for i in self.splits:\n", | |||
" self.isplits[i] = {self.splits[i][k]:k for k in self.splits[i]} # isplit maps k to (phas_A, phas_B)\n" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"execution_count": 49, | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"data": { | |||
"text/plain": [ | |||
"{(175, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (3, 4): 4, (4, 4): 5},\n", | |||
" (175, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (3, 4): 4, (4, 4): 5},\n", | |||
" (175, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (3, 4): 4, (4, 4): 5},\n", | |||
" (175, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (3, 4): 4, (4, 4): 5},\n", | |||
" (176, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3},\n", | |||
" (176, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3},\n", | |||
" (176, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3},\n", | |||
" (176, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3},\n", | |||
" (177, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (177, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (177, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (177, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (178, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (178, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 3): 4, (4, 4): 5},\n", | |||
" (178, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 3): 4, (4, 4): 5},\n", | |||
" (178, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 3): 4, (4, 4): 5},\n", | |||
" (201, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4, (5, 5): 5},\n", | |||
" (201, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4, (5, 5): 5},\n", | |||
" (201, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4, (5, 5): 5},\n", | |||
" (201, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4, (5, 5): 5},\n", | |||
" (202, 0, 0): {(1, 1): 1, (2, 2): 2},\n", | |||
" (202, 7, 0): {(1, 1): 1, (2, 2): 2},\n", | |||
" (202, 9, 0): {(1, 1): 1, (2, 2): 2},\n", | |||
" (202, 18, 30): {(1, 1): 1, (2, 2): 2},\n", | |||
" (206, 0, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (206, 7, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (206, 9, 0): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (206, 18, 30): {(1, 1): 1, (2, 2): 2, (3, 3): 3, (4, 4): 4},\n", | |||
" (210, 0, 0): {(1, 1): 1, (1, 2): 2, (2, 2): 3, (3, 3): 4, (4, 4): 5},\n", | |||
" (210, 7, 0): {(1, 1): 1, (1, 2): 2, (2, 2): 3, (3, 3): 4, (4, 4): 5},\n", | |||
" (210, 9, 0): {(1, 1): 1, (1, 2): 2, (2, 2): 3, (3, 3): 4, (4, 4): 5},\n", | |||
" (210, 18, 30): {(1, 1): 1, (1, 2): 2, (2, 2): 3, (3, 3): 4, (4, 4): 5}}" | |||
] | |||
}, | |||
"execution_count": 49, | |||
"metadata": {}, | |||
"output_type": "execute_result" | |||
} | |||
], | |||
"source": [ | |||
"self.splits" | |||
] | |||
} | |||
], | |||
"metadata": { | |||
"kernelspec": { | |||
"display_name": "rts", | |||
"language": "python", | |||
"name": "rts" | |||
}, | |||
"language_info": { | |||
"codemirror_mode": { | |||
"name": "ipython", | |||
"version": 3 | |||
}, | |||
"file_extension": ".py", | |||
"mimetype": "text/x-python", | |||
"name": "python", | |||
"nbconvert_exporter": "python", | |||
"pygments_lexer": "ipython3", | |||
"version": "3.8.10" | |||
} | |||
}, | |||
"nbformat": 4, | |||
"nbformat_minor": 2 | |||
} |