evorobotexperiment.cpp
79 // be the first to declare resources (if we did this later we should have used addUsableResources
81 usableResources( QStringList() << "world" << "arena" << "experiment" << "robot" << "evonet" << "neuronsIterator" );
123 batchRunning = ConfigurationHelper::getBool(params, "__INTERNAL__/BatchRunning", batchRunning); // If we are running in batch or not
124 ntrials = ConfigurationHelper::getInt(params, prefix + "ntrials", ntrials); // number of trials to do
126 nsteps = ConfigurationHelper::getInt(params, prefix + "nsteps", nsteps); // number of step for each trial
128 // Reading world parameters. We need to do this before calling recreateWorld because that function uses the parameters
136 sameRandomSequence = ConfigurationHelper::getBool(params, prefix + "sameRandomSequence", sameRandomSequence);
158 QStringList sensorsList = savedConfigurationParameters->getGroupsWithPrefixList(prefix, "Sensor:");
162 QStringList motorsList = savedConfigurationParameters->getGroupsWithPrefixList(prefix, "Motor:");
197 Descriptor d = addTypeDescription( type, "The experimental setup that defines the conditions and the fitness function of the evolutionary experiment" );
198 d.describeInt( "ntrials" ).def(1).limits(1,MaxInteger).runtime( &EvoRobotExperiment::setNTrials, &EvoRobotExperiment::getNTrials ).help("The number of trials the individual will be tested to calculate its fitness");
199 d.describeInt( "nsteps" ).def(1).limits(1,MaxInteger).help("The number of step a trials will last");
200 d.describeInt( "nagents" ).def(1).limits(1,MaxInteger).help("The number of embodied agents to create", "This parameter allow to setup experiments with more than one robot; all agents are clones");
201 d.describeBool("sameRandomSequence").def(false).help("Whether the generated random number sequence should be the same for all individuals in the same generation or not (default false)");
202 d.describeSubgroup( "NET" ).props( IsMandatory ).type( "Evonet" ).help( "The Neural Network controlling the robot");
204 d.describeSubgroup( "Sensor" ).props( AllowMultiple ).type( "Sensor" ).help( "One of the Sensors from which the neural network will receive information about the environment" );
205 d.describeSubgroup( "Motor" ).props( AllowMultiple ).type( "Motor" ).help( "One of the Motors with which the neural network acts on the robot and on the environment" );
208 SubgroupDescriptor world = d.describeSubgroup( "World" ).help( "Parameters affecting the simulated World" );
209 world.describeReal( "timestep" ).def(0.05).runtime( &EvoRobotExperiment::setWorldTimestep, &EvoRobotExperiment::getWorldTimeStep ).help( "The time in seconds corresponding to one simulated step of the World" );
246 localRNG.setSeed(ga->getCurrentSeed() + (ga->getCurrentGeneration() * ga->getNumReplications()));
274 Logger::info("Fitness for trial " + QString::number(ntrial) + ": " + QString::number(trialFitnessValue));
287 // If the GUI is active, adding a small delay to let the GUI catch up (this is only done on MacOSX
440 Logger::error( "getSensor returned NULL pointer because the agent "+QString::number(id)+" is disabled" );
445 Logger::error( "getSensor returned NULL pointer because there is no sensor named "+name+" in the agent "+QString::number(id) );
452 Logger::error( "getMotor returned NULL pointer because the agent "+QString::number(id)+" is disabled" );
457 Logger::error( "getMotor returned NULL pointer because there is no motor named "+name+" in the agent "+QString::number(id) );
605 if (!ConfigurationHelper::hasGroup( *savedConfigurationParameters, (*savedPrefix) + "Arena" ) ) {
683 EvoRobotExperiment::EmbodiedAgent::EmbodiedAgent( int id, QString agentPath, EvoRobotExperiment* exp ) {
702 // Reading the sensors parameters. For each sensor there must be a subgroup Sensor:NN where NN is a progressive number
704 QStringList sensorsList = exp->savedConfigurationParameters->getGroupsWithPrefixList(agentPath, "Sensor:");
708 // !! WARNING !! this should only be a temporary implementation, a better implementation is needed
712 Sensor* sensor = exp->savedConfigurationParameters->getObjectFromGroup<Sensor>(agentPath + sensorGroup);
714 Logger::error("Cannot create the Sensor from group " + *(exp->savedPrefix) + sensorGroup + ". Aborting");
718 // the Sensors are renamed using the same name of the Group when they don't have a name assigned
725 // if the user manually set the name and create a name clash, it is only reported as error in Logger
727 Logger::error( "More than one sensor has name "+sensor->name()+" !! The name has to be unique !!" );
735 QStringList motorsList = exp->savedConfigurationParameters->getGroupsWithPrefixList(agentPath, "Motor:");
739 // !! WARNING !! this should only be a temporary implementation, a better implementation is needed
743 Motor* motor = exp->savedConfigurationParameters->getObjectFromGroup<Motor>(agentPath + motorGroup);
745 Logger::error("Cannot create the Motor from group " + *(exp->savedPrefix) + motorGroup + ". Aborting");
756 // if the user manually set the name and create a name clash, it is only reported as error in Logger
758 Logger::error( "More than one motor has name "+motor->name()+" !! The name has to be unique !!" );
767 exp->declareResource( resourcePrefix+"neuronsIterator", neuronsIterator, resourcePrefix+"evonet" );
820 exp->savedConfigurationParameters->createParameter( agentPath+"NET", "nSensors", QString::number(nSensors) );
821 exp->savedConfigurationParameters->createParameter( agentPath+"NET", "nMotors", QString::number(nMotors) );
823 // Now creating the neural network. We first set ourself as the resouce manager, then we lock resources (because during configuration
824 // evonet could use resources, but the resource user it will use is not thread safe (SimpleResourceUser))
831 exp->declareResource( resourcePrefix+"evonet", static_cast<farsa::ParameterSettable*>(evonet) );
840 neuronsIterator->defineBlock( sensor->name(), EvonetIterator::InputLayer, startIndex, sensor->size() );
845 neuronsIterator->defineBlock( motor->name(), EvonetIterator::OutputLayer, startIndex, motor->size() );
This class iterate over the neurons of a Evonet neural network.
Definition: neuroninterfaces.h:333
void usableResources(QStringList resources)
double totalFitnessValue
the fitness value of the individual all over the trials
Definition: evorobotexperiment.h:558
virtual void endTrial(int trial)
Called at the end of a trial.
Definition: evorobotexperiment.cpp:339
virtual void initStep(int step)
Initialize whatever at step granularity when needed.
Definition: evorobotexperiment.cpp:313
bool agentEnabled(int agentId)
Returns true if the agent is enabled, false otherwise.
Definition: evorobotexperiment.cpp:496
bool selectAgent(int agentId)
select the i-the agent and make available the corresponding resources
Definition: evorobotexperiment.cpp:471
void setFrictionModel(QString model)
RealDescriptor & runtime(void(T::*setter)(double), double(T::*getter)() const )
void advance()
FARSA_UTIL_API RandomGenerator * globalRNG
void FARSA_UTIL_TEMPLATE msleep(unsigned int msec)
virtual void setNetParameters(float *genes)
Sets the free parameters of the neural network. This is done for all agents, even disabled ones...
Definition: evorobotexperiment.cpp:516
void declareResource(QString name, T *resource, QString lockBuddy="")
void setSize(const wVector &minPoint, const wVector &maxPoint)
void addUsableResource(QString resource)
void restartTrial()
Stops the current trial and restarts it from scratch.
Definition: evorobotexperiment.cpp:420
virtual void initGeneration(int generation)
Called at the beginning of a generation. This function is NEVER called concurrently on different obje...
Definition: evorobotexperiment.cpp:296
bool copyGroupTree(QString sourceGroup, QString destGroup)
RealDescriptor describeReal(QString parameter)
void doAllTrialsForIndividual(int individual)
Performs all trials for the given individual.
Definition: evorobotexperiment.cpp:242
bool isStopped()
return true if the evolution process has been stopped with stop()
Definition: evoga.cpp:3050
int getNAgents()
return the number of agents present in the experiment
Definition: evorobotexperiment.cpp:467
void setIsRealTime(bool b)
virtual unsigned int getCurrentGeneration()
Returns the current generation.
Definition: evoga.cpp:3086
void setEvoga(Evoga *ga)
Set the Evoga on which this EvoRobotExperiment is used.
Definition: evorobotexperiment.cpp:505
virtual void postConfigureInitialization()
This function is called after all linked objects have been configured.
Definition: evorobotexperiment.cpp:212
double totalErrorValue
the error of the individual all over the trials
Definition: evorobotexperiment.h:562
Sensor * getSensor(QString sensorName, int agentId=0)
Return a pointer to the Sensor with name specified.
Definition: evorobotexperiment.cpp:438
void recreateAllNeuralNetworks()
Recreates all neural networks.
Definition: evorobotexperiment.cpp:648
virtual void shareResourcesWith(ResourcesUser *buddy)
Motor * getMotor(QString motorName, int agentId=0)
Return a pointer to the Motor with name specified.
Definition: evorobotexperiment.cpp:450
int getStepDelay()
returns the current delay applied at each step
Definition: evorobotexperiment.cpp:679
RealDescriptor & help(QString shortHelp, QString longHelp=QString(""))
void setSeed(int seed)
void shareObserversWith(ConfigurationParameters ¶ms)
static bool getBool(ConfigurationParameters ¶ms, QString paramPath, bool def=false)
void createGroup(QString groupPath)
virtual void setTestingAgentAndSeed(int idindividual, int nreplica)
called by AbstractTest and subclasses to inform which individual is going to test ...
Definition: evorobotexperiment.cpp:532
static void info(QString msg)
bool commitStep()
this method marks the point on which it is called as a commited step of evolution ...
Definition: evoga.cpp:3040
static void error(QString msg)
void setTimeStep(real)
float getWorldTimeStep() const
helper method for getting timestep of the world at runtime
Definition: evorobotexperiment.cpp:666
Evonet * getNeuralNetwork(int agentId=0)
Return the neural network used for the experiment.
Definition: evorobotexperiment.cpp:500
RealDescriptor & def(double defaultValue)
void recreateNeuralNetwork(int agentId=0)
Recreate the neural network.
Definition: evorobotexperiment.cpp:638
void notifyChangesToParam(QString paramName)
static void describe(QString type)
Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups.
Definition: evorobotexperiment.cpp:196
virtual void beforeWorldAdvance()
Called just before the world advances, after the update of motors.
Definition: evorobotexperiment.cpp:335
virtual void endGeneration(int generation)
Called at the end of a generation. This function is NEVER called concurrently on different objects...
Definition: evorobotexperiment.cpp:349
static double getDouble(ConfigurationParameters ¶ms, QString paramPath, double def=0)
static Descriptor addTypeDescription(QString type, QString shortHelp, QString longHelp=QString(""))
QString getValue(QString path, bool alsoMatchParents=false) const
void newGASeed(int seed)
Called by the ga when the seed changes (e.g. in a new replication)
Definition: evorobotexperiment.cpp:670
TypeToCreate * getObjectFromGroup(QString group, bool configure=true, bool forceObjectCreation=false)
void setMultiThread(int numThreads)
void unlock()
virtual void endIndividual(int individual)
Called at the end of an individual's life.
Definition: evorobotexperiment.cpp:345
QStringList getGroupsWithPrefixList(QString group, QString prefix) const
virtual void save(ConfigurationParameters ¶ms, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
Definition: evorobotexperiment.cpp:190
virtual void doNotUseMultipleThreads()
Forces execution of the GA using no threads (i.e., in the current thread)
Definition: evoga.cpp:3170
void handleKinematicRobotCollisions()
Checks collisions of kinematic robots.
Definition: arena.cpp:348
bool inBatchRunning()
Return true if the simulation is running in batch modality, false if is running with the GUI...
Definition: evorobotexperiment.cpp:462
static const int MaxInteger
virtual void afterSensorsUpdate()
Called just after the updating of sensors and before the updating of the neural network.
Definition: evorobotexperiment.cpp:327
void setResourcesUser(ResourcesUser *resourcesUser)
void setStepDelay(int delay)
set the delay to apply at each step for slowing down the simulation
Definition: evorobotexperiment.cpp:675
virtual void initIndividual(int individual)
Called at the beginning of an individual's life.
Definition: evorobotexperiment.cpp:300
virtual void beforeMotorsUpdate()
Called just before the updating of motors and after the updating of the neural network.
Definition: evorobotexperiment.cpp:331
void deleteResource(QString name)
AllowMultiple
double trialFitnessValue
the fitness value of the individual during the execution of one trial
Definition: evorobotexperiment.h:556
static int getInt(ConfigurationParameters ¶ms, QString paramPath, int def=0)
double trialErrorValue
the error of the individual during the execution of one trial
Definition: evorobotexperiment.h:560
virtual void initTrial(int trial)
Definition: evorobotexperiment.cpp:304
The base common class that evaluate the fitness of a robot.
Definition: evorobotexperiment.h:155
void setSolverModel(QString model)
void createParameter(QString groupPath, QString parameter)
virtual unsigned int getNumReplications()
Returns the number of replications.
Definition: evoga.cpp:3101
IsMandatory
virtual void configure(ConfigurationParameters ¶ms, QString prefix)
Configures the object using a ConfigurationParameters object.
Definition: evorobotexperiment.cpp:108
static bool hasGroup(ConfigurationParameters ¶ms, QString group)
void prepareToHandleKinematicRobotCollisions()
Call this before advancing the world to prepare stuffs needed by a call to handleKinematicRobotCollis...
Definition: arena.cpp:332