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 <FlowShopBenchmarkParser.h>
FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName)
{
init(_benchmarkFileName);
init(_benchmarkFileName);
}
const unsigned int FlowShopBenchmarkParser::getM()
{
return M;
return M;
}
const unsigned int FlowShopBenchmarkParser::getN()
{
return N;
return N;
}
const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP()
{
return p;
return p;
}
const std::vector<unsigned int> FlowShopBenchmarkParser::getD()
{
return d;
return d;
}
void FlowShopBenchmarkParser::printOn(std::ostream & _os) const
{
{
_os << "M=" << M << " N=" << N << std::endl;
_os << "*** processing times" << std::endl;
for (unsigned int i=0; i<M; i++)
{
{
for (unsigned int j=0; j<N; j++)
{
{
_os << p[i][j] << " ";
}
}
_os << std::endl;
}
}
_os << "*** due-dates" << std::endl;
for (unsigned int j=0; j<N; j++)
{
{
_os << d[j] << " ";
}
}
_os << std::endl << std::endl;
}
}
void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName)
{
std::string buffer;
std::string::size_type start, end;
std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
// opening of the benchmark file
if (! inputFile)
throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
// number of jobs (N)
getline(inputFile, buffer, '\n');
N = atoi(buffer.data());
// number of machines M
getline(inputFile, buffer, '\n');
M = atoi(buffer.data());
// initial and current seeds (not used)
getline(inputFile, buffer, '\n');
// processing times and due-dates
//p = std::vector< std::vector<unsigned int> > (M,N);
p.resize(N);
d = std::vector<unsigned int> (N);
// for each job...
for (unsigned int j=0 ; j<N ; j++)
std::string buffer;
std::string::size_type start, end;
std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
// opening of the benchmark file
if (! inputFile)
throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
// number of jobs (N)
getline(inputFile, buffer, '\n');
N = atoi(buffer.data());
// number of machines M
getline(inputFile, buffer, '\n');
M = atoi(buffer.data());
// initial and current seeds (not used)
getline(inputFile, buffer, '\n');
// processing times and due-dates
// p = std::vector< std::vector<unsigned int> > (M,N);
p.resize(M);
for (unsigned int j=0 ; j<M ; j++)
{
// index of the job (<=> j)
getline(inputFile, buffer, '\n');
// due-date of the job j
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(" ");
p[j].resize(M);
for (unsigned int i=0 ; i<M ; i++)
p[j].resize(N);
}
d = std::vector<unsigned int> (N);
// for each job...
for (unsigned int j=0 ; j<N ; j++)
{
// index of the job (<=> j)
getline(inputFile, buffer, '\n');
// due-date of the job j
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);
p[i][j] = atoi(buffer.substr(start, end-start).data());
start = buffer.find_first_not_of(" ", end);
end = buffer.find_first_of(" ", start);
p[i][j] = atoi(buffer.substr(start, end-start).data());
start = buffer.find_first_not_of(" ", end);
}
}
// closing of the input file
inputFile.close();
// closing of the input file
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) :
M(_M), N (_N), p(_p), d(_d)
M(_M), N (_N), p(_p), d(_d)
{}
void FlowShopEval::operator()(FlowShop & _flowshop)
{
FlowShopObjectiveVector objVector;
objVector[0] = makespan(_flowshop);
objVector[1] = tardiness(_flowshop);
_flowshop.objectiveVector(objVector);
FlowShopObjectiveVector objVector;
objVector[0] = makespan(_flowshop);
objVector[1] = tardiness(_flowshop);
_flowshop.objectiveVector(objVector);
}
double FlowShopEval::makespan(const FlowShop & _flowshop)
{
// completion times computation for each job on each 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);
return C[M-1][_flowshop[N-1]];
// completion times computation for each job on each 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);
return C[M-1][_flowshop[N-1]];
}
double FlowShopEval::tardiness(const FlowShop & _flowshop)
{
// completion times computation for each job on each 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);
// tardiness computation
unsigned int long sum = 0;
for (unsigned int j=0 ; j<N ; j++)
sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
return sum;
// completion times computation for each job on each 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);
// tardiness computation
unsigned int long sum = 0;
for (unsigned int j=0 ; j<N ; j++)
sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
return sum;
}
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;
C.resize(M);
for(unsigned int i=0;i<N;i++)
std::vector< std::vector<unsigned int> > C;
C.resize(M);
for (unsigned int i=0;i<M;i++)
{
C[i].resize(N);
C[i].resize(N);
}
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++)
C[0][_flowshop[0]] = p[0][_flowshop[0]];
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;
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++)
C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
return C;
}