evorobotexperiment.cpp
76 // be the first to declare resources (if we did this later we should have used addUsableResources
78 usableResources( QStringList() << "world" << "arena" << "experiment" << "robot" << "evonet" << "neuronsIterator" );
120 batchRunning = ConfigurationHelper::getBool(params, "__INTERNAL__/BatchRunning", batchRunning); // If we are running in batch or not
121 ntrials = ConfigurationHelper::getInt(params, prefix + "ntrials", ntrials); // number of trials to do
123 nsteps = ConfigurationHelper::getInt(params, prefix + "nsteps", nsteps); // number of step for each trial
125 // Reading world parameters. We need to do this before calling recreateWorld because that function uses the parameters
146 QStringList sensorsList = savedConfigurationParameters->getGroupsWithPrefixList(prefix, "Sensor:");
150 QStringList motorsList = savedConfigurationParameters->getGroupsWithPrefixList(prefix, "Motor:");
185 Descriptor d = addTypeDescription( type, "The experimental setup that defines the conditions and the fitness function of the evolutionary experiment" );
186 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");
187 d.describeInt( "nsteps" ).def(1).limits(1,MaxInteger).help("The number of step a trials will last");
188 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");
189 d.describeSubgroup( "NET" ).props( IsMandatory ).type( "Evonet" ).help( "The Neural Network controlling the robot");
191 d.describeSubgroup( "Sensor" ).props( AllowMultiple ).type( "Sensor" ).help( "One of the Sensors from which the neural network will receive information about the environment" );
192 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" );
195 SubgroupDescriptor world = d.describeSubgroup( "World" ).help( "Parameters affecting the simulated World" );
196 world.describeReal( "timestep" ).def(0.05).runtime( &EvoRobotExperiment::setWorldTimestep, &EvoRobotExperiment::getWorldTimeStep ).help( "The time in seconds corresponding to one simulated step of the World" );
268 // If the GUI is active, adding a small delay to let the GUI catch up (this is only done on MacOSX
415 Logger::error( "getSensor returned NULL pointer because the agent "+QString::number(id)+" is disabled" );
420 Logger::error( "getSensor returned NULL pointer because there is no sensor named "+name+" in the agent "+QString::number(id) );
427 Logger::error( "getMotor returned NULL pointer because the agent "+QString::number(id)+" is disabled" );
432 Logger::error( "getMotor returned NULL pointer because there is no motor named "+name+" in the agent "+QString::number(id) );
570 if (!ConfigurationHelper::hasGroup( *savedConfigurationParameters, (*savedPrefix) + "Arena" ) ) {
638 EvoRobotExperiment::EmbodiedAgent::EmbodiedAgent( int id, QString agentPath, EvoRobotExperiment* exp ) {
657 // Reading the sensors parameters. For each sensor there must be a subgroup Sensor:NN where NN is a progressive number
659 QStringList sensorsList = exp->savedConfigurationParameters->getGroupsWithPrefixList(agentPath, "Sensor:");
663 // !! WARNING !! this should only be a temporary implementation, a better implementation is needed
667 Sensor* sensor = exp->savedConfigurationParameters->getObjectFromGroup<Sensor>(agentPath + sensorGroup);
669 Logger::error("Cannot create the Sensor from group " + *(exp->savedPrefix) + sensorGroup + ". Aborting");
673 // the Sensors are renamed using the same name of the Group when they don't have a name assigned
680 // if the user manually set the name and create a name clash, it is only reported as error in Logger
682 Logger::error( "More than one sensor has name "+sensor->name()+" !! The name has to be unique !!" );
690 QStringList motorsList = exp->savedConfigurationParameters->getGroupsWithPrefixList(agentPath, "Motor:");
694 // !! WARNING !! this should only be a temporary implementation, a better implementation is needed
698 Motor* motor = exp->savedConfigurationParameters->getObjectFromGroup<Motor>(agentPath + motorGroup);
700 Logger::error("Cannot create the Motor from group " + *(exp->savedPrefix) + motorGroup + ". Aborting");
711 // if the user manually set the name and create a name clash, it is only reported as error in Logger
713 Logger::error( "More than one motor has name "+motor->name()+" !! The name has to be unique !!" );
722 exp->declareResource( resourcePrefix+"neuronsIterator", neuronsIterator, resourcePrefix+"evonet" );
775 exp->savedConfigurationParameters->createParameter( agentPath+"NET", "nSensors", QString::number(nSensors) );
776 exp->savedConfigurationParameters->createParameter( agentPath+"NET", "nMotors", QString::number(nMotors) );
778 // Now creating the neural network. We first set ourself as the resouce manager, then we lock resources (because during configuration
779 // evonet could use resources, but the resource user it will use is not thread safe (SimpleResourceUser))
786 exp->declareResource( resourcePrefix+"evonet", static_cast<farsa::ParameterSettable*>(evonet) );
795 neuronsIterator->defineBlock( sensor->name(), EvonetIterator::InputLayer, startIndex, sensor->size() );