00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00070 if (! inputFile)
00071 throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
00072
00073 getline(inputFile, buffer, '\n');
00074 N = atoi(buffer.data());
00075
00076 getline(inputFile, buffer, '\n');
00077 M = atoi(buffer.data());
00078
00079 getline(inputFile, buffer, '\n');
00080
00081 p = std::vector< std::vector<unsigned int> > (M,N);
00082 d = std::vector<unsigned int> (N);
00083
00084 for (unsigned int j=0 ; j<N ; j++) {
00085
00086 getline(inputFile, buffer, '\n');
00087
00088 getline(inputFile, buffer, '\n');
00089 d[j] = atoi(buffer.data());
00090
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
00100 inputFile.close();
00101 }