Modernized GAlib  3.0.0 current
gaid.h
1 /* ----------------------------------------------------------------------------
2  mbwall 7may95
3  Copyright (c) 1995 Massachusetts Institute of Technology
4  all rights reserved
5 ---------------------------------------------------------------------------- */
6 
7 #pragma once
8 
19 class GAID
20 {
21  public:
22  enum
23  {
24  BaseGA = 0,
25  SimpleGA,
26  SteadyStateGA,
27  IncrementalGA,
28  DemeGA,
29 
30  Population = 10,
31 
32  Scaling = 15,
33  NoScaling,
34  LinearScaling,
35  SigmaTruncationScaling,
36  PowerLawScaling,
37  Sharing,
38 
39  Selection = 40,
40  RankSelection,
41  RouletteWheelSelection,
42  TournamentSelection,
43  UniformSelection,
44  SRSSelection,
45  DSSelection,
46 
47  Genome = 50,
48  BinaryStringGenome,
49  BinaryStringGenome2D,
50  BinaryStringGenome3D,
51  Bin2DecGenome,
52  ListGenome,
53  TreeGenome,
54  ArrayGenome,
55  ArrayGenome2D,
56  ArrayGenome3D,
57  ArrayAlleleGenome,
58  ArrayAlleleGenome2D,
59  ArrayAlleleGenome3D,
60  StringGenome,
61  FloatGenome,
62  IntGenome,
63  DoubleGenome
64  };
65 
66  bool sameClass(const GAID &b) const { return (classID() == b.classID()); }
67  virtual const char *className() const { return "no class"; }
68  virtual int classID() const { return 0; }
69  virtual ~GAID() = default;
70 };
71 
72 // Here are the ID values for the GA library:
73 //
74 // class range
75 // ---------------------------------------------
76 // reserved 0-199
77 // anyone can use these 200-
78 //
79 // The ID numbers for built-in classes are enumerated in the GAID class. Sorry
80 // but I had to do the dimension at the end of the names rather than at the
81 // beginning since you cannot use a digit to start a variable name.
82 // If you derive your own polymorphic class or specialize a
83 // template class, then give it its own ID number and class name in the
84 // specialization (see the string and real number specializations for examples)
85 // Use these macros to define the identity for your class. If you do not use
86 // these macros then your object will be identity-less.
87 // Here's how to use the macro.
88 //
89 // class GASimpleGA : public GA {
90 // public:
91 // GADefineClassIdentity("GASimpleGA", 1);
92 // ...
93 // };
94 //
95 // Notice that your template classes will all have the same name using this
96 // method unless you specialize. For example, GA1DArrayGenome<char> and
97 // GA1DArrayGenome<int> will both have the name GA1DArrayGenome as well as
98 // the same number. Beware.
99 
100 #define GADefineIdentity(name, id) \
101  const char *className() const override { return name; } \
102  int classID() const override { return id; }
103 
104 #define GADeclareIdentity() \
105  const char *className() const override; \
106  int classID() const override
107 
108 #define GADefineIdentitySRC(clss, name, id) \
109  const char *clss ::className() const { return name; } \
110  int clss ::classID() const { return id; }
This defines the identifiers for polymorphic classes.
Definition: gaid.h:20