GCC 4.3 compatible

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1240 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2008-09-24 15:04:01 +00:00
commit ea6fce84f2
2 changed files with 81 additions and 80 deletions

View file

@ -34,100 +34,103 @@
* *
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <iostream>
#include <stdexcept> #include <stdexcept>
#include <FlowShopBenchmarkParser.h> #include <FlowShopBenchmarkParser.h>
FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName) FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName)
{ {
init(_benchmarkFileName); init(_benchmarkFileName);
} }
const unsigned int FlowShopBenchmarkParser::getM() const unsigned int FlowShopBenchmarkParser::getM()
{ {
return M; return M;
} }
const unsigned int FlowShopBenchmarkParser::getN() const unsigned int FlowShopBenchmarkParser::getN()
{ {
return N; return N;
} }
const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP() const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP()
{ {
return p; return p;
} }
const std::vector<unsigned int> FlowShopBenchmarkParser::getD() const std::vector<unsigned int> FlowShopBenchmarkParser::getD()
{ {
return d; return d;
} }
void FlowShopBenchmarkParser::printOn(std::ostream & _os) const void FlowShopBenchmarkParser::printOn(std::ostream & _os) const
{ {
_os << "M=" << M << " N=" << N << std::endl; _os << "M=" << M << " N=" << N << std::endl;
_os << "*** processing times" << std::endl; _os << "*** processing times" << std::endl;
for (unsigned int i=0; i<M; i++) for (unsigned int i=0; i<M; i++)
{ {
for (unsigned int j=0; j<N; j++) for (unsigned int j=0; j<N; j++)
{ {
_os << p[i][j] << " "; _os << p[i][j] << " ";
} }
_os << std::endl; _os << std::endl;
} }
_os << "*** due-dates" << std::endl; _os << "*** due-dates" << std::endl;
for (unsigned int j=0; j<N; j++) for (unsigned int j=0; j<N; j++)
{ {
_os << d[j] << " "; _os << d[j] << " ";
} }
_os << std::endl << std::endl; _os << std::endl << std::endl;
} }
void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName) void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName)
{ {
std::string buffer; std::string buffer;
std::string::size_type start, end; std::string::size_type start, end;
std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in); std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
// opening of the benchmark file // opening of the benchmark file
if (! inputFile) if (! inputFile)
throw std::runtime_error("*** ERROR : Unable to open the benchmark file"); throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
// number of jobs (N) // number of jobs (N)
getline(inputFile, buffer, '\n'); getline(inputFile, buffer, '\n');
N = atoi(buffer.data()); N = atoi(buffer.data());
// number of machines M // number of machines M
getline(inputFile, buffer, '\n'); getline(inputFile, buffer, '\n');
M = atoi(buffer.data()); M = atoi(buffer.data());
// initial and current seeds (not used) // initial and current seeds (not used)
getline(inputFile, buffer, '\n'); getline(inputFile, buffer, '\n');
// processing times and due-dates // processing times and due-dates
//p = std::vector< std::vector<unsigned int> > (M,N); // p = std::vector< std::vector<unsigned int> > (M,N);
p.resize(N); p.resize(M);
d = std::vector<unsigned int> (N); for (unsigned int j=0 ; j<M ; j++)
// for each job...
for (unsigned int j=0 ; j<N ; j++)
{ {
// index of the job (<=> j) p[j].resize(N);
getline(inputFile, buffer, '\n'); }
// due-date of the job j d = std::vector<unsigned int> (N);
getline(inputFile, buffer, '\n'); // for each job...
d[j] = atoi(buffer.data()); for (unsigned int j=0 ; j<N ; j++)
// processing times of the job j on each machine {
getline(inputFile, buffer, '\n'); // index of the job (<=> j)
start = buffer.find_first_not_of(" "); getline(inputFile, buffer, '\n');
p[j].resize(M); // due-date of the job j
for (unsigned int i=0 ; i<M ; i++) getline(inputFile, buffer, '\n');
d[j] = atoi(buffer.data());
// processing times of the job j on each machine
getline(inputFile, buffer, '\n');
start = buffer.find_first_not_of(" ");
for (unsigned int i=0 ; i<M ; i++)
{ {
end = buffer.find_first_of(" ", start); end = buffer.find_first_of(" ", start);
p[i][j] = atoi(buffer.substr(start, end-start).data()); p[i][j] = atoi(buffer.substr(start, end-start).data());
start = buffer.find_first_not_of(" ", end); start = buffer.find_first_not_of(" ", end);
} }
} }
// closing of the input file // closing of the input file
inputFile.close(); inputFile.close();
} }

