The base common class that evaluate the fitness of a robot. More...

Inheritance diagram for EvoRobotExperiment:

List of all members.

Public Types

enum  Phases { INTEST, INEVOLUTION, NONE }
 

this type define the phase of which the EvoRobotExperiment

More...

Public Member Functions

 EvoRobotExperiment ()
 Constructor.
virtual ~EvoRobotExperiment ()
 Destructor.
virtual void afterSensorsUpdate ()
 Called just after the updating of sensors and before the updating of the neural network.
virtual void beforeMotorsUpdate ()
 Called just before the updating of motors and after the updating of the neural network.
virtual void configure (ConfigurationParameters &params, QString prefix)
 Configures the object using a ConfigurationParameters object.
void doAllTrialsForIndividual (int individual)
 Performs all trials for the given individual.
virtual void endGeneration (int generation)
 Called at the end of a generation. This function is NEVER called concurrently on different objects.
virtual void endIndividual (int individual)
 Called at the end of an individual's life.
void endIndividualLife ()
 Ends the invidual life.
virtual void endStep (int step)=0
 Called at the end of the step.
virtual void endTrial (int trial)
 Called at the end of a trial.
Phases getActivityPhase ()
 return the state of the EvoRobotExperiment
int getCurStep () const
 Returns the current step.
int getCurTrial () const
 Returns the current trial.
EvogagetEvoga ()
 Return the pointer to the Evoga setted.
double getFitness ()
 return the current value of the fitness
int getGenomeLength ()
 Returns the length of the genome.
MotorgetMotor (QString motorName)
 Return a pointer to the Motor with name specified.
EvonetgetNeuralNetwork ()
 Return the neural network used for the experiment.
int getNSteps () const
 Returns the number of steps.
int getNTrials () const
 Returns the number of trials.
SensorgetSensor (QString sensorName)
 Return a pointer to the Sensor with name specified.
bool inBatchRunning ()
 Return true if the simulation is running in batch modality, false if is running with the GUI.
virtual void initGeneration (int generation)
 Called at the beginning of a generation. This function is NEVER called concurrently on different objects.
virtual void initIndividual (int individual)
 Called at the beginning of an individual's life.
virtual void initStep (int step)
 Initialize whatever at step granularity when needed.
virtual void initTrial (int trial)
 Called at the beginning of a trial.
virtual void postConfigureInitialization ()
 This function is called after all linked objects have been configured.
void restartTrial ()
 Stops the current trial and restarts it from scratch.
virtual void save (ConfigurationParameters &params, QString prefix)
 Save the actual status of parameters into the ConfigurationParameters object passed.
void setActivityPhase (Phases newPhase)
 set the new activity phase
void setEvoga (Evoga *ga)
 Set the Evoga on which this EvoRobotExperiment is used.
void setNetParameters (int *genes)
 Sets the free parameters of the neural network.
virtual void setTestingAgentAndSeed (int idindividual, int nreplica)
 called by AbstractTest and subclasses to inform which individual is going to test
void skipTrial ()
 Skips the next trial.
void stopTrial ()
 Stops the current trial.

Static Public Member Functions

static void describe (QString type)
 Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups.

Protected Member Functions

void recreateNeuralNetwork ()
 Recreate the neural network.
void recreateRobot ()
 Recreate the robot.
void recreateWorld ()
 current trial

Protected Attributes

int nstep
 number of cycles
int nsteps
 number of test
int ntrial
 current step
int ntrials
ConfigurationParameterssavedConfigurationParameters
const QString * savedPrefix
double totalFitnessValue
 the fitness value of the individual all over the trials
double trialFitnessValue
 the fitness value of the individual during the execution of one trial

Detailed Description

The base common class that evaluate the fitness of a robot.

This class don't actually implement any particular scenario or fitness function. The user must subclass from this, and provide the implementation for the necessary methods for setting up his scenario and fitness function.

The main assumption that cannot be changed in the subclasses are:

  • the robot and the environment are a simulated physic world (Worldsim::World). Moreover there must be one robot (and only one)
  • the controller is a neural network
  • the fitness is computed evaluating the robot over a set of trials

The methods that can be re-implemented in order to setup a scenario and a fitness function are:

  • initGeneration
  • initIndividual
  • initTrial
  • initStep
  • afterSensorsUpdate
  • beforeMotorsUpdate
  • endStep (this is pure virtual, so it MUST be re-implemented)
  • endTrial
  • endIndividual
  • endGeneration In the most common cases, you need to re-implment just few of them but they are provided for fullfill almost any situations. The schema on which they are called during the evolution of individual is the following:
      foreach generation do
          initGeneration
          foreach inidividual do
              initIndividual
              foreach trial do
                  initTrial
                  foreach step do
                      initStep
                      afterSensorsUpdate
                      beforeMotorsUpdate
                      endStep
                  endTrial
              endIndividual
          endGeneration
      

