Modernized GAlib  3.0.0 current
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
GA1DArrayGenome< T > Class Template Reference

1 dimensional Array Genome More...

#include <GA1DArrayGenome.hpp>

Inheritance diagram for GA1DArrayGenome< T >:
[legend]
Collaboration diagram for GA1DArrayGenome< T >:
[legend]

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[])
 
GAGenomeclone (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)
 
- Public Member Functions inherited from GAArray< T >
 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
 
- Public Member Functions inherited from GAGenome
 GADefineIdentity ("GAGenome", GAID::Genome)
 
 GAGenome (Initializer i=nullptr, Mutator m=nullptr, Comparator c=nullptr)
 
 GAGenome (const GAGenome &orig)
 
GAGenomeoperator= (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)
 
GAGeneticAlgorithmgeneticAlgorithm () const
 
GAGeneticAlgorithmgeneticAlgorithm (GAGeneticAlgorithm &g)
 
void * userData () const
 
void * userData (void *u)
 
GAEvalDataevalData () const
 
GAEvalDataevalData (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
 
- Public Member Functions inherited from GAID
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 Public Member Functions inherited from GAGenome
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
 
- Protected Attributes inherited from GAArray< T >
std::vector< T > a
 the contents of the array
 
- Protected Attributes inherited from GAGenome
float _score
 
float _fitness
 
bool _evaluated
 
unsigned int _neval
 
GAGeneticAlgorithmga
 
void * ud
 
Evaluator eval
 
GAEvalDataevd
 
Mutator mutr
 
Initializer init
 
Comparator cmp
 
SexualCrossover sexcross
 
AsexualCrossover asexcross
 

Additional Inherited Members

- Public Types inherited from GAGenome
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 *)
 
- Public Types inherited from GAID
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
}
 

Detailed Description

template<class T>
class GA1DArrayGenome< T >

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:

Template Parameters
T

Member Function Documentation

◆ ElementComparator()

template<class T >
static float GA1DArrayGenome< T >::ElementComparator ( const GAGenome a,
const GAGenome b 
)
inlinestatic

How similar are two genomes.

operator== must be defined

Parameters
aGenome a
bGenome b
Returns
Number indicates how many elements match
Return values
-1if genomes a and b are not the same length

◆ SwapMutator()

template<class T >
static int GA1DArrayGenome< T >::SwapMutator ( GAGenome c,
float  pmut 
)
inlinestatic

Randomly swap elements in the array.

Parameters
c
pmut
Returns
int

◆ UniformCrossover()

template<class T >
static int GA1DArrayGenome< T >::UniformCrossover ( const GAGenome p1,
const GAGenome p2,
GAGenome c1,
GAGenome c2 
)
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.

Parameters
p1Parent 1
p2Parent 2
c1
c2
Returns
int

The documentation for this class was generated from the following file: