예제 #1
0
/**
 * Standard constructor.
 */
PhysicsManager::PhysicsManager() : mPhysicalSimulationAlgorithm(0), mCollisionManager(0),
		mSynchronizeObjectsWithPhysicalModel(true), mNextStepEvent(0),
		mCompletedNextStepEvent(0),
		mResetEvent(0), mResetFinalizedEvent(0), mResetSettingsEvent(0), 
		mResetSettingsTerminatedEvent(0), mInitialResetDone(false), mCurrentSimulationTime(0),
		mCurrentRealTime(0),  mCurrentStep(0), mResetDuration(0), mStepExecutionDuration(0),
		mPhysicalStepDuration(0), mSynchronizationDuration(0), mPostStepDuration(0),
		mCollisionHandlingDuration(0), mDisablePhysics(0), mResetMutex(QMutex::Recursive)
{
	EventManager *em = Core::getInstance()->getEventManager();

	//make sure these events are created right at the beginning (required for morphology evolution)
	em->getEvent(NerdConstants::EVENT_EXECUTION_RESET_SETTINGS, true);
	em->getEvent(NerdConstants::EVENT_EXECUTION_RESET_SETTINGS_COMPLETED, true);
	mPhysicsEnvironmentChangedEvent = em->createEvent(
					SimulationConstants::EVENT_PHYSICS_ENVIRONMENT_CHANGED);
	
	CommandLineArgument *switchXZArg = new CommandLineArgument("switchYZAxis", "switchYZAxis", "",
						"The y-axis now means height, so that the position of a robot in the plane is (x,z).",
						0, 0, true, false);
	bool switchXZ = switchXZArg->getNumberOfEntries() > 0 ? false : true;
	
	mSwitchYZAxes = new BoolValue(switchXZ);
	mSwitchYZAxes->setDescription("Changes the XYZ space to a XZY space, so that X and Y are in the plain.");
	Core::getInstance()->getValueManager()->addValue(SimulationConstants::VALUE_SWITCH_YZ_AXES, mSwitchYZAxes);
	
	mDisablePhysics = new BoolValue(false);
	mDisablePhysics->setDescription("If true, then the physical simulation is skipped and no update or resets of the physics takes place.");
	Core::getInstance()->getValueManager()->addValue(SimulationConstants::VALUE_DISABLE_PHYSICS, mDisablePhysics);
}
예제 #2
0
bool CollisionManager::bind() {

	CommandLineArgument *printCollisionRulePrototypesArg = new CommandLineArgument(
			"collisionRulePrototypes", "colp", "", 
			"Displays a list with all available collision rule prototypes",
			0, 0, false, false);
	CommandLineArgument *printCollisionRulesArg = new CommandLineArgument(
			"collisionRules", "col", "", 
			"Displays a list with all available collision rules that have been registered up to the binding phase.",
			0, 0, false, false);

	if(printCollisionRulePrototypesArg->getNumberOfEntries() > 0) {
		printCollisionRulePrototypes();
	}
	if(printCollisionRulesArg->getNumberOfEntries() > 0) {
		printCollisionRules();
	}

	return true;
}
/**
 * Constructs a new NeuralNetworkEditorApplication.
 */
NetworkDynamicsPlotterApplication::NetworkDynamicsPlotterApplication()
	: BaseApplication(), mExecutionLoop(0), mEnableSimulator(false)
{
	mName = "NeuralNetworkApplication";

	//Add statis mode value to allow the plotters to prevent network modifications in the editor
	//while the plots are calculated.
	BoolValue *stasisModeValue = new BoolValue(true);

	Core::getInstance()->getValueManager()->addValue(
				EvolutionConstants::VALUE_EVO_STASIS_MODE, stasisModeValue);

	//Check if the physical simulator is enabled.
	CommandLineArgument *simArg = new CommandLineArgument("useSimulator", "sim", "",
														  "Enables the physical simulator.", 0, 0, true, true);
	if(simArg->getNumberOfEntries() > 0) {
		mEnableSimulator = true;
	}
	Physics::install();
}
/**
 * Constructs a new UniversalNeuroScriptLoader.
 */
UniversalNeuroScriptLoader::UniversalNeuroScriptLoader()
{
    CommandLineArgument *scriptLoaderArgument = new CommandLineArgument(
        "installScript", "is", "<ScriptName> [<ScriptFileName> <TriggerEvent> <ResetEvent> <AgentInterface>]",
        QString("Installs a new script with name <ScriptName>, that loads file <ScriptFileName> ")
        + "during the bind phase. The script is reset by <ResetEvent> and executed each "
        + "time <TriggerEvent> is triggered.\nThe <AgentInterface> "
        + "specifies the agents whose neural network can be changed.", 1, 4, true);

    QList<QString> scriptNames;

    int numberOfScriptsToInstall = scriptLoaderArgument->getNumberOfEntries();
    for(int i = 0; i < numberOfScriptsToInstall; ++i) {
        QList<QString> entryParams = scriptLoaderArgument->getEntryParameters(i);

        QString name = entryParams.at(0);
        QString fileName = "";
        if(entryParams.size() > 1) {
            fileName = entryParams.at(1);
        }
        QString triggerEvent = "";
        if(entryParams.size() > 2) {
            triggerEvent = entryParams.at(2);
        }
        QString resetEvent = "";
        if(entryParams.size() > 3) {
            resetEvent = entryParams.at(3);
        }
        QString agentName = "";
        if(entryParams.size() > 4) {
            agentName = entryParams.at(4);
        }

        if(name != "" && !scriptNames.contains(name)) {
            new UniversalNeuroScriptingContext(name, fileName, triggerEvent, resetEvent, agentName);
            scriptNames.append(name);
            Core::log("UniversalScriptLoader: Installed UniversalScriptingContext ["
                      + name + "]");
        }
    }
}
예제 #5
0
/**
 * Initializes the FitnessManager.
 */
bool FitnessManager::init() {
	bool initOk = true;

	//print names of FitnessFunctionPrototypes if required
	CommandLineArgument *printFitnessFunctionsArgument = new CommandLineArgument("fitnessPrototypes",
							"fitnessPrototypes", "",
							"Prints the names of all available FitnessFunction prototypes.",
							0, 0, false, false);
	printFitnessFunctionsArgument->setProperty("debug");

	if(printFitnessFunctionsArgument->getNumberOfEntries() > 0) {
		cerr << "FitnessFunction Prototypes: " << endl
			 << "-----------------------------" << endl;
		QList<FitnessFunction*> prototypes = mFitnessFunctionPrototypes.values();
		for(QListIterator<FitnessFunction*> i(prototypes); i.hasNext();) {
			FitnessFunction *ff = i.next();
			cerr << " > " << ff->getName().toStdString().c_str() << endl;
		}
	}

	return initOk;
}
bool EvolutionOperatorTestApplication::setupApplication()
{
	bool ok = true;
	

	//Choose Physics Engine (or external Yars simulator)
	CommandLineArgument *physicsArg = new CommandLineArgument("physics", "p", "<physicsLibrary>",
			"Uses <physicsLibrary> as physics engine. "
			"Currently there are [ode, yars].", 1,0, true);
	if(physicsArg->getNumberOfEntries() != 0 && !physicsArg->getEntryParameters(0).empty()
			&& physicsArg->getEntryParameters(0).at(0).trimmed() == "yars")
	{
		YarsCommunication();
	}
	else {
		//install ODE PhysicsLayer
		ODE_Physics();
	}


	EvolutionSimulationPrototypes();

	//install file parser
	new SimpleObjectFileParser();

	//Install file interface for HTTPS communication.
	//new LoadAndStoreValueManagerPerGeneration();

	//Install fitness prototypes
	NeuroFitnessPrototypes();
	
	//Install standard NN functions and objects.
	StandardNeuralNetworkFunctions();

	//Install constraint manager.
	StandardConstraintCollection();

	//Install neuro modules
	NeuroModuleCollection();

	//Install network attribute characterizer
	new NeuralNetworkAttributes();

	//Install statistics logger to save the current statistics to a file.
	new StatisticsLogger(Evolution::getEvolutionManager()->getEvolutionWorkingDirectory());

	//Install and initialize the settings logger (logging of settings history).
	SettingsLogger *settingsLogger = new SettingsLogger();
	settingsLogger->addValues("(?!.*/Evo/.*/Fitness/.*/Fitness/.*)(?!.*/Performance/.*)/Evo/.*/Algorithm/.*");
	settingsLogger->addValues("(?!.*/Evo/.*/Fitness/.*/Fitness/.*)(?!.*/Performance/.*)/Evo/.*/Pop/.*");
	settingsLogger->addValues("/Evo/.*/Fitness/.*/Fitness/CalculationMode");
	settingsLogger->addValues("/Control/NumberOfSteps");
	settingsLogger->addValues("/Control/NumberOfTries");

	new FramesPerSecondCounter();
	new SimObjectGroupPrinter();
	new SaveBestNetworksHandler(3); 


	if(!buildSimulationModel()) {
		Core::log("LocalNNSimulatorEvolutionApplication: "
				  "Problem while building the simulation model.");
		ok = false;
	}

	if(!buildEvolutionSystem()) {
		Core::log("LocalNNSimulatorEvolutionApplication: "
				  "Problem while building the evolution system.");
		ok = false;
	}

	mRunner = new EvolutionRunner();

	return ok;

}
예제 #7
0
/**
 * Constructs a new NeuroEvolutionSelector.
 */
