TvlSim Logo  1.00.0
C++ Simulated Travel-Oriented Distribution System Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimulationTestSuite.cpp
Go to the documentation of this file.
1 
5 // //////////////////////////////////////////////////////////////////////
6 // Import section
7 // //////////////////////////////////////////////////////////////////////
8 // STL
9 #include <sstream>
10 #include <fstream>
11 #include <string>
12 // Boost Unit Test Framework (UTF)
13 #define BOOST_TEST_DYN_LINK
14 #define BOOST_TEST_MAIN
15 #define BOOST_TEST_MODULE SimulationTestSuite
16 #include <boost/test/unit_test.hpp>
17 // StdAir
18 #include <stdair/stdair_exceptions.hpp>
19 #include <stdair/basic/BasConst_General.hpp>
20 #include <stdair/basic/BasLogParams.hpp>
21 #include <stdair/basic/BasFileMgr.hpp>
22 #include <stdair/basic/DemandGenerationMethod.hpp>
23 #include <stdair/service/Logger.hpp>
24 // SimFQT
25 #include <simfqt/SIMFQT_Types.hpp>
26 // Dsim
27 #include <tvlsim/TVLSIM_Types.hpp>
29 #include <tvlsim/config/tvlsim-paths.hpp>
30 
31 namespace boost_utf = boost::unit_test;
32 
33 // (Boost) Unit Test XML Report
34 std::ofstream utfReportStream ("SimulationTestSuite_utfresults.xml");
35 
39 struct UnitTestConfig {
41  UnitTestConfig() {
42  boost_utf::unit_test_log.set_stream (utfReportStream);
43  boost_utf::unit_test_log.set_format (boost_utf::XML);
44  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
45  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
46  }
48  ~UnitTestConfig() {
49  }
50 };
51 
52 // //////////////////////////////////////////////////////////////////////
56 void SimulationTest (const unsigned short iTestFlag,
57  const stdair::Filename_T iScheduleInputFilename,
58  const stdair::Filename_T iOnDInputFilename,
59  const stdair::Filename_T iFRAT5InputFilename,
60  const stdair::Filename_T iFFDisutilityInputFilename,
61  const stdair::Filename_T iYieldInputFilename,
62  const stdair::Filename_T iFareInputFilename,
63  const stdair::Filename_T iDemandInputFilename,
64  const bool isBuiltin) {
65 
66  // Method for the demand generation (here, statistics order)
67  const stdair::DemandGenerationMethod lOrderStatDemandGenMethod =
68  stdair::DemandGenerationMethod::STA_ORD;
69 
70  // Start date
71  const stdair::Date_T lStartDate (2009, boost::gregorian::Jan, 01);
72 
73  // End date
74  const stdair::Date_T lEndDate (2011, boost::gregorian::Jan, 01);
75 
76  // Random generation seed
77  const stdair::RandomSeed_T lRandomSeed (stdair::DEFAULT_RANDOM_SEED);
78 
79  // Number of simulation runs to be performed
80  const TVLSIM::NbOfRuns_T lNbOfRuns (1);
81 
82  // Output log File
83  std::ostringstream oStr;
84  oStr << "SimpleSimulationTestSuite_" << iTestFlag << ".log";
85  const stdair::Filename_T lLogFilename (oStr.str());
86 
87  // Set the log parameters
88  std::ofstream logOutputFile;
89  // Open and clean the log outputfile
90  logOutputFile.open (lLogFilename.c_str());
91  logOutputFile.clear();
92 
93  // Initialise the simulation context
94  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
95 
96  TVLSIM::TVLSIM_Service tvlsimService (lLogParams, lStartDate, lEndDate,
97  lRandomSeed, lOrderStatDemandGenMethod,
98  lNbOfRuns);
99 
100  // Check wether or not a (CSV) input file should be read
101  if (isBuiltin == true) {
102 
103  // Build the default sample BOM tree (filled with fares) for Simfqt
104  tvlsimService.buildSampleBom();
105 
106  } else {
107 
108  // Retrieve the input file path
109  const stdair::ScheduleFilePath lScheduleFilePath (iScheduleInputFilename);
110  const stdair::ODFilePath lODFilePath (iOnDInputFilename);
111  const stdair::FRAT5FilePath lFRAT5FilePath (iFRAT5InputFilename);
112  const stdair::FFDisutilityFilePath lFFDisutilityFilePath (iFFDisutilityInputFilename);
113  const AIRRAC::YieldFilePath lYieldFilePath (iYieldInputFilename);
114  const SIMFQT::FareFilePath lFareFilePath (iFareInputFilename);
115  const TRADEMGEN::DemandFilePath lDemandFilePath (iDemandInputFilename);
116 
117  // Load the input files
118  tvlsimService.setInputFiles(lScheduleFilePath,
119  lODFilePath,
120  lFRAT5FilePath,
121  lFFDisutilityFilePath,
122  lYieldFilePath,
123  lFareFilePath,
124  lDemandFilePath);
125 
126  // Parse the input files
127  tvlsimService.parseAndLoad ();
128  }
129 
130  // Initialise the snapshot and RM events
131  tvlsimService.initSnapshotAndRMEvents();
132 
133  // Perform a simulation
134  tvlsimService.simulate ();
135 
136  // Close the log file
137  logOutputFile.close();
138 
139 }
140 
141 // /////////////// Main: Unit Test Suite //////////////
142 
143 // Set the UTF configuration (re-direct the output to a specific file)
144 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
145 
146 // Start the test suite
147 BOOST_AUTO_TEST_SUITE (master_test_suite)
148 
149 
152 BOOST_AUTO_TEST_CASE (simple_simulation_test) {
153 
154  // State whether the BOM tree should be built-in or parsed from input files
155  const bool isBuiltin = false;
156 
157  // Schedule input file name
158  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
159  "/rds01/schedule.csv");
160 
161  // O&D input file name
162  const stdair::Filename_T lOnDInputFilename (STDAIR_SAMPLE_DIR "/ond01.csv");
163 
164  // FRAT5 curve input file name
165  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
166  "/frat5.csv");
167 
168  // Fare family disutility curve input file name
169  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
170  "/ffDisutility.csv");
171 
172  // Yield input file name
173  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
174  "/rds01/yield.csv");
175 
176  // Fare input file name
177  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR
178  "/rds01/fare.csv");
179 
180  // Demand input file name
181  const stdair::Filename_T lDemandInputFilename (STDAIR_SAMPLE_DIR
182  "/rds01/demand.csv");
183 
184  // Simulate
185  BOOST_CHECK_NO_THROW (SimulationTest(0,
186  lScheduleInputFilename,
187  lOnDInputFilename,
188  lFRAT5InputFilename,
189  lFFDisutilityInputFilename,
190  lYieldInputFilename,
191  lFareInputFilename,
192  lDemandInputFilename,
193  isBuiltin));
194 }
195 
199 BOOST_AUTO_TEST_CASE (default_bom_simulation_test) {
200 
201  // State whether the BOM tree should be built-in or parsed from input files
202  const bool isBuiltin = true;
203 
204  // Simulate
205  BOOST_CHECK_NO_THROW (SimulationTest(1,
206  " ", " ", " ", " ", " ", " ", " ",
207  isBuiltin));
208 
209 
210 }
211 
212 // End the test suite
213 BOOST_AUTO_TEST_SUITE_END()
214 
215