Exemple #1
0
    def __init__(self, transit_events, seed_stop, start_time, end_time,
                 transfer_margin, walk_network, walk_speed):
        """
        Parameters
        ----------
        transit_events: list[Connection]
        seed_stop: int
            index of the seed node
        start_time : int
            start time in unixtime seconds
        end_time: int
            end time in unixtime seconds (no new connections will be scanned after this time)
        transfer_margin: int
            required extra margin required for transfers in seconds
        walk_speed: float
            walking speed between stops in meters / second
        walk_network: networkx.Graph
            each edge should have the walking distance as a data attribute ("d_walk") expressed in meters
        """
        AbstractRoutingAlgorithm.__init__(self)
        self._seed = seed_stop
        self._connections = transit_events
        self._start_time = start_time
        self._end_time = end_time
        self._transfer_margin = transfer_margin
        self._walk_network = walk_network
        self._walk_speed = walk_speed

        # algorithm internals
        self.__stop_labels = defaultdict(lambda: float('inf'))
        self.__stop_labels[seed_stop] = start_time

        # trip flags:
        self.__trip_reachable = defaultdict(lambda: False)
Exemple #2
0
    def __init__(self,
                 transit_events,
                 targets,
                 start_time_ut=None,
                 end_time_ut=None,
                 transfer_margin=0,
                 walk_network=None,
                 walk_speed=1.5,
                 verbose=False,
                 track_vehicle_legs=True,
                 track_time=True,
                 track_route=False):
        """
        Parameters
        ----------
        transit_events: list[Connection]
            events are assumed to be ordered in DECREASING departure_time (!)
        targets: int, list
            index of the target stop
        start_time_ut : int, optional
            start time in unixtime seconds
        end_time_ut: int, optional
            end time in unixtime seconds (no connections will be scanned after this time)
        transfer_margin: int, optional
            required extra margin required for transfers in seconds
        walk_speed: float, optional
            walking speed between stops in meters / second.
        walk_network: networkx.Graph, optional
            each edge should have the walking distance as a data attribute ("distance_shape") expressed in meters
        verbose: boolean, optional
            whether to print out progress
        track_vehicle_legs: boolean, optional
            whether to consider the number of vehicle legs
        track_time: boolean, optional
            whether to consider time in the set of pareto_optimal
        """
        AbstractRoutingAlgorithm.__init__(self)
        assert (len(transit_events) == len(set(transit_events))), "Duplicate transit events spotted!"
        self._transit_connections = transit_events
        if start_time_ut is None:
            start_time_ut = transit_events[-1].departure_time
        if end_time_ut is None:
            end_time_ut = transit_events[0].departure_time
        self._start_time = start_time_ut
        self._end_time = end_time_ut
        self._transfer_margin = transfer_margin
        if walk_network is None:
            walk_network = networkx.Graph()
        self._walk_network = walk_network
        self._walk_speed = walk_speed
        self._verbose = verbose

        # algorithm internals

        # initialize stop_profiles
        self._count_vehicle_legs = track_vehicle_legs
        self._consider_time = track_time

        assert(track_time or track_vehicle_legs)
        if track_vehicle_legs:
            if track_time:
                if track_route:
                    self._label_class = LabelTimeBoardingsAndRoute
                else:
                    self._label_class = LabelTimeWithBoardingsCount
            else:
                self._label_class = LabelVehLegCount
        else:
            if track_route:
                self._label_class = LabelTimeAndRoute
            else:
                self._label_class = LabelTime

        print("using label:", str(self._label_class))
        self._stop_departure_times, self._stop_arrival_times = self.__compute_stop_dep_and_arrival_times()
        self._all_nodes = set.union(set(self._stop_departure_times.keys()),
                                    set(self._stop_arrival_times.keys()),
                                    set(self._walk_network.nodes()))

        self._pseudo_connections = self.__compute_pseudo_connections()
        self._add_pseudo_connection_departures_to_stop_departure_times()
        self._all_connections = self._pseudo_connections + self._transit_connections
        self._all_connections.sort(key=lambda connection: (-connection.departure_time, -connection.seq))
        self._augment_all_connections_with_arrival_stop_next_dep_time()
        if isinstance(targets, list):
            self._targets = targets
        else:
            self._targets = [targets]
        self.reset(self._targets)
    def __init__(self,
                 transit_events,
                 target_stop,
                 start_time=None,
                 end_time=None,
                 transfer_margin=0,
                 walk_network=None,
                 walk_speed=1.5,
                 verbose=False):
        """
        Parameters
        ----------
        transit_events: list[Connection]
            events are assumed to be ordered in DECREASING departure_time (!)
        target_stop: int
            index of the target stop
        start_time : int, optional
            start time in unixtime seconds
        end_time: int, optional
            end time in unixtime seconds (no connections will be scanned after this time)
        transfer_margin: int, optional
            required extra margin required for transfers in seconds
        walk_speed: float, optional
            walking speed between stops in meters / second.
        walk_network: networkx.Graph, optional
            each edge should have the walking distance as a data attribute ("distance_shape") expressed in meters
        verbose: boolean, optional
            whether to print out progress
        """
        AbstractRoutingAlgorithm.__init__(self)

        self._target = target_stop
        self._transit_connections = transit_events
        if start_time is None:
            start_time = transit_events[-1].departure_time
        if end_time is None:
            end_time = transit_events[0].departure_time
        self._start_time = start_time
        self._end_time = end_time
        self._transfer_margin = transfer_margin
        if walk_network is None:
            walk_network = networkx.Graph()
        self._walk_network = walk_network
        self._walk_speed = float(walk_speed)
        self._verbose = verbose

        # algorithm internals

        # trip flags:
        self.__trip_min_arrival_time = defaultdict(lambda: float("inf"))

        # initialize stop_profiles
        self._stop_profiles = defaultdict(lambda: NodeProfileC())
        # initialize stop_profiles for target stop, and its neighbors
        self._stop_profiles[self._target] = NodeProfileC(0)
        if target_stop in walk_network.nodes():
            for target_neighbor in walk_network.neighbors(target_stop):
                edge_data = walk_network.get_edge_data(target_neighbor,
                                                       target_stop)
                walk_duration = edge_data["d_walk"] / self._walk_speed
                self._stop_profiles[target_neighbor] = NodeProfileC(
                    walk_duration)
        pseudo_connection_set = compute_pseudo_connections(
            transit_events, self._start_time, self._end_time,
            self._transfer_margin, self._walk_network, self._walk_speed)
        self._pseudo_connections = list(pseudo_connection_set)
        self._all_connections = self._pseudo_connections + self._transit_connections
        self._all_connections.sort(
            key=lambda connection: -connection.departure_time)