Example #1
0
    def test_reset(self):
        walk_speed = 1
        target_stop = 2
        start_time = 0
        end_time = 60
        transfer_margin = 0
        transit_connections = [
            Connection(0, 1, 40, 50, "trip_1", 1),
            Connection(1, 2, 55, 60, "trip_1", 1),
            Connection(3, 1, 40, 60, "trip_2", 1)
        ]
        csa_profile = MultiObjectivePseudoCSAProfiler(transit_connections,
                                                      target_stop, start_time,
                                                      end_time,
                                                      transfer_margin,
                                                      networkx.Graph(),
                                                      walk_speed)
        csa_profile.run()
        nodes = [0, 1, 2, 3]
        label_counts = [1, 1, 0, 0]
        for node, count in zip(nodes, label_counts):
            n_labels = len(
                csa_profile.stop_profiles[node].get_final_optimal_labels())
            self.assertEqual(n_labels, count)

        target_stops = [1]
        csa_profile.reset(target_stops)
        csa_profile.run()
        label_counts = [1, 0, 0, 1]
        for node, count in zip(nodes, label_counts):
            n_labels = len(
                csa_profile.stop_profiles[node].get_final_optimal_labels())
            self.assertEqual(n_labels, count)
Example #2
0
    def loop_trough_targets_and_run_routing(self, targets, slurm_array_i):
        net, connections = self.get_all_events()
        csp = None

        for target in targets:
            print(target)
            if csp is None:
                csp = MultiObjectivePseudoCSAProfiler(connections, target, walk_network=net,
                                                      end_time_ut=self.routing_end_time,
                                                      transfer_margin=TRANSFER_MARGIN,
                                                      start_time_ut=self.routing_start_time, walk_speed=WALK_SPEED,
                                                      verbose=True, track_vehicle_legs=TRACK_VEHICLE_LEGS,
                                                      track_time=TRACK_TIME, track_route=TRACK_ROUTE)
            else:
                csp.reset([target])
            csp.run()

            profiles = dict(csp.stop_profiles)
            if self.pickle:
                self._pickle_results(profiles, slurm_array_i, target)
            else:
                self.jdm.import_journey_data_for_target_stop(target, profiles)
            profiles = None
            gc.collect()