00001
00002
00003
00004
00005
00006
00007 #ifndef ROUTEPLANNINGV2_TRANSITNETWORKDEPENDENT_H_
00008 #define ROUTEPLANNINGV2_TRANSITNETWORKDEPENDENT_H_
00009
00010 #include <gtest/gtest.h>
00011 #include <unordered_map>
00012 #include <unordered_set>
00013 #include <string>
00014 #include <utility>
00015 #include <vector>
00016 #include "./RoadNetwork.h"
00017 #include "./NodeDependent.h"
00018 #include "./EdgeDependent.h"
00019 #include "./Time.h"
00020 #include "./TransitParser.h"
00021 #include "./LiveConnection.h"
00022 using std::string;
00023 using std::unordered_map;
00024 using std::unordered_set;
00025 using std::pair;
00026 using std::vector;
00027
00028 class TransitNetworkDependent : public Graph
00029 {
00030
00031
00032 struct TripFrequency
00033 {
00034 char startHour;
00035 char startMinute;
00036 char startSecond;
00037 char endHour;
00038 char endMinute;
00039 char endSecond;
00040 int intervalInSeconds;
00041 TripFrequency();
00042 TripFrequency(char startHour, char startMinute, char startSecond,
00043 char endHour, char endMinute, char endSecond,
00044 int intervalInSeconds);
00045 };
00046
00047 public:
00048 TransitNetworkDependent();
00049 TransitNetworkDependent(const TransitNetworkDependent& orig);
00050 virtual ~TransitNetworkDependent();
00051 FRIEND_TEST(TransitNetworkTest, parseFromGTFSFiles);
00052 FRIEND_TEST(TransitNetworkTest, computeShortestPathTransit);
00053
00054 void parseFromGTFSFiles(string folderName);
00055
00056
00057 void addEdgeWithTimeDifference(int startId, int endId);
00058
00059 string getStopName(size_t id);
00060
00061 size_t getNumNodes() const;
00062
00063 size_t getNumStops() const;
00064
00065 NodeDependent* getNode(int id) const;
00066
00067 vector<EdgeDependent>* getOutEdges(int nodeId) const;
00068
00069 void getStopsStartingWith(const string& prefix,
00070 vector<string>* stopNames) const;
00071
00072 int getNodeIdByTheStopName(string stopName);
00073
00074 void getConnections(int nodeId, Time time, int tripId,
00075 bool isMultiCriteria, bool isStartNode,
00076 vector<LiveConnection>* outConnections);
00077
00078 private:
00079 FRIEND_TEST(TransitNetworkTest, parseCalendarFile);
00080 void parseCalendarFile(const string& calendarFileName,
00081 char validWeekDay,
00082 unordered_set<string>* validServiceIds);
00083
00084 FRIEND_TEST(TransitNetworkTest, parseTripsFile);
00085 void parseTripsFile(string tripFileName,
00086 const unordered_set<string>& validServiceIds,
00087 unordered_map<string, int>* tripIdNameToTripId);
00088
00089 FRIEND_TEST(TransitNetworkDependentTest, parseStopsFile);
00090 void parseStopsFile(string stopFileName);
00091
00092
00093 void parseFrequenciesFile(string frequencyFileName,
00094 unordered_map<string, vector<TransitParser::TripFrequency> >*
00095 tripIdNameToFrequencies);
00096
00097 void parseStopTimesFile(string stopTimesFile,
00098 const unordered_map<string, vector<TransitParser::TripFrequency> >&
00099 tripIdNameToFrequencies,
00100 const unordered_map<string, int >& tripStrToIntId);
00101
00102 FRIEND_TEST(TransitNetworkTest, addTrip);
00103
00104
00105 void addTrip(int startNodeId, int endNodeId,
00106 const TransitParser::TripFrequency& frequency,
00107 Time startTime, Time endTime,
00108 int tripId);
00109
00110 void addEdge(int startId, int endId);
00111
00112 void addStopTimeToCorrespondEdge(int startStopId, int endStopId,
00113 Time startTime,
00114 Time endTime,
00115 int lineId);
00116 vector<NodeDependent>* _nodes;
00117 vector<vector<EdgeDependent> >* _outgoingEdges;
00118 vector<vector<EdgeDependent> >* _incomingEdges;
00119 vector<vector<bool> > availableWeekdays;
00120 unordered_map<string, int>* _stopIdNameToId;
00121 vector <string> _stopIdToName;
00122 };
00123 #endif // ROUTEPLANNINGV2_TRANSITNETWORKDEPENDENT_H_