|
@ -14,7 +14,7 @@ class DailyPreprocessor(): |
|
|
self.path_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
|
self.path_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
|
with open(os.path.join(self.path_root, 'configs', f'config_{self.config_name}.json'), 'r') as config_file: |
|
|
with open(os.path.join(self.path_root, 'configs', f'config_{self.config_name}.json'), 'r') as config_file: |
|
|
config = json.load(config_file) |
|
|
config = json.load(config_file) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 주요 폴더 경로 지정 |
|
|
# 주요 폴더 경로 지정 |
|
|
self.paths = config['paths'] |
|
|
self.paths = config['paths'] |
|
|
self.path_data = os.path.join(self.path_root, *self.paths['data']) |
|
|
self.path_data = os.path.join(self.path_root, *self.paths['data']) |
|
@ -27,6 +27,7 @@ class DailyPreprocessor(): |
|
|
# 이슈사항 목록 |
|
|
# 이슈사항 목록 |
|
|
self.issues = [] |
|
|
self.issues = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 1. 데이터 불러오기 |
|
|
# 1. 데이터 불러오기 |
|
|
def load_data(self): |
|
|
def load_data(self): |
|
|
print('1. 데이터를 로드합니다.') |
|
|
print('1. 데이터를 로드합니다.') |
|
@ -37,11 +38,13 @@ class DailyPreprocessor(): |
|
|
self.standardize() |
|
|
self.standardize() |
|
|
self.store_objects() |
|
|
self.store_objects() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 1-1. 네트워크 불러오기 |
|
|
# 1-1. 네트워크 불러오기 |
|
|
def load_networks(self): |
|
|
def load_networks(self): |
|
|
self.net = sumolib.net.readNet(self.path_network) |
|
|
self.net = sumolib.net.readNet(self.path_network) |
|
|
print("1-1. 네트워크가 로드되었습니다.") |
|
|
print("1-1. 네트워크가 로드되었습니다.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 1-2. 테이블 불러오기 |
|
|
# 1-2. 테이블 불러오기 |
|
|
def load_tables(self): |
|
|
def load_tables(self): |
|
|
if self.config_name == 'draft': |
|
|
if self.config_name == 'draft': |
|
@ -160,6 +163,7 @@ class DailyPreprocessor(): |
|
|
|
|
|
|
|
|
print("1-2. 테이블들이 로드되었습니다.") |
|
|
print("1-2. 테이블들이 로드되었습니다.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 1-3. 네트워크 무결성 검사 |
|
|
# 1-3. 네트워크 무결성 검사 |
|
|
def check_networks(self): |
|
|
def check_networks(self): |
|
|
# https://sumo.dlr.de/docs/Netedit/neteditUsageExamples.html#simplify_tls_program_state_after_changing_connections |
|
|
# https://sumo.dlr.de/docs/Netedit/neteditUsageExamples.html#simplify_tls_program_state_after_changing_connections |
|
@ -184,6 +188,7 @@ class DailyPreprocessor(): |
|
|
traci.close() |
|
|
traci.close() |
|
|
print("1-3. 네트워크의 모든 clean state requirement들을 체크했습니다.") |
|
|
print("1-3. 네트워크의 모든 clean state requirement들을 체크했습니다.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 1-4. 테이블 무결성 검사 |
|
|
# 1-4. 테이블 무결성 검사 |
|
|
def check_tables(self): |
|
|
def check_tables(self): |
|
|
self.check_plan() |
|
|
self.check_plan() |
|
@ -191,6 +196,7 @@ class DailyPreprocessor(): |
|
|
self.check_angle() |
|
|
self.check_angle() |
|
|
print("1-4. 테이블들의 무결성 검사를 완료했습니다.") |
|
|
print("1-4. 테이블들의 무결성 검사를 완료했습니다.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 1-4-1. 신호계획(plan) 검사 |
|
|
# 1-4-1. 신호계획(plan) 검사 |
|
|
def check_plan(self): |
|
|
def check_plan(self): |
|
|
# 1-4-1-1. inter_no 검사 |
|
|
# 1-4-1-1. inter_no 검사 |
|
@ -242,6 +248,7 @@ class DailyPreprocessor(): |
|
|
msg = f"1-4-1-5. inter_no:{inc_inter_no}, A링현시시간의 합과 B링현시시간의 합이 일치하지 않거나, 현시시간의 합과 주기가 일치하지 않습니다." |
|
|
msg = f"1-4-1-5. inter_no:{inc_inter_no}, A링현시시간의 합과 B링현시시간의 합이 일치하지 않거나, 현시시간의 합과 주기가 일치하지 않습니다." |
|
|
self.issues.append(msg) |
|
|
self.issues.append(msg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 1-4-2. 교차로정보(inter_info) 검사 |
|
|
# 1-4-2. 교차로정보(inter_info) 검사 |
|
|
def check_inter_info(self): |
|
|
def check_inter_info(self): |
|
|
# 1-4-2-1. inter_lat, inter_lon 적절성 검사 |
|
|
# 1-4-2-1. inter_lat, inter_lon 적절성 검사 |
|
@ -255,6 +262,7 @@ class DailyPreprocessor(): |
|
|
msg = f"1-4-2-1. 위도 또는 경도가 범위를 벗어난 교차로가 있습니다: inter_no : {row['inter_no']}" |
|
|
msg = f"1-4-2-1. 위도 또는 경도가 범위를 벗어난 교차로가 있습니다: inter_no : {row['inter_no']}" |
|
|
self.issues.append(msg) |
|
|
self.issues.append(msg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 1-4-3. 방위각정보(inter_info) 검사 |
|
|
# 1-4-3. 방위각정보(inter_info) 검사 |
|
|
def check_angle(self): |
|
|
def check_angle(self): |
|
|
# 1-4-3-1. inter_no 검사 |
|
|
# 1-4-3-1. inter_no 검사 |
|
@ -444,6 +452,7 @@ class DailyPreprocessor(): |
|
|
|
|
|
|
|
|
print("1-6. 주요 객체 (리스트, 딕셔너리)들을 저장했습니다.") |
|
|
print("1-6. 주요 객체 (리스트, 딕셔너리)들을 저장했습니다.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2. 중간산출물 만들기 |
|
|
# 2. 중간산출물 만들기 |
|
|
def get_intermediates(self): |
|
|
def get_intermediates(self): |
|
|
print('2. 중간산출물을 생성합니다.') |
|
|
print('2. 중간산출물을 생성합니다.') |
|
@ -454,6 +463,7 @@ class DailyPreprocessor(): |
|
|
self.avoid_all_reds() |
|
|
self.avoid_all_reds() |
|
|
self.save_intermediates() |
|
|
self.save_intermediates() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-1 매칭테이블 생성 |
|
|
# 2-1 매칭테이블 생성 |
|
|
def get_matches(self): |
|
|
def get_matches(self): |
|
|
self.make_match1() |
|
|
self.make_match1() |
|
@ -465,6 +475,7 @@ class DailyPreprocessor(): |
|
|
self.make_matching() |
|
|
self.make_matching() |
|
|
print('2-1. 매칭 테이블들을 생성했습니다.') |
|
|
print('2-1. 매칭 테이블들을 생성했습니다.') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-1-1 |
|
|
# 2-1-1 |
|
|
def make_match1(self, fetch_all:bool=False): |
|
|
def make_match1(self, fetch_all:bool=False): |
|
|
''' |
|
|
''' |
|
@ -493,6 +504,7 @@ class DailyPreprocessor(): |
|
|
else: |
|
|
else: |
|
|
self.match1 = pd.read_csv(os.path.join(self.path_intermediates, 'match1.csv')) |
|
|
self.match1 = pd.read_csv(os.path.join(self.path_intermediates, 'match1.csv')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-1-2 |
|
|
# 2-1-2 |
|
|
def make_match2(self): |
|
|
def make_match2(self): |
|
|
''' |
|
|
''' |
|
@ -511,6 +523,7 @@ class DailyPreprocessor(): |
|
|
self.match2 = self.match2[['inter_no', 'phase_no', 'ring_type', 'move_no']] |
|
|
self.match2 = self.match2[['inter_no', 'phase_no', 'ring_type', 'move_no']] |
|
|
self.match2 = self.match2.sort_values(by=list(self.match2.columns)) |
|
|
self.match2 = self.match2.sort_values(by=list(self.match2.columns)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-1-3 |
|
|
# 2-1-3 |
|
|
def make_match3(self): |
|
|
def make_match3(self): |
|
|
''' |
|
|
''' |
|
@ -521,6 +534,7 @@ class DailyPreprocessor(): |
|
|
# 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() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-1-4 |
|
|
# 2-1-4 |
|
|
def make_match4(self): |
|
|
def make_match4(self): |
|
|
''' |
|
|
''' |
|
@ -558,6 +572,7 @@ class DailyPreprocessor(): |
|
|
self.match4.at[i, 'inc_angle'] = im2inc_angle[(inter_no, move_no)] |
|
|
self.match4.at[i, 'inc_angle'] = im2inc_angle[(inter_no, move_no)] |
|
|
self.match4.at[i, 'out_angle'] = im2out_angle[(inter_no, move_no)] |
|
|
self.match4.at[i, 'out_angle'] = im2out_angle[(inter_no, move_no)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-1-5 |
|
|
# 2-1-5 |
|
|
def make_match5(self): |
|
|
def make_match5(self): |
|
|
''' |
|
|
''' |
|
@ -633,6 +648,7 @@ class DailyPreprocessor(): |
|
|
turn_type = io2turn[(inc_edge_id, out_edge_id)] |
|
|
turn_type = io2turn[(inc_edge_id, out_edge_id)] |
|
|
self.match5.at[i, 'turn_type'] = turn_type |
|
|
self.match5.at[i, 'turn_type'] = turn_type |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-1-6 |
|
|
# 2-1-6 |
|
|
def make_match6(self): |
|
|
def make_match6(self): |
|
|
''' |
|
|
''' |
|
@ -772,6 +788,7 @@ class DailyPreprocessor(): |
|
|
self.match6 = pd.concat([self.match5, cmatches, self.coord]).drop_duplicates().sort_values(by=['inter_no', 'node_id', 'phase_no', 'ring_type']) |
|
|
self.match6 = pd.concat([self.match5, cmatches, self.coord]).drop_duplicates().sort_values(by=['inter_no', 'node_id', 'phase_no', 'ring_type']) |
|
|
self.match6 = self.match6.reset_index(drop=True) |
|
|
self.match6 = self.match6.reset_index(drop=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-1-7 |
|
|
# 2-1-7 |
|
|
def make_matching(self): |
|
|
def make_matching(self): |
|
|
''' |
|
|
''' |
|
@ -898,6 +915,7 @@ class DailyPreprocessor(): |
|
|
.sort_values(by=['inter_no', 'node_id', 'move_no']).reset_index(drop=True) |
|
|
.sort_values(by=['inter_no', 'node_id', 'move_no']).reset_index(drop=True) |
|
|
self.matching['move_no'] = self.matching['move_no'].astype(int) |
|
|
self.matching['move_no'] = self.matching['move_no'].astype(int) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-2 신호 초기화 |
|
|
# 2-2 신호 초기화 |
|
|
def initialize_state(self): |
|
|
def initialize_state(self): |
|
|
''' |
|
|
''' |
|
@ -1017,6 +1035,7 @@ class DailyPreprocessor(): |
|
|
self.p2UPLindices2inc_edge_ids[parent_id][UPLindex] = inc_edge_ids |
|
|
self.p2UPLindices2inc_edge_ids[parent_id][UPLindex] = inc_edge_ids |
|
|
print('2-3. 유턴 인덱스 / 비보호좌회전 인덱스를 지정했습니다.') |
|
|
print('2-3. 유턴 인덱스 / 비보호좌회전 인덱스를 지정했습니다.') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2-4 신호배정 |
|
|
# 2-4 신호배정 |
|
|
def assign_signals(self): |
|
|
def assign_signals(self): |
|
|
# matching : 신호 배정 |
|
|
# matching : 신호 배정 |
|
@ -1184,6 +1203,7 @@ class DailyPreprocessor(): |
|
|
for review in self.issues: |
|
|
for review in self.issues: |
|
|
print(review) |
|
|
print(review) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(self): |
|
|
def main(self): |
|
|
# 1. 데이터 불러오기 |
|
|
# 1. 데이터 불러오기 |
|
|
self.load_data() |
|
|
self.load_data() |
|
@ -1192,6 +1212,7 @@ class DailyPreprocessor(): |
|
|
# 3. 이슈사항 저장 |
|
|
# 3. 이슈사항 저장 |
|
|
self.write_issues() |
|
|
self.write_issues() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
parser = argparse.ArgumentParser() |
|
|
parser = argparse.ArgumentParser() |
|
|
parser.add_argument('-c','--config_name', dest='config_name', type=str, default='revised') |
|
|
parser.add_argument('-c','--config_name', dest='config_name', type=str, default='revised') |
|
|