Population.hpp 1.41 KB
Newer Older
Imanol Pérez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#ifndef POPULATIONDEF
#define POPULATIONDEF

//////////////////////////////////////////////////////
//                                                  //
//             Class for the population             //
//                                                  //
//                  Imanol Perez                    //
//                  December 2016                   //
//                                                  //
//////////////////////////////////////////////////////

#include <cmath>
#include "Exception.hpp"//  This class throws errors using the class "error"
#include "Quote.hpp"
#include "Stock.hpp"
#include "Organism.hpp"
#include <algorithm>

class Population;

class Population
{
public:
   Population(); // constructor
   Population(Stock, int, int); // constructor

   void addOrganism(Organism); // Add organism
   double fitness(Stock&, int, int); // fitness function: gives the returns of the organism in a random period of a specific length
   double returns(int); // fitness function: gives the returns of the organism
   Population top20(void); // returns the strongest 20% organisms
   void crossover(void); // performs crossover
   void mutation(void); // performs mutation of the new generation
   
   Stock stock;
   Organism* organisms;
   int size, filled, max_ma;

   //output
   friend std::ostream& operator<<(std::ostream&, Population&);


};


#endif