// chromo.h
// Declaration of class Chromo
// Thomas Pederson, 950505

#ifndef CHROMO
#define CHROMO

#include "global.h"
#include "gene.h"
#include <iostream.h>

class Chromo
{
public:
   Chromo(unsigned int _chromoLength, Gene *_genePool[]);
   ~Chromo();
   
   // Copy constructor.
   Chromo& Chromo::operator=(Chromo& original);

   // Chromosome initialization.
   void init();

   // Calculates (if necessary) and returns chromosome evaluation.
   eval_t eval();

   // Sets chromosome's modified evaluation (fitness).
   eval_t setModEval(eval_t _modEval) {return (myModEval = _modEval);}

   // Returns chromosome's modified evaluation (fitness).
   eval_t getModEval() {return myModEval;}

   // Returns chromosome's evaluation (fitness).
   eval_t getEval() {return myEval;}

   // Mates this chromosome with partner resulting in two new offsprings, child1 and child2.
   void mate(float _crossover, cross_t crossoverType, float _mutation, Chromo& partner,
	     Chromo& child1, Chromo& child2);

   // Returns chromosome length.
   unsigned int getLength() {return chromoLength;}

   // Prints chromosome information to stream.
   friend ostream& operator<<(ostream& outStr, Chromo& chromo);
   
private:
   unsigned int chromoLength; // chromosome length
   eval_t myEval; // chromosome evaluation
   eval_t myModEval; // chromosome modified evaluation (fitness)
   Gene **genePool; // pointer to original gene pool vector
   Gene **myGenePool; // private gene pool vector

   // Keeping track of used genes during crossover.
   int Chromo::isUsed(Gene *gene, Gene *usedGene[], int noOfUsedGenes);

   // Performs crossover using parent1 and parent2 as templates.
   // This chromosome is assigned the result. 
   void crossover(cross_t crossoverType, Chromo& parent1, Chromo& parent2);

   // Performs mutation on this chromosome.
   void mutate();

   // Modified random generator.
   unsigned int myRand();
};

#endif















