Пример #1
0
 def test_compute_pareto_front_all_include(self):
     label_a = LabelTimeWithBoardingsCount(departure_time=1, arrival_time_target=2, n_boardings=0, first_leg_is_walk=False)
     label_b = LabelTimeWithBoardingsCount(departure_time=2, arrival_time_target=3, n_boardings=0, first_leg_is_walk=False)
     label_c = LabelTimeWithBoardingsCount(departure_time=3, arrival_time_target=4, n_boardings=0, first_leg_is_walk=False)
     label_d = LabelTimeWithBoardingsCount(departure_time=4, arrival_time_target=5, n_boardings=0, first_leg_is_walk=False)
     labels = [label_a, label_b, label_c, label_d]
     self.assertEqual(4, len(compute_pareto_front(labels)))
Пример #2
0
    def test_some_are_optimal_some_are_not(self):
        label_a = LabelTimeWithBoardingsCount(
            departure_time=1,
            arrival_time_target=2,
            n_boardings=1,
            first_leg_is_walk=False)  # optimal
        label_b = LabelTimeWithBoardingsCount(
            departure_time=1,
            arrival_time_target=5,
            n_boardings=0,
            first_leg_is_walk=False)  # label_d dominates
        label_c = LabelTimeWithBoardingsCount(
            departure_time=3,
            arrival_time_target=4,
            n_boardings=1,
            first_leg_is_walk=False)  # optimal
        label_d = LabelTimeWithBoardingsCount(
            departure_time=4,
            arrival_time_target=5,
            n_boardings=0,
            first_leg_is_walk=False)  # optimal
        labels = [label_a, label_b, label_c, label_d]

        pareto_front = compute_pareto_front(labels)
        self.assertEqual(3, len(pareto_front))
        self.assertNotIn(label_b, pareto_front)
Пример #3
0
 def test_pareto_optimality(self):
     event_list_raw_data = [(0, 2, 0, 10, "trip_1", 1),
                            (0, 1, 2, 5, "trip_2", 1),
                            (1, 2, 5, 8, "trip_3", 1)]
     transit_connections = list(
         map(lambda el: Connection(*el), event_list_raw_data))
     walk_speed = 2
     source_stop = 0
     target_stop = 2
     transfer_margin = 0
     start_time = 0
     end_time = 20
     walk_network = networkx.Graph()
     csa_profile = MultiObjectivePseudoCSAProfiler(transit_connections,
                                                   target_stop, start_time,
                                                   end_time,
                                                   transfer_margin,
                                                   walk_network, walk_speed)
     csa_profile.run()
     source_profile = csa_profile.stop_profiles[source_stop]
     self.assertEqual(
         min_arrival_time_target(source_profile.evaluate(0, 0)), 8)
     found_labels = source_profile.get_final_optimal_labels()
     labels_should_be = list()
     labels_should_be.append(
         LabelTimeWithBoardingsCount(0,
                                     10,
                                     n_boardings=1,
                                     first_leg_is_walk=False))
     labels_should_be.append(
         LabelTimeWithBoardingsCount(2,
                                     8,
                                     n_boardings=2,
                                     first_leg_is_walk=False))
     self._assert_label_sets_equal(found_labels, labels_should_be)
