Browse Source

rename : dir -> dire (four or eight directions is reperesented by the variable name 'dire' rather than 'dir')

master
김선중 1 year ago
parent
commit
9722d453f7
4 changed files with 621 additions and 797 deletions
  1. +16
    -0
      .vscode/launch.json
  2. +1
    -1
      Data/tables/nema.csv
  3. +564
    -681
      Results/sn_1704418800.add.xml
  4. +40
    -115
      Scripts/preprocess_daily.py

+ 16
- 0
.vscode/launch.json View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": "${command:pickArgs}"
}
]
}

+ 1
- 1
Data/tables/nema.csv View File

@ -1,4 +1,4 @@
move_no,inc_dir,out_dir
move_no,inc_dire,out_dire
1,동,남 1,동,남
2,서,동 2,서,동
3,남,서 3,남,서

+ 564
- 681
Results/sn_1704418800.add.xml
File diff suppressed because it is too large
View File


+ 40
- 115
Scripts/preprocess_daily.py View File

@ -254,7 +254,7 @@ class DailyPreprocessor():
''' '''
match2의 , match2의 ,
: inter_no, phase_no, ring_type, move_no, inc_dir, out_dir
: inter_no, phase_no, ring_type, move_no, inc_dire, out_dire
''' '''
# nema 정보 불러오기 및 병합 # nema 정보 불러오기 및 병합
self.match3 = pd.merge(self.match2, self.nema, how='left', on='move_no').drop_duplicates() self.match3 = pd.merge(self.match2, self.nema, how='left', on='move_no').drop_duplicates()
@ -264,7 +264,7 @@ class DailyPreprocessor():
''' '''
match3의 , match3의 ,
: inter_no, phase_no, ring_type, move_no, inc_dir, out_dir, inc_angle, out_angle
: inter_no, phase_no, ring_type, move_no, inc_dire, out_dire, inc_angle, out_angle
''' '''
# # 계층화 # # 계층화
@ -312,29 +312,10 @@ class DailyPreprocessor():
# 2-1-5 # 2-1-5
def make_match5(self): def make_match5(self):
''' '''
id, id, id를 ().
- match4의 : inter_no, phase_no, ring_type, move_no, inc_dir, out_dir, inc_angle, out_angle
- match5의 : inter_no, phase_no, ring_type, move_no, inc_dir, out_dir, inc_angle, out_angle, inc_edge, out_edge, node_id
:
(1) net
-
(2) inter_node
- id를 .
- parent/child
- : inter_no, node_id, inter_type
(3) inter_info
- . .
- : inter_no, inter_name, inter_lat, inter_lon, group_no, main_phase_no
id, id를 :
- match5 = match4.copy() .
*
- ID를 , id를 inc_edges에 .
* inc_edge() : incoming edge, out_edge() : outgoing_edge
- inc_edges의 (inc_dires, 2 ) .
- () .
- inc_edge_id로 .
match4의 id, id id
* , id를 : cosine similarity
: inter_no, phase_no, ring_type, move_no, inc_dire, out_dire, inc_angle, out_angle, inc_edge, out_edge, node_id
''' '''
# parent node만 가져옴. # parent node만 가져옴.
@ -392,53 +373,9 @@ class DailyPreprocessor():
# 2-1-6 # 2-1-6
def make_match6(self): def make_match6(self):
''' '''
id, id, id를 ().
- match6의 : inter_no, phase_no, ring_type, move_no, inc_dir, out_dir, inc_angle, out_angle, inc_edge, out_edge, node_id
:
(1) inter_node
- id를 .
- parent/child
- : inter_no, node_id, inter_type
(2) uturn ()
- : parent_id, child_id, direction, condition, inc_edge, out_edge
- parent_id, child_id : id, id
- direction : ()
- condition : , , ,
- inc_edge, out_edge :
(3) coord ()
- : parent_id, child_id, phase_no, ring_type, inc_edge, out_edge
- parent_id, child_id : id, id
- : (, )
:
- match5는 id, id, id를 .
uturn, coord를 (, ) .
:
- directions를 8 .
- , , (, ) .
- ) (direction) '' ,
- : (, )
* : directions[(ind + 4) % len(directions)]
- : (, )
* : directions[(ind + 2) % len(directions)]
- : (, )
* : directions[(ind - 2) % len(directions)]
- uturn의
- match5에서 parent_id에 (cmatch).
- condition , .
- directions를 .
- (, ) (, ) id, id를 .
- ex) cmatch.loc[(cmatch.inc_dir==inc_dire) & (cmatch.out_dir==out_dire), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]
- cmatch를 cmatchs라는 .
:
- coord에 (, ) ID, ID가 .
- 'inc_dir', 'out_dir', 'inc_angle','out_angle' np.nan을 .
- , np.nan으로 .
match6 :
- match5, cmatchs, coord를 pd.concat하여 match6을 .
match5에서 (, )
: inter_no, phase_no, ring_type, move_no, inc_dire, out_dire, inc_angle, out_angle, inc_edge, out_edge, node_id
''' '''
self.node2inter = dict(zip(self.inter_node['node_id'], self.inter_node['inter_no'])) self.node2inter = dict(zip(self.inter_node['node_id'], self.inter_node['inter_no']))
@ -489,8 +426,8 @@ class DailyPreprocessor():
out_dire_right = self.directions[(ind + 2) % len(self.directions)] out_dire_right = self.directions[(ind + 2) % len(self.directions)]
# 보행신호시/좌회전시 조건 # 보행신호시/좌회전시 조건
pedes_exists = (cmatch.inc_dir==inc_dire_pedes) & (cmatch.out_dir==out_dire_pedes)
right_exists = (cmatch.inc_dir==inc_dire_right) & (cmatch.out_dir==out_dire_right)
pedes_exists = (cmatch.inc_dire==inc_dire_pedes) & (cmatch.out_dire==out_dire_pedes)
right_exists = (cmatch.inc_dire==inc_dire_right) & (cmatch.out_dire==out_dire_right)
# 보행신호시/좌회전시 진입/진출 엣지id 배정 # 보행신호시/좌회전시 진입/진출 엣지id 배정
ind = self.directions.index(direction) ind = self.directions.index(direction)
@ -515,18 +452,18 @@ class DailyPreprocessor():
cmatch.loc[pedes_exists, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id] cmatch.loc[pedes_exists, ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]
# 보행신호이동류(17) 발생시 # 보행신호이동류(17) 발생시
elif crosswalk_on.any(): elif crosswalk_on.any():
cmatch.loc[crosswalk_on & (cmatch.out_dir!=direction), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]
cmatch.loc[crosswalk_on & (cmatch.out_dire!=direction), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]
# 신호없음이동류(18) 발생시 # 신호없음이동류(18) 발생시
elif all_redsigns.any(): elif all_redsigns.any():
cmatch.loc[all_redsigns & (cmatch.out_dir!=direction), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]
cmatch.loc[all_redsigns & (cmatch.out_dire!=direction), ['inc_edge', 'out_edge']] = [inc_edge_id, out_edge_id]
cmatches.append(cmatch) cmatches.append(cmatch)
# 각 연등교차로(coordination node)에 대하여 (inc_edge_id, out_edge_id) 부여 # 각 연등교차로(coordination node)에 대하여 (inc_edge_id, out_edge_id) 부여
self.coord['inter_no'] = self.coord['parent_id'].map(self.node2inter) self.coord['inter_no'] = self.coord['parent_id'].map(self.node2inter)
self.coord = self.coord.rename(columns={'child_id':'node_id'}) self.coord = self.coord.rename(columns={'child_id':'node_id'})
self.coord[['inc_dir', 'out_dir', 'inc_angle','out_angle']] = np.nan
self.coord[['inc_dire', 'out_dire', 'inc_angle','out_angle']] = np.nan
self.coord['move_no'] = 20 self.coord['move_no'] = 20
self.coord = self.coord[['inter_no', 'phase_no', 'ring_type', 'move_no', 'inc_dir', 'out_dir', 'inc_angle','out_angle', 'inc_edge_id', 'out_edge_id', 'node_id']]
self.coord = self.coord[['inter_no', 'phase_no', 'ring_type', 'move_no', 'inc_dire', 'out_dire', 'inc_angle','out_angle', 'inc_edge_id', 'out_edge_id', 'node_id']]
# display(coord) # display(coord)
cmatches = pd.concat(cmatches) cmatches = pd.concat(cmatches)
@ -537,50 +474,38 @@ class DailyPreprocessor():
# 2-1-7 # 2-1-7
def make_matching(self): def make_matching(self):
''' '''
: , (1~18, 21) ·ID를 .
, · ID를 .
- matching의 : inter_no, move_no, inc_dir, out_dir, inc_edge, out_edge, node_id
:
- ,
(1) (, ) []
(2) : pdires (possible directions) []
(3) (, ) id : inc2id (incoming direction to incoming edge_id) []
(4) (, ) id : out2id (outgoing direction to outgoing edge_id) []
(5) (, ) : pflow (possible flows) []
- matching은 .
- id에
- id에 (, )
- (id, ) id를 . id도
- (new_row) matching에 append
, (1~18, 21) ·ID를
*
: inter_no, move_no, inc_dire, out_dire, inc_edge, out_edge, node_id
''' '''
self.match7 = self.match6.copy() self.match7 = self.match6.copy()
self.match7 = self.match7[['inter_no', 'move_no', 'inc_dir', 'out_dir', 'inc_edge', 'out_edge', 'node_id']]
self.match7 = self.match7[['inter_no', 'move_no', 'inc_dire', 'out_dire', 'inc_edge', 'out_edge', 'node_id']]
# parent_ids = sorted(self.inter_node[self.inter_node.inter_type=='parent'].node_id.unique()) # parent_ids = sorted(self.inter_node[self.inter_node.inter_type=='parent'].node_id.unique())
# child_ids = sorted(self.inter_node[self.inter_node.inter_type=='child'].node_id.unique()) # child_ids = sorted(self.inter_node[self.inter_node.inter_type=='child'].node_id.unique())
# (1) 가능한 (진입방향, 진출방향) 목록 # (1) 가능한 (진입방향, 진출방향) 목록
flows = self.nema.dropna().apply(lambda row: (row['inc_dir'], row['out_dir']), axis=1).tolist()
flows = self.nema.dropna().apply(lambda row: (row['inc_dire'], row['out_dire']), axis=1).tolist()
# (2) 각 교차로별 방향 목록 : pdires (possible directions) # (2) 각 교차로별 방향 목록 : pdires (possible directions)
pdires = {} pdires = {}
for node_id in self.parent_ids: for node_id in self.parent_ids:
dires = self.match7[self.match7.node_id == node_id][['inc_dir','out_dir']].values.flatten()
dires = self.match7[self.match7.node_id == node_id][['inc_dire','out_dire']].values.flatten()
dires = {dire for dire in dires if type(dire)==str} dires = {dire for dire in dires if type(dire)==str}
pdires[node_id] = dires pdires[node_id] = dires
# (3) 각 (교차로, 진입방향) 별 진입id 목록 : inc2id (incoming direction to incoming edge_id) # (3) 각 (교차로, 진입방향) 별 진입id 목록 : inc2id (incoming direction to incoming edge_id)
inc2id = {} inc2id = {}
for node_id in self.parent_ids: for node_id in self.parent_ids:
for inc_dir in pdires[node_id]:
df = self.match7[(self.match7.node_id==node_id) & (self.match7.inc_dir==inc_dir)]
inc2id[(node_id, inc_dir)] = df.inc_edge.iloc[0]
for inc_dire in pdires[node_id]:
df = self.match7[(self.match7.node_id==node_id) & (self.match7.inc_dire==inc_dire)]
inc2id[(node_id, inc_dire)] = df.inc_edge.iloc[0]
# (4) 각 (교차로, 진출방향) 별 진출id 목록 : out2id (outgoing direction to outgoing edge_id) # (4) 각 (교차로, 진출방향) 별 진출id 목록 : out2id (outgoing direction to outgoing edge_id)
out2id = {} out2id = {}
for node_id in self.parent_ids: for node_id in self.parent_ids:
for out_dir in pdires[node_id]:
df = self.match7[(self.match7.node_id==node_id) & (self.match7.out_dir==out_dir)]
out2id[(node_id, out_dir)] = df.out_edge.iloc[0]
for out_dire in pdires[node_id]:
df = self.match7[(self.match7.node_id==node_id) & (self.match7.out_dire==out_dire)]
out2id[(node_id, out_dire)] = df.out_edge.iloc[0]
# (5) 각 교차로별 가능한 (진입방향, 진출방향) 목록 : pflow (possible flows) # (5) 각 교차로별 가능한 (진입방향, 진출방향) 목록 : pflow (possible flows)
pflow = {} pflow = {}
for node_id in self.parent_ids: for node_id in self.parent_ids:
@ -592,28 +517,28 @@ class DailyPreprocessor():
for node_id in self.parent_ids: for node_id in self.parent_ids:
inter_no = self.node2inter[node_id] inter_no = self.node2inter[node_id]
# 좌회전과 직진(1 ~ 16) # 좌회전과 직진(1 ~ 16)
for (inc_dir, out_dir) in pflow[node_id]:
move_no = self.nema[(self.nema.inc_dir==inc_dir) & (self.nema.out_dir==out_dir)].move_no.iloc[0]
inc_edge = inc2id[(node_id, inc_dir)]
out_edge = out2id[(node_id, out_dir)]
for (inc_dire, out_dire) in pflow[node_id]:
move_no = self.nema[(self.nema.inc_dire==inc_dire) & (self.nema.out_dire==out_dire)].move_no.iloc[0]
inc_edge = inc2id[(node_id, inc_dire)]
out_edge = out2id[(node_id, out_dire)]
new_row = pd.DataFrame({'inter_no':[inter_no], 'move_no':[move_no], new_row = pd.DataFrame({'inter_no':[inter_no], 'move_no':[move_no],
'inc_dir':[inc_dir], 'out_dir':[out_dir],
'inc_dire':[inc_dire], 'out_dire':[out_dire],
'inc_edge':[inc_edge], 'out_edge':[out_edge], 'node_id':[node_id]}) 'inc_edge':[inc_edge], 'out_edge':[out_edge], 'node_id':[node_id]})
self.matching.append(new_row) self.matching.append(new_row)
# 보행신호(17), 전적색(18) # 보행신호(17), 전적색(18)
new_row = pd.DataFrame({'inter_no':[inter_no] * 2, 'move_no':[17, 18], new_row = pd.DataFrame({'inter_no':[inter_no] * 2, 'move_no':[17, 18],
'inc_dir':[None]*2, 'out_dir':[None]*2,
'inc_dire':[None]*2, 'out_dire':[None]*2,
'inc_edge':[None]*2, 'out_edge':[None]*2, 'node_id':[node_id]*2}) 'inc_edge':[None]*2, 'out_edge':[None]*2, 'node_id':[node_id]*2})
self.matching.append(new_row) self.matching.append(new_row)
# 신호우회전(21) # 신호우회전(21)
for d in range(len(dires_right)-1): for d in range(len(dires_right)-1):
inc_dir = dires_right[d]
out_dir = dires_right[d+1]
if {inc_dir, out_dir}.issubset(pdires[node_id]):
inc_edge = inc2id[(node_id, inc_dir)]
out_edge = out2id[(node_id, out_dir)]
inc_dire = dires_right[d]
out_dire = dires_right[d+1]
if {inc_dire, out_dire}.issubset(pdires[node_id]):
inc_edge = inc2id[(node_id, inc_dire)]
out_edge = out2id[(node_id, out_dire)]
new_row = pd.DataFrame({'inter_no':[inter_no], 'move_no':[21], new_row = pd.DataFrame({'inter_no':[inter_no], 'move_no':[21],
'inc_dir':[inc_dir], 'out_dir':[out_dir],
'inc_dire':[inc_dire], 'out_dire':[out_dire],
'inc_edge':[inc_edge], 'out_edge':[out_edge], 'node_id':[node_id]}) 'inc_edge':[inc_edge], 'out_edge':[out_edge], 'node_id':[node_id]})
self.matching.append(new_row) self.matching.append(new_row)
self.matching.append(self.match7[self.match7.node_id.isin(self.child_ids)]) self.matching.append(self.match7[self.match7.node_id.isin(self.child_ids)])

Loading…
Cancel
Save