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_only(self): LabelClass = LabelVehLegCount node_profile = NodeProfileMultiObjective(dep_times=[5, 6, 7], label_class=LabelClass) pt3 = LabelClass(departure_time=5, n_vehicle_legs=0, last_leg_is_walk=False) pt2 = LabelClass(departure_time=6, n_vehicle_legs=1, last_leg_is_walk=False) pt1 = LabelClass(departure_time=7, n_vehicle_legs=2, last_leg_is_walk=False) self.assertTrue(node_profile.update([pt1])) self.assertTrue(node_profile.update([pt2])) self.assertTrue(node_profile.update([pt3])) node_profile.finalize() self.assertEqual(1, len(node_profile.get_final_optimal_labels()))
def _get_analyzer(self, labels, start_time, end_time, walk_to_target_duration=float('inf')): dep_times = list(set(map(lambda el: el.departure_time, labels))) p = NodeProfileMultiObjective( dep_times=dep_times, walk_to_target_duration=walk_to_target_duration, label_class=LabelTimeWithBoardingsCount) for label in labels: p.update([label]) p.finalize() analyzer = NodeProfileAnalyzerTimeAndVehLegs.from_profile( p, start_time, end_time) return analyzer
def __compute_profile_stats_from_profiles(profile_data): """ Parameters ---------- profiles: dict mapping from stop_I -> MultiObjectiveNodeProfile Returns ------- observable_name_to_data: dict """ profile_summary_methods, profile_observable_names = NodeProfileAnalyzerTimeAndVehLegs.all_measures_and_names_as_lists( ) profile_summary_data = [[] for _ in range(len(profile_observable_names))] observable_name_to_method = dict( zip(profile_observable_names, profile_summary_methods)) observable_name_to_data = dict( zip(profile_observable_names, profile_summary_data)) nodes = pandas.read_csv(HELSINKI_NODES_FNAME, sep=";") for stop_I in nodes['stop_I'].values: try: profile = profile_data[stop_I] except KeyError: profile = NodeProfileMultiObjective() profile.finalize() profile_analyzer = NodeProfileAnalyzerTimeAndVehLegs( profile, ANALYSIS_START_TIME_DEP, ANALYSIS_END_TIME_DEP) for observable_name in profile_observable_names: method = observable_name_to_method[observable_name] observable_value = method(profile_analyzer) if observable_value is None: print(observable_name, stop_I) _assert_results_are_positive_or_infs_or_nans( numpy.array([observable_value])) observable_name_to_data[observable_name].append(observable_value) return observable_name_to_data
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()