Пример #4
0
    def test_sort(self):
        l1 = LabelTimeWithBoardingsCount(departure_time=1,
                                         arrival_time_target=1,
                                         n_boardings=3,
                                         first_leg_is_walk=False)
        l2 = LabelTimeWithBoardingsCount(0, 0, 0, False)
        self.assertTrue(l1 > l2)
        self.assertTrue(l1 >= l2)
        self.assertFalse(l1 < l2)
        self.assertFalse(l1 <= l2)

        l1 = LabelTimeWithBoardingsCount(0, 0, 0, False)
        l2 = LabelTimeWithBoardingsCount(0, 0, 0, False)
        self.assertTrue(l1 == l2)
        self.assertTrue(l1 >= l2)
        self.assertTrue(l1 <= l2)
        self.assertFalse(l1 != l2)

        l1 = LabelTimeWithBoardingsCount(1, 0, 10, False)
        l2 = LabelTimeWithBoardingsCount(1, 1, 10, False)
        self.assertTrue(l1 > l2)
        self.assertFalse(l1 < l2)

        l1 = LabelTimeWithBoardingsCount(1, 1, 0, False)
        l2 = LabelTimeWithBoardingsCount(1, 1, 10, False)
        self.assertTrue(l1 > l2)
        self.assertFalse(l1 < l2)

        self.assertTrue(sorted([l1, l2])[0] == l2)

        l1 = LabelTimeWithBoardingsCount(1, 1, 10, True)
        l2 = LabelTimeWithBoardingsCount(1, 1, 10, False)
        self.assertTrue(l1 < l2)
        self.assertFalse(l1 > l2)
    def test_dep_time_skipped_in_update(self):
        label3 = LabelTimeWithBoardingsCount(departure_time=30, arrival_time_target=20, n_boardings=0,
                                             first_leg_is_walk=False)
        label2 = LabelTimeWithBoardingsCount(departure_time=20, arrival_time_target=20, n_boardings=0,
                                             first_leg_is_walk=False)
        label1 = LabelTimeWithBoardingsCount(departure_time=10, arrival_time_target=20, n_boardings=0,
                                             first_leg_is_walk=False)

        # This should work ok
        node_profile = NodeProfileMultiObjective(label_class=LabelTimeWithBoardingsCount, dep_times=[10, 20, 30])
        node_profile.update([label3])
        node_profile.update([label2])
        node_profile.update([label2])
        node_profile.update([label1])

        # This should fail due to dep time 20 missing in between
        with self.assertRaises(AssertionError):
            node_profile = NodeProfileMultiObjective(label_class=LabelTimeWithBoardingsCount, dep_times=[10, 20, 30])
            node_profile.update([label3])
            node_profile.update([label1])

        # This should fail due to dep time 30 not being the first to deal with
        with self.assertRaises(AssertionError):
            node_profile = NodeProfileMultiObjective(label_class=LabelTimeWithBoardingsCount, dep_times=[10, 20, 30])
            node_profile.update([label2])
Пример #6
0
    def test_merge_pareto_frontiers(self):
        label_a = LabelTimeWithBoardingsCount(
            departure_time=1,
            arrival_time_target=2,
            n_boardings=1,
            first_leg_is_walk=False)  # optimal
        label_b = LabelTimeWithBoardingsCount(
            departure_time=1,
            arrival_time_target=5,
            n_boardings=0,
            first_leg_is_walk=False)  # d dominates
        label_c = LabelTimeWithBoardingsCount(
            departure_time=3,
            arrival_time_target=4,
            n_boardings=1,
            first_leg_is_walk=False)  # optimal
        label_d = LabelTimeWithBoardingsCount(
            departure_time=4,
            arrival_time_target=5,
            n_boardings=0,
            first_leg_is_walk=False)  # optimal
        front_1 = [label_a, label_b]
        front_2 = [label_c, label_d]

        pareto_front = merge_pareto_frontiers(front_1, front_2)
        self.assertEqual(3, len(pareto_front))
        self.assertNotIn(label_b, pareto_front)
 def test_min_n_boardings(self):
     labels = [
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=12,
                                     n_boardings=4,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=5,
                                     arrival_time_target=10,
                                     n_boardings=2,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=5,
                                     arrival_time_target=12,
                                     n_boardings=1,
                                     first_leg_is_walk=False)
     ]
     analyzer = self._get_analyzer(labels,
                                   0,
                                   10,
                                   walk_to_target_duration=10)
     self.assertEqual(analyzer.min_n_boardings(), 0)
     analyzer2 = self._get_analyzer(labels,
                                    0,
                                    10,
                                    walk_to_target_duration=float('inf'))
     self.assertEqual(analyzer2.min_n_boardings(), 1)
