Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | Namespace Members | Class Members

CrogaiAgent Class Reference

#include <src/CrogaiAgent.h>

Inheritance diagram for CrogaiAgent:

Inheritance graph
[legend]
Collaboration diagram for CrogaiAgent:

Collaboration graph
[legend]
List of all members.

Detailed Description

Base agent for the Crogai scenario: - Adds a notion of specie, and associated avatar.

The specie should be a value >0, 0 is reserved for obstacles.

Author:
Nicolas Brodu


Public Member Functions

 CrogaiAgent (int specie=1)
 Provide a default specie different from obstacles.
void updateStatistics ()
 Called from destructor, to update these statistics that can only be known after agent death May be called explicitly in some special cases, though.
virtual void addStudent (CrogaiAgent *student)
 Add a student to this teacher.
virtual void removeStudent (CrogaiAgent *student)
 Remove a student to this teacher - It has finished training.
virtual void aiStep ()
 Hook into AI stub to notifies all students.
virtual void findNeighbors (double radius)
 overload parent to use eliminate agents behind this one: it sees only what's in front, if this option was choosen (see 'seeOnlyInFront') TODO: integrate this directly in the locality query, so it's possible to quickly eliminate bricks completely behind => might expect an average of 50% perf increase!!!

Static Public Member Functions

static osg::Vec4 getDefaultColorForSpecie (int specie)
 The default color for the given specie.
static void createScoresLogger (const std::string &id, int numSpecies)
 Creates the logScores with the given ID and max number of species utility routine.
static void createPopulationsLogger (const std::string &id, int numSpecies)
 Creates the logPopulations with the given ID and max number of species utility routine.
static void createStatisticsLogger (const std::string &id, int numSpecies)
 Creates a logger with the given ID and max number of species Use this to monitor the previous statistics, or by default they won't even be computed This routine also initializes the statistics for the generation 0 Thus, you should first create all the initial agents, then trigger the log.
static void recordStatistics ()
 Tells the logger to record all its statistics now. It won't be possible to change the values afterward, so this should normally be called at the end of your program.
static void setPopulationUpdateCallback (void(*callback)(int delta, int specie))
 TODO: Revamp Simulator interface system and re-use dispatchers both here, in EventQueueViewer, and for simu->postXXX including simu->postAtStop Ugly hack for immediate needs!

Public Attributes

int specie
 Specie of this agent, to make the prey/predator game.
int generation
 Generation of this agent.
int offspringQuantity
 Number of offsprings this agent has spawned.
double birthDate
 Birth date of this agent, in simulator time units. Used to compute statistics.
double searchRadius
const Simulator::GenericDispatcheraiEvent
const Simulator::GenericDispatcherintegrationEvent

Static Public Attributes

static std::map< int, int > scores
 Score for each specie.
static bool displayScores = false
 Whether to display score counters on top left. Default is false.
static LoggerlogScores = 0
 Whether to log score values. Default is null, so no log.
static std::map< int, int > populations
 Population for each specie.
static bool displayPopulationNumbers = true
 Whether to display population statistics on top right. Default is true.
static bool displayPopulationCounter = true
 Whether to display population counter on top left. Default is true.
static LoggerlogPopulations = 0
 Whether to log population values. Default is null, so no log.
static std::map< int, std::vector<
double > > 
lifeTimeMean
 How long an agent lives on average.
static std::map< int, std::vector<
double > > 
lifeTimeVariance
static std::map< int, std::vector<
double > > 
maxEnergyReachedMean
 The maximum energy an agent has had. High count mean it has eaten a lot a preys.
static std::map< int, std::vector<
double > > 
maxEnergyReachedVariance
static std::map< int, std::vector<
double > > 
offspringQuantityMean
 number of offsprings an agent produced during its life
static std::map< int, std::vector<
double > > 
offspringQuantityVariance
static std::map< int, std::vector<
int > > 
generationsPopulationNumber
 Keep track of how many agents were produced in each specie, for each generation. Necessary to normalize the previous mean/variance.
static std::map< int, std::vector<
double > > 
generationsPopulationFirstTime
 Keep also track of when the first agent of a given generation was produced.
static LoggerlogStatistics = 0
 The statistics logger. Please use createStatisticsLogger to allocate it, unless you known what you're doing. These can't be updated in real time, and generations co-exist at the same time and their statistics may be updated in parallel (which would require to "go back" in the log file to update a value). => the logger is used only at the end of the program, when the last agent is destroyed, but it is also used as a flag indicator whether to bother computing the statistics at all! null by default.
static bool seeOnlyInFront = true
 Whether agents see only in front of them. True by default.
static double defaultSearchRadius = 30.0

Protected Member Functions

virtual void energyGainAction (double gain)
 Override this to specify an action to do when an agent gains energy Default is to increase our own energy with this amount, and maintain max energy stats.
virtual void winnerAction (CrogaiAgent *looser)
 Override this to specify an action to do when an agent wins over another one Default is to acquire energy equivalent to looser mass.
virtual void looserAction (CrogaiAgent *winner)
 Override this to specify an action to do when an agent loses, before it is destroyed.