In the most common case

The resources declared by this experiment are:

  • "evonet": the neural network
  • "neuronsIterator": the Neurons Iterator for iterate over neurons
  • "world": the physic world where the robot are simulated
  • "robot": the robot

Definition at line 151 of file evorobotexperiment.h.


Member Enumeration Documentation

enum Phases

this type define the phase of which the EvoRobotExperiment

Definition at line 265 of file evorobotexperiment.h.


Constructor & Destructor Documentation

~EvoRobotExperiment ( ) [virtual]

Destructor.

Definition at line 81 of file evorobotexperiment.cpp.


Member Function Documentation

void afterSensorsUpdate ( ) [virtual]

Called just after the updating of sensors and before the updating of the neural network.

Note:
useful, for example, to overwrite the inputs of the neural network (i.e.: to silence some neurons during the experiment withouth modifing sensors classes)

Definition at line 288 of file evorobotexperiment.cpp.

void beforeMotorsUpdate ( ) [virtual]

Called just before the updating of motors and after the updating of the neural network.

Note:
useful, for example, to overwrite the outputs of the neural network

Definition at line 292 of file evorobotexperiment.cpp.

void configure ( ConfigurationParameters params,
QString  prefix 
) [virtual]

Configures the object using a ConfigurationParameters object.

This also creates and configures the neural network controlling the individual

Parameters:
paramsthe configuration parameters object with parameters to use
prefixthe prefix to use to access the object configuration parameters. This is guaranteed to end with the separator character when called by the factory, so you don't need to add one

Implements ParameterSettableWithConfigureFunction.

Definition at line 95 of file evorobotexperiment.cpp.

References ConcurrentResourcesUser::declareResource(), Logger::error(), ConfigurationHelper::getBool(), ConfigurationParameters::getGroupsWithPrefixList(), ConfigurationHelper::getInt(), ConfigurationParameters::getObjectFromGroup(), ConfigurationParameters::getValue(), Logger::info(), Motor::name(), Sensor::name(), EvoRobotExperiment::nsteps, EvoRobotExperiment::recreateNeuralNetwork(), EvoRobotExperiment::recreateRobot(), EvoRobotExperiment::recreateWorld(), Motor::setName(), Sensor::setName(), and ConfigurationParameters::setResourcesUser().

void describe ( QString  type) [static]

Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups.

Parameters:
typeis the name of the type regarding the description. The type is used when a subclass reuse the description of its parent calling the parent describe method passing the type of the subclass. In this way, the result of the method describe of the parent will be the addition of the description of the parameters of the parent class into the type of the subclass

Reimplemented from ParameterSettable.

Definition at line 185 of file evorobotexperiment.cpp.

References ParameterSettable::addTypeDescription(), ParameterSettable::AllowMultiple, ParameterSettable::IntDescriptor::def(), ParameterSettable::Descriptor::describeInt(), ParameterSettable::Descriptor::describeSubgroup(), ParameterSettable::SubgroupDescriptor::help(), ParameterSettable::IntDescriptor::help(), ParameterSettable::IsMandatory, ParameterSettable::IntDescriptor::limits(), ParameterSettable::MaxInteger, ParameterSettable::SubgroupDescriptor::props(), and ParameterSettable::SubgroupDescriptor::type().

void endGeneration ( int  generation) [virtual]

Called at the end of a generation. This function is NEVER called concurrently on different objects.

Definition at line 305 of file evorobotexperiment.cpp.

Referenced by Evoga::evolveGenerational(), Evoga::evolveSteadyState(), TestIndividual::runTest(), and TestRandom::runTest().

void endIndividual ( int  individual) [virtual]

Called at the end of an individual's life.

Definition at line 301 of file evorobotexperiment.cpp.

Referenced by EvoRobotExperiment::doAllTrialsForIndividual().

void endIndividualLife ( )

Ends the invidual life.

Call this function to end the life of the individual. This can only be called from initTrial(), initStep(), endStep() and endTrial(). When you call this function the current trial is stopped as if stopTrial() was called, so everthing said for the stopTrial() function also applies to this function when called inside initStep() or endStep(). If you call this function from initTrial() the trial is terminated immediately without calling any step function. After returning from initTrial(), endTrial() is called. In all cases the fitness for the last trial is taken into account. After the call to endTrial() endIndividual() is called as if the individual life ended normally. You should never mix calls to this functions with calls to stopTrial(), skipTrial() or restartTrial() during the same trial.

Definition at line 363 of file evorobotexperiment.cpp.

virtual void endStep ( int  step) [pure virtual]

Called at the end of the step.

void endTrial ( int  trial) [virtual]

Called at the end of a trial.

Note:
the default implementation will add the current trialFitnessValue to totalFitnessValue