View file

@ -39,59 +39,57 @@
FlowShopEval::FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector<unsigned int> > & _p, const std::vector<unsigned int> & _d) : FlowShopEval::FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector<unsigned int> > & _p, const std::vector<unsigned int> & _d) :
M(_M), N (_N), p(_p), d(_d) M(_M), N (_N), p(_p), d(_d)
{} {}
void FlowShopEval::operator()(FlowShop & _flowshop) void FlowShopEval::operator()(FlowShop & _flowshop)
{ {
FlowShopObjectiveVector objVector; FlowShopObjectiveVector objVector;
objVector[0] = makespan(_flowshop); objVector[0] = makespan(_flowshop);
objVector[1] = tardiness(_flowshop); objVector[1] = tardiness(_flowshop);
_flowshop.objectiveVector(objVector); _flowshop.objectiveVector(objVector);
} }
double FlowShopEval::makespan(const FlowShop & _flowshop) double FlowShopEval::makespan(const FlowShop & _flowshop)
{ {
// completion times computation for each job on each machine // completion times computation for each job on each machine
// C[i][j] = completion of the jth job of the scheduling on the ith machine // C[i][j] = completion of the jth job of the scheduling on the ith machine
std::vector< std::vector<unsigned int> > C = completionTime(_flowshop); std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
return C[M-1][_flowshop[N-1]]; return C[M-1][_flowshop[N-1]];
} }
double FlowShopEval::tardiness(const FlowShop & _flowshop) double FlowShopEval::tardiness(const FlowShop & _flowshop)
{ {
// completion times computation for each job on each machine // completion times computation for each job on each machine
// C[i][j] = completion of the jth job of the scheduling on the ith machine // C[i][j] = completion of the jth job of the scheduling on the ith machine
std::vector< std::vector<unsigned int> > C = completionTime(_flowshop); std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
// tardiness computation // tardiness computation
unsigned int long sum = 0; unsigned int long sum = 0;
for (unsigned int j=0 ; j<N ; j++) for (unsigned int j=0 ; j<N ; j++)
sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]])); sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
return sum; return sum;
} }
std::vector< std::vector<unsigned int> > FlowShopEval::completionTime(const FlowShop & _flowshop) std::vector< std::vector<unsigned int> > FlowShopEval::completionTime(const FlowShop & _flowshop)
{ {
//std::vector< std::vector<unsigned int> > C(M,N); std::vector< std::vector<unsigned int> > C;
std::vector< std::vector<unsigned int> > C; C.resize(M);
C.resize(M); for (unsigned int i=0;i<M;i++)
for(unsigned int i=0;i<N;i++)
{ {
C[i].resize(N); C[i].resize(N);
} }
C[0][_flowshop[0]] = p[0][_flowshop[0]];
C[0][_flowshop[0]] = p[0][_flowshop[0]];
for (unsigned int j=1; j<N; j++)
C[0][_flowshop[j]] = C[0][_flowshop[j-1]] + p[0][_flowshop[j]];
for (unsigned int i=1; i<M; i++)
C[i][_flowshop[0]] = C[i-1][_flowshop[0]] + p[i][_flowshop[0]];
for (unsigned int i=1; i<M; i++)
for (unsigned int j=1; j<N; j++) for (unsigned int j=1; j<N; j++)
C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]]; C[0][_flowshop[j]] = C[0][_flowshop[j-1]] + p[0][_flowshop[j]];
return C; for (unsigned int i=1; i<M; i++)
C[i][_flowshop[0]] = C[i-1][_flowshop[0]] + p[i][_flowshop[0]];
for (unsigned int i=1; i<M; i++)
for (unsigned int j=1; j<N; j++)
C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
return C;
} }