コード例 #1
0
    def test_prune_progress_dict(self):
        subject = Traverser(data=None, progress_between_pruning_progress_dict=None,
                            prune_thoroughness=.5, stop_join_string='~~', transfer_duration_seconds=None,
                            transfer_route=None, walk_route=None, walk_speed_mph=None, end_date=None,
                            route_types_to_solve=None, stops_to_solve=None)
        location_1 = LocationStatusInfo(location='1', arrival_route=1, unvisited='~~a~~b~~c~~')
        location_2 = LocationStatusInfo(location='2', arrival_route=2, unvisited='~~a~~c~~d~~b~~')
        location_3 = LocationStatusInfo(location='3', arrival_route=3, unvisited='~~a~~')
        location_4 = LocationStatusInfo(location='4', arrival_route=4, unvisited='~~a~~b~~c~~d~~e~~')
        eliminated_progress = ProgressInfo(duration=None, arrival_trip=None, trip_stop_no=None, parent=None,
                                           children=None,
                                           minimum_remaining_time=None, expanded=None, eliminated=True)
        subject._progress_dict = {
            location_1: eliminated_progress,
            location_2: eliminated_progress,
            location_3: eliminated_progress,
            location_4: eliminated_progress
        }
        subject._exp_queue = ExpansionQueue(num_solution_stops=5, stop_join_string='~~')
        subject._exp_queue.add([location_1, location_2, location_3, location_4])

        expected_progress_dict = {
            location_1: eliminated_progress,
            location_3: eliminated_progress
        }
        expected_expansion_queue_queue = {
            1: {location_3},
            3: {location_1}
        }
        subject.prune_progress_dict()
        actual_progress_dict = subject._progress_dict
        actual_expansion_queue_queue = subject._exp_queue._queue

        self.assertDictEqual(expected_progress_dict, actual_progress_dict)
        self.assertDictEqual(expected_expansion_queue_queue, actual_expansion_queue_queue)
コード例 #2
0
    def test_pop(self):
        location_a = LocationStatusInfo(location='a',
                                        arrival_route=None,
                                        unvisited="~~a~~")
        location_b = LocationStatusInfo(location='b',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        subject = ExpansionQueue(num_solution_stops=2, stop_join_string="~~")
        solver_progress_dict = {
            location_a:
            ProgressInfo(duration=1,
                         arrival_trip=None,
                         trip_stop_no=None,
                         parent=None,
                         children=None,
                         minimum_remaining_time=None,
                         expanded=None,
                         eliminated=True),
            location_b:
            ProgressInfo(duration=1,
                         arrival_trip=None,
                         trip_stop_no=None,
                         parent=None,
                         children=None,
                         minimum_remaining_time=None,
                         expanded=None,
                         eliminated=True),
        }

        subject.add([location_a, location_b])

        expected_queue = {2: {location_b}}
        expected_node = location_a
        expected_stop_to_pop = 2

        actual_node = subject.pop(solver_progress_dict)
        actual_queue = subject._queue
        actual_stop_to_pop = subject._num_remaining_stops_to_pop

        self.assertEqual(expected_node, actual_node)
        self.assertDictEqual(expected_queue, actual_queue)
        self.assertEqual(expected_stop_to_pop, actual_stop_to_pop)
コード例 #3
0
    def test_add(self):
        location_a = LocationStatusInfo(location='a',
                                        arrival_route=None,
                                        unvisited="~~a~~")
        location_b = LocationStatusInfo(location='b',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        nodes = [location_a, location_b, location_b]
        subject = ExpansionQueue(num_solution_stops=2, stop_join_string="~~")
        subject.add(nodes)
        expected_queue = {
            1: {location_a},
            2: {location_b, location_b},
        }
        expected_stop_to_pop = 1
        actual_queue = subject._queue
        actual_stop_to_pop = subject._num_remaining_stops_to_pop

        self.assertDictEqual(expected_queue, actual_queue)
        self.assertEqual(expected_stop_to_pop, actual_stop_to_pop)
コード例 #4
0
    def test_remove_keys(self):
        location_a = LocationStatusInfo(location='a',
                                        arrival_route=None,
                                        unvisited="~~a~~")
        location_b = LocationStatusInfo(location='b',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        location_c = LocationStatusInfo(location='c',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        location_d = LocationStatusInfo(location='d',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        location_e = LocationStatusInfo(location='e',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~c~~")
        location_f = LocationStatusInfo(location='f',
                                        arrival_route=None,
                                        unvisited="~~a~~c~~")
        subject = ExpansionQueue(num_solution_stops=2, stop_join_string="~~")
        subject.add([location_a, location_b, location_c, location_c])

        subject.remove_keys(
            [location_a, location_c, location_d, location_e, location_f])
        expected_queue = {2: {location_b}}
        expected_stop_to_pop = 2
        actual_queue = subject._queue
        actual_stop_to_pop = subject._num_remaining_stops_to_pop

        self.assertDictEqual(expected_queue, actual_queue)
        self.assertEqual(expected_stop_to_pop, actual_stop_to_pop)
コード例 #5
0
    def test_is_empty(self):
        location_a = LocationStatusInfo(location='a',
                                        arrival_route=None,
                                        unvisited="~~a~~")
        subject = ExpansionQueue(num_solution_stops=2, stop_join_string="~~")
        solver_progress_dict = {
            location_a:
            ProgressInfo(duration=1,
                         arrival_trip=None,
                         trip_stop_no=None,
                         parent=None,
                         children=None,
                         minimum_remaining_time=None,
                         expanded=None,
                         eliminated=True),
        }
        self.assertTrue(subject.is_empty())

        subject.add([location_a])
        self.assertFalse(subject.is_empty())

        subject.pop(solver_progress_dict)
        self.assertTrue(subject.is_empty())
コード例 #6
0
    def test_sort_latest_nodes(self):
        def progress_info_with_duration(duration):
            return ProgressInfo(arrival_trip=None,
                                duration=duration,
                                trip_stop_no=None,
                                expanded=None,
                                eliminated=None,
                                children=None,
                                parent=None,
                                minimum_remaining_time=None)

        location_b = LocationStatusInfo(location='b',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        location_c = LocationStatusInfo(location='c',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        location_d = LocationStatusInfo(location='d',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        location_e = LocationStatusInfo(location='e',
                                        arrival_route=None,
                                        unvisited="~~a~~b~~")
        solver_progress_dict = {
            location_b: progress_info_with_duration(1),
            location_c: progress_info_with_duration(2),
            location_d: progress_info_with_duration(3),
            location_e: progress_info_with_duration(4),
        }
        subject = ExpansionQueue(num_solution_stops=6, stop_join_string='~~')
        subject.add([location_d, location_e, location_b, location_c])
        subject.sort_latest_nodes(solver_progress_dict)

        expected = [location_b, location_c, location_d, location_e]
        actual = subject._queue[2]
        self.assertListEqual(expected, actual)