Definition at line 296 of file evorobotexperiment.cpp.

References EvoRobotExperiment::totalFitnessValue, and EvoRobotExperiment::trialFitnessValue.

Referenced by EvoRobotExperiment::doAllTrialsForIndividual().

Phases getActivityPhase ( ) [inline]

return the state of the EvoRobotExperiment

Definition at line 271 of file evorobotexperiment.h.

int getCurStep ( ) const [inline]

Returns the current step.

Returns:
the current step

Definition at line 345 of file evorobotexperiment.h.

int getCurTrial ( ) const [inline]

Returns the current trial.

Returns:
the current trial

Definition at line 355 of file evorobotexperiment.h.

Evoga * getEvoga ( )

Return the pointer to the Evoga setted.

Definition at line 409 of file evorobotexperiment.cpp.

double getFitness ( )

return the current value of the fitness

Definition at line 283 of file evorobotexperiment.cpp.

References EvoRobotExperiment::totalFitnessValue.

Referenced by Evoga::evolveGenerational(), Evoga::evolveSteadyState(), and EvaluatorThreadForEvoga::run().

int getGenomeLength ( )

Returns the length of the genome.

Definition at line 369 of file evorobotexperiment.cpp.

Referenced by TestRandom::buildRandomDNA(), and Evoga::postConfigureInitialization().

Motor * getMotor ( QString  motorName)

Return a pointer to the Motor with name specified.

Parameters:
nameis the name of the motor your are looking for

Definition at line 385 of file evorobotexperiment.cpp.

References Logger::error().

Evonet * getNeuralNetwork ( )

Return the neural network used for the experiment.

Definition at line 399 of file evorobotexperiment.cpp.

Referenced by TestRandom::buildRandomDNA(), and EvoRobotViewer::EvoRobotViewer().

int getNSteps ( ) const [inline]

Returns the number of steps.

Returns:
the number of steps

Definition at line 335 of file evorobotexperiment.h.

int getNTrials ( ) const [inline]

Returns the number of trials.

Returns:
the number of trials

Definition at line 325 of file evorobotexperiment.h.

Sensor * getSensor ( QString  sensorName)

Return a pointer to the Sensor with name specified.

Parameters:
nameis the name of the sensor your are looking for

Definition at line 376 of file evorobotexperiment.cpp.

References Logger::error().

bool inBatchRunning ( )

Return true if the simulation is running in batch modality, false if is running with the GUI.

Definition at line 394 of file evorobotexperiment.cpp.

void initGeneration ( int  generation) [virtual]

Called at the beginning of a generation. This function is NEVER called concurrently on different objects.

Definition at line 264 of file evorobotexperiment.cpp.

Referenced by Evoga::evolveGenerational(), Evoga::evolveSteadyState(), TestIndividual::runTest(), and TestRandom::runTest().

void initIndividual ( int  individual) [virtual]

Called at the beginning of an individual's life.

Definition at line 268 of file evorobotexperiment.cpp.

Referenced by EvoRobotExperiment::doAllTrialsForIndividual().

void initStep ( int  step) [virtual]

Initialize whatever at step granularity when needed.

Definition at line 279 of file evorobotexperiment.cpp.

void initTrial ( int  trial) [virtual]

Called at the beginning of a trial.

Definition at line 272 of file evorobotexperiment.cpp.

Referenced by EvoRobotExperiment::doAllTrialsForIndividual().

void postConfigureInitialization ( ) [virtual]

This function is called after all linked objects have been configured.

Reimplemented from ParameterSettable.

Definition at line 195 of file evorobotexperiment.cpp.

References Evoga::doNotUseMultipleThreads().

void recreateNeuralNetwork ( ) [protected]

Recreate the neural network.

This method helps in the creation of the Neural Network (only Evonet for now). It's strongly advised to use this method instead of creating a neural network by yourself. You can configure the neural network after this method accessing to the resource "evonet".

Warning:
it will destroy the neural network and create a new one.

Definition at line 475 of file evorobotexperiment.cpp.

References ConfigurationParameters::createParameter(), ConcurrentResourcesUser::declareResource(), EvonetIterator::defineBlock(), ConfigurationParameters::getObjectFromGroup(), ConfigurationParameters::getValue(), ResourcesLocker::lock(), Motor::name(), Sensor::name(), EvonetIterator::setEvonet(), ConfigurationParameters::setResourcesUser(), Motor::size(), Sensor::size(), and ResourcesLocker::unlock().

Referenced by EvoRobotExperiment::configure().

void recreateRobot ( ) [protected]

Recreate the robot.

This method helps in the creation of the Robot. It's strongly advised to use this method instead of creating a robot by yourself. You can configure the robot after having called this method accessing the resource "robot".

Warning:
it will destroy the robot and create a new one.

