From: <den...@us...> - 2010-02-07 02:41:50
|
Revision: 62 http://dsim.svn.sourceforge.net/dsim/?rev=62&view=rev Author: denis_arnaud Date: 2010-02-07 02:41:42 +0000 (Sun, 07 Feb 2010) Log Message: ----------- [DB] Now fully support database storage (with a simple example for airline names). Modified Paths: -------------- trunk/dsim/configure.ac trunk/dsim/dsim/DSIM_Service.hpp trunk/dsim/dsim/batches/Makefile.am trunk/dsim/dsim/batches/sources.mk trunk/dsim/dsim/command/Makefile.am trunk/dsim/dsim/command/sources.mk trunk/dsim/dsim/service/DSIM_Service.cpp trunk/dsim/dsim/service/DSIM_ServiceContext.hpp trunk/dsim/test/dsim/Makefile.am trunk/dsim/test/dsim/simulate.cpp Added Paths: ----------- trunk/dsim/dsim/batches/simulate.cpp trunk/dsim/dsim/command/DBManager.cpp trunk/dsim/dsim/command/DBManager.hpp trunk/dsim/test/dsim/SimulationTestSuite.cpp trunk/dsim/test/dsim/SimulationTestSuite.hpp Property Changed: ---------------- trunk/dsim/dsim/batches/ trunk/dsim/test/dsim/ Modified: trunk/dsim/configure.ac =================================================================== --- trunk/dsim/configure.ac 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/configure.ac 2010-02-07 02:41:42 UTC (rev 62) @@ -171,20 +171,20 @@ # ----------------------------------------------------------- # OpenMPI: http://www.open-mpi.org # ----------------------------------------------------------- -#AX_OPENMPI -#AC_SUBST(MPIGEN_VERSION) -#AC_SUBST(MPIGEN_CFLAGS) -#AC_SUBST(MPIGEN_LIBS) +AX_OPENMPI +AC_SUBST(MPIGEN_VERSION) +AC_SUBST(MPIGEN_CFLAGS) +AC_SUBST(MPIGEN_LIBS) # ----------------------------------------------------------- # MPICH2: http://www.mcs.anl.gov/research/projects/mpich2 # Note: Boost.MPI depends on MPICH2 by default, rather than # on OpenMPI # ----------------------------------------------------------- -AX_MPICH2 -AC_SUBST(MPIGEN_VERSION) -AC_SUBST(MPIGEN_CFLAGS) -AC_SUBST(MPIGEN_LIBS) +#AX_MPICH2 +#AC_SUBST(MPIGEN_VERSION) +#AC_SUBST(MPIGEN_CFLAGS) +#AC_SUBST(MPIGEN_LIBS) # --------------------------------------------------------------- # Support for Boost (Extension of the STL): http://www.boost.org @@ -404,6 +404,7 @@ stdair/Makefile stdair/basic/Makefile stdair/bom/Makefile + stdair/dbadaptor/Makefile stdair/factory/Makefile stdair/config/Makefile stdair/service/Makefile Modified: trunk/dsim/dsim/DSIM_Service.hpp =================================================================== --- trunk/dsim/dsim/DSIM_Service.hpp 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/dsim/DSIM_Service.hpp 2010-02-07 02:41:42 UTC (rev 62) @@ -6,10 +6,17 @@ // ////////////////////////////////////////////////////////////////////// // StdAir #include <stdair/STDAIR_Types.hpp> -#include <stdair/basic/BasLogParams.hpp> // Dsim #include <dsim/DSIM_Types.hpp> +// Forward declarations. +namespace stdair { + class AirlineFeatureSet; + class STDAIR_Service; + struct BasLogParams; + struct BasDBParams; +} + namespace DSIM { // Forward declaration @@ -19,37 +26,50 @@ /** Interface for the DSIM Services. */ class DSIM_Service { public: - // /////////// Business Methods ///////////// - /** Perform a simulation. */ - void simulate(); - - - public: // ////////// Constructors and destructors ////////// /** Constructor. <br>The init() method is called; see the corresponding documentation for more details. - <br>Moreover, a reference on an output stream is given, so - that log outputs can be directed onto that stream. + <br>A reference on an output stream is given, so that log + outputs can be directed onto that stream. + <br>Moreover, database connection parameters are given, so that a + session can be created on the corresponding database. @param const stdair::BasLogParams& Parameters for the output log stream. - @param const stdair::Filename_T& Filename of the input schedule file. */ - DSIM_Service (const stdair::BasLogParams&, const stdair::Filename_T&); + @param const stdair::BasDBParams& Parameters for the database access. + @param const stdair::Filename_T& Filename of the input schedule file. + @param const stdair::Filename_T& Filename of the input demand file. */ + DSIM_Service (const stdair::BasLogParams&, const stdair::BasDBParams&, + const stdair::Filename_T& iScheduleInputFilename, + const stdair::Filename_T& iDemandInputFilenames); /** Constructor. <br>The init() method is called; see the corresponding documentation for more details. <br>Moreover, as no reference on any output stream is given, - it is assumed that the StdAir log service has already been - initialised with the proper log output stream by some other - methods in the calling chain (for instance, when the DSIM_Service - is itself being initialised by another library service). - @param const stdair::Filename_T& Filename of the input schedule file. */ - DSIM_Service (const stdair::Filename_T&); + neither any database access parameter is given, it is assumed + that the StdAir log service has already been initialised with + the proper log output stream by some other methods in the + calling chain (for instance, when the DSIM_Service is + itself being initialised by another library service). + @param const stdair::Filename_T& Filename of the input schedule file. + @param const stdair::Filename_T& Filename of the input demand file. */ + DSIM_Service (stdair::STDAIR_ServicePtr_T, + const stdair::Filename_T& iScheduleInputFilename, + const stdair::Filename_T& iDemandInputFilenames); /** Destructor. */ ~DSIM_Service(); + public: + // /////////// Business Methods ///////////// + /** Perform a simulation. */ + void simulate(); + + /** Display the list of airlines. */ + void displayAirlineListFromDB(); + + private: // /////// Construction and Destruction helper methods /////// /** Default constructor. */ @@ -57,13 +77,6 @@ /** Default copy constructor. */ DSIM_Service (const DSIM_Service&); - /** Initialise the log. */ - void logInit (const stdair::BasLogParams&); - - /** Initialise. - @param const stdair::Filename_T& Filename of the input schedule file. */ - void init (stdair::STDAIR_ServicePtr_T, const stdair::Filename_T&); - /** Initialise the (DSIM) service context (i.e., the DSIM_ServiceContext object). */ void initServiceContext (); @@ -72,9 +85,20 @@ <br>A reference on the root of the BOM tree, namely the BomRoot object, is stored within the service context for later use. @param const stdair::BasLogParams& Parameters for the output log stream. - */ - stdair::STDAIR_ServicePtr_T initStdAirService (const stdair::BasLogParams&); - + @param const stdair::BasDBParams& Parameters for the database access. + @param const stdair::AirlineFeatureSet& Set of airline features. */ + void initStdAirService (const stdair::BasLogParams&, + const stdair::BasDBParams&); + + /** Initialise. + <br>The CSV file, describing the airline schedules for the + simulator, is parsed and the inventories are generated accordingly. + @param const stdair::AirlineFeatureSet& Set of airline features. + @param const stdair::Filename_T& Filename of the input schedule file. + @param const stdair::Filename_T& Filename of the input demand file. */ + void init (const stdair::Filename_T& iScheduleInputFilename, + const stdair::Filename_T& iDemandInputFilename); + /** Finalise. */ void finalise (); Property changes on: trunk/dsim/dsim/batches ___________________________________________________________________ Modified: svn:ignore - .deps .libs Makefile.in Makefile dsim + .deps .libs Makefile.in Makefile simulate simulate.log Modified: trunk/dsim/dsim/batches/Makefile.am =================================================================== --- trunk/dsim/dsim/batches/Makefile.am 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/dsim/batches/Makefile.am 2010-02-07 02:41:42 UTC (rev 62) @@ -6,10 +6,12 @@ MAINTAINERCLEANFILES = Makefile.in + # Binaries (batches) -bin_PROGRAMS = +bin_PROGRAMS = simulate -#airinv_SOURCES = $(batches_h_sources) $(batches_cc_sources) -#airinv_CXXFLAGS = $(BOOST_CFLAGS) -#airinv_LDADD = -#airinv_LDFLAGS = $(BOOST_PROGRAM_OPTIONS_LIB) $(top_builddir)/airinv/core/libairinv.la +simulate_SOURCES = $(batches_h_sources) $(batches_cc_sources) +simulate_CXXFLAGS = $(BOOST_CFLAGS) +simulate_LDADD = +simulate_LDFLAGS = $(BOOST_PROGRAM_OPTIONS_LIB) $(SOCI_LIBS) \ + $(top_builddir)/dsim/core/libdsim.la Added: trunk/dsim/dsim/batches/simulate.cpp =================================================================== --- trunk/dsim/dsim/batches/simulate.cpp (rev 0) +++ trunk/dsim/dsim/batches/simulate.cpp 2010-02-07 02:41:42 UTC (rev 62) @@ -0,0 +1,338 @@ +// STL +#include <cassert> +#include <iostream> +#include <sstream> +#include <fstream> +#include <vector> +#include <string> +// Boost (Extended STL) +#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/date_time/gregorian/gregorian.hpp> +#include <boost/tokenizer.hpp> +#include <boost/program_options.hpp> +// StdAir +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/BasLogParams.hpp> +#include <stdair/basic/BasDBParams.hpp> +#include <stdair/factory/FacBomContent.hpp> +#include <stdair/bom/AirlineFeatureSet.hpp> +#include <stdair/bom/AirlineFeature.hpp> +// DSIM +#include <dsim/DSIM_Service.hpp> +#include <dsim/config/dsim-paths.hpp> + +// //////// Type definitions /////// +typedef std::vector<std::string> WordList_T; + + +// //////// Constants ////// +/** Default name and location for the log file. */ +const std::string K_DSIM_DEFAULT_LOG_FILENAME ("simulate.log"); + +/** Default name and location for the (CSV) demand input file. */ +const std::string K_DSIM_DEFAULT_DEMAND_INPUT_FILENAME ("../../test/samples/demand01.csv"); + +/** Default name and location for the (CSV) schedule input file. */ +const std::string K_DSIM_DEFAULT_SCHEDULE_INPUT_FILENAME ("../../test/samples/schedule01.csv"); + +/** Default query string. */ +const std::string K_DSIM_DEFAULT_QUERY_STRING ("my good old query"); + +/** Default name and location for the Xapian database. */ +const std::string K_DSIM_DEFAULT_DB_USER ("dsim"); +const std::string K_DSIM_DEFAULT_DB_PASSWD ("dsim"); +const std::string K_DSIM_DEFAULT_DB_DBNAME ("dsim"); +const std::string K_DSIM_DEFAULT_DB_HOST ("localhost"); +const std::string K_DSIM_DEFAULT_DB_PORT ("3306"); + + +// ////////////////////////////////////////////////////////////////////// +void tokeniseStringIntoWordList (const std::string& iPhrase, + WordList_T& ioWordList) { + // Empty the word list + ioWordList.clear(); + + // Boost Tokeniser + typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T; + + // Define the separators + const boost::char_separator<char> lSepatorList(" .,;:|+-*/_=!@#$%`~^&(){}[]?'<>\""); + + // Initialise the phrase to be tokenised + Tokeniser_T lTokens (iPhrase, lSepatorList); + for (Tokeniser_T::const_iterator tok_iter = lTokens.begin(); + tok_iter != lTokens.end(); ++tok_iter) { + const std::string& lTerm = *tok_iter; + ioWordList.push_back (lTerm); + } + +} + +// ////////////////////////////////////////////////////////////////////// +std::string createStringFromWordList (const WordList_T& iWordList) { + std::ostringstream oStr; + + unsigned short idx = iWordList.size(); + for (WordList_T::const_iterator itWord = iWordList.begin(); + itWord != iWordList.end(); ++itWord, --idx) { + const std::string& lWord = *itWord; + oStr << lWord; + if (idx > 1) { + oStr << " "; + } + } + + return oStr.str(); +} + + +// ///////// Parsing of Options & Configuration ///////// +// A helper function to simplify the main part. +template<class T> std::ostream& operator<< (std::ostream& os, + const std::vector<T>& v) { + std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, " ")); + return os; +} + +/** Early return status (so that it can be differentiated from an error). */ +const int K_DSIM_EARLY_RETURN_STATUS = 99; + +/** Read and parse the command line options. */ +int readConfiguration (int argc, char* argv[], + std::string& ioQueryString, + stdair::Filename_T& ioScheduleInputFilename, + stdair::Filename_T& ioDemandInputFilename, + std::string& ioLogFilename, + std::string& ioDBUser, std::string& ioDBPasswd, + std::string& ioDBHost, std::string& ioDBPort, + std::string& ioDBDBName) { + + // Initialise the travel query string, if that one is empty + if (ioQueryString.empty() == true) { + ioQueryString = K_DSIM_DEFAULT_QUERY_STRING; + } + + // Transform the query string into a list of words (STL strings) + WordList_T lWordList; + tokeniseStringIntoWordList (ioQueryString, lWordList); + + // Declare a group of options that will be allowed only on command line + boost::program_options::options_description generic ("Generic options"); + generic.add_options() + ("prefix", "print installation prefix") + ("version,v", "print version string") + ("help,h", "produce help message"); + + // Declare a group of options that will be allowed both on command + // line and in config file + boost::program_options::options_description config ("Configuration"); + config.add_options() + ("demand,d", + boost::program_options::value< std::string >(&ioScheduleInputFilename)->default_value(K_DSIM_DEFAULT_DEMAND_INPUT_FILENAME), + "(CVS) input file for the demand distributions") + ("schedule,s", + boost::program_options::value< std::string >(&ioDemandInputFilename)->default_value(K_DSIM_DEFAULT_SCHEDULE_INPUT_FILENAME), + "(CVS) input file for the schedules") + ("log,l", + boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_DSIM_DEFAULT_LOG_FILENAME), + "Filepath for the logs") + ("user,u", + boost::program_options::value< std::string >(&ioDBUser)->default_value(K_DSIM_DEFAULT_DB_USER), + "SQL database hostname (e.g., dsim)") + ("passwd,p", + boost::program_options::value< std::string >(&ioDBPasswd)->default_value(K_DSIM_DEFAULT_DB_PASSWD), + "SQL database hostname (e.g., dsim)") + ("host,H", + boost::program_options::value< std::string >(&ioDBHost)->default_value(K_DSIM_DEFAULT_DB_HOST), + "SQL database hostname (e.g., localhost)") + ("port,P", + boost::program_options::value< std::string >(&ioDBPort)->default_value(K_DSIM_DEFAULT_DB_PORT), + "SQL database port (e.g., 3306)") + ("dbname,m", + boost::program_options::value< std::string >(&ioDBDBName)->default_value(K_DSIM_DEFAULT_DB_DBNAME), + "SQL database name (e.g., dsim)") + ("query,q", + boost::program_options::value< WordList_T >(&lWordList)->multitoken(), + "Query word list") + ; + + // Hidden options, will be allowed both on command line and + // in config file, but will not be shown to the user. + boost::program_options::options_description hidden ("Hidden options"); + hidden.add_options() + ("copyright", + boost::program_options::value< std::vector<std::string> >(), + "Show the copyright (license)"); + + boost::program_options::options_description cmdline_options; + cmdline_options.add(generic).add(config).add(hidden); + + boost::program_options::options_description config_file_options; + config_file_options.add(config).add(hidden); + + boost::program_options::options_description visible ("Allowed options"); + visible.add(generic).add(config); + + boost::program_options::positional_options_description p; + p.add ("copyright", -1); + + boost::program_options::variables_map vm; + boost::program_options:: + store (boost::program_options::command_line_parser (argc, argv). + options (cmdline_options).positional(p).run(), vm); + + std::ifstream ifs ("simulate.cfg"); + boost::program_options::store (parse_config_file (ifs, config_file_options), + vm); + boost::program_options::notify (vm); + + if (vm.count ("help")) { + std::cout << visible << std::endl; + return K_DSIM_EARLY_RETURN_STATUS; + } + + if (vm.count ("version")) { + std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl; + return K_DSIM_EARLY_RETURN_STATUS; + } + + if (vm.count ("prefix")) { + std::cout << "Installation prefix: " << PREFIXDIR << std::endl; + return K_DSIM_EARLY_RETURN_STATUS; + } + + if (vm.count ("schedule")) { + ioScheduleInputFilename = vm["schedule"].as< std::string >(); + std::cout << "Schedule input filename is: " << ioScheduleInputFilename + << std::endl; + } + + if (vm.count ("demand")) { + ioDemandInputFilename = vm["demand"].as< std::string >(); + std::cout << "Demand input filename is: " << ioDemandInputFilename + << std::endl; + } + + if (vm.count ("log")) { + ioLogFilename = vm["log"].as< std::string >(); + std::cout << "Log filename is: " << ioLogFilename << std::endl; + } + + if (vm.count ("user")) { + ioDBUser = vm["user"].as< std::string >(); + std::cout << "SQL database user name is: " << ioDBUser << std::endl; + } + + if (vm.count ("passwd")) { + ioDBPasswd = vm["passwd"].as< std::string >(); + //std::cout << "SQL database user password is: " << ioDBPasswd << std::endl; + } + + if (vm.count ("host")) { + ioDBHost = vm["host"].as< std::string >(); + std::cout << "SQL database host name is: " << ioDBHost << std::endl; + } + + if (vm.count ("port")) { + ioDBPort = vm["port"].as< std::string >(); + std::cout << "SQL database port number is: " << ioDBPort << std::endl; + } + + if (vm.count ("dbname")) { + ioDBDBName = vm["dbname"].as< std::string >(); + std::cout << "SQL database name is: " << ioDBDBName << std::endl; + } + + ioQueryString = createStringFromWordList (lWordList); + std::cout << "The query string is: " << ioQueryString << std::endl; + + return 0; +} + +// ///////// M A I N //////////// +int main (int argc, char* argv[]) { + + try { + + // Query + std::string lQuery; + + // Schedule input file name + stdair::Filename_T lScheduleInputFilename; + + // Demand input file name + stdair::Filename_T lDemandInputFilename; + + // Output log File + std::string lLogFilename; + + // SQL database parameters + std::string lDBUser; + std::string lDBPasswd; + std::string lDBHost; + std::string lDBPort; + std::string lDBDBName; + + // Airline code + stdair::AirlineCode_T lAirlineCode ("BA"); + + // Call the command-line option parser + const int lOptionParserStatus = + readConfiguration (argc, argv, lQuery, lScheduleInputFilename, + lDemandInputFilename, lLogFilename, + lDBUser, lDBPasswd, lDBHost, lDBPort, lDBDBName); + + if (lOptionParserStatus == K_DSIM_EARLY_RETURN_STATUS) { + return 0; + } + + // Set the database parameters + stdair::BasDBParams lDBParams (lDBUser, lDBPasswd, lDBHost, lDBPort, + lDBDBName); + + // Set the log parameters + std::ofstream logOutputFile; + // open and clean the log outputfile + logOutputFile.open (lLogFilename.c_str()); + logOutputFile.clear(); + + // Initialise the set of required airline features + stdair::AirlineFeatureSet& lAirlineFeatureSet = + stdair::FacBomContent::instance().create<stdair::AirlineFeatureSet>(); + + // Initialise an AirlineFeature object + stdair::AirlineFeatureKey_T lAirlineFeatureKey (lAirlineCode); + stdair::AirlineFeature& lAirlineFeature = stdair::FacBomContent:: + instance().create<stdair::AirlineFeature> (lAirlineFeatureKey); + stdair::FacBomContent:: + linkWithParent<stdair::AirlineFeature> (lAirlineFeature, + lAirlineFeatureSet); + + // Initialise the simulation context + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + DSIM::DSIM_Service dsimService (lLogParams, lDBParams, + lScheduleInputFilename, + lDemandInputFilename); + + // Perform a simulation + dsimService.simulate(); + + // DEBUG + // Display the airlines stored in the database + dsimService.displayAirlineListFromDB(); + + } catch (const DSIM::RootException& otexp) { + std::cerr << "Standard exception: " << otexp.what() << std::endl; + return -1; + + } catch (const std::exception& stde) { + std::cerr << "Standard exception: " << stde.what() << std::endl; + return -1; + + } catch (...) { + return -1; + } + + return 0; +} + Modified: trunk/dsim/dsim/batches/sources.mk =================================================================== --- trunk/dsim/dsim/batches/sources.mk 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/dsim/batches/sources.mk 2010-02-07 02:41:42 UTC (rev 62) @@ -1,2 +1,2 @@ batches_h_sources = -batches_cc_sources = +batches_cc_sources = $(top_srcdir)/dsim/batches/simulate.cpp Added: trunk/dsim/dsim/command/DBManager.cpp =================================================================== --- trunk/dsim/dsim/command/DBManager.cpp (rev 0) +++ trunk/dsim/dsim/command/DBManager.cpp 2010-02-07 02:41:42 UTC (rev 62) @@ -0,0 +1,166 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +// SOCI +#include <soci/core/soci.h> +#include <soci/backends/mysql/soci-mysql.h> +// StdAir +#include <stdair/bom/AirlineStruct.hpp> +#include <stdair/dbadaptor/DbaAirline.hpp> +#include <stdair/service/Logger.hpp> +// Dsim +#include <dsim/command/DBManager.hpp> + +namespace DSIM { + + // ////////////////////////////////////////////////////////////////////// + void DBManager:: + prepareSelectStatement (stdair::DBSession_T& ioSociSession, + stdair::DBRequestStatement_T& ioSelectStatement, + stdair::AirlineStruct& ioAirline) { + + try { + + // Instanciate a SQL statement (no request is performed at that stage) + /** + select code, name + from airlines; + */ + + ioSelectStatement = (ioSociSession.prepare + << "select iata_code, name " + << "from airlines ", soci::into (ioAirline)); + + // Execute the SQL query + ioSelectStatement.execute(); + + } catch (std::exception const& lException) { + STDAIR_LOG_ERROR ("Error: " << lException.what()); + throw SQLDatabaseException(); + } + } + + // ////////////////////////////////////////////////////////////////////// + void DBManager:: + prepareSelectOnAirlineCodeStatement (stdair::DBSession_T& ioSociSession, + stdair::DBRequestStatement_T& ioSelectStatement, + const stdair::AirlineCode_T& iAirlineCode, + stdair::AirlineStruct& ioAirline) { + + try { + + // Instanciate a SQL statement (no request is performed at that stage) + /** + select code, name + from airlines + where code = iAirlineCode; + */ + + ioSelectStatement = (ioSociSession.prepare + << "select iata_code, name " + << "from airlines " + << "where iata_code = :airline_code ", + soci::into (ioAirline), soci::use (iAirlineCode)); + + // Execute the SQL query + ioSelectStatement.execute(); + + } catch (std::exception const& lException) { + STDAIR_LOG_ERROR ("Error: " << lException.what()); + throw SQLDatabaseException(); + } + } + + // ////////////////////////////////////////////////////////////////////// + bool DBManager::iterateOnStatement (stdair::DBRequestStatement_T& ioStatement, + stdair::AirlineStruct& ioAirline) { + bool hasStillData = false; + + try { + + // Retrieve the next row of Airline object + hasStillData = ioStatement.fetch(); + + } catch (std::exception const& lException) { + STDAIR_LOG_ERROR ("Error: " << lException.what()); + throw SQLDatabaseException(); + } + + return hasStillData; + } + + // ////////////////////////////////////////////////////////////////////// + void DBManager::updateAirlineInDB (stdair::DBSession_T& ioSociSession, + const stdair::AirlineStruct& iAirline) { + + try { + + // Begin a transaction on the database + ioSociSession.begin(); + + // Retrieve the airline code + const std::string& lAirlineCode = iAirline.getAirlineCode(); + + // Retrieve the airline name + const std::string& lAirlineName = iAirline.getAirlineName(); + + // Instanciate a SQL statement (no request is performed at that stage) + stdair::DBRequestStatement_T lUpdateStatement = + (ioSociSession.prepare + << "update airlines " + << "set name = :name " + << "where iata_code = :iata_code", + soci::use (lAirlineName), soci::use (lAirlineCode)); + + // Execute the SQL query + lUpdateStatement.execute (true); + + // Commit the transaction on the database + ioSociSession.commit(); + + // Debug + // STDAIR_LOG_DEBUG ("[" << lAirlineCode << "] " << iAirline); + + } catch (std::exception const& lException) { + STDAIR_LOG_ERROR ("Error: " << lException.what()); + throw SQLDatabaseException(); + } + } + + // ////////////////////////////////////////////////////////////////////// + bool DBManager::retrieveAirline (stdair::DBSession_T& ioSociSession, + const stdair::AirlineCode_T& iAirlineCode, + stdair::AirlineStruct& ioAirline) { + bool oHasRetrievedAirline = false; + + try { + + // Prepare the SQL request corresponding to the select statement + stdair::DBRequestStatement_T lSelectStatement (ioSociSession); + DBManager::prepareSelectOnAirlineCodeStatement (ioSociSession, + lSelectStatement, + iAirlineCode, ioAirline); + const bool shouldDoReset = true; + bool hasStillData = iterateOnStatement (lSelectStatement, ioAirline); + if (hasStillData == true) { + oHasRetrievedAirline = true; + } + + // Sanity check + const bool shouldNotDoReset = false; + hasStillData = iterateOnStatement (lSelectStatement, ioAirline); + + // Debug + // STDAIR_LOG_DEBUG ("[" << iDocID << "] " << ioAirline); + + } catch (std::exception const& lException) { + STDAIR_LOG_ERROR ("Error: " << lException.what()); + throw SQLDatabaseException(); + } + + return oHasRetrievedAirline; + } + +} Added: trunk/dsim/dsim/command/DBManager.hpp =================================================================== --- trunk/dsim/dsim/command/DBManager.hpp (rev 0) +++ trunk/dsim/dsim/command/DBManager.hpp 2010-02-07 02:41:42 UTC (rev 62) @@ -0,0 +1,77 @@ +#ifndef __DSIM_CMD_DBMANAGER_HPP +#define __DSIM_CMD_DBMANAGER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// StdAir +#include <stdair/STDAIR_Types.hpp> +// Dsim +#include <dsim/DSIM_Types.hpp> + +namespace DSIM { + + // Forward declarations + struct AirlineStruct; + + /** Class building the Business Object Model (BOM) from data retrieved + from the database. */ + class DBManager { + public: + /** Update the fields of the database row + corresponding to the given BOM object. + @parameter stdair::DBSession_T& + @parameter stdair::AirlineStruct& . */ + static void updateAirlineInDB (stdair::DBSession_T&, + const stdair::AirlineStruct&); + + /** Retrieve, from the (MySQL) database, the row corresponding to + the given BOM code, and fill the given BOM object with that retrieved + data. + @parameter stdair::DBSession_T& + @parameter const stdair::AirlineCode_T& + @parameter stdair::AirlineStruct& . */ + static bool retrieveAirline (stdair::DBSession_T&, + const stdair::AirlineCode_T&, + stdair::AirlineStruct&); + + + public: + /** Prepare (parse and put in cache) the SQL statement. + @parameter stdair::DBSession_T& + @parameter stdair::DBRequestStatement_T& + @parameter stdair::AirlineStruct& . */ + static void prepareSelectStatement (stdair::DBSession_T&, + stdair::DBRequestStatement_T&, + stdair::AirlineStruct&); + + /** Iterate on the SQL statement. + <br>The SQL has to be already prepared. + @parameter stdair::DBRequestStatement_T& + @parameter stdair::AirlineStruct& . */ + static bool iterateOnStatement (stdair::DBRequestStatement_T&, + stdair::AirlineStruct&); + + + private: + /** Prepare (parse and put in cache) the SQL statement. + @parameter stdair::DBSession_T& + @parameter stdair::DBRequestStatement_T& + @parameter const stdair::AirlineCode_T& + @parameter stdair::AirlineStruct& */ + static void prepareSelectOnAirlineCodeStatement (stdair::DBSession_T&, + stdair::DBRequestStatement_T&, + const stdair::AirlineCode_T&, + stdair::AirlineStruct&); + + + private: + /** Constructors. */ + DBManager() {} + DBManager(const DBManager&) {} + /** Destructor. */ + ~DBManager() {} + }; + +} +#endif // __DSIM_CMD_DBMANAGER_HPP Modified: trunk/dsim/dsim/command/Makefile.am =================================================================== --- trunk/dsim/dsim/command/Makefile.am 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/dsim/command/Makefile.am 2010-02-07 02:41:42 UTC (rev 62) @@ -5,9 +5,9 @@ noinst_LTLIBRARIES= libcmd.la libcmd_la_SOURCES= $(cmd_h_sources) $(cmd_cc_sources) -libcmd_la_CXXFLAGS = $(BOOST_CFLAGS) +libcmd_la_CXXFLAGS = $(BOOST_CFLAGS) $(SOCI_CFLAGS) libcmd_la_LIBADD = -libcmd_la_LDFLAGS = $(BOOST_LIBS) \ +libcmd_la_LDFLAGS = $(BOOST_LIBS) $(SOCI_LIBS) \ $(top_builddir)/simcrs/core/libsimcrs.la \ $(top_builddir)/trademgen/core/libtrademgen.la Modified: trunk/dsim/dsim/command/sources.mk =================================================================== --- trunk/dsim/dsim/command/sources.mk 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/dsim/command/sources.mk 2010-02-07 02:41:42 UTC (rev 62) @@ -1,6 +1,8 @@ cmd_h_sources = \ $(top_srcdir)/dsim/command/CmdAbstract.hpp \ + $(top_srcdir)/dsim/command/DBManager.hpp \ $(top_srcdir)/dsim/command/Simulator.hpp cmd_cc_sources = \ $(top_srcdir)/dsim/command/CmdAbstract.cpp \ + $(top_srcdir)/dsim/command/DBManager.cpp \ $(top_srcdir)/dsim/command/Simulator.cpp \ No newline at end of file Modified: trunk/dsim/dsim/service/DSIM_Service.cpp =================================================================== --- trunk/dsim/dsim/service/DSIM_Service.cpp 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/dsim/service/DSIM_Service.cpp 2010-02-07 02:41:42 UTC (rev 62) @@ -4,24 +4,29 @@ // STL #include <cassert> #include <ostream> +// SOCI +#include <soci/core/soci.h> // StdAir #include <stdair/basic/BasChronometer.hpp> #include <stdair/bom/BomManager.hpp> // for display() +#include <stdair/bom/BomRoot.hpp> +#include <stdair/bom/AirlineStruct.hpp> #include <stdair/bom/AirlineFeature.hpp> #include <stdair/bom/AirlineFeatureSet.hpp> -#include <stdair/bom/BomRoot.hpp> #include <stdair/factory/FacBomContent.hpp> #include <stdair/service/Logger.hpp> +#include <stdair/service/DBSessionManager.hpp> #include <stdair/STDAIR_Service.hpp> // Distribution #include <simcrs/SIMCRS_Service.hpp> -// TRADEMGEN +// TraDemGen #include <trademgen/TRADEMGEN_Service.hpp> #include <trademgen/DBParams.hpp> // Dsim #include <dsim/basic/BasConst_DSIM_Service.hpp> +#include <dsim/factory/FacDsimServiceContext.hpp> +#include <dsim/command/DBManager.hpp> #include <dsim/command/Simulator.hpp> -#include <dsim/factory/FacDsimServiceContext.hpp> #include <dsim/service/DSIM_ServiceContext.hpp> #include <dsim/DSIM_Service.hpp> @@ -38,31 +43,40 @@ } // ////////////////////////////////////////////////////////////////////// - DSIM_Service::DSIM_Service (const stdair::Filename_T& iScheduleInputFilename) + DSIM_Service::DSIM_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_ServicePtr, + const stdair::Filename_T& iScheduleInputFilename, + const stdair::Filename_T& iDemandInputFilename) : _dsimServiceContext (NULL) { // Initialise the service context initServiceContext (); + + // Retrieve the Trademgen service context + assert (_dsimServiceContext != NULL); + DSIM_ServiceContext& lDSIM_ServiceContext = *_dsimServiceContext; + + // Store the STDAIR service object within the (TRADEMGEN) service context + lDSIM_ServiceContext.setSTDAIR_Service (ioSTDAIR_ServicePtr); + // Initialise the context - //init (iScheduleInputFilename); - - assert (false); + init (iScheduleInputFilename, iDemandInputFilename); } // ////////////////////////////////////////////////////////////////////// DSIM_Service::DSIM_Service (const stdair::BasLogParams& iLogParams, - const stdair::Filename_T& iScheduleInputFilename) + const stdair::BasDBParams& iDBParams, + const stdair::Filename_T& iScheduleInputFilename, + const stdair::Filename_T& iDemandInputFilename) : _dsimServiceContext (NULL) { // Initialise the service context initServiceContext (); // Initialise the STDAIR service handler - stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = - initStdAirService (iLogParams); + initStdAirService (iLogParams, iDBParams); // Initialise the (remaining of the) context - init (lSTDAIR_Service_ptr, iScheduleInputFilename); + init (iScheduleInputFilename, iDemandInputFilename); } // ////////////////////////////////////////////////////////////////////// @@ -80,8 +94,8 @@ } // ////////////////////////////////////////////////////////////////////// - stdair::STDAIR_ServicePtr_T DSIM_Service:: - initStdAirService (const stdair::BasLogParams& iLogParams) { + void DSIM_Service::initStdAirService (const stdair::BasLogParams& iLogParams, + const stdair::BasDBParams& iDBParams) { // Retrieve the Dsim service context assert (_dsimServiceContext != NULL); @@ -90,13 +104,14 @@ // Initialise the STDAIR service handler // Note that the track on the object memory is kept thanks to the Boost // Smart Pointers component. - stdair::STDAIR_ServicePtr_T oSTDAIR_Service_ptr = - stdair::STDAIR_ServicePtr_T (new stdair::STDAIR_Service (iLogParams)); + stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = + stdair::STDAIR_ServicePtr_T (new stdair::STDAIR_Service (iLogParams, + iDBParams)); // Retrieve the root of the BOM tree, on which all of the other BOM objects // will be attached - assert (oSTDAIR_Service_ptr != NULL); - stdair::BomRoot& lBomRoot = oSTDAIR_Service_ptr->getBomRoot(); + assert (lSTDAIR_Service_ptr != NULL); + stdair::BomRoot& lBomRoot = lSTDAIR_Service_ptr->getBomRoot(); // TODO: do not hardcode the initialisation of AirlineFeatureSet // Initialise the set of required airline features @@ -116,16 +131,22 @@ // Set the AirlineFeatureSet for the BomRoot. lBomRoot.setAirlineFeatureSet (&lAirlineFeatureSet); - return oSTDAIR_Service_ptr; + // Store the STDAIR service object within the (TRADEMGEN) service context + lDSIM_ServiceContext.setSTDAIR_Service (lSTDAIR_Service_ptr); } // ////////////////////////////////////////////////////////////////////// - void DSIM_Service::init (stdair::STDAIR_ServicePtr_T ioSTDAIR_ServicePtr, - const stdair::Filename_T& iScheduleInputFilename) { + void DSIM_Service::init (const stdair::Filename_T& iScheduleInputFilename, + const stdair::Filename_T& iDemandInputFilename) { // Retrieve the service context assert (_dsimServiceContext != NULL); DSIM_ServiceContext& lDSIM_ServiceContext = *_dsimServiceContext; + // Retrieve the StdAir service context + stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = + lDSIM_ServiceContext.getSTDAIR_Service(); + assert (lSTDAIR_Service_ptr != NULL); + // TODO: do not hardcode the CRS code (e.g., take it from a // configuration file). // Initialise the SIMCRS service handler @@ -135,20 +156,17 @@ // on the Service object, and deletes that object when it is no longer // referenced (e.g., at the end of the process). SIMCRS_ServicePtr_T lSIMCRS_Service = - SIMCRS_ServicePtr_T (new SIMCRS::SIMCRS_Service (ioSTDAIR_ServicePtr, + SIMCRS_ServicePtr_T (new SIMCRS::SIMCRS_Service (lSTDAIR_Service_ptr, lCRSCode, iScheduleInputFilename)); lDSIM_ServiceContext.setSIMCRS_Service (lSIMCRS_Service); - // TODO: do not hardcode the stdair::BasDBParams. // TODO: do not hardcode the demand input file. // Initialise the TRADEMGEN service handler - const stdair::Filename_T lDemandInputFilename ("../../test/samples/demand01.csv"); - const stdair::BasDBParams lDBParams = - stdair::BasDBParams ("dsim", "dsim", "localhost", "3306", "dsim"); TRADEMGEN_ServicePtr_T lTRADEMGEN_Service = - TRADEMGEN_ServicePtr_T (new TRADEMGEN::TRADEMGEN_Service (ioSTDAIR_ServicePtr, - lDemandInputFilename)); + TRADEMGEN_ServicePtr_T (new TRADEMGEN:: + TRADEMGEN_Service (lSTDAIR_Service_ptr, + iDemandInputFilename)); lDSIM_ServiceContext.setTRADEMGEN_Service (lTRADEMGEN_Service); } @@ -191,4 +209,62 @@ } } + // ////////////////////////////////////////////////////////////////////// + void DSIM_Service::displayAirlineListFromDB () { + if (_dsimServiceContext == NULL) { + throw NonInitialisedServiceException(); + } + assert (_dsimServiceContext != NULL); + DSIM_ServiceContext& lDSIM_ServiceContext = *_dsimServiceContext; + + // Get the date-time for the present time + boost::posix_time::ptime lNowDateTime = + boost::posix_time::second_clock::local_time(); + boost::gregorian::date lNowDate = lNowDateTime.date(); + + // DEBUG + STDAIR_LOG_DEBUG (std::endl + << "===================================================" + << std::endl + << lNowDateTime); + + try { + + // Delegate the query execution to the dedicated command + stdair::BasChronometer lDsimChronometer; + lDsimChronometer.start(); + + // Retrieve the database session handler + stdair::DBSession_T& lDBSession = + stdair::DBSessionManager::instance().getDBSession(); + + // Prepare and execute the select statement + stdair::AirlineStruct lAirline; + stdair::DBRequestStatement_T lSelectStatement (lDBSession); + DBManager::prepareSelectStatement(lDBSession, lSelectStatement, lAirline); + + // Prepare the SQL request corresponding to the select statement + bool hasStillData = true; + unsigned int idx = 0; + while (hasStillData == true) { + hasStillData = DBManager::iterateOnStatement (lSelectStatement, + lAirline); + // DEBUG + STDAIR_LOG_DEBUG ("[" << idx << "]: " << lAirline); + + // Iteration + ++idx; + } + + const double lDsimMeasure = lDsimChronometer.elapsed(); + + // DEBUG + STDAIR_LOG_DEBUG ("Sample service for Dsim: " << lDsimMeasure); + + } catch (const std::exception& error) { + STDAIR_LOG_ERROR ("Exception: " << error.what()); + throw SimulationException(); + } + } + } Modified: trunk/dsim/dsim/service/DSIM_ServiceContext.hpp =================================================================== --- trunk/dsim/dsim/service/DSIM_ServiceContext.hpp 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/dsim/service/DSIM_ServiceContext.hpp 2010-02-07 02:41:42 UTC (rev 62) @@ -8,6 +8,8 @@ #include <string> // Boost #include <boost/shared_ptr.hpp> +// StdAir +#include <stdair/STDAIR_Types.hpp> // Dsim #include <dsim/DSIM_Types.hpp> #include <dsim/bom/ConfigurationParameters.hpp> @@ -36,6 +38,11 @@ friend class FacDsimServiceContext; public: // ///////// Getters ////////// + /** Get the pointer on the STDAIR service handler. */ + stdair::STDAIR_ServicePtr_T getSTDAIR_Service () const { + return _stdairService; + } + /** Get the simulator ID. */ const SimulatorID_T& getSimulatorID () const { return _simulatorID; @@ -62,6 +69,11 @@ } // ///////// Setters ////////// + /** Set the pointer on the STDAIR service handler. */ + void setSTDAIR_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_ServicePtr) { + _stdairService = ioSTDAIR_ServicePtr; + } + /** Set the simulator ID. */ void setSimulatorID (const SimulatorID_T& iSimulatorID) { _simulatorID = iSimulatorID; @@ -106,6 +118,8 @@ private: // ///////////// Children //////////// + /** Standard Airline (StdAir) Service Handler. */ + stdair::STDAIR_ServicePtr_T _stdairService; /** CRS Service Handler. */ SIMCRS_ServicePtr_T _simcrsService; /** TRADEMGEN Service Handler. */ Property changes on: trunk/dsim/test/dsim ___________________________________________________________________ Modified: svn:ignore - .deps .libs Makefile.in Makefile simulate simulate.log + .deps .libs Makefile.in Makefile simulate simulate.log SimulationTestSuite SimulationTestSuite_results.xml Modified: trunk/dsim/test/dsim/Makefile.am =================================================================== --- trunk/dsim/test/dsim/Makefile.am 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/test/dsim/Makefile.am 2010-02-07 02:41:42 UTC (rev 62) @@ -1,4 +1,4 @@ -## test sub-directory +## test/dsim sub-directory include $(top_srcdir)/Makefile.common MAINTAINERCLEANFILES = Makefile.in @@ -9,20 +9,19 @@ EXTRA_DIST = ## -check_PROGRAMS = simulate +check_PROGRAMS = SimulationTestSuite TESTS = $(check_PROGRAMS) XFAIL_TESTS = # -#SimulationTestSuite_SOURCES = SimulationTestSuite.hpp \ - SimulationTestSuite.cpp -#SimulationTestSuite_CXXFLAGS= $(CPPUNIT_CFLAGS) $(BOOST_CFLAGS) -#SimulationTestSuite_LDADD = $(top_builddir)/test/com/libcppunitcore.la -#SimulationTestSuite_LDFLAGS = \ -# $(BOOST_LIBS) $(CPPUNIT_LIBS) \ -# $(top_builddir)/dsim/libdsim.la - -simulate_SOURCES = simulate.cpp -simulate_CXXFLAGS= $(CPPUNIT_CFLAGS) $(BOOST_CFLAGS) -simulate_LDADD = -simulate_LDFLAGS = $(BOOST_LIBS) \ +SimulationTestSuite_SOURCES = SimulationTestSuite.hpp SimulationTestSuite.cpp +SimulationTestSuite_CXXFLAGS= $(CPPUNIT_CFLAGS) $(BOOST_CFLAGS) +SimulationTestSuite_LDADD = +SimulationTestSuite_LDFLAGS = \ + $(BOOST_LIBS) $(CPPUNIT_LIBS) \ + $(top_builddir)/extracppunit/libextracc-extracppunit.la \ $(top_builddir)/dsim/core/libdsim.la + +#simulate_SOURCES = simulate.cpp +#simulate_CXXFLAGS= $(CPPUNIT_CFLAGS) $(BOOST_CFLAGS) +#simulate_LDADD = +#simulate_LDFLAGS = $(BOOST_LIBS) $(top_builddir)/dsim/core/libdsim.la Added: trunk/dsim/test/dsim/SimulationTestSuite.cpp =================================================================== --- trunk/dsim/test/dsim/SimulationTestSuite.cpp (rev 0) +++ trunk/dsim/test/dsim/SimulationTestSuite.cpp 2010-02-07 02:41:42 UTC (rev 62) @@ -0,0 +1,83 @@ +// STL +#include <sstream> +#include <fstream> +#include <string> +// CPPUNIT +#include <extracppunit/CppUnitCore.hpp> +// StdAir +#include <stdair/basic/BasLogParams.hpp> +#include <stdair/basic/BasDBParams.hpp> +// Dsim +#include <dsim/DSIM_Types.hpp> +#include <dsim/DSIM_Service.hpp> +// Dsim Test Suite +#include <test/dsim/SimulationTestSuite.hpp> + +// ////////////////////////////////////////////////////////////////////// +// Test is based on ... +// ////////////////////////////////////////////////////////////////////// + +// ////////////////////////////////////////////////////////////////////// +void SimulationTestSuite::simpleSimulationHelper() { + + try { + + // Schedule input file name + const std::string lScheduleInputFilename ("../samples/schedule01.csv"); + + // Demand input file name + const stdair::Filename_T lDemandInputFilename ("../samples/demand01.csv"); + + // Output log File + const std::string lLogFilename ("simulate.log"); + + // Set the log parameters + std::ofstream logOutputFile; + // Open and clean the log outputfile + logOutputFile.open (lLogFilename.c_str()); + logOutputFile.clear(); + + // Initialise the simulation context + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + const stdair::BasDBParams lDBParams ("dsim", "dsim", "localhost", "3306", + "dsim"); + DSIM::DSIM_Service dsimService (lLogParams, lDBParams, + lScheduleInputFilename, + lDemandInputFilename); + + // Perform a simulation + dsimService.simulate(); + + } catch (const DSIM::RootException& otexp) { + std::cerr << "Standard exception: " << otexp.what() << std::endl; + return; + + } catch (const std::exception& stde) { + std::cerr << "Standard exception: " << stde.what() << std::endl; + return; + + } catch (...) { + return; + } + +} + +// ////////////////////////////////////////////////////////////////////// +void SimulationTestSuite::simpleSimulation () { + // TODO: Check that the simulation goes as expected + CPPUNIT_ASSERT_NO_THROW ( simpleSimulationHelper();); +} + +// ////////////////////////////////////////////////////////////////////// +// void SimulationTestSuite::errorCase () { +// CPPUNIT_ASSERT (false); +// } + +// ////////////////////////////////////////////////////////////////////// +SimulationTestSuite::SimulationTestSuite () { + _describeKey << "Running test on simulation"; +} + +// /////////////// M A I N ///////////////// +CPPUNIT_MAIN() + Added: trunk/dsim/test/dsim/SimulationTestSuite.hpp =================================================================== --- trunk/dsim/test/dsim/SimulationTestSuite.hpp (rev 0) +++ trunk/dsim/test/dsim/SimulationTestSuite.hpp 2010-02-07 02:41:42 UTC (rev 62) @@ -0,0 +1,31 @@ +// STL +#include <iosfwd> +// CPPUNIT +#include <cppunit/extensions/HelperMacros.h> + +/** Utility class for CPPUnit-based testing. */ +class SimulationTestSuite : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE (SimulationTestSuite); + CPPUNIT_TEST (simpleSimulation); + // CPPUNIT_TEST (errorCase); + CPPUNIT_TEST_SUITE_END (); +public: + + /** Test a simple simulation functionality. */ + void simpleSimulation(); + + /** Test some error detection functionalities. */ + // void errorCase (); + + /** Constructor. */ + SimulationTestSuite (); + +private: + /** Test a simple simulation functionality. */ + void simpleSimulationHelper(); + +protected: + std::stringstream _describeKey; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION (SimulationTestSuite); Modified: trunk/dsim/test/dsim/simulate.cpp =================================================================== --- trunk/dsim/test/dsim/simulate.cpp 2010-02-06 17:58:43 UTC (rev 61) +++ trunk/dsim/test/dsim/simulate.cpp 2010-02-07 02:41:42 UTC (rev 62) @@ -4,6 +4,10 @@ #include <sstream> #include <fstream> #include <string> +// StdAir +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/BasLogParams.hpp> +#include <stdair/basic/BasDBParams.hpp> // DSIM #include <dsim/DSIM_Service.hpp> #include <dsim/config/dsim-paths.hpp> @@ -11,11 +15,16 @@ // ///////// M A I N //////////// int main (int argc, char* argv[]) { + try { + // Schedule input file name - std::string lScheduleInputFilename ("../samples/schedule01.csv"); + const std::string lScheduleInputFilename ("../samples/schedule01.csv"); + // Demand input file name + const stdair::Filename_T lDemandInputFilename ("../samples/demand01.csv"); + // Output log File - std::string lLogFilename ("simulate.log"); + const std::string lLogFilename ("simulate.log"); // Set the log parameters std::ofstream logOutputFile; @@ -23,13 +32,29 @@ logOutputFile.open (lLogFilename.c_str()); logOutputFile.clear(); - // Initialise the list of classes/buckets + // Initialise the simulation context const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); - DSIM::DSIM_Service dsimService (lLogParams, lScheduleInputFilename); + const stdair::BasDBParams lDBParams ("dsim", "dsim", "localhost", "3306", + "dsim"); + DSIM::DSIM_Service dsimService (lLogParams, lDBParams, + lScheduleInputFilename, + lDemandInputFilename); // Perform a simulation dsimService.simulate(); + } catch (const DSIM::RootException& otexp) { + std::cerr << "Standard exception: " << otexp.what() << std::endl; + return -1; + + } catch (const std::exception& stde) { + std::cerr << "Standard exception: " << stde.what() << std::endl; + return -1; + + } catch (...) { + return -1; + } + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |