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