def shift_ref_station(self, new_ref_station): current_ref_index = find_index_in_list(self.all_stations, self.ref_station) new_ref_index = find_index_in_list(self.all_stations, new_ref_station) if current_ref_index == -1: raise ValueError("current index not found in shift_ref_station") if new_ref_index == -1: raise ValueError("new ref index not found in shift_ref_station") #TODO use real distances between stations self.offset += (new_ref_index - current_ref_index) * 2 self.ref_station = new_ref_station
def get_station_index(self, station: 'Station'): station_index = find_index_in_list(self.stations, station) #print(station) if station_index == -1: raise ValueError("Station " + str(station) + " not found in stations of train (" + str([str(stat) for stat in self.stations]) + ")") return station_index
def find_neighbours(networkdb: 'NetworkDb', station: str): neighbours: Dict[str, List[str]] = {} for line, v in networkdb.all_lines.items(): stations = v['all_stations'] index: int = find_index_in_list(stations, station) if index == -1: continue find_neighbour(neighbours, stations, index - 1, line) find_neighbour(neighbours, stations, index + 1, line) return neighbours
def find_all_possible_switches_per_line(line: 'Line', already_visited: Set['Line'], starting_station: 'Station'): ret: List[StationSwitch] = [] starting_station_index = find_index_in_list(line.all_stations, starting_station) for i, station in enumerate(line.all_stations): switch_lines = station.get_switch_lines(already_visited) for switch_line in switch_lines: if switch_line in already_visited: continue ret.append(StationSwitch(line, station, switch_line, abs(starting_station_index-i))) already_visited.add(switch_line) return ret
def find_next_station(current_station: 'Station', stations: List['Station'], direction: int): current_index: int = find_index_in_list(stations, current_station) current_index += direction if current_index < 0: direction *= -1 current_index += 2 if current_index >= len(stations): direction *= -1 current_index -= 2 return stations[current_index], direction, stations[-1 if direction == 1 else 0]
def depart_passenger(self, passenger: 'Passenger'): passenger_index = find_index_in_list(self.passengers, passenger) if passenger_index == -1: raise ValueError("Passenger not found in station.") del self.passengers[passenger_index]
def get_index(self, station: 'Station'): return find_index_in_list(self.all_stations, station)