fasttrips.Passenger¶
-
class
fasttrips.
Passenger
(input_dir, output_dir, today, stops, routes, capacity_constraint)[source]¶ Bases:
object
Passenger class.
One instance represents all of the households and persons that could potentially make transit trips.
Stores household information in
Passenger.households_df
and person information inPassenger.persons_df
, which are bothpandas.DataFrame
instances.-
__init__
(input_dir, output_dir, today, stops, routes, capacity_constraint)[source]¶ Constructor from dictionary mapping attribute to value.
Methods
__init__
(input_dir, output_dir, today, …)Constructor from dictionary mapping attribute to value. add_pathset
(trip_list_id, pathset)Stores this path set for the trip_list_id. choose_paths
(choose_for_everyone, iteration, …)Returns the same dataframes as input, but with a new/updated column, Assignment.SIM_COL_PAX_CHOSEN
.get_chosen_links
(pathset_links_df[, …])Given the pathset paths and pathset links, returns the pathset links for the ones marked as chosen. get_pathset
(trip_list_id)Retrieves a stored path set for the given trip_list_id get_person_id
(trip_list_id)read_passenger_pathsets
(pathset_dir, stops, …)Reads the dataframes described in Passenger.setup_passenger_pathsets()
and returns them.setup_passenger_pathsets
(iteration, …)Converts pathfinding results (which is stored in each Passenger PathSet
) into twopandas.DataFrame
instances.write_paths
(output_dir, iteration, …)Write either pathset paths (if links=False) or pathset links (if links=True) as the case may be Attributes
HOUSEHOLDS_COLUMN_HOUSEHOLD_ID
Households column: Household ID INPUT_HOUSEHOLDS_FILE
File with households INPUT_PERSONS_FILE
File with persons INPUT_TRIP_LIST_FILE
File with trip list MIN_VALUE_OF_TIME
Minumum Value of Time: 1 dollar shouldn’t be worth 180 minutes MODE_GENERIC_TRANSIT
Generic transit. MODE_GENERIC_TRANSIT_NUM
Generic transit - Numeric mode number PATHSET_LINKS_CSV
PATHSET_PATHS_CSV
results - PathSets PERSONS_COLUMN_HOUSEHOLD_ID
Persons column: Household ID PERSONS_COLUMN_PERSON_ID
Persons column: Person ID (string) PERSONS_COLUMN_PERSON_ID_NUM
Persons column: Person ID number PF_COL_DESCRIPTION
path text description PF_COL_LINK_COST
cost (generalized) path-finder thinks passenger spent on link PF_COL_LINK_DIST
dist path-finder thinks passenger spent on link PF_COL_LINK_FARE
fare path-finder thinks passenger spent on link PF_COL_LINK_MODE
link mode (Access, Trip, Egress, etc) PF_COL_LINK_NUM
link number, starting from access PF_COL_LINK_TIME
time path-finder thinks passenger spent on link PF_COL_MODE
supply mode PF_COL_PATH_NUM
path number, starting from 0 PF_COL_PAX_A_TIME
time path-finder thinks passenger arrived at A PF_COL_PAX_A_TIME_MIN
todo replace/rename ?? PF_COL_PAX_B_TIME
time path-finder thinks passenger arrived at B PF_COL_PF_ITERATION
0.01*pathfinding_iteration + iteration during which this path was found PF_COL_ROUTE_ID
link route ID PF_COL_TRIP_ID
link trip ID PF_COL_WAIT_TIME
time path-finder thinks passenger waited for vehicle on trip links PF_LINKS_CSV
PF_PATHS_CSV
pathfinding results TIME_TARGET_ARRIVAL
Option for Passenger.TRIP_LIST_COLUMN_TIME_TARGET
(arrival time)TIME_TARGET_DEPARTURE
Option for Passenger.TRIP_LIST_COLUMN_TIME_TARGET
(departure time)TRIP_LIST_COLUMN_ACCESS_MODE
Trip list column: Access Mode TRIP_LIST_COLUMN_ARRIVAL_TIME
Trip list column: Arrival Time. TRIP_LIST_COLUMN_ARRIVAL_TIME_MIN
Trip list column: Departure Time. TRIP_LIST_COLUMN_DEPARTURE_TIME
Trip list column: Departure Time. TRIP_LIST_COLUMN_DEPARTURE_TIME_MIN
Trip list column: Departure Time. TRIP_LIST_COLUMN_DESTINATION_TAZ_ID
Trip list column: Destination TAZ ID TRIP_LIST_COLUMN_DESTINATION_TAZ_ID_NUM
Trip list column: Destination Numeric TAZ ID TRIP_LIST_COLUMN_EGRESS_MODE
Trip list column: Egress Mode TRIP_LIST_COLUMN_MODE
Trip list column: Mode TRIP_LIST_COLUMN_ORIGIN_TAZ_ID
Trip list column: Origin TAZ ID TRIP_LIST_COLUMN_ORIGIN_TAZ_ID_NUM
Trip list column: Origin TAZ Numeric ID TRIP_LIST_COLUMN_OUTBOUND
Trip list column: Outbound (bool), true iff time target is arrival TRIP_LIST_COLUMN_PERSON_ID
Trip list column: Person ID TRIP_LIST_COLUMN_PERSON_TRIP_ID
Trip list column: Person Trip ID TRIP_LIST_COLUMN_PURPOSE
Trip list column: Purpose. TRIP_LIST_COLUMN_TIME_TARGET
Trip list column: Time Target (either ‘arrival’ or ‘departure’) TRIP_LIST_COLUMN_TRACE
Trip list column: Trace. TRIP_LIST_COLUMN_TRANSIT_MODE
Trip list column: Transit Mode TRIP_LIST_COLUMN_TRIP_LIST_ID_NUM
Trip list column: Unique numeric ID for this passenger/trip TRIP_LIST_COLUMN_USER_CLASS
Trip list column: User class. TRIP_LIST_COLUMN_VOT
Trip list column: Value of time. -
static
choose_paths
(choose_for_everyone, iteration, pathfinding_iteration, simulation_iteration, pathset_paths_df, pathset_links_df)[source]¶ Returns the same dataframes as input, but with a new/updated column,
Assignment.SIM_COL_PAX_CHOSEN
. This column is set to:Assignment.CHOSEN_NOT_CHOSEN_YET
for not chosen yet- ‘iter%d.%02d sim%d’ % (iteration, pathfinding_iteration, simulation_iteration for chosen)
Assignment.CHOSEN_REJECTED
for chosen but then rejected
If choose_for_everyone is True, this will attempt to choose for every passenger trip. Otherwise, this will attempt to choose for just those passenger trips that still need it.
Returns (TOTAL num passenger trips chosen, NEW num passenger trips chosen, updated pathset_paths_df, updated pathset_links_df)
-
static
get_chosen_links
(pathset_links_df, transit_only=False, copy=True)[source]¶ Given the pathset paths and pathset links, returns the pathset links for the ones marked as chosen.
-
read_passenger_pathsets
(pathset_dir, stops, modes_df, include_asgn=True)[source]¶ Reads the dataframes described in
Passenger.setup_passenger_pathsets()
and returns them.Parameters: - pathset_dir (string) – Location of csv files to read
- include_asgn – If true, read from files called
Passenger.PF_PATHS_CSV
andPassenger.PF_LINKS_CSV
. Otherwise read from files calledPassenger.PATHSET_PATHS_CSV
andPassenger.PATHSET_LINKS_CSV
which include assignment results.
Returns: See
Assignment.setup_passengers()
for documentation on the passenger pathspandas.DataFrame
Return type: a tuple of (
pandas.DataFrame
,pandas.DataFrame
)
-
setup_passenger_pathsets
(iteration, pathfinding_iteration, stops, trip_id_df, trips_df, modes_df, transfers, tazs, prepend_route_id_to_trip_id)[source]¶ Converts pathfinding results (which is stored in each Passenger
PathSet
) into twopandas.DataFrame
instances.Returns two
pandas.DataFrame
instances: pathset_paths_df and pathset_links_df. These only include pathsets for person trips which have just been sought (e.g. those inPassenger.pathfind_trip_list_df
)pathset_paths_df has path set information, where each row represents a passenger’s path:
column name column type description person_id object person ID person_trip_id object person trip ID trip_list_id_num int64 trip list numerical ID trace bool Are we tracing this person trip? pathdir int64 the PathSet.direction
pathmode object the PathSet.mode
pf_iteration float64 iteration + 0.01*pathfinding_iteration in which these paths were found pathnum int64 the path number for the path within the pathset pf_cost float64 the cost of the entire path pf_fare float64 the fare of the entire path pf_probability float64 the probability of the path pf_initcost float64 the initial cost of the entire path pf_initfare float64 the initial fare of the entire path description object string representation of the path pathset_links_df has path link information, where each row represents a link in a passenger’s path:
column name column type description person_id object person ID person_trip_id object person trip ID trip_list_id_num int64 trip list numerical ID trace bool Are we tracing this person trip? pf_iteration float64 iteration + 0.01*pathfinding_iteration in which these paths were found pathnum int64 the path number for the path within the pathset linkmode object the mode of the link, one of PathSet.STATE_MODE_ACCESS
,PathSet.STATE_MODE_EGRESS
,PathSet.STATE_MODE_TRANSFER
orPathSet.STATE_MODE_TRIP
. PathSets will always start with access, followed by trips with transfers in between, and ending in an egress following the last trip.mode_num int64 the mode number for the link mode object the supply mode for the link route_id object the route ID for trip links. Set to numpy.nan
for non-trip links.trip_id object the trip ID for trip links. Set to numpy.nan
for non-trip links.trip_id_num float64 the numerical trip ID for trip links. Set to numpy.nan
for non-trip links.A_id object the stop ID at the start of the link, or TAZ ID for access links A_id_num int64 the numerical stop ID at the start of the link, or a numerical TAZ ID for access links B_id object the stop ID at the end of the link, or a TAZ ID for access links B_id_num int64 the numerical stop ID at the end of the link, or a numerical TAZ ID for access links A_seq int64 the sequence number for the stop at the start of the link, or -1 for access links B_seq int64 the sequence number for the stop at the start of the link, or -1 for access links pf_A_time datetime64[ns] the time the passenger arrives at A_id pf_B_time datetime64[ns] the time the passenger arrives at B_id pf_linktime timedelta64[ns] the time spent on the link pf_linkfare float64 the fare of the link pf_linkcost float64 the generalized cost of the link pf_linkdist float64 the distance for the link A_lat float64 the latitude of A (if it’s a stop) A_lon float64 the longitude of A (if it’s a stop) B_lat float64 the latitude of B (if it’s a stop) B_lon float64 the longitude of B (if it’s a stop)
-
static
write_paths
(output_dir, iteration, pathfinding_iteration, simulation_iteration, pathset_df, links, output_pathset_per_sim_iter, drop_debug_columns, drop_pathfinding_columns)[source]¶ Write either pathset paths (if links=False) or pathset links (if links=True) as the case may be
-
HOUSEHOLDS_COLUMN_HOUSEHOLD_ID
= 'hh_id'¶ Households column: Household ID
-
INPUT_HOUSEHOLDS_FILE
= 'household.txt'¶ File with households
-
INPUT_PERSONS_FILE
= 'person.txt'¶ File with persons
-
INPUT_TRIP_LIST_FILE
= 'trip_list.txt'¶ File with trip list
-
MIN_VALUE_OF_TIME
= 0.3333333333333333¶ Minumum Value of Time: 1 dollar shouldn’t be worth 180 minutes
-
MODE_GENERIC_TRANSIT
= 'transit'¶ Generic transit. Specify this for mode when you mean walk, any transit modes, walk TODO: get rid of this? Maybe user should always specify.
-
MODE_GENERIC_TRANSIT_NUM
= 1000¶ Generic transit - Numeric mode number
-
PATHSET_LINKS_CSV
= 'pathset_links.csv'¶
-
PATHSET_PATHS_CSV
= 'pathset_paths.csv'¶ results - PathSets
-
PERSONS_COLUMN_HOUSEHOLD_ID
= 'hh_id'¶ Persons column: Household ID
-
PERSONS_COLUMN_PERSON_ID
= 'person_id'¶ Persons column: Person ID (string)
-
PERSONS_COLUMN_PERSON_ID_NUM
= 'person_id_num'¶ Persons column: Person ID number
-
PF_COL_DESCRIPTION
= 'description'¶ path text description
-
PF_COL_LINK_COST
= 'pf_linkcost'¶ cost (generalized) path-finder thinks passenger spent on link
-
PF_COL_LINK_DIST
= 'pf_linkdist'¶ dist path-finder thinks passenger spent on link
-
PF_COL_LINK_FARE
= 'pf_linkfare'¶ fare path-finder thinks passenger spent on link
-
PF_COL_LINK_MODE
= 'linkmode'¶ link mode (Access, Trip, Egress, etc)
-
PF_COL_LINK_NUM
= 'linknum'¶ link number, starting from access
-
PF_COL_LINK_TIME
= 'pf_linktime'¶ time path-finder thinks passenger spent on link
-
PF_COL_MODE
= 'mode'¶ supply mode
-
PF_COL_PATH_NUM
= 'pathnum'¶ path number, starting from 0
-
PF_COL_PAX_A_TIME
= 'pf_A_time'¶ time path-finder thinks passenger arrived at A
-
PF_COL_PAX_A_TIME_MIN
= 'pf_A_time_min'¶ todo replace/rename ??
-
PF_COL_PAX_B_TIME
= 'pf_B_time'¶ time path-finder thinks passenger arrived at B
-
PF_COL_PF_ITERATION
= 'pf_iteration'¶ 0.01*pathfinding_iteration + iteration during which this path was found
-
PF_COL_ROUTE_ID
= 'route_id'¶ link route ID
-
PF_COL_TRIP_ID
= 'trip_id'¶ link trip ID
-
PF_COL_WAIT_TIME
= 'pf_waittime'¶ time path-finder thinks passenger waited for vehicle on trip links
-
PF_LINKS_CSV
= 'enumerated_links.csv'¶
-
PF_PATHS_CSV
= 'enumerated_paths.csv'¶ pathfinding results
-
TIME_TARGET_ARRIVAL
= 'arrival'¶ Option for
Passenger.TRIP_LIST_COLUMN_TIME_TARGET
(arrival time)
-
TIME_TARGET_DEPARTURE
= 'departure'¶ Option for
Passenger.TRIP_LIST_COLUMN_TIME_TARGET
(departure time)
-
TRIP_LIST_COLUMN_ACCESS_MODE
= 'access_mode'¶ Trip list column: Access Mode
-
TRIP_LIST_COLUMN_ARRIVAL_TIME
= 'arrival_time'¶ Trip list column: Arrival Time. DateTime.
-
TRIP_LIST_COLUMN_ARRIVAL_TIME_MIN
= 'arrival_time_min'¶ Trip list column: Departure Time. Float, minutes after midnight.
-
TRIP_LIST_COLUMN_DEPARTURE_TIME
= 'departure_time'¶ Trip list column: Departure Time. DateTime.
-
TRIP_LIST_COLUMN_DEPARTURE_TIME_MIN
= 'departure_time_min'¶ Trip list column: Departure Time. Float, minutes after midnight.
-
TRIP_LIST_COLUMN_DESTINATION_TAZ_ID
= 'd_taz'¶ Trip list column: Destination TAZ ID
-
TRIP_LIST_COLUMN_DESTINATION_TAZ_ID_NUM
= 'd_taz_num'¶ Trip list column: Destination Numeric TAZ ID
-
TRIP_LIST_COLUMN_EGRESS_MODE
= 'egress_mode'¶ Trip list column: Egress Mode
-
TRIP_LIST_COLUMN_MODE
= 'mode'¶ Trip list column: Mode
-
TRIP_LIST_COLUMN_ORIGIN_TAZ_ID
= 'o_taz'¶ Trip list column: Origin TAZ ID
-
TRIP_LIST_COLUMN_ORIGIN_TAZ_ID_NUM
= 'o_taz_num'¶ Trip list column: Origin TAZ Numeric ID
-
TRIP_LIST_COLUMN_OUTBOUND
= 'outbound'¶ Trip list column: Outbound (bool), true iff time target is arrival
-
TRIP_LIST_COLUMN_PERSON_ID
= 'person_id'¶ Trip list column: Person ID
-
TRIP_LIST_COLUMN_PERSON_TRIP_ID
= 'person_trip_id'¶ Trip list column: Person Trip ID
-
TRIP_LIST_COLUMN_PURPOSE
= 'purpose'¶ Trip list column: Purpose. String.
-
TRIP_LIST_COLUMN_TIME_TARGET
= 'time_target'¶ Trip list column: Time Target (either ‘arrival’ or ‘departure’)
-
TRIP_LIST_COLUMN_TRACE
= 'trace'¶ Trip list column: Trace. Boolean.
-
TRIP_LIST_COLUMN_TRANSIT_MODE
= 'transit_mode'¶ Trip list column: Transit Mode
-
TRIP_LIST_COLUMN_TRIP_LIST_ID_NUM
= 'trip_list_id_num'¶ Trip list column: Unique numeric ID for this passenger/trip
-
TRIP_LIST_COLUMN_USER_CLASS
= 'user_class'¶ Trip list column: User class. String.
-
TRIP_LIST_COLUMN_VOT
= 'vot'¶ Trip list column: Value of time. Float.
-