From 4bbf22b101b0b83e9e513cb223392794b6e60394 Mon Sep 17 00:00:00 2001 From: thgcMtdh Date: Thu, 17 Nov 2022 16:06:10 +0900 Subject: [PATCH 1/3] fix dia for only local train --- backend/auto_operation/DiaPlanner.py | 163 ++++++++++++++------------- 1 file changed, 82 insertions(+), 81 deletions(-) diff --git a/backend/auto_operation/DiaPlanner.py b/backend/auto_operation/DiaPlanner.py index 6ffc840c..6c15d70d 100644 --- a/backend/auto_operation/DiaPlanner.py +++ b/backend/auto_operation/DiaPlanner.py @@ -44,44 +44,44 @@ def __init__(self, state: State) -> None: # ダイヤ自動更新の初期値を記述 def setup(self) -> None: - # 初期値として、列車0は八王子経由の特急とする + # 初期値として、列車0は八王子経由の特急とする→各停に変更 self.setDia(0, "shinjuku_down", False, 5, "shinjuku_b2", "shinjuku_b1") - self.setDia(0, "sakurajosui_down", False, 0, "sakurajosui_b2", "sakurajosui_b5") + self.setDia(0, "sakurajosui_down", False, 0, "sakurajosui_b1", "sakurajosui_b5") self.setDia(0, "chofu_down", False, 5, "chofu_b2", "chofu_b4") self.setDia(0, "hachioji_down", False, 5, "chofu_b4", "hachioji_b1") self.setDia(0, "hachioji_up", False, 5, "hachioji_b1", "hachioji_b2") self.setDia(0, "chofu_up", False, 5, "hachioji_b2", "chofu_b5") - self.setDia(0, "sakurajosui_up", False, 0, "sakurajosui_b3", "sakurajosui_b6") + self.setDia(0, "sakurajosui_up", False, 0, "sakurajosui_b4", "sakurajosui_b6") self.setDia(0, "shinjuku_up", False, 5, "sakurajosui_b6", "shinjuku_b2") # 初期値として、列車1は八王子経由の普通とする self.setDia(1, "shinjuku_down", False, 5, "shinjuku_b2", "shinjuku_b1") - self.setDia(1, "sakurajosui_down", True, 5, "sakurajosui_b1", "sakurajosui_b5") + self.setDia(1, "sakurajosui_down", False, 5, "sakurajosui_b1", "sakurajosui_b5") self.setDia(1, "chofu_down", False, 5, "chofu_b2", "chofu_b4") self.setDia(1, "hachioji_down", False, 5, "chofu_b4", "hachioji_b1") self.setDia(1, "hachioji_up", False, 5, "hachioji_b1", "hachioji_b2") self.setDia(1, "chofu_up", False, 5, "hachioji_b2", "chofu_b5") - self.setDia(1, "sakurajosui_up", True, 5, "sakurajosui_b4", "sakurajosui_b6") + self.setDia(1, "sakurajosui_up", False, 5, "sakurajosui_b4", "sakurajosui_b6") self.setDia(1, "shinjuku_up", False, 5, "sakurajosui_b6", "shinjuku_b2") - # 初期値として、列車2は橋本経由の特急とする + # 初期値として、列車2は橋本経由の特急とする→各停に変更 self.setDia(2, "shinjuku_down", False, 5, "shinjuku_b2", "shinjuku_b1") - self.setDia(2, "sakurajosui_down", False, 0, "sakurajosui_b2", "sakurajosui_b5") + self.setDia(2, "sakurajosui_down", False, 0, "sakurajosui_b1", "sakurajosui_b5") self.setDia(2, "chofu_down", False, 5, "chofu_b1", "chofu_b3") self.setDia(2, "hashimoto_down", False, 5, "chofu_b3", "hashimoto_b1") self.setDia(2, "hashimoto_up", False, 5, "hashimoto_b1", "hashimoto_b2") self.setDia(2, "chofu_up", False, 5, "hashimoto_b2", "chofu_b5") - self.setDia(2, "sakurajosui_up", False, 0, "sakurajosui_b3", "sakurajosui_b6") + self.setDia(2, "sakurajosui_up", False, 0, "sakurajosui_b4", "sakurajosui_b6") self.setDia(2, "shinjuku_up", False, 5, "sakurajosui_b6", "shinjuku_b2") # 初期値として、列車3は橋本経由の普通とする self.setDia(3, "shinjuku_down", False, 5, "shinjuku_b2", "shinjuku_b1") - self.setDia(3, "sakurajosui_down", True, 5, "sakurajosui_b1", "sakurajosui_b5") + self.setDia(3, "sakurajosui_down", False, 5, "sakurajosui_b1", "sakurajosui_b5") self.setDia(3, "chofu_down", False, 5, "chofu_b1", "chofu_b3") self.setDia(3, "hashimoto_down", False, 5, "chofu_b3", "hashimoto_b1") self.setDia(3, "hashimoto_up", False, 5, "hashimoto_b1", "hashimoto_b2") self.setDia(3, "chofu_up", False, 5, "hashimoto_b2", "chofu_b5") - self.setDia(3, "sakurajosui_up", True, 5, "sakurajosui_b4", "sakurajosui_b6") + self.setDia(3, "sakurajosui_up", False, 5, "sakurajosui_b4", "sakurajosui_b6") self.setDia(3, "shinjuku_up", False, 5, "sakurajosui_b6", "shinjuku_b2") # ダイヤ自動更新のルールを記述. 毎update時によぶ @@ -104,77 +104,78 @@ def update(self) -> None: # self.setDia(1, 1, False, 0, 2, 4) # print("[DiaPlanner.update] wait flag switched!") - # 桜上水下り線で退避していた列車の退避終了処理 - waitingTrain = self.__state.getTrainInSection( - self.__state.getSectionById("sakurajosui_b1") - ) # 桜上水下り退避線にいる列車 - if waitingTrain is not None and self.getDia(waitingTrain.id, "sakurajosui_down").wait: - for train in self.__state.trainList: - # sectionが変化した瞬間だけ、mileageがprevmileageより小さくなることを利用し、桜上水を出発した下り列車がいるか判断。いれば、追い抜きに成功したので、退避していたほうの退避フラグをリセット - if ( - train.currentSection.id == "sakurajosui_b5" - and train.mileage < train.prevMileage - ): - self.setDia( - waitingTrain.id, - "sakurajosui_down", - False, - 5, - "sakurajosui_b1", - "sakurajosui_b5", - ) - print(f"[DiaPlanner.update] train {waitingTrain.id} wait finish!") - # 退避を終えて出発した各停列車の退避フラグを再びTrueに戻す - sakurajosuiDepartedTrain = self.__state.getTrainInSection( - self.__state.getSectionById("sakurajosui_b5") - ) # 桜上水下りを出発後の列車を取得 - if sakurajosuiDepartedTrain is not None and ( - sakurajosuiDepartedTrain.id == 1 or sakurajosuiDepartedTrain.id == 3 - ): # 各停列車なら - self.setDia( - sakurajosuiDepartedTrain.id, - "sakurajosui_down", - True, - 5, - "sakurajosui_b1", - "sakurajosui_b5", - ) - - # 桜上水上り線で退避していた列車の退避終了処理 - waitingTrain = self.__state.getTrainInSection( - self.__state.getSectionById("sakurajosui_b4") - ) # 桜上水上り退避線にいる列車 - if waitingTrain is not None and self.getDia(waitingTrain.id, "sakurajosui_up").wait: - for train in self.__state.trainList: - # sectionが変化した瞬間だけ、mileageがprevmileageより小さくなることを利用し、桜上水を出発した上り列車がいるか判断。いれば、追い抜きに成功したので、退避していたほうの退避フラグをリセット - if ( - train.currentSection.id == "sakurajosui_b6" - and train.mileage < train.prevMileage - ): - self.setDia( - waitingTrain.id, - "sakurajosui_up", - False, - 5, - "sakurajosui_b4", - "sakurajosui_b6", - ) - print(f"[DiaPlanner.update] train {waitingTrain.id} wait finish!") - # 退避を終えて出発した各停列車の退避フラグを再びTrueに戻す - sakurajosuiDepartedTrain = self.__state.getTrainInSection( - self.__state.getSectionById("sakurajosui_b6") - ) # 桜上水上りを出発後の列車を取得 - if sakurajosuiDepartedTrain is not None and ( - sakurajosuiDepartedTrain.id == 1 or sakurajosuiDepartedTrain.id == 3 - ): # 各停列車なら - self.setDia( - sakurajosuiDepartedTrain.id, - "sakurajosui_up", - True, - 5, - "sakurajosui_b4", - "sakurajosui_b6", - ) + # いったん追い抜き関係アルゴリズムをコメントアウト + # # 桜上水下り線で退避していた列車の退避終了処理 + # waitingTrain = self.__state.getTrainInSection( + # self.__state.getSectionById("sakurajosui_b1") + # ) # 桜上水下り退避線にいる列車 + # if waitingTrain is not None and self.getDia(waitingTrain.id, "sakurajosui_down").wait: + # for train in self.__state.trainList: + # # sectionが変化した瞬間だけ、mileageがprevmileageより小さくなることを利用し、桜上水を出発した下り列車がいるか判断。いれば、追い抜きに成功したので、退避していたほうの退避フラグをリセット + # if ( + # train.currentSection.id == "sakurajosui_b5" + # and train.mileage < train.prevMileage + # ): + # self.setDia( + # waitingTrain.id, + # "sakurajosui_down", + # False, + # 5, + # "sakurajosui_b1", + # "sakurajosui_b5", + # ) + # print(f"[DiaPlanner.update] train {waitingTrain.id} wait finish!") + # # 退避を終えて出発した各停列車の退避フラグを再びTrueに戻す + # sakurajosuiDepartedTrain = self.__state.getTrainInSection( + # self.__state.getSectionById("sakurajosui_b5") + # ) # 桜上水下りを出発後の列車を取得 + # if sakurajosuiDepartedTrain is not None and ( + # sakurajosuiDepartedTrain.id == 1 or sakurajosuiDepartedTrain.id == 3 + # ): # 各停列車なら + # self.setDia( + # sakurajosuiDepartedTrain.id, + # "sakurajosui_down", + # True, + # 5, + # "sakurajosui_b1", + # "sakurajosui_b5", + # ) + + # # 桜上水上り線で退避していた列車の退避終了処理 + # waitingTrain = self.__state.getTrainInSection( + # self.__state.getSectionById("sakurajosui_b4") + # ) # 桜上水上り退避線にいる列車 + # if waitingTrain is not None and self.getDia(waitingTrain.id, "sakurajosui_up").wait: + # for train in self.__state.trainList: + # # sectionが変化した瞬間だけ、mileageがprevmileageより小さくなることを利用し、桜上水を出発した上り列車がいるか判断。いれば、追い抜きに成功したので、退避していたほうの退避フラグをリセット + # if ( + # train.currentSection.id == "sakurajosui_b6" + # and train.mileage < train.prevMileage + # ): + # self.setDia( + # waitingTrain.id, + # "sakurajosui_up", + # False, + # 5, + # "sakurajosui_b4", + # "sakurajosui_b6", + # ) + # print(f"[DiaPlanner.update] train {waitingTrain.id} wait finish!") + # # 退避を終えて出発した各停列車の退避フラグを再びTrueに戻す + # sakurajosuiDepartedTrain = self.__state.getTrainInSection( + # self.__state.getSectionById("sakurajosui_b6") + # ) # 桜上水上りを出発後の列車を取得 + # if sakurajosuiDepartedTrain is not None and ( + # sakurajosuiDepartedTrain.id == 1 or sakurajosuiDepartedTrain.id == 3 + # ): # 各停列車なら + # self.setDia( + # sakurajosuiDepartedTrain.id, + # "sakurajosui_up", + # True, + # 5, + # "sakurajosui_b4", + # "sakurajosui_b6", + # ) # 指定した列車の、指定した駅に対するダイヤを取得 def getDia(self, trainId: int, stationId: Station.StationId) -> Dia: From 6a1ecd49056fc35cfeac9c33ad1d286c2031c2bd Mon Sep 17 00:00:00 2001 From: thgcMtdh Date: Fri, 18 Nov 2022 09:20:06 +0900 Subject: [PATCH 2/3] dont use sakurajosui_b1 (use b2 and b4) --- backend/auto_operation/DiaPlanner.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/auto_operation/DiaPlanner.py b/backend/auto_operation/DiaPlanner.py index 6c15d70d..065a5bcb 100644 --- a/backend/auto_operation/DiaPlanner.py +++ b/backend/auto_operation/DiaPlanner.py @@ -46,7 +46,7 @@ def __init__(self, state: State) -> None: def setup(self) -> None: # 初期値として、列車0は八王子経由の特急とする→各停に変更 self.setDia(0, "shinjuku_down", False, 5, "shinjuku_b2", "shinjuku_b1") - self.setDia(0, "sakurajosui_down", False, 0, "sakurajosui_b1", "sakurajosui_b5") + self.setDia(0, "sakurajosui_down", False, 0, "sakurajosui_b2", "sakurajosui_b5") self.setDia(0, "chofu_down", False, 5, "chofu_b2", "chofu_b4") self.setDia(0, "hachioji_down", False, 5, "chofu_b4", "hachioji_b1") self.setDia(0, "hachioji_up", False, 5, "hachioji_b1", "hachioji_b2") @@ -56,7 +56,7 @@ def setup(self) -> None: # 初期値として、列車1は八王子経由の普通とする self.setDia(1, "shinjuku_down", False, 5, "shinjuku_b2", "shinjuku_b1") - self.setDia(1, "sakurajosui_down", False, 5, "sakurajosui_b1", "sakurajosui_b5") + self.setDia(1, "sakurajosui_down", False, 5, "sakurajosui_b2", "sakurajosui_b5") self.setDia(1, "chofu_down", False, 5, "chofu_b2", "chofu_b4") self.setDia(1, "hachioji_down", False, 5, "chofu_b4", "hachioji_b1") self.setDia(1, "hachioji_up", False, 5, "hachioji_b1", "hachioji_b2") @@ -66,7 +66,7 @@ def setup(self) -> None: # 初期値として、列車2は橋本経由の特急とする→各停に変更 self.setDia(2, "shinjuku_down", False, 5, "shinjuku_b2", "shinjuku_b1") - self.setDia(2, "sakurajosui_down", False, 0, "sakurajosui_b1", "sakurajosui_b5") + self.setDia(2, "sakurajosui_down", False, 0, "sakurajosui_b2", "sakurajosui_b5") self.setDia(2, "chofu_down", False, 5, "chofu_b1", "chofu_b3") self.setDia(2, "hashimoto_down", False, 5, "chofu_b3", "hashimoto_b1") self.setDia(2, "hashimoto_up", False, 5, "hashimoto_b1", "hashimoto_b2") @@ -76,7 +76,7 @@ def setup(self) -> None: # 初期値として、列車3は橋本経由の普通とする self.setDia(3, "shinjuku_down", False, 5, "shinjuku_b2", "shinjuku_b1") - self.setDia(3, "sakurajosui_down", False, 5, "sakurajosui_b1", "sakurajosui_b5") + self.setDia(3, "sakurajosui_down", False, 5, "sakurajosui_b2", "sakurajosui_b5") self.setDia(3, "chofu_down", False, 5, "chofu_b1", "chofu_b3") self.setDia(3, "hashimoto_down", False, 5, "chofu_b3", "hashimoto_b1") self.setDia(3, "hashimoto_up", False, 5, "hashimoto_b1", "hashimoto_b2") From 76c77f03204245974c1a86ccd69b4f55881b85b7 Mon Sep 17 00:00:00 2001 From: n4o847 <22975590+n4o847@users.noreply.github.com> Date: Fri, 18 Nov 2022 10:49:03 +0900 Subject: [PATCH 3/3] use sakurajosui_b3 instead of sakurajosui_b4 --- backend/auto_operation/DiaPlanner.py | 8 ++++---- backend/auto_operation/State.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/auto_operation/DiaPlanner.py b/backend/auto_operation/DiaPlanner.py index 065a5bcb..6f5c0901 100644 --- a/backend/auto_operation/DiaPlanner.py +++ b/backend/auto_operation/DiaPlanner.py @@ -51,7 +51,7 @@ def setup(self) -> None: self.setDia(0, "hachioji_down", False, 5, "chofu_b4", "hachioji_b1") self.setDia(0, "hachioji_up", False, 5, "hachioji_b1", "hachioji_b2") self.setDia(0, "chofu_up", False, 5, "hachioji_b2", "chofu_b5") - self.setDia(0, "sakurajosui_up", False, 0, "sakurajosui_b4", "sakurajosui_b6") + self.setDia(0, "sakurajosui_up", False, 0, "sakurajosui_b3", "sakurajosui_b6") self.setDia(0, "shinjuku_up", False, 5, "sakurajosui_b6", "shinjuku_b2") # 初期値として、列車1は八王子経由の普通とする @@ -61,7 +61,7 @@ def setup(self) -> None: self.setDia(1, "hachioji_down", False, 5, "chofu_b4", "hachioji_b1") self.setDia(1, "hachioji_up", False, 5, "hachioji_b1", "hachioji_b2") self.setDia(1, "chofu_up", False, 5, "hachioji_b2", "chofu_b5") - self.setDia(1, "sakurajosui_up", False, 5, "sakurajosui_b4", "sakurajosui_b6") + self.setDia(1, "sakurajosui_up", False, 5, "sakurajosui_b3", "sakurajosui_b6") self.setDia(1, "shinjuku_up", False, 5, "sakurajosui_b6", "shinjuku_b2") # 初期値として、列車2は橋本経由の特急とする→各停に変更 @@ -71,7 +71,7 @@ def setup(self) -> None: self.setDia(2, "hashimoto_down", False, 5, "chofu_b3", "hashimoto_b1") self.setDia(2, "hashimoto_up", False, 5, "hashimoto_b1", "hashimoto_b2") self.setDia(2, "chofu_up", False, 5, "hashimoto_b2", "chofu_b5") - self.setDia(2, "sakurajosui_up", False, 0, "sakurajosui_b4", "sakurajosui_b6") + self.setDia(2, "sakurajosui_up", False, 0, "sakurajosui_b3", "sakurajosui_b6") self.setDia(2, "shinjuku_up", False, 5, "sakurajosui_b6", "shinjuku_b2") # 初期値として、列車3は橋本経由の普通とする @@ -81,7 +81,7 @@ def setup(self) -> None: self.setDia(3, "hashimoto_down", False, 5, "chofu_b3", "hashimoto_b1") self.setDia(3, "hashimoto_up", False, 5, "hashimoto_b1", "hashimoto_b2") self.setDia(3, "chofu_up", False, 5, "hashimoto_b2", "chofu_b5") - self.setDia(3, "sakurajosui_up", False, 5, "sakurajosui_b4", "sakurajosui_b6") + self.setDia(3, "sakurajosui_up", False, 5, "sakurajosui_b3", "sakurajosui_b6") self.setDia(3, "shinjuku_up", False, 5, "sakurajosui_b6", "shinjuku_b2") # ダイヤ自動更新のルールを記述. 毎update時によぶ diff --git a/backend/auto_operation/State.py b/backend/auto_operation/State.py index bd4aaadb..51f96ec6 100644 --- a/backend/auto_operation/State.py +++ b/backend/auto_operation/State.py @@ -367,7 +367,7 @@ def __init__(self) -> None: self.trainList.append( Train( 3, - self.getSectionById("sakurajosui_b4"), + self.getSectionById("sakurajosui_b3"), State.STRAIGHT_UNIT * 4, pidParam1, )