Definition at line 453 of file evorobotexperiment.cpp.

References ConcurrentResourcesUser::declareResource(), ConfigurationParameters::getObjectFromGroup(), EvoRobotExperiment::recreateWorld(), ConfigurationParameters::setResourcesUser(), and ResourcesLocker::unlock().

Referenced by EvoRobotExperiment::configure().

void recreateWorld ( ) [protected]

current trial

Recreate the world

This method helps in the creation of the World where the robot and the objects are simulated. It's strongly advised to use this method instead of creating a World by yourself. You can configure the World after this method accessing to the resource "world".

Warning:
it will destroy the World with any robot and object inside and create a new one without restoring any robot and objects present before.

Definition at line 425 of file evorobotexperiment.cpp.

References ConcurrentResourcesUser::declareResource(), ConcurrentResourcesUser::deleteResource(), World::setFrictionModel(), World::setMultiThread(), World::setSize(), World::setSolverModel(), and World::setTimeStep().

Referenced by EvoRobotExperiment::configure(), and EvoRobotExperiment::recreateRobot().

void restartTrial ( )

Stops the current trial and restarts it from scratch.

Call this function to stop the current trial and restart it from scratch. The current fitness value is discarded, too. You can call this function only from initStep() or endStep(). After the end of the function from which this is called, the trial is restarted and initTrial() is called. In particular no call to endTrial() is performed in any case and, if you call this function from initStep(), the functions afterSensorsUpdate(), beforeMotorsUpdate() and endStep() for the current step are not called. You should never mix calls to this functions with calls to stopTrial(), skipTrial() or endIndividualLife() during the same trial.

Definition at line 358 of file evorobotexperiment.cpp.

void save ( ConfigurationParameters params,
QString  prefix 
) [virtual]

Save the actual status of parameters into the ConfigurationParameters object passed.

This is not implemented, a call to this function will cause an abort

Parameters:
paramsthe configuration parameters object on which save actual parameters
prefixthe prefix to use to access the object configuration parameters.

Implements ParameterSettable.

Definition at line 179 of file evorobotexperiment.cpp.

References Logger::error().

void setActivityPhase ( Phases  newPhase) [inline]

set the new activity phase

Definition at line 275 of file evorobotexperiment.h.

Referenced by EvoRobotComponent::evolve(), EvolveOperation::run(), TestIndividual::runTest(), and TestRandom::runTest().

void setEvoga ( Evoga ga)

Set the Evoga on which this EvoRobotExperiment is used.

Definition at line 404 of file evorobotexperiment.cpp.

Referenced by Evoga::configure(), and Evoga::evolveSteadyState().

void setNetParameters ( int *  genes)
void setTestingAgentAndSeed ( int  idindividual,
int  nreplica 
) [virtual]

called by AbstractTest and subclasses to inform which individual is going to test

Definition at line 420 of file evorobotexperiment.cpp.

References Logger::error().

void skipTrial ( )

Skips the next trial.

Call this function to skip the execution of the next trial. This function can only be called from initTrial(). If you call this function, after initTrial(), execution continues with initTrial() (if there are more trials) or with endIndividual() (if there are no more trials to do). Of course no fitness is assigned for the skipped trials. You should never mix calls to this functions with calls to stopTrial(), restartTrial() or endIndividualLife() during the same trial.

Definition at line 353 of file evorobotexperiment.cpp.

void stopTrial ( )

Stops the current trial.

Call this function to stop the current trial and move to the next trial (if present). This function can only be called initStep() or endStep(). If you call this from initStep(), the functions afterSensorsUpdate(), beforeMotorsUpdate() and endStep() are also called before terminating the trial. After endStep(), execution continues with endTrial() as if the trial ended normally. This also means that trialFitnessValue is taken into account (unless you overrided the endTrial() function, in which case the behaviour depends on your implementation). You should never mix calls to this functions with calls to skipTrial(), restartTrial() or endIndividualLife() during the same trial.

Definition at line 348 of file evorobotexperiment.cpp.


Member Data Documentation

int nstep [protected]

number of cycles

Definition at line 363 of file evorobotexperiment.h.

int nsteps [protected]

number of test

Definition at line 362 of file evorobotexperiment.h.

Referenced by EvoRobotExperiment::configure().

int ntrial [protected]
double totalFitnessValue [protected]

the fitness value of the individual all over the trials

Definition at line 395 of file evorobotexperiment.h.

Referenced by EvoRobotExperiment::doAllTrialsForIndividual(), EvoRobotExperiment::endTrial(), and EvoRobotExperiment::getFitness().

double trialFitnessValue [protected]

the fitness value of the individual during the execution of one trial

Definition at line 393 of file evorobotexperiment.h.

Referenced by EvoRobotExperiment::doAllTrialsForIndividual(), and EvoRobotExperiment::endTrial().


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