#include "Evaluator.h" #include "Genetic.h" #include #include #include #define DEBUG 0 using namespace std; /** * the default constructor */ TaskInfo::TaskInfo(){ start = 0; end = 0; proc_index = -1; } /** * the default constructor */ Evaluator::Evaluator(){} /** * the constructor * * @param TG the input graph of tasks * @param PG the input graph of processors */ Evaluator::Evaluator(TaskGraf &TG, ProcesorGraf &PG){ tasks = TG; procs = PG; proc_time = (int*)calloc(procs.nr_noduri , sizeof(int)); task_info = (TaskInfo*)calloc(tasks.nr_noduri , sizeof(TaskInfo));; } /** * Method that evaluates one chromosome, computing its makespan, fitness, etc * * @param ch the chromosome we want to evaluate */ void Evaluator::evaluateIndividual(Chromosome &ch){ int i,j; Gene g; int time,start,end; int cost_com, id_proc, id_task; tasks.init(); procs.init(); if (DEBUG == 1) ch.print(); //initializes the task information for (i=0;icost; id_task = ((Muchie *)(tasks.noduri[g.task_index].predecesori[j]))->predecesor->id; id_proc = task_info[id_task].proc_index; if (DEBUG == 1) printf("T%d pe P%d - cost=%d\n",id_task,id_proc,cost_com); if (id_proc == g.proc_index) cost_com = 0; else cost_com *= procs.noduri[g.proc_index].cost_comm[id_proc]; if (DEBUG == 1) printf("Cost comm : %d\n",cost_com); if (time < cost_com + task_info[id_task].end) time = cost_com + task_info[id_task].end; if (DEBUG == 1) printf("Time : %d\n",time); } start = time; time += tasks.noduri[g.task_index].cost * procs.noduri[g.proc_index].cost; end = time; //tasks.noduri[g.task_index].setProcesor(g.proc_index,start,end); //procs.noduri[g.proc_index].time = time; //procs.noduri[g.proc_index].addTask(g.task_index); task_info[g.task_index].start = start; task_info[g.task_index].end = end; task_info[g.task_index].proc_index = g.proc_index; proc_time[g.proc_index] = time; if (DEBUG == 1) printf("Time update on P%d : %d\n\n",g.proc_index,time); } int makespan = proc_time[0]; for (i=1;i makespan) makespan = proc_time[i]; if (DEBUG == 2) printf("makespan = %d\n",makespan); ch.makespan = makespan; double av = 0; double min = 30000; for (i=0;i &chs){ int i; for (i=0;i<(int)chs.size();i++){ if (chs[i].fitness == 0) evaluateIndividual(chs[i]); } double best = chs[0].makespan; for (i=0;i<(int)chs.size();i++){ if (chs[i].makespan < best) best = chs[i].makespan; } for (i=0;i<(int)chs.size();i++){ chs[i].evalT3 = best / chs[i].makespan; chs[i].fitness = chs[i].evalT1 * chs[i].evalT2 * chs[i].evalT3 * chs[i].evalT3 * chs[i].evalT3 ; if (DEBUG == 1) printf("Fit = %f\n",chs[i].fitness); } }