Пример #8
0
 def test_one_dominates_all(self):
     label_a = LabelTimeWithBoardingsCount(departure_time=1, arrival_time_target=12, n_boardings=0, first_leg_is_walk=False)
     label_b = LabelTimeWithBoardingsCount(departure_time=2, arrival_time_target=13, n_boardings=0, first_leg_is_walk=False)
     label_c = LabelTimeWithBoardingsCount(departure_time=3, arrival_time_target=14, n_boardings=0, first_leg_is_walk=False)
     label_d = LabelTimeWithBoardingsCount(departure_time=4, arrival_time_target=5, n_boardings=0, first_leg_is_walk=False)
     labels = [label_a, label_b, label_c, label_d]
     pareto_front = compute_pareto_front(labels)
     self.assertEqual(1, len(pareto_front))
     self.assertEqual(label_d, pareto_front[0])
 def test_finalize(self):
     node_profile = NodeProfileMultiObjective(label_class=LabelTimeWithBoardingsCount, dep_times=[10])
     own_label = LabelTimeWithBoardingsCount(departure_time=10, arrival_time_target=20, n_boardings=0, first_leg_is_walk=False)
     self.assertTrue(node_profile.update([own_label]))
     neighbor_label = LabelTimeWithBoardingsCount(departure_time=15, arrival_time_target=18, n_boardings=2, first_leg_is_walk=False)
     assert(len(node_profile.get_labels_for_real_connections()) == 1)
     node_profile.finalize([[neighbor_label]], [3])
     assert (len(node_profile.get_final_optimal_labels()) == 2)
     self.assertTrue(any(map(lambda el: el.departure_time == 12, node_profile.get_final_optimal_labels())))
 def test_pareto_optimality_with_transfers_and_time(self):
     node_profile = NodeProfileMultiObjective(dep_times=[5, 6, 7])
     pt3 = LabelTimeWithBoardingsCount(departure_time=5, arrival_time_target=45, n_boardings=0, first_leg_is_walk=False)
     pt2 = LabelTimeWithBoardingsCount(departure_time=6, arrival_time_target=40, n_boardings=1, first_leg_is_walk=False)
     pt1 = LabelTimeWithBoardingsCount(departure_time=7, arrival_time_target=35, n_boardings=2, first_leg_is_walk=False)
     self.assertTrue(node_profile.update([pt1]))
     self.assertTrue(node_profile.update([pt2]))
     self.assertTrue(node_profile.update([pt3]))
     self.assertEqual(3, len(node_profile.get_labels_for_real_connections()))
Пример #11
0
 def test_dominates_less_transfers(self):
     labela = LabelTimeWithBoardingsCount(departure_time=1,
                                          arrival_time_target=10,
                                          n_boardings=1,
                                          first_leg_is_walk=False)
     labelb = LabelTimeWithBoardingsCount(departure_time=1,
                                          arrival_time_target=10,
                                          n_boardings=0,
                                          first_leg_is_walk=False)
     self.assertTrue(labelb.dominates(labela))
Пример #12
0
 def test_dominates_later_arrival_time(self):
     label2 = LabelTimeWithBoardingsCount(departure_time=1,
                                          arrival_time_target=10,
                                          n_boardings=0,
                                          first_leg_is_walk=False)
     label4 = LabelTimeWithBoardingsCount(departure_time=1,
                                          arrival_time_target=11,
                                          n_boardings=0,
                                          first_leg_is_walk=False)
     self.assertTrue(label2.dominates(label4))
Пример #13
0
    def test_last_leg_is_walk(self):
        event_list_raw_data = [(0, 1, 0, 10, "trip_1", 1)]
        transit_connections = list(
            map(lambda el: Connection(*el), event_list_raw_data))
        walk_network = networkx.Graph()
        walk_network.add_edge(1, 2, d_walk=20)

        walk_speed = 1
        source_stop = 0
        target_stop = 2
        transfer_margin = 0
        start_time = 0
        end_time = 50
        labels = list()
        labels.append(
            LabelTimeWithBoardingsCount(departure_time=0,
                                        arrival_time_target=30,
                                        n_boardings=1,
                                        first_leg_is_walk=False))

        csa_profile = MultiObjectivePseudoCSAProfiler(transit_connections,
                                                      target_stop, start_time,
                                                      end_time,
                                                      transfer_margin,
                                                      walk_network, walk_speed)
        csa_profile.run()
        found_tuples = csa_profile.stop_profiles[
            source_stop].get_final_optimal_labels()
        self._assert_label_sets_equal(found_tuples, labels)
