CEvolutionaryAlgorithm.h 2.15 KB
Newer Older
kruger's avatar
kruger committed
1 2 3 4 5 6 7 8 9 10 11
/*
 * CEvolutionaryAlgorithm.h
 *
 *  Created on: 22 juin 2009
 *      Author: maitre
 */

#ifndef CEVOLUTIONARYALGORITHM_H_
#define CEVOLUTIONARYALGORITHM_H_
#include <stdlib.h>
#include <string>
12
#include <time.h>
kruger's avatar
kruger committed
13 14 15 16
#include "CEvolutionaryAlgorithm.h"
#include "CSelectionOperator.h"
#include "CPopulation.h"
#include "CStoppingCriterion.h"
kruger's avatar
kruger committed
17
#include "CComUDPLayer.h"
kruger's avatar
kruger committed
18 19 20 21 22 23 24 25 26 27
#ifdef WIN32
#include <windows.h>
#endif

class Parameters;
class CGnuplot;

class CEvolutionaryAlgorithm {
public:

kruger's avatar
kruger committed
28
 /* CEvolutionaryAlgorithm( size_t parentPopulationSize,
kruger's avatar
kruger committed
29 30 31 32 33
			 size_t offspringPopulationSize,
			 float selectionPressure, float replacementPressure, float parentReductionPressure, float offspringReductionPressure,
			 CSelectionOperator* selectionOperator, CSelectionOperator* replacementOperator,
			 CSelectionOperator* parentReductionOperator, CSelectionOperator* offspringReductionOperator,
			 float pCrossover, float pMutation,
kruger's avatar
kruger committed
34
			 float pMutationPerGene);*/
kruger's avatar
kruger committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

  CEvolutionaryAlgorithm( Parameters* params );
  virtual void initializeParentPopulation() = 0;

  size_t* getCurrentGenerationPtr(){ return &currentGeneration;}
  void addStoppingCriterion(CStoppingCriterion* sc);
  void runEvolutionaryLoop();
  bool allCriteria();
  CPopulation* getPopulation(){ return population;}
  size_t getCurrentGeneration() { return currentGeneration;}
public:
  size_t currentGeneration;
  CPopulation* population;
  size_t reduceParents;
  size_t reduceOffsprings;
maitre's avatar
maitre committed
50

kruger's avatar
kruger committed
51 52 53
  //methods and variables for remote island model
  size_t treatedIndividuals;
  size_t numberOfClients;
kruger's avatar
kruger committed
54
  size_t myClientNumber;
kruger's avatar
kruger committed
55 56 57 58 59 60
  CComUDPServer *server;
  CComUDPClient **Clients;
  void initializeClients();
  void receiveIndividuals();
  void sendIndividual();

61 62 63
#ifdef WIN32
  void showPopulationStats(clock_t beginTime);
#else
kruger's avatar
kruger committed
64
  void showPopulationStats(struct timeval beginTime);
65
#endif
maitre's avatar
maitre committed
66 67 68 69
  void generateGnuplotScript();
  void generateRScript();

  void outputGraph();
kruger's avatar
kruger committed
70 71 72
  Parameters* params;

  CGnuplot* gnuplot;
73 74
  double currentAverageFitness;
  double currentSTDEV;
75

76
  virtual ~CEvolutionaryAlgorithm();
kruger's avatar
kruger committed
77 78 79 80 81 82 83 84

  std::vector<CStoppingCriterion*> stoppingCriteria;

  std::string* outputfile;
  std::string* inputfile;
};

#endif /* CEVOLUTIONARYALGORITHM_H_ */