00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <FlowShopEval.h>
00014
00015
00016 FlowShopEval::FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector<unsigned int> > & _p, const std::vector<unsigned int> & _d) :
00017 M(_M), N (_N), p(_p), d(_d)
00018 {}
00019
00020
00021 void FlowShopEval::operator()(FlowShop & _flowshop)
00022 {
00023 FlowShopObjectiveVector objVector;
00024 objVector[0] = makespan(_flowshop);
00025 objVector[1] = tardiness(_flowshop);
00026 _flowshop.objectiveVector(objVector);
00027 }
00028
00029
00030
00031 double FlowShopEval::makespan(const FlowShop & _flowshop)
00032 {
00033
00034
00035 std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
00036 return C[M-1][_flowshop[N-1]];
00037 }
00038
00039
00040 double FlowShopEval::tardiness(const FlowShop & _flowshop)
00041 {
00042
00043
00044 std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
00045
00046 unsigned int long sum = 0;
00047 for (unsigned int j=0 ; j<N ; j++)
00048 sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
00049 return sum;
00050 }
00051
00052
00053 std::vector< std::vector<unsigned int> > FlowShopEval::completionTime(const FlowShop & _flowshop) {
00054 std::vector< std::vector<unsigned int> > C(M,N);
00055 C[0][_flowshop[0]] = p[0][_flowshop[0]];
00056 for (unsigned int j=1; j<N; j++)
00057 C[0][_flowshop[j]] = C[0][_flowshop[j-1]] + p[0][_flowshop[j]];
00058 for (unsigned int i=1; i<M; i++)
00059 C[i][_flowshop[0]] = C[i-1][_flowshop[0]] + p[i][_flowshop[0]];
00060 for (unsigned int i=1; i<M; i++)
00061 for (unsigned int j=1; j<N; j++)
00062 C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
00063 return C;
00064 }