def _compute_real_connection_labels(self): pareto_optimal_labels = [] # do not take those bags with first event is a pseudo-connection for dep_time in self._connection_dep_times: index = self.dep_times_to_index[dep_time] pareto_optimal_labels.extend([label for label in self._label_bags[index] if not label.first_leg_is_walk]) if self.label_class == LabelTimeWithBoardingsCount or self.label_class == LabelTime \ or self.label_class == LabelTimeBoardingsAndRoute: pareto_optimal_labels = [label for label in pareto_optimal_labels if label.duration() < self._walk_to_target_duration] if self.label_class == LabelVehLegCount and self._walk_to_target_duration < float('inf'): pareto_optimal_labels.append(LabelVehLegCount(0)) self._real_connection_labels = [label.get_copy() for label in compute_pareto_front(pareto_optimal_labels, finalization=True)]
def test_sort(self): l1 = LabelVehLegCount(departure_time=1, n_boardings=3) l2 = LabelVehLegCount(departure_time=0, n_boardings=0) self.assertTrue(l2 > l1) self.assertTrue(l2 >= l1) self.assertFalse(l2 < l1) self.assertFalse(l2 <= l1) l1 = LabelVehLegCount(departure_time=0, n_boardings=0) l2 = LabelVehLegCount(departure_time=0, n_boardings=0) self.assertTrue(l1 == l2) self.assertTrue(l1 >= l2) self.assertTrue(l1 <= l2) self.assertFalse(l1 != l2) l1 = LabelVehLegCount(departure_time=0, n_boardings=1) l2 = LabelVehLegCount(departure_time=0, n_boardings=0) self.assertFalse(l1 > l2) self.assertTrue(l1 < l2) self.assertTrue(l1 <= l2) self.assertTrue(l1 != l2) self.assertTrue(sorted([l1, l2])[0] == l1)
def test_pareto_frontier(self): pt3 = LabelVehLegCount(departure_time=5, n_boardings=0) pt2 = LabelVehLegCount(departure_time=6, n_boardings=1) pt1 = LabelVehLegCount(departure_time=7, n_boardings=2) labels = [pt1, pt2, pt3] self.assertEqual(1, len(compute_pareto_front(labels)))
def test_dominates_simple(self): label1 = LabelVehLegCount(n_boardings=1) label2 = LabelVehLegCount(n_boardings=0) self.assertTrue(label2.dominates(label1))