示例#1
0
def test_bunny(demand, network):
    """
    Test to ensure that the most simple of networks and demand is working.
    """
    EXAMPLE_DIR = os.path.join(os.getcwd(), "fasttrips", "Examples",
                               "Bunny_Hop")

    INPUT_NETWORK = os.path.join(EXAMPLE_DIR, "networks", network)
    INPUT_DEMAND = os.path.join(EXAMPLE_DIR, "demand", demand)
    INPUT_CONFIG = os.path.join(EXAMPLE_DIR, "configs", "base")
    OUTPUT_DIR = os.path.join(EXAMPLE_DIR, "output")

    Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                      input_demand_dir=INPUT_DEMAND,
                      run_config=os.path.join(INPUT_CONFIG, "config_ft.txt"),
                      input_functions=os.path.join(INPUT_CONFIG,
                                                   'config_ft.py'),
                      input_weights=os.path.join(INPUT_CONFIG,
                                                 "pathweight_ft.txt"),
                      output_dir=OUTPUT_DIR,
                      output_folder=demand + "-" + network,
                      pathfinding_type="stochastic",
                      capacity=False,
                      iters=1,
                      OVERLAP="None",
                      dispersion=0.5)
示例#2
0
def test_post_assignment():
    out_folder = "post_assignment_test"  # str(uuid.uuid4())
    Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                      input_demand_dir=INPUT_DEMAND,
                      run_config=CONFIG_FILE,
                      input_weights=INPUT_WEIGHTS,
                      output_dir=OUTPUT_DIR,
                      output_folder=out_folder,
                      skim_config_file=SKIMMING_CONFIG,
                      iters=1)
    files_exist(Path(OUTPUT_DIR) / out_folder)
示例#3
0
def test_convergence():
    '''
    This test uses the learning and convergence gap keywords in the config.
    '''

    Run.run_fasttrips(
        input_network_dir=INPUT_NETWORK,
        input_demand_dir=INPUT_DEMAND,
        run_config=CONFIG_FILE,
        input_functions=INPUT_FUNCTIONS,
        input_weights=INPUT_WEIGHTS,
        output_dir=OUTPUT_DIR,
        output_folder=OUTPUT_FOLDER,
        capacity=True,
        iters=10,
        dispersion=0.50,
        num_trips=10,
    )
示例#4
0
def run_convergence():
    EXAMPLE_DIR = os.path.join(os.getcwd(), "fasttrips", "Examples",
                               "Springfield")

    INPUT_NETWORK = os.path.join(EXAMPLE_DIR, "networks", "vermont")
    INPUT_DEMAND = os.path.join(EXAMPLE_DIR, "demand", "simpson_zorn")
    INPUT_CONFIG = os.path.join(EXAMPLE_DIR, "configs", "B")
    OUTPUT_DIR = os.path.join(EXAMPLE_DIR, "output")

    Run.run_fasttrips(
        input_network_dir=INPUT_NETWORK,
        input_demand_dir=INPUT_DEMAND,
        run_config=CONFIG_FILE,
        input_functions=INPUT_FUNCTIONS,
        input_weights=INPUT_WEIGHTS,
        output_dir=OUTPUT_DIR,
        output_folder=OUTPUT_FOLDER,
        pathfinding_type="stochastic",
        capacity=True,
        iters=4,
        dispersion=0.50,
        num_trips=10,
    )
示例#5
0
def test_psrc():
    """
    Test to ensure that more complex network, PSRC, is working. Also a
    useful benchmark for Partridge loader compared to transitfeed.
    """

    Run.run_fasttrips(
        input_network_dir=INPUT_NETWORK,
        input_demand_dir=INPUT_DEMAND,
        run_config=CONFIG_FILE,
        input_weights=INPUT_WEIGHTS,
        input_functions=INPUT_FUNCTIONS,
        output_dir=OUTPUT_DIR,
        output_folder="test_psrc",
        max_stop_process_count=2,
        pf_iters=2,
        overlap_variable="None",
        pathfinding_type="stochastic",
        capacity=True,
        iters=1,
        OVERLAP="None",
        dispersion=1.0,
        num_trips=5,
    )
