00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdexcept>
00039 #include <FlowShopBenchmarkParser.h>
00040
00041 FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName)
00042 {
00043 init(_benchmarkFileName);
00044 }
00045
00046
00047 const unsigned int FlowShopBenchmarkParser::getM()
00048 {
00049 return M;
00050 }
00051
00052
00053 const unsigned int FlowShopBenchmarkParser::getN()
00054 {
00055 return N;
00056 }
00057
00058
00059 const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP()
00060 {
00061 return p;
00062 }
00063
00064
00065 const std::vector<unsigned int> FlowShopBenchmarkParser::getD()
00066 {
00067 return d;
00068 }
00069
00070
00071 void FlowShopBenchmarkParser::printOn(std::ostream & _os) const
00072 {
00073 _os << "M=" << M << " N=" << N << std::endl;
00074 _os << "*** processing times" << std::endl;
00075 for (unsigned int i=0; i<M; i++)
00076 {
00077 for (unsigned int j=0; j<N; j++)
00078 {
00079 _os << p[i][j] << " ";
00080 }
00081 _os << std::endl;
00082 }
00083 _os << "*** due-dates" << std::endl;
00084 for (unsigned int j=0; j<N; j++)
00085 {
00086 _os << d[j] << " ";
00087 }
00088 _os << std::endl << std::endl;
00089 }
00090
00091
00092 void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName)
00093 {
00094 std::string buffer;
00095 std::string::size_type start, end;
00096 std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
00097
00098 if (! inputFile)
00099 throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
00100
00101 getline(inputFile, buffer, '\n');
00102 N = atoi(buffer.data());
00103
00104 getline(inputFile, buffer, '\n');
00105 M = atoi(buffer.data());
00106
00107 getline(inputFile, buffer, '\n');
00108
00109 p = std::vector< std::vector<unsigned int> > (M,N);
00110 d = std::vector<unsigned int> (N);
00111
00112 for (unsigned int j=0 ; j<N ; j++)
00113 {
00114
00115 getline(inputFile, buffer, '\n');
00116
00117 getline(inputFile, buffer, '\n');
00118 d[j] = atoi(buffer.data());
00119
00120 getline(inputFile, buffer, '\n');
00121 start = buffer.find_first_not_of(" ");
00122 for (unsigned int i=0 ; i<M ; i++)
00123 {
00124 end = buffer.find_first_of(" ", start);
00125 p[i][j] = atoi(buffer.substr(start, end-start).data());
00126 start = buffer.find_first_not_of(" ", end);
00127 }
00128 }
00129
00130 inputFile.close();
00131 }