Exemple #1
0
def test_pat_growth_type_validation():
    PathSet.WEIGHTS_FIXED_WIDTH = True
    Assignment.read_weights(INPUT_WEIGHTS)
    check, error_str = PathSet.verify_weights(PathSet.WEIGHTS_DF)
    assert check

    sample = pd.DataFrame(
        data={
            'user_class': ['all'] * 7,
            'purpose': ['other'] * 7,
            'demand_mode_type': ['access'] * 7,
            'demand_mode': ['walk'] * 7,
            'supply_mode': ['walk_access'] * 7,
            'weight_name': ['depart_early_min'] * 7,
            'weight_value': list(np.random.rand(7)),
            'growth_type': ['linear'] * 2 + ['logarithmic'] * 2 +
            ['logistic'] * 3,
            'log_base': [np.nan] * 3 + list(np.random.rand(2)) + [np.nan] * 2,
            'logistic_mid': [np.nan] * 5 + [1.3] + [np.nan],
            'logistic_max': [16] + [np.nan] * 5 + [1.3],
        })

    check, error_str = PathSet.verify_weights(sample)
    assert not check

    expected_error = '\n-------Errors: pathweight_ft.txt---------------\n' \
                     'Logistic qualifier includes log_base modifier\n' \
                     'Logarithmic qualifier missing necessary log_base modifier\n' \
                     'Logistic qualifier missing necessary modifiers\n'

    assert expected_error == error_str
Exemple #2
0
def simulation_paths(ft_instance, pathfinder_paths):
    """
    Generate the assignment simulation calculate_cost results for a set of demand inputs. This
    method yields results, so that it could potentially be recycled for multiple tests.
    :return: (sim_pathset_paths, sim_pathset_links)
    """

    ft = ft_instance

    pf_pathset_paths = pathfinder_paths[0]
    pf_pathset_links = pathfinder_paths[1]

    veh_trips_df = ft.trips.get_full_trips()

    sim_pathset_links = pf_pathset_links.copy()
    sim_pathset_paths = pf_pathset_paths.copy()

    sim_pathset_links = Assignment.find_passenger_vehicle_times(sim_pathset_links, veh_trips_df)
    (sim_pathset_paths, sim_pathset_links) = Assignment.flag_missed_transfers(sim_pathset_paths,
                                                                              sim_pathset_links)

    yield PathSet.calculate_cost(
        Assignment.STOCH_DISPERSION, sim_pathset_paths, sim_pathset_links, veh_trips_df,
        ft.passengers.trip_list_df, ft.routes, ft.tazs, ft.transfers, stops=ft.stops,
        reset_bump_iter=False
    )
Exemple #3
0
def test_parse_weight_qualifiers_bad_logistic_mid_qualifier_value(sample_dataframe):
    """
    Test to ensure the validation on qualifier types is working.
    """
    sample_dataframe.loc[sample_dataframe[PathSet.WEIGHTS_COLUMN_WEIGHT_NAME] ==
                         'depart_early_cost_min.logistic.logistic_mid', 'weight_value'] = -1
    with raises(AssertionError):
        Assignment.process_weight_qualifiers(sample_dataframe)
Exemple #4
0
def test_parse_weight_qualifiers_bad_logrithmic_qualifier_value(sample_dataframe):
    """
    Test to ensure the validation on qualifier types is working.
    """
    sample_dataframe.loc[sample_dataframe[PathSet.WEIGHTS_COLUMN_WEIGHT_NAME] ==
                         'arrive_late_cost_min.logarithmic.log_base', 'weight_value'] = -1
    with raises(AssertionError, message="Expecting AssertionError"):
        Assignment.process_weight_qualifiers(sample_dataframe)
Exemple #5
0
def test_parse_weight_qualifiers_bad_key(sample_dataframe):
    """
    Test to ensure the validation on qualifier types is working.
    """
    sample_dataframe.loc[sample_dataframe[PathSet.WEIGHTS_COLUMN_WEIGHT_NAME].str.contains('logistic') , 'weight_name'] = \
        sample_dataframe[PathSet.WEIGHTS_COLUMN_WEIGHT_NAME].str.replace('logistic', 'logging')

    with raises(KeyError):
        Assignment.process_weight_qualifiers(sample_dataframe)
