신호생성 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.
 
 

7122 lines
239 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"os.listdir('../../scripts')\n",
"import sys\n",
"sys.path.append('../../Scripts')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from generate_signals import SignalGenerator\n",
"from preprocess_daily import DailyPreprocessor"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"inter_no = 175\n",
"Node_id = 'i0'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1. 데이터를 준비합니다.\n",
"1-1. 네트워크가 로드되었습니다.\n",
"1-2. 테이블들이 로드되었습니다.\n",
"2. 신호이력 테이블을 변환합니다.\n",
"3. 이동류정보 테이블을 변환합니다.\n",
"4. 통합 테이블을 생성합니다.\n"
]
},
{
"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>node_id</th>\n",
" <th>start_unix</th>\n",
" <th>phas_A</th>\n",
" <th>phas_B</th>\n",
" <th>move_A</th>\n",
" <th>move_B</th>\n",
" <th>duration</th>\n",
" <th>state</th>\n",
" <th>phase_sumo</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704416690</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>33</td>\n",
" <td>gggggg</td>\n",
" <td>0_g</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704416690</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>gggggg</td>\n",
" <td>0_y</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704416690</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>gggggg</td>\n",
" <td>1__r</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704416690</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>34</td>\n",
" <td>GGGGGG</td>\n",
" <td>1_g</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704416690</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>GGGGGG</td>\n",
" <td>1_y</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",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704417140</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>ggggggggr</td>\n",
" <td>3__r</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704417140</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" <td>4</td>\n",
" <td>65</td>\n",
" <td>ggggggggr</td>\n",
" <td>3_g</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704417140</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>ggggggggr</td>\n",
" <td>3_y</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704417140</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>8</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>ggggggggr</td>\n",
" <td>4__r</td>\n",
" </tr>\n",
" <tr>\n",
" <th>237</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704417140</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>8</td>\n",
" <td>3</td>\n",
" <td>19</td>\n",
" <td>ggggggggr</td>\n",
" <td>4_g</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>684 rows × 10 columns</p>\n",
"</div>"
],
"text/plain": [
" inter_no node_id start_unix phas_A phas_B move_A move_B duration \\\n",
"0 178 c30 1704416690 1 1 8 4 33 \n",
"1 178 c30 1704416690 1 1 8 4 4 \n",
"2 178 c30 1704416690 2 2 7 3 1 \n",
"0 178 c30 1704416690 2 2 7 3 34 \n",
"1 178 c30 1704416690 2 2 7 3 4 \n",
".. ... ... ... ... ... ... ... ... \n",
"2 210 u60 1704417140 3 3 7 4 1 \n",
"0 210 u60 1704417140 3 3 7 4 65 \n",
"1 210 u60 1704417140 3 3 7 4 4 \n",
"2 210 u60 1704417140 4 4 8 3 1 \n",
"237 210 u60 1704417140 4 4 8 3 19 \n",
"\n",
" state phase_sumo \n",
"0 gggggg 0_g \n",
"1 gggggg 0_y \n",
"2 gggggg 1__r \n",
"0 GGGGGG 1_g \n",
"1 GGGGGG 1_y \n",
".. ... ... \n",
"2 ggggggggr 3__r \n",
"0 ggggggggr 3_g \n",
"1 ggggggggr 3_y \n",
"2 ggggggggr 4__r \n",
"237 ggggggggr 4_g \n",
"\n",
"[684 rows x 10 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# desired result\n",
"self = SignalGenerator()\n",
"self.prepare_data()\n",
"self.process_history()\n",
"self.process_movement()\n",
"self.make_histids()\n",
"self.set_timepoints()\n",
"self.assign_red_yellow()\n",
"self.SIGTABLE"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1. 데이터를 준비합니다.\n",
"1-1. 네트워크가 로드되었습니다.\n",
"1-2. 테이블들이 로드되었습니다.\n",
"2. 신호이력 테이블을 변환합니다.\n",
"3. 이동류정보 테이블을 변환합니다.\n"
]
}
],
"source": [
"self = SignalGenerator()\n",
"self.prepare_data()\n",
"self.process_history()\n",
"self.process_movement()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"self.merge_dfs()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# 4-2. histid\n",
"self.histid = self.movedur.copy()\n",
"self.histid['node_id'] = self.histid['inter_no'].map(self.inter2node)\n",
"histid_start = self.present_time - 600\n",
"self.histid = self.histid[self.histid.start_unix > histid_start]\n",
"\n",
"mapping_dict = self.matching.set_index(['node_id', 'move_no'])['state'].to_dict()\n",
"\n",
"for i, row in self.histid.iterrows():\n",
" node_id = row.node_id\n",
" move_A = row.move_A\n",
" move_B = row.move_B\n",
" \n",
" # A링의 state 지정\n",
" if (node_id, move_A) in mapping_dict:\n",
" state_A = mapping_dict[(node_id, move_A)]\n",
" else:\n",
" state_A = ''.join(self.node2init[node_id])\n",
" self.histid.at[i, 'state_A'] = state_A\n",
"\n",
" # B링의 state 지정\n",
" if (node_id, move_B) in mapping_dict:\n",
" state_B = mapping_dict[(node_id, move_B)]\n",
" else:\n",
" state_B = ''.join(self.node2init[node_id])\n",
" self.histid.at[i, 'state_B'] = state_B "
]
},
{
"cell_type": "code",
"execution_count": 8,
"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>start_unix</th>\n",
" <th>phas_A</th>\n",
" <th>phas_B</th>\n",
" <th>move_A</th>\n",
" <th>move_B</th>\n",
" <th>duration</th>\n",
" <th>node_id</th>\n",
" <th>state_A</th>\n",
" <th>state_B</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>175</td>\n",
" <td>1704416540</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>43</td>\n",
" <td>i0</td>\n",
" <td>grrrgrrrgGGGGrgrr</td>\n",
" <td>gGGrgrrrgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>175</td>\n",
" <td>1704416540</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>46</td>\n",
" <td>i0</td>\n",
" <td>grrGgrrrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrGgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>175</td>\n",
" <td>1704416540</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>33</td>\n",
" <td>i0</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrGgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>175</td>\n",
" <td>1704416540</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>23</td>\n",
" <td>i0</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>175</td>\n",
" <td>1704416540</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>37</td>\n",
" <td>i0</td>\n",
" <td>grrrgrrrgrrrrrgrG</td>\n",
" <td>grrrgrrrgrrrrrgGr</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",
" </tr>\n",
" <tr>\n",
" <th>255</th>\n",
" <td>201</td>\n",
" <td>1704417410</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>3</td>\n",
" <td>33</td>\n",
" <td>i8</td>\n",
" <td>grrrrrrrgGGrgrrr</td>\n",
" <td>grrrrrrrgrrGgrrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>256</th>\n",
" <td>201</td>\n",
" <td>1704417410</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>36</td>\n",
" <td>i8</td>\n",
" <td>grrrrrrrgrrrgrrG</td>\n",
" <td>grrrrrrrgrrrgGGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>257</th>\n",
" <td>201</td>\n",
" <td>1704417410</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>25</td>\n",
" <td>i8</td>\n",
" <td>grrrGGGrgrrrgrrr</td>\n",
" <td>grrrrrrrgrrrgGGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>258</th>\n",
" <td>201</td>\n",
" <td>1704417410</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>58</td>\n",
" <td>i8</td>\n",
" <td>grrrGGGrgrrrgrrr</td>\n",
" <td>grrrrrrGgrrrgrrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>259</th>\n",
" <td>201</td>\n",
" <td>1704417410</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>7</td>\n",
" <td>4</td>\n",
" <td>18</td>\n",
" <td>i8</td>\n",
" <td>grrGrrrrgrrrgrrr</td>\n",
" <td>gGGrrrrrgrrrgrrr</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>203 rows × 10 columns</p>\n",
"</div>"
],
"text/plain": [
" inter_no start_unix phas_A phas_B move_A move_B duration node_id \\\n",
"10 175 1704416540 1 1 8 4 43 i0 \n",
"11 175 1704416540 2 2 7 3 46 i0 \n",
"12 175 1704416540 3 3 6 1 33 i0 \n",
"13 175 1704416540 3 4 6 2 23 i0 \n",
"14 175 1704416540 4 4 5 2 37 i0 \n",
".. ... ... ... ... ... ... ... ... \n",
"255 201 1704417410 1 1 8 3 33 i8 \n",
"256 201 1704417410 2 2 5 2 36 i8 \n",
"257 201 1704417410 3 3 6 2 25 i8 \n",
"258 201 1704417410 4 4 6 1 58 i8 \n",
"259 201 1704417410 5 5 7 4 18 i8 \n",
"\n",
" state_A state_B \n",
"10 grrrgrrrgGGGGrgrr gGGrgrrrgrrrrrgrr \n",
"11 grrGgrrrgrrrrrgrr grrrgrrrgrrrrGgrr \n",
"12 grrrgGGrgrrrrrgrr grrrgrrGgrrrrrgrr \n",
"13 grrrgGGrgrrrrrgrr grrrgrrrgrrrrrgGr \n",
"14 grrrgrrrgrrrrrgrG grrrgrrrgrrrrrgGr \n",
".. ... ... \n",
"255 grrrrrrrgGGrgrrr grrrrrrrgrrGgrrr \n",
"256 grrrrrrrgrrrgrrG grrrrrrrgrrrgGGr \n",
"257 grrrGGGrgrrrgrrr grrrrrrrgrrrgGGr \n",
"258 grrrGGGrgrrrgrrr grrrrrrGgrrrgrrr \n",
"259 grrGrrrrgrrrgrrr gGGrrrrrgrrrgrrr \n",
"\n",
"[203 rows x 10 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.histid"
]
},
{
"cell_type": "code",
"execution_count": 16,
"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>node_id</th>\n",
" <th>start_unix</th>\n",
" <th>phas_A</th>\n",
" <th>phas_B</th>\n",
" <th>move_A</th>\n",
" <th>move_B</th>\n",
" <th>duration</th>\n",
" <th>state_A</th>\n",
" <th>state_B</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>44</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416540</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>43</td>\n",
" <td>grrrgrrrgGGGGrgrr</td>\n",
" <td>gGGrgrrrgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416540</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>46</td>\n",
" <td>grrGgrrrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrGgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416540</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>33</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrGgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>47</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416540</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>23</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>48</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416540</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>37</td>\n",
" <td>grrrgrrrgrrrrrgrG</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416720</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>43</td>\n",
" <td>grrrgrrrgGGGGrgrr</td>\n",
" <td>gGGrgrrrgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416720</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>45</td>\n",
" <td>grrGgrrrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrGgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416720</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>33</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrGgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416720</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>22</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416720</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>37</td>\n",
" <td>grrrgrrrgrrrrrgrG</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>173</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416900</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>43</td>\n",
" <td>grrrgrrrgGGGGrgrr</td>\n",
" <td>gGGrgrrrgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>174</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416900</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>45</td>\n",
" <td>grrGgrrrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrGgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>175</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416900</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>33</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrGgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>176</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416900</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>22</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>177</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704416900</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>37</td>\n",
" <td>grrrgrrrgrrrrrgrG</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>244</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417080</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>43</td>\n",
" <td>grrrgrrrgGGGGrgrr</td>\n",
" <td>gGGrgrrrgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>245</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417080</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>45</td>\n",
" <td>grrGgrrrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrGgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>246</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417080</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>33</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrGgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>247</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417080</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>22</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>248</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417080</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>37</td>\n",
" <td>grrrgrrrgrrrrrgrG</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>306</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417260</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>43</td>\n",
" <td>grrrgrrrgGGGGrgrr</td>\n",
" <td>gGGrgrrrgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>307</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417260</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>45</td>\n",
" <td>grrGgrrrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrGgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>308</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417260</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>33</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrGgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>309</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417260</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>22</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>310</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417260</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>37</td>\n",
" <td>grrrgrrrgrrrrrgrG</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>357</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417420</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>38</td>\n",
" <td>grrrgrrrgGGGGrgrr</td>\n",
" <td>gGGrgrrrgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>358</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417420</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>40</td>\n",
" <td>grrGgrrrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrGgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>359</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417420</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>29</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrGgrrrrrgrr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>360</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417420</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>20</td>\n",
" <td>grrrgGGrgrrrrrgrr</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" <tr>\n",
" <th>361</th>\n",
" <td>175</td>\n",
" <td>i0</td>\n",
" <td>1704417420</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>33</td>\n",
" <td>grrrgrrrgrrrrrgrG</td>\n",
" <td>grrrgrrrgrrrrrgGr</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no node_id start_unix phas_A phas_B move_A move_B duration \\\n",
"44 175 i0 1704416540 1 1 8 4 43 \n",
"45 175 i0 1704416540 2 2 7 3 46 \n",
"46 175 i0 1704416540 3 3 6 1 33 \n",
"47 175 i0 1704416540 3 4 6 2 23 \n",
"48 175 i0 1704416540 4 4 5 2 37 \n",
"109 175 i0 1704416720 1 1 8 4 43 \n",
"110 175 i0 1704416720 2 2 7 3 45 \n",
"111 175 i0 1704416720 3 3 6 1 33 \n",
"112 175 i0 1704416720 3 4 6 2 22 \n",
"113 175 i0 1704416720 4 4 5 2 37 \n",
"173 175 i0 1704416900 1 1 8 4 43 \n",
"174 175 i0 1704416900 2 2 7 3 45 \n",
"175 175 i0 1704416900 3 3 6 1 33 \n",
"176 175 i0 1704416900 3 4 6 2 22 \n",
"177 175 i0 1704416900 4 4 5 2 37 \n",
"244 175 i0 1704417080 1 1 8 4 43 \n",
"245 175 i0 1704417080 2 2 7 3 45 \n",
"246 175 i0 1704417080 3 3 6 1 33 \n",
"247 175 i0 1704417080 3 4 6 2 22 \n",
"248 175 i0 1704417080 4 4 5 2 37 \n",
"306 175 i0 1704417260 1 1 8 4 43 \n",
"307 175 i0 1704417260 2 2 7 3 45 \n",
"308 175 i0 1704417260 3 3 6 1 33 \n",
"309 175 i0 1704417260 3 4 6 2 22 \n",
"310 175 i0 1704417260 4 4 5 2 37 \n",
"357 175 i0 1704417420 1 1 8 4 38 \n",
"358 175 i0 1704417420 2 2 7 3 40 \n",
"359 175 i0 1704417420 3 3 6 1 29 \n",
"360 175 i0 1704417420 3 4 6 2 20 \n",
"361 175 i0 1704417420 4 4 5 2 33 \n",
"\n",
" state_A state_B \n",
"44 grrrgrrrgGGGGrgrr gGGrgrrrgrrrrrgrr \n",
"45 grrGgrrrgrrrrrgrr grrrgrrrgrrrrGgrr \n",
"46 grrrgGGrgrrrrrgrr grrrgrrGgrrrrrgrr \n",
"47 grrrgGGrgrrrrrgrr grrrgrrrgrrrrrgGr \n",
"48 grrrgrrrgrrrrrgrG grrrgrrrgrrrrrgGr \n",
"109 grrrgrrrgGGGGrgrr gGGrgrrrgrrrrrgrr \n",
"110 grrGgrrrgrrrrrgrr grrrgrrrgrrrrGgrr \n",
"111 grrrgGGrgrrrrrgrr grrrgrrGgrrrrrgrr \n",
"112 grrrgGGrgrrrrrgrr grrrgrrrgrrrrrgGr \n",
"113 grrrgrrrgrrrrrgrG grrrgrrrgrrrrrgGr \n",
"173 grrrgrrrgGGGGrgrr gGGrgrrrgrrrrrgrr \n",
"174 grrGgrrrgrrrrrgrr grrrgrrrgrrrrGgrr \n",
"175 grrrgGGrgrrrrrgrr grrrgrrGgrrrrrgrr \n",
"176 grrrgGGrgrrrrrgrr grrrgrrrgrrrrrgGr \n",
"177 grrrgrrrgrrrrrgrG grrrgrrrgrrrrrgGr \n",
"244 grrrgrrrgGGGGrgrr gGGrgrrrgrrrrrgrr \n",
"245 grrGgrrrgrrrrrgrr grrrgrrrgrrrrGgrr \n",
"246 grrrgGGrgrrrrrgrr grrrgrrGgrrrrrgrr \n",
"247 grrrgGGrgrrrrrgrr grrrgrrrgrrrrrgGr \n",
"248 grrrgrrrgrrrrrgrG grrrgrrrgrrrrrgGr \n",
"306 grrrgrrrgGGGGrgrr gGGrgrrrgrrrrrgrr \n",
"307 grrGgrrrgrrrrrgrr grrrgrrrgrrrrGgrr \n",
"308 grrrgGGrgrrrrrgrr grrrgrrGgrrrrrgrr \n",
"309 grrrgGGrgrrrrrgrr grrrgrrrgrrrrrgGr \n",
"310 grrrgrrrgrrrrrgrG grrrgrrrgrrrrrgGr \n",
"357 grrrgrrrgGGGGrgrr gGGrgrrrgrrrrrgrr \n",
"358 grrGgrrrgrrrrrgrr grrrgrrrgrrrrGgrr \n",
"359 grrrgGGrgrrrrrgrr grrrgrrGgrrrrrgrr \n",
"360 grrrgGGrgrrrrrgrr grrrgrrrgrrrrrgGr \n",
"361 grrrgrrrgrrrrrgrG grrrgrrrgrrrrrgGr "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 4-3. histids\n",
"new_histids = []\n",
"for parent_id in self.parent_ids:\n",
" for child_id in self.pa2ch[parent_id]:\n",
" new_histid = self.histid.copy()[self.histid.node_id==parent_id].drop(columns=['state_A', 'state_B'])\n",
" # new_histid[['inc_edge_A', 'out_edge_A', 'inc_edge_B', 'out_edge_B']] = np.nan\n",
" for i, row in new_histid.iterrows():\n",
" phas_A = row.phas_A\n",
" phas_B = row.phas_B\n",
" new_match = self.match6[self.match6.node_id==child_id]\n",
" Arow = new_match[(new_match.phase_no==phas_A) & (new_match.ring_type=='A')]\n",
"\n",
" # A링의 state 지정\n",
" state_A = Arow.iloc[0].state\n",
" new_histid.at[i, 'state_A'] = state_A\n",
"\n",
" # B링의 state 지정\n",
" Brow = new_match[(new_match.phase_no==phas_B) & (new_match.ring_type=='B')]\n",
" state_B = Brow.iloc[0].state\n",
" new_histid.at[i, 'state_B'] = state_B\n",
"\n",
" new_histid.at[i, 'node_id'] = child_id\n",
" new_histids.append(new_histid)\n",
"import pandas as pd\n",
"new_histids = pd.concat(new_histids)\n",
"self.histids = pd.concat([self.histid.copy(), new_histids])\n",
"self.histids = self.histids.sort_values(by=['start_unix', 'node_id', 'phas_A', 'phas_B']).reset_index(drop=True)\n",
"self.histids = self.histids[['inter_no', 'node_id', 'start_unix', 'phas_A', 'phas_B', 'move_A', 'move_B', 'duration', 'state_A', 'state_B']]\n",
"self.histids.query('node_id==@Node_id')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"self.set_timepoints()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"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>node_id</th>\n",
" <th>start_unix</th>\n",
" <th>phas_A</th>\n",
" <th>phas_B</th>\n",
" <th>move_A</th>\n",
" <th>move_B</th>\n",
" <th>duration</th>\n",
" <th>state_A</th>\n",
" <th>state_B</th>\n",
" <th>phase_sumo</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704418730</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>38</td>\n",
" <td>gggggg</td>\n",
" <td>gggggg</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704418730</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>39</td>\n",
" <td>GGGggg</td>\n",
" <td>gggGGG</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704418730</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>43</td>\n",
" <td>GGGggg</td>\n",
" <td>gggGGG</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704418730</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>1</td>\n",
" <td>22</td>\n",
" <td>GGGggg</td>\n",
" <td>gggGGG</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>178</td>\n",
" <td>c30</td>\n",
" <td>1704418900</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>38</td>\n",
" <td>gggggg</td>\n",
" <td>gggggg</td>\n",
" <td>0</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>233</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704419299</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>18</td>\n",
" <td>28</td>\n",
" <td>ggggggggr</td>\n",
" <td>ggggggggr</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>234</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704419299</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>15</td>\n",
" <td>ggggggggr</td>\n",
" <td>ggggggggr</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>235</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704419299</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>43</td>\n",
" <td>ggggggggG</td>\n",
" <td>ggggggggr</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>236</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704419299</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" <td>4</td>\n",
" <td>70</td>\n",
" <td>ggggggggr</td>\n",
" <td>ggggggggr</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>237</th>\n",
" <td>210</td>\n",
" <td>u60</td>\n",
" <td>1704419299</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>8</td>\n",
" <td>3</td>\n",
" <td>24</td>\n",
" <td>ggggggggr</td>\n",
" <td>ggggggggr</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>238 rows × 11 columns</p>\n",
"</div>"
],
"text/plain": [
" inter_no node_id start_unix phas_A phas_B move_A move_B duration \\\n",
"0 178 c30 1704418730 1 1 8 4 38 \n",
"1 178 c30 1704418730 2 2 7 3 39 \n",
"2 178 c30 1704418730 3 3 5 2 43 \n",
"3 178 c30 1704418730 4 4 6 1 22 \n",
"4 178 c30 1704418900 1 1 8 4 38 \n",
".. ... ... ... ... ... ... ... ... \n",
"233 210 u60 1704419299 1 1 6 18 28 \n",
"234 210 u60 1704419299 1 2 6 2 15 \n",
"235 210 u60 1704419299 2 2 5 2 43 \n",
"236 210 u60 1704419299 3 3 7 4 70 \n",
"237 210 u60 1704419299 4 4 8 3 24 \n",
"\n",
" state_A state_B phase_sumo \n",
"0 gggggg gggggg 0 \n",
"1 GGGggg gggGGG 1 \n",
"2 GGGggg gggGGG 2 \n",
"3 GGGggg gggGGG 3 \n",
"4 gggggg gggggg 0 \n",
".. ... ... ... \n",
"233 ggggggggr ggggggggr 0 \n",
"234 ggggggggr ggggggggr 1 \n",
"235 ggggggggG ggggggggr 2 \n",
"236 ggggggggr ggggggggr 3 \n",
"237 ggggggggr ggggggggr 4 \n",
"\n",
"[238 rows x 11 columns]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.sigtable"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [],
"source": [
"# 5-2-1 helper function of 5-2\n",
"def get_red(pre_state:str, cur_state:str):\n",
" assert len(pre_state) == len(cur_state), \"cur_state, nex_state의 길이가 서로 다릅니다.\"\n",
" state_r = ''\n",
" for c, n in zip(pre_state, cur_state):\n",
" if c == n:\n",
" state_r += c\n",
" elif (c == 'r') and (n == 'G'):\n",
" state_r += 'r'\n",
" elif (c == 'G') and (n == 'r'):\n",
" state_r += 'r'\n",
" else:\n",
" raise ValueError(f\"예상치 못한 신호조합: current={c}, next={n}\")\n",
" return state_r\n",
"\n",
"# 5-2-2 helper function of 5-2\n",
"def get_yellow(cur_state:str, nex_state:str):\n",
" assert len(cur_state) == len(nex_state), \"cur_state, nex_state의 길이가 서로 다릅니다.\"\n",
" state_y = ''\n",
" for c, n in zip(cur_state, nex_state):\n",
" if c == n:\n",
" state_y += c\n",
" elif (c == 'r') and (n == 'G'):\n",
" state_y += 'r'\n",
" elif (c == 'G') and (n == 'r'):\n",
" state_y += 'y'\n",
" else:\n",
" raise ValueError(f\"예상치 못한 신호조합: current={c}, next={n}\")\n",
" return state_y\n",
"\n",
"# 5-2-3 helper function of 5-2\n",
"def cumulate(sig, alph):\n",
" csig = [] # cumulated sig\n",
" pre = pd.Series({f'phas_{alph}':None})\n",
"\n",
" start_time = 0\n",
" elapsed = 0\n",
" for i, cur in sig.iterrows():\n",
" start_unix = cur.start_unix\n",
" \n",
" # pre, nex\n",
" if i != 0:\n",
" pre = sig.iloc[i-1]\n",
" \n",
" if i != len(sig) - 1:\n",
" nex = sig.iloc[i+1]\n",
" \n",
" # duration\n",
" if cur[f'phas_{alph}'] == nex[f'phas_{alph}']:\n",
" continue\n",
" if cur[f'phas_{alph}'] == pre[f'phas_{alph}']:\n",
" duration = cur.duration + pre.duration\n",
" else:\n",
" duration = cur.duration\n",
" start_times = []\n",
" states = []\n",
" phases = []\n",
"\n",
" # red\n",
" if i != 0:\n",
" start_time += elapsed\n",
" start_times.append(start_time)\n",
" states.append(get_red(pre[f'state_{alph}'], cur[f'state_{alph}']))\n",
" phases.append(f'{cur[f\"phas_{alph}\"]}r')\n",
"\n",
" elapsed = cur[f'red_{alph}']\n",
"\n",
" # green\n",
" if i == 0:\n",
" start_time = 0\n",
" else:\n",
" start_time += elapsed\n",
" start_times.append(start_time)\n",
" states.append(cur[f'state_{alph}'])\n",
" phases.append(f'{cur[f\"phas_{alph}\"]}g')\n",
" if i == 0:\n",
" elapsed = duration - cur[f'yellow_{alph}']\n",
" else:\n",
" elapsed = duration - cur[f'yellow_{alph}'] - cur[f'red_{alph}']\n",
"\n",
" # yellow\n",
" if i != len(sig) - 1:\n",
" start_time += elapsed\n",
" start_times.append(start_time)\n",
" states.append(get_yellow(cur[f'state_{alph}'], nex[f'state_{alph}']))\n",
" phases.append(f'{cur[f\"phas_{alph}\"]}y')\n",
" elapsed = cur[f'yellow_{alph}']\n",
" sig_ = pd.DataFrame({'start_time':start_times, f'phas_{alph}':phases, f'state_{alph}':states})\n",
" sig_['start_unix'] = start_unix\n",
" csig.append(sig_)\n",
" csig = pd.concat(csig).reset_index(drop=True)\n",
" return csig"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.6227824687957764\n"
]
}
],
"source": [
"import time\n",
"now = time.time()\n",
"self.SIGTABLE = []\n",
"for node_id in self.sigtable.node_id.unique():\n",
" sig = self.sigtable.query('node_id==@node_id')\n",
" for i, row in sig.iterrows():\n",
" inter_no = row.inter_no\n",
" phas_A = row.phas_A\n",
" phas_B = row.phas_B\n",
" start_unix = row.start_unix\n",
" prow = self.load_prow(inter_no, start_unix)[1].iloc[0]\n",
" red_A = prow[f'red_A{phas_A}']\n",
" yellow_A = prow[f'yellow_A{phas_A}']\n",
" red_B = prow[f'red_B{phas_B}']\n",
" yellow_B = prow[f'yellow_B{phas_B}']\n",
" sig.loc[i, ['red_A', 'red_B', 'yellow_A', 'yellow_B']] = red_A, red_B, yellow_A, yellow_B\n",
" sig = sig.astype({'red_A': int, 'red_B': int, 'yellow_A': int, 'yellow_B': int,\n",
" 'phas_A':str, 'phas_B':str})\n",
" sig = sig.drop(['move_A','move_B'], axis=1)\n",
"\n",
" sig_A = sig[['start_unix', 'phas_A', 'duration', 'state_A', 'red_A', 'yellow_A']].reset_index(drop=True)\n",
" sig_B = sig[['start_unix', 'phas_B', 'duration', 'state_B', 'red_B', 'yellow_B']].reset_index(drop=True)\n",
"\n",
" csig_A = cumulate(sig_A, 'A')\n",
" csig_B = cumulate(sig_B, 'B')\n",
"\n",
" SIG = pd.merge(csig_A, csig_B, on=['start_time', 'start_unix'], how='outer')\n",
" SIG = SIG.sort_values(by='start_time').reset_index(drop=True)\n",
" SIG[['phas_A', 'state_A']] = SIG[['phas_A', 'state_A']].fillna(method='ffill')\n",
" SIG[['phas_B', 'state_B']] = SIG[['phas_B', 'state_B']].fillna(method='ffill')\n",
" SIG['phase'] = SIG['phas_A'] + \"_\" + SIG['phas_B']\n",
" SIG['node_id'] = node_id\n",
" SIG = SIG[['node_id', 'start_unix', 'start_time', 'phase', 'state_A', 'state_B']]\n",
" SIG['duration'] = SIG['start_time'].shift(-1) - SIG['start_time']\n",
" SIG = SIG[:-1]\n",
" SIG['duration'] = SIG['duration'].astype(int)\n",
" for row in SIG.itertuples():\n",
" state = ''\n",
" for a, b, in zip(row.state_A, row.state_B):\n",
" if a == 'r':\n",
" state += b\n",
" elif b == 'r':\n",
" state += a\n",
" elif a == b:\n",
" state += a\n",
" else:\n",
" raise ValueError(f\"예상되지 않은 조합 발생: a={a}, b={b}\")\n",
" SIG.at[row.Index, 'state'] = state\n",
" SIG = SIG.drop(columns=['start_time', 'state_A', 'state_B'])\n",
" self.SIGTABLE.append(SIG)\n",
"self.SIGTABLE = pd.concat(self.SIGTABLE)\n",
"self.SIGTABLE\n",
"print(time.time() - now)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"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",
"2. 중간산출물을 생성합니다.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"이동류정보 불러오는 중: 100%|██████████| 17280/17280 [00:14<00:00, 1200.17it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"2-1. 매칭 테이블들을 생성했습니다.\n",
"2-2. 비보호우회전(g)을 배정했습니다.\n",
"2-3. 직진 및 좌회전(G)을 배정했습니다.\n",
"2-2. node2num_cycles.json를 저장했습니다.\n",
"3. 이슈사항을 저장합니다.\n"
]
}
],
"source": [
"self = DailyPreprocessor()\n",
"self.main()"
]
},
{
"cell_type": "code",
"execution_count": 97,
"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:15<00:00, 1135.80it/s]\n"
]
}
],
"source": [
"self.load_data()\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": 99,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"이동류정보 불러오는 중: 0%| | 0/17280 [00:00<?, ?it/s]"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"이동류정보 불러오는 중: 100%|██████████| 17280/17280 [00:13<00:00, 1274.30it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"2-1. 매칭 테이블들을 생성했습니다.\n"
]
}
],
"source": [
"self.get_matches()"
]
},
{
"cell_type": "code",
"execution_count": 104,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2-2. 비보호우회전(g)을 배정했습니다.\n"
]
}
],
"source": [
"self.initialize_state()"
]
},
{
"cell_type": "code",
"execution_count": 142,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['g', 'g', 'g', 'g', 'r', 'g', 'g', 'g', 'g']"
]
},
"execution_count": 142,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.nodes = [self.net.getNode(node_id) for node_id in self.node_ids]\n",
"self.node2init = {}\n",
"# 모든 노드들을 순회\n",
"for node in self.nodes:\n",
" node_id = node.getID()\n",
" # 모든 connection\n",
" conns = [(c.getJunctionIndex(), c) for c in node.getConnections()]\n",
" conns = [c for c in conns if c[0] >= 0]\n",
" conns = sorted(conns, key=lambda x: x[0])\n",
" state = []\n",
" # i번째 connection : ci\n",
" for i, ci in conns:\n",
" if ci.getTLLinkIndex() < 0:\n",
" continue\n",
" are_foes = False\n",
" # j번째 connection : cj\n",
" # 합류지점이 다르면서 상충되는 cj가 존재하면 are_foes = True (r)\n",
" # 그외의 경우에는 are_foes = False (g)\n",
" for j, cj in conns:\n",
" # ci, cj의 합류지점이 같으면 통과\n",
" if ci.getTo() == cj.getTo():\n",
" continue\n",
" # ci, cj가 상충되면 are_foes를 True로 지정.\n",
" if node.areFoes(i, j):\n",
" are_foes = True\n",
" break\n",
" state.append('r' if are_foes else 'g')\n",
" self.node2init[node_id] = state\n",
"\n",
"# 어떤 연결과도 상충이 일어나지는 않지만, 신호가 부여되어 있는 경우에는 r을 부여\n",
"for _, row in self.matching.iterrows():\n",
" node_id = row.node_id\n",
" move_no = row.move_no\n",
" inc_edge = row.inc_edge\n",
" out_edge = row.out_edge\n",
" if move_no != 21:\n",
" inc_edge = self.net.getEdge(inc_edge)\n",
" out_edge = self.net.getEdge(out_edge)\n",
" for conn in inc_edge.getConnections(out_edge):\n",
" index = conn.getTLLinkIndex()\n",
" if index >= 0:\n",
" self.node2init[node_id][index] = 'r'\n",
"\n",
"# 연등교차로\n",
"for _, row in self.coord.iterrows():\n",
" node_id = row.node_id\n",
" inc_edge = row.inc_edge\n",
" out_edge = row.out_edge\n",
" if not (pd.isna(inc_edge) and pd.isna(out_edge)):\n",
" inc_edge = self.net.getEdge(inc_edge)\n",
" out_edge = self.net.getEdge(out_edge)\n",
" for conn in inc_edge.getConnections(out_edge):\n",
" index = conn.getTLLinkIndex()\n",
" if index >= 0:\n",
" self.node2init[node_id][index] = 'r'\n",
"\n",
"# 유턴교차로\n",
"for _, row in self.uturn.iterrows():\n",
" node_id = row.child_id\n",
" inc_edge = row.inc_edge\n",
" out_edge = row.out_edge\n",
" if not (pd.isna(inc_edge) and pd.isna(out_edge)):\n",
" inc_edge = self.net.getEdge(inc_edge)\n",
" out_edge = self.net.getEdge(out_edge)\n",
" for conn in inc_edge.getConnections(out_edge):\n",
" index = conn.getTLLinkIndex()\n",
" if index >= 0:\n",
" self.node2init[node_id][index] = 'r'\n",
"\n",
"self.node2init['u00']"
]
},
{
"cell_type": "code",
"execution_count": 135,
"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>parent_id</th>\n",
" <th>child_id</th>\n",
" <th>direction</th>\n",
" <th>condition</th>\n",
" <th>inc_edge</th>\n",
" <th>out_edge</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>i0</td>\n",
" <td>u00</td>\n",
" <td>북</td>\n",
" <td>좌회전시</td>\n",
" <td>571500487_02</td>\n",
" <td>571500487_01.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>i2</td>\n",
" <td>u20</td>\n",
" <td>북</td>\n",
" <td>보행신호시</td>\n",
" <td>571542810_01.51</td>\n",
" <td>571542810_02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>i3</td>\n",
" <td>u30</td>\n",
" <td>북</td>\n",
" <td>보행신호시</td>\n",
" <td>571556452_01</td>\n",
" <td>571556452_02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>i3</td>\n",
" <td>u31</td>\n",
" <td>동</td>\n",
" <td>보행신호시</td>\n",
" <td>571500475_02</td>\n",
" <td>571500475_01.26</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>i3</td>\n",
" <td>u32</td>\n",
" <td>서</td>\n",
" <td>보행신호시</td>\n",
" <td>571540303_02</td>\n",
" <td>-571540303_02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>i6</td>\n",
" <td>u60</td>\n",
" <td>서</td>\n",
" <td>좌회전시</td>\n",
" <td>571500535_02</td>\n",
" <td>-571500535_02</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" parent_id child_id direction condition inc_edge out_edge\n",
"0 i0 u00 북 좌회전시 571500487_02 571500487_01.32\n",
"1 i2 u20 북 보행신호시 571542810_01.51 571542810_02\n",
"2 i3 u30 북 보행신호시 571556452_01 571556452_02\n",
"3 i3 u31 동 보행신호시 571500475_02 571500475_01.26\n",
"4 i3 u32 서 보행신호시 571540303_02 -571540303_02\n",
"5 i6 u60 서 좌회전시 571500535_02 -571500535_02"
]
},
"execution_count": 135,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.uturn"
]
},
{
"cell_type": "code",
"execution_count": 108,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'c30': ['g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'i0': ['g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r'],\n",
" 'i1': ['g', 'r', 'r', 'r', 'r', 'r', 'r', 'g', 'r', 'r'],\n",
" 'i2': ['r', 'r', 'g', 'r', 'r', 'r', 'r'],\n",
" 'i3': ['g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r'],\n",
" 'i6': ['g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r'],\n",
" 'i7': ['r', 'r', 'r', 'g', 'g', 'r', 'r'],\n",
" 'i8': ['g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r'],\n",
" 'i9': ['r', 'r', 'r', 'r'],\n",
" 'u00': ['g', 'g', 'g', 'g', 'r', 'g', 'g', 'g', 'g'],\n",
" 'u20': ['g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'u30': ['g', 'g', 'g', 'g', 'r', 'g', 'g', 'g'],\n",
" 'u31': ['g', 'g', 'g', 'g', 'r', 'g', 'g', 'g'],\n",
" 'u32': ['g', 'g', 'g', 'g', 'g', 'g', 'g', 'r'],\n",
" 'u60': ['g', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'r']}"
]
},
"execution_count": 108,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.node2init"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"self.node2inter = dict(zip(self.inter_node['node_id'], self.inter_node['inter_no']))\n",
"\n",
"self.parent_ids = sorted(self.inter_node[self.inter_node.inter_type=='parent'].node_id.unique())\n",
"self.child_ids = sorted(self.inter_node[self.inter_node.inter_type=='child'].node_id.unique())\n",
"self.uturn_ids = sorted(self.uturn.child_id.unique())\n",
"self.coord_ids = sorted(self.coord.child_id.unique())\n",
"\n",
"ch2pa = {} # child to parent\n",
"for child_id in self.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"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [],
"source": [
"# 각 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",
"\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"
]
},
{
"cell_type": "code",
"execution_count": 63,
"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>178</td>\n",
" <td>1</td>\n",
" <td>A</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>c30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>1</td>\n",
" <td>B</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>c30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>571542116_01</td>\n",
" <td>-571542116_02.96</td>\n",
" <td>c30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>178</td>\n",
" <td>2</td>\n",
" <td>B</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>571542116_02.96</td>\n",
" <td>571542116_02.164</td>\n",
" <td>c30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>178</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>571542116_01</td>\n",
" <td>-571542116_02.96</td>\n",
" <td>c30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>178</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>571542116_02.96</td>\n",
" <td>571542116_02.164</td>\n",
" <td>c30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>571542116_01</td>\n",
" <td>-571542116_02.96</td>\n",
" <td>c30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>20</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>571542116_02.96</td>\n",
" <td>571542116_02.164</td>\n",
" <td>c30</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle \\\n",
"0 178 1 A 20 NaN NaN NaN \n",
"1 178 1 B 20 NaN NaN NaN \n",
"2 178 2 A 20 NaN NaN NaN \n",
"3 178 2 B 20 NaN NaN NaN \n",
"4 178 3 A 20 NaN NaN NaN \n",
"5 178 3 B 20 NaN NaN NaN \n",
"6 178 4 A 20 NaN NaN NaN \n",
"7 178 4 B 20 NaN NaN NaN \n",
"\n",
" out_angle inc_edge out_edge node_id \n",
"0 NaN NaN NaN c30 \n",
"1 NaN NaN NaN c30 \n",
"2 NaN 571542116_01 -571542116_02.96 c30 \n",
"3 NaN 571542116_02.96 571542116_02.164 c30 \n",
"4 NaN 571542116_01 -571542116_02.96 c30 \n",
"5 NaN 571542116_02.96 571542116_02.164 c30 \n",
"6 NaN 571542116_01 -571542116_02.96 c30 \n",
"7 NaN 571542116_02.96 571542116_02.164 c30 "
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\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",
"self.coord"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [],
"source": [
"# 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'))\n"
]
},
{
"cell_type": "code",
"execution_count": 94,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'c30': ['g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'i0': ['g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r'],\n",
" 'i1': ['g', 'r', 'r', 'g', 'g', 'g', 'r', 'g', 'r', 'r'],\n",
" 'i2': ['g', 'g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'i3': ['g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r'],\n",
" 'i6': ['g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r'],\n",
" 'i7': ['g', 'g', 'r', 'g', 'g', 'r', 'r'],\n",
" 'i8': ['g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r',\n",
" 'g',\n",
" 'r',\n",
" 'r',\n",
" 'r'],\n",
" 'i9': ['g', 'g', 'g', 'g'],\n",
" 'u00': ['g', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'u20': ['g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'u30': ['g', 'g', 'g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'u31': ['g', 'g', 'g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'u32': ['g', 'g', 'g', 'g', 'g', 'g', 'g', 'g'],\n",
" 'u60': ['g', 'g', 'g', 'g', 'g', 'g', 'g', 'g', 'g']}"
]
},
"execution_count": 94,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.node2init"
]
},
{
"cell_type": "code",
"execution_count": 95,
"metadata": {},
"outputs": [],
"source": [
"self.node2init = {}\n",
"node_id = 'c30'\n",
"node = self.net.getNode(node_id)\n",
"\n",
"node_id = node.getID()\n",
"# 모든 connection\n",
"conns = [(c.getJunctionIndex(), c) for c in node.getConnections()]\n",
"conns = [c for c in conns if c[0] >= 0]\n",
"conns = sorted(conns, key=lambda x: x[0])\n",
"state = []\n",
"# i번째 connection : ci\n",
"for i, ci in conns:\n",
" if ci.getTLLinkIndex() < 0:\n",
" continue\n",
" are_foes = False\n",
" # j번째 connection : cj\n",
" # 합류지점이 다르면서 상충되는 cj가 존재하면 are_foes = True (r)\n",
" # 그외의 경우에는 are_foes = False (g)\n",
" for j, cj in conns:\n",
" # ci, cj의 합류지점이 같으면 통과\n",
" if ci.getTo() == cj.getTo():\n",
" continue\n",
" # ci, cj가 상충되면 are_foes를 True로 지정.\n",
" if node.areFoes(i, j):\n",
" are_foes = True\n",
" break\n",
" state.append('r' if are_foes else 'g')\n",
"self.node2init[node_id] = state"
]
},
{
"cell_type": "code",
"execution_count": 96,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'Series' object has no attribute 'inc_edge'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[96], line 34\u001b[0m\n\u001b[0;32m 32\u001b[0m node_id \u001b[38;5;241m=\u001b[39m row\u001b[38;5;241m.\u001b[39mnode_id\n\u001b[0;32m 33\u001b[0m move_no \u001b[38;5;241m=\u001b[39m row\u001b[38;5;241m.\u001b[39mmove_no\n\u001b[1;32m---> 34\u001b[0m inc_edge \u001b[38;5;241m=\u001b[39m \u001b[43mrow\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minc_edge\u001b[49m\n\u001b[0;32m 35\u001b[0m out_edge \u001b[38;5;241m=\u001b[39m row\u001b[38;5;241m.\u001b[39mout_edge\n\u001b[0;32m 36\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m move_no \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m21\u001b[39m:\n",
"File \u001b[1;32mc:\\Github\\sts\\sts\\lib\\site-packages\\pandas\\core\\generic.py:5989\u001b[0m, in \u001b[0;36mNDFrame.__getattr__\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m 5982\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (\n\u001b[0;32m 5983\u001b[0m name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_internal_names_set\n\u001b[0;32m 5984\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_metadata\n\u001b[0;32m 5985\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_accessors\n\u001b[0;32m 5986\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_info_axis\u001b[38;5;241m.\u001b[39m_can_hold_identifiers_and_holds_name(name)\n\u001b[0;32m 5987\u001b[0m ):\n\u001b[0;32m 5988\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m[name]\n\u001b[1;32m-> 5989\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mobject\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__getattribute__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[1;31mAttributeError\u001b[0m: 'Series' object has no attribute 'inc_edge'"
]
}
],
"source": [
"self.nodes = [self.net.getNode(node_id) for node_id in self.node_ids]\n",
"self.node2init = {}\n",
"# 모든 노드들을 순회\n",
"for node in self.nodes:\n",
" node_id = node.getID()\n",
" # 모든 connection\n",
" conns = [(c.getJunctionIndex(), c) for c in node.getConnections()]\n",
" conns = [c for c in conns if c[0] >= 0]\n",
" conns = sorted(conns, key=lambda x: x[0])\n",
" state = []\n",
" # i번째 connection : ci\n",
" for i, ci in conns:\n",
" if ci.getTLLinkIndex() < 0:\n",
" continue\n",
" are_foes = False\n",
" # j번째 connection : cj\n",
" # 합류지점이 다르면서 상충되는 cj가 존재하면 are_foes = True (r)\n",
" # 그외의 경우에는 are_foes = False (g)\n",
" for j, cj in conns:\n",
" # ci, cj의 합류지점이 같으면 통과\n",
" if ci.getTo() == cj.getTo():\n",
" continue\n",
" # ci, cj가 상충되면 are_foes를 True로 지정.\n",
" if node.areFoes(i, j):\n",
" are_foes = True\n",
" break\n",
" state.append('r' if are_foes else 'g')\n",
" self.node2init[node_id] = state\n",
"\n",
"# 어떤 연결과도 상충이 일어나지는 않지만, 신호가 부여되어 있는 경우에는 r을 부여\n",
"for _, row in self.matching.iterrows():\n",
" node_id = row.node_id\n",
" move_no = row.move_no\n",
" inc_edge = row.inc_edge\n",
" out_edge = row.out_edge\n",
" if move_no != 21:\n",
" inc_edge = self.net.getEdge(inc_edge)\n",
" out_edge = self.net.getEdge(out_edge)\n",
" for conn in inc_edge.getConnections(out_edge):\n",
" index = conn.getTLLinkIndex()\n",
" if index >= 0:\n",
" self.node2init[node_id][index] = 'r'\n",
"\n",
"# 연등교차로에도 마찬가지로 신호가 부여되어 있는 경우에 r 부여\n",
"for _, row in self.coord.iterrows():\n",
" node_id = row.node_id\n",
" inc_edge = row.inc_edge\n",
" out_edge = row.out_edge\n",
" inc_edge = self.net.getEdge(inc_edge)\n",
" out_edge = self.net.getEdge(out_edge)\n",
" for conn in inc_edge.getConnections(out_edge):\n",
" index = conn.getTLLinkIndex()\n",
" if index >= 0:\n",
" self.node2init[node_id][index] = 'r'\n",
"\n",
"\n",
"# json 파일로 저장\n",
"with open(os.path.join(self.path_intermediates, 'node2init.json'), 'w') as file:\n",
" json.dump(self.node2init, file)\n"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'Pandas' object has no attribute 'inc_edge'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[48], line 9\u001b[0m\n\u001b[0;32m 7\u001b[0m node_id \u001b[38;5;241m=\u001b[39m row\u001b[38;5;241m.\u001b[39mnode_id\n\u001b[0;32m 8\u001b[0m move_no \u001b[38;5;241m=\u001b[39m row\u001b[38;5;241m.\u001b[39mmove_no\n\u001b[1;32m----> 9\u001b[0m inc_edge \u001b[38;5;241m=\u001b[39m \u001b[43mrow\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minc_edge\u001b[49m\n\u001b[0;32m 10\u001b[0m out_edge \u001b[38;5;241m=\u001b[39m row\u001b[38;5;241m.\u001b[39mout_edge\n\u001b[0;32m 11\u001b[0m state \u001b[38;5;241m=\u001b[39m copy\u001b[38;5;241m.\u001b[39mdeepcopy(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnode2init)[node_id]\n",
"\u001b[1;31mAttributeError\u001b[0m: 'Pandas' object has no attribute 'inc_edge'"
]
}
],
"source": [
"import copy\n",
"# assign signals on matching\n",
"self.matching['init_state'] = self.matching['node_id'].map(self.node2init)\n",
"self.matching['state'] = self.matching['init_state'].map(lambda x:''.join(x))\n",
"# matching의 각 행을 순회\n",
"for row in self.matching.itertuples(index=True):\n",
" node_id = row.node_id\n",
" move_no = row.move_no\n",
" inc_edge = row.inc_edge\n",
" out_edge = row.out_edge\n",
" state = copy.deepcopy(self.node2init)[node_id]\n",
"\n",
" if move_no != 21:\n",
" inc_edge = self.net.getEdge(inc_edge)\n",
" out_edge = self.net.getEdge(out_edge)\n",
" for conn in inc_edge.getConnections(out_edge):\n",
" index = conn.getTLLinkIndex()\n",
" if index >= 0:\n",
" state[index] = 'G'\n",
" self.matching.at[row.Index, 'state'] = ''.join(state)\n",
"\n",
"self.matching = self.matching.dropna(subset='state')\n",
"self.matching = self.matching.reset_index(drop=True)\n",
"self.matching = self.matching[['inter_no', 'node_id', 'move_no', 'state']]\n",
"\n",
"# assign signals on match6\n",
"\n",
"self.match6 = self.match6.reset_index(drop=True)\n",
"self.match6['init_state'] = self.match6['node_id'].map(self.node2init)\n",
"self.match6['state'] = self.match6['init_state'].map(lambda x:''.join(x))\n",
"\n",
"# match6의 각 행을 순회\n",
"for i, row in self.match6.iterrows():\n",
" node_id = row.node_id\n",
" move_no = row.move_no\n",
" inc_edge = row.inc_edge\n",
" out_edge = row.out_edge\n",
" state = copy.deepcopy(self.node2init)[node_id]\n",
" if (pd.isna(inc_edge)) or (pd.isna(out_edge)):\n",
" continue\n",
" if (move_no != 21):\n",
" # print(i, node_id, move_no, ''.join(state))\n",
" inc_edge = self.net.getEdge(inc_edge)\n",
" out_edge = self.net.getEdge(out_edge)\n",
" for conn in inc_edge.getConnections(out_edge):\n",
" index = conn.getTLLinkIndex()\n",
" if index >= 0:\n",
" state[index] = 'G'\n",
" # print(i, node_id, move_no, index, ''.join(state))\n",
" self.match6.at[i, 'state'] = ''.join(state)\n",
"\n",
"self.match6 = self.match6.dropna(subset='state')\n",
"self.match6 = self.match6.reset_index(drop=True)\n",
"self.match6 = self.match6[['inter_no', 'node_id', 'phase_no', 'ring_type', 'move_no', 'state']]\n",
"self.match6"
]
},
{
"cell_type": "code",
"execution_count": 146,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['g', 'g', 'g', 'g', 'g', 'g', 'g']\n"
]
},
{
"ename": "KeyError",
"evalue": "'i0'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[146], line 41\u001b[0m\n\u001b[0;32m 39\u001b[0m index \u001b[38;5;241m=\u001b[39m conn\u001b[38;5;241m.\u001b[39mgetTLLinkIndex()\n\u001b[0;32m 40\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m index \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m---> 41\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mnode2init\u001b[49m\u001b[43m[\u001b[49m\u001b[43mnode_id\u001b[49m\u001b[43m]\u001b[49m[index] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 43\u001b[0m \u001b[38;5;66;03m# 연등교차로에도 마찬가지로 신호가 부여되어 있는 경우에 r 부여\u001b[39;00m\n\u001b[0;32m 44\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _, row \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcoord\u001b[38;5;241m.\u001b[39miterrows():\n",
"\u001b[1;31mKeyError\u001b[0m: 'i0'"
]
}
],
"source": [
"node_id = 'i2'\n",
"node = self.net.getNode(node_id)\n",
"self.node2init = {}\n",
"# 모든 connection\n",
"conns = [(c.getJunctionIndex(), c) for c in node.getConnections()]\n",
"conns = [c for c in conns if c[0] >= 0]\n",
"conns = sorted(conns, key=lambda x: x[0])\n",
"state = []\n",
"# i번째 connection : ci\n",
"for i, ci in conns:\n",
" if ci.getTLLinkIndex() < 0:\n",
" continue\n",
" are_foes = False\n",
" # j번째 connection : cj\n",
" # 합류지점이 다르면서 상충되는 cj가 존재하면 are_foes = True (r)\n",
" # 그외의 경우에는 are_foes = False (g)\n",
" for j, cj in conns:\n",
" # ci, cj의 합류지점이 같으면 통과\n",
" if ci.getTo() == cj.getTo():\n",
" continue\n",
" # ci, cj가 상충되면 are_foes를 True로 지정.\n",
" if node.areFoes(i, j):\n",
" are_foes = True\n",
" break\n",
" state.append('r' if are_foes else 'g')\n",
"self.node2init[node_id] = state\n",
"print(state)\n",
"\n",
"# 어떤 연결과도 상충이 일어나지는 않지만, 신호가 부여되어 있는 경우에는 r을 부여\n",
"for _, row in self.matching.iterrows():\n",
" node_id = row.node_id\n",
" move_no = row.move_no\n",
" inc_edge = row.inc_edge\n",
" out_edge = row.out_edge\n",
" if move_no != 21:\n",
" inc_edge = self.net.getEdge(inc_edge)\n",
" out_edge = self.net.getEdge(out_edge)\n",
" for conn in inc_edge.getConnections(out_edge):\n",
" index = conn.getTLLinkIndex()\n",
" if index >= 0:\n",
" self.node2init[node_id][index] = 'r'"
]
},
{
"cell_type": "code",
"execution_count": 161,
"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",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>177</td>\n",
" <td>1</td>\n",
" <td>A</td>\n",
" <td>8</td>\n",
" <td>남</td>\n",
" <td>북</td>\n",
" <td>180</td>\n",
" <td>000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>177</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>176</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>177</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>7</td>\n",
" <td>북</td>\n",
" <td>동</td>\n",
" <td>000</td>\n",
" <td>090</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>177</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",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>17</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle\n",
"14 177 1 A 8 남 북 180 000\n",
"15 177 1 B 4 북 남 001 176\n",
"16 177 2 A 7 북 동 000 090\n",
"17 177 2 B 3 남 서 179 270\n",
"18 177 3 A 17 NaN NaN NaN NaN\n",
"19 177 3 B 18 NaN NaN NaN NaN\n",
"20 177 4 A 5 서 북 268 000\n",
"21 177 4 B 1 동 남 090 180"
]
},
"execution_count": 161,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.match4[self.match4.inter_no==177]"
]
},
{
"cell_type": "code",
"execution_count": 160,
"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>14</th>\n",
" <td>177</td>\n",
" <td>1</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>-571542809_01</td>\n",
" <td>571542811_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>177</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>176</td>\n",
" <td>571542811_02</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>177</td>\n",
" <td>2</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>571542811_02</td>\n",
" <td>571542107_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>177</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>-571542809_01</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>17</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>-571542809_01</td>\n",
" <td>571542811_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>571542107_02</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"14 177 1 A 8 남 북 180 000 \n",
"15 177 1 B 4 북 남 001 176 \n",
"16 177 2 A 7 북 동 000 090 \n",
"17 177 2 B 3 남 서 179 270 \n",
"18 177 3 A 17 NaN NaN NaN NaN \n",
"19 177 3 B 18 NaN NaN NaN NaN \n",
"20 177 4 A 5 서 북 268 000 \n",
"21 177 4 B 1 동 남 090 180 \n",
"\n",
" inc_edge out_edge node_id \n",
"14 -571542809_01 571542811_01 i2 \n",
"15 571542811_02 571542809_01 i2 \n",
"16 571542811_02 571542107_01 i2 \n",
"17 -571542809_01 571542809_01 i2 \n",
"18 NaN NaN i2 \n",
"19 NaN NaN i2 \n",
"20 -571542809_01 571542811_01 i2 \n",
"21 571542107_02 571542809_01 i2 "
]
},
"execution_count": 160,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"self.match5[self.match5.node_id=='i2']"
]
},
{
"cell_type": "code",
"execution_count": 151,
"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>14</th>\n",
" <td>177</td>\n",
" <td>1</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>-571542809_01</td>\n",
" <td>571542811_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>177</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>176</td>\n",
" <td>571542811_02</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>177</td>\n",
" <td>2</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>571542811_02</td>\n",
" <td>571542107_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>177</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>-571542809_01</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>17</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>-571542809_01</td>\n",
" <td>571542811_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>571542107_02</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"14 177 1 A 8 남 북 180 000 \n",
"15 177 1 B 4 북 남 001 176 \n",
"16 177 2 A 7 북 동 000 090 \n",
"17 177 2 B 3 남 서 179 270 \n",
"18 177 3 A 17 NaN NaN NaN NaN \n",
"19 177 3 B 18 NaN NaN NaN NaN \n",
"20 177 4 A 5 서 북 268 000 \n",
"21 177 4 B 1 동 남 090 180 \n",
"\n",
" inc_edge out_edge node_id \n",
"14 -571542809_01 571542811_01 i2 \n",
"15 571542811_02 571542809_01 i2 \n",
"16 571542811_02 571542107_01 i2 \n",
"17 -571542809_01 571542809_01 i2 \n",
"18 NaN NaN i2 \n",
"19 NaN NaN i2 \n",
"20 -571542809_01 571542811_01 i2 \n",
"21 571542107_02 571542809_01 i2 "
]
},
"execution_count": 151,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.match5[self.match5.node_id=='i2']"
]
},
{
"cell_type": "code",
"execution_count": 148,
"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_dir</th>\n",
" <th>out_dir</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>19</th>\n",
" <td>177</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>571542107_02</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>177</td>\n",
" <td>2</td>\n",
" <td>서</td>\n",
" <td>동</td>\n",
" <td>-571542809_01</td>\n",
" <td>571542107_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>남</td>\n",
" <td>서</td>\n",
" <td>-571542809_01</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>북</td>\n",
" <td>남</td>\n",
" <td>571542811_02</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>177</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>-571542809_01</td>\n",
" <td>571542811_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>177</td>\n",
" <td>6</td>\n",
" <td>동</td>\n",
" <td>서</td>\n",
" <td>571542107_02</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>177</td>\n",
" <td>7</td>\n",
" <td>북</td>\n",
" <td>동</td>\n",
" <td>571542811_02</td>\n",
" <td>571542107_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>177</td>\n",
" <td>8</td>\n",
" <td>남</td>\n",
" <td>북</td>\n",
" <td>-571542809_01</td>\n",
" <td>571542811_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>177</td>\n",
" <td>21</td>\n",
" <td>북</td>\n",
" <td>서</td>\n",
" <td>571542811_02</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>177</td>\n",
" <td>21</td>\n",
" <td>서</td>\n",
" <td>남</td>\n",
" <td>-571542809_01</td>\n",
" <td>571542809_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>177</td>\n",
" <td>21</td>\n",
" <td>남</td>\n",
" <td>동</td>\n",
" <td>-571542809_01</td>\n",
" <td>571542107_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>177</td>\n",
" <td>21</td>\n",
" <td>동</td>\n",
" <td>북</td>\n",
" <td>571542107_02</td>\n",
" <td>571542811_01</td>\n",
" <td>i2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no move_no inc_dir out_dir inc_edge out_edge node_id\n",
"19 177 1 동 남 571542107_02 571542809_01 i2\n",
"20 177 2 서 동 -571542809_01 571542107_01 i2\n",
"21 177 3 남 서 -571542809_01 571542809_01 i2\n",
"22 177 4 북 남 571542811_02 571542809_01 i2\n",
"23 177 5 서 북 -571542809_01 571542811_01 i2\n",
"24 177 6 동 서 571542107_02 571542809_01 i2\n",
"25 177 7 북 동 571542811_02 571542107_01 i2\n",
"26 177 8 남 북 -571542809_01 571542811_01 i2\n",
"27 177 21 북 서 571542811_02 571542809_01 i2\n",
"28 177 21 서 남 -571542809_01 571542809_01 i2\n",
"29 177 21 남 동 -571542809_01 571542107_01 i2\n",
"30 177 21 동 북 571542107_02 571542811_01 i2"
]
},
"execution_count": 148,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.matching[self.matching.node_id=='i2']"
]
},
{
"cell_type": "code",
"execution_count": 163,
"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:16<00:00, 1053.69it/s]\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()"
]
},
{
"cell_type": "code",
"execution_count": 164,
"metadata": {},
"outputs": [],
"source": [
"self.node2inter = dict(zip(self.inter_node['node_id'], self.inter_node['inter_no']))\n",
"\n",
"self.parent_ids = sorted(self.inter_node[self.inter_node.inter_type=='parent'].node_id.unique())\n",
"self.child_ids = sorted(self.inter_node[self.inter_node.inter_type=='child'].node_id.unique())\n",
"self.uturn_ids = sorted(self.uturn.child_id.unique())\n",
"self.coord_ids = sorted(self.coord.child_id.unique())\n",
"\n",
"ch2pa = {} # child to parent\n",
"for child_id in self.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방향"
]
},
{
"cell_type": "code",
"execution_count": 165,
"metadata": {},
"outputs": [],
"source": [
"# 각 uturn node에 대하여 (inc_edge_id, out_edge_id) 부여\n",
"cmatches = []"
]
},
{
"cell_type": "code",
"execution_count": 167,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"parent_id i0\n",
"child_id u00\n",
"direction 북\n",
"condition 좌회전시\n",
"inc_edge 571500487_02\n",
"out_edge 571500487_01.32\n",
"Name: 0, dtype: object\n"
]
}
],
"source": [
"row = self.uturn.iloc[0]\n",
"print(row)"
]
},
{
"cell_type": "code",
"execution_count": 172,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"u00 i0\n",
"북 좌회전시\n",
"571500487_02 571500487_01.32\n"
]
}
],
"source": [
"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",
"print(child_id, parent_id)\n",
"print(direction, condition)\n",
"print(inc_edge_id, out_edge_id)"
]
},
{
"cell_type": "code",
"execution_count": 169,
"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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>175</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>175</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>175</td>\n",
" <td>4</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>u00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\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",
"5 175 3 B 1 동 남 090 180 \n",
"6 175 4 A 5 서 북 268 000 \n",
"7 175 4 B 2 서 동 270 090 \n",
"\n",
" inc_edge out_edge node_id \n",
"0 NaN NaN u00 \n",
"1 NaN NaN u00 \n",
"2 NaN NaN u00 \n",
"3 NaN NaN u00 \n",
"4 NaN NaN u00 \n",
"5 NaN NaN u00 \n",
"6 NaN NaN u00 \n",
"7 NaN NaN u00 "
]
},
"execution_count": 169,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 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",
"cmatch"
]
},
{
"cell_type": "code",
"execution_count": 173,
"metadata": {},
"outputs": [],
"source": [
"# condition 별로 inc_dire, out_dire를 정함\n",
"ind = directions.index(direction)\n",
"if condition == \"좌회전시\":\n",
" inc_dire = direction\n",
" out_dire = directions[(ind + 2) % len(directions)]\n",
"elif condition == \"보행신호시\":\n",
" inc_dire = directions[(ind + 2) % len(directions)]\n",
" out_dire = directions[(ind - 2) % len(directions)]"
]
},
{
"cell_type": "code",
"execution_count": 174,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"북 동\n"
]
}
],
"source": [
"print(inc_dire, out_dire)"
]
},
{
"cell_type": "code",
"execution_count": 177,
"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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>175</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>북</td>\n",
" <td>동</td>\n",
" <td>001</td>\n",
" <td>095</td>\n",
" <td>571500487_02</td>\n",
" <td>571500487_01.32</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>175</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>175</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>175</td>\n",
" <td>4</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>u00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\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 19 북 동 001 095 \n",
"3 175 2 B 3 남 서 179 270 \n",
"4 175 3 A 6 동 서 090 270 \n",
"5 175 3 B 1 동 남 090 180 \n",
"6 175 4 A 5 서 북 268 000 \n",
"7 175 4 B 2 서 동 270 090 \n",
"\n",
" inc_edge out_edge node_id \n",
"0 NaN NaN u00 \n",
"1 NaN NaN u00 \n",
"2 571500487_02 571500487_01.32 u00 \n",
"3 NaN NaN u00 \n",
"4 NaN NaN u00 \n",
"5 NaN NaN u00 \n",
"6 NaN NaN u00 \n",
"7 NaN NaN u00 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# (inc_dire, out_dire) 별로 inc_edge_id, out_edge_id를 정함\n",
"cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire), ['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), 'move_no'] = 19\n",
"\n",
"display(cmatch)"
]
},
{
"cell_type": "code",
"execution_count": 185,
"metadata": {},
"outputs": [],
"source": [
"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를 정함\n",
" ind = directions.index(direction)\n",
" if condition == \"좌회전시\":\n",
" inc_dire = direction\n",
" out_dire = directions[(ind + 2) % len(directions)]\n",
" elif condition == \"보행신호시\":\n",
" inc_dire = directions[(ind + 2) % len(directions)]\n",
" out_dire = directions[(ind - 2) % len(directions)]\n",
"\n",
" # (inc_dire, out_dire) 별로 inc_edge_id, out_edge_id를 정함\n",
" cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire), ['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), 'move_no'] = 19\n",
" cmatches.append(cmatch)"
]
},
{
"cell_type": "code",
"execution_count": 191,
"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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>175</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>북</td>\n",
" <td>동</td>\n",
" <td>001</td>\n",
" <td>095</td>\n",
" <td>571500487_02</td>\n",
" <td>571500487_01.32</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>175</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>175</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>175</td>\n",
" <td>4</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>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>177</td>\n",
" <td>1</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>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>177</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>176</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>177</td>\n",
" <td>2</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>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>177</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>17</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>571542810_01.51</td>\n",
" <td>571542810_02</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>178</td>\n",
" <td>1</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>1</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>2</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>178</td>\n",
" <td>2</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>178</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>270</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>178</td>\n",
" <td>3</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>동</td>\n",
" <td>서</td>\n",
" <td>090</td>\n",
" <td>270</td>\n",
" <td>571556452_01</td>\n",
" <td>571556452_02</td>\n",
" <td>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>178</td>\n",
" <td>1</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>남</td>\n",
" <td>북</td>\n",
" <td>180</td>\n",
" <td>000</td>\n",
" <td>571500475_02</td>\n",
" <td>571500475_01.26</td>\n",
" <td>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>1</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>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>2</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>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>178</td>\n",
" <td>2</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>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>178</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>270</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>178</td>\n",
" <td>3</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>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>178</td>\n",
" <td>4</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>178</td>\n",
" <td>1</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>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>1</td>\n",
" <td>B</td>\n",
" <td>19</td>\n",
" <td>북</td>\n",
" <td>남</td>\n",
" <td>000</td>\n",
" <td>180</td>\n",
" <td>571540303_02</td>\n",
" <td>-571540303_02</td>\n",
" <td>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>2</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>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>178</td>\n",
" <td>2</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>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>178</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>270</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>178</td>\n",
" <td>3</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>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>178</td>\n",
" <td>4</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>210</td>\n",
" <td>1</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u60</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>210</td>\n",
" <td>1</td>\n",
" <td>B</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u60</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>210</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>571500535_02</td>\n",
" <td>-571500535_02</td>\n",
" <td>u60</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",
"</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 19 북 동 001 095 \n",
"3 175 2 B 3 남 서 179 270 \n",
"4 175 3 A 6 동 서 090 270 \n",
"5 175 3 B 1 동 남 090 180 \n",
"6 175 4 A 5 서 북 268 000 \n",
"7 175 4 B 2 서 동 270 090 \n",
"0 177 1 A 8 남 북 180 000 \n",
"1 177 1 B 4 북 남 001 176 \n",
"2 177 2 A 7 북 동 000 090 \n",
"3 177 2 B 3 남 서 179 270 \n",
"4 177 3 A 17 NaN NaN NaN NaN \n",
"5 177 3 B 18 NaN NaN NaN NaN \n",
"6 177 4 A 5 서 북 268 000 \n",
"7 177 4 B 1 동 남 090 180 \n",
"0 178 1 A 8 남 북 180 000 \n",
"1 178 1 B 4 북 남 000 180 \n",
"2 178 2 A 7 북 동 000 090 \n",
"3 178 2 B 3 남 서 180 270 \n",
"4 178 3 A 5 서 북 270 000 \n",
"5 178 3 B 2 서 동 270 090 \n",
"6 178 4 A 19 동 서 090 270 \n",
"7 178 4 B 1 동 남 090 180 \n",
"0 178 1 A 19 남 북 180 000 \n",
"1 178 1 B 4 북 남 000 180 \n",
"2 178 2 A 7 북 동 000 090 \n",
"3 178 2 B 3 남 서 180 270 \n",
"4 178 3 A 5 서 북 270 000 \n",
"5 178 3 B 2 서 동 270 090 \n",
"6 178 4 A 6 동 서 090 270 \n",
"7 178 4 B 1 동 남 090 180 \n",
"0 178 1 A 8 남 북 180 000 \n",
"1 178 1 B 19 북 남 000 180 \n",
"2 178 2 A 7 북 동 000 090 \n",
"3 178 2 B 3 남 서 180 270 \n",
"4 178 3 A 5 서 북 270 000 \n",
"5 178 3 B 2 서 동 270 090 \n",
"6 178 4 A 6 동 서 090 270 \n",
"7 178 4 B 1 동 남 090 180 \n",
"0 210 1 A 6 동 서 090 270 \n",
"1 210 1 B 18 NaN NaN NaN NaN \n",
"2 210 2 A 19 서 북 268 000 \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 NaN NaN u00 \n",
"1 NaN NaN u00 \n",
"2 571500487_02 571500487_01.32 u00 \n",
"3 NaN NaN u00 \n",
"4 NaN NaN u00 \n",
"5 NaN NaN u00 \n",
"6 NaN NaN u00 \n",
"7 NaN NaN u00 \n",
"0 NaN NaN u20 \n",
"1 NaN NaN u20 \n",
"2 NaN NaN u20 \n",
"3 NaN NaN u20 \n",
"4 571542810_01.51 571542810_02 u20 \n",
"5 NaN NaN u20 \n",
"6 NaN NaN u20 \n",
"7 NaN NaN u20 \n",
"0 NaN NaN u30 \n",
"1 NaN NaN u30 \n",
"2 NaN NaN u30 \n",
"3 NaN NaN u30 \n",
"4 NaN NaN u30 \n",
"5 NaN NaN u30 \n",
"6 571556452_01 571556452_02 u30 \n",
"7 NaN NaN u30 \n",
"0 571500475_02 571500475_01.26 u31 \n",
"1 NaN NaN u31 \n",
"2 NaN NaN u31 \n",
"3 NaN NaN u31 \n",
"4 NaN NaN u31 \n",
"5 NaN NaN u31 \n",
"6 NaN NaN u31 \n",
"7 NaN NaN u31 \n",
"0 NaN NaN u32 \n",
"1 571540303_02 -571540303_02 u32 \n",
"2 NaN NaN u32 \n",
"3 NaN NaN u32 \n",
"4 NaN NaN u32 \n",
"5 NaN NaN u32 \n",
"6 NaN NaN u32 \n",
"7 NaN NaN u32 \n",
"0 NaN NaN u60 \n",
"1 NaN NaN u60 \n",
"2 571500535_02 -571500535_02 u60 \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 "
]
},
"execution_count": 191,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.concat(cmatches)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"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:16<00:00, 1071.54it/s]\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()"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"u00\n"
]
},
{
"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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>175</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>북</td>\n",
" <td>동</td>\n",
" <td>001</td>\n",
" <td>095</td>\n",
" <td>571500487_02</td>\n",
" <td>571500487_01.32</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>175</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>175</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>175</td>\n",
" <td>4</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>u00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\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 19 북 동 001 095 \n",
"3 175 2 B 3 남 서 179 270 \n",
"4 175 3 A 6 동 서 090 270 \n",
"5 175 3 B 1 동 남 090 180 \n",
"6 175 4 A 5 서 북 268 000 \n",
"7 175 4 B 2 서 동 270 090 \n",
"\n",
" inc_edge out_edge node_id \n",
"0 NaN NaN u00 \n",
"1 NaN NaN u00 \n",
"2 571500487_02 571500487_01.32 u00 \n",
"3 NaN NaN u00 \n",
"4 NaN NaN u00 \n",
"5 NaN NaN u00 \n",
"6 NaN NaN u00 \n",
"7 NaN NaN u00 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"u20\n"
]
},
{
"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>177</td>\n",
" <td>1</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>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>177</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>176</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>177</td>\n",
" <td>2</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>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>177</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>17</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>571542810_01.51</td>\n",
" <td>571542810_02</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>177</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>177</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u20</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"0 177 1 A 8 남 북 180 000 \n",
"1 177 1 B 4 북 남 001 176 \n",
"2 177 2 A 7 북 동 000 090 \n",
"3 177 2 B 3 남 서 179 270 \n",
"4 177 3 A 17 NaN NaN NaN NaN \n",
"5 177 3 B 18 NaN NaN NaN NaN \n",
"6 177 4 A 5 서 북 268 000 \n",
"7 177 4 B 1 동 남 090 180 \n",
"\n",
" inc_edge out_edge node_id \n",
"0 NaN NaN u20 \n",
"1 NaN NaN u20 \n",
"2 NaN NaN u20 \n",
"3 NaN NaN u20 \n",
"4 571542810_01.51 571542810_02 u20 \n",
"5 NaN NaN u20 \n",
"6 NaN NaN u20 \n",
"7 NaN NaN u20 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"u30\n"
]
},
{
"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>178</td>\n",
" <td>1</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>1</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>2</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>178</td>\n",
" <td>2</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>178</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>270</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>178</td>\n",
" <td>3</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>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>동</td>\n",
" <td>서</td>\n",
" <td>090</td>\n",
" <td>270</td>\n",
" <td>571556452_01</td>\n",
" <td>571556452_02</td>\n",
" <td>u30</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u30</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"0 178 1 A 8 남 북 180 000 \n",
"1 178 1 B 4 북 남 000 180 \n",
"2 178 2 A 7 북 동 000 090 \n",
"3 178 2 B 3 남 서 180 270 \n",
"4 178 3 A 5 서 북 270 000 \n",
"5 178 3 B 2 서 동 270 090 \n",
"6 178 4 A 19 동 서 090 270 \n",
"7 178 4 B 1 동 남 090 180 \n",
"\n",
" inc_edge out_edge node_id \n",
"0 NaN NaN u30 \n",
"1 NaN NaN u30 \n",
"2 NaN NaN u30 \n",
"3 NaN NaN u30 \n",
"4 NaN NaN u30 \n",
"5 NaN NaN u30 \n",
"6 571556452_01 571556452_02 u30 \n",
"7 NaN NaN u30 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"u31\n"
]
},
{
"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>178</td>\n",
" <td>1</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>남</td>\n",
" <td>북</td>\n",
" <td>180</td>\n",
" <td>000</td>\n",
" <td>571500475_02</td>\n",
" <td>571500475_01.26</td>\n",
" <td>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>1</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>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>2</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>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>178</td>\n",
" <td>2</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>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>178</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>270</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>178</td>\n",
" <td>3</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>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>178</td>\n",
" <td>4</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u31</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"0 178 1 A 19 남 북 180 000 \n",
"1 178 1 B 4 북 남 000 180 \n",
"2 178 2 A 7 북 동 000 090 \n",
"3 178 2 B 3 남 서 180 270 \n",
"4 178 3 A 5 서 북 270 000 \n",
"5 178 3 B 2 서 동 270 090 \n",
"6 178 4 A 6 동 서 090 270 \n",
"7 178 4 B 1 동 남 090 180 \n",
"\n",
" inc_edge out_edge node_id \n",
"0 571500475_02 571500475_01.26 u31 \n",
"1 NaN NaN u31 \n",
"2 NaN NaN u31 \n",
"3 NaN NaN u31 \n",
"4 NaN NaN u31 \n",
"5 NaN NaN u31 \n",
"6 NaN NaN u31 \n",
"7 NaN NaN u31 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"u32\n"
]
},
{
"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>178</td>\n",
" <td>1</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>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>178</td>\n",
" <td>1</td>\n",
" <td>B</td>\n",
" <td>19</td>\n",
" <td>북</td>\n",
" <td>남</td>\n",
" <td>000</td>\n",
" <td>180</td>\n",
" <td>571540303_02</td>\n",
" <td>-571540303_02</td>\n",
" <td>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>178</td>\n",
" <td>2</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>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>178</td>\n",
" <td>2</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>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>178</td>\n",
" <td>3</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>270</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>178</td>\n",
" <td>3</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>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>178</td>\n",
" <td>4</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>178</td>\n",
" <td>4</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u32</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"0 178 1 A 8 남 북 180 000 \n",
"1 178 1 B 19 북 남 000 180 \n",
"2 178 2 A 7 북 동 000 090 \n",
"3 178 2 B 3 남 서 180 270 \n",
"4 178 3 A 5 서 북 270 000 \n",
"5 178 3 B 2 서 동 270 090 \n",
"6 178 4 A 6 동 서 090 270 \n",
"7 178 4 B 1 동 남 090 180 \n",
"\n",
" inc_edge out_edge node_id \n",
"0 NaN NaN u32 \n",
"1 571540303_02 -571540303_02 u32 \n",
"2 NaN NaN u32 \n",
"3 NaN NaN u32 \n",
"4 NaN NaN u32 \n",
"5 NaN NaN u32 \n",
"6 NaN NaN u32 \n",
"7 NaN NaN u32 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"u60\n"
]
},
{
"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>210</td>\n",
" <td>1</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u60</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>210</td>\n",
" <td>1</td>\n",
" <td>B</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u60</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>210</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>571500535_02</td>\n",
" <td>-571500535_02</td>\n",
" <td>u60</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",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"0 210 1 A 6 동 서 090 270 \n",
"1 210 1 B 18 NaN NaN NaN NaN \n",
"2 210 2 A 19 서 북 268 000 \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 NaN NaN u60 \n",
"1 NaN NaN u60 \n",
"2 571500535_02 -571500535_02 u60 \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 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"self.node2inter = dict(zip(self.inter_node['node_id'], self.inter_node['inter_no']))\n",
"\n",
"self.parent_ids = sorted(self.inter_node[self.inter_node.inter_type=='parent'].node_id.unique())\n",
"self.child_ids = sorted(self.inter_node[self.inter_node.inter_type=='child'].node_id.unique())\n",
"self.uturn_ids = sorted(self.uturn.child_id.unique())\n",
"self.coord_ids = sorted(self.coord.child_id.unique())\n",
"\n",
"ch2pa = {} # child to parent\n",
"for child_id in self.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를 정함\n",
" ind = directions.index(direction)\n",
" if condition == \"좌회전시\":\n",
" inc_dire = direction\n",
" out_dire = directions[(ind + 2) % len(directions)]\n",
" elif condition == \"보행신호시\":\n",
" inc_dire = directions[(ind + 2) % len(directions)]\n",
" out_dire = directions[(ind - 2) % len(directions)]\n",
"\n",
" # (inc_dire, out_dire) 별로 inc_edge_id, out_edge_id를 정함\n",
" cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire), ['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), 'move_no'] = 19\n",
" print(child_id)\n",
" display(cmatch)\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'))\n"
]
},
{
"cell_type": "code",
"execution_count": 58,
"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>inc</th>\n",
" <th>out</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>105.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>NaN</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inc out\n",
"0 1.0 105.0\n",
"1 2.0 NaN\n",
"2 NaN 5.0\n",
"3 NaN NaN"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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>inc</th>\n",
" <th>out</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inc out\n",
"0 True True\n",
"1 True False\n",
"2 False True\n",
"3 False False"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 True\n",
"1 False\n",
"2 False\n",
"3 False\n",
"dtype: bool\n",
"inc False\n",
"out False\n",
"dtype: bool\n"
]
}
],
"source": [
"bdf = pd.DataFrame({'inc':[1, 2, np.nan, np.nan], 'out':[105, np.nan, 5, np.nan]})\n",
"display(bdf)\n",
"display(bdf.notna())\n",
"print(bdf.notna().all(axis=1))\n",
"print(bdf.notna().all(axis=0))\n"
]
},
{
"cell_type": "code",
"execution_count": 59,
"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>inc</th>\n",
" <th>out</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>NaN</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inc out\n",
"0 2.0 NaN\n",
"1 NaN 5.0\n",
"2 NaN NaN"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" inc out\n",
"0 False True\n",
"1 True False\n",
"2 True True\n",
"0 True\n",
"1 True\n",
"2 True\n",
"dtype: bool\n",
"True\n"
]
}
],
"source": [
"bdf = pd.DataFrame({'inc':[2, np.nan, np.nan], 'out':[np.nan, 5, np.nan]})\n",
"display(bdf)\n",
"# print((bdf[['inc','out']].notna()))\n",
"# print((bdf[['inc','out']].notna()).all(axis=1))\n",
"# print((bdf[['inc','out']].notna()).all(axis=1).any())\n",
"print((bdf[['inc','out']].isna()))\n",
"print((bdf[['inc','out']].isna()).any(axis=1))\n",
"print(bdf[['inc','out']].isna().any(axis=1).all())"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" inc_edge out_edge\n",
"0 False False\n",
"1 False False\n",
"2 True True\n",
"3 False False\n",
"4 False False\n",
"5 False False\n",
"6 False False\n",
"7 False False\n",
"0 False\n",
"1 False\n",
"2 True\n",
"3 False\n",
"4 False\n",
"5 False\n",
"6 False\n",
"7 False\n",
"dtype: bool\n",
"True\n"
]
}
],
"source": [
"\n",
"print(cmatch[['inc_edge','out_edge']].notna())\n",
"print((cmatch[['inc_edge','out_edge']].notna()).all(axis=1))\n",
"print((cmatch[['inc_edge','out_edge']].notna()).all(axis=1).any())"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cmatch[['inc_edge','out_edge']].isna().any(axis=1).all()"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"서\n",
"북\n"
]
}
],
"source": [
"print(inc_dire)\n",
"print(out_dire)"
]
},
{
"cell_type": "code",
"execution_count": 63,
"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>210</td>\n",
" <td>1</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u60</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>210</td>\n",
" <td>1</td>\n",
" <td>B</td>\n",
" <td>18</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u60</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>210</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>571500535_02</td>\n",
" <td>-571500535_02</td>\n",
" <td>u60</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",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"0 210 1 A 6 동 서 090 270 \n",
"1 210 1 B 18 NaN NaN NaN NaN \n",
"2 210 2 A 19 서 북 268 000 \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 NaN NaN u60 \n",
"1 NaN NaN u60 \n",
"2 571500535_02 -571500535_02 u60 \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 "
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cmatch"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"((cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire)).any()"
]
},
{
"cell_type": "code",
"execution_count": 65,
"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>2</th>\n",
" <td>210</td>\n",
" <td>2</td>\n",
" <td>A</td>\n",
" <td>19</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>571500535_02</td>\n",
" <td>-571500535_02</td>\n",
" <td>u60</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" inter_no phase_no ring_type move_no inc_dir out_dir inc_angle out_angle \\\n",
"2 210 2 A 19 서 북 268 000 \n",
"\n",
" inc_edge out_edge node_id \n",
"2 571500535_02 -571500535_02 u60 "
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire)]"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1. 데이터를 로드합니다.\n",
"1-1. 네트워크가 로드되었습니다.\n",
"1-2. 테이블들이 로드되었습니다.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1-3. 네트워크의 모든 clean state requirement들을 체크했습니다.\n",
"1-4. 테이블들의 무결성 검사를 완료했습니다.\n"
]
}
],
"source": [
"self.load_data()\n",
"self.node2inter = dict(zip(self.inter_node['node_id'], self.inter_node['inter_no']))\n",
"\n",
"self.parent_ids = sorted(self.inter_node[self.inter_node.inter_type=='parent'].node_id.unique())\n",
"self.child_ids = sorted(self.inter_node[self.inter_node.inter_type=='child'].node_id.unique())\n",
"self.uturn_ids = sorted(self.uturn.child_id.unique())\n",
"self.coord_ids = sorted(self.coord.child_id.unique())\n",
"\n",
"ch2pa = {} # child to parent\n",
"for child_id in self.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"
]
},
{
"cell_type": "code",
"execution_count": 67,
"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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</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>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>175</td>\n",
" <td>3</td>\n",
" <td>B</td>\n",
" <td>1</td>\n",
" <td>동</td>\n",
" <td>남</td>\n",
" <td>090</td>\n",
" <td>180</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>175</td>\n",
" <td>4</td>\n",
" <td>A</td>\n",
" <td>5</td>\n",
" <td>서</td>\n",
" <td>북</td>\n",
" <td>268</td>\n",
" <td>000</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>u00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>175</td>\n",
" <td>4</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>u00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\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",
"5 175 3 B 1 동 남 090 180 \n",
"6 175 4 A 5 서 북 268 000 \n",
"7 175 4 B 2 서 동 270 090 \n",
"\n",
" inc_edge out_edge node_id \n",
"0 NaN NaN u00 \n",
"1 NaN NaN u00 \n",
"2 NaN NaN u00 \n",
"3 NaN NaN u00 \n",
"4 NaN NaN u00 \n",
"5 NaN NaN u00 \n",
"6 NaN NaN u00 \n",
"7 NaN NaN u00 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"row = self.uturn.iloc[0]\n",
"\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",
"\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",
"display(cmatch)"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
"ind = directions.index(direction)\n",
"inc_dire_right = direction\n",
"out_dire_right = directions[(ind + 2) % len(directions)]\n",
"inc_dire_pedes = directions[(ind + 2) % len(directions)]\n",
"out_dire_pedes = directions[(ind - 2) % len(directions)]\n",
"\n",
"if condition == \"좌회전시\":\n",
" inc_dire = inc_dire_right\n",
" out_dire = out_dire_right\n",
"elif condition == \"보행신호시\":\n",
" inc_dire = inc_dire_pedes\n",
" out_dire = out_dire_pedes\n",
"pedes_condition = ((cmatch.inc_dir==inc_dire_pedes) & (cmatch.out_dir==out_dire_pedes)).any()\n",
"right_condition = ((cmatch.inc_dir==inc_dire_right) & (cmatch.out_dir==out_dire_right)).any()\n"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [],
"source": [
"# 각 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를 정함\n",
" ind = directions.index(direction)\n",
" if condition == \"좌회전시\":\n",
" inc_dire = direction\n",
" out_dire = directions[(ind + 2) % len(directions)]\n",
" elif condition == \"보행신호시\":\n",
" inc_dire = directions[(ind + 2) % len(directions)]\n",
" out_dire = directions[(ind - 2) % len(directions)]\n",
"\n",
" # (inc_dire, out_dire) 별로 inc_edge_id, out_edge_id를 정함\n",
" cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire), ['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",
"\n",
" # 만약 어떤 유턴신호도 배정되지 않았다면, 보행신호시 > 좌회전시 > 전적색이동류발생시 > 보행신호이동류발생시 순으로 유턴신호를 배정한다.\n",
" uturn_not_assigned = cmatch[['inc_edge','out_edge']].isna().any(axis=1).all()\n",
" if uturn_not_assigned:\n",
" # 보행신호시\n",
" inc_dire_pedes = directions[(ind + 2) % len(directions)]\n",
" out_dire_pedes = directions[(ind - 2) % len(directions)]\n",
" # 좌회전시\n",
" inc_dire_right = direction\n",
" out_dire_right = directions[(ind + 2) % len(directions)]\n",
"\n",
" # 보행신호시의 inc_dir, out_dir 존재\n",
" pedes_exists = ((cmatch.inc_dir==inc_dire_pedes) & (cmatch.out_dir==out_dire_pedes))\n",
" right_exists = ((cmatch.inc_dir==inc_dire_right) & (cmatch.out_dir==out_dire_right))\n",
" all_redsigns = cmatch.move_no == 18\n",
" crosswalk_on = cmatch.move_no == 17\n",
" \n",
" if pedes_exists.any():\n",
" cmatch.loc[pedes_exists, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
" elif right_exists.any():\n",
" cmatch.loc[right_exists, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
" elif all_redsigns.any():\n",
" cmatch.loc[all_redsigns, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
" elif crosswalk_on.any():\n",
" cmatch.loc[crosswalk_on & (cmatch.out_dir!=direction), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
"\n",
" # 유턴신호의 이동류번호를 19로 부여한다.\n",
" cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire), 'move_no'] = 19\n"
]
},
{
"cell_type": "code",
"execution_count": 92,
"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": [
"이동류정보 불러오는 중: 68%|██████▊ | 11723/17280 [01:23<00:39, 140.43it/s] \n",
"이동류정보 불러오는 중: 100%|██████████| 17280/17280 [00:14<00:00, 1174.55it/s]\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": 166,
"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>parent_id</th>\n",
" <th>child_id</th>\n",
" <th>direction</th>\n",
" <th>condition</th>\n",
" <th>inc_edge</th>\n",
" <th>out_edge</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>i0</td>\n",
" <td>u00</td>\n",
" <td>북</td>\n",
" <td>좌회전시</td>\n",
" <td>571500487_02</td>\n",
" <td>571500487_01.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>i2</td>\n",
" <td>u20</td>\n",
" <td>북</td>\n",
" <td>보행신호시</td>\n",
" <td>571542810_01.51</td>\n",
" <td>571542810_02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>i3</td>\n",
" <td>u30</td>\n",
" <td>북</td>\n",
" <td>보행신호시</td>\n",
" <td>571556452_01</td>\n",
" <td>571556452_02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>i3</td>\n",
" <td>u31</td>\n",
" <td>동</td>\n",
" <td>보행신호시</td>\n",
" <td>571500475_02</td>\n",
" <td>571500475_01.26</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>i3</td>\n",
" <td>u32</td>\n",
" <td>서</td>\n",
" <td>보행신호시</td>\n",
" <td>571540303_02</td>\n",
" <td>-571540303_02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>i6</td>\n",
" <td>u60</td>\n",
" <td>서</td>\n",
" <td>좌회전시</td>\n",
" <td>571500535_02</td>\n",
" <td>-571500535_02</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" parent_id child_id direction condition inc_edge out_edge\n",
"0 i0 u00 북 좌회전시 571500487_02 571500487_01.32\n",
"1 i2 u20 북 보행신호시 571542810_01.51 571542810_02\n",
"2 i3 u30 북 보행신호시 571556452_01 571556452_02\n",
"3 i3 u31 동 보행신호시 571500475_02 571500475_01.26\n",
"4 i3 u32 서 보행신호시 571540303_02 -571540303_02\n",
"5 i6 u60 서 좌회전시 571500535_02 -571500535_02"
]
},
"execution_count": 166,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"self.uturn"
]
},
{
"cell_type": "code",
"execution_count": 227,
"metadata": {},
"outputs": [],
"source": [
"# 각 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",
"\n",
" # match5에서 부모노드id에 해당하는 행들을 가져옴 (cmatch)\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",
" # 보행신호시/좌회전시 진입/진출방향\n",
" ind = directions.index(direction)\n",
" inc_dire_pedes = directions[(ind + 2) % len(directions)]\n",
" out_dire_pedes = directions[(ind - 2) % len(directions)]\n",
" inc_dire_right = direction\n",
" out_dire_right = directions[(ind + 2) % len(directions)]\n",
"\n",
" # 보행신호시/좌회전시 조건\n",
" pedes_exists = (cmatch.inc_dir==inc_dire_pedes) & (cmatch.out_dir==out_dire_pedes)\n",
" right_exists = (cmatch.inc_dir==inc_dire_right) & (cmatch.out_dir==out_dire_right)\n",
"\n",
" # 보행신호시/좌회전시 진입/진출 엣지id 배정\n",
" ind = directions.index(direction)\n",
" if condition == \"보행신호시\":\n",
" cmatch.loc[pedes_exists, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
" elif condition == \"좌회전시\":\n",
" cmatch.loc[right_exists, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
"\n",
" # 신호없음이동류발생시/보행신호이동류발생시 조건\n",
" all_redsigns = cmatch.move_no == 18\n",
" crosswalk_on = cmatch.move_no == 17\n",
"\n",
" # 만약 어떤 유턴신호도 배정되지 않았다면\n",
" # 신호없음이동류발생시 → 보행신호이동류발생시 → 보행신호시 → 좌회전시 순으로 진입/진출 엣지id 배정\n",
" uturn_not_assigned = cmatch[['inc_edge','out_edge']].isna().any(axis=1).all()\n",
" if uturn_not_assigned:\n",
" # 신호없음이동류(18) 발생시\n",
" if all_redsigns.any():\n",
" cmatch.loc[all_redsigns, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
" # 보행신호이동류(17) 발생시\n",
" elif crosswalk_on.any():\n",
" cmatch.loc[crosswalk_on & (cmatch.out_dir!=direction), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
" # 보행신호시\n",
" elif pedes_exists.any():\n",
" cmatch.loc[pedes_exists, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]\n",
" # 좌회전시\n",
" elif right_exists.any():\n",
" cmatch.loc[right_exists, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 유턴신호 부여 로직\n",
"## 입력 1. `self.match5`\n",
"- 컬럼목록 : 노드id, 현시번호, 링타입, 이동류번호, 진입/진출방향, 진입/진출엣지id\n",
"- 설명 : 부모교차로에 대한 매칭정보\n",
"\n",
"## 입력 2. `self.uturn`\n",
"- 컬럼목록 : 부모노드id, 자식노드id, 진입방향, 조건, 진입/진출방향\n",
"- 설명 : 유턴에 대한 정보\n",
"- 여기에서 조건이란 \"좌회전시\" 또는 \"보행신호시\" 또는 \"\"(지정되지 않음) 중 하나임.\n",
"\n",
"## 출력 : `self.match6`\n",
"- 컬럼목록 : `self.match5와` 같음\n",
"- 설명 : 부모 및 자식교차로에 대한 매칭정보 (자식교차로 : 유턴교차로, 연등교차로)\n",
"\n",
"## 유턴신호 부여 알고리즘\n",
"\n",
"## 요약 :\n",
"각 유턴노드별로 `self.match5`에서 해당되는 행들을 가져오고 (이것을 `cmatch`라고 한다.)\n",
"조건별로 `cmatch`에서 해당되는 행에 진입/진출엣지id를 지정한다. \n",
"\n",
"## 상세:\n",
"각 유턴 노드에 대하여 `cmatch`를 다음과 같이 정한다.\n",
"\n",
"- (1) `cmatch`\n",
" - (1-1) 부모노드의 `self.match5`에 해당하는 데이터프레임(`cmatch`)을 가져온다.\n",
" - (1-2) `node_id`는 자식노드id로 부여하고, 진입/진출엣지id는 `np.nan`으로 초기화한다.\n",
"- (2) 조건이 \"좌회전시\", \"보행신호시\"이면\n",
" - (2-1) 그에 따라 진입/진출방향을 정한다. (8방위)\n",
" - (2-2) `cmatch`에서 진입/진출방향에 대응되는 행에 진입/진출엣지id를 지정한다.\n",
"- (3) 조건이 지정되지 않았거나,\n",
" 조건이 지정되었어도 진입/진출방향에 대응되는 행이 존재하지 않으면\n",
" 보행신호이동류발생시 → 전적색이동류발생시 → 보행신호시 → 좌회전시 순으로 유턴신호를 정한다.\n",
" - (3-1) 신호없음이동류발생시\n",
" \n",
" 이동류번호가 18(신호없음)인 행이 cmatch에 존재하면\n",
" 해당 행에 진입/진출엣지id를 지정한다.\n",
" - (3-2) 보행신호이동류발생시\n",
" \n",
" 3-1에 해당하지 않고, 이동류번호가 17(보행신호이동류)인 행이 `cmatch`에 존재하며\n",
" 유턴노드 방향으로 진출하는 신호가 없으면\n",
" 해당 행에 진입/진출엣지id를 지정한다.\n",
" - (3-3) 보행신호시\n",
" \n",
" 3-1, 3-2에 해당하지 않고\n",
" 보행신호에 대응되는 진입/진출방향에 대한 행이 `cmatch`에 존재하면\n",
" 해당 행에 진입/진출엣지id를 지정한다.\n",
" - (3-4) 좌회전시\n",
" \n",
" 3-1, 3-2, 3-3에 해당하지 않고\n",
" 좌회전에 대응되는 진입/진출방향에 대한 행이 `cmatch`에 존재하면\n",
" 해당 행에 진입/진출엣지id를 지정한다.\n",
" - (3-5) 3-1 ~ 3-4에 해당되지 않는다면 유턴신호가 지정되지 않는다.\n",
"\n",
"## 이후과정:\n",
"각 유턴노드에 대한 `cmatch`들을 리스트 형태로 저장한 후 `pd.concat`하여 합친다 (`cmatches`).\n",
"연동교차로에 대해서도 비슷한 종류의 테이블을 만들어둔다. (`self.coord`, 상세 생성과정 생략)\n",
"`self.match5`, `cmatches`, `self.coord를` `pd.concat`하여 `self.match6`를 만든다."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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
}