Exemplo n.º 1
0
def test_artificially_filling_in_solution_for_partial_pt_routing_problem_results_in_correct_solution_and_routed_path(
        mocker, test_network, test_spatialtree):
    df = DataFrame({
        'index_left': {4: 4611, 5: 2836, 6: 1620, 7: 1619, 8: 4612, 9: 4611,
                       10: 1929, 11: 17, 12: 18, 13: 2291, 14: 17, 15: 2804, 16: 3361},
        'link_id': {4: '5221390698590575489_5221390721979501095', 5: '52213908340665748775221390828301496736',
                    6: '5221390721979501095_5221390721979501095', 7: '5221390721979501095_5221390721985855617',
                    8: '5221390698590575489_5221390698590575489', 9: '5221390698590575489_5221390721979501095',
                    10: '5221390698557344687_5221390698590575489', 11: '5221390688502743083_5221390698590575489',
                    12: '5221390688502743083_5221390688502743083', 13: '5221390319100521975_5221390688502743083',
                    14: '5221390688502743083_5221390698590575489', 15: '5221390319261602009_5221390688502743083',
                    16: '5221390688613602227_5221390688502743083'},
        'id': {4: '5221390721979501095', 5: '5221390721979501095', 6: '5221390721979501095', 7: '5221390721979501095',
               8: '5221390698590575489', 9: '5221390698590575489', 10: '5221390698590575489',
               11: '5221390698590575489', 12: '5221390688502743083', 13: '5221390688502743083',
               14: '5221390688502743083', 15: '5221390688502743083', 16: '5221390688502743083'},
        'catchment': {4: 5, 5: 5, 6: 5, 7: 5, 8: 5, 9: 5,
                      10: 5, 11: 5, 12: 5, 13: 5, 14: 5, 15: 5, 16: 5},
        'problem_nodes': {
            4: '5221390721979501095.link:5221390698590575489_5221390721979501095',
            5: '5221390721979501095.link:52213908340665748775221390828301496736',
            6: '5221390721979501095.link:5221390721979501095_5221390721979501095',
            7: '5221390721979501095.link:5221390721979501095_5221390721985855617',
            8: '5221390698590575489.link:5221390698590575489_5221390698590575489',
            9: '5221390698590575489.link:5221390698590575489_5221390721979501095',
            10: '5221390698590575489.link:5221390698557344687_5221390698590575489',
            11: '5221390698590575489.link:5221390688502743083_5221390698590575489',
            12: '5221390688502743083.link:5221390688502743083_5221390688502743083',
            13: '5221390688502743083.link:5221390319100521975_5221390688502743083',
            14: '5221390688502743083.link:5221390688502743083_5221390698590575489',
            15: '5221390688502743083.link:5221390319261602009_5221390688502743083',
            16: '5221390688502743083.link:5221390688613602227_5221390688502743083'}}).set_index('id', drop=False)
    df.index.rename(name='index', inplace=True)
    mocker.patch.object(spatial.SpatialTree, 'closest_links',
                        return_value=df)

    mss = MaxStableSet(pt_graph=test_network.schedule.route('40230_1').graph(),
                       network_spatial_tree=test_spatialtree,
                       modes={'car', 'bus'},
                       distance_threshold=5,
                       step_size=5)
    assert not mss.all_stops_have_nearest_links()
    mss.solve()
    assert mss.unsolved_stops == {'5221390319100521975'}
    mss.route_edges()
    mss.fill_in_solution_artificially()

    art_link = 'artificial_link===from:5221390319100521975===to:5221390319100521975'
    assert mss.solution['5221390319100521975'] == art_link
    art_stop = '5221390319100521975.link:artificial_link===from:5221390319100521975===to:5221390319100521975'
    assert art_stop in mss.artificial_stops
    assert mss.artificial_stops[art_stop]['linkRefId'] == art_link
    assert mss.artificial_stops[art_stop]['stop_id'] == '5221390319100521975'
    assert mss.artificial_stops[art_stop]['id'] == art_stop
    assert mss.routed_path(
        ['5221390319100521975', '5221390688502743083', '5221390698590575489', '5221390721979501095']) == [
               'artificial_link===from:5221390319100521975===to:5221390319100521975',
               'artificial_link===from:5221390319100521975===to:5221390688502743083',
               '5221390688502743083_5221390698590575489', '5221390698590575489_5221390721979501095']
