void ModNeatExperiment7::webotsEvaluateIndividual(string xmlFileName, unsigned int groupnr, string pathToWorldFile) { stringstream xml_env_name; xml_env_name << "CPPN_XML_FILE" << groupnr; string xml_env_name_string = xml_env_name.str(); const char * xml_env_name_char = xml_env_name_string.c_str(); screen << "env var name: " << xml_env_name_string << endl; // set CPPN environment variable ::setenv(xml_env_name_char, xmlFileName.c_str(), true); stringstream ss; ss << groupnr; string str_groupnr = ss.str(); // calling the webots evaluation string command = "export " + xml_env_name_string + "=" + xmlFileName + " && "; // time // command += "--minimize --mode=fast --stdout --stderr "; command += "webots " + pathToWorldFile + str_groupnr + ".wbt"; // command += " | tee -a " + pathToExperiment + "/experiment.log"; // make system call (perform one WeBots individual simulation) int rez = runSystemCommand(command); if (rez != 0) { screen << "system() returned a non zero value: " << rez << "." << endl; // exit(-1); } }
int main() { int a = runSystemCommand("ls"); if(a> 0) { std::cout << "Execute the command successuflly" << std::endll; } }
void UI::encoderPress(void){ selectedEntry = menuOffset + cursorOffset; printf("Menu Selection: %d, %s\n", selectedEntry, menuItems[selectedEntry]); // menu items 0-10 are part of system menu if (selectedEntry < patchMenuOffset) { runSystemCommand(); } else { runPatch(); } }
double ModNeatExperiment7::processEvaluation(shared_ptr<NEAT::GeneticIndividual> individual, wxDC *drawContext, unsigned int groupnr) { // randomize arena worlds stringstream commandStream; commandStream << "python " << pathToExperiment << "/worlds/world_gen.py " << pathToExperiment << "/worlds/ " << groupnr + 1 << endl; string strCommand = commandStream.str(); screen << strCommand << endl; int rez = runSystemCommand(strCommand); if (rez != 0) { screen << "system() call to generate arena worlds exited with non-zero status: " << rez << "." << endl; exit(EXIT_FAILURE); } // individual->print(); stringstream id_str; // CPPN xml file name id_str << pathToCurrentCppnFolder << "/cppn_" << currGeneration << "_" << currIndividual << ".xml"; string xmlFileName = id_str.str(); // Write CPPN to file screen << "Writing file: " << "\n" << xmlFileName << endl; writeCppnToXml(individual, xmlFileName); // evaluate individual (alternate worldfile based on groupnr) webotsEvaluateIndividual(xmlFileName, groupnr + 1, pathToWorldFile); // read back the fitness double fitness = 0.0; fitness = readDoubleFromXml(xmlFileName, "Fitness"); screen << "Read back fitness: " << fitness << "\t\t\t\t\t\t\t\t(****) " << endl; // read back the collision data std::vector<double> collisionData; collisionData = readCollisionData(xmlFileName); screen << "Read back collision data : " << collisionData[0] << " - " << collisionData[1] << "\t\t\t\t\t(****) " << endl; // fitness must be positive fitness = (fitness > 0.0 ? fitness : 1.0E-8); screen << "ModNeatExperiment7 Bye!\n\n\n"; fflush(stdout); return fitness; }
void FileData::launchGame(Window* window) { LOG(LogInfo) << "Attempting to launch game..."; AudioManager::getInstance()->deinit(); VolumeControl::getInstance()->deinit(); window->deinit(); std::string command = mEnvData->mLaunchCommand; const std::string rom = escapePath(getPath()); const std::string basename = getPath().stem().string(); const std::string rom_raw = fs::path(getPath()).make_preferred().string(); command = strreplace(command, "%ROM%", rom); command = strreplace(command, "%BASENAME%", basename); command = strreplace(command, "%ROM_RAW%", rom_raw); LOG(LogInfo) << " " << command; int exitCode = runSystemCommand(command); if(exitCode != 0) { LOG(LogWarning) << "...launch terminated with nonzero exit code " << exitCode << "!"; } window->init(); VolumeControl::getInstance()->init(); AudioManager::getInstance()->init(); window->normalizeNextUpdate(); //update number of times the game has been launched FileData* gameToUpdate = getSourceFileData(); int timesPlayed = gameToUpdate->metadata.getInt("playcount") + 1; gameToUpdate->metadata.set("playcount", std::to_string(static_cast<long long>(timesPlayed))); //update last played time boost::posix_time::ptime time = boost::posix_time::second_clock::universal_time(); gameToUpdate->metadata.setTime("lastplayed", time); CollectionSystemManager::get()->updateCollectionSystems(gameToUpdate); }
void InputManager::doOnFinish() { assert(initialized()); std::string path = getConfigPath(); pugi::xml_document doc; if(fs::exists(path)) { pugi::xml_parse_result result = doc.load_file(path.c_str()); if(!result) { LOG(LogError) << "Error parsing input config: " << result.description(); } else { pugi::xml_node root = doc.child("inputList"); if(root) { root = root.find_child_by_attribute("inputAction", "type", "onfinish"); if(root) { for(pugi::xml_node command = root.child("command"); command; command = command.next_sibling("command")) { std::string tocall = command.text().get(); LOG(LogInfo) << " " << tocall; std::cout << "==============================================\ninput config finish command:\n"; int exitCode = runSystemCommand(tocall); std::cout << "==============================================\n"; if(exitCode != 0) { LOG(LogWarning) << "...launch terminated with nonzero exit code " << exitCode << "!"; } } } } } } }