示例#6
0
def test_max_stop_process_count(stop_process_count, passengers_arrived):
    r = Run.run_fasttrips(
        input_network_dir=INPUT_NETWORK,
        input_demand_dir=INPUT_DEMAND,
        run_config=CONFIG_FILE,
        input_weights=INPUT_WEIGHTS,
        output_dir=OUTPUT_DIR,
        output_folder="test_dispers_%4.2d" % stop_process_count,
        overlap_variable="None",
        pf_iters=2,
        pathfinding_type="stochastic",
        max_stop_process_count=stop_process_count,
        iters=1,
        num_trips=test_size,
        dispersion=0.50)

    assert passengers_arrived == r["passengers_arrived"]
示例#7
0
def test_assignment_type(assignment_type):
    OUTPUT_FOLDER = "assignment_type_%s" % (assignment_type)
    r = Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                          input_demand_dir=INPUT_DEMAND,
                          run_config=CONFIG_FILE,
                          input_weights=INPUT_WEIGHTS,
                          output_dir=OUTPUT_DIR,
                          output_folder=OUTPUT_FOLDER,
                          overlap_variable="None",
                          pf_iters=2,
                          max_stop_process_count=2,
                          pathfinding_type=assignment_type,
                          iters=1,
                          dispersion=0.50,
                          num_trips=5)

    assert r["passengers_arrived"] > 0
示例#8
0
def test_user_classes():
    r = Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                          input_demand_dir=INPUT_DEMAND,
                          run_config=CONFIG_FILE,
                          input_weights=INPUT_WEIGHTS,
                          input_functions=INPUT_FUNCTIONS,
                          output_dir=OUTPUT_DIR,
                          output_folder="test_userclasses",
                          max_stop_process_count=2,
                          pf_iters=2,
                          overlap_variable="None",
                          pathfinding_type="stochastic",
                          iters=1,
                          dispersion=0.50,
                          num_trips=5,
                          number_of_processes=1)

    assert r["passengers_arrived"] > 0
示例#9
0
def test_dispersion(dispersion_rate, utils_conversion_factor, passengers_arrived):
    r = Run.run_fasttrips(
        input_network_dir=INPUT_NETWORK,
        input_demand_dir=INPUT_DEMAND,
        run_config=os.path.join(INPUT_CONFIG, "config_ft.txt"),
        input_weights=os.path.join(INPUT_CONFIG, "pathweight_ft.txt"),
        output_dir=OUTPUT_DIR,
        output_folder="test_dispers_%4.2f" % dispersion_rate,
        max_stop_process_count=2,
        utils_conversion_factor=utils_conversion_factor,
        pf_iters=2,
        overlap_variable="None",
        pathfinding_type="stochastic",
        iters=1,
        dispersion=dispersion_rate,
        num_trips=test_size)

    assert passengers_arrived == r["passengers_arrived"]
示例#10
0
def test_feedback(feedback_iters, capacity_const):
    r = Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                          input_demand_dir=INPUT_DEMAND,
                          run_config=CONFIG_FILE,
                          input_weights=INPUT_WEIGHTS,
                          output_dir=OUTPUT_DIR,
                          output_folder="test_feedback_iters-%d_capConst-%s" %
                          (feedback_iters, capacity_const),
                          max_stop_process_count=2,
                          pf_iters=2,
                          overlap_variable="None",
                          utils_conversion_factor=10,
                          pathfinding_type="stochastic",
                          capacity=capacity_const,
                          iters=feedback_iters,
                          num_trips=5,
                          dispersion=0.50)

    assert r["passengers_arrived"] > 0
示例#11
0
def test_overlap(overlap_var, split_links):

    r = Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                          input_demand_dir=INPUT_DEMAND,
                          run_config=CONFIG_FILE,
                          input_weights=INPUT_WEIGHTS,
                          output_dir=OUTPUT_DIR,
                          output_folder="test_overlap_var-%s_split-%s" %
                          (overlap_var, split_links),
                          max_stop_process_count=2,
                          pf_iters=2,
                          pathfinding_type="stochastic",
                          overlap_variable=overlap_var,
                          overlap_split_transit=split_links,
                          iters=1,
                          dispersion=0.50,
                          num_trips=5)

    assert r["passengers_arrived"] > 0
示例#12
0
def test_fares(ignore_PF_fares, ignore_EN_fares):

    r = Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                          input_demand_dir=INPUT_DEMAND,
                          run_config=CONFIG_FILE,
                          input_weights=INPUT_WEIGHTS,
                          output_dir=OUTPUT_DIR,
                          output_folder="test_ignore_fares_PF-%s_EN-%s" %
                          (ignore_PF_fares, ignore_EN_fares),
                          pathfinding_type="stochastic",
                          max_stop_process_count=2,
                          pf_iters=2,
                          overlap_variable="None",
                          iters=1,
                          dispersion=0.50,
                          num_trips=5,
                          transfer_fare_ignore_pathfinding=ignore_PF_fares,
                          transfer_fare_ignore_pathenum=ignore_EN_fares)

    assert r["passengers_arrived"] > 0
