TvlSim Logo  1.01.6
C++ Simulated Travel-Oriented Distribution System Library
PartnerSimulationTestSuite.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 TvlSimTest
16 #include <boost/test/unit_test.hpp>
17 // StdAir
18 #include <stdair/stdair_exceptions.hpp>
19 #include <stdair/stdair_json.hpp>
20 #include <stdair/basic/BasConst_General.hpp>
21 #include <stdair/basic/BasLogParams.hpp>
22 #include <stdair/basic/BasFileMgr.hpp>
23 #include <stdair/basic/DemandGenerationMethod.hpp>
24 #include <stdair/service/Logger.hpp>
25 // SimFQT
26 #include <simfqt/SIMFQT_Types.hpp>
27 // Dsim
28 #include <tvlsim/TVLSIM_Types.hpp>
30 #include <tvlsim/config/tvlsim-paths.hpp>
31 
32 namespace boost_utf = boost::unit_test;
33 
34 // (Boost) Unit Test XML Report
35 std::ofstream utfReportStream ("PartnerSimulationTestSuite_utfresults.xml");
36 
40 struct UnitTestConfig {
42  UnitTestConfig() {
43  boost_utf::unit_test_log.set_stream (utfReportStream);
44 #if BOOST_VERSION_MACRO >= 105900
45  boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
46 #else // BOOST_VERSION_MACRO
47  boost_utf::unit_test_log.set_format (boost_utf::XML);
48 #endif // BOOST_VERSION_MACRO
49  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
50  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
51  }
53  ~UnitTestConfig() {
54  }
55 };
56 
57 
58 // /////////////// Main: Unit Test Suite //////////////
59 
60 // Set the UTF configuration (re-direct the output to a specific file)
61 BOOST_GLOBAL_FIXTURE (UnitTestConfig);
62 
63 // Start the test suite
64 BOOST_AUTO_TEST_SUITE (master_test_suite)
65 
66 
69 BOOST_AUTO_TEST_CASE (partner_simulation_test) {
70 
71  // Method for the demand generation (here, statistics order)
72  const stdair::DemandGenerationMethod lOrderStatDemandGenMethod =
73  stdair::DemandGenerationMethod::STA_ORD;
74 
75  // Start date
76  const stdair::Date_T lStartDate (2009, boost::gregorian::Jan, 01);
77 
78  // End date
79  const stdair::Date_T lEndDate (2011, boost::gregorian::Jan, 01);
80 
81  // Random generation seed
82  const stdair::RandomSeed_T lRandomSeed (stdair::DEFAULT_RANDOM_SEED);
83 
84  // Number of simulation runs to be performed
85  const TVLSIM::NbOfRuns_T lNbOfRuns (1);
86 
87  // Demand input file name
88  const stdair::Filename_T lDemandInputFilename (STDAIR_SAMPLE_DIR
89  "/IBP_study/demand01.csv");
90 
91  // Schedule input file name
92  const stdair::Filename_T lScheduleInputFilename (STDAIR_SAMPLE_DIR
93  "/IBP_study/schedule01.csv");
94 
95  // O&D input file name
96  const stdair::Filename_T lOnDInputFilename (STDAIR_SAMPLE_DIR "/IBP_study/ond01.csv");
97 
98  // FRAT5 curve input file name
99  const stdair::Filename_T lFRAT5InputFilename (STDAIR_SAMPLE_DIR
100  "/frat5.csv");
101 
102  // Fare family disutility curve input file name
103  const stdair::Filename_T lFFDisutilityInputFilename (STDAIR_SAMPLE_DIR
104  "/ffDisutility.csv");
105 
106  // Yield input file name
107  const stdair::Filename_T lYieldInputFilename (STDAIR_SAMPLE_DIR
108  "/IBP_study/yield01.csv");
109 
110  // Fare input file name
111  const stdair::Filename_T lFareInputFilename (STDAIR_SAMPLE_DIR
112  "/IBP_study/fare01.csv");
113 
114  // Check that the file path given as input corresponds to an actual file
115  bool doesExistAndIsReadable =
116  stdair::BasFileMgr::doesExistAndIsReadable (lScheduleInputFilename);
117  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
118  "The '" << lScheduleInputFilename
119  << "' input file can not be open and read");
120 
121  // Check that the file path given as input corresponds to an actual file
122  doesExistAndIsReadable =
123  stdair::BasFileMgr::doesExistAndIsReadable (lOnDInputFilename);
124  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
125  "The '" << lOnDInputFilename
126  << "' input file can not be open and read");
127 
128  // Check that the file path given as input corresponds to an actual file
129  doesExistAndIsReadable =
130  stdair::BasFileMgr::doesExistAndIsReadable (lFRAT5InputFilename);
131  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
132  "The '" << lFRAT5InputFilename
133  << "' input file can not be open and read");
134 
135  // Check that the file path given as input corresponds to an actual file
136  doesExistAndIsReadable =
137  stdair::BasFileMgr::doesExistAndIsReadable (lFFDisutilityInputFilename);
138  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
139  "The '" << lFFDisutilityInputFilename
140  << "' input file can not be open and read");
141 
142  // Check that the file path given as input corresponds to an actual file
143  doesExistAndIsReadable =
144  stdair::BasFileMgr::doesExistAndIsReadable (lDemandInputFilename);
145  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
146  "The '" << lDemandInputFilename
147  << "' input file can not be open and read");
148 
149  // Check that the file path given as input corresponds to an actual file
150  doesExistAndIsReadable =
151  stdair::BasFileMgr::doesExistAndIsReadable (lFareInputFilename);
152  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
153  "The '" << lFareInputFilename
154  << "' input file can not be open and read");
155 
156  // Check that the file path given as input corresponds to an actual file
157  doesExistAndIsReadable =
158  stdair::BasFileMgr::doesExistAndIsReadable (lYieldInputFilename);
159  BOOST_CHECK_MESSAGE (doesExistAndIsReadable == true,
160  "The '" << lYieldInputFilename
161  << "' input file can not be open and read");
162 
163  // Output log File
164  const stdair::Filename_T lLogFilename ("PartnerSimulationTestSuite.log");
165 
166  // Set the log parameters
167  std::ofstream logOutputFile;
168  // Open and clean the log outputfile
169  logOutputFile.open (lLogFilename.c_str());
170  logOutputFile.clear();
171 
172  // Initialise the simulation context
173  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
174 
175  TVLSIM::TVLSIM_Service tvlsimService (lLogParams, lStartDate, lEndDate,
176  lRandomSeed, lOrderStatDemandGenMethod,
177  lNbOfRuns);
178 
179  // Construct the JSON command string for the airline features
180  std::ostringstream lMyCommandJSONstream;
181  lMyCommandJSONstream << "{\"config\":"
182  << "{\"airline1\":"
183  << "{ \"airline_code\":\"" << "SQ"
184  << "\",\"unconstraining_method\":\"" << "E"
185  << "\",\"pre_optimisation_method\":\"N"
186  << "\",\"optimisation_method\":\"M"
187  << "\",\"partnership_technique\":\"i"
188  << "\",\"forecasting_method\":\"B"
189  << "\"},"
190  << "\"airline2\":"
191  << "{ \"airline_code\":\"" << "CX"
192  << "\",\"unconstraining_method\":\"" << "E"
193  << "\",\"pre_optimisation_method\":\"N"
194  << "\",\"optimisation_method\":\"M"
195  << "\",\"partnership_technique\":\"i"
196  << "\",\"forecasting_method\":\"B"
197  << "\"}}}";
198 
199  STDAIR_LOG_DEBUG(lMyCommandJSONstream.str());
200  // Load the airlines features configuration
201  const stdair::JSONString lJSONCommandString (lMyCommandJSONstream.str());
202  const std::string& lCSVConfigDump =
203  tvlsimService.jsonHandler (lJSONCommandString);
204 
205  STDAIR_LOG_DEBUG(lCSVConfigDump);
210  // Build the BOM tree from parsing input files
211  const stdair::ScheduleFilePath lScheduleFilePath (lScheduleInputFilename);
212  const stdair::ODFilePath lODFilePath (lOnDInputFilename);
213  const stdair::FRAT5FilePath lFRAT5FilePath (lFRAT5InputFilename);
214  const stdair::FFDisutilityFilePath lFFDisutilityFilePath (lFFDisutilityInputFilename);
215  const SIMFQT::FareFilePath lFareFilePath (lFareInputFilename);
216  const AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
217  const TRADEMGEN::DemandFilePath lDemandFilePath (lDemandInputFilename);
218 
219  // Load the input files
220  BOOST_CHECK_NO_THROW (tvlsimService.setInputFiles(lScheduleFilePath,
221  lODFilePath,
222  lFRAT5FilePath,
223  lFFDisutilityFilePath,
224  lYieldFilePath,
225  lFareFilePath,
226  lDemandFilePath));
227 
228  // Parse the input files
229  BOOST_CHECK_NO_THROW (tvlsimService.parseAndLoad ());
230 
231  // Initialise the snapshot and RM events
232  BOOST_CHECK_NO_THROW (tvlsimService.initSnapshotAndRMEvents());
233 
234  // Perform a simulation
235  // BOOST_CHECK_THROW (tvlsimService.simulate(), stdair::EventException);
236  BOOST_CHECK_NO_THROW (tvlsimService.simulate ());
237 
238  // Close the log file
239  logOutputFile.close();
240 }
241 
242 // End the test suite
243 BOOST_AUTO_TEST_SUITE_END()
244 
245 
unsigned int NbOfRuns_T