Modernized GAlib  3.0.0 current
GASStateGA.h
1 /* ----------------------------------------------------------------------------
2  mbwall 28jul94
3  Copyright (c) 1995 Massachusetts Institute of Technology
4  all rights reserved
5 ---------------------------------------------------------------------------- */
6 
7 #pragma once
8 
9 #include "GABaseGA.h"
10 
16 {
17  public:
18  GADefineIdentity("GASteadyStateGA", GAID::SteadyStateGA);
19 
20  static GAParameterList &registerDefaultParameters(GAParameterList &);
21 
22  public:
23  explicit GASteadyStateGA(const GAGenome &);
24  explicit GASteadyStateGA(const GAPopulation &);
26  GASteadyStateGA &operator=(const GASteadyStateGA &);
27  ~GASteadyStateGA() override;
28  void copy(const GAGeneticAlgorithm &) override;
29 
30  void initialize(unsigned int seed = 0) override;
31  void step() override;
32  GASteadyStateGA &operator++()
33  {
34  step();
35  return *this;
36  }
37 
38  int setptr(const std::string &name, const void *value) override;
39  int get(const char *name, void *value) const override;
40 
41  int minimaxi() const override { return minmax; }
42  int minimaxi(int m) override;
43 
44  const GAPopulation &population() const override { return *pop; }
45  const GAPopulation &population(const GAPopulation &) override;
46  int populationSize() const override { return pop->size(); }
47  int populationSize(unsigned int n) override;
48  GAScalingScheme &scaling() const override { return pop->scaling(); }
49  GAScalingScheme &scaling(const GAScalingScheme &s) override
50  { /* tmpPop->scaling(s); */
51  return GAGeneticAlgorithm::scaling(s);
52  }
53  GASelectionScheme &selector() const override { return pop->selector(); }
54  GASelectionScheme &selector(const GASelectionScheme &s) override
55  { /* tmpPop->selector(s); */
56  return GAGeneticAlgorithm::selector(s);
57  }
58  void objectiveFunction(GAGenome::Evaluator f) override;
59  void objectiveData(const GAEvalData &v) override;
60 
61  float pReplacement() const { return pRepl; }
62  float pReplacement(float p);
63  int nReplacement() const { return nRepl; }
64  int nReplacement(unsigned int n);
65 
66  protected:
67  GAPopulation *tmpPop; // temporary population for replacements
68  float pRepl; // percentage of population to replace each gen
69  unsigned int nRepl; // how many of each population to replace
70  short which; // 0 if prepl, 1 if nrepl
71 };
72 
73 inline std::ostream &operator<<(std::ostream &os, GASteadyStateGA &arg)
74 {
75  arg.write(os);
76  return (os);
77 }
78 inline std::istream &operator>>(std::istream &is, GASteadyStateGA &arg)
79 {
80  arg.read(is);
81  return (is);
82 }
This is the basic interface for the object that contains evaluation data.
Definition: GAEvalData.h:15
The base GA class is virtual - it defines the core data elements and parts of the interface that are ...
Definition: GABaseGA.h:89
The base genome class just defines the genome interface - how to mutate, crossover,...
Definition: GAGenome.h:200
Parameter List.
Definition: GAParameter.h:83
Definition: GAPopulation.h:66
Definition: GAScaling.h:46
Definition: GASelector.h:55
Steady-state genetic algorithm class.
Definition: GASStateGA.h:16
void initialize(unsigned int seed=0) override
Undefined for the base class.
void step() override
Evolve by one generation.