#include #include "Genetic.h" /* Gene class */ /** * Default constructor. */ Gene::Gene(){ task_index = -1; proc_index = -1; level = -1; } /** * Constructor * * @param task the index of the task * @param proc the index of the processor * @param lev the topological level of the task */ Gene::Gene(int task,int proc,int lev){ task_index = task; proc_index = proc; level = lev; } /** * Copy operator */ Gene& Gene::operator=(const Gene& clone){ task_index = clone.task_index; proc_index = clone.proc_index; level = clone.level; return *this; } /** * Method printing the gene's configuration */ void Gene::print(){ printf("(%d, %d, %d)", task_index, proc_index, level); } /** * the default constructor */ /* Chromosome class */ Chromosome::Chromosome(){ makespan=0; fitness=0; evalT1=0; evalT2=0; evalT3=0; loadBalance=0; } /** * Copy operator */ Chromosome& Chromosome::operator=(const Chromosome& clone){ makespan=clone.makespan; fitness=clone.fitness; evalT1=clone.evalT1; evalT2=clone.evalT2; evalT3=clone.evalT3; loadBalance=clone.loadBalance; genes=clone.genes; f_nodes=clone.f_nodes; return *this; } /** * Iterator operator */ Gene& Chromosome::operator[](int poz){ if(poz >= 0 && poz <(int)genes.size()){ return genes[poz]; } return null_gene; } /** * Method that adds a gene to the genes list * * @param g the new gene */ void Chromosome::append(Gene &g){ genes.push_back(g); } /** * Method that returns the size of the genes list * * @return the size */ int Chromosome::size(void){ return genes.size(); } /** * Method that initializes the population */ void Chromosome::init(void){ fitness = 0; makespan = 0; loadBalance = 0; evalT1 = 0; evalT2 = 0; evalT3 = 0; } /** * Method that inserts a gene to the genes list in the specified position * * @param g the new gene * @param poz the position in the list */ void Chromosome::insert(Gene g,int poz){ genes.insert(genes.begin()+poz, g); } /** * Method that removes a gene from the genes list * * @param poz the gene's position * @return the removed gene */ Gene Chromosome::remove(int poz){ Gene g = genes[poz]; genes.erase(genes.begin()+poz); return g; } /** * Method that prints the chromosome's configuration */ void Chromosome::print() const{ printf("%f %f %lf %lf %lf %lf\n", makespan, fitness, evalT1, evalT2, evalT3, loadBalance); printf("[%i]:", genes.size()); for (unsigned int i=0;i