def test_parse_weight_qualifiers_bad_logistic_qualifier(sample_dataframe):
    """
    Test to ensure the validation on qualifier types is working.
    """
    sample_dataframe.loc[sample_dataframe[PathSet.WEIGHTS_COLUMN_WEIGHT_NAME] == 'depart_early_cost_min.logistic.logistic_max' , 'weight_name'] = \
        'depart_early_cost_min.logistic.logistic_max_bad'

    with raises(AssertionError, message="Expecting AssertionError"):
        Assignment.process_weight_qualifiers(sample_dataframe)
Exemple #7
0
def test_no_qualifiers(sample_dataframe):
    """
     Test to ensure that dataframe without qualifiers is return the same as it went in.
    """
    weights = sample_dataframe[~sample_dataframe[PathSet.WEIGHTS_COLUMN_WEIGHT_NAME].str.contains('\.')].copy()
    result_df = Assignment.process_weight_qualifiers(weights)
    weights['growth_type'] = PathSet.CONSTANT_GROWTH_MODEL
    pd.testing.assert_frame_equal(result_df, weights, check_exact=True, check_frame_type=True)
Exemple #8
0
def test_parse_weight_qualifiers(sample_dataframe, expected_dataframe):
    """
    Test to ensure that the pathweight_ft pivot for qualifiers is working as expected.
    """
    results_df = Assignment.process_weight_qualifiers(sample_dataframe)

    pd.testing.assert_frame_equal(results_df.sort_values(sort_cols).reset_index(drop=True),
                                  expected_dataframe.sort_values(sort_cols).reset_index(drop=True),
                                  check_like=True)
def pathfinder_paths(ft_instance, config_scenario):
    """
    Generate the C++ pathfinder results for a set of demand inputs. This method yields
    results, so that it could potentially be recycled for multiple tests.
    :return: (pf_pathset_paths, pf_pathset_links)
    """

    ft = ft_instance
    OUTPUT_FOLDER = os.path.join(EXAMPLE_DIR, 'output', 'test_cost_symmetry',
                                 config_scenario)

    # for debugging insight
    Assignment.write_configuration(OUTPUT_FOLDER)

    veh_trips_df = ft.trips.get_full_trips()

    Trip.reset_onboard(veh_trips_df)

    Assignment.initialize_fasttrips_extension(0, OUTPUT_FOLDER, veh_trips_df)

    # This statement looks weird, but it is required later when setting up passenger pathsets
    ft.passengers.pathfind_trip_list_df = ft.passengers.trip_list_df

    path_cols = list(ft.passengers.pathfind_trip_list_df.columns.values)
    for path_tuple in ft.passengers.pathfind_trip_list_df.itertuples(
            index=False):
        path_dict = dict(list(zip(path_cols, path_tuple)))
        trip_list_id = path_dict[Passenger.TRIP_LIST_COLUMN_TRIP_LIST_ID_NUM]

        trip_pathset = PathSet(path_dict)
        ft.passengers.add_pathset(trip_list_id, trip_pathset)

        (pathdict, perf_dict) = \
            Assignment.find_trip_based_pathset(1, 1, trip_pathset,
                                               Assignment.PATHFINDING_TYPE ==
                                               Assignment.PATHFINDING_TYPE_STOCHASTIC,
                                               trace=path_dict[Passenger.TRIP_LIST_COLUMN_TRACE])

        trip_pathset.pathdict = pathdict

    yield ft.passengers.setup_passenger_pathsets(
        1, 1, ft.stops, ft.trips.trip_id_df, ft.trips.trips_df,
        ft.routes.modes_df, ft.transfers, ft.tazs,
        Assignment.PREPEND_ROUTE_ID_TO_TRIP_ID)