Пример #14
0
    def _get_node_profile_analyzer_time_and_veh_legs(self, target, origin,
                                                     start_time_dep,
                                                     end_time_dep):
        sql = """SELECT from_stop_I, to_stop_I, n_boardings, departure_time, arrival_time_target FROM journeys WHERE to_stop_I = %s AND from_stop_I = %s""" % (
            target, origin)
        df = pd.read_sql_query(sql, self.conn)

        journey_labels = []
        for journey in df.itertuples():
            departure_time = journey.departure_time
            arrival_time_target = journey.arrival_time_target
            n_boardings = journey.n_boardings
            journey_labels.append(
                LabelTimeWithBoardingsCount(departure_time,
                                            arrival_time_target,
                                            n_boardings,
                                            first_leg_is_walk=float('nan')))

        # This ought to be optimized...
        query = """SELECT d, d_walk FROM stop_distances WHERE to_stop_I = %s AND from_stop_I = %s""" % (
            target, origin)
        df = self.gtfs.execute_custom_query_pandas(query)
        if len(df) > 0:
            walk_duration = float(
                df['d_walk']) / self.routing_params_input['walk_speed']
        else:
            walk_duration = float('inf')
        analyzer = NodeProfileAnalyzerTimeAndVehLegs(
            journey_labels,
            walk_duration,  # walking time
            start_time_dep,
            end_time_dep)
        return analyzer
Пример #15
0
 def test_compute_pareto_front_smart_randomized(self):
     import random
     for i in range(10):
         labels = [LabelTimeWithBoardingsCount(random.randint(0, 1000), random.randint(0, 1000), random.randint(0, 10), 0)
                   for _ in range(1000)]
         pareto_optimal_labels_old = compute_pareto_front_naive(labels)
         pareto_optimal_labels_smart = compute_pareto_front(labels)
         self.assertEqual(len(pareto_optimal_labels_old), len(pareto_optimal_labels_smart))
Пример #16
0
 def test_boardings_computations_based_on_journeys(self):
     # input some journeys
     destination_stop = 1
     origin_stop = 2
     self.jdm.import_journey_data_for_target_stop(
         destination_stop, {
             origin_stop: [
                 LabelTimeWithBoardingsCount(1, 2, 1, True),
                 LabelTimeWithBoardingsCount(2, 3, 2, True)
             ]
         })
     self.jdm.compute_travel_impedance_measures_for_od_pairs(0, 2)
     df = self.jdm.get_table_as_dataframe("n_boardings")
     self.assertAlmostEqual(df.iloc[0]["min"], 1)
     self.assertAlmostEqual(df.iloc[0]["mean"], 1.5)
     self.assertAlmostEqual(df.iloc[0]["max"], 2.0)
     self.assertIn(df.iloc[0]["median"], [1, 2, 1.0, 1.5, 2.0])
Пример #17
0
 def test_pareto_optimality_with_transfers(self):
     node_profile = NodeProfileSimple(
         label_class=LabelTimeWithBoardingsCount)
     pt3 = LabelTimeWithBoardingsCount(departure_time=5,
                                       arrival_time_target=35,
                                       n_boardings=0,
                                       first_leg_is_walk=True)
     pt2 = LabelTimeWithBoardingsCount(departure_time=5,
                                       arrival_time_target=35,
                                       n_boardings=1,
                                       first_leg_is_walk=True)
     pt1 = LabelTimeWithBoardingsCount(departure_time=5,
                                       arrival_time_target=35,
                                       n_boardings=2,
                                       first_leg_is_walk=True)
     self.assertTrue(node_profile.update_pareto_optimal_tuples(pt1))
     self.assertTrue(node_profile.update_pareto_optimal_tuples(pt2))
     self.assertTrue(node_profile.update_pareto_optimal_tuples(pt3))
     self.assertEqual(1, len(node_profile.get_final_optimal_labels()))
Пример #18
0
 def test_large_numbers_do_not_overflow(self):
     departure_time = 1475530980
     arrival_time = 1475530980
     label = LabelTimeWithBoardingsCount(
         departure_time=float(departure_time),
         arrival_time_target=float(arrival_time),
         n_boardings=0,
         first_leg_is_walk=False)
     self.assertEqual(departure_time, label.departure_time)
     self.assertEqual(arrival_time, label.arrival_time_target)
