24node Nodes[TOTAL_NODES];
27#define CHECKMSG(condition, text) \
28if(!(condition)) {fprintf(stderr,"file: " __FILE__ "\nline: %d\nmsg: " text "\n",__LINE__); exit(1);}
29#define CHECK(condition) \
30if(!(condition)) {fprintf(stderr,"Nesto ne valja!\nfile: " __FILE__ "\nline: %d\n" ,__LINE__); exit(1);}
32#define POS(x) (x>0 ? x : 0)
33#define MIN(x,y) (x<y ? x : y)
34#define MAX(x,y) (x>y ? x : y)
39int Before(
const void *arg1,
const void *arg2)
41 if(pVal[*(uint*)arg1] < pVal[*(uint*)arg2])
43 else if(pVal[*(uint*)arg1] > pVal[*(uint*)arg2])
50SchedulingEvalOp::SchedulingEvalOp()
52 for(
int i=0; i<TERMINALS+OFFSET; i++)
53 { Nodes[i].active =
false;
55 for(
int i=TERMINALS+OFFSET; i<TOTAL_NODES; i++)
56 { Nodes[i].active =
true;
59 Nodes[NUL].name =
"0";
61 Nodes[ONE].name =
"1";
63 Nodes[T_N].name =
"N";
64 Nodes[T_SP].name =
"SP";
65 Nodes[T_SD].name =
"SD";
66 Nodes[T_pt].name =
"pt";
67 Nodes[T_dd].name =
"dd";
68 Nodes[T_w].name =
"w";
69 Nodes[T_Nr].name =
"Nr";
70 Nodes[T_SPr].name =
"SPr";
71 Nodes[T_SL].name =
"SL";
72 Nodes[T_AR].name =
"AR";
73 Nodes[T_SC].name =
"SC";
74 Nodes[T_LVL].name =
"LVL";
75 Nodes[T_STP].name =
"STP";
76 Nodes[T_Sav].name =
"Sav";
77 Nodes[T_SLs].name =
"SLs";
78 Nodes[T_SPD].name =
"SPD";
79 Nodes[T_Msm].name =
"Msm";
80 Nodes[T_pmin].name =
"pmin";
81 Nodes[T_pavg].name =
"pavg";
82 Nodes[T_PAT].name =
"PAT";
83 Nodes[T_MR].name =
"MR";
84 Nodes[T_age].name =
"age";
85 Nodes[T_L].name =
"L";
86 Nodes[T_SLr].name =
"SLr";
87 Nodes[T_CLK].name =
"CLK";
88 Nodes[T_NOPr].name =
"NOPr";
89 Nodes[T_TWK].name =
"TWK";
90 Nodes[T_TWKr].name =
"TWKR";
91 Nodes[T_PTav].name =
"PTav";
92 Nodes[T_HTR].name =
"HTR";
93 Nodes[T_TF].name =
"TF";
95 Nodes[T_MNOPr].name =
"MNOPr";
96 Nodes[T_MNOPw].name =
"MNOPw";
97 Nodes[T_MTWK].name =
"MTWK";
98 Nodes[T_MTWKr].name =
"MTWKr";
99 Nodes[T_MTWKav].name =
"MTWKav";
100 Nodes[T_MUTL].name =
"MUTL";
103 Nodes[T_wc].name=
"wc";
104 Nodes[T_we].name=
"we";
107 Nodes[ADD].name =
"+";
108 Nodes[SUB].name =
"-";
109 Nodes[MUL].name =
"*";
110 Nodes[DIV].name =
"/";
111 Nodes[POS].name =
"pos";
112 Nodes[SQR].name =
"sqr";
113 Nodes[IFGT].name =
"ifgt";
120 m_Evaluation =
false;
127SchedulingEvalOp::~SchedulingEvalOp()
129 delete [] pRasporedjen;
130 delete [] pVrijednosti;
135 delete [] pSlackSpeed;
141 delete [] pMachineScheduled;
142 delete [] pOperationReady;
144 delete [] pOperationsScheduled;
145 delete [] pTotalWorkRemaining;
146 delete [] pTotalWorkDone;
147 delete [] pTotalMachineWork;
148 delete [] pMachineWorkRemaining;
149 delete [] pOperationsWaiting;
150 delete [] pMachineValues;
156 state->getRegistry()->registerEntry(
"test_cases", (voidP) (
new std::string), ECF::STRING);
157 state->getRegistry()->registerEntry(
"normalized", (voidP) (
new uint(1)), ECF::UINT);
158 state->getRegistry()->registerEntry(
"genotip", (voidP) (
new std::string), ECF::STRING);
159 state->getRegistry()->registerEntry(
"primjer", (voidP) (
new uint(0)), ECF::UINT);
169 std::string configFile;
172 if(!state->getRegistry()->isModified(
"test_cases"))
175 voidP sptr = state->getRegistry()->getEntry(
"test_cases");
176 configFile = *((std::string*) sptr.get());
177 in_file = configFile;
179 sptr = state->getRegistry()->getEntry(
"normalized");
180 m_Normalized = (bool) *((uint*) sptr.get());
182 sptr = state->getRegistry()->getEntry(
"genotip");
183 m_genotip = *((std::string*) sptr.get());
185 sptr = state->getRegistry()->getEntry(
"primjer");
186 m_primjer = (uint) *((uint*) sptr.get());
189 m_primjer = *((uint*) state->getContext()->environment);
192 if(m_genotip ==
"GP")
194 ReadTerminals(state);
196 m_primjer = *((uint*) state->getContext()->environment);
199 std::string input,sp,duration,deadline,weightT,weightF,weightE,weightN, weightC,term,ready,cons,speed;
203 double d_niz[2][1000];
221 p.OpenFile(input.c_str());
222 if(p.ReadParameter(
"single",ReadPar::INTEGER,&i))
223 m_Environment = SINGLE;
224 else if(p.ReadParameter(
"uniform",ReadPar::INTEGER,&i))
225 m_Environment = UNIFORM;
226 else if(p.ReadParameter(
"unrelated",ReadPar::INTEGER,&i))
227 m_Environment = UNRELATED;
228 else if(p.ReadParameter(
"jobshop",ReadPar::INTEGER,&i))
229 m_Environment = JOBSHOP;
230 p.ReadParameter(
"sets",ReadPar::INTEGER,&sets);
231 p.ReadParameter(
"max_jobs",ReadPar::INTEGER,&max_jobs);
232 if(!p.ReadParameter(
"max_machines",ReadPar::INTEGER,&max_machines))
234 p.ReadParameter(
"max_length",ReadPar::INTEGER,&max_length);
235 p.ReadParameter(
"duration",ReadPar::STRING,pom); duration = pom;
236 p.ReadParameter(
"deadline",ReadPar::STRING,pom); deadline = pom;
237 p.ReadParameter(
"weight_T",ReadPar::STRING,pom); weightT = pom;
238 p.ReadParameter(
"weight_F",ReadPar::STRING,pom); weightF = pom;
239 p.ReadParameter(
"weight_E",ReadPar::STRING,pom); weightE = pom;
240 p.ReadParameter(
"weight_N",ReadPar::STRING,pom); weightN = pom;
241 p.ReadParameter(
"weight_C",ReadPar::STRING,pom); weightC = pom;
242 p.ReadParameter(
"SP",ReadPar::STRING,pom); sp = pom;
243 p.ReadParameter(
"machine_file",ReadPar::STRING,pom); speed = pom;
245 if(p.ReadParameter(
"ready",ReadPar::STRING,pom))
252 if(p.ReadParameter(
"LEF",ReadPar::INTEGER,&i))
255 if(!p.ReadParameter(
"LEF_value",ReadPar::DOUBLE,&m_LEFVal))
256 CHECKMSG(0,
"LEF vrijednost nije zadana!");
260 if(p.ReadParameter(
"evaluation",ReadPar::INTEGER,&i))
261 if(i==1) m_Evaluation =
true;
263 if(p.ReadParameter(
"fitness",ReadPar::STRING,pom))
267 else if(input ==
"Nwt")
269 else if(input ==
"FTwt")
271 else if(input ==
"ETwt")
273 else if(input ==
"Cmax")
275 else if(input ==
"Fwt")
277 else if(input ==
"TwtCmax")
279 else if(input ==
"NwtCmax")
281 else if(input ==
"Mus")
283 else if(input ==
"Fmax")
285 else if(input==
"Tmax")
287 else if(input ==
"Cw"){
292 CHECKMSG(0,
"Nepoznata fitnes funkcija!");
294 else CHECKMSG(0,
"Nije definirana fitnes funkcija!");
296 if(p.ReadParameter(
"editing",ReadPar::INTEGER,&i))
297 if(i==1) m_editing =
true;
299 if(p.ReadParameter(
"stsampling",ReadPar::DOUBLE,&m_sampling))
302 m_stsampling =
false;
304 if(p.ReadParameter(
"constraints",ReadPar::STRING,pom))
306 m_constrained =
true;
309 m_constrained =
false;
311 if(p.ReadParameter(
"setup",ReadPar::DOUBLE,&m_setup_faktor))
316 p.ReadParameter(
"bestsubset",ReadPar::INTEGER,&m_BestSubset);
317 if(p.ReadParameter(
"idleness",ReadPar::INTEGER, &i))
318 if(i == 1) m_Idleness =
true;
324 MachineReady.Init(max_machines);
325 Speed.Init(sets,max_jobs);
326 Duration.Init(sets,max_jobs);
327 Deadline.Init(sets,max_jobs);
328 Durations.Init(max_jobs, max_machines);
329 MachineIndex.Init(max_jobs, max_machines);
330 WeightT.Init(sets,max_jobs);
331 WeightF.Init(sets,max_jobs);
332 WeightE.Init(sets,max_jobs);
333 WeightN.Init(sets,max_jobs);
334 WeightC.Init(sets,max_jobs);
335 Fitness.Init(sets+1,FUNCTIONS);
336 Values.Init(max_machines,max_jobs);
337 Precedence.Reset(max_jobs,max_jobs);
338 Setup.Init(max_jobs+1,max_jobs);
339 if(m_Environment == JOBSHOP)
340 { Schedule.Init(sets, max_machines*max_jobs);
341 PTimeAvg.Reset(sets, max_machines);
344 { Schedule.Init(sets,max_jobs);
345 PTimeAvg.Init(sets,max_jobs);
346 PTimeMinMachine.Init(sets,max_jobs);
348 SortedReady.Init(sets,max_jobs);
350 pVrijednosti =
new double[max_jobs];
351 pRasporedjen =
new bool[max_jobs];
352 pIndex =
new unsigned int[max_jobs];
353 pUsed =
new unsigned int[max_jobs];
354 pArray =
new double[max_jobs];
355 pSlack =
new double[max_jobs];
356 pSlackSpeed =
new double[max_jobs];
357 pArrival =
new double[max_jobs];
358 pLevel =
new double[max_jobs];
359 pSetupAvg =
new double[max_jobs + 1];
360 pSamples =
new bool[sets];
361 pLastJob =
new unsigned int[max_machines];
362 pMachineScheduled =
new unsigned int[max_machines];
363 pOperationReady =
new double[max_machines];
364 pJobReady =
new double[max_jobs];
365 pOperationsScheduled =
new unsigned int[max_jobs];
366 pTotalWorkRemaining =
new double[max_jobs];
367 pTotalWorkDone =
new double[max_jobs];
368 pTotalMachineWork =
new double[max_machines];
369 pOperationsWaiting =
new unsigned int[max_machines];
370 pMachineWorkRemaining =
new double[max_machines];
371 pMachineValues =
new double[max_machines];
372 p.ReadParameter(
"jobs",ReadPar::DOUBLE,&d_niz[0][0],sets);
373 p.ReadParameter(
"machines",ReadPar::DOUBLE,&d_niz[1][0],sets);
375 for(i=0; i<sets; i++)
376 { N[i][0] = d_niz[0][i];
377 total_jobs += (int) d_niz[0][i];
378 Machines[i][0] = d_niz[1][i];
380 Duration.Load(duration.c_str());
381 Deadline.Load(deadline.c_str());
382 if(m_Environment==UNIFORM)
383 { Speed.Load(speed.c_str());
385 WeightT.Load(weightT.c_str());
386 WeightF.Load(weightF.c_str());
387 WeightE.Load(weightE.c_str());
388 WeightN.Load(weightN.c_str());
390 WeightC.Load(weightC.c_str());
392 if(m_dynamic) Ready.Load(ready.c_str());
393 else Ready.Reset(sets,max_jobs);
394 if(m_constrained) Constraints.Load(cons.c_str());
396 Level.Init(sets,max_jobs);
397 for(i=0; i<sets; i++)
399 for(j=0; j<(
unsigned int)N.Get(i); j++)
400 { SD.data[i][0] += Deadline.data[i][j];
405 for(i=0; i<sets; i++)
407 ReadConstraints(Constraints,i,(
unsigned int)N.Get(i),Precedence);
408 for(j=0; j<(
unsigned int)N.Get(i); j++)
409 Level[i][j] = NodeLevel(i,j);
412 if(m_Environment == UNRELATED)
413 {
for(uint set=0; set<sets; set++)
414 { uint jobs = (uint) N[set][0];
415 uint machines = (uint) Machines[set][0];
416 for(j=0; j<jobs; j++)
417 { PTimeAvg[set][j] = 0;
418 uint min_machine = 0;
419 for(uint machine=0; machine<machines; machine++)
420 { PTimeAvg[set][j] += Duration[set][j*machines + machine];
421 if(Duration[set][j*machines + machine] < Duration[set][j*machines + min_machine])
422 min_machine = machine;
424 PTimeAvg[set][j] /= machines;
425 PTimeMinMachine[set][j] = min_machine;
429 if(m_Environment == JOBSHOP)
430 {
for(uint set=0; set<sets; set++)
431 { uint jobs = (uint) N[set][0];
432 uint machines = (uint) Machines[set][0];
433 for(j=0; j<jobs; j++)
434 { uint operations = machines;
435 for(uint op=0; op<operations; op++)
436 {
double dur = Duration[set][j*operations + op];
437 uint machine = (uint) dur / 1000;
438 dur = (int)dur % 1000;
439 PTimeAvg[set][machine] += dur;
442 for(uint m=0; m<machines; m++)
443 PTimeAvg[set][m] /= jobs;
448 for(i=0; i<sets; i++)
450 uint jobs = (uint) N[i][0];
451 for(j=0; j<jobs; j++)
453 qsort(pIndex,jobs,
sizeof(
unsigned int),::Before);
454 for(j=0; j<jobs; j++)
455 SortedReady[i][j] = pIndex[j];
466void SchedulingEvalOp::DefineNodeNames(
void)
474void SchedulingEvalOp::ReadTerminals(TreeP tree)
479 p.OpenFile(in_file.c_str());
482 for(i = OFFSET; i < TERMINALS + OFFSET; i++)
483 { term =
"T_" + Nodes[i].name;
484 if(p.ReadParameter(term.c_str(),ReadPar::INTEGER,&dummy))
485 { Nodes[i].active =
true;
489 newTerm->
setName(Nodes[i].name);
490 tree->addTerminal(newTerm);
499void SchedulingEvalOp::ReadTerminals(StateP state)
504 GenotypeP gen = (GenotypeP) (state->getGenotypes()[0]);
505 TreeP tree = boost::dynamic_pointer_cast<Tree::Tree> (gen);
506 voidP val = tree->getParameterValue(state,
"terminalset");
507 std::string terminals = *((std::string*) val.get());
508 terminals =
" " + terminals +
" ";
512 for(i = 0; i < TERMINALS + OFFSET; i++)
513 {
if(terminals.find(
" " + Nodes[i].name +
" ") != string::npos)
514 { Nodes[i].active =
true;
523vector<IndividualP> jedinke;
525bool provjeriDuplikate(IndividualP individual, StateP state_)
528 static uint jednakih = 0;
530 bool jednaka =
false;
533 if(state_->getGenerationNo() != gen) {
534 gen = state_->getGenerationNo();
536 ECF_LOG(state_, 1,
"jednakih: " + uint2str(jednakih) +
", " + uint2str(100*jednakih/jedinke.size()));
543 uint broj = (uint) jedinke.size();
545 for(uint i = 0; i < broj; i++) {
547 if(nova->size() != stara->size())
549 uint n, size = (uint) nova->size();
550 Tree::NodeP cvor1, cvor2;
551 for(n = 0; n < size; n++) {
554 if(cvor1->primitive_ != cvor2->primitive_)
560 individual->fitness = (FitnessP) jedinke[i]->fitness->
copy();
588 FitnessP fitness =
static_cast<FitnessP
> (
new FitnessMin);
590 if(m_genotip ==
"FP") {
592 FloatingPointP fp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (individual->getGenotype());
595 EvaluateUnrelatedFP(fp, dFitness);
597 fitness->setValue(dFitness);
601 if(m_genotip ==
"PERM"){
604 EvaluateUnrelatedPermutation(individual, dFitness);
605 fitness->setValue(dFitness);
611 TreeP tree = boost::dynamic_pointer_cast<Tree::Tree> (individual->getGenotype());
620 double dRawFitness, dFitness;
621 ReadIndividual(individual);
625 {
int koliko = (int) (m_sampling*sets);
626 int razmak = sets / koliko;
627 int pocetni = rand()%razmak;
628 for(i=0; i<sets; i++)
630 for(i=pocetni; i<sets; i+=razmak)
634 switch(m_Environment)
636 EvaluateSingle(dRawFitness);
639 EvaluateUniform(dRawFitness);
642 EvaluateUnrelated(dRawFitness);
645 EvaluateJobShop(dRawFitness);
652 dFitness = dRawFitness;
655 {
Fitness.Save(
"rezultat_GP.txt");
656 std::ostream *file =
new std::ofstream(
"rezultat_GP.txt", std::ios_base::app);
658 *file << std::endl <<
"-- infix: " <<
Evaluator.m_output <<
" --" << std::endl;
659 *file <<
"Editirano: " << edited <<
", ukupno: " << total << std::endl;
662 Schedule.Save(
"raspored_GP.txt");
669 fitness->setValue(dFitness);
672 individual->fitness = fitness;
673 jedinke.push_back((IndividualP) individual->copy());
679void SchedulingEvalOp::write(std::string &output)
685void SchedulingEvalOp::ReadConstraints(
Matrica &Constraints,
int set,
int jobs,
Matrica &Precedence)
687 int i,j,prethodnika,prethodnik,pom;
688 unsigned int podatak;
691 for(i=0; i<jobs; i++)
693 Precedence[i][j] = 0;
694 for(i=0; i<jobs; i++)
695 { podatak = (
unsigned int) Constraints[set][i];
701 pom = (int) Precedence[i-prethodnik][1] + 1;
702 Precedence[i-prethodnik][pom+1] = i;
703 Precedence[i-prethodnik][1] = pom;
708 Precedence[i][0] = prethodnika;
715void SchedulingEvalOp::MakeSetup(
Matrica &Duration,
int set,
int jobs,
double faktor,
Matrica &Setup)
719 if(m_Environment == JOBSHOP)
721 for(i=0; i<jobs; i++)
722 { Setup[jobs][i] = (int) ((rand()%max_length+1) * faktor);
723 pSetupAvg[jobs] += Setup[jobs][i];
725 { Setup[i][j] = (int) ((rand()%max_length+1) * faktor);
726 Setup[j][i] = (int) ((rand()%max_length+1) * faktor);
727 pSetupAvg[i] += Setup[i][j];
728 pSetupAvg[j] += Setup[j][i];
733 for(i=0; i<jobs; i++)
735 Setup[jobs][i] = Duration[set][(i+1) % jobs];
736 pSetupAvg[jobs] += Setup[jobs][i];
738 { Setup[i][j] = ceil( fabs( Duration[set][i] - Duration[set][j] ) * faktor);
739 Setup[j][i] = ceil( fabs( Duration[set][(i+1) % jobs] - Duration[set][(j+1) % jobs] ) * faktor);
740 pSetupAvg[i] += Setup[i][j];
741 pSetupAvg[j] += Setup[j][i];
744 pSetupAvg[jobs] /= jobs;
745 for(i=0; i<jobs; i++)
746 pSetupAvg[i] /= (jobs-1);
751void SchedulingEvalOp::ReadIndividual(IndividualP individual)
753 TreeP tree = boost::dynamic_pointer_cast<Tree::Tree> (individual->getGenotype());
754 static std::string strTerminal;
755 unsigned int nTreeSize,i,j,nTree;
756 uint nTrees = (uint) individual->size();
757 for(nTree = 0; nTree<nTrees; nTree++)
758 { TreeP pTree = boost::dynamic_pointer_cast<Tree::Tree> (individual->getGenotype(nTree));
759 nTreeSize = (uint) pTree->size();
764 for(i=0; i<nTreeSize; i++)
766 strTerminal = (*pTree)[i]->primitive_->getName();
767 for(j=0; j<TOTAL_NODES; j++)
768 {
if(!Nodes[j].active)
770 if(strTerminal == Nodes[j].name)
775 assert(j<TOTAL_NODES);
794double SchedulingEvalOp::NodeLevel(
int set,
int node)
797 if(Level[set][
node] > -1)
798 return Level[set][
node];
799 if(Precedence[
node][1] == 0)
800 return Duration[set][
node];
801 succ = (int)Precedence[
node][1];
802 next = (int)Precedence[
node][2];
803 level = NodeLevel(set,next) + Duration[set][
node];
804 for(i=1; i<succ; i++)
805 { next = (int)Precedence[
node][i+2];
806 value = NodeLevel(set,next) + Duration[set][
node];
815void SchedulingEvalOp::CalcTimedTerminals(uint &nNiz, uint &nPoslova, uint &nJob,
double &dClock, \
816 uint nMachine, uint nMachines)
818 for(i=nJob; i<nPoslova; i++)
820 if(m_Environment == UNIFORM)
821 {
Evaluator.m_dTermValuesArray[T_SPD][j] = Speed[nNiz][nMachine];
822 pSlack[j] = Deadline[nNiz][j] - (dClock + Duration[nNiz][j]);
823 pSlackSpeed[j] = Deadline[nNiz][j] - (dClock + Duration[nNiz][j] * Speed[nNiz][nMachine]);
824 Evaluator.m_dTermValuesArray[T_L][j] = POS(dClock + Duration[nNiz][j]*Speed[nNiz][nMachine]- Deadline[nNiz][j]);
826 if(m_Environment == UNRELATED)
827 {
Evaluator.m_dTermValuesArray[T_PAT][j] = POS(MachineReady[(uint)PTimeMinMachine[nNiz][j]][0] - dClock);
828 Evaluator.m_dTermValuesArray[T_MR][j] = POS(MachineReady[nMachine][0] - dClock);
829 Evaluator.m_dTermValuesArray[T_pt][j] = Duration[nNiz][j*nMachines + nMachine];
830 Evaluator.m_dTermValuesArray[T_age][j] = POS(dClock - Ready[nNiz][j]);
831 pSlack[j] = Deadline[nNiz][j] - (dClock + Duration[nNiz][j*nMachines + nMachine]);
832 Evaluator.m_dTermValuesArray[T_L][j] = POS(dClock + Duration[nNiz][j*nMachines + nMachine]- Deadline[nNiz][j]);
834 if(m_Environment == SINGLE)
835 { pSlack[j] = Deadline[nNiz][j] - (dClock + Duration[nNiz][j]);
836 Evaluator.m_dTermValuesArray[T_L][j] = POS(dClock + Duration[nNiz][j]- Deadline[nNiz][j]);
841 Evaluator.m_dTermValuesArray[T_CLK][j] = dClock;
842 pArrival[j] = POS(Ready[nNiz][j] - dClock);
843 Evaluator.m_dTermValuesArray[T_AR][j] = pArrival[j];
844 if(pSlack[j]<0) pSlack[j] = 0;
845 if(pSlackSpeed[j]<0) pSlackSpeed[j] = 0;
847 Evaluator.m_dTermValuesArray[T_SL][j] = pSlack[j];
848 Evaluator.m_dTermValuesArray[T_SLs][j] = pSlackSpeed[j];
850 if(m_Environment != SINGLE)
852 Evaluator.m_dTermValuesArray[T_STP][j] = Setup[pLastJob[nMachine]][j];
853 Evaluator.m_dTermValuesArray[T_Sav][j] = pSetupAvg[pLastJob[nMachine]];
860void SchedulingEvalOp::EvaluateSingle(
double &dRawFitness)
862 double dClock, dRez, dSetFitness, dAvgWeights, dAvgDuration, dAvgDueDate;
863 double dLateness, dTotalLateness=0, dTardiness, dTotalTardiness=0;
864 double dNwt, dTotalNwt=0, dBest, dSPr, dSDr;
865 unsigned int nPoslova,nNiz,nJob,i,j,k,index,nLateJobs,nTotalLateJobs=0,nNr;
866 unsigned int nLastJob,nOdabrani;
871 for(nNiz=0; nNiz<sets; nNiz++)
874 if(m_primjer > 0 && m_primjer != (nNiz + 1))
877 nNr = nPoslova = (int) N.Get(nNiz);
881 if(pSamples[nNiz] ==
false)
885 {
if(dRawFitness > m_LEFVal)
889 ReadConstraints(Constraints,nNiz,nPoslova,Precedence);
891 MakeSetup(Duration,nNiz,nPoslova,m_setup_faktor,Setup);
897 dClock = 0; dSetFitness = 0;
900 for(i=0; i<nPoslova; i++)
901 { dAvgDueDate += Deadline[nNiz][i];
902 pRasporedjen[i] =
false;
905 dAvgDueDate /= nPoslova;
907 Evaluator.m_pTermValues[T_N] = N.Get(nNiz);
908 dSPr =
Evaluator.m_pTermValues[T_SP] = SP.Get(nNiz);
909 dSDr =
Evaluator.m_pTermValues[T_SD] = SD.Get(nNiz);
913 for(i=0; i<nPoslova; i++)
914 {
Evaluator.m_dTermValuesArray[T_N][i] = N.data[nNiz][0];
915 Evaluator.m_dTermValuesArray[T_SP][i] = SP.data[nNiz][0];
916 Evaluator.m_dTermValuesArray[T_SD][i] = SD.data[nNiz][0];
917 Evaluator.m_dTermValuesArray[T_SC][i] = Precedence[i][1];
918 Evaluator.m_dTermValuesArray[T_TF][i] = 1 - dAvgDueDate / SP[nNiz][0];
920 memcpy(
Evaluator.m_dTermValuesArray[T_pt], Duration.data[nNiz], nPoslova*
sizeof(
double));
921 memcpy(
Evaluator.m_dTermValuesArray[T_dd], Deadline.data[nNiz], nPoslova*
sizeof(
double));
922 memcpy(
Evaluator.m_dTermValuesArray[T_w], WeightT.data[nNiz], nPoslova*
sizeof(
double));
923 memcpy(
Evaluator.m_dTermValuesArray[T_LVL], Level[nNiz], nPoslova*
sizeof(
double));
928 for(nJob=0; nJob<nPoslova; nJob++)
929 {
for(i=nJob; i<nPoslova; i++)
931 Evaluator.m_dTermValuesArray[T_SPr][j] = dSPr;
932 Evaluator.m_dTermValuesArray[T_Nr][j] = nNr;
933 Evaluator.m_dTermValuesArray[T_STP][j] = Setup[nLastJob][j];
934 Evaluator.m_dTermValuesArray[T_Sav][j] = pSetupAvg[nLastJob];
941 {
unsigned int raspolozivi = nJob, prvi = nJob;
942 unsigned int najkraci;
944 for(; Precedence[pIndex[raspolozivi]][0] > 0; raspolozivi++) NULL;
945 double kada = Ready[nNiz][pIndex[raspolozivi]];
946 double najdulje = 0, najkrace = 0;
947 for( ; raspolozivi < nPoslova; raspolozivi++)
948 { k = pIndex[raspolozivi];
949 if(Ready.data[nNiz][k] < kada && Precedence[k][0] == 0)
950 { kada = Ready.data[nNiz][k];
958 CalcTimedTerminals(nNiz,nPoslova,nJob,dClock);
960 najdulje = najkrace = Duration[nNiz][pIndex[prvi]];
962 for(i=nJob; i<nPoslova; i++)
964 if(dClock < Ready[nNiz][k] || Precedence[k][0] > 0)
966 if(Duration[nNiz][k] < najkrace)
967 { najkrace = Duration[nNiz][k];
972 for(i=nJob; i<nPoslova; i++)
974 if(Precedence[k][0] > 0)
976 if(Duration[nNiz][k] > najdulje && Ready[nNiz][k] <= (dClock+najkrace))
977 najdulje = Duration[nNiz][k];
988 kada = najkrace + najdulje;
989 dBest = pVrijednosti[pIndex[najkraci]];
990 nOdabrani = najkraci;
991 for(i=nJob; i<nPoslova; i++)
993 if(Precedence[k][0] == 0 && (pVrijednosti[k] < dBest) && (Ready[nNiz][k] < dClock + kada))
994 { dBest = pVrijednosti[k];
998 kada = Ready[nNiz][pIndex[nOdabrani]] - dClock;
1000 { dBest = pVrijednosti[pIndex[najkraci]];
1001 nOdabrani = najkraci;
1002 for(i=nJob; i<nPoslova; i++)
1004 if(Precedence[k][0] == 0 && (Ready[nNiz][k] + Duration[nNiz][k] <= dClock + kada) \
1005 && pVrijednosti[k] < dBest \
1006 && Ready[nNiz][k] - dClock < najkrace)
1007 { dBest = pVrijednosti[k];
1011 kada = Ready[nNiz][pIndex[nOdabrani]] - dClock;
1033 { CalcTimedTerminals(nNiz,nPoslova,nJob,dClock);
1036 for(; Precedence[pIndex[nOdabrani]][0] > 0; nOdabrani++) NULL;
1038 dBest = pVrijednosti[pIndex[nOdabrani]];
1039 for(i=nJob; i<nPoslova; i++)
1041 if(pVrijednosti[pIndex[i]] < dBest && Precedence[pIndex[i]][0] == 0)
1042 { dBest = pVrijednosti[pIndex[i]];
1051 pIndex[nJob] = pIndex[nOdabrani];
1052 pIndex[nOdabrani] = i;
1053 pRasporedjen[pIndex[nJob]] =
true;
1054 dClock += Duration[nNiz][pIndex[nJob]];
1055 dSPr -= Duration[nNiz][pIndex[nJob]];
1056 dSDr -= Deadline[nNiz][pIndex[nJob]];
1059 for(i=0; i<Precedence[pIndex[nJob]][1]; i++)
1060 { j = (int) Precedence[pIndex[nJob]][i+2];
1061 Precedence[j][0] -= 1;
1064 { dClock += Setup[nLastJob][pIndex[nJob]];
1065 nLastJob = pIndex[nJob];
1067 Schedule[nNiz][nJob] = pIndex[nJob];
1072 {
for(nJob=nPoslova ; nJob < this->max_jobs; nJob++)
1073 Schedule[nNiz][nJob] = 0;
1076 dClock = 0; nLastJob = nPoslova; dAvgWeights = dAvgDuration = 0;
1077 for(nJob = 0; nJob<nPoslova; nJob++)
1078 { index = pIndex[nJob];
1079 dAvgWeights += WeightT[nNiz][index];
1080 dAvgDuration += Duration[nNiz][index];
1081 if(m_dynamic && dClock < Ready[nNiz][index])
1082 dClock = Ready[nNiz][index];
1084 dClock += Setup[nLastJob][index];
1086 dClock += Duration.data[nNiz][index];
1087 dRez = dClock - Deadline.Get(nNiz,index);
1088 dLateness += dRez*WeightT.data[nNiz][index];
1089 if(dRez > 0) dTardiness += dRez*WeightT.data[nNiz][index];
1090 if(dRez > 0) nLateJobs ++;
1091 if(dRez > 0) dNwt += WeightN.data[nNiz][index];
1095 dAvgWeights /= nPoslova;
1096 dAvgDuration /= nPoslova;
1097 dTardiness /= (nPoslova * dAvgWeights * dAvgDuration);
1098 dNwt /= (nPoslova * dAvgWeights);
1099 double Cmax = dClock / (nPoslova * dAvgDuration);
1101 {
case Twt: dRawFitness += dTardiness;
break;
1102 case Nwt: dRawFitness += dNwt;
break;
1103 case TwtCmax: dRawFitness += dTardiness * Cmax;
break;
1104 case NwtCmax: dRawFitness += dNwt * Cmax;
break;
1107 nTotalLateJobs += nLateJobs;
1109 dTotalLateness += dLateness;
1110 dTotalTardiness += dTardiness;
1111 Fitness[nNiz][Twt] = dTardiness;
1118 Fitness.data[sets][Twt] = dTotalTardiness;
1119 Fitness.data[sets][Nwt] = dTotalNwt;
1126void SchedulingEvalOp::EvaluateUniform(
double &dRawFitness)
1128 double dClock, dRez, dSetFitness, dAvgWeights, dAvgDuration;
1129 double dLateness, dTotalLateness=0, dTardiness, dTotalTardiness=0, dTotalFwt=0;
1130 double dNwt, dTotalNwt=0, dBest, dSPr, dMsum, dSetupTime, dFwt, dCmax, dTotalCmax=0;
1131 unsigned int nPoslova,nNiz,nJob,i,j,k,index,nLateJobs,nTotalLateJobs=0,nNr;
1132 unsigned int nLastJob,nMachines,nOdabrani,nMachine;
1137 for(nNiz=0; nNiz<sets; nNiz++)
1138 { nNr = nPoslova = (int) N.Get(nNiz);
1142 if(pSamples[nNiz] ==
false)
1146 {
if(dRawFitness > m_LEFVal)
1150 ReadConstraints(Constraints,nNiz,nPoslova,Precedence);
1152 MakeSetup(Duration,nNiz,nPoslova,m_setup_faktor,Setup);
1159 dClock = 0; dSetFitness = 0;
1160 nLastJob = nPoslova;
1161 for(i=0; i<nPoslova; i++)
1162 { pRasporedjen[i] =
false;
1165 nMachines = (uint) Machines[nNiz][0];
1167 for(j=0; j<nMachines; j++)
1168 { MachineReady[j][0] = 0;
1169 dMsum += 1/Speed[nNiz][j];
1170 pLastJob[j] = nPoslova;
1173 Evaluator.m_pTermValues[T_N] = N.Get(nNiz);
1174 dSPr =
Evaluator.m_pTermValues[T_SP] = SP.Get(nNiz);
1175 Evaluator.m_pTermValues[T_SD] = SD.Get(nNiz);
1179 for(i=0; i<nPoslova; i++)
1180 {
Evaluator.m_dTermValuesArray[T_N][i] = N.data[nNiz][0];
1181 Evaluator.m_dTermValuesArray[T_SP][i] = SP.data[nNiz][0];
1182 Evaluator.m_dTermValuesArray[T_SD][i] = SD.data[nNiz][0];
1183 Evaluator.m_dTermValuesArray[T_SC][i] = Precedence[i][1];
1185 memcpy(
Evaluator.m_dTermValuesArray[T_pt], Duration.data[nNiz], nPoslova*
sizeof(
double));
1186 memcpy(
Evaluator.m_dTermValuesArray[T_dd], Deadline.data[nNiz], nPoslova*
sizeof(
double));
1187 memcpy(
Evaluator.m_dTermValuesArray[T_w], WeightT.data[nNiz], nPoslova*
sizeof(
double));
1188 memcpy(
Evaluator.m_dTermValuesArray[T_LVL], Level[nNiz], nPoslova*
sizeof(
double));
1193 for(nJob=0; nJob<nPoslova; nJob++)
1194 {
for(i=nJob; i<nPoslova; i++)
1196 Evaluator.m_dTermValuesArray[T_SPr][j] = dSPr;
1197 Evaluator.m_dTermValuesArray[T_Nr][j] = nNr;
1204 unsigned int raspolozivi = nJob, prvi = nJob;
1206 for(; Precedence[pIndex[raspolozivi]][0] > 0; raspolozivi++) NULL;
1207 double kada = Ready[nNiz][pIndex[raspolozivi]];
1208 for( ; raspolozivi < nPoslova; raspolozivi++)
1209 { k = pIndex[raspolozivi];
1210 if(Ready.data[nNiz][k] < kada && Precedence[k][0] == 0)
1211 { kada = Ready.data[nNiz][k];
1216 for(i=0; i<nMachines; i++)
1217 if(MachineReady[i][0] < MachineReady[nMachine][0])
1220 if(kada < MachineReady[nMachine][0])
1221 kada = MachineReady[nMachine][0];
1225 CalcTimedTerminals(nNiz,nPoslova,nJob,dClock,nMachine);
1229 dBest = pVrijednosti[pIndex[prvi]];
1231 for(i=nJob; i<nPoslova; i++)
1232 {
if((pVrijednosti[pIndex[i]] < dBest) && Precedence[pIndex[i]][0] == 0 \
1233 && Ready[nNiz][pIndex[i]] <= dClock)
1234 { dBest = pVrijednosti[pIndex[i]];
1242 for(i=1; i<nMachines; i++)
1243 if(MachineReady[i][0] < MachineReady[nMachine][0])
1245 dClock = MachineReady[nMachine][0];
1246 CalcTimedTerminals(nNiz,nPoslova,nJob,dClock,nMachine);
1249 for(; Precedence[pIndex[nOdabrani]][0] > 0; nOdabrani++) NULL;
1251 dBest = pVrijednosti[pIndex[nOdabrani]];
1252 for(i=nJob; i<nPoslova; i++)
1254 if(pVrijednosti[pIndex[i]] < dBest && Precedence[pIndex[i]][0] == 0)
1255 { dBest = pVrijednosti[pIndex[i]];
1264 pIndex[nJob] = pIndex[nOdabrani];
1265 pIndex[nOdabrani] = i;
1266 pRasporedjen[pIndex[nJob]] =
true;
1269 dSPr -= Duration.data[nNiz][pIndex[nJob]]*dMsum;
1272 { dSetupTime = Setup[pLastJob[nMachine]][pIndex[nJob]];
1273 pLastJob[nMachine] = pIndex[nJob];
1275 else dSetupTime = 0;
1277 for(i=0; i<Precedence[pIndex[nJob]][1]; i++)
1278 { j = (int) Precedence[pIndex[nJob]][i+2];
1279 Precedence[j][0] -= 1;
1281 MachineReady[nMachine][0] = dClock + dSetupTime + \
1282 Duration[nNiz][pIndex[nJob]] * Speed[nNiz][nMachine];
1284 Schedule[nNiz][nJob] = pIndex[nJob] + nMachine * 1000;
1288 {
for(nJob=nPoslova ; nJob < this->max_jobs; nJob++)
1289 Schedule[nNiz][nJob] = 0;
1292 dClock = 0; nLastJob = nPoslova; dAvgWeights = 0;
1293 for(i=0; i<nMachines; i++)
1294 { MachineReady[i][0] = 0;
1295 pLastJob[i] = nPoslova;
1297 for(nJob = 0; nJob<nPoslova; nJob++)
1298 { index = (int) Schedule[nNiz][nJob];
1299 nMachine = index / 1000;
1300 index = index % 1000;
1301 dAvgWeights += WeightT[nNiz][index];
1302 if(m_dynamic && MachineReady[nMachine][0] < Ready[nNiz][index])
1303 MachineReady[nMachine][0] = Ready[nNiz][index];
1304 MachineReady[nMachine][0] += Duration[nNiz][index] * Speed[nNiz][nMachine];
1306 MachineReady[nMachine][0] += Setup[pLastJob[nMachine]][index];
1307 pLastJob[nMachine] = index;
1308 dRez = MachineReady[nMachine][0] - Deadline.Get(nNiz,index);
1309 dLateness += dRez*WeightT.data[nNiz][index];
1310 if(dRez > 0) dTardiness += dRez*WeightT.data[nNiz][index];
1311 if(dRez > 0) nLateJobs ++;
1312 if(dRez > 0) dNwt += WeightN.data[nNiz][index];
1313 dFwt = (MachineReady[nMachine][0] - Ready[nNiz][index]) * WeightT[nNiz][index];
1316 for(i=0; i<nMachines; i++)
1317 if(MachineReady[i][0] > dCmax)
1318 dCmax = MachineReady[i][0];
1321 dAvgDuration = SP[nNiz][0] / nPoslova;
1322 dAvgWeights /= nPoslova;
1323 dTardiness /= (nPoslova * dAvgWeights * dAvgDuration);
1324 dNwt /= (nPoslova * dAvgWeights);
1325 dFwt /= (nPoslova * dAvgWeights * dAvgDuration);
1326 dCmax /= (nPoslova * dAvgDuration);
1328 {
case Twt: dRawFitness += dTardiness;
break;
1329 case Nwt: dRawFitness += dNwt;
break;
1330 case Fwt: dRawFitness += dFwt;
break;
1331 case Cmax: dRawFitness += dCmax;
break;
1334 nTotalLateJobs += nLateJobs;
1337 dTotalLateness += dLateness;
1338 dTotalTardiness += dTardiness;
1339 dTotalCmax += dCmax;
1340 Fitness[nNiz][Twt] = dTardiness;
1349 Fitness[sets][Twt] = dTotalTardiness;
1350 Fitness[sets][Nwt] = dTotalNwt;
1353 Fitness[sets][Fwt] = dTotalFwt;
1354 Fitness[sets][Cmax] = dTotalCmax;
1363void SchedulingEvalOp::EvaluateUnrelated(
double &dRawFitness)
1365 double dClock, dRez, dSetFitness, dAvgWeights, dCmax, dTotalCmax=0;
1366 double dLateness, dTotalLateness=0, dTardiness, dTotalTardiness=0;
1367 double dEarliness, dTotalEarliness = 0;
1368 double dEarlinessTardiness, dTotalEarlinessTardiness = 0;
1369 double dTmax, dTotalTmax = 0;
1370 double dFmax, dTotalFmax = 0;
1371 double dMus, dTotalMus = 0;
1372 double dCw, dTotalCw =0;
1373 vector<double> machineUseage;
1374 double dNwt, dTotalNwt=0, dBest, dSPr, dSetupTime, dFwt, dTotalFwt=0;
1375 unsigned int nPoslova,nNiz,nJob,i,j,k,index,nLateJobs,nTotalLateJobs=0,nNr;
1376 unsigned int nLastJob,nMachines,nOdabrani,nMachine;
1377 double dAvgWeightsC;
1378 double dAvgWeightsE;
1384 for(nNiz=0; nNiz<sets; nNiz++)
1385 { nNr = nPoslova = (int) N.Get(nNiz);
1389 if(pSamples[nNiz] ==
false)
1393 {
if(dRawFitness > m_LEFVal)
1397 ReadConstraints(Constraints,nNiz,nPoslova,Precedence);
1399 MakeSetup(Duration,nNiz,nPoslova,m_setup_faktor,Setup);
1411 dClock = 0; dSetFitness = 0;
1414 nLastJob = nPoslova;
1415 for(i=0; i<nPoslova; i++)
1416 { pRasporedjen[i] =
false;
1418 pIndex[i] = (uint) SortedReady[nNiz][i];
1421 nMachines = (uint) Machines[nNiz][0];
1423 machineUseage.clear();
1424 for(
int kk=0; kk<nMachines; kk++){
1425 machineUseage.push_back(0);
1429 for(j=0; j<nMachines; j++)
1430 { MachineReady[j][0] = 0;
1431 pLastJob[j] = nPoslova;
1435 dSPr = SP.Get(nNiz);
1440 for(i=0; i<nPoslova; i++)
1441 {
Evaluator.m_dTermValuesArray[T_N][i] = N.data[nNiz][0];
1442 Evaluator.m_dTermValuesArray[T_SP][i] = SP.data[nNiz][0];
1443 Evaluator.m_dTermValuesArray[T_SD][i] = SD.data[nNiz][0];
1444 Evaluator.m_dTermValuesArray[T_SC][i] = Precedence[i][1];
1446 Evaluator.m_dTermValuesArray[T_pmin][i] = Duration[nNiz][i*nMachines + (uint)PTimeMinMachine[nNiz][i]];
1448 memcpy(
Evaluator.m_dTermValuesArray[T_dd], Deadline.data[nNiz], nPoslova*
sizeof(
double));
1449 memcpy(
Evaluator.m_dTermValuesArray[T_w], WeightT.data[nNiz], nPoslova*
sizeof(
double));
1450 memcpy(
Evaluator.m_dTermValuesArray[T_LVL], Level[nNiz], nPoslova*
sizeof(
double));
1451 memcpy(
Evaluator.m_dTermValuesArray[T_pavg], PTimeAvg[nNiz], nPoslova*
sizeof(
double));
1456 for(nJob=0; nJob<nPoslova; nJob++)
1457 {
for(i=nJob; i<nPoslova; i++)
1459 Evaluator.m_dTermValuesArray[T_SPr][j] = dSPr;
1460 Evaluator.m_dTermValuesArray[T_Nr][j] = nNr;
1477 unsigned int raspolozivi = nJob, prvi = nJob;
1479 for(; Precedence[pIndex[raspolozivi]][0] > 0; raspolozivi++) NULL;
1480 double kada = Ready[nNiz][pIndex[raspolozivi]];
1481 for( ; raspolozivi < nPoslova; raspolozivi++)
1482 { k = pIndex[raspolozivi];
1483 if(Ready.data[nNiz][k] < kada && Precedence[k][0] == 0)
1484 { kada = Ready.data[nNiz][k];
1489 for(i=0; i<nMachines; i++)
1490 if(MachineReady[i][0] < MachineReady[nMachine][0])
1493 if(kada < MachineReady[nMachine][0])
1494 kada = MachineReady[nMachine][0];
1497 for(i=
Evaluator.m_iEnd; i<nPoslova && Ready[nNiz][pIndex[i]]<=dClock; i++) NULL;
1502 for(nMachine=0; nMachine<nMachines; nMachine++)
1506 CalcTimedTerminals(nNiz,nPoslova,nJob,dClock,nMachine,nMachines);
1509 memcpy(Values[nMachine],pVrijednosti,nPoslova*
sizeof(
double));
1511 bool BestSet =
false;
1512 uint nBestMachine, nBestJobMachine;
1513 for(i=nJob; i<nPoslova; i++)
1514 {
if(Precedence[pIndex[i]][0] != 0 || Ready[nNiz][pIndex[i]] > dClock)
1517 nBestJobMachine = 0;
1518 for(nMachine=1; nMachine<nMachines; nMachine++)
1519 if(Values[nBestJobMachine][pIndex[i]] < Values[nMachine][pIndex[i]])
1520 nBestJobMachine = nMachine;
1521 if(MachineReady[nBestJobMachine][0] > dClock)
1524 { nBestMachine = nBestJobMachine;
1525 dBest = Values[nBestMachine][pIndex[i]];
1530 {
if(Values[nBestJobMachine][pIndex[i]] < dBest)
1531 { nBestMachine = nBestJobMachine;
1532 dBest = Values[nBestJobMachine][pIndex[i]];
1542 for(i=0; i<nMachines && MachineReady[i][0] <= dClock; i++) NULL;
1544 for( ; i<nMachines; i++)
1545 if(MachineReady[i][0] > dClock && MachineReady[i][0] < MachineReady[nMachine][0])
1549 unsigned int raspolozivi = nJob, prvi = nJob;
1551 for(; raspolozivi < nPoslova && (Precedence[pIndex[raspolozivi]][0] > 0 || Ready[nNiz][pIndex[raspolozivi]] <= dClock); raspolozivi++) NULL;
1553 if(raspolozivi < nPoslova)
1554 { kada = Ready[nNiz][pIndex[raspolozivi]];
1555 for( ; raspolozivi < nPoslova; raspolozivi++)
1556 { k = pIndex[raspolozivi];
1557 if(Ready[nNiz][k] < kada && Ready[nNiz][k] > dClock && Precedence[k][0] == 0)
1558 { kada = Ready[nNiz][k];
1565 dClock = MachineReady[nMachine][0];
1566 if(raspolozivi < nPoslova && kada < dClock)
1570 for(i=0; i<nMachines; i++)
1571 if(MachineReady[i][0] < dClock)
1572 MachineReady[i][0] = dClock;
1576 nMachine = nBestMachine;
1582 for(i=1; i<nMachines; i++)
1583 if(MachineReady[i][0] < MachineReady[nMachine][0])
1585 dClock = MachineReady[nMachine][0];
1586 CalcTimedTerminals(nNiz,nPoslova,nJob,dClock,nMachine,nMachines);
1589 for(; Precedence[pIndex[nOdabrani]][0] > 0; nOdabrani++) NULL;
1591 dBest = pVrijednosti[pIndex[nOdabrani]];
1592 for(i=nJob; i<nPoslova; i++)
1594 if(pVrijednosti[pIndex[i]] < dBest && Precedence[pIndex[i]][0] == 0)
1595 { dBest = pVrijednosti[pIndex[i]];
1604 pIndex[nJob] = pIndex[nOdabrani];
1605 pIndex[nOdabrani] = i;
1606 pRasporedjen[pIndex[nJob]] =
true;
1607 nOdabrani = pIndex[nJob];
1613 { dSetupTime = Setup[pLastJob[nMachine]][nOdabrani];
1614 pLastJob[nMachine] = nOdabrani;
1616 else dSetupTime = 0;
1618 for(i=0; i<Precedence[nOdabrani][1]; i++)
1619 { j = (int) Precedence[nOdabrani][i+2];
1620 Precedence[j][0] -= 1;
1622 MachineReady[nMachine][0] = dClock + dSetupTime + \
1623 Duration[nNiz][nOdabrani*nMachines + nMachine];
1625 Schedule[nNiz][nJob] = nOdabrani + nMachine * 1000;
1630 {
for(nJob=nPoslova ; nJob < this->max_jobs; nJob++)
1631 Schedule[nNiz][nJob] = 0;
1634 dClock = 0; nLastJob = nPoslova; dAvgWeights = 0; dCmax = 0;
1635 for(i=0; i<nMachines; i++)
1636 { MachineReady[i][0] = 0;
1637 pLastJob[i] = nPoslova;
1639 for(nJob = 0; nJob<nPoslova; nJob++)
1640 { index = (int) Schedule[nNiz][nJob];
1641 nMachine = index / 1000;
1642 index = index % 1000;
1643 dAvgWeights += WeightT[nNiz][index];
1644 if(m_dynamic && MachineReady[nMachine][0] < Ready[nNiz][index])
1645 MachineReady[nMachine][0] = Ready[nNiz][index];
1646 MachineReady[nMachine][0] += Duration[nNiz][index*nMachines + nMachine];
1648 MachineReady[nMachine][0] += Setup[pLastJob[nMachine]][index];
1649 pLastJob[nMachine] = index;
1650 dRez = MachineReady[nMachine][0] - Deadline.Get(nNiz,index);
1651 dLateness += dRez*WeightT.data[nNiz][index];
1652 dAvgWeightsC+= WeightC.data[nNiz][index];
1653 dAvgWeightsE+= WeightE.data[nNiz][index];
1654 machineUseage[nMachine] += Duration[nNiz][index*nMachines + nMachine];
1655 dCw += MachineReady[nMachine][0] * WeightC.data[nNiz][index];
1657 if(dRez>0&&dTmax<(dRez*WeightT.data[nNiz][index])){
1658 dTmax = dRez*WeightT.data[nNiz][index];
1661 if(dFmax<(MachineReady[nMachine][0] - Ready[nNiz][index])){
1662 dFmax = MachineReady[nMachine][0] - Ready[nNiz][index];
1665 if(dRez > 0) dTardiness += dRez*WeightT.data[nNiz][index];
1666 if(dRez > 0) nLateJobs ++;
1667 if(dRez > 0) dNwt += WeightN.data[nNiz][index];
1668 if(dRez < 0) dEarliness += WeightE.data[nNiz][index]*dRez;
1670 dFwt += MachineReady[nMachine][0] - Ready[nNiz][index];
1672 dFwt += MachineReady[nMachine][0];
1674 for(i=0; i<nMachines; i++)
1675 if(MachineReady[i][0] > dCmax)
1676 dCmax = MachineReady[i][0];
1678 double max=machineUseage[0]/dCmax, min =machineUseage[0]/dCmax;
1681 for(i=0; i<nMachines; i++){
1682 machineUseage[i]/= dCmax;
1683 dMus+=machineUseage[i];
1684 if(max<machineUseage[i])
1685 max = machineUseage[i];
1686 if(min>machineUseage[i])
1687 min = machineUseage[i];
1692 dAvgWeights /= nPoslova;
1693 dAvgWeightsC/= nPoslova;
1694 dAvgWeightsE/= nPoslova;
1695 double dAvgDuration = SP[nNiz][0] / nPoslova;
1696 dMus=(max - min)/(nPoslova * dAvgDuration);
1697 dTardiness /= (nPoslova * dAvgWeights * dAvgDuration);
1698 dEarliness /= (nPoslova * dAvgWeightsE * dAvgDuration);
1699 dNwt /= (nPoslova * dAvgWeights);
1700 dFwt /= dAvgDuration * nPoslova;
1701 dCmax /= nPoslova * dAvgDuration;
1702 dCw /=(nPoslova * dAvgWeightsC * dAvgDuration);
1703 dTmax /= (dAvgDuration*nPoslova);
1704 dFmax /= (dAvgDuration*nPoslova);
1706 {
case Twt: dRawFitness += dTardiness;
break;
1707 case Nwt: dRawFitness += dNwt;
break;
1708 case Fwt: dRawFitness += dFwt;
break;
1709 case Cmax: dRawFitness += dCmax;
break;
1710 case Ewt: dRawFitness += dEarliness;
break;
1711 case ETwt: dRawFitness += (-dEarliness+dTardiness);
break;
1712 case Tmax: dRawFitness += dTmax;
break;
1713 case Fmax: dRawFitness += dFmax;
break;
1714 case Cw: dRawFitness += dCw;
break;
1715 case Mus: dRawFitness += dMus;
break;
1716 default: CHECKMSG(0,
"NEsto poslo po zlu");
1718 nTotalLateJobs += nLateJobs;
1721 dTotalLateness += dLateness;
1722 dTotalTardiness += dTardiness;
1723 dTotalCmax += dCmax;
1724 dTotalEarliness += dEarliness;
1725 dTotalEarlinessTardiness+=(-dEarliness+dTardiness);
1729 dTotalFmax += dFmax;
1730 Fitness[nNiz][Twt] = dTardiness;
1733 Fitness[nNiz][Ewt] = dEarliness;
1736 Fitness[nNiz][ETwt] = (-dEarliness)+dTardiness;
1745 Fitness[sets][Twt] = dTotalTardiness;
1746 Fitness[sets][Nwt] = dTotalNwt;
1747 Fitness[sets][Fwt] = dTotalFwt;
1748 Fitness[sets][Cmax] = dTotalCmax;
1749 Fitness[sets][ETwt] = dTotalEarlinessTardiness;
1750 Fitness[sets][Mus] = dTotalMus;
1751 Fitness[sets][Ewt] = dTotalEarliness;
1753 Fitness[sets][Tmax] = dTotalTmax;
1754 Fitness[sets][Fmax] = dTotalFmax;
1758void SchedulingEvalOp::EvaluateUnrelatedPermutation(IndividualP individual,
double &dRawFitness)
1763 double dClock, dRez, dSetFitness, dAvgWeights, dCmax, dTotalCmax=0;
1764 double dLateness, dTotalLateness=0, dTardiness, dTotalTardiness=0;
1765 double dEarliness, dTotalEarliness = 0;
1766 double dEarlinessTardiness, dTotalEarlinessTardiness = 0;
1767 double dTmax, dTotalTmax = 0;
1768 double dFmax, dTotalFmax = 0;
1769 double dMus, dTotalMus = 0;
1770 double dCw, dTotalCw =0;
1771 vector<double> machineUseage;
1772 double dNwt, dTotalNwt=0, dBest, dSPr, dSetupTime, dFwt, dTotalFwt=0;
1773 unsigned int nPoslova,nNiz,nJob,i,j,k,index,nLateJobs,nTotalLateJobs=0,nNr;
1774 unsigned int nLastJob,nMachines,nOdabrani,nMachine;
1775 double dAvgWeightsC;
1776 double dAvgWeightsE;
1785 nNr = nPoslova = (int) N.Get(nNiz);
1788 ReadConstraints(Constraints,nNiz,nPoslova,Precedence);
1790 MakeSetup(Duration,nNiz,nPoslova,m_setup_faktor,Setup);
1797 dEarlinessTardiness = 0;
1804 dClock = 0; dSetFitness = 0;
1807 dClock = 0; dSetFitness = 0;
1808 nLastJob = nPoslova;
1809 for(i=0; i<nPoslova; i++)
1810 { pRasporedjen[i] =
false;
1812 pIndex[i] = (uint) SortedReady[nNiz][i];
1814 nMachines = (uint) Machines[nNiz][0];
1864 for(uint i = 0; i < permutation->getSize(); i++) {
1865 Schedule[nNiz][i] = permutation->variables.at(i) + intGenotype->intValues.at(i) * 1000;
1868 for(
int kk=0; kk<nMachines; kk++){
1869 machineUseage.push_back(0);
1877 {
for(nJob=nPoslova ; nJob < this->max_jobs; nJob++)
1878 Schedule[nNiz][nJob] = 0;
1881 dClock = 0; nLastJob = nPoslova; dAvgWeights = 0; dCmax = 0;
1882 for(i=0; i<nMachines; i++)
1883 { MachineReady[i][0] = 0;
1884 pLastJob[i] = nPoslova;
1886 for(nJob = 0; nJob<nPoslova; nJob++)
1887 { index = (int) Schedule[nNiz][nJob];
1888 nMachine = index / 1000;
1889 index = index % 1000;
1890 dAvgWeights += WeightT[nNiz][index];
1891 if(m_dynamic && MachineReady[nMachine][0] < Ready[nNiz][index])
1892 MachineReady[nMachine][0] = Ready[nNiz][index];
1893 MachineReady[nMachine][0] += Duration[nNiz][index*nMachines + nMachine];
1895 MachineReady[nMachine][0] += Setup[pLastJob[nMachine]][index];
1896 pLastJob[nMachine] = index;
1897 dRez = MachineReady[nMachine][0] - Deadline.Get(nNiz,index);
1898 dLateness += dRez*WeightT.data[nNiz][index];
1899 dAvgWeightsC+= WeightC.data[nNiz][index];
1900 dAvgWeightsE+= WeightE.data[nNiz][index];
1901 machineUseage[nMachine] += Duration[nNiz][index*nMachines + nMachine];
1902 dCw += MachineReady[nMachine][0] * WeightC.data[nNiz][index];
1904 if(dRez>0&&dTmax<(dRez*WeightT.data[nNiz][index])){
1905 dTmax = dRez*WeightT.data[nNiz][index];
1908 if(dFmax<(MachineReady[nMachine][0] - Ready[nNiz][index])){
1909 dFmax = MachineReady[nMachine][0] - Ready[nNiz][index];
1912 if(dRez > 0) dTardiness += dRez*WeightT.data[nNiz][index];
1913 if(dRez > 0) nLateJobs ++;
1914 if(dRez > 0) dNwt += WeightN.data[nNiz][index];
1915 if(dRez < 0) dEarliness += WeightE.data[nNiz][index]*dRez;
1917 dFwt += MachineReady[nMachine][0] - Ready[nNiz][index];
1919 dFwt += MachineReady[nMachine][0];
1921 for(i=0; i<nMachines; i++)
1922 if(MachineReady[i][0] > dCmax)
1923 dCmax = MachineReady[i][0];
1925 double max=machineUseage[0]/dCmax, min =machineUseage[0]/dCmax;
1928 for(i=0; i<nMachines; i++){
1929 machineUseage[i]/= dCmax;
1930 dMus+=machineUseage[i];
1931 if(max<machineUseage[i])
1932 max = machineUseage[i];
1933 if(min>machineUseage[i])
1934 min = machineUseage[i];
1939 dAvgWeights /= nPoslova;
1940 dAvgWeightsC/= nPoslova;
1941 dAvgWeightsE/= nPoslova;
1942 double dAvgDuration = SP[nNiz][0] / nPoslova;
1943 dMus=(max - min)/(nPoslova * dAvgDuration);
1944 dTardiness /= (nPoslova * dAvgWeights * dAvgDuration);
1945 dEarliness /= (nPoslova * dAvgWeightsE * dAvgDuration);
1946 dNwt /= (nPoslova * dAvgWeights);
1947 dFwt /= dAvgDuration * nPoslova;
1948 dCmax /= nPoslova * dAvgDuration;
1949 dCw /=(nPoslova * dAvgWeightsC * dAvgDuration);
1950 dTmax /= (dAvgDuration*nPoslova);
1951 dFmax /= (dAvgDuration*nPoslova);
1953 {
case Twt: dRawFitness += dTardiness;
break;
1954 case Nwt: dRawFitness += dNwt;
break;
1955 case Fwt: dRawFitness += dFwt;
break;
1956 case Cmax: dRawFitness += dCmax;
break;
1957 case Ewt: dRawFitness += dEarliness;
break;
1960 nTotalLateJobs += nLateJobs;
1963 dTotalLateness += dLateness;
1964 dTotalTardiness += dTardiness;
1965 dTotalCmax += dCmax;
1966 dTotalEarliness += dEarliness;
1967 dTotalEarlinessTardiness+=dEarliness+dTardiness;
1971 dTotalFmax += dFmax;
1972 Fitness[nNiz][Twt] = dTardiness;
1975 Fitness[nNiz][Ewt] = dEarliness;
1978 Fitness[nNiz][ETwt] = dEarliness+dTardiness;
1988 Fitness[sets][Twt] = dTotalTardiness;
1989 Fitness[sets][Nwt] = dTotalNwt;
1990 Fitness[sets][Fwt] = dTotalFwt;
1991 Fitness[sets][Cmax] = dTotalCmax;
1992 Fitness[sets][ETwt] = dTotalEarlinessTardiness;
1993 Fitness[sets][Mus] = dTotalMus;
1994 Fitness[sets][Ewt] = dTotalEarliness;
1996 Fitness[sets][Tmax] = dTotalTmax;
1997 Fitness[sets][Fmax] = dTotalFmax;
2004void SchedulingEvalOp::EvaluateUnrelatedFP(FloatingPointP fp,
double &dRawFitness)
2006 double dClock, dRez, dSetFitness, dAvgWeights, dCmax, dTotalCmax=0;
2007 double dLateness, dTotalLateness=0, dTardiness, dTotalTardiness=0;
2008 double dNwt, dTotalNwt=0, dBest, dSPr, dSetupTime, dFwt, dTotalFwt=0;
2009 unsigned int nPoslova,nNiz,nJob,i,j,k,index,nLateJobs,nTotalLateJobs=0,nNr;
2010 unsigned int nLastJob,nMachines,nOdabrani,nMachine;
2019 nNr = nPoslova = (int) N.Get(nNiz);
2022 ReadConstraints(Constraints,nNiz,nPoslova,Precedence);
2024 MakeSetup(Duration,nNiz,nPoslova,m_setup_faktor,Setup);
2032 dClock = 0; dSetFitness = 0;
2033 nLastJob = nPoslova;
2034 for(i=0; i<nPoslova; i++)
2035 { pRasporedjen[i] =
false;
2037 pIndex[i] = (uint) SortedReady[nNiz][i];
2039 nMachines = (uint) Machines[nNiz][0];
2045 std::vector<double> machineBounds;
2046 machineBounds.resize(nMachines + 1);
2047 for(uint m = 0; m <= nMachines; m++)
2048 machineBounds[m] = (m) * 1. / nMachines;
2049 machineBounds[nMachines] = 1.000000001;
2050 std::vector<double> jobValues(nPoslova);
2051 std::vector<uint> jobIndexes(nPoslova);
2054 for(uint m = 0; m < nMachines; m++) {
2058 for(uint job = 0; job < nPoslova; job++)
2059 if(fp->realValue[job] >= machineBounds[m] && fp->realValue[job] < machineBounds[m + 1]) {
2060 jobValues[nJobs] = fp->realValue[job];
2061 jobIndexes[nJobs] = job;
2072 for(uint i = 0; i < nJobs - 1; i++)
2073 for(uint j = i + 1; j < nJobs; j++)
2074 if(jobValues[i] > jobValues[j]) {
2076 jobValues[i] = jobValues[j];
2079 jobIndexes[i] = jobIndexes[j];
2084 for(uint job = 0; job < nJobs; job++) {
2085 Schedule[nNiz][nJob] = jobIndexes[job] + m * 1000;
2098 {
for(nJob=nPoslova ; nJob < this->max_jobs; nJob++)
2099 Schedule[nNiz][nJob] = 0;
2102 dClock = 0; nLastJob = nPoslova; dAvgWeights = 0; dCmax = 0;
2103 for(i=0; i<nMachines; i++)
2104 { MachineReady[i][0] = 0;
2105 pLastJob[i] = nPoslova;
2107 for(nJob = 0; nJob<nPoslova; nJob++)
2108 { index = (int) Schedule[nNiz][nJob];
2109 nMachine = index / 1000;
2110 index = index % 1000;
2111 dAvgWeights += WeightT[nNiz][index];
2112 if(m_dynamic && MachineReady[nMachine][0] < Ready[nNiz][index])
2113 MachineReady[nMachine][0] = Ready[nNiz][index];
2114 MachineReady[nMachine][0] += Duration[nNiz][index*nMachines + nMachine];
2116 MachineReady[nMachine][0] += Setup[pLastJob[nMachine]][index];
2117 pLastJob[nMachine] = index;
2118 dRez = MachineReady[nMachine][0] - Deadline.Get(nNiz,index);
2119 dLateness += dRez*WeightT.data[nNiz][index];
2120 if(dRez > 0) dTardiness += dRez*WeightT.data[nNiz][index];
2121 if(dRez > 0) nLateJobs ++;
2122 if(dRez > 0) dNwt += WeightN.data[nNiz][index];
2124 dFwt += MachineReady[nMachine][0] - Ready[nNiz][index];
2126 dFwt += MachineReady[nMachine][0];
2128 for(i=0; i<nMachines; i++)
2129 if(MachineReady[i][0] > dCmax)
2130 dCmax = MachineReady[i][0];
2132 double dAvgDuration = SP[nNiz][0] / nPoslova;
2133 dAvgWeights /= nPoslova;
2134 dTardiness /= (nPoslova * dAvgWeights * dAvgDuration);
2135 dNwt /= (nPoslova * dAvgWeights);
2136 dFwt /= dAvgDuration * nPoslova;
2137 dCmax /= (nPoslova * dAvgDuration);
2139 {
case Twt: dRawFitness += dTardiness;
break;
2140 case Nwt: dRawFitness += dNwt;
break;
2141 case Fwt: dRawFitness += dFwt;
break;
2142 case Cmax: dRawFitness += dCmax;
break;
2145 nTotalLateJobs += nLateJobs;
2148 dTotalLateness += dLateness;
2149 dTotalTardiness += dTardiness;
2150 dTotalCmax += dCmax;
2151 Fitness[nNiz][Twt] = dTardiness;
2160 Fitness[sets][Twt] = dTotalTardiness;
2161 Fitness[sets][Nwt] = dTotalNwt;
2162 Fitness[sets][Fwt] = dTotalFwt;
2163 Fitness[sets][Cmax] = dTotalCmax;
2170void SchedulingEvalOp::EvaluateJobShop(
double &dRawFitness)
2172 double dL, dT, dTwt, dF, dFwt, dN, dNwt, dCmax;
2173 double dTotalT, dTotalTwt, dTotalF, dTotalFwt, dTotalN, dTotalNwt, dTotalCmax;
2174 double dClock, dAvgWeights, dTotalAvgLoad, dBestMachineValue, dAvgDuration;
2175 double dBest, dSetupTime, m1, m2, dNajkrace, dBegin;
2176 unsigned int nPoslova, nNiz, nJob, i, j, k, nNr, nOperations, nOperation, nNextOperation;
2177 unsigned int nMachines, nMachine, nSchedule, nMachineIndex, nJobsToEval, nBestJob, nNextMachine;
2178 unsigned int nBottleneck;
2181 dTotalT = dTotalTwt = dTotalF = dTotalFwt = dTotalN = dTotalNwt = dTotalCmax = 0;
2184 for(nNiz=0; nNiz<sets; nNiz++)
2185 { nNr = nPoslova = (int) N.Get(nNiz);
2189 if(pSamples[nNiz] ==
false)
2193 {
if(dRawFitness > m_LEFVal)
2197 MakeSetup(Duration,nNiz,nPoslova,m_setup_faktor,Setup);
2201 nOperations = nMachines = (uint) Machines[nNiz][0];
2202 dBestMachineValue = 0;
2203 nBottleneck = nMachines;
2204 for(j=0; j<nMachines; j++)
2205 { MachineReady[j][0] = 0;
2206 pLastJob[j] = nPoslova;
2207 pMachineScheduled[j] = 0;
2208 pOperationReady[j] = -1;
2209 pTotalMachineWork[j] = 0;
2210 pOperationsWaiting[j] = 0;
2211 pMachineValues[j] = 0;
2213 for(i=0; i<nPoslova; i++)
2214 { pTotalWorkRemaining[i] = 0;
2215 pTotalWorkDone[i] = 0;
2217 pJobReady[i] = Ready[nNiz][i];
2218 pOperationsScheduled[i] = 0;
2219 for(j=0; j<nOperations; j++)
2220 { k = (int) Duration[nNiz][i*nOperations + j];
2221 nMachine = k / 1000;
2223 pOperationsWaiting[nMachine]++;
2225 pTotalWorkRemaining[i] += k;
2226 Durations[i][j] = k;
2228 MachineIndex[i][j] = nMachine;
2229 pTotalMachineWork[nMachine] += k;
2232 nMachine = (int) MachineIndex[i][0];
2233 pOperationReady[nMachine] = pJobReady[i];
2236 dAvgDuration = dTotalAvgLoad / nPoslova;
2237 dTotalAvgLoad /= nMachines;
2243 memcpy(
Evaluator.m_dTermValuesArray[T_dd], Deadline.data[nNiz], nPoslova*
sizeof(
double));
2244 memcpy(
Evaluator.m_dTermValuesArray[T_w], WeightT.data[nNiz], nPoslova*
sizeof(
double));
2245 memcpy(
Evaluator.m_dTermValuesArray[T_TWK], pTotalWorkRemaining, nPoslova*
sizeof(
double));
2247 for(i=0; i<nMachines; i++)
2248 {
Evaluator.m_dTermValuesArray[T_MTWKav][i] = dTotalAvgLoad;
2249 Evaluator.m_dTermValuesArray[T_MTWK][i] = pTotalMachineWork[i];
2250 pMachineWorkRemaining[i] = pTotalMachineWork[i];
2252 memcpy(
Evaluator.m_dTermValuesArray[T_MTWK], pTotalMachineWork, nMachines*
sizeof(
double));
2254 for(nSchedule = 0; nSchedule < nPoslova*nMachines; nSchedule++)
2256 for(nMachine = 0; nMachine<nMachines; nMachine++)
2257 if(pOperationReady[nMachine] >= 0)
2259 for(i = nMachine; i < nMachines; i++)
2260 {
if(pOperationReady[i] < 0)
2262 m1 = MAX(MachineReady[i][0],pOperationReady[i]);
2263 m2 = MAX(MachineReady[nMachine][0],pOperationReady[nMachine]);
2267 dClock = MAX(MachineReady[nMachine][0], pOperationReady[nMachine]);
2270 for(nJob=0; nJob<nPoslova; nJob++)
2271 { nOperation = pOperationsScheduled[nJob];
2272 if(nOperation == nMachines)
continue;
2273 nMachineIndex = (int) MachineIndex[nJob][nOperation];
2274 if(nMachineIndex != nMachine)
continue;
2276 dNajkrace = MAX(dClock, pJobReady[nJob]) + Durations[nJob][nOperation];
2278 { dBegin = MAX(dClock, pJobReady[nJob]);
2279 if(dNajkrace > dBegin + Durations[nJob][nOperation])
2280 dNajkrace = dBegin + Durations[nJob][nOperation];
2287 for(nJob=0; nJob<nPoslova; nJob++)
2288 { nOperation = pOperationsScheduled[nJob];
2289 if(nOperation == nMachines)
continue;
2290 nMachineIndex = (int) MachineIndex[nJob][nOperation];
2291 if(nMachineIndex != nMachine)
continue;
2294 if(pJobReady[nJob] > dClock)
continue;
2296 dBegin = MAX(pJobReady[nJob],dClock);
2297 if(dBegin > dNajkrace)
2300 pIndex[nJobsToEval] = nJob;
2306MNOPr[nMachine] = nOperations - pMachineScheduled[nMachine]
2307MTWKav = dTotalAvgLoad;
2308MTWK[nMachine] = pTotalMachineWork[nMachine];
2309MNOPw[nMachine] = pOperationsWaiting[nMachine];
2310MTWKr[nMachine] = pMachineWorkRemaining[nMachine];
2311MUTL[nMachine] = (pTotalMachineWork[nMachine] - pMachineWorkRemaining[nMachine]) / dClock;
2315 Evaluator.m_dTermValuesArray[T_MNOPr][nMachine] = nOperations - pMachineScheduled[nMachine];
2316 Evaluator.m_dTermValuesArray[T_MNOPw][nMachine] = pOperationsWaiting[nMachine];
2317 Evaluator.m_dTermValuesArray[T_MTWKr][nMachine] = pMachineWorkRemaining[nMachine];
2319 Evaluator.m_dTermValuesArray[T_MUTL][nMachine] = 1;
2321 Evaluator.m_dTermValuesArray[T_MUTL][nMachine] = (pTotalMachineWork[nMachine] - pMachineWorkRemaining[nMachine]) / dClock;
2324 nSavedIndex = pIndex[nMachine];
2325 pIndex[nMachine] = nMachine;
2329 pMachineValues[nMachine] = pVrijednosti[nMachine];
2331* dBestMachineValue = pMachineValues[0];
2333 for(i=0; i<nMachine; i++)
2334 if(pMachineValues[i] > dBestMachineValue)
2335 { dBestMachineValue = pMachineValues[i];
2341 if(pMachineValues[nMachine] >= dBestMachineValue)
2342 { dBestMachineValue = pMachineValues[nMachine];
2343 nBottleneck = nMachine;
2346 if(nMachine == nBottleneck)
2350 pIndex[nMachine] = nSavedIndex;
2356 for(i=0; i<nJobsToEval; i++)
2358 nOperation = pOperationsScheduled[nJob];
2359 Evaluator.m_dTermValuesArray[T_pt][nJob] = Durations[nJob][nOperation];
2360 Evaluator.m_dTermValuesArray[T_CLK][nJob] = dClock;
2361 Evaluator.m_dTermValuesArray[T_AR][nJob] = POS(pJobReady[nJob] - dClock);
2362 Evaluator.m_dTermValuesArray[T_STP][nJob] = Setup[pLastJob[nMachine]][nJob];
2363 Evaluator.m_dTermValuesArray[T_Sav][nJob] = pSetupAvg[pLastJob[nMachine]];
2364 Evaluator.m_dTermValuesArray[T_age][nJob] = POS(dClock - Ready[nNiz][nJob]);
2365 Evaluator.m_dTermValuesArray[T_NOPr][nJob] = nOperations - pOperationsScheduled[nJob];
2366 Evaluator.m_dTermValuesArray[T_PTav][nJob] = PTimeAvg[nNiz][nMachine];
2367 Evaluator.m_dTermValuesArray[T_TWKr][nJob] = pTotalWorkRemaining[nJob];
2368 if(pTotalWorkDone[nJob] == 0)
2369 Evaluator.m_dTermValuesArray[T_HTR][nJob] = 1;
2371 Evaluator.m_dTermValuesArray[T_HTR][nJob] = POS(dClock - Ready[nNiz][nJob]) / pTotalWorkDone[nJob];
2377 dBest = pVrijednosti[pIndex[0]];
2378 nBestJob = pIndex[0];
2379 for(i=1; i<nJobsToEval; i++)
2380 {
if(pVrijednosti[pIndex[i]] < dBest)
2381 { dBest = pVrijednosti[pIndex[i]];
2382 nBestJob = pIndex[i];
2387 nOperation = pOperationsScheduled[nBestJob];
2388 pOperationsScheduled[nBestJob] += 1;
2389 pTotalWorkRemaining[nBestJob] -= Durations[nBestJob][nOperation];
2390 pMachineWorkRemaining[nMachine] -= Durations[nBestJob][nOperation];
2391 pTotalWorkDone[nBestJob] += Durations[nBestJob][nOperation];
2393 { dSetupTime = Setup[pLastJob[nMachine]][nBestJob];
2394 pLastJob[nMachine] = nBestJob;
2398 dClock = MAX(dClock, pJobReady[nBestJob]);
2399 MachineReady[nMachine][0] = dClock + dSetupTime + Durations[nBestJob][nOperation];
2400 pJobReady[nBestJob] = MachineReady[nMachine][0];
2401 if(nOperation < nOperations-1)
2402 { nNextMachine = (int) MachineIndex[nBestJob][pOperationsScheduled[nBestJob]];
2403 if(pOperationReady[nNextMachine] < 0)
2404 pOperationReady[nNextMachine] = pJobReady[nBestJob];
2406 if(pOperationReady[nNextMachine] > pJobReady[nBestJob])
2407 pOperationReady[nNextMachine] = pJobReady[nBestJob];
2410 pOperationReady[nMachine] = -1;
2411 pOperationsWaiting[nMachine] = 0;
2412 for(j=0; j<nPoslova; j++)
2413 { nNextOperation = pOperationsScheduled[j];
2414 if(nNextOperation == nMachines)
continue;
2415 nNextMachine = (int) MachineIndex[j][nNextOperation];
2416 if(nNextMachine != nMachine)
continue;
2417 pOperationsWaiting[nMachine]++;
2418 if(pOperationReady[nMachine] < 0)
2419 pOperationReady[nMachine] = pJobReady[j];
2421 if(pOperationReady[nMachine] > pJobReady[j])
2422 pOperationReady[nMachine] = pJobReady[j];
2424 nOperation = (int) pMachineScheduled[nMachine];
2425 pMachineScheduled[nMachine] += 1;
2426 Schedule[nNiz][nMachine * nPoslova + nOperation] = nBestJob;
2431 {
for(i=nPoslova*nMachines ; i < (uint)Schedule.GetCol(); i++)
2432 Schedule[nNiz][i] = 0;
2436 dCmax = dF = dFwt = dT = dTwt = dN = dNwt = 0;
2437 for(j=0; j<nPoslova; j++)
2438 { dAvgWeights += WeightT[nNiz][j];
2439 if(dCmax < pJobReady[j])
2440 dCmax = pJobReady[j];
2441 dF += pJobReady[j] - Ready[nNiz][j];
2442 dFwt += (pJobReady[j] - Ready[nNiz][j]) * WeightT[nNiz][j];
2443 if(pJobReady[j] > Deadline[nNiz][j])
2445 dNwt += WeightT[nNiz][j];
2446 dL = pJobReady[j] - Deadline[nNiz][j];
2448 dTwt += WeightT[nNiz][j] * dL;
2451 dAvgWeights /= nPoslova;
2452 dCmax /= nPoslova*dAvgDuration;
2454 dFwt /= nPoslova*dAvgWeights*dAvgDuration;
2456 dTwt /= nPoslova*dAvgWeights*dAvgDuration;
2458 dNwt /= nPoslova*dAvgWeights;
2459 dTotalCmax += dCmax;
2468 {
case Twt: dRawFitness += dTwt;
break;
2469 case Nwt: dRawFitness += dNwt;
break;
2470 case Fwt: dRawFitness += dFwt;
break;
2471 case Cmax: dRawFitness += dCmax;
break;
2483 Fitness.data[sets][Twt] = dTotalTwt;
2484 Fitness.data[sets][Nwt] = dTotalNwt;
Fitness for minimization problems.
Permutation class - implements genotype as a vector of indices 0..(n-1) (permutation of indices)
bool initialize(StateP)
Initialize the evaluator. Called before first evaluation occurs.
FitnessP evaluate(IndividualP individual)
Evaluate a single individual. Method must create and return a Fitness object.
void registerParameters(StateP)
Register evaluator parameters. Called before EvaluateOp::initialize method.
void setName(std::string name)
Set primitive's name.
Terminal tree node class (Tree genotype).
Tree class - implements genotype as a tree.
Tree * copy()
Create an identical copy of the genotype object.