diff --git a/src/pfaedle/router/ShapeBuilder.cpp b/src/pfaedle/router/ShapeBuilder.cpp index 1f69696..2b7ba8d 100644 --- a/src/pfaedle/router/ShapeBuilder.cpp +++ b/src/pfaedle/router/ShapeBuilder.cpp @@ -776,6 +776,7 @@ EdgeCandMap ShapeBuilder::getECM( double avgChildT = 0; if (chldTrNd.trips) avgChildT = chldTrNd.accTime / chldTrNd.trips; + double timeDiff = avgChildT - avgT; if (timeDiff < 0) timeDiff = 0; @@ -812,7 +813,7 @@ double ShapeBuilder::timePen(int candTime, int schedTime) const { int diff = abs(candTime - schedTime); - double cNorm = (diff) / standarddev; + double cNorm = diff / standarddev; return cNorm * cNorm; } diff --git a/src/pfaedle/router/TripTrie.tpp b/src/pfaedle/router/TripTrie.tpp index 4b2b87e..b0a6c28 100644 --- a/src/pfaedle/router/TripTrie.tpp +++ b/src/pfaedle/router/TripTrie.tpp @@ -5,6 +5,7 @@ #include #include #include + #include "TripTrie.h" #include "ad/cppgtfs/gtfs/Feed.h" #include "pfaedle/gtfs/Feed.h" @@ -16,7 +17,7 @@ using pfaedle::router::TripTrie; // _____________________________________________________________________________ template bool TripTrie::addTrip(TRIP* trip, const RoutingAttrs& rAttrs, - bool timeEx, bool degen) { + bool timeEx, bool degen) { if (!degen) return add(trip, rAttrs, timeEx); // check if trip is already fully and uniquely contained, if not, fail @@ -32,11 +33,14 @@ bool TripTrie::addTrip(TRIP* trip, const RoutingAttrs& rAttrs, // _____________________________________________________________________________ template -bool TripTrie::add(TRIP* trip, const RoutingAttrs& rAttrs, - bool timeEx) { +bool TripTrie::add(TRIP* trip, const RoutingAttrs& rAttrs, bool timeEx) { if (trip->getStopTimes().size() == 0) return false; - int startSecs = trip->getStopTimes().front().getDepartureTime().seconds(); + int startSecs = 0; + + if (!trip->getStopTimes().front().getDepartureTime().empty()) { + startSecs = trip->getStopTimes().front().getDepartureTime().seconds(); + } size_t curNdId = 0; for (size_t stId = 0; stId < trip->getStopTimes().size(); stId++) { @@ -48,7 +52,11 @@ bool TripTrie::add(TRIP* trip, const RoutingAttrs& rAttrs, st.getStop()->getLng()); if (stId > 0) { - int arrTime = st.getArrivalTime().seconds() - startSecs; + int arrTime = startSecs; + + if (!st.getArrivalTime().empty()) { + arrTime = st.getArrivalTime().seconds() - startSecs; + } size_t arrChild = getMatchChild(curNdId, name, platform, pos, arrTime, timeEx); @@ -66,7 +74,11 @@ bool TripTrie::add(TRIP* trip, const RoutingAttrs& rAttrs, } if (stId < trip->getStopTimes().size() - 1) { - int depTime = st.getDepartureTime().seconds() - startSecs; + int depTime = startSecs; + + if (!st.getDepartureTime().empty()) { + depTime = st.getDepartureTime().seconds() - startSecs; + } size_t depChild = getMatchChild(curNdId, name, platform, pos, depTime, timeEx); @@ -109,7 +121,11 @@ size_t TripTrie::get(TRIP* trip, bool timeEx) { st.getStop()->getLng()); if (stId > 0) { - int arrTime = st.getArrivalTime().seconds() - startSecs; + int arrTime = startSecs; + + if (!st.getArrivalTime().empty()) { + arrTime = st.getArrivalTime().seconds() - startSecs; + } size_t arrChild = getMatchChild(curNdId, name, platform, pos, arrTime, timeEx); @@ -122,7 +138,11 @@ size_t TripTrie::get(TRIP* trip, bool timeEx) { } if (stId < trip->getStopTimes().size() - 1) { - int depTime = st.getDepartureTime().seconds() - startSecs; + int depTime = startSecs; + + if (!st.getDepartureTime().empty()) { + depTime = st.getDepartureTime().seconds() - startSecs; + } size_t depChild = getMatchChild(curNdId, name, platform, pos, depTime, timeEx); @@ -141,8 +161,8 @@ size_t TripTrie::get(TRIP* trip, bool timeEx) { // _____________________________________________________________________________ template size_t TripTrie::insert(const ad::cppgtfs::gtfs::Stop* stop, - const RoutingAttrs& rAttrs, const POINT& pos, int time, - bool arr, size_t parent) { + const RoutingAttrs& rAttrs, const POINT& pos, + int time, bool arr, size_t parent) { _nds.emplace_back(TripTrieNd{stop, stop->getName(), stop->getPlatformCode(), @@ -168,9 +188,10 @@ const std::vector& TripTrie::getNds() const { // _____________________________________________________________________________ template -size_t TripTrie::getMatchChild(size_t parentNid, const std::string& stopName, - const std::string& platform, POINT pos, int time, - bool timeEx) const { +size_t TripTrie::getMatchChild(size_t parentNid, + const std::string& stopName, + const std::string& platform, POINT pos, + int time, bool timeEx) const { for (size_t child : _nds[parentNid].childs) { // TODO(patrick): use similarity classification here? if (_nds[child].stopName == stopName && _nds[child].platform == platform && @@ -186,7 +207,7 @@ size_t TripTrie::getMatchChild(size_t parentNid, const std::string& stopNa // _____________________________________________________________________________ template void TripTrie::toDot(std::ostream& os, const std::string& rootName, - size_t gid) const { + size_t gid) const { os << "digraph triptrie" << gid << " {"; for (size_t nid = 0; nid < _nds.size(); nid++) { @@ -215,8 +236,7 @@ void TripTrie::toDot(std::ostream& os, const std::string& rootName, // _____________________________________________________________________________ template -const std::map>& -TripTrie::getNdTrips() const { +const std::map>& TripTrie::getNdTrips() const { return _ndTrips; } diff --git a/src/util/Misc.h b/src/util/Misc.h index e74546b..0cda368 100644 --- a/src/util/Misc.h +++ b/src/util/Misc.h @@ -271,21 +271,21 @@ inline std::string getHomeDir() { } // _____________________________________________________________________________ -inline char* readableSize(double size, char* buf) { +inline char* readableSize(double size, size_t n, char* buf) { int i = 0; const char* units[] = {"B", "kB", "MB", "GB", "TB", "PB"}; while (size > 1024 && i < 5) { size /= 1024; i++; } - sprintf(buf, "%.*f %s", i, size, units[i]); + snprintf(buf, n, "%.*f %s", i, size, units[i]); return buf; } // _____________________________________________________________________________ inline std::string readableSize(double size) { char buffer[30]; - return readableSize(size, buffer); + return readableSize(size, 30, buffer); } // _____________________________________________________________________________