신호생성 repo (24. 1. 5 ~).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

847 lines
30 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pandas as pd\n",
"import numpy as np\n",
"import sys\n",
"sys.path.append('../../Scripts')\n",
"from preprocess_daily import DailyPreprocessor\n",
"from generate_signals import SignalGenerator"
]
},
{
"cell_type": "code",
"execution_count": 2,
"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",
"1-5. 주요 객체 (리스트, 딕셔너리)들을 저장했습니다.\n"
]
}
],
"source": [
"self = DailyPreprocessor()\n",
"self.load_data()\n",
"self.make_match1()\n",
"self.make_match2()\n",
"self.make_match3()\n",
"self.make_match4()\n",
"self.make_match5()\n",
"self.make_match6()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"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_dire</th>\n",
" <th>out_dire</th>\n",
" <th>inc_angle</th>\n",
" <th>out_angle</th>\n",
" <th>inc_edge_id</th>\n",
" <th>out_edge_id</th>\n",
" <th>node_id</th>\n",
" <th>turn_type</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>000</td>\n",
" <td>-571542797_02</td>\n",
" <td>571500487_01</td>\n",
" <td>i0</td>\n",
" <td>straight</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>001</td>\n",
" <td>180</td>\n",
" <td>-571500487_01</td>\n",
" <td>571542797_02</td>\n",
" <td>i0</td>\n",
" <td>straight</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>090</td>\n",
" <td>-571500487_01</td>\n",
" <td>571545870_01</td>\n",
" <td>i0</td>\n",
" <td>left</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",
" <td>left</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",
" <td>straight</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",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</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",
" <td>straight</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</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>000</td>\n",
" <td>090</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u60</td>\n",
" <td>left</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</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",
" <td>straight</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</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",
" <td>straight</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</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",
" <td>left</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>108 rows × 12 columns</p>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dire out_dire inc_angle \\\n",
"0 175 1 A 8 남 북 179 \n",
"1 175 1 B 4 북 남 001 \n",
"2 175 2 A 7 북 동 001 \n",
"3 175 2 B 3 남 서 179 \n",
"4 175 3 A 6 동 서 090 \n",
".. ... ... ... ... ... ... ... \n",
"103 210 2 B 2 서 동 270 \n",
"104 210 3 A 7 북 동 000 \n",
"105 210 3 B 4 북 남 000 \n",
"106 210 4 A 8 남 북 180 \n",
"107 210 4 B 3 남 서 180 \n",
"\n",
" out_angle inc_edge_id out_edge_id node_id turn_type \n",
"0 000 -571542797_02 571500487_01 i0 straight \n",
"1 180 -571500487_01 571542797_02 i0 straight \n",
"2 090 -571500487_01 571545870_01 i0 left \n",
"3 270 -571542797_02 571510153_01 i0 left \n",
"4 270 571545870_02 571510153_01 i0 straight \n",
".. ... ... ... ... ... \n",
"103 090 NaN NaN u60 straight \n",
"104 090 NaN NaN u60 left \n",
"105 180 NaN NaN u60 straight \n",
"106 000 NaN NaN u60 straight \n",
"107 270 NaN NaN u60 left \n",
"\n",
"[108 rows x 12 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.match6"
]
},
{
"cell_type": "code",
"execution_count": 9,
"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>move_no</th>\n",
" <th>inc_dire</th>\n",
" <th>out_dire</th>\n",
" <th>inc_edge_id</th>\n",
" <th>out_edge_id</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>동</td>\n",
" <td>남</td>\n",
" <td>571545870_02</td>\n",
" <td>571542797_02</td>\n",
" <td>i0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>175</td>\n",
" <td>2</td>\n",
" <td>서</td>\n",
" <td>동</td>\n",
" <td>571510153_02</td>\n",
" <td>571545870_01</td>\n",
" <td>i0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>175</td>\n",
" <td>3</td>\n",
" <td>남</td>\n",
" <td>서</td>\n",
" <td>-571542797_02</td>\n",
" <td>571510153_01</td>\n",
" <td>i0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>175</td>\n",
" <td>4</td>\n",
" <td>북</td>\n",
" <td>남</td>\n",
" <td>-571500487_01</td>\n",
" <td>571542797_02</td>\n",
" <td>i0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>175</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>571510153_02</td>\n",
" <td>571500487_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",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>210</td>\n",
" <td>12</td>\n",
" <td>북서</td>\n",
" <td>남동</td>\n",
" <td>571500535_02.18</td>\n",
" <td>571542115_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>210</td>\n",
" <td>13</td>\n",
" <td>남서</td>\n",
" <td>북서</td>\n",
" <td>571500585_02</td>\n",
" <td>571500535_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>210</td>\n",
" <td>14</td>\n",
" <td>북동</td>\n",
" <td>남서</td>\n",
" <td>571511538_02.121</td>\n",
" <td>571500585_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>210</td>\n",
" <td>15</td>\n",
" <td>북서</td>\n",
" <td>북동</td>\n",
" <td>571500535_02.18</td>\n",
" <td>571511538_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>210</td>\n",
" <td>16</td>\n",
" <td>남동</td>\n",
" <td>북서</td>\n",
" <td>-571542115_01</td>\n",
" <td>571500535_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>128 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" inter_no move_no inc_dire out_dire inc_edge_id out_edge_id \\\n",
"0 175 1 동 남 571545870_02 571542797_02 \n",
"1 175 2 서 동 571510153_02 571545870_01 \n",
"2 175 3 남 서 -571542797_02 571510153_01 \n",
"3 175 4 북 남 -571500487_01 571542797_02 \n",
"4 175 5 서 북 571510153_02 571500487_01 \n",
".. ... ... ... ... ... ... \n",
"123 210 12 북서 남동 571500535_02.18 571542115_01 \n",
"124 210 13 남서 북서 571500585_02 571500535_01 \n",
"125 210 14 북동 남서 571511538_02.121 571500585_01 \n",
"126 210 15 북서 북동 571500535_02.18 571511538_01 \n",
"127 210 16 남동 북서 -571542115_01 571500535_01 \n",
"\n",
" node_id \n",
"0 i0 \n",
"1 i0 \n",
"2 i0 \n",
"3 i0 \n",
"4 i0 \n",
".. ... \n",
"123 i6 \n",
"124 i6 \n",
"125 i6 \n",
"126 i6 \n",
"127 i6 \n",
"\n",
"[128 rows x 7 columns]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"self.match7 = self.match6.copy()\n",
"self.match7 = self.match7[['inter_no', 'node_id', 'move_no', 'inc_angle', 'out_angle', 'inc_dire', 'out_dire', 'inc_edge_id', 'out_edge_id']]\n",
"# (1) 가능한 (진입방향, 진출방향) 목록 \n",
"flows = self.nema.dropna().apply(lambda row: (row['inc_dire'], row['out_dire']), axis=1).tolist()\n",
"\n",
"# (2) 각 교차로별 방향 목록 : pdires (possible directions)\n",
"p2dires = {} # parent_id to directions\n",
"for parent_id in self.parent_ids:\n",
" dires = self.match7[self.match7.node_id == parent_id][['inc_dire','out_dire']].values.flatten()\n",
" dires = {dire for dire in dires if type(dire)==str}\n",
" p2dires[parent_id] = dires\n",
"\n",
"# (3) 각 (교차로, 진입방향) 별 진입id 목록 : inc2id (incoming direction to incoming edge_id)\n",
"inc2id = {}\n",
"for parent_id in self.parent_ids:\n",
" for inc_dire in p2dires[parent_id]:\n",
" df = self.match7[(self.match7.node_id==parent_id) & (self.match7.inc_dire==inc_dire)]\n",
" inc2id[(parent_id, inc_dire)] = df.inc_edge_id.iloc[0]\n",
"\n",
"# (4) 각 (교차로, 진출방향) 별 진출id 목록 : out2id (outgoing direction to outgoing edge_id)\n",
"out2id = {}\n",
"for parent_id in self.parent_ids:\n",
" for out_dire in p2dires[parent_id]:\n",
" df = self.match7[(self.match7.node_id==parent_id) & (self.match7.out_dire==out_dire)]\n",
" out2id[(parent_id, out_dire)] = df.out_edge_id.iloc[0]\n",
"\n",
"# (5) 각 parent_id별 이동류번호 목록\n",
"p2move = dict() # parent id to a list of aligned movement numbers\n",
"for parent_id in self.parent_ids:\n",
" pnema = self.nema[self.nema.inc_dire.isin(p2dires[parent_id]) & self.nema.out_dire.isin(p2dires[parent_id])]\n",
" p2move[parent_id] = list(pnema.move_no)\n",
"\n",
"# (6) 방위별 방향벡터\n",
"dire2vec = dict() # direction to unit vector\n",
"theta = np.pi/2\n",
"for dire in self.dires:\n",
" dire2vec[dire] = np.array([np.cos(theta), np.sin(theta)])\n",
" theta -= np.pi/4\n",
"\n",
"# (7) 각 parent_id별 : 각 이동류별 진입/진출 엣지 id\n",
"p2move2inc_edge_id = dict() # parent id to move2inc_edge_id\n",
"p2move2out_edge_id = dict() # parent id to move2out_edge_id\n",
"for parent_id in self.parent_ids:\n",
" move2inc_edge_id = dict() # plain movement to incoming edge id\n",
" move2out_edge_id = dict() # plain movement to outgoing edge id\n",
" for move_no in range(1,17):\n",
" row = self.nema[self.nema.move_no==move_no].iloc[0]\n",
" inc_dire = row.inc_dire\n",
" out_dire = row.out_dire\n",
" inc_vec_true = dire2vec[inc_dire]\n",
" out_vec_true = dire2vec[out_dire]\n",
"\n",
" node = self.net.getNode(parent_id)\n",
" # 교차로의 모든 (from / to) edges\n",
" inc_edges = [edge for edge in node.getIncoming() if edge.getFunction() == ''] # incoming edges\n",
" out_edges = [edge for edge in node.getOutgoing() if edge.getFunction() == ''] # outgoing edges\n",
" # 교차로의 모든 (from / to) unit vector\n",
" inc_vecs = []\n",
" for inc_edge in inc_edges:\n",
" start = inc_edge.getShape()[-1]\n",
" end = inc_edge.getShape()[-2]\n",
" inc_vec = np.array(end) - np.array(start)\n",
" inc_vec = inc_vec / (inc_vec ** 2).sum() ** 0.5\n",
" inc_vecs.append(inc_vec)\n",
" out_vecs = []\n",
" for out_edge in out_edges:\n",
" start = out_edge.getShape()[0]\n",
" end = out_edge.getShape()[1]\n",
" out_vec = np.array(end) - np.array(start)\n",
" out_vec = out_vec / (out_vec ** 2).sum() ** 0.5\n",
" out_vecs.append(out_vec)\n",
" # 매칭 엣지 반환\n",
" inc_index = np.array([np.dot(inc_vec, inc_vec_true) for inc_vec in inc_vecs]).argmax()\n",
" out_index = np.array([np.dot(out_vec, out_vec_true) for out_vec in out_vecs]).argmax()\n",
" inc_edge_id = inc_edges[inc_index].getID()\n",
" out_edge_id = out_edges[out_index].getID()\n",
" move2inc_edge_id[move_no] = inc_edge_id\n",
" move2out_edge_id[move_no] = out_edge_id\n",
" p2move2inc_edge_id[parent_id] = move2inc_edge_id\n",
" p2move2out_edge_id[parent_id] = move2out_edge_id\n",
"\n",
"# (8) 각 이동류별 진입/진출 방위\n",
"m2inc_dire = dict()\n",
"m2out_dire = dict()\n",
"for move_no in range(1,17):\n",
" row = self.nema[self.nema.move_no==move_no].iloc[0]\n",
" m2inc_dire[move_no] = row.inc_dire\n",
" m2out_dire[move_no] = row.out_dire\n",
"\n",
"# (9) 가능한 모든 이동류에 대하여 진입id, 진출id 배정 : matching\n",
"self.matching = []\n",
"for parent_id in self.parent_ids:\n",
" inter_no = self.node2inter[parent_id]\n",
" # 좌회전과 직진(1 ~ 16)\n",
" for move_no in range(1,17):\n",
" inc_dire = m2inc_dire[move_no]\n",
" out_dire = m2out_dire[move_no]\n",
" if move_no in p2move[parent_id]:\n",
" inc_edge_id = inc2id[(parent_id, inc_dire)]\n",
" out_edge_id = out2id[(parent_id, out_dire)]\n",
" else:\n",
" inc_edge_id = p2move2inc_edge_id[parent_id][move_no]\n",
" out_edge_id = p2move2out_edge_id[parent_id][move_no]\n",
" new_row = pd.DataFrame({'inter_no':[inter_no], 'move_no':[move_no],\n",
" 'inc_dire':[inc_dire], 'out_dire':[out_dire],\n",
" 'inc_edge_id':[inc_edge_id], 'out_edge_id':[out_edge_id], 'node_id':[parent_id]})\n",
" self.matching.append(new_row)\n",
"child_matching = self.match7[self.match7.node_id.isin(self.child_ids)]\n",
"child_matching = child_matching.drop(columns=['inc_angle', 'out_angle'])\n",
"self.matching = pd.concat(self.matching)\n",
"self.matching = self.matching.dropna(subset=['inc_edge_id', 'out_edge_id'])\\\n",
" .sort_values(by=['inter_no', 'node_id', 'move_no']).reset_index(drop=True)\n",
"self.matching['move_no'] = self.matching['move_no'].astype(int)\n",
"display(self.matching)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"m2inc_dire = dict()\n",
"m2out_dire = dict()\n",
"for move_no in range(1,17):\n",
" row = self.nema[self.nema.move_no==move_no].iloc[0]\n",
" m2inc_dire[move_no] = row.inc_dire\n",
" m2out_dire[move_no] = row.out_dire"
]
},
{
"cell_type": "code",
"execution_count": 37,
"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>move_no</th>\n",
" <th>inc_dire</th>\n",
" <th>out_dire</th>\n",
" <th>inc_edge_id</th>\n",
" <th>out_edge_id</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>동</td>\n",
" <td>남</td>\n",
" <td>571545870_02</td>\n",
" <td>571542797_02</td>\n",
" <td>i0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>175</td>\n",
" <td>2</td>\n",
" <td>서</td>\n",
" <td>동</td>\n",
" <td>571510153_02</td>\n",
" <td>571545870_01</td>\n",
" <td>i0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>175</td>\n",
" <td>3</td>\n",
" <td>남</td>\n",
" <td>서</td>\n",
" <td>-571542797_02</td>\n",
" <td>571510153_01</td>\n",
" <td>i0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>175</td>\n",
" <td>4</td>\n",
" <td>북</td>\n",
" <td>남</td>\n",
" <td>-571500487_01</td>\n",
" <td>571542797_02</td>\n",
" <td>i0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>175</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>571510153_02</td>\n",
" <td>571500487_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",
" </tr>\n",
" <tr>\n",
" <th>135</th>\n",
" <td>210</td>\n",
" <td>13</td>\n",
" <td>남서</td>\n",
" <td>북서</td>\n",
" <td>571500585_02</td>\n",
" <td>571500535_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>136</th>\n",
" <td>210</td>\n",
" <td>14</td>\n",
" <td>북동</td>\n",
" <td>남서</td>\n",
" <td>571511538_02.121</td>\n",
" <td>571500585_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>137</th>\n",
" <td>210</td>\n",
" <td>15</td>\n",
" <td>북서</td>\n",
" <td>북동</td>\n",
" <td>571500535_02.18</td>\n",
" <td>571511538_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>138</th>\n",
" <td>210</td>\n",
" <td>16</td>\n",
" <td>남동</td>\n",
" <td>북서</td>\n",
" <td>-571542115_01</td>\n",
" <td>571500535_01</td>\n",
" <td>i6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>139</th>\n",
" <td>210</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>571500535_02</td>\n",
" <td>-571500535_02</td>\n",
" <td>u60</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>140 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" inter_no move_no inc_dire out_dire inc_edge_id out_edge_id \\\n",
"0 175 1 동 남 571545870_02 571542797_02 \n",
"1 175 2 서 동 571510153_02 571545870_01 \n",
"2 175 3 남 서 -571542797_02 571510153_01 \n",
"3 175 4 북 남 -571500487_01 571542797_02 \n",
"4 175 5 서 북 571510153_02 571500487_01 \n",
".. ... ... ... ... ... ... \n",
"135 210 13 남서 북서 571500585_02 571500535_01 \n",
"136 210 14 북동 남서 571511538_02.121 571500585_01 \n",
"137 210 15 북서 북동 571500535_02.18 571511538_01 \n",
"138 210 16 남동 북서 -571542115_01 571500535_01 \n",
"139 210 5 서 북 571500535_02 -571500535_02 \n",
"\n",
" node_id \n",
"0 i0 \n",
"1 i0 \n",
"2 i0 \n",
"3 i0 \n",
"4 i0 \n",
".. ... \n",
"135 i6 \n",
"136 i6 \n",
"137 i6 \n",
"138 i6 \n",
"139 u60 \n",
"\n",
"[140 rows x 7 columns]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# (6) 가능한 이동류에 대하여 진입id, 진출id 배정 : matching\n",
"self.matching = []\n",
"for parent_id in self.parent_ids:\n",
" inter_no = self.node2inter[parent_id]\n",
" # 좌회전과 직진(1 ~ 16)\n",
" for move_no in range(1,17):\n",
" inc_dire = m2inc_dire[move_no]\n",
" out_dire = m2out_dire[move_no]\n",
" if move_no in p2move[parent_id]:\n",
" inc_edge_id = inc2id[(parent_id, inc_dire)]\n",
" out_edge_id = out2id[(parent_id, out_dire)]\n",
" else:\n",
" inc_edge_id = p2pm2inc_edge_id[parent_id][move_no]\n",
" out_edge_id = p2pm2out_edge_id[parent_id][move_no]\n",
" new_row = pd.DataFrame({'inter_no':[inter_no], 'move_no':[move_no],\n",
" 'inc_dire':[inc_dire], 'out_dire':[out_dire],\n",
" 'inc_edge_id':[inc_edge_id], 'out_edge_id':[out_edge_id], 'node_id':[parent_id]})\n",
" self.matching.append(new_row)\n",
"self.matching.append(self.match7[self.match7.node_id.isin(self.child_ids)])\n",
"self.matching = pd.concat(self.matching)\n",
"self.matching = self.matching.dropna(subset=['inc_edge_id', 'out_edge_id'])\\\n",
" .sort_values(by=['inter_no', 'node_id', 'move_no']).reset_index(drop=True)\n",
"self.matching['move_no'] = self.matching['move_no'].astype(int)\n",
"display(self.matching)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "sts",
"language": "python",
"name": "sts"
},
"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
}