CEvolutionaryAlgorithm.h 1.78 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
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
47
48
#include "CEvolutionaryAlgorithm.h"
#include "CSelectionOperator.h"
#include "CPopulation.h"
#include "CStoppingCriterion.h"
#ifdef WIN32
#include <windows.h>
#endif

class Parameters;
class CGnuplot;

class CEvolutionaryAlgorithm {
public:

  CEvolutionaryAlgorithm( size_t parentPopulationSize,
			 size_t offspringPopulationSize,
			 float selectionPressure, float replacementPressure, float parentReductionPressure, float offspringReductionPressure,
			 CSelectionOperator* selectionOperator, CSelectionOperator* replacementOperator,
			 CSelectionOperator* parentReductionOperator, CSelectionOperator* offspringReductionOperator,
			 float pCrossover, float pMutation,
			 float pMutationPerGene);

  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
49

50
51
52
#ifdef WIN32
  void showPopulationStats(clock_t beginTime);
#else
kruger's avatar
kruger committed
53
  void showPopulationStats(struct timeval beginTime);
54
#endif
maitre's avatar
maitre committed
55
56
57
58
  void generateGnuplotScript();
  void generateRScript();

  void outputGraph();
kruger's avatar
kruger committed
59
60
61
62
63
64
65
66
67
68
69
  Parameters* params;

  CGnuplot* gnuplot;

  std::vector<CStoppingCriterion*> stoppingCriteria;

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

#endif /* CEVOLUTIONARYALGORITHM_H_ */