Пример #19
0
    def test_basics(self):
        csa_profile = MultiObjectivePseudoCSAProfiler(
            self.transit_connections, self.target_stop, self.start_time,
            self.end_time, self.transfer_margin, self.walk_network,
            self.walk_speed)
        csa_profile.run()

        stop_3_labels = csa_profile.stop_profiles[3].get_final_optimal_labels()
        self.assertEqual(len(stop_3_labels), 1)
        self.assertIn(
            LabelTimeWithBoardingsCount(32,
                                        35,
                                        n_boardings=1,
                                        first_leg_is_walk=False),
            stop_3_labels)

        stop_2_labels = csa_profile.stop_profiles[2].get_final_optimal_labels()
        self.assertEqual(len(stop_2_labels), 3)
        self.assertIn(
            LabelTimeWithBoardingsCount(40,
                                        50,
                                        n_boardings=1,
                                        first_leg_is_walk=False),
            stop_2_labels)
        self.assertIn(
            LabelTimeWithBoardingsCount(25,
                                        35,
                                        n_boardings=2,
                                        first_leg_is_walk=False),
            stop_2_labels)
        self.assertIn(
            LabelTimeWithBoardingsCount(25,
                                        45,
                                        n_boardings=1,
                                        first_leg_is_walk=False),
            stop_2_labels)

        stop_one_profile = csa_profile.stop_profiles[1]
        stop_one_pareto_labels = stop_one_profile.get_final_optimal_labels()

        labels = list()
        # these should exist at least:
        labels.append(
            LabelTimeWithBoardingsCount(departure_time=10,
                                        arrival_time_target=35,
                                        n_boardings=3,
                                        first_leg_is_walk=False))
        labels.append(
            LabelTimeWithBoardingsCount(departure_time=20,
                                        arrival_time_target=50,
                                        n_boardings=1,
                                        first_leg_is_walk=False))
        labels.append(
            LabelTimeWithBoardingsCount(departure_time=32,
                                        arrival_time_target=55,
                                        n_boardings=1,
                                        first_leg_is_walk=False))
Пример #20
0
 def test_boardings_computations_based_on_journeys(self):
     # input some journeys
     destination_stop = 1
     origin_stop = 2
     self.jdm.import_journey_data_for_target_stop(
         destination_stop, {
             origin_stop: [
                 LabelTimeWithBoardingsCount(1, 2, 1, True),
                 LabelTimeWithBoardingsCount(2, 3, 2, True)
             ]
         },
         enforce_synchronous_writes=True)
     self.jdm.compute_and_store_travel_impedance_measures(
         0, 2, self.data_store_path)
     store = TravelImpedanceDataStore(self.data_store_path)
     df = store.read_data_as_dataframe("temporal_distance")
     self.assertAlmostEqual(df.iloc[0]["min"], 1)
     self.assertAlmostEqual(df.iloc[0]["mean"], 1.5)
     self.assertAlmostEqual(df.iloc[0]["max"], 2.0)
     self.assertIn(df.iloc[0]["median"], [1, 2, 1.0, 1.5, 2.0])
 def test_n_boardings_on_fastest_trip(self):
     labels = [
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=22,
                                     n_boardings=4,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=24,
                                     n_boardings=2,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=26,
                                     n_boardings=1,
                                     first_leg_is_walk=False)
     ]
     analyzer = self._get_analyzer(labels,
                                   start_time=0,
                                   end_time=11,
                                   walk_to_target_duration=float('inf'))
     self.assertEqual(analyzer.n_boardings_on_fastest_trip(), 4)
 def test_min_n_boardings_on_fastest_paths(self):
     labels = [
         LabelTimeWithBoardingsCount(departure_time=5,
                                     arrival_time_target=12,
                                     n_boardings=4,
                                     first_leg_is_walk=False),
     ]
     analyzer = self._get_analyzer(labels,
                                   0,
                                   10,
                                   walk_to_target_duration=10)
     self.assertEqual(analyzer.min_n_boardings_on_shortest_paths(), 0)
 def test_min_n_boardings_after_departure_time_2(self):
     # (This tests the bug experienced with the Jollas region)
     labels = [
         LabelTimeWithBoardingsCount(departure_time=12,
                                     arrival_time_target=14,
                                     n_boardings=2,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=11,
                                     arrival_time_target=12,
                                     n_boardings=3,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=5,
                                     arrival_time_target=10,
                                     n_boardings=4,
                                     first_leg_is_walk=False),
     ]
     analyzer = self._get_analyzer(labels,
                                   0,
                                   10,
                                   walk_to_target_duration=float('inf'))
     self.assertEqual(analyzer.min_n_boardings(), 2)
 def test_mean_temporal_distance_with_min_n_boardings(self):
     labels = [
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=22,
                                     n_boardings=4,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=24,
                                     n_boardings=2,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=26,
                                     n_boardings=1,
                                     first_leg_is_walk=False)
     ]
     analyzer = self._get_analyzer(labels,
                                   0,
                                   5,
                                   walk_to_target_duration=float('inf'))
     self.assertEqual(
         analyzer.mean_temporal_distance_with_min_n_boardings(),
         2.5 + 5 + 26 - 10)
