From 37e4e4afd115c1d6aaafad4cb5f4d84de6cdbd66 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 14:14:23 +0200 Subject: [PATCH 01/11] debug prints --- src/api/run.py | 20 ++++++++----------- .../route_controller.py | 6 +++++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/api/run.py b/src/api/run.py index 37c1a2dc..473bd678 100644 --- a/src/api/run.py +++ b/src/api/run.py @@ -9,41 +9,37 @@ @bp.route("/run", methods=["get"]) -@token_required() -def get_all_run_ids(token): +def get_all_run_ids(): """Get all run id""" options = {} options["simulationId"] = request.args.get("simulationId") - return impl.run.get_all_run_ids(options, token) + return impl.run.get_all_run_ids(options, None) @bp.route("/run", methods=["post"]) -@token_required() -def create_run(token): +def create_run(): """Create a run""" schema = schemas.RunConfiguration() body = parser.parse(schema, request, location="json") - return impl.run.create_run(body, token) + return impl.run.create_run(body, None) @bp.route("/run/", methods=["get"]) -@token_required() -def get_run(identifier, token): +def get_run(identifier): """Get a run""" options = {} options["identifier"] = identifier - return impl.run.get_run(options, token) + return impl.run.get_run(options, None) @bp.route("/run/", methods=["delete"]) -@token_required() -def delete_run(identifier, token): +def delete_run(identifier): """Delete a run""" options = {} options["identifier"] = identifier - return impl.run.delete_run(options, token) + return impl.run.delete_run(options, None) diff --git a/src/interlocking_component/route_controller.py b/src/interlocking_component/route_controller.py index 225c3cd5..e27411ba 100644 --- a/src/interlocking_component/route_controller.py +++ b/src/interlocking_component/route_controller.py @@ -109,7 +109,7 @@ class UninitializedTrain: """ identifier: str = "/not_a_real_train" - reserved_tracks: List[Track] = None + reserved_tracks: List[ReservationTrack] = None reserved_until_station_index: int = 1 timetable: List[Platform] = None route: str = None @@ -282,6 +282,8 @@ def reserve_for_initialized_train( :param reservation_placeholder: The placeholder, that has reservations :param train: The train that will get those reservations """ + #for track in reservation_placeholder.reserved_tracks: + # print(track.identifier, "is first reserved for: ", track.reservations[0][0].identifier) for track in reservation_placeholder.reserved_tracks: for reserved_train, edge in track.reservations: if reserved_train == reservation_placeholder: @@ -292,6 +294,8 @@ def reserve_for_initialized_train( + track.reservations[i + 1 :] ) train.reserved_tracks = reservation_placeholder.reserved_tracks + #for track in reservation_placeholder.reserved_tracks: + # print(track.identifier, "is first reserved for: ", track.reservations[0][0].identifier) def maybe_set_fahrstrasse(self, train: Train, edge: Edge): """This method should be called when a train enters a new track_segment. From 4e7cc60d5e17115b54f309c0bb08148401384bc2 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 15:32:07 +0200 Subject: [PATCH 02/11] one try --- pyproject.toml | 2 +- scripts/insert_simple_simulation.py | 2 +- .../route_controller.py | 44 +++++++++++++++---- src/wrapper/simulation_objects.py | 8 ++++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b1992960..45131e61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -174,7 +174,7 @@ build-backend = "poetry.core.masonry.api" [tool.poe.tasks.insert-config] help = "Inserts the configs into the database" - cmd = "python scripts/insert_demonstration_simulation.py" + cmd = "python scripts/insert_simple_simulation.py" envfile = [".env.shared", ".env.secret"] [tool.poe.tasks.cov] diff --git a/scripts/insert_simple_simulation.py b/scripts/insert_simple_simulation.py index c6505b5e..e313e4a5 100644 --- a/scripts/insert_simple_simulation.py +++ b/scripts/insert_simple_simulation.py @@ -18,7 +18,7 @@ strategy_start_time=2, strategy_end_time=400, train_schedule_train_type="regio", - regular_strategy_frequency=60, + regular_strategy_frequency=300, ) print(f"regular schedule: {regular_schedule.id}") for index, platform in enumerate(platforms): diff --git a/src/interlocking_component/route_controller.py b/src/interlocking_component/route_controller.py index e27411ba..f9f19504 100644 --- a/src/interlocking_component/route_controller.py +++ b/src/interlocking_component/route_controller.py @@ -108,14 +108,16 @@ class UninitializedTrain: When the spawnroute is set, the train is not yet initialized. """ - identifier: str = "/not_a_real_train" + identifier: str reserved_tracks: List[ReservationTrack] = None reserved_until_station_index: int = 1 timetable: List[Platform] = None route: str = None _station_index: int = 1 + state: Train.State = Train.State.DRIVING - def __init__(self, timetable: List[Platform]): + def __init__(self, timetable: List[Platform], identifier: str = "/not_a_real_train"): + self.identifier = identifier self.timetable = timetable self.reserved_tracks = [] @@ -269,9 +271,30 @@ def set_spawn_fahrstrasse( :raises KeyError: The route could not be found in the interlocking. :return: The id of the first SUMO Route and the placholder for reservations. """ - train_to_be_initialized = UninitializedTrain(timetable) + print("setting spawn fahrstrasse") + train_to_be_initialized = UninitializedTrain(timetable, "/not_a_real_train_" + str(self.tick)) self.set_fahrstrasse(train_to_be_initialized, starting_edge) - return train_to_be_initialized.route, train_to_be_initialized + if train_to_be_initialized.state == Train.State.DRIVING: + return train_to_be_initialized.route, train_to_be_initialized + else: + self.remove_train_from_queues(train_to_be_initialized) + self.remove_reservations_for_train(train_to_be_initialized) + return None, train_to_be_initialized + + def remove_train_from_queues(self, train_to_be_removed: Train): + for route, train, interlocking_route, entire_route in self.route_queues.routes_waiting_for_reservations: + if train == train_to_be_removed: + self.route_queues.routes_waiting_for_reservations.remove((route, train, interlocking_route, entire_route)) + for interlocking_route in self.route_queues.routes_to_be_set: + if train == train_to_be_removed: + self.route_queues.routes_waiting_for_reservations.remove(interlocking_route) + + def remove_reservations_for_train(self, train: Train): + for track in train.reserved_tracks: + for reserved_train, edge in track.reservations: + if reserved_train == train: + track.reservations.remove((reserved_train, edge)) + train.reserved_tracks = [] def reserve_for_initialized_train( self, reservation_placeholder: UninitializedTrain, train: Train @@ -282,8 +305,7 @@ def reserve_for_initialized_train( :param reservation_placeholder: The placeholder, that has reservations :param train: The train that will get those reservations """ - #for track in reservation_placeholder.reserved_tracks: - # print(track.identifier, "is first reserved for: ", track.reservations[0][0].identifier) + print("reserve for initilized train") for track in reservation_placeholder.reserved_tracks: for reserved_train, edge in track.reservations: if reserved_train == reservation_placeholder: @@ -294,8 +316,6 @@ def reserve_for_initialized_train( + track.reservations[i + 1 :] ) train.reserved_tracks = reservation_placeholder.reserved_tracks - #for track in reservation_placeholder.reserved_tracks: - # print(track.identifier, "is first reserved for: ", track.reservations[0][0].identifier) def maybe_set_fahrstrasse(self, train: Train, edge: Edge): """This method should be called when a train enters a new track_segment. @@ -367,6 +387,7 @@ def set_fahrstrasse(self, train: Train, edge: Edge): new_route, ) ) + train.state = Train.State.WAITING_FOR_RESERVATION return # If the no interlocking route is found an error is raised raise KeyError() @@ -396,6 +417,7 @@ def set_fahrstrasse_if_reservations_work( was_set = self.set_interlocking_route(interlocking_route) if not was_set: self.route_queues.routes_to_be_set.append(interlocking_route) + train.state = Train.State.WAITING_FOR_FAHRSTRASSE return True return False @@ -549,6 +571,9 @@ def maybe_put_reservations_as_first(self, train: Train, route: List[Node]): :param train: The train which reservation may be changed :param route: The route along which the reservation may be changed """ + print(train.identifier) + for track in train.reserved_tracks: + print(track.identifier, "is first reserved for: ", track.reservations[0][0].identifier) edge_route = self.get_edges_of_node_route(route) first_reservation_track: ReservationTrack = None for edge in edge_route: @@ -578,6 +603,9 @@ def maybe_put_reservations_as_first(self, train: Train, route: List[Node]): if edge.track.reservations[0][0] == train: self.put_reservations_as_first(train, edge_route[:i]) break + print(train.identifier) + for track in train.reserved_tracks: + print(track.identifier, "is first reserved for: ", track.reservations[0][0].identifier) def put_reservations_as_first(self, train: Train, edge_route: List[Edge]): """Moves reservations of the given train to the first place along the given route. diff --git a/src/wrapper/simulation_objects.py b/src/wrapper/simulation_objects.py index 516e056c..e78cba5f 100644 --- a/src/wrapper/simulation_objects.py +++ b/src/wrapper/simulation_objects.py @@ -780,11 +780,19 @@ def from_simulation( def add_simulation_connections(self) -> None: pass + class State(IntEnum): + """The possible states of the signal""" + + DRIVING = 1 + WAITING_FOR_RESERVATION = 2 + WAITING_FOR_FAHRSTRASSE = 3 + _position: Tuple[float, float] _route: str _edge: Edge _speed: float _timetable: List[Platform] + state: State = State.DRIVING train_type: TrainType reserved_tracks: List[ReservationTrack] _station_index: int = 0 From f4aefd1492e93617ebf4c75dee6fd4459572d5a9 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 15:37:30 +0200 Subject: [PATCH 03/11] change skript --- scripts/insert_simple_simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/insert_simple_simulation.py b/scripts/insert_simple_simulation.py index e313e4a5..c6505b5e 100644 --- a/scripts/insert_simple_simulation.py +++ b/scripts/insert_simple_simulation.py @@ -18,7 +18,7 @@ strategy_start_time=2, strategy_end_time=400, train_schedule_train_type="regio", - regular_strategy_frequency=300, + regular_strategy_frequency=60, ) print(f"regular schedule: {regular_schedule.id}") for index, platform in enumerate(platforms): From 5ba68a0b9c75c374d5e929df8da8f161605f9c30 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 15:43:34 +0200 Subject: [PATCH 04/11] fix? --- src/interlocking_component/route_controller.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interlocking_component/route_controller.py b/src/interlocking_component/route_controller.py index f9f19504..b510f3bd 100644 --- a/src/interlocking_component/route_controller.py +++ b/src/interlocking_component/route_controller.py @@ -285,9 +285,9 @@ def remove_train_from_queues(self, train_to_be_removed: Train): for route, train, interlocking_route, entire_route in self.route_queues.routes_waiting_for_reservations: if train == train_to_be_removed: self.route_queues.routes_waiting_for_reservations.remove((route, train, interlocking_route, entire_route)) - for interlocking_route in self.route_queues.routes_to_be_set: - if train == train_to_be_removed: - self.route_queues.routes_waiting_for_reservations.remove(interlocking_route) + for interlocking_route_in_queue in self.route_queues.routes_to_be_set: + if interlocking_route_in_queue == interlocking_route: + self.route_queues.routes_waiting_for_reservations.remove(interlocking_route) def remove_reservations_for_train(self, train: Train): for track in train.reserved_tracks: From feab0ac711e5f82314040d22d3408da2d49efdf1 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 16:21:38 +0200 Subject: [PATCH 05/11] change check if route is reserved as first --- src/interlocking_component/route_controller.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/interlocking_component/route_controller.py b/src/interlocking_component/route_controller.py index b510f3bd..594f38de 100644 --- a/src/interlocking_component/route_controller.py +++ b/src/interlocking_component/route_controller.py @@ -274,6 +274,7 @@ def set_spawn_fahrstrasse( print("setting spawn fahrstrasse") train_to_be_initialized = UninitializedTrain(timetable, "/not_a_real_train_" + str(self.tick)) self.set_fahrstrasse(train_to_be_initialized, starting_edge) + print(train_to_be_initialized.state) if train_to_be_initialized.state == Train.State.DRIVING: return train_to_be_initialized.route, train_to_be_initialized else: @@ -409,13 +410,17 @@ def set_fahrstrasse_if_reservations_work( :return: if it worked or not """ if not self.check_if_route_is_reserved(route, train, entire_route): + print("reserving new") if not self.reserve_route(entire_route, train): + print("reservation failed") return False self.maybe_put_reservations_as_first(train, entire_route) if self.check_if_route_is_reserved_as_first(route, train, entire_route): + print("reserved as first") was_set = self.set_interlocking_route(interlocking_route) if not was_set: + print("fahrstrasse not set") self.route_queues.routes_to_be_set.append(interlocking_route) train.state = Train.State.WAITING_FOR_FAHRSTRASSE return True @@ -471,14 +476,11 @@ def check_if_route_is_reserved_as_first( :return: if the route is reserved for the train """ route_as_tracks = self.get_tracks_of_node_route(route) - entire_route_as_tracks = self.get_tracks_of_node_route(entire_route) - for i, track in enumerate(entire_route_as_tracks): - if not track.is_reservation_track: - continue - if len(track.reservations) == 0 or track.reservations[0][0] != train: - return False - if i >= len(route_as_tracks): + for i, reserved_track in enumerate(train.reserved_tracks): + if reserved_track not in route_as_tracks and i != 0: break + if len(reserved_track.reservations) == 0 or reserved_track.reservations[0][0] != train: + return False return True def reserve_route(self, route: List[Node], train: Train) -> bool: From b769fff510c73111111695b386e67b9b4513e507 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 17:37:23 +0200 Subject: [PATCH 06/11] fix issue --- .../infrastructure_provider.py | 1 + .../route_controller.py | 28 +++++-------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/interlocking_component/infrastructure_provider.py b/src/interlocking_component/infrastructure_provider.py index 096d885a..90101ece 100644 --- a/src/interlocking_component/infrastructure_provider.py +++ b/src/interlocking_component/infrastructure_provider.py @@ -75,6 +75,7 @@ def train_drove_onto_track(self, train: Train, edge: Edge): :param edge: The edge the train drove onto :type edge: Edge """ + track_segment_id = edge.identifier.split("-re")[0] # The interlocking does not have two edges per track, so the -re must be removed if there self.tds_count_in(track_segment_id) diff --git a/src/interlocking_component/route_controller.py b/src/interlocking_component/route_controller.py index 594f38de..c10cc04e 100644 --- a/src/interlocking_component/route_controller.py +++ b/src/interlocking_component/route_controller.py @@ -191,7 +191,7 @@ class RouteController(Component): class RouteQueues: """This class capsules all routes, that need to be considered every tick.""" - routes_to_be_set: List[Route] + routes_to_be_set: List[Tuple[Train, Route]] routes_waiting_for_reservations: List[ Tuple[List[Node], Train, Route, List[Node]] ] @@ -237,12 +237,12 @@ def __init__( def next_tick(self, tick: int): self.tick = tick - for interlocking_route in self.route_queues.routes_to_be_set: + for train, interlocking_route in self.route_queues.routes_to_be_set: # This tries to set the fahrstrasse in the interlocking. # The Sumo route was already set and the route was reserved. was_set = self.set_interlocking_route(interlocking_route) if was_set: - self.route_queues.routes_to_be_set.remove(interlocking_route) + self.route_queues.routes_to_be_set.remove(train, interlocking_route) for ( route, train, @@ -274,7 +274,6 @@ def set_spawn_fahrstrasse( print("setting spawn fahrstrasse") train_to_be_initialized = UninitializedTrain(timetable, "/not_a_real_train_" + str(self.tick)) self.set_fahrstrasse(train_to_be_initialized, starting_edge) - print(train_to_be_initialized.state) if train_to_be_initialized.state == Train.State.DRIVING: return train_to_be_initialized.route, train_to_be_initialized else: @@ -286,9 +285,9 @@ def remove_train_from_queues(self, train_to_be_removed: Train): for route, train, interlocking_route, entire_route in self.route_queues.routes_waiting_for_reservations: if train == train_to_be_removed: self.route_queues.routes_waiting_for_reservations.remove((route, train, interlocking_route, entire_route)) - for interlocking_route_in_queue in self.route_queues.routes_to_be_set: - if interlocking_route_in_queue == interlocking_route: - self.route_queues.routes_waiting_for_reservations.remove(interlocking_route) + for train, interlocking_route in self.route_queues.routes_to_be_set: + if train == train_to_be_removed: + self.route_queues.routes_to_be_set.remove((train, interlocking_route)) def remove_reservations_for_train(self, train: Train): for track in train.reserved_tracks: @@ -306,7 +305,6 @@ def reserve_for_initialized_train( :param reservation_placeholder: The placeholder, that has reservations :param train: The train that will get those reservations """ - print("reserve for initilized train") for track in reservation_placeholder.reserved_tracks: for reserved_train, edge in track.reservations: if reserved_train == reservation_placeholder: @@ -329,7 +327,6 @@ def maybe_set_fahrstrasse(self, train: Train, edge: Edge): """ if train.current_platform is None: # if the train has reached the last station, don't allocate a new fahrstraße - print("No new route needed") return routes = self._get_interlocking_routes_for_edge(edge) @@ -337,7 +334,6 @@ def maybe_set_fahrstrasse(self, train: Train, edge: Edge): if route.get_last_segment_of_route() != edge.identifier.split("-re")[0]: continue - print("Setting fahrstrasse.") self.set_fahrstrasse(train, edge) break @@ -410,18 +406,14 @@ def set_fahrstrasse_if_reservations_work( :return: if it worked or not """ if not self.check_if_route_is_reserved(route, train, entire_route): - print("reserving new") if not self.reserve_route(entire_route, train): - print("reservation failed") return False self.maybe_put_reservations_as_first(train, entire_route) if self.check_if_route_is_reserved_as_first(route, train, entire_route): - print("reserved as first") was_set = self.set_interlocking_route(interlocking_route) if not was_set: - print("fahrstrasse not set") - self.route_queues.routes_to_be_set.append(interlocking_route) + self.route_queues.routes_to_be_set.append((train, interlocking_route)) train.state = Train.State.WAITING_FOR_FAHRSTRASSE return True return False @@ -573,9 +565,6 @@ def maybe_put_reservations_as_first(self, train: Train, route: List[Node]): :param train: The train which reservation may be changed :param route: The route along which the reservation may be changed """ - print(train.identifier) - for track in train.reserved_tracks: - print(track.identifier, "is first reserved for: ", track.reservations[0][0].identifier) edge_route = self.get_edges_of_node_route(route) first_reservation_track: ReservationTrack = None for edge in edge_route: @@ -605,9 +594,6 @@ def maybe_put_reservations_as_first(self, train: Train, route: List[Node]): if edge.track.reservations[0][0] == train: self.put_reservations_as_first(train, edge_route[:i]) break - print(train.identifier) - for track in train.reserved_tracks: - print(track.identifier, "is first reserved for: ", track.reservations[0][0].identifier) def put_reservations_as_first(self, train: Train, edge_route: List[Edge]): """Moves reservations of the given train to the first place along the given route. From 0eefea431fde95dfd94d4c404e81279f79012319 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 17:42:10 +0200 Subject: [PATCH 07/11] clean up --- src/api/run.py | 20 +++++++++++-------- .../infrastructure_provider.py | 1 - 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/api/run.py b/src/api/run.py index 473bd678..37c1a2dc 100644 --- a/src/api/run.py +++ b/src/api/run.py @@ -9,37 +9,41 @@ @bp.route("/run", methods=["get"]) -def get_all_run_ids(): +@token_required() +def get_all_run_ids(token): """Get all run id""" options = {} options["simulationId"] = request.args.get("simulationId") - return impl.run.get_all_run_ids(options, None) + return impl.run.get_all_run_ids(options, token) @bp.route("/run", methods=["post"]) -def create_run(): +@token_required() +def create_run(token): """Create a run""" schema = schemas.RunConfiguration() body = parser.parse(schema, request, location="json") - return impl.run.create_run(body, None) + return impl.run.create_run(body, token) @bp.route("/run/", methods=["get"]) -def get_run(identifier): +@token_required() +def get_run(identifier, token): """Get a run""" options = {} options["identifier"] = identifier - return impl.run.get_run(options, None) + return impl.run.get_run(options, token) @bp.route("/run/", methods=["delete"]) -def delete_run(identifier): +@token_required() +def delete_run(identifier, token): """Delete a run""" options = {} options["identifier"] = identifier - return impl.run.delete_run(options, None) + return impl.run.delete_run(options, token) diff --git a/src/interlocking_component/infrastructure_provider.py b/src/interlocking_component/infrastructure_provider.py index 90101ece..096d885a 100644 --- a/src/interlocking_component/infrastructure_provider.py +++ b/src/interlocking_component/infrastructure_provider.py @@ -75,7 +75,6 @@ def train_drove_onto_track(self, train: Train, edge: Edge): :param edge: The edge the train drove onto :type edge: Edge """ - track_segment_id = edge.identifier.split("-re")[0] # The interlocking does not have two edges per track, so the -re must be removed if there self.tds_count_in(track_segment_id) From 55b5cee0d4a69e805c0732ce19caebd51f8b43f3 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 17:53:51 +0200 Subject: [PATCH 08/11] fix lint --- .../route_controller.py | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/interlocking_component/route_controller.py b/src/interlocking_component/route_controller.py index c10cc04e..19adae48 100644 --- a/src/interlocking_component/route_controller.py +++ b/src/interlocking_component/route_controller.py @@ -116,7 +116,9 @@ class UninitializedTrain: _station_index: int = 1 state: Train.State = Train.State.DRIVING - def __init__(self, timetable: List[Platform], identifier: str = "/not_a_real_train"): + def __init__( + self, timetable: List[Platform], identifier: str = "/not_a_real_train" + ): self.identifier = identifier self.timetable = timetable self.reserved_tracks = [] @@ -272,24 +274,42 @@ def set_spawn_fahrstrasse( :return: The id of the first SUMO Route and the placholder for reservations. """ print("setting spawn fahrstrasse") - train_to_be_initialized = UninitializedTrain(timetable, "/not_a_real_train_" + str(self.tick)) + train_to_be_initialized = UninitializedTrain( + timetable, "/not_a_real_train_" + str(self.tick) + ) self.set_fahrstrasse(train_to_be_initialized, starting_edge) if train_to_be_initialized.state == Train.State.DRIVING: return train_to_be_initialized.route, train_to_be_initialized - else: - self.remove_train_from_queues(train_to_be_initialized) - self.remove_reservations_for_train(train_to_be_initialized) - return None, train_to_be_initialized - + self.remove_train_from_queues(train_to_be_initialized) + self.remove_reservations_for_train(train_to_be_initialized) + return None, train_to_be_initialized + def remove_train_from_queues(self, train_to_be_removed: Train): - for route, train, interlocking_route, entire_route in self.route_queues.routes_waiting_for_reservations: + """This method removes a train from all queues where fahrstrassen or + things like that may be set in the next_tick method + + :param train_to_be_removed: The train, that will not be considered anymore + """ + for ( + route, + train, + interlocking_route, + entire_route, + ) in self.route_queues.routes_waiting_for_reservations: if train == train_to_be_removed: - self.route_queues.routes_waiting_for_reservations.remove((route, train, interlocking_route, entire_route)) + self.route_queues.routes_waiting_for_reservations.remove( + (route, train, interlocking_route, entire_route) + ) for train, interlocking_route in self.route_queues.routes_to_be_set: if train == train_to_be_removed: self.route_queues.routes_to_be_set.remove((train, interlocking_route)) def remove_reservations_for_train(self, train: Train): + """This Methods removes all reservations made by an train. + It deletes them in the train and in the tracks. + + :param train: The train, that will have it's reservations removed + """ for track in train.reserved_tracks: for reserved_train, edge in track.reservations: if reserved_train == train: @@ -410,7 +430,7 @@ def set_fahrstrasse_if_reservations_work( return False self.maybe_put_reservations_as_first(train, entire_route) - if self.check_if_route_is_reserved_as_first(route, train, entire_route): + if self.check_if_route_is_reserved_as_first(route, train): was_set = self.set_interlocking_route(interlocking_route) if not was_set: self.route_queues.routes_to_be_set.append((train, interlocking_route)) @@ -458,7 +478,7 @@ def check_if_route_is_reserved( return True def check_if_route_is_reserved_as_first( - self, route: List[Node], train: Train, entire_route: List[Node] + self, route: List[Node], train: Train ) -> bool: """This method checks, if the given route is fully reserved for the given train and if the train is in the first position in the queue. @@ -471,7 +491,10 @@ def check_if_route_is_reserved_as_first( for i, reserved_track in enumerate(train.reserved_tracks): if reserved_track not in route_as_tracks and i != 0: break - if len(reserved_track.reservations) == 0 or reserved_track.reservations[0][0] != train: + if ( + len(reserved_track.reservations) == 0 + or reserved_track.reservations[0][0] != train + ): return False return True From 1f537b27891a887f64452d68d341bf297f13ede5 Mon Sep 17 00:00:00 2001 From: MaxLietze Date: Mon, 24 Jul 2023 17:56:38 +0200 Subject: [PATCH 09/11] fix lint again --- src/interlocking_component/route_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interlocking_component/route_controller.py b/src/interlocking_component/route_controller.py index 19adae48..0f1b0f25 100644 --- a/src/interlocking_component/route_controller.py +++ b/src/interlocking_component/route_controller.py @@ -285,7 +285,7 @@ def set_spawn_fahrstrasse( return None, train_to_be_initialized def remove_train_from_queues(self, train_to_be_removed: Train): - """This method removes a train from all queues where fahrstrassen or + """This method removes a train from all queues where fahrstrassen or things like that may be set in the next_tick method :param train_to_be_removed: The train, that will not be considered anymore From 2341f4c1a226bcb73d593c5ce4ea6a833fe149ca Mon Sep 17 00:00:00 2001 From: Lucas Reisener Date: Tue, 25 Jul 2023 09:40:15 +0200 Subject: [PATCH 10/11] adapt insert_demonstration_simulation.py script, add to pyproject.toml --- pyproject.toml | 2 +- scripts/insert_demonstration_simulation.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 45131e61..b1992960 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -174,7 +174,7 @@ build-backend = "poetry.core.masonry.api" [tool.poe.tasks.insert-config] help = "Inserts the configs into the database" - cmd = "python scripts/insert_simple_simulation.py" + cmd = "python scripts/insert_demonstration_simulation.py" envfile = [".env.shared", ".env.secret"] [tool.poe.tasks.cov] diff --git a/scripts/insert_demonstration_simulation.py b/scripts/insert_demonstration_simulation.py index 3534baec..64686953 100644 --- a/scripts/insert_demonstration_simulation.py +++ b/scripts/insert_demonstration_simulation.py @@ -29,10 +29,11 @@ strategy_type="RandomScheduleStrategy", strategy_start_time=0, strategy_end_time=7200, + train_schedule_train_type="cargo", random_strategy_trains_per_1000_seconds=2.0, ) print(f"regular schedule: {regular_schedule.id}") - print(f"radom schedule: {random_schedule.id}") + print(f"random schedule: {random_schedule.id}") for index, platform in enumerate(platforms): ScheduleConfigurationXSimulationPlatform.create( schedule_configuration_id=regular_schedule, From 717cf70b93efe809a66b36250ced8bebdb0e8f24 Mon Sep 17 00:00:00 2001 From: Lucas Reisener Date: Wed, 26 Jul 2023 11:50:25 +0200 Subject: [PATCH 11/11] remove print, fix typo --- src/interlocking_component/route_controller.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/interlocking_component/route_controller.py b/src/interlocking_component/route_controller.py index 0f1b0f25..36d5326b 100644 --- a/src/interlocking_component/route_controller.py +++ b/src/interlocking_component/route_controller.py @@ -273,7 +273,6 @@ def set_spawn_fahrstrasse( :raises KeyError: The route could not be found in the interlocking. :return: The id of the first SUMO Route and the placholder for reservations. """ - print("setting spawn fahrstrasse") train_to_be_initialized = UninitializedTrain( timetable, "/not_a_real_train_" + str(self.tick) ) @@ -305,10 +304,10 @@ def remove_train_from_queues(self, train_to_be_removed: Train): self.route_queues.routes_to_be_set.remove((train, interlocking_route)) def remove_reservations_for_train(self, train: Train): - """This Methods removes all reservations made by an train. + """This Method removes all reservations made by a train. It deletes them in the train and in the tracks. - :param train: The train, that will have it's reservations removed + :param train: The train, that will have its reservations removed """ for track in train.reserved_tracks: for reserved_train, edge in track.reservations: