FlowShopBenchmarkParser.cpp

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // FlowShopBenchmarkParser.cpp
00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
00006 /*
00007     This library...
00008 
00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
00010  */
00011 //-----------------------------------------------------------------------------
00012 
00013 #include <stdexcept>
00014 #include <FlowShopBenchmarkParser.h>
00015 
00016 FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName)
00017 {
00018     init(_benchmarkFileName);
00019 }
00020 
00021 
00022 const unsigned int FlowShopBenchmarkParser::getM()
00023 {
00024     return M;
00025 }
00026 
00027 
00028 const unsigned int FlowShopBenchmarkParser::getN()
00029 {
00030     return N;
00031 }
00032 
00033 
00034 const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP()
00035 {
00036     return p;
00037 }
00038 
00039 
00040 const std::vector<unsigned int> FlowShopBenchmarkParser::getD()
00041 {
00042     return d;
00043 }
00044 
00045 
00046 void FlowShopBenchmarkParser::printOn(std::ostream & _os) const
00047 {
00048     _os << "M=" << M << " N=" << N << std::endl;
00049     _os << "*** processing times" << std::endl;
00050     for (unsigned int i=0; i<M; i++) {
00051         for (unsigned int j=0; j<N; j++) {
00052             _os << p[i][j] << " ";
00053         }
00054         _os << std::endl;
00055     }
00056     _os << "*** due-dates" << std::endl;
00057     for (unsigned int j=0; j<N; j++) {
00058         _os << d[j] << " ";
00059     }
00060     _os << std::endl << std::endl;
00061 }
00062 
00063 
00064 void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName)
00065 {
00066     std::string buffer;
00067     std::string::size_type start, end;
00068     std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
00069     // opening of the benchmark file
00070     if (! inputFile)
00071         throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
00072     // number of jobs (N)
00073     getline(inputFile, buffer, '\n');
00074     N = atoi(buffer.data());
00075     // number of machines M
00076     getline(inputFile, buffer, '\n');
00077     M = atoi(buffer.data());
00078     // initial and current seeds (not used)
00079     getline(inputFile, buffer, '\n');
00080     // processing times and due-dates
00081     p = std::vector< std::vector<unsigned int> > (M,N);
00082     d = std::vector<unsigned int> (N);
00083     // for each job...
00084     for (unsigned int j=0 ; j<N ; j++) {
00085         // index of the job (<=> j)
00086         getline(inputFile, buffer, '\n');
00087         // due-date of the job j
00088         getline(inputFile, buffer, '\n');
00089         d[j] = atoi(buffer.data());
00090         // processing times of the job j on each machine
00091         getline(inputFile, buffer, '\n');
00092         start = buffer.find_first_not_of(" ");
00093         for (unsigned int i=0 ; i<M ; i++) {
00094             end = buffer.find_first_of(" ", start);
00095             p[i][j] = atoi(buffer.substr(start, end-start).data());
00096             start = buffer.find_first_not_of(" ", end);
00097         }
00098     }
00099     // closing of the input file
00100     inputFile.close();
00101 }

Generated on Mon Oct 8 10:35:51 2007 for ParadisEO-MOEOMovingObjects by  doxygen 1.4.7