fasttrips.PathSet¶
- 
class 
fasttrips.PathSet(trip_list_dict)[source]¶ Bases:
objectRepresents a path set for a passenger from an origin
TAZto a destinationTAZthrough a set of stops.Methods
__init__(trip_list_dict)Constructor from dictionary mapping attribute to value. calculate_cost(STOCH_DISPERSION, …[, …])This is equivalent to the C++ Path::calculateCost() method. calculate_overlap(pathset_links_to_use)Given a set of pathset links, returns a the results of overlap calculations. goes_somewhere()Does this path go somewhere? Does the destination differ from the origin? num_paths()Number of paths in the PathSet path_found()Was a a transit path found from the origin to the destination with the constraints? reset()Delete my states, something went wrong and it won’t work out. set_user_class(trip_list_df, new_colname)Adds a column called user_class by applying the configured user class function. split_transit_links(pathset_links_df, …)Splits the transit links to their component links and returns. verify_weight_config(modes_df, output_dir, …)Verify that we have complete weight configurations for the user classes and modes in the given DataFrame. verify_weights(weights)write_path_times(passengers_df, output_dir)Write the assigned path times to the given output file. write_paths(passengers_df, output_dir)Write the assigned paths to the given output file. Attributes
ARRIVE_LATE_ALLOWED_MINAllow departures and arrivals before / after preferred time BUMP_EXPERIENCED_COSTBUMP_FLAG_COLUMNCONFIGURED_FUNCTIONSConfigured functions, indexed by name CONSTANT_GROWTH_MODELDEPART_EARLY_ALLOWED_MINDIR_INBOUNDTrips inbound to home have preferred departure times DIR_OUTBOUNDTrips outbound from home have preferred arrival times EXP_GROWTH_MODELHUGE_COSTLEARN_ROUTESLEARN_ROUTES_RATELOGARITHMIC_GROWTH_MODELLOGISTIC_GROWTH_MODELMIN_TRANSFER_PENALTYConfiguration: Minimum transfer penalty. OUTPUT_WEIGHTS_FILEFile with weights for c++ OVERLAP_CHUNK_SIZEOverlap chunk size. OVERLAP_COUNTOverlap variable option: count. OVERLAP_DISTANCEOverlap variable option: distance. OVERLAP_NONEOverlap variable option: None. OVERLAP_SCALE_PARAMETERConfiguration: Overlap scale parameter. OVERLAP_SPLIT_TRANSITOverlap option: Split transit leg into component parts? e.g. OVERLAP_TIMEOverlap variable option: time. OVERLAP_VARIABLEConfiguration: Overlap variable. OVERLAP_VARIABLE_OPTIONSValid values for OVERLAP_VARAIBLE PATHS_OUTPUT_FILEPaths output file PATH_KEY_COSTpath cost according to pathfinder PATH_KEY_FAREpath fare according to pathfinder PATH_KEY_INIT_COSTinitial cost (in pathfinding, before path was finalized) PATH_KEY_INIT_FAREinitial fare (in pathfinding, before path was finalized) PATH_KEY_PROBABILITYpath probability according to pathfinder PATH_KEY_STATESPATH_TIMES_OUTPUT_FILEPath times output file PENALTY_GROWTH_MODELSSTATE_IDX_ARRDEPdatetime.datetimeinstance.STATE_IDX_COSTcost float, for hyperpath/stochastic assignment STATE_IDX_DEPARRdatetime.datetimeinstance.STATE_IDX_DEPARRMODEmode id STATE_IDX_LABELdatetime.timedeltainstanceSTATE_IDX_LINKCOSTlink generalized cost, float for hyperpath/stochastic, STATE_IDX_LINKDISTlink distance, float STATE_IDX_LINKFAREfare cost, float STATE_IDX_LINKTIMEdatetime.timedeltainstanceSTATE_IDX_SEQsequence (for trip) STATE_IDX_SEQ_SUCCPREDsequence for successor/predecessor STATE_IDX_SUCCPREDstop identifier or TAZ identifier STATE_IDX_TRIPtrip id STATE_MODE_ACCESSSTATE_MODE_EGRESSSTATE_MODE_TRANSFERSTATE_MODE_TRIPSUCCESS_FLAG_COLUMNUSER_CLASS_FUNCTIONPath configuration: Name of the function that defines user class WEIGHTS_COLUMN_DEMAND_MODEWeights column: Demand Mode Type WEIGHTS_COLUMN_DEMAND_MODE_TYPEWeights column: Demand Mode Type WEIGHTS_COLUMN_PURPOSEWeights column: Purpose WEIGHTS_COLUMN_SUPPLY_MODEWeights column: Supply Mode WEIGHTS_COLUMN_SUPPLY_MODE_NUMWeights column: Supply Mode number WEIGHTS_COLUMN_USER_CLASSWeights column: User Class WEIGHTS_COLUMN_WEIGHT_NAMEWeights column: Weight Name WEIGHTS_COLUMN_WEIGHT_VALUEWeights column: Weight Value WEIGHTS_DFPath weights WEIGHTS_FILEFile with weights file. WEIGHTS_FIXED_WIDTHRead weights file as fixed-width format. WEIGHTS_GROWTH_LOGISTIC_MAXWeights column: Max value for logistic growth function WEIGHTS_GROWTH_LOGISTIC_MIDWeights column: Midpoint value for logistic growth function WEIGHTS_GROWTH_LOG_BASEWeights column: Log Base for logarithmic growth function WEIGHTS_GROWTH_TYPEWeights column: Growth Type WEIGHT_NAME_ARRIVE_EARLY_MINWEIGHT_NAME_ARRIVE_LATE_MINWEIGHT_NAME_DEPART_EARLY_MINWEIGHT_NAME_DEPART_LATE_MINWEIGHT_NAME_VALID_NAMES- 
static 
calculate_cost(STOCH_DISPERSION, pathset_paths_df, pathset_links_df, veh_trips_df, trip_list_df, routes, tazs, transfers, stops=None, reset_bump_iter=False)[source]¶ This is equivalent to the C++ Path::calculateCost() method. Would it be faster to do it in C++? It would require us to package up the networks and paths and send back and forth. :p
I think if we can do it using vectorized pandas operations, it should be fast, but we can compare/test.
It’s also messier to have this in two places. Maybe we should delete it from the C++; the overlap calcs are only in here right now.
Returns pathset_paths_df with additional columns, Assignment.SIM_COL_PAX_FARE, Assignment.SIM_COL_PAX_COST, Assignment.SIM_COL_PAX_PROBABILITY, Assignment.SIM_COL_PAX_LOGSUM And pathset_links_df with additional columns, Assignment.SIM_COL_PAX_FARE, Assignment.SIM_COL_PAX_FARE_PERIOD, Assignment.SIM_COL_PAX_COST and Assignment.SIM_COL_PAX_DISTANCE
- 
static 
calculate_overlap(pathset_links_to_use)[source]¶ Given a set of pathset links, returns a the results of overlap calculations.
This return dataframe will have colums person_id, person_trip_id, pathnum, and ln_PS
- 
path_found()[source]¶ Was a a transit path found from the origin to the destination with the constraints?
- 
static 
set_user_class(trip_list_df, new_colname)[source]¶ Adds a column called user_class by applying the configured user class function.
- 
static 
split_transit_links(pathset_links_df, veh_trips_df, stops)[source]¶ Splits the transit links to their component links and returns.
So if a transit trip goes from stop A to D but passes stop B and C in between, the row A->D will now be replaced by rows A->B, B->C, and C->D.
Adds “split_first” bool - True on the first veh link only
Note that this does not renumber the linknum field.
- 
static 
verify_weight_config(modes_df, output_dir, routes, capacity_constraint, trip_list_df)[source]¶ Verify that we have complete weight configurations for the user classes and modes in the given DataFrame.
Trips with invalid weight configurations will be dropped from the trip list and warned about.
The parameter mode_df is a dataframe with the user_class, demand_mode_type and demand_mode combinations found in the demand file.
If capacity_constraint is true, make sure there’s an at_capacity weight on the transit supply mode links to enforce it.
Returns updated trip_list_df.
- 
static 
write_path_times(passengers_df, output_dir)[source]¶ Write the assigned path times to the given output file.
Parameters: - passengers_df (
pandas.DataFrameinstance) – Passenger path links - output_dir (string) – Output directory
 
