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