Modernized GAlib
3.0.0 current
|
1 dimensional Array Genome More...
#include <GA1DArrayGenome.hpp>
Public Member Functions | |
GADefineIdentity ("GA1DArrayGenome", GAID::ArrayGenome) | |
GA1DArrayGenome (unsigned int length, GAGenome::Evaluator f=nullptr, void *u=nullptr) | |
GA1DArrayGenome (const GA1DArrayGenome< T > &orig) | |
GA1DArrayGenome< T > & | operator= (const GAGenome &orig) |
GA1DArrayGenome< T > & | operator= (const T array[]) |
GAGenome * | clone (GAGenome::CloneMethod flag=CloneMethod::CONTENTS) const override |
void | copy (const GAGenome &orig) override |
int | read (std::istream &) override |
int | write (std::ostream &os) const override |
bool | equal (const GAGenome &c) const override |
const T & | gene (unsigned int x=0) const |
T & | gene (unsigned int x, const T &value) |
int | length () const |
int | length (int x) |
virtual int | resize (int len) |
int | resizeBehaviour (unsigned int lower, unsigned int upper) |
int | resizeBehaviour () const |
void | copy (const GA1DArrayGenome< T > &orig, unsigned int r, unsigned int x, unsigned int l) |
void | swap (unsigned int i, unsigned int j) |
![]() | |
GAArray (unsigned int s) | |
GAArray (const GAArray< T > &orig) | |
GAArray< T > & | operator= (const GAArray< T > &orig) |
GAArray< T > * | clone () |
const T & | operator[] (unsigned int i) const |
T & | operator[] (unsigned int i) |
void | copy (const GAArray< T > &orig) |
void | copy (const GAArray< T > &orig, unsigned int dest, unsigned int src, unsigned int length) |
void | move (unsigned int dest, unsigned int src, unsigned int length) |
void | swap (unsigned int i, unsigned int j) |
int | size () const |
int | size (unsigned int n) |
bool | equal (const GAArray< T > &b, unsigned int dest, unsigned int src, unsigned int length) const |
template<class U > | |
bool | operator== (const GAArray< U > &rhs) const |
template<class U > | |
bool | operator!= (const GAArray< U > &rhs) const |
![]() | |
GADefineIdentity ("GAGenome", GAID::Genome) | |
GAGenome (Initializer i=nullptr, Mutator m=nullptr, Comparator c=nullptr) | |
GAGenome (const GAGenome &orig) | |
GAGenome & | operator= (const GAGenome &arg) |
virtual bool | notequal (const GAGenome &g) const |
int | nevals () const |
float | score () const |
float | score (float s) |
float | fitness () |
float | fitness (float f) |
GAGeneticAlgorithm * | geneticAlgorithm () const |
GAGeneticAlgorithm * | geneticAlgorithm (GAGeneticAlgorithm &g) |
void * | userData () const |
void * | userData (void *u) |
GAEvalData * | evalData () const |
GAEvalData * | evalData (const GAEvalData &o) |
float | evaluate (bool flag=false) const |
Evaluator | evaluator () const |
Evaluator | evaluator (Evaluator f) |
void | initialize () |
Initializer | initializer () const |
Initializer | initializer (Initializer op) |
int | mutate (float p) |
Mutator | mutator () const |
Mutator | mutator (Mutator op) |
float | compare (const GAGenome &g) const |
Comparator | comparator () const |
Comparator | comparator (Comparator c) |
SexualCrossover | crossover (SexualCrossover f) |
SexualCrossover | sexual () const |
AsexualCrossover | crossover (AsexualCrossover f) |
AsexualCrossover | asexual () const |
![]() | |
bool | sameClass (const GAID &b) const |
virtual const char * | className () const |
virtual int | classID () const |
Static Public Member Functions | |
static int | SwapMutator (GAGenome &c, float pmut) |
Randomly swap elements in the array. More... | |
static float | ElementComparator (const GAGenome &a, const GAGenome &b) |
How similar are two genomes. More... | |
static int | UniformCrossover (const GAGenome &p1, const GAGenome &p2, GAGenome *c1, GAGenome *c2) |
Randomly take bits from each parent. More... | |
static int | OnePointCrossover (const GAGenome &p1, const GAGenome &p2, GAGenome *c1, GAGenome *c2) |
static int | TwoPointCrossover (const GAGenome &p1, const GAGenome &p2, GAGenome *c1, GAGenome *c2) |
static int | EvenOddCrossover (const GAGenome &p1, const GAGenome &p2, GAGenome *c1, GAGenome *c2) |
static int | PartialMatchCrossover (const GAGenome &p1, const GAGenome &p2, GAGenome *c1, GAGenome *c2) |
static int | OrderCrossover (const GAGenome &p1, const GAGenome &p2, GAGenome *c1, GAGenome *c2) |
static int | CycleCrossover (const GAGenome &p1, const GAGenome &p2, GAGenome *c1, GAGenome *c2) |
![]() | |
static void | NoInitializer (GAGenome &) |
static int | NoMutator (GAGenome &, float) |
static float | NoComparator (const GAGenome &, const GAGenome &) |
Protected Attributes | |
unsigned int | nx |
unsigned int | minX |
unsigned int | maxX |
![]() | |
std::vector< T > | a |
the contents of the array | |
![]() | |
float | _score |
float | _fitness |
bool | _evaluated |
unsigned int | _neval |
GAGeneticAlgorithm * | ga |
void * | ud |
Evaluator | eval |
GAEvalData * | evd |
Mutator | mutr |
Initializer | init |
Comparator | cmp |
SexualCrossover | sexcross |
AsexualCrossover | asexcross |
Additional Inherited Members | |
![]() | |
enum class | Dimension { LENGTH = 0 , WIDTH = 0 , HEIGHT = 1 , DEPTH = 2 } |
enum class | CloneMethod { CONTENTS = 0 , ATTRIBUTES = 1 } |
enum | { FIXED_SIZE = -1 , ANY_SIZE = -10 } |
using | Evaluator = float(*)(GAGenome &) |
using | Initializer = void(*)(GAGenome &) |
using | Mutator = int(*)(GAGenome &, float) |
using | Comparator = float(*)(const GAGenome &, const GAGenome &) |
using | SexualCrossover = int(*)(const GAGenome &, const GAGenome &, GAGenome *, GAGenome *) |
using | AsexualCrossover = int(*)(const GAGenome &, GAGenome *) |
![]() | |
enum | { BaseGA = 0 , SimpleGA , SteadyStateGA , IncrementalGA , DemeGA , Population = 10 , Scaling = 15 , NoScaling , LinearScaling , SigmaTruncationScaling , PowerLawScaling , Sharing , Selection = 40 , RankSelection , RouletteWheelSelection , TournamentSelection , UniformSelection , SRSSelection , DSSelection , Genome = 50 , BinaryStringGenome , BinaryStringGenome2D , BinaryStringGenome3D , Bin2DecGenome , ListGenome , TreeGenome , ArrayGenome , ArrayGenome2D , ArrayGenome3D , ArrayAlleleGenome , ArrayAlleleGenome2D , ArrayAlleleGenome3D , StringGenome , FloatGenome , IntGenome , DoubleGenome } |
1 dimensional Array Genome
You can use ANY kind of object in this genome. But notice that it is really easy to optimize this for some of the simpler types.
The objects in the array must have the following operators defined:
operator=
operator==
operator!=
operator>>
must be defined, if you use the default read methods
If you want speed, specialize the comparison routines and copy routines so that you can use memcpy, memmove, memcmp rather than looping through each element.
make the object defined for simple types, if you want to use complex types then specialize to do member copy rather than bit copy (that way simple users won't sacrifice speed, and complex users will get more complexity)
T |
|
inlinestatic |
How similar are two genomes.
operator==
must be defined
a | Genome a |
b | Genome b |
-1 | if genomes a and b are not the same length |
|
inlinestatic |
Randomly swap elements in the array.
c | |
pmut |
|
inlinestatic |
Randomly take bits from each parent.
For each bit we flip a coin to see if that bit should come from the mother or the father. If strings are different lengths then we need to use the mask to get things right.
p1 | Parent 1 |
p2 | Parent 2 |
c1 | |
c2 |