- passengers_df (
 
- 
static 
write_paths(passengers_df, output_dir)[source]¶ Write the assigned paths to the given output file.
Parameters: - passengers_df (
pandas.DataFrameinstance) – Passenger paths assignment results - output_dir (string) – Output directory
 
- passengers_df (
 
- 
ARRIVE_LATE_ALLOWED_MIN= datetime.timedelta(0)¶ Allow departures and arrivals before / after preferred time
- 
BUMP_EXPERIENCED_COST= 999999¶ 
- 
BUMP_FLAG_COLUMN= 'bump_flag'¶ 
- 
CONFIGURED_FUNCTIONS= {'generic_user_class': <function generic_user_class>}¶ Configured functions, indexed by name
- 
CONSTANT_GROWTH_MODEL= 'constant'¶ 
- 
DEPART_EARLY_ALLOWED_MIN= datetime.timedelta(0)¶ 
- 
DIR_INBOUND= 2¶ Trips inbound to home have preferred departure times
- 
DIR_OUTBOUND= 1¶ Trips outbound from home have preferred arrival times
- 
EXP_GROWTH_MODEL= 'exponential'¶ 
- 
HUGE_COST= 9999¶ 
- 
LEARN_ROUTES= False¶ 
- 
LEARN_ROUTES_RATE= 0.05¶ 
- 
LOGARITHMIC_GROWTH_MODEL= 'logarithmic'¶ 
- 
LOGISTIC_GROWTH_MODEL= 'logistic'¶ 
- 
MIN_TRANSFER_PENALTY= None¶ Configuration: Minimum transfer penalty. Safeguard against having no transfer penalty which can result in terrible paths with excessive transfers.
- 
OUTPUT_WEIGHTS_FILE= 'ft_intermediate_weights.txt'¶ File with weights for c++
- 
OVERLAP_CHUNK_SIZE= None¶ Overlap chunk size. How many person’s trips to process at a time in overlap calculations in python simulation
- 
OVERLAP_COUNT= 'count'¶ Overlap variable option: count. Use leg count overlap pathsize correction.
- 
OVERLAP_DISTANCE= 'distance'¶ Overlap variable option: distance. Use leg distance overlap pathsize correction.
- 
OVERLAP_NONE= 'None'¶ Overlap variable option: None. Don’t use overlap pathsize correction.
- 
OVERLAP_SCALE_PARAMETER= None¶ Configuration: Overlap scale parameter.
- 
OVERLAP_SPLIT_TRANSIT= None¶ Overlap option: Split transit leg into component parts? e.g. split A-E into A-B-C-D-E for overlap calculations?
- 
OVERLAP_TIME= 'time'¶ Overlap variable option: time. Use leg time overlap pathsize correction.
- 
OVERLAP_VARIABLE= None¶ Configuration: Overlap variable. Can be “None”, “count”, “distance”, “time”.
- 
OVERLAP_VARIABLE_OPTIONS= ['None', 'count', 'distance', 'time']¶ Valid values for OVERLAP_VARAIBLE
- 
PATHS_OUTPUT_FILE= 'ft_output_passengerPaths.txt'¶ Paths output file
- 
PATH_KEY_COST= 'pf_cost'¶ path cost according to pathfinder
- 
PATH_KEY_FARE= 'pf_fare'¶ path fare according to pathfinder
- 
PATH_KEY_INIT_COST= 'pf_initcost'¶ initial cost (in pathfinding, before path was finalized)
- 
PATH_KEY_INIT_FARE= 'pf_initfare'¶ initial fare (in pathfinding, before path was finalized)
- 
PATH_KEY_PROBABILITY= 'pf_probability'¶ path probability according to pathfinder
- 
PATH_KEY_STATES= 'states'¶ 
- 
PATH_TIMES_OUTPUT_FILE= 'ft_output_passengerTimes.txt'¶ Path times output file
- 
PENALTY_GROWTH_MODELS= ['constant', 'exponential', 'logarithmic', 'logistic']¶ 
- 
STATE_IDX_ARRDEP= 12¶ datetime.datetimeinstance. Arrival if outbound/backwards, departure if inbound/forwards.
- 
STATE_IDX_COST= 11¶ cost float, for hyperpath/stochastic assignment
- 
STATE_IDX_DEPARR= 1¶ datetime.datetimeinstance. Departure if outbound/backwards, arrival if inbound/forwards.
- 
STATE_IDX_DEPARRMODE= 2¶ mode id
- 
STATE_IDX_LABEL= 0¶ datetime.timedeltainstance
- 
STATE_IDX_LINKCOST= 9¶ link generalized cost, float for hyperpath/stochastic,
- 
STATE_IDX_LINKDIST= 10¶ link distance, float
- 
STATE_IDX_LINKFARE= 8¶ fare cost, float
- 
STATE_IDX_LINKTIME= 7¶ datetime.timedeltainstance
- 
STATE_IDX_SEQ= 5¶ sequence (for trip)
- 
STATE_IDX_SEQ_SUCCPRED= 6¶ sequence for successor/predecessor
- 
STATE_IDX_SUCCPRED= 4¶ stop identifier or TAZ identifier
- 
STATE_IDX_TRIP= 3¶ trip id
- 
STATE_MODE_ACCESS= 'access'¶ 
- 
STATE_MODE_EGRESS= 'egress'¶ 
- 
STATE_MODE_TRANSFER= 'transfer'¶ 
- 
STATE_MODE_TRIP= 'transit'¶ 
- 
SUCCESS_FLAG_COLUMN= 'success_flag'¶ 
- 
USER_CLASS_FUNCTION= None¶ Path configuration: Name of the function that defines user class
- 
WEIGHTS_COLUMN_DEMAND_MODE= 'demand_mode'¶ Weights column: Demand Mode Type
- 
WEIGHTS_COLUMN_DEMAND_MODE_TYPE= 'demand_mode_type'¶ Weights column: Demand Mode Type
- 
WEIGHTS_COLUMN_PURPOSE= 'purpose'¶ Weights column: Purpose
- 
WEIGHTS_COLUMN_SUPPLY_MODE= 'supply_mode'¶ Weights column: Supply Mode
- 
WEIGHTS_COLUMN_SUPPLY_MODE_NUM= 'supply_mode_num'¶ Weights column: Supply Mode number
- 
WEIGHTS_COLUMN_USER_CLASS= 'user_class'¶ Weights column: User Class
- 
WEIGHTS_COLUMN_WEIGHT_NAME= 'weight_name'¶ Weights column: Weight Name
- 
WEIGHTS_COLUMN_WEIGHT_VALUE= 'weight_value'¶ Weights column: Weight Value
- 
WEIGHTS_DF= None¶ Path weights
- 
WEIGHTS_FILE= 'pathweight_ft.txt'¶ File with weights file. Space delimited table.
- 
WEIGHTS_FIXED_WIDTH= False¶ Read weights file as fixed-width format. If false, standard CSV format is read.
- 
WEIGHTS_GROWTH_LOGISTIC_MAX= 'logistic_max'¶ Weights column: Max value for logistic growth function
- 
WEIGHTS_GROWTH_LOGISTIC_MID= 'logistic_mid'¶ Weights column: Midpoint value for logistic growth function
- 
WEIGHTS_GROWTH_LOG_BASE= 'log_base'¶ Weights column: Log Base for logarithmic growth function
- 
WEIGHTS_GROWTH_TYPE= 'growth_type'¶ Weights column: Growth Type
- 
WEIGHT_NAME_ARRIVE_EARLY_MIN= 'arrive_early_min'¶ 
- 
WEIGHT_NAME_ARRIVE_LATE_MIN= 'arrive_late_min'¶ 
- 
WEIGHT_NAME_DEPART_EARLY_MIN= 'depart_early_min'¶ 
- 
WEIGHT_NAME_DEPART_LATE_MIN= 'depart_late_min'¶ 
- 
WEIGHT_NAME_VALID_NAMES= ['depart_early_min', 'depart_late_min', 'arrive_early_min', 'arrive_late_min']¶ 
- 
pathdict= None¶ Dict of path-num -> { cost:, probability:, states: [List of (stop_id, stop_state)]}
- 
static