Exemplo n.º 1
0
 def test_assert_raises_wrong_order(self):
     node_profile = NodeProfileC()
     pt1 = LabelTime(departure_time=5, arrival_time_target=35)
     pt2 = LabelTime(departure_time=10, arrival_time_target=35)
     self.assertTrue(node_profile.update_pareto_optimal_tuples(pt1))
     with self.assertRaises(AssertionError):
         node_profile.update_pareto_optimal_tuples(pt2)
Exemplo n.º 2
0
    def test_earliest_arrival_time(self):
        node_profile = NodeProfileC()
        self.assertEquals(float("inf"), node_profile.evaluate_earliest_arrival_time_at_target(0, 0))

        node_profile.update_pareto_optimal_tuples(LabelTime(departure_time=3, arrival_time_target=4))
        self.assertEquals(4, node_profile.evaluate_earliest_arrival_time_at_target(2, 0))

        node_profile.update_pareto_optimal_tuples(LabelTime(departure_time=1, arrival_time_target=1))
        self.assertEquals(1, node_profile.evaluate_earliest_arrival_time_at_target(0, 0))
Exemplo n.º 3
0
    def test_pareto_optimality(self):
        node_profile = NodeProfileC()

        pair3 = LabelTime(departure_time=2, arrival_time_target=3)
        node_profile.update_pareto_optimal_tuples(pair3)
        pair2 = LabelTime(departure_time=1, arrival_time_target=2)
        node_profile.update_pareto_optimal_tuples(pair2)
        pair1 = LabelTime(departure_time=1, arrival_time_target=1)
        node_profile.update_pareto_optimal_tuples(pair1)
        self.assertEqual(2, len(node_profile.get_final_optimal_labels()))
Exemplo n.º 4
0
 def test_pareto_optimality2(self):
     node_profile = NodeProfileC()
     pt2 = LabelTime(departure_time=10, arrival_time_target=35)
     node_profile.update_pareto_optimal_tuples(pt2)
     pt1 = LabelTime(departure_time=5, arrival_time_target=35)
     node_profile.update_pareto_optimal_tuples(pt1)
     print(node_profile._labels)
     self.assertEquals(len(node_profile.get_final_optimal_labels()), 1)
Exemplo n.º 5
0
 def test_walk_duration(self):
     node_profile = NodeProfileC(walk_to_target_duration=27)
     self.assertEqual(27, node_profile.get_walk_to_target_duration())
     pt2 = LabelTime(departure_time=10, arrival_time_target=35)
     pt1 = LabelTime(departure_time=5, arrival_time_target=35)
     node_profile.update_pareto_optimal_tuples(pt2)
     node_profile.update_pareto_optimal_tuples(pt1)
     self.assertEqual(1, len(node_profile.get_final_optimal_labels()))
    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)
Exemplo n.º 7
0
 def test_identity_profile(self):
     identity_profile = NodeProfileC(0)
     self.assertFalse(identity_profile.update_pareto_optimal_tuples(LabelTime(10, 10)))
     self.assertEqual(10, identity_profile.evaluate_earliest_arrival_time_at_target(10, 0))