Exemplo n.º 2
0
def test_snapping_disconnected_partial_pt_route_results_in_all_stops_with_link_references_and_routes_between_viable_catchments(
        mocker, test_network, test_spatialtree):
    df = DataFrame({
        'index_left': {0: 2291, 1: 2290, 2: 2292, 3: 5178, 4: 4611, 5: 2836, 6: 1620, 7: 1619, 8: 4612, 9: 4611,
                       10: 1929, 11: 17, 12: 18, 13: 2291, 14: 17, 15: 2804, 16: 3361},
        'link_id': {0: '5221390319100521975_5221390688502743083', 1: '5221390319100521975_5221390319062365867',
                    2: '5221390319100521975_5221390319100521975', 3: '5221390319091334983_5221390319100521975',
                    4: '5221390698590575489_5221390721979501095', 5: '52213908340665748775221390828301496736',
                    6: '5221390721979501095_5221390721979501095', 7: '5221390721979501095_5221390721985855617',
                    12: '5221390688502743083_5221390688502743083', 13: '5221390319100521975_5221390688502743083',
                    14: '5221390688502743083_5221390698590575489', 15: '5221390319261602009_5221390688502743083',
                    16: '5221390688613602227_5221390688502743083'},
        'id': {0: '5221390319100521975', 1: '5221390319100521975', 2: '5221390319100521975', 3: '5221390319100521975',
               4: '5221390721979501095', 5: '5221390721979501095', 6: '5221390721979501095', 7: '5221390721979501095',
               12: '5221390688502743083', 13: '5221390688502743083',
               14: '5221390688502743083', 15: '5221390688502743083', 16: '5221390688502743083'},
        'catchment': {0: 5, 1: 5, 2: 5, 3: 5, 4: 5, 5: 5, 6: 5, 7: 5, 12: 5, 13: 5, 14: 5, 15: 5, 16: 5},
        'problem_nodes': {
            0: '5221390319100521975.link:5221390319100521975_5221390688502743083',
            1: '5221390319100521975.link:5221390319100521975_5221390319062365867',
            2: '5221390319100521975.link:5221390319100521975_5221390319100521975',
            3: '5221390319100521975.link:5221390319091334983_5221390319100521975',
            4: '5221390721979501095.link:5221390698590575489_5221390721979501095',
            5: '5221390721979501095.link:52213908340665748775221390828301496736',
            6: '5221390721979501095.link:5221390721979501095_5221390721979501095',
            7: '5221390721979501095.link:5221390721979501095_5221390721985855617',
            12: '5221390688502743083.link:5221390688502743083_5221390688502743083',
            13: '5221390688502743083.link:5221390319100521975_5221390688502743083',
            14: '5221390688502743083.link:5221390688502743083_5221390698590575489',
            15: '5221390688502743083.link:5221390319261602009_5221390688502743083',
            16: '5221390688502743083.link:5221390688613602227_5221390688502743083'}}).set_index('id', drop=False)
    df.index.rename(name='index', inplace=True)
    mocker.patch.object(spatial.SpatialTree, 'closest_links',
                        return_value=df)

    mss = MaxStableSet(pt_graph=test_network.schedule.route('40230_1').graph(),
                       network_spatial_tree=test_spatialtree,
                       modes={'car', 'bus'},
                       distance_threshold=5,
                       step_size=5)
    assert not mss.all_stops_have_nearest_links()
    mss.solve()
    assert mss.unsolved_stops == {'5221390698590575489', '5221390721979501095'}
    mss.route_edges()
    assert set(mss.pt_edges[mss.pt_edges['shortest_path'].isna()]['u']) == {'5221390698590575489',
                                                                            '5221390688502743083'}
    assert set(mss.pt_edges[mss.pt_edges['shortest_path'].isna()]['v']) == {'5221390698590575489',
                                                                            '5221390721979501095'}
Exemplo n.º 3
0
def test_detects_stops_that_lack_nearest_links(mocker, network, network_spatial_tree):
    closest_links = DataFrame({
        'id': {0: 'stop_2', 1: 'stop_2', 2: 'stop_3', 3: 'stop_3'},
        'link_id': {0: 'link_4_5_car', 1: 'link_5_6_car', 2: 'link_7_8_car', 3: 'link_8_9_car'},
    }).set_index('id', drop=False)
    closest_links.index.rename(name='index', inplace=True)
    mocker.patch.object(spatial.SpatialTree, 'closest_links',
                        return_value=closest_links)

    mss = MaxStableSet(pt_graph=network.schedule['bus_service'].graph(),
                       network_spatial_tree=network_spatial_tree,
                       modes={'car', 'bus'},
                       step_size=10,
                       distance_threshold=10
                       )
    assert not mss.all_stops_have_nearest_links()