Transit Planner
1.0
An experiment on transfer patterns robustness
|
00001 // Copyright 2012: Eugen Sawin, Philip Stahl, Jonas Sternisko 00002 #ifndef SRC_SCENARIOGENERATOR_H_ 00003 #define SRC_SCENARIOGENERATOR_H_ 00004 00005 #include <set> 00006 #include <string> 00007 #include <vector> 00008 #include "gtest/gtest_prod.h" // Needed for FRIEND_TEST in this case. 00009 #include "./TransitNetwork.h" 00010 00011 class RandomGen; 00012 class ExpDistribution; 00013 class TransitNetwork; 00014 class Trip; 00015 class Line; 00016 class Logger; 00017 00018 struct ScenarioParams { 00019 ScenarioParams(); 00020 // Checks if the parameter set is valid. 00021 bool valid() const; 00022 // Returns a string representation of the parameterset. 00023 const std::string str() const; 00024 // Percentage of trips delayed. 00025 int delayPercentage; 00026 // Mean (mu) of the exponential distribution used to generate delay seconds. 00027 float delayMean; 00028 }; 00029 00030 00031 // A Generator for TransitNetwork of one day with random delay in trips. 00032 class ScenarioGenerator { 00033 public: 00034 explicit ScenarioGenerator(const vector<ScenarioParams>& params); 00035 explicit ScenarioGenerator(const ScenarioParams& params); 00036 // Generate and return a delayed version of the network. 00037 const TransitNetwork gen(const std::string& networkName); 00038 const TransitNetwork& generatedNetwork() const; 00039 // Returns the last generated dc-lines 00040 const std::vector<Line>& generatedLines() const; 00041 FRIEND_TEST(ScenarioGeneratorTest, gen); 00042 const vector<ScenarioParams>& params() const; 00043 // Selects N random indices in the range 0 ... SIZE-1 using a random number 00044 // generator with range [0...1] 00045 static std::set<size_t> 00046 selectNRandomIndices(int size, int N, RandomFloatGen* random); 00047 private: 00048 const std::vector<std::string> extractGtfsDirs(const std::string& args) const; 00049 FRIEND_TEST(ScenarioGeneratorTest, extractGtfsDirs); 00050 const std::vector<Trip> delayTrips(const std::vector<Trip>& cTrips, 00051 const Logger* log = NULL) const; 00052 const Trip delayTrip(const Trip& trip, const int index, 00053 const int delay) const; 00054 FRIEND_TEST(ScenarioGeneratorTest, delayTrips); 00055 // Tests if all scenario parameters are valid. 00056 bool validParams() const; 00057 FRIEND_TEST(ScenarioGeneratorTest, delayTrips_multipleScenarios); 00058 00059 std::vector<ScenarioParams> _params; 00060 TransitNetwork _lastGeneratedTN; 00061 std::vector<Line> _lastGeneratedLines; 00062 }; 00063 00064 #endif // SRC_SCENARIOGENERATOR_H_