Skip to content

Commit

Permalink
Merge pull request #18 from MetropolitanTransportationCommission/develop
Browse files Browse the repository at this point in the history
Merge develop bug fixes to hyperpath_tree
  • Loading branch information
lmz committed Feb 20, 2016
2 parents c7dea40 + 708b435 commit c4839d6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
6 changes: 2 additions & 4 deletions fasttrips/TAZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = \
Expand Down
6 changes: 4 additions & 2 deletions fasttrips/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 25 additions & 13 deletions src/pathfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>* 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 };
Expand Down Expand Up @@ -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<int>& stop_done) const
{
double dir_factor = path_spec.outbound_ ? 1.0 : -1.0;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -771,7 +780,8 @@ namespace fasttrips {
int label_iteration,
const LabelStop& current_label_stop,
double latest_dep_earliest_arr,
std::tr1::unordered_set<int>& trips_done) const
std::tr1::unordered_set<int>& trips_done,
const std::tr1::unordered_set<int>& stop_done) const
{
double dir_factor = path_spec.outbound_ ? 1.0 : -1.0;

Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -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,
Expand All @@ -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!
Expand Down
9 changes: 6 additions & 3 deletions src/pathfinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>* stop_done) const;

/**
* Initialize the stop states from the access (for inbound) or egress (for outbound) links
Expand All @@ -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<int>& stop_done) const;

/**
* Iterate through all the stops that are accessible by transit vehicle trip
Expand All @@ -383,7 +385,8 @@ namespace fasttrips {
int label_iteration,
const LabelStop& current_label_stop,
double latest_dep_earliest_arr,
std::tr1::unordered_set<int>& trips_done) const;
std::tr1::unordered_set<int>& trips_done,
const std::tr1::unordered_set<int>& stop_done) const;

/**
* Label stops by:
Expand Down

0 comments on commit c4839d6

Please sign in to comment.