RMOL Logo Get Revenue Management Optimisation Library at SourceForge.net. Fast, secure and Free Open Source software downloads

rmol.cpp

Go to the documentation of this file.
00001 // STL
00002 #include <iostream>
00003 #include <sstream>
00004 #include <fstream>
00005 // RMOL
00006 #include <rmol/RMOL_Service.hpp>
00007 
00008 
00009 // ///////// M A I N ////////////
00010 int main (int argc, char* argv[]) {
00011   try {
00012     
00013     // Output log File
00014     std::string lLogFilename ("rmol.log");
00015     
00016     // Number of random draws to be generated (best if greater than 100)
00017     int K = 100000;
00018     
00019     // Methods of optimisation (0 = Monte-Carlo, 1 = Dynamic Programming, 
00020     // 2 = EMSR, 3 = EMSR-a, 4 = EMSR-b)
00021     short METHOD_FLAG = 0;
00022     
00023     // Cabin Capacity (it must be greater then 100 here)
00024     double cabinCapacity = 500.0;
00025     
00026     // Input file name
00027     std::string inputFileName ("class.csv");
00028     bool hasInputFile = false;
00029     
00030     if (argc >= 1 && argv[1] != NULL) {
00031       std::istringstream istr (argv[1]);
00032       istr >> lLogFilename;
00033     }
00034     
00035     if (argc >= 2 && argv[2] != NULL) {
00036       std::istringstream istr (argv[2]);
00037       istr >> K;
00038     }
00039     
00040     if (argc >= 3 && argv[3] != NULL) {
00041       std::istringstream istr (argv[3]);
00042       istr >> cabinCapacity;
00043     }
00044     
00045     if (argc >= 4 && argv[4] != NULL) {
00046       std::istringstream istr (argv[4]);
00047       istr >> inputFileName;
00048       hasInputFile = true;
00049     }
00050     
00051     if (argc >= 5 && argv[5] != NULL) {
00052       std::istringstream istr (argv[5]);
00053       istr >> METHOD_FLAG;
00054     }
00055     
00056     // Set the log parameters
00057     std::ofstream logOutputFile;
00058     // open and clean the log outputfile
00059     logOutputFile.open (lLogFilename.c_str());
00060     logOutputFile.clear();
00061     
00062     // Initialise the list of classes/buckets
00063     RMOL::RMOL_Service rmolService (logOutputFile, cabinCapacity);
00064     
00065     if (hasInputFile) {
00066       // Read the input file
00067       rmolService.readFromInputFile (inputFileName);
00068       
00069     } else {
00070       // No input file has been provided. So, process a sample.
00071       
00072       // STEP 0.
00073       // List of demand distribution parameters (mean and standard deviation)
00074       
00075       // Class/bucket 1: N (20, 9), p1 = 100
00076       rmolService.addBucket (100.0, 20, 9);
00077       
00078       // Class/bucket 2: N (45, 12), p2 = 70
00079       rmolService.addBucket (70.0, 45, 12);
00080       
00081       // Class/bucket 3: no need to define a demand distribution, p3 = 42
00082       rmolService.addBucket (42.0, 0, 0);
00083     }
00084     
00085     switch (METHOD_FLAG) {
00086 
00087     case 0 : // Calculate the optimal protections by the Monte Carlo
00088              // Integration approach
00089       rmolService.optimalOptimisationByMCIntegration (K);
00090       break;
00091 
00092     case 1 : // Calculate the optimal protections by DP.
00093       rmolService.optimalOptimisationByDP ();
00094       break;
00095       
00096     case 2 : // Calculate the Bid-Price Vector by EMSR
00097       rmolService.heuristicOptimisationByEmsr ();
00098       break;
00099 
00100     case 3 : // Calculate the protections by EMSR-a
00101       rmolService.heuristicOptimisationByEmsrA ();
00102       break;
00103       
00104     case 4 : // Calculate the protections by EMSR-b
00105       rmolService.heuristicOptimisationByEmsrB ();
00106       break;
00107 
00108     default : rmolService.optimalOptimisationByMCIntegration (K);
00109     }
00110     
00111   } catch (const std::exception& stde) {
00112     std::cerr << "Standard exception: " << stde.what() << std::endl;
00113     return -1;
00114     
00115   } catch (...) {
00116     return -1;
00117   }
00118   
00119   return 0;     
00120 }
SourceForge Logo

Generated on Fri Sep 11 06:32:00 2009 for RMOL by Doxygen 1.5.8