示例#13
0
def test_overlap(overlap_var, split_links):
    if overlap_var == "time" and sys.version_info > (3, 0):
        pytest.xfail("python and pandas updates make time division fail for now Issue #172")

    r = Run.run_fasttrips(
        input_network_dir=INPUT_NETWORK,
        input_demand_dir=INPUT_DEMAND,
        run_config=CONFIG_FILE,
        input_weights=INPUT_WEIGHTS,
        output_dir=OUTPUT_DIR,
        output_folder="test_overlap_var-%s_split-%s" % (overlap_var, split_links),
        max_stop_process_count=2,
        pf_iters=2,
        pathfinding_type="stochastic",
        overlap_variable=overlap_var,
        overlap_split_transit=split_links,
        iters=1,
        dispersion=0.50,
        num_trips=5)

    assert r["passengers_arrived"] > 0
示例#14
0
import os
from fasttrips import Run

# DIRECTORY LOCATIONS
EXAMPLE_DIR = os.path.abspath(os.path.dirname(__file__))

INPUT_NETWORK = os.path.join(EXAMPLE_DIR, 'networks', 'vermont')
INPUT_DEMAND = os.path.join(EXAMPLE_DIR, 'demand', 'general')
INPUT_CONFIG = os.path.join(EXAMPLE_DIR, 'configs', 'A')
OUTPUT_DIR = os.path.join(EXAMPLE_DIR, 'output')
OUTPUT_FOLDER = "general_run"

# INPUT FILE LOCATIONS
CONFIG_FILE = os.path.join(INPUT_CONFIG, 'config_ft.txt')
INPUT_WEIGHTS = os.path.join(INPUT_CONFIG, 'pathweight_ft.txt')

print("Running Fast-Trips in %s" % (EXAMPLE_DIR.split(os.sep)[-1:]))

Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                  input_demand_dir=INPUT_DEMAND,
                  run_config=CONFIG_FILE,
                  input_weights=INPUT_WEIGHTS,
                  output_dir=OUTPUT_DIR,
                  output_folder=OUTPUT_FOLDER,
                  pathfinding_type="stochastic",
                  overlap_variable="count",
                  overlap_split_transit=True,
                  iters=3,
                  dispersion=0.50)
示例#15
0
import os
from fasttrips import Run

network = "psrc_1_1"
demand = "psrc_1_1"
config = "base"
out_folder = "seattle_base"

ex_dir = os.path.abspath(os.path.dirname(__file__))
print
"Running Fast-Trips in %s" % (ex_dir.split(os.sep)[-1:])

Run.run_fasttrips(
    input_network_dir=os.path.join(ex_dir, "networks", network),
    input_demand_dir=os.path.join(ex_dir, "demand", demand),
    run_config=os.path.join(ex_dir, "configs", config, "config_ft.txt"),
    input_weights=os.path.join(ex_dir, "configs", config, "pathweight_ft.txt"),
    input_functions=os.path.join(ex_dir, "configs", config, 'config_ft.py'),
    output_dir=os.path.join(ex_dir, "output"),
    output_folder=out_folder,
    pathfinding_type="stochastic",
    overlap_variable="count",
    overlap_split_transit=True,
    iters=1,
    dispersion=0.50)
示例#16
0
import os

from fasttrips import Run

EXAMPLES_DIR   = os.path.join(os.path.dirname(os.getcwd()),"fasttrips","Examples","test_scenario")

Run.run_fasttrips(
    input_network_dir    = os.path.join(EXAMPLES_DIR,"network"),
    input_demand_dir = os.path.join(EXAMPLES_DIR,"demand_reg"),
    run_config       = os.path.join(EXAMPLES_DIR,"demand_reg","config_ft.txt"),
    input_weights    = os.path.join(EXAMPLES_DIR,"demand_reg","pathweight_ft.txt"),
    output_dir       = os.path.join(EXAMPLES_DIR,"output"),
    output_folder    = "example",
    pathfinding_type = "stochastic",
    overlap_variable = "count",
    overlap_split_transit = True,
    iters            = 1,
    dispersion       = 0.50)

    