Пример #25
0
 def test_compute_pareto_front_smart(self):
     labels = []
     for n in [1, 2, 10]: #, 500]:
         for dep_time in range(0, n):
             for n_veh_legs in range(2):
                 for arr_time in range(dep_time, dep_time  + 10):
                     label = LabelTimeWithBoardingsCount(dep_time, arr_time - n_veh_legs, n_veh_legs, False)
                     labels.append(label)
         import random
         random.shuffle(labels)
         labels_copy = copy.deepcopy(labels)
         pareto_optimal_labels = compute_pareto_front_naive(labels)
         self.assertEqual(len(pareto_optimal_labels), n * 2)
         pareto_optimal_labels = compute_pareto_front(labels_copy)
         self.assertEqual(len(pareto_optimal_labels), n * 2)
 def test_temporal_distances_by_n_vehicles(self):
     labels = [
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=12,
                                     n_boardings=4,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=15,
                                     n_boardings=2,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=17,
                                     n_boardings=1,
                                     first_leg_is_walk=False)
     ]
     analyzer = self._get_analyzer(labels,
                                   0,
                                   10,
                                   walk_to_target_duration=10)
     median_temporal_distances = analyzer.median_temporal_distances()
     self.assertEqual(len(median_temporal_distances), 4 + 1)
     for i in range(len(median_temporal_distances) - 1):
         assert (median_temporal_distances[i] >=
                 median_temporal_distances[i + 1])
Пример #27
0
    def test_simple(self):
        event_list_raw_data = [
            (2, 4, 40, 50, "trip_5", 1),
        ]
        transit_connections = list(
            map(lambda el: Connection(*el), event_list_raw_data))
        walk_network = networkx.Graph()
        walk_network.add_edge(1, 2, d_walk=20)
        walk_network.add_edge(3, 4, d_walk=15)
        walk_speed = 1
        source_stop = 1
        target_stop = 4
        transfer_margin = 0
        start_time = 0
        end_time = 50

        csa_profile = MultiObjectivePseudoCSAProfiler(transit_connections,
                                                      target_stop, start_time,
                                                      end_time,
                                                      transfer_margin,
                                                      walk_network, walk_speed)
        csa_profile.run()
        source_stop_profile = csa_profile.stop_profiles[source_stop]
        self.assertTrue(source_stop_profile._finalized)
        self.assertTrue(source_stop_profile._closed)

        source_stop_labels = source_stop_profile.get_final_optimal_labels()

        labels = list()
        labels.append(
            LabelTimeWithBoardingsCount(departure_time=20,
                                        arrival_time_target=50,
                                        n_boardings=1,
                                        first_leg_is_walk=True))

        self._assert_label_sets_equal(labels, source_stop_labels)
 def test_plot(self):
     labels = [
         LabelTimeWithBoardingsCount(departure_time=20,
                                     arrival_time_target=22,
                                     n_boardings=5,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=15,
                                     arrival_time_target=20,
                                     n_boardings=6,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=14,
                                     arrival_time_target=21,
                                     n_boardings=5,
                                     first_leg_is_walk=False),
         LabelTimeWithBoardingsCount(departure_time=13,
                                     arrival_time_target=22,
                                     n_boardings=4,
                                     first_leg_is_walk=False),
         # LabelTimeWithBoardingsCount(departure_time=12, arrival_time_target=23, n_vehicle_legs=3),
         LabelTimeWithBoardingsCount(departure_time=11,
                                     arrival_time_target=24,
                                     n_boardings=2,
                                     first_leg_is_walk=True),
         LabelTimeWithBoardingsCount(departure_time=10,
                                     arrival_time_target=25,
                                     n_boardings=1,
                                     first_leg_is_walk=True),
         LabelTimeWithBoardingsCount(departure_time=5,
                                     arrival_time_target=10,
                                     n_boardings=1,
                                     first_leg_is_walk=True)
     ]
     analyzer = self._get_analyzer(labels, 0, 20, 35)
     print(fig)
     import matplotlib.pyplot as plt
     plt.show()