virtual void updateIntegration (const double elapsedTime, const double currentTime)
 Handle collision detection in addition to parent's terrain handling Subclasses should call this before their own routine, if any.
virtual void removeTeacher (CrogaiAgent *teacher)
 For learning subclasses to be notified when this agent leaves the game.
virtual void learnAI (const double elapsedTime, const double currentTime, CrogaiAgent *teacher)
 Students registered on this teacher should have overloaded this.
virtual bool isPrey (CrogaiAgent *agent)
 Allow subclasses to identify preys based on their own criteria.
virtual bool isPredator (CrogaiAgent *agent)
 Allow subclasses to identify preys based on their own criteria.
virtual double getEnergyForFight ()
 Return the amount of energy this predator is willing to spend in a fight with the prey.
virtual void updateChild (CrogaiAgent *child)
 Subclasses may call this function when spawning to set base class parameters This function should copy all base parameters to the child, then do mutations.
osg::Node * buildAvatar ()
 Build this agent avatar. Default is a white box of dimensions (1,2,0.5). For subclasses to override.

Protected Attributes

std::list< CrogaiAgent * > students
double maxEnergyReached
 Used for statistics purpose.

Static Protected Attributes

static osg::Box * crogaiAgentShape = new osg::Box(osg::Vec3(0,0,0),1,2,0.5)
 shared instance of box


Member Function Documentation

void CrogaiAgent::aiStep  )  [virtual]
 

Hook into AI stub to notifies all students.

Students are notified with the learnAI routine, to allow them to make the difference. If overloading aiStep, Subclasses should call this before their own routine. Note: Subclasses should use updateAI as usual and not worry

Reimplemented from Agent.

double CrogaiAgent::getEnergyForFight  )  [protected, virtual]
 

Return the amount of energy this predator is willing to spend in a fight with the prey.

By default, set no limit (return the current amount of energy) and thus fight to death even if the prey escapes (which is pretty desperate for a predator).

Reimplemented in ExplicitAIAgent.

bool CrogaiAgent::isPredator CrogaiAgent agent  )  [protected, virtual]
 

Allow subclasses to identify preys based on their own criteria.

Used during collision. By default, consider any agent of different specie as predator.

Reimplemented in ExplicitAIAgent.

bool CrogaiAgent::isPrey CrogaiAgent agent  )  [protected, virtual]
 

Allow subclasses to identify preys based on their own criteria.

Used during collision. By default, consider any agent of different specie as prey.

Reimplemented in ExplicitAIAgent.

void CrogaiAgent::learnAI const double  elapsedTime,
const double  currentTime,
CrogaiAgent teacher
[protected, virtual]
 

Students registered on this teacher should have overloaded this.

This is the function called during teacher updateAI to notify all students. It does nothing by default, and is never called if your object is not registered as a student.

Reimplemented in NeuronalAgent.

void CrogaiAgent::looserAction CrogaiAgent winner  )  [protected, virtual]
 

Override this to specify an action to do when an agent loses, before it is destroyed.

Default is to do nothing. Use it to do an action each time before an agent is destroyed, and use winnerAction only for score counting and such other actions that may miss destroyed agents (see note 2). Note: Looser destruction and score counting are already handled outside this function. Note 2: There is a need for this function because there may be cases where a draw occurs, and there is no winner. Thus winnerAction is not called in these cases.

Parameters:
winner The winner agent, or null if this is a draw

void CrogaiAgent::updateChild CrogaiAgent child  )  [protected, virtual]
 

Subclasses may call this function when spawning to set base class parameters This function should copy all base parameters to the child, then do mutations.

This base class function position the child somewhere aroung the parent, but does nothing else.

Parameters:
child a newly created instance of a subclass for which base fields should be updated.

Reimplemented in NeuronalAgent.

void CrogaiAgent::winnerAction CrogaiAgent looser  )  [protected, virtual]
 

Override this to specify an action to do when an agent wins over another one Default is to acquire energy equivalent to looser mass.

Note: Looser destruction and score counting are already handled outside this function You should on the other hand use the parent function to handle energy

Reimplemented in ExplicitAIAgent.


Member Data Documentation

int CrogaiAgent::generation
 

Generation of this agent.

This is initially 0, and will be updated by incrementing the parent generation in the "updateChild" method

int CrogaiAgent::offspringQuantity
 

Number of offsprings this agent has spawned.

This is initially 0, and will be updated by incrementing the parent generation in the "updateChild" method

std::map< int, int > CrogaiAgent::populations [static]
 

Population for each specie.

Key is specie, value is population count.

std::map< int, int > CrogaiAgent::scores [static]
 

Score for each specie.

Key is specie, value is score.

int CrogaiAgent::specie
 

Specie of this agent, to make the prey/predator game.

This should be fixed, except in a "vampire" or conversion scenario where the specie could be altered at run-time... This could also be called team, or class, or type.


The documentation for this class was generated from the following files:
Generated on Mon Mar 28 11:27:02 2005 for Crogai by  doxygen 1.4.1