示例#17
0
def test_pat_before_and_after():
    """
    Test to ensure that some of the pathfinder trips are returned before preferred departure
    or after preferred arrival.
    """
    OUTPUT_FOLDER = 'pat_scenario'

    r = Run.run_fasttrips(input_network_dir=INPUT_NETWORK,
                          input_demand_dir=INPUT_DEMAND,
                          run_config=CONFIG_FILE,
                          input_weights=INPUT_WEIGHTS,
                          output_dir=OUTPUT_DIR,
                          output_folder=OUTPUT_FOLDER,
                          pathfinding_type="stochastic",
                          overlap_variable="count",
                          iters=1,
                          dispersion=0.50)

    links = pd.read_csv(os.path.join(OUTPUT_DIR, OUTPUT_FOLDER,
                                     'pathset_links.csv'),
                        usecols=[
                            'person_trip_id', 'pathnum', 'linkmode', 'linknum',
                            'new_A_time', 'new_B_time'
                        ],
                        parse_dates=['new_A_time', 'new_B_time'],
                        infer_datetime_format=True)

    trips = pd.read_csv(os.path.join(INPUT_DEMAND, 'trip_list.txt'),
                        usecols=[
                            'person_trip_id', 'departure_time', 'arrival_time',
                            'time_target'
                        ])

    departure_link = links.loc[links.groupby(['person_trip_id',
                                              'pathnum'])['linknum'].idxmin()]
    # The C++ Pathfinder doesn't seem to respect the last egress leg from a preferred time perspective
    arrival_link = links.loc[links[links.linkmode == 'transit'].groupby(
        ['person_trip_id', 'pathnum'])['linknum'].idxmax()]

    network_date = links['new_A_time'].dt.date.unique()[0]
    trips['arrival_time'] = trips['arrival_time'].apply(
        lambda x: parse_date(network_date, x))
    trips['departure_time'] = trips['departure_time'].apply(
        lambda x: parse_date(network_date, x))
    arrival_trips = trips[trips['time_target'] == 'arrival']
    departure_trips = trips[trips['time_target'] == 'departure']

    departures = pd.merge(departure_trips[['person_trip_id',
                                           'departure_time']],
                          departure_link[['person_trip_id', 'new_A_time']],
                          on=['person_trip_id'])

    arrivals = pd.merge(arrival_trips[['person_trip_id', 'arrival_time']],
                        arrival_link[['person_trip_id', 'new_B_time']],
                        on=['person_trip_id'])

    early_departure = departures[
        departures['new_A_time'] < departures['departure_time']]
    size = early_departure.shape[0]
    assert size > 0
    confirm_size = early_departure[(
        (early_departure['departure_time'] - early_departure['new_A_time']) /
        np.timedelta64(1, 'm')) <= 10].shape[0]
    assert size == confirm_size

    late_arrivals = arrivals[arrivals['new_B_time'] > arrivals['arrival_time']]
    size = late_arrivals.shape[0]
    assert size > 0
    confirm_size = \
    late_arrivals[((late_arrivals['new_B_time'] - late_arrivals['arrival_time']) / np.timedelta64(1, 'm')) <= 10].shape[
        0]
    assert size == confirm_size
示例#18
0
            print "Input Level: %s" % (inp)
            print "out folder %s\n" % (output_folder)

        else:
            if os.path.exists(output_folder):
                print "Path exists [%s] -- skipping" % output_folder
            else:
                from fasttrips import Run
                Run.run_fasttrips(
                    input_network_dir=network_inputs,
                    input_demand_dir=demand_inputs,
                    run_config=run_config,
                    input_weights=pathweights,
                    output_dir=base_dir,
                    iters=1,
                    output_folder=output_folder,
                    number_of_processes=proc,
                    dispersion=levels[lev]["disp"],
                    overlap_split_transit=levels[lev]["overlap_split"],
                    overlap_variable=levels[lev]["overlap"],
                    max_stop_process_count=levels[lev]["max_revisit"],
                    time_window=levels[lev]["dt"],
                    transfer_fare_ignore_pathfinding=levels[lev]
                    ["transfer_fare_ignore_pathfinding"],
                    transfer_fare_ignore_pathenum=levels[lev]
                    ["transfer_fare_ignore_pathenum"],
                )

    if args.norun:
        print "TOTAL RUNS: %d" % (run_count)