fasttrips.PathSet¶
-
class
fasttrips.
PathSet
(trip_list_dict)[source]¶ Bases:
object
Represents a path set for a passenger from an origin
TAZ
to a destinationTAZ
through 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_MIN
Allow departures and arrivals before / after preferred time BUMP_EXPERIENCED_COST
BUMP_FLAG_COLUMN
CONFIGURED_FUNCTIONS
Configured functions, indexed by name CONSTANT_GROWTH_MODEL
DEPART_EARLY_ALLOWED_MIN
DIR_INBOUND
Trips inbound to home have preferred departure times DIR_OUTBOUND
Trips outbound from home have preferred arrival times EXP_GROWTH_MODEL
HUGE_COST
LEARN_ROUTES
LEARN_ROUTES_RATE
LOGARITHMIC_GROWTH_MODEL
LOGISTIC_GROWTH_MODEL
MIN_TRANSFER_PENALTY
Configuration: Minimum transfer penalty. OUTPUT_WEIGHTS_FILE
File with weights for c++ OVERLAP_CHUNK_SIZE
Overlap chunk size. OVERLAP_COUNT
Overlap variable option: count. OVERLAP_DISTANCE
Overlap variable option: distance. OVERLAP_NONE
Overlap variable option: None. OVERLAP_SCALE_PARAMETER
Configuration: Overlap scale parameter. OVERLAP_SPLIT_TRANSIT
Overlap option: Split transit leg into component parts? e.g. OVERLAP_TIME
Overlap variable option: time. OVERLAP_VARIABLE
Configuration: Overlap variable. OVERLAP_VARIABLE_OPTIONS
Valid values for OVERLAP_VARAIBLE PATHS_OUTPUT_FILE
Paths output file PATH_KEY_COST
path cost according to pathfinder PATH_KEY_FARE
path fare according to pathfinder PATH_KEY_INIT_COST
initial cost (in pathfinding, before path was finalized) PATH_KEY_INIT_FARE
initial fare (in pathfinding, before path was finalized) PATH_KEY_PROBABILITY
path probability according to pathfinder PATH_KEY_STATES
PATH_TIMES_OUTPUT_FILE
Path times output file PENALTY_GROWTH_MODELS
STATE_IDX_ARRDEP
datetime.datetime
instance.STATE_IDX_COST
cost float, for hyperpath/stochastic assignment STATE_IDX_DEPARR
datetime.datetime
instance.STATE_IDX_DEPARRMODE
mode id STATE_IDX_LABEL
datetime.timedelta
instanceSTATE_IDX_LINKCOST
link generalized cost, float for hyperpath/stochastic, STATE_IDX_LINKDIST
link distance, float STATE_IDX_LINKFARE
fare cost, float STATE_IDX_LINKTIME
datetime.timedelta
instanceSTATE_IDX_SEQ
sequence (for trip) STATE_IDX_SEQ_SUCCPRED
sequence for successor/predecessor STATE_IDX_SUCCPRED
stop identifier or TAZ identifier STATE_IDX_TRIP
trip id STATE_MODE_ACCESS
STATE_MODE_EGRESS
STATE_MODE_TRANSFER
STATE_MODE_TRIP
SUCCESS_FLAG_COLUMN
USER_CLASS_FUNCTION
Path configuration: Name of the function that defines user class WEIGHTS_COLUMN_DEMAND_MODE
Weights column: Demand Mode Type WEIGHTS_COLUMN_DEMAND_MODE_TYPE
Weights column: Demand Mode Type WEIGHTS_COLUMN_PURPOSE
Weights column: Purpose WEIGHTS_COLUMN_SUPPLY_MODE
Weights column: Supply Mode WEIGHTS_COLUMN_SUPPLY_MODE_NUM
Weights column: Supply Mode number WEIGHTS_COLUMN_USER_CLASS
Weights column: User Class WEIGHTS_COLUMN_WEIGHT_NAME
Weights column: Weight Name WEIGHTS_COLUMN_WEIGHT_VALUE
Weights column: Weight Value WEIGHTS_DF
Path weights WEIGHTS_FILE
File with weights file. WEIGHTS_FIXED_WIDTH
Read weights file as fixed-width format. WEIGHTS_GROWTH_LOGISTIC_MAX
Weights column: Max value for logistic growth function WEIGHTS_GROWTH_LOGISTIC_MID
Weights column: Midpoint value for logistic growth function WEIGHTS_GROWTH_LOG_BASE
Weights column: Log Base for logarithmic growth function WEIGHTS_GROWTH_TYPE
Weights column: Growth Type WEIGHT_NAME_ARRIVE_EARLY_MIN
WEIGHT_NAME_ARRIVE_LATE_MIN
WEIGHT_NAME_DEPART_EARLY_MIN
WEIGHT_NAME_DEPART_LATE_MIN
WEIGHT_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.DataFrame
instance) – 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.DataFrame
instance) – 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.datetime
instance. Arrival if outbound/backwards, departure if inbound/forwards.
-
STATE_IDX_COST
= 11¶ cost float, for hyperpath/stochastic assignment
-
STATE_IDX_DEPARR
= 1¶ datetime.datetime
instance. Departure if outbound/backwards, arrival if inbound/forwards.
-
STATE_IDX_DEPARRMODE
= 2¶ mode id
-
STATE_IDX_LABEL
= 0¶ datetime.timedelta
instance
-
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.timedelta
instance
-
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