def plot_transfer_profile():
    alphabetical_labels = list(labels_t_dep_dur_b)
    alphabetical_labels.sort(key=lambda el: el[-1])
    for label in alphabetical_labels:
        print(label[-1] + " & " + str(label[0]) + " & " +
              str(label[0] + label[1]) + " & " + str(label[1]) + " & " +
              str(label[2]) + " \\\\")

    labels = [
        LabelTimeWithBoardingsCount(departure_time=label[0],
                                    arrival_time_target=label[0] + label[1],
                                    n_boardings=label[2],
                                    first_leg_is_walk=False)
        for label in labels_t_dep_dur_b
    ]

    dep_times = list(set(map(lambda el: el.departure_time, labels)))
    p = NodeProfileMultiObjective(dep_times=dep_times,
                                  walk_to_target_duration=10,
                                  label_class=LabelTimeWithBoardingsCount)

    for label in labels:
        p.update([label])

    p.finalize()
    analyzer = NodeProfileAnalyzerTimeAndVehLegs(p, 0, 20)
    print(analyzer.mean_n_boardings_on_shortest_paths())

    journey_letters = [label[-1] for label in labels_t_dep_dur_b[::-1]]

    fig = plt.figure(figsize=(5.5, 3.5))
    ax1 = plt.subplot(gs[:, :4])
    fig = analyzer.plot_new_transfer_temporal_distance_profile(
        format_string="%S",
        duration_divider=1,
        default_lw=4,
        journey_letters=journey_letters,
        ax=ax1,
        ncol_legend=2,
        legend_font_size=9)

    ax1.set_xlabel("Departure time $t_{\\text{dep}}$ (min)")
    ax1.set_ylabel("Temporal distance $\\tau$ (min)")

    ax2 = plt.subplot(gs[:, 4:])
    ax2 = analyzer.plot_temporal_distance_pdf_horizontal(use_minutes=True,
                                                         duration_divider=1,
                                                         ax=ax2,
                                                         legend_font_size=9)

    ax2.set_ylabel("")

    ax1.set_ylim(0, 11.5)
    ax2.set_ylim(0, 11.5)
    ax2.set_xlim(0, 0.3)
    ax2.set_yticklabels(["" for _ in ax2.get_yticks()])
    ax2.set_xlabel("Probability density $P(\\tau)$")
    ax2.set_xticks([0.1, 0.2, 0.3])

    for _ax, letter in zip([ax1, ax2], "AB"):
        _ax.text(0.04,
                 0.98,
                 "\\textbf{" + letter + "}",
                 horizontalalignment="left",
                 verticalalignment="top",
                 transform=_ax.transAxes,
                 fontsize=15,
                 color="black")
    fig.savefig(settings.FIGS_DIRECTORY + "schematic_transfer_profile.pdf")
    plt.show()
 def test_identity_profile(self):
     identity_profile = NodeProfileMultiObjective(dep_times=[10])
     identity_profile.update([LabelTimeWithBoardingsCount(10, 10, 0, True)])
     self.assertEqual(10, min_arrival_time_target(identity_profile.evaluate(10, first_leg_can_be_walk=True)))