Represents persistent read-only storage space for Actors. More...
#include <dna.h>
Classes | |
struct | InitData |
the initialisation data More... | |
struct | Partition |
an entry in the list of partitions More... |
Public Types | |
enum | Predef { OffKind = 0, OffBrains, OffActuators, OffSensors, OffReflexes, OffCost, OffAge, OffStartEnergy, OffMax, OffLastList = OffReflexes+1 } |
offsets for predefined values More... |
Public Member Functions | |
DNA (void) | |
constructor; creates an empty, invalid shell | |
DNA (const World *w, ID kind) | |
constructor; creates a valid instance | |
~DNA (void) | |
destructor; | |
bool | fromMerge (const DNA &p1, const DNA &p2) |
set the DNA as a result of the two parents | |
bool | isValid (void) const |
tell if this instance is valid or not | |
bool | operator== (const DNA &other) const |
tell if two classes are equal | |
bool | save (QSettings &stg) const |
save the content of this DNA to indicated object | |
bool | load (QSettings &stg) |
load the content of this DNA from indicated object | |
int | findID (ID id) const |
get the index of the ID or -1 if not found | |
void | initDNA (const InitData &init) |
initialise an empty DNA; the instance becomes valid | |
void | reinitDNA (const DNA &src, bool clear_content) |
set components and characteristics for source DNA | |
examine components | |
DNAView | getView (ID id, Factory *f=NULL) |
get a view for a particular id | |
DNAView | getView (ID id, int sz, Factory *f=NULL) |
get a view for a particular id | |
ID | kind (void) const |
get the kind | |
quint64 | cost (void) const |
energy cost | |
quint64 | age (void) const |
average age for this kind of actor | |
quint64 | energy (void) const |
birth energy | |
QList< ID > | brains (void) const |
get the list of brains | |
QList< ID > | actuators (void) const |
get the list of actuators | |
QList< ID > | sensors (void) const |
get the list of sensors | |
QList< ID > | reflexes (void) const |
get the list of reflexes | |
QVector< Partition > | partitions (void) const |
list of regions that partition the list of values | |
add components | |
bool | addBrain (ID id) |
append a brain | |
bool | addActuator (ID id) |
append an actuator | |
bool | addSensor (ID id) |
append a sensor | |
bool | addReflex (ID id) |
append a reflex |
Static Public Member Functions | |
static qreal | dnaNoise (void) |
the level of noise to add to copy opperations |
Protected Attributes | |
QVector< Partition > | parts_ |
list of regions that partition the list of values | |
QList< qreal > | values_ |
actual sequence of numbers; subject to degradation | |
QList< quint64 > | values_i_ |
actual sequence of numbers; not subject to degradation |
Friends | |
class | DNAView |
class | ActorFactory |
Represents persistent read-only storage space for Actors.
The class stores a list of real numbers represented as double-precision floating points. This list is partitioned in parts, each with an unique id. Each part is accesible as a DNAView.
enum april::DNA::Predef |
offsets for predefined values
OffKind |
the kind - ID |
OffBrains |
number of brains in the list that follows |
OffActuators |
number of actuators in the list that follows |
OffSensors |
number of sensors in the list that follows |
OffReflexes |
number of reflexes in the list that follows |
OffCost |
the cost for running the Actor per time unit |
OffAge |
average age |
OffStartEnergy |
energy at birth |
DNA::DNA | ( | const World * | w, |
ID | kind | ||
) |
constructor; creates a valid instance
The kind is looked up in the world and, if found, the default DNA for that kind is copied.
The resulted instance may be invalid if something goes wrong (world is invalid, the kind does not have a valid default DNA).
If the world does not contain that kind the instance is valid but mostly empty.
bool DNA::addActuator | ( | ID | id | ) |
append an actuator
May fail because id is invalid. The id is inserted in the list and will be shown by a call to actuators().
id | the ID to insert (different than InvalidID) |
bool DNA::addBrain | ( | ID | id | ) |
append a brain
May fail because id is invalid. The id is inserted in the list and will be shown by a call to brains().
id | the ID to insert (different than InvalidID) |
bool DNA::addReflex | ( | ID | id | ) |
append a reflex
May fail because id is invalid. The id is inserted in the list and will be shown by a call to reflexes().
id | the ID to insert (different than InvalidID) |
bool DNA::addSensor | ( | ID | id | ) |
append a sensor
May fail because id is invalid. The id is inserted in the list and will be shown by a call to sensors().
id | the ID to insert (different than InvalidID) |
set the DNA as a result of the two parents
This instance is set to the result of the merge. It is affected by random noise in the real part.
p1 | first parent |
p2 | second parent |
get a view for a particular id
If the id is not to be found and a factory is provided then it is asked for a default for this ID. If that does not work the DNAView will be invalid.
get a view for a particular id
This variant is for the callers that assert a certain minimum size for returned view. If the id is not to be found and a factory is provided then it is asked for a default for this ID. If that does not work the DNAView will be invalid.
If the id is found but its size is smaller than requested a new portion large enough is allocated at the end of the dna array. Old values are copied in their respective spots and new spots are filled by requesting the averageDNA values from the factory.
void DNA::initDNA | ( | const InitData & | init | ) |
initialise an empty DNA; the instance becomes valid
This is usefull for ActorFactory to create a default DNA
init | initial data |
void DNA::reinitDNA | ( | const DNA & | src, |
bool | clear_content | ||
) |