blob: 0eafb780e7e5e991864b19b0b6cb4ca58039c5e5 (
plain)
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
48
49
50
51
52
53
54
55
|
#ifndef GENETIC_PHENOTYPE_H
#define GENETIC_PHENOTYPE_H
#include <bu/string.h>
#include <bu/hash.h>
#include <bu/variant.h>
#include "genetic/config.h"
namespace Genetic
{
class Phenotype
{
public:
Phenotype();
virtual ~Phenotype();
virtual int getSize()=0;
virtual Phenotype &randomize()=0;
/**
* Modify the given location by the given magnitude. The magnitude
* should be between -1.0 and 1.0 inclusive. A 0.0 indicates no
* change.
*/
virtual void mutate( int iLocation, float fMagnitude )=0;
virtual Phenotype ©From( const Phenotype &rSrc, int iStart,
int iSize, int iDest=-1 )=0;
/**
* Produces a Phenotype class that can be used to contain the data for
* an offspring. The produced phenotype will be compatible, but empty.
*/
virtual Phenotype *makeEmptyOffspring( int iNewSize=-1 )=0;
virtual Bu::String toString()=0;
bool hasProperty( const Bu::String &sKey ) const;
Bu::Variant getProperty( const Bu::String &sKey ) const;
void setProperty( const Bu::String &sKey, Bu::Variant vValue );
void setCreated( Genetic::Time t, Genetic::PhenotypeId id )
{ tCreated = t; uId = id; bActive = true; }
Genetic::Time getCreated() const { return tCreated; }
Genetic::PhenotypeId getId() const { return uId; }
bool isActive() const { return bActive; }
private:
Genetic::Time tCreated;
Genetic::PhenotypeId uId;
bool bActive;
typedef Bu::Hash<Bu::String, Bu::Variant> PropHash;
PropHash hProp;
};
};
#endif
|