CEvolutionaryAlgorithm.h 1.83 KB
Newer Older
kruger's avatar
kruger 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
47
/*
 * CEvolutionaryAlgorithm.h
 *
 *  Created on: 22 juin 2009
 *      Author: maitre
 */

#ifndef CEVOLUTIONARYALGORITHM_H_
#define CEVOLUTIONARYALGORITHM_H_
#include <stdlib.h>
#include <string>
#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
48

kruger's avatar
kruger committed
49
  void showPopulationStats(struct timeval beginTime);
maitre's avatar
maitre committed
50
51
52
53
  void generateGnuplotScript();
  void generateRScript();

  void outputGraph();
kruger's avatar
kruger committed
54
55
56
57
58
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;
};

#ifdef WIN32
int gettimeofday(struct timeval* tp, void* tzp);
void timersub( const timeval * tvp, const timeval * uvp, timeval* vvp );
#endif

#endif /* CEVOLUTIONARYALGORITHM_H_ */