NeuroEvolutionSelector::NeuroEvolutionSelector(EvaluationMethod *evaluationMethod)
{

	//TODO Currently only a single world with a single population is supported.

	//Select evolution algorithm
	CommandLineArgument *evoAlgorithmArg = new CommandLineArgument(
		"evolutionAlgorithm", "evo", "<algorithmName> <controlledAgent> <populationName>", 
		"Uses the evolution algorithm with the given <algorithmName> "
		"to evolve controllers for agent <controlledAgent> (optional). "
		"Optionally the population name can be set with <populationName>.", 1, 2, true);

	CommandLineArgument *fitnessFunctionArg = new CommandLineArgument(
			"fitness", "fit", "<prototypeName> <fitnessFunctionName> <population>", 
			"Creates a copy of <prototypeName> and uses it "
			" with the given <fitnessFunctionName>. The <population>"
			" is a number and specifies the population in which the fitness function is used.", 
			2, 1, true);

	//ensure that there is at least on world, even if not specified via command line.
	bool createDefaultWorld = false;
	if(evoAlgorithmArg->getNumberOfEntries() == 0) {
		createDefaultWorld = true;
	}
	
	int scriptFitnessCounter = 0;
	
	QList<QString> evoWorldNames;

	for(int evoCount = 0; evoCount < evoAlgorithmArg->getNumberOfEntries() || createDefaultWorld; ++evoCount) {

		QString worldName = "Main";
		QString popName = "Controllers";
		if(evoCount > 0) {
			worldName = "Pop" + QString::number(evoCount);
		}
		if(evoCount > 0) {
			popName = "Controllers" + QString::number(evoCount);
		}
		
		QList<QString> evoArguments = evoAlgorithmArg->getEntryParameters(evoCount);
		
		if(evoArguments.size() >= 3) {
			worldName = evoArguments[2];
			QString name = worldName;
			int counter = 1;
			while(evoWorldNames.contains(worldName)) {
				worldName = name + QString::number(counter);
				counter++;
			}
			evoWorldNames.append(worldName);
		}
	
		World *world = new World(worldName);
		Population *population = new Population(popName, world);
		world->addPopulation(population);
		
		if(evoCount == 0) {
			world->setEvaluationMethod(evaluationMethod);
		}
		else {
			world->setEvaluationMethod(0);
		}
		
		
	
		Evolution::getEvolutionManager()->addEvolutionWorld(world);
	
	
		//Install Fitness
		FitnessFunction *fitness = 0;

	
		for(int i = 0; i < fitnessFunctionArg->getNumberOfEntries(); ++i) {
			QList<QString> fitArguments = fitnessFunctionArg->getEntryParameters(i);
			if((evoCount == 0 && fitArguments.size() <= 2)
			  || (fitArguments.size() > 2 
					&& fitArguments.at(2).toInt() == evoCount))
			{
				if(fitArguments.size() > 1) {
					fitness = Fitness::getFitnessManager()
						->createFitnessFunctionFromPrototype(fitArguments.at(0), fitArguments.at(1));
			
					if(fitness == 0) {
						cerr << "Failed to create FitnessFunction prototype ["
							<< fitArguments.at(0).toStdString().c_str() << endl;
					}
				}
				if(fitness != 0) {
					population->addFitnessFunction(fitness);
				}
			}
		}
		if(fitness == 0) {
			QString scriptName = "Script";
			if(scriptFitnessCounter > 0) {
				scriptName += QString::number(scriptFitnessCounter);
			}
			scriptFitnessCounter++;
		
			fitness = Fitness::getFitnessManager()
				->createFitnessFunctionFromPrototype("Script", scriptName);
			population->addFitnessFunction(fitness);
		}
	
		if(evoArguments.size() >= 1 && evoArguments.at(0).trimmed() == "ens3")
		{
			ENS3EvolutionAlgorithm evo(world);
		}
		else if(evoArguments.size() >= 1 && evoArguments.at(0).trimmed() == "neat") {
			NeatAlgorithm evo(world);
		}
		else if(evoArguments.size() < 1 || (evoArguments.size() >= 1 
				&& (evoArguments.at(0).trimmed() == "mens" || evoArguments.at(0).trimmed() == "icone")))
		{
			ModularNeuroEvolution1 evo(world);
		}
		if(evoArguments.size() >= 2) {
			world->getControlleAgentValue()->set(evoArguments.at(1));
		}

		//add individual statistics
		StandardIndividualStatistics indStatistics(population); 
		NeuralNetworkIndividualStatistics neuroStatistics(population);
		
		//Add neuralNetworkStatustic calculator.
		Statistics::getStatisticsManager()->addGenerationStatistics(
			new BasicNeuralNetworkStatistics(*population));

		createDefaultWorld = false;
	}

}
예제 #8
0
bool NerdNeuroEvoApplication::setupApplication()
{
	bool ok = true;


	//Choose Physics Engine (or external Yars simulator)
	CommandLineArgument *physicsArg = new CommandLineArgument("physics", "p", "<physicsLibrary>",
			"Uses <physicsLibrary> as physics engine. "
			"Currently there are [ode, yars].", 1,0, true);
	if(physicsArg->getNumberOfEntries() != 0 && !physicsArg->getEntryParameters(0).empty()
			&& physicsArg->getEntryParameters(0).at(0).trimmed() == "yars")
	{
		YarsCommunication();
	}
	else if(physicsArg->getNumberOfEntries() != 0 && !physicsArg->getEntryParameters(0).empty()
			&& physicsArg->getEntryParameters(0).at(0).trimmed() == "s2d")
	{
		Simple2D_Physics();
	}
	else {
		//install ODE PhysicsLayer
		ODE_Physics();
	}


	EvolutionSimulationPrototypes();

	//install file parser
	new SimpleObjectFileParser();

	//Install file interface for HTTPS communication.
	//new LoadAndStoreValueManagerPerGeneration();

	//Install fitness prototypes
	NeuroFitnessPrototypes();

	//Install standard NN functions and objects.
	StandardNeuralNetworkFunctions();

	//Install constraint manager.
	StandardConstraintCollection();

	//Install neuro modules
	NeuroModuleCollection();
	StandardTagCollection();

	//Enable NeuroModulation
	NeuroModulatorManager::getInstance();

	//Install network attribute characterizer
	new NeuralNetworkAttributes();

	new AutoStoreNetworksHelper();

	//Install statistics logger to save the current statistics to a file.
	new StatisticsLogger(Evolution::getEvolutionManager()->getEvolutionWorkingDirectoryValue());

	new EvolutionTerminationTrigger();

	//Install and initialize the settings logger (logging of settings history).
	SettingsLogger *settingsLogger = new SettingsLogger();
	settingsLogger->addValues("(?!.*/Evo/.*/Fitness/.*/Fitness/.*)(?!.*/Performance/.*)/Evo/.*/Algorithm/.*");
	settingsLogger->addValues("(?!.*/Evo/.*/Fitness/.*/Fitness/.*)(?!.*/Performance/.*)/Evo/.*/Pop/.*");
	settingsLogger->addValues("/Evo/.*/Fitness/.*/Fitness/CalculationMode");
	settingsLogger->addValues("/Control/NumberOfSteps");
	settingsLogger->addValues("/Control/NumberOfTries");

	new TerminateTryCollisionRule();

	new StepsPerSecondCounter();
	new SimObjectGroupPrinter();
	new SaveBestNetworksHandler(3);

	//add motor model rotation
	new ModelParameterRotator();

	//allow neural networks for other agents outside of the evolution.
	new NetworkAgentControlParser();

	UniversalNeuroScriptLoader();
	ScriptedModelLoader();

	//Add plugin to calculate the open degrees of freedom of the network during evolution.
	new NetworkDegreeOfFreedomCalculator();

	if(!buildSimulationModel()) {
		Core::log("NerdNeuroEvo: "
				  "Problem while building the simulation model.");
		ok = false;
	}

	if(!buildEvolutionSystem()) {
		Core::log("NerdNeuroEvo: "
				  "Problem while building the evolution system.");
		ok = false;
	}

	mRunner = new EvolutionRunner();

	return ok;

}
bool NetworkDynamicsPlotterApplication::setupApplication() {
	bool ok = true;

	//install network characterizer
	new NeuralNetworkAttributes();
	StandardTagCollection();
	NeuroModuleCollection();

	DynamicsPlotCollection();

	if(mEnableSimulator) {
		new SimObjectGroupPrinter();

		//Choose Physics Engine (or external Yars simulator)
		CommandLineArgument *physicsArg = new CommandLineArgument("physics", "p", "<physicsLibrary>",
											"Uses <physicsLibrary> as physics engine. "
											"Currently there are [ode, yars].", 1,0, true);

		if(physicsArg->getNumberOfEntries() != 0 && !physicsArg->getEntryParameters(0).empty()
			&& physicsArg->getEntryParameters(0).at(0).trimmed() == "yars")
		{
			YarsCommunication();
		}
		else if(physicsArg->getNumberOfEntries() != 0 && !physicsArg->getEntryParameters(0).empty()
			&& physicsArg->getEntryParameters(0).at(0).trimmed() == "s2d")
		{
			Simple2D_Physics();
		}
		else {
			//install ODE PhysicsLayer
			ODE_Physics();
		}

		//install file parser
		new SimpleObjectFileParser();

		new StepsPerSecondCounter();


		//Priovide the -net required to load a network for one or more agents.
		new NetworkAgentControlParser();

		new ModelParameterRotator();

		ScriptedModelLoader();
	}

	UniversalNeuroScriptLoader();


	//load a network if given.
	CommandLineArgument *netArg = new CommandLineArgument("loadNetwork", "net", "<networkFile",
								"Loads a NeuralNetwork to the NetworkEditor",
								1, 0, false, true);

	//Only provide a -net to load a network (or create a default in case no -net is given) when
	//NOT using a physical simulation.
	if(!mEnableSimulator) {
		if(netArg->getNumberOfEntries() > 0) {
			QStringList files = netArg->getEntryParameters(0);
			if(files.size() > 0) {
				QString errorMessage;
				QList<QString> warnings;
				NeuralNetwork *net = NeuralNetworkIO::createNetworkFromFile(files.at(0),
								&errorMessage, &warnings);

				if(errorMessage != "") {
					Core::log("Error while loading net: " + errorMessage, true);
				}
				if(!warnings.empty()) {
					for(QListIterator<QString> j(warnings); j.hasNext();) {
						Core::log("Warning: " + j.next(), true);
					}
				}

				if(dynamic_cast<ModularNeuralNetwork*>(net) != 0) {
					Neuro::getNeuralNetworkManager()->addNeuralNetwork(net);
				}
			}
		}
		else {
			Neuro::getNeuralNetworkManager()->addNeuralNetwork(new ModularNeuralNetwork(
											AdditiveTimeDiscreteActivationFunction(),
											TransferFunctionTanh(),
											SimpleSynapseFunction()));
		}
	}

	mExecutionLoop = new PlotterExecutionLoop();

	new MatlabExporter();

	return ok;
}
예제 #10
0
bool NerdNeuroSimApplication::setupApplication()
{
	
	//install simulation recorder
	new NetworkSimulationRecorder();
	
	
// 	StandardConstraintCollection();
// 	StandardNeuralNetworkFunctions();
	NeuroAndSimEvaluationStandardGuiApplication::setupApplication();
	
	//Install network characterization
	new NeuralNetworkAttributes();

	//Choose Physics Engine (or external Yars simulator)
	CommandLineArgument *physicsArg = new CommandLineArgument("physics", "p", "<physicsLibrary>",
			"Uses <physicsLibrary> as physics engine. "
			"Currently there are [ode, yars].", 1,0, true);
	if(physicsArg->getNumberOfEntries() != 0 && !physicsArg->getEntryParameters(0).empty()
			&& physicsArg->getEntryParameters(0).at(0).trimmed() == "yars")
	{
		YarsCommunication();
	}
	else if(physicsArg->getNumberOfEntries() != 0 && !physicsArg->getEntryParameters(0).empty()
			&& physicsArg->getEntryParameters(0).at(0).trimmed() == "s2d")
	{
		Simple2D_Physics();
	}
	else {
		//install ODE PhysicsLayer
		ODE_Physics();
	}
	
	
	
	new StepsPerSecondCounter();


	EvolutionSimulationPrototypes();

	//install file parser
	new SimpleObjectFileParser();
	//install neural network control parser.
	new NetworkAgentControlParser();

	new ActivationFrequencyCalculator("A");

	//add motor model rotation
	new ModelParameterRotator();

	//Install neuro modules
	NeuroModuleCollection();
	StandardTagCollection();
	
	//Enable NeuroModulation
	NeuroModulatorManager::getInstance();
	
	Fitness::install();
	new FitnessLogger();
	NeuroFitnessPrototypes();
	Statistics::getStatisticsManager();

	UniversalNeuroScriptLoader();
	ScriptedModelLoader();
	
	//Add plugin to calculate the open degrees of freedom of the network during evolution.
	new NetworkDegreeOfFreedomCalculator();
	
	//add simple fitness logger
	CommandLineArgument *useSimpleFitnessLogger = 
			new CommandLineArgument("simpleFitnessLogger", "sfl", "<logfile name>",
			"Logs all fitness values of all fitness functions "
			"incrementally to a file.", 1, 0, true, false);
	if(useSimpleFitnessLogger->getNumberOfEntries() != 0 
			&& !useSimpleFitnessLogger->getEntryParameters(0).empty())
	{
		new SimpleFitnessLogger(useSimpleFitnessLogger->getEntryParameters(0).at(0));
	}
	else if(NerdConstants::HackMode == true) { //HACK MODE remove!
		new SimpleFitnessLogger("simpleFitnessLog.txt");
	}

	return true;
}