diff --git a/fasttrips/TAZ.py b/fasttrips/TAZ.py index 9d34fcdb..43904ce9 100644 --- a/fasttrips/TAZ.py +++ b/fasttrips/TAZ.py @@ -296,11 +296,9 @@ def __init__(self, input_dir, output_dir, today, stops, transfers, routes, is_ch # lot open/close time: datetime version self.drive_access_df[TAZ.DRIVE_ACCESS_COLUMN_START_TIME] = \ - self.drive_access_df[TAZ.DRIVE_ACCESS_COLUMN_START_TIME].map(lambda x: \ - datetime.datetime.combine(today, datetime.datetime.strptime(x, '%H:%M:%S').time())) + self.drive_access_df[TAZ.DRIVE_ACCESS_COLUMN_START_TIME].map(lambda x: Util.read_time(x)) self.drive_access_df[TAZ.DRIVE_ACCESS_COLUMN_END_TIME] = \ - self.drive_access_df[TAZ.DRIVE_ACCESS_COLUMN_END_TIME].map(lambda x: \ - datetime.datetime.combine(today, datetime.datetime.strptime(x, '%H:%M:%S').time())) + self.drive_access_df[TAZ.DRIVE_ACCESS_COLUMN_END_TIME].map(lambda x: Util.read_time(x)) # lot open/close time: float version self.drive_access_df[TAZ.DRIVE_ACCESS_COLUMN_START_TIME_MIN] = \ diff --git a/fasttrips/Util.py b/fasttrips/Util.py index c2eb9484..d6033cad 100644 --- a/fasttrips/Util.py +++ b/fasttrips/Util.py @@ -69,9 +69,11 @@ def add_new_id(input_df, id_colname, newid_colname, # print return_df.head() # make sure all ids were mapped to numbers - if pandas.isnull(return_df[mapping_newid_colname]).sum() != pandas.isnull(input_df[id_colname]).sum(): + # first check if mapping_newid_colname was already in input_df; if it was, check needs to be performed on "_mapping" + mapping_newid_colname_chk = mapping_id_colname + "_mapping" if mapping_newid_colname in input_cols else mapping_newid_colname + if pandas.isnull(return_df[mapping_newid_colname_chk]).sum() != pandas.isnull(input_df[id_colname]).sum(): FastTripsLogger.fatal("Util.add_new_id failed to map all ids to numbers") - FastTripsLogger.fatal("pandas.isnull(return_df[%s]).sum() = %d" % (mapping_newid_colname, pandas.isnull(return_df[mapping_newid_colname]).sum())) + FastTripsLogger.fatal("pandas.isnull(return_df[%s]).sum() = %d" % (mapping_newid_colname_chk, pandas.isnull(return_df[mapping_newid_colname_chk]).sum())) FastTripsLogger.fatal("pandas.isnull(input_df[%s]).sum() = %d" % (id_colname, pandas.isnull(input_df[id_colname]).sum())) raise diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp index b5e2924b..c898cfc1 100644 --- a/src/pathfinder.cpp +++ b/src/pathfinder.cpp @@ -461,9 +461,17 @@ namespace fasttrips { const int stop_id, const StopState& ss, StopStates& stop_states, - LabelStopQueue& label_stop_queue) const + LabelStopQueue& label_stop_queue, + const std::tr1::unordered_set* stop_done=NULL) const { + // if the stop state is already considered done, that's a problem + if (stop_done && stop_done->find(stop_id) != stop_done->end()) { + if (path_spec.trace_) { + trace_file << "Problem: Adding stop state with done stop " << stop_num_to_str_.find(stop_id)->second << std::endl; + } + } + // add it to stop_states stop_states[stop_id].push_back(ss); LabelStop ls = { ss.label_, stop_id }; @@ -633,7 +641,8 @@ namespace fasttrips { LabelStopQueue& label_stop_queue, int label_iteration, const LabelStop& current_label_stop, - double latest_dep_earliest_arr) const + double latest_dep_earliest_arr, + const std::tr1::unordered_set& stop_done) const { double dir_factor = path_spec.outbound_ ? 1.0 : -1.0; @@ -705,12 +714,12 @@ namespace fasttrips { if ((new_label < PathFinder::MAX_COST) && (new_label > 0.0)) { use_new_state = true; } } - // deterministic: cost is just additive + // deterministic: label = cost = total time, just additive else { link_cost = transfer_time; - cost = transfer_time; - new_label = current_label_stop.label_ + cost; + cost = current_label_stop.label_ + link_cost; + new_label = cost; // check (departure mode, stop) if someone's waiting already // curious... this only applies to OUTBOUND @@ -758,7 +767,7 @@ namespace fasttrips { label_iteration, // label iteration latest_dep_earliest_arr // arrival/departure time }; - addStopState(path_spec, trace_file, xfer_stop_id, ss, stop_states, label_stop_queue); + addStopState(path_spec, trace_file, xfer_stop_id, ss, stop_states, label_stop_queue, &stop_done); } } } @@ -771,7 +780,8 @@ namespace fasttrips { int label_iteration, const LabelStop& current_label_stop, double latest_dep_earliest_arr, - std::tr1::unordered_set& trips_done) const + std::tr1::unordered_set& trips_done, + const std::tr1::unordered_set& stop_done) const { double dir_factor = path_spec.outbound_ ? 1.0 : -1.0; @@ -928,11 +938,11 @@ namespace fasttrips { } if ((new_label < PathFinder::MAX_COST) && (new_label > 0)) { use_new_state = true; } } - // deterministic: cost is just additive + // deterministic: label = cost = total time, just additive else { link_cost = in_vehicle_time + wait_time; - cost = cost; - new_label = current_label_stop.label_ + cost; + cost = current_label_stop.label_ + link_cost; + new_label = cost; double old_label = PathFinder::MAX_TIME; if (possible_stop_state_iter != stop_states.end()) { old_label = possible_stop_state_iter->second.front().label_; @@ -981,7 +991,7 @@ namespace fasttrips { label_iteration, // label iteration arrdep_time // arrival/departure time }; - addStopState(path_spec, trace_file, board_alight_stop, ss, stop_states, label_stop_queue); + addStopState(path_spec, trace_file, board_alight_stop, ss, stop_states, label_stop_queue, &stop_done); } } trips_done.insert(it->trip_id_); @@ -1080,7 +1090,8 @@ namespace fasttrips { label_stop_queue, label_iterations, current_label_stop, - latest_dep_earliest_arr); + latest_dep_earliest_arr, + stop_done); updateStopStatesForTrips(path_spec, trace_file, @@ -1089,7 +1100,8 @@ namespace fasttrips { label_iterations, current_label_stop, latest_dep_earliest_arr, - trips_done); + trips_done, + stop_done); // Done with this label iteration! diff --git a/src/pathfinder.h b/src/pathfinder.h index dd362602..84683b7b 100644 --- a/src/pathfinder.h +++ b/src/pathfinder.h @@ -344,7 +344,8 @@ namespace fasttrips { const int stop_id, const StopState& ss, StopStates& stop_states, - LabelStopQueue& label_stop_queue) const; + LabelStopQueue& label_stop_queue, + const std::tr1::unordered_set* stop_done) const; /** * Initialize the stop states from the access (for inbound) or egress (for outbound) links @@ -368,7 +369,8 @@ namespace fasttrips { LabelStopQueue& label_stop_queue, int label_iteration, const LabelStop& current_label_stop, - double latest_dep_earliest_arr) const; + double latest_dep_earliest_arr, + const std::tr1::unordered_set& stop_done) const; /** * Iterate through all the stops that are accessible by transit vehicle trip @@ -383,7 +385,8 @@ namespace fasttrips { int label_iteration, const LabelStop& current_label_stop, double latest_dep_earliest_arr, - std::tr1::unordered_set& trips_done) const; + std::tr1::unordered_set& trips_done, + const std::tr1::unordered_set& stop_done) const; /** * Label stops by: