Пример #1
0
/** 
 * Main   --  process command line, read in and pre-process the test file,
 *            call other functions to do the actual tests.
 */
int main(int argc, const char** argv) 
{
    if (processOptions(argc, argv, opts) != TRUE || opt_help) {
        printf(gHelpString);
        return -1;
    }

    if (processCollator() != TRUE) {
		fprintf(stderr, "Error creating collator for comparison\n");
		return -1;
	}

	fprintf(stdout, "Comparing source=%s and target=%s\n", opt_source,
			opt_target);
	int result = strcmp();
	if (result == 0) {
		fprintf(stdout, "source is equals to target\n"); 
	}
	else if (result < 0) {
		fprintf(stdout, "source is less than target\n"); 
	}
	else {
		fprintf(stdout, "source is greater than target\n"); 
	}
	
	ucol_close(collator);
	return 0;
}
Пример #2
0
/*!  Main function  */
int main (int argc, char *argv[]) {
  INFO *info;
  bool result = false;

  info = initialize ();

#if HAVE_MPI
  MPI_Init (&argc, &argv);

  MPI_Comm_rank (MPI_COMM_WORLD, &(info -> world_id));
  MPI_Comm_size (MPI_COMM_WORLD, &(info -> world_size));
#endif

#if HAVE_OPENMP
  info -> threads = omp_get_num_procs ();
  omp_set_num_threads (info -> threads);
#endif

  /*  Process the command line parameters and then check them;
  **  if either fail then print usage information  */
  if ((!processOptions (argc, argv, info)) || (!checkSettings (info))) {
    usage (argv[0]);
  }
  else {
    result = run (info);
  }

#if HAVE_MPI
  MPI_Finalize ();
#endif

  uninitialize (info);

  return (EXIT_SUCCESS);
}
Пример #3
0
/**
 * Initialize an interpreter instance.
 *
 * @param activity The root activity for the interpreter instance.
 * @param handlers The exit handlers used by all threads running under this instance.
 * @param defaultEnvironment
 *                 The default address environment for this interpreter instance.  Each
 *                 active interpreter instance can define its own default environment.
 */
void InterpreterInstance::initialize(RexxActivity *activity, RexxOption *options)
{
    rootActivity = activity;
    allActivities = new_list();
    searchExtensions = new_list();     // this will be filled in during options processing
    requiresFiles = new_directory();   // our list of loaded requires packages
    // this gets added to the entire active list.
    allActivities->append((RexxObject *)activity);
    globalReferences = new_identity_table();
    // create a default wrapper for this security manager
    securityManager = new SecurityManager(OREF_NULL);
    // set the default system address environment (can be overridden by options)
    defaultEnvironment = SystemInterpreter::getDefaultAddressName();
    // our list of command handlers (must be done before options are processed)
    commandHandlers = new_directory();

    // associate the thread with this instance
    activity->setupAttachedActivity(this);
    // create a local environment
    localEnvironment = new_directory();
    processOptions(options);
    // when handled originally, we didn't have the exits setup
    // do this now.
    activity->setupExits();
    // do system specific initialization
    sysInstance.initialize(this, options);
    // register the system command handlers for this platform.
    sysInstance.registerCommandHandlers(this);
    // now do the local initialization;
    Interpreter::initLocal();
}
Пример #4
0
/** 
 * Main   --  process command line, read in and pre-process the test file,
 *            call other functions to do the actual tests.
 */
int main(int argc, const char** argv) 
{
    if (processOptions(argc, argv, opts) != TRUE || opt_help) {
        printf(gHelpString);
        return -1;
    }

    if (processCollator() != TRUE) {
		fprintf(stderr, "Error creating collator\n");
		return -1;
	}

	if (processStringSearch() != TRUE) {
		fprintf(stderr, "Error creating string search\n");
		return -1;
	}

	fprintf(stdout, "Finding pattern %s in source %s\n", opt_pattern, 
		    opt_source);

	findPattern();
	ucol_close(collator);
	usearch_close(search);
	return 0;
}
Пример #5
0
void BrowserApplication::newLocalSocketConnection()
{
    QLocalSocket *socket = m_localServer->nextPendingConnection();
    if (!socket)
        return;
    socket->waitForReadyRead(1000);
    QDataStream stream(socket);
    QSharedDataPointer<ProcessOptions> processOptions(new ProcessOptions());
    stream >> *processOptions;
    QString url = processOptions->url;
    if (!url.isEmpty()) {
        QSettings settings;
        settings.beginGroup(QLatin1String("general"));
        int openLinksIn = settings.value(QLatin1String("openLinksIn"), 0).toInt();
        settings.endGroup();
        if (openLinksIn == 1)
            newMainWindow(processOptions);
        else {
            mainWindow()->tabWidget()->newTab(processOptions);
        }
        openUrl(url);
    }
    delete socket;
    mainWindow()->raise();
    mainWindow()->activateWindow();
}
Пример #6
0
int main( int argc, char **argv ) {
    int defs_ok = _LANG_DEFS_OK();

    if( argc < 5 || argc > 10 ) {
        fatal( "usage: msgencod [-w] [-i] [-ip] [-q] [-p] <gml> <msgc> <msgh> <levh>" );
    }
    if( ! defs_ok ) {
        fatal( "language index mismatch" );
    }
    processOptions( argv + 1 );
    readGML();
    if( flags.gen_gpick ) {
        writeMsgHGP();
        writeMsgCGP();
        writeLevHGP();
    }else{
        compressMsgs();
        writeMsgH();
        writeMsgC();
        writeLevH();
    }
    closeFiles();
    if( flags.international ) {
        dumpInternational();
    }
    if( ! flags.quiet ) {
        dumpStats();
    }
    if( warnings != 0 && flags.warnings_always_rebuild ) {
        forceRebuild();
    }
    return( errors ? EXIT_FAILURE : EXIT_SUCCESS );
}
Пример #7
0
 /** 
  * Uses sub-function for each bigger group of tags.
  */
 void ConfigReader::readConfig() {
     configXmlDoc = xmlReadFile(m_config->configPath().c_str(), NULL, 0);
     if(configXmlDoc == NULL) {
         _inf(
                 "%sThere is no config file (~/.keyfrog/config).\n"
                 "You must create one. You can use example config included with keyfrog.\n"
                 "It should be placed at `/usr/share/keyfrog/doc/sample-config' or\n"
                 "`/usr/local/share/keyfrog/doc/sample-config'. If it's not there,\n"
                 "download sources and check doc/ directory.%s\n"
                 , ccyan, creset);
     }
     xmlNode *rootElement = xmlDocGetRootElement(configXmlDoc);
     // Walk through nodes and invoke proper processing functions
     for (xmlNode * cur_node = rootElement->children; cur_node; cur_node = cur_node->next) {
         if (cur_node->type != XML_ELEMENT_NODE) {
             continue;
         }
         if(0==xmlStrcmp((const xmlChar *)"application-groups",cur_node->name)) {
             processGroups(cur_node->children);
         }
         if(0==xmlStrcmp((const xmlChar *)"options",cur_node->name)) {
             processOptions(cur_node->children);
         }
     }
     xmlFreeDoc(configXmlDoc);
 }
Пример #8
0
int
main(int argc, char* argv[])
{
	namespace po = boost::program_options;

	try {

		po::options_description desc = commonOptions();
		desc.add_options()
			("neurons,n", po::value<unsigned>()->default_value(1000), "number of neurons")
			("synapses,m", po::value<unsigned>()->default_value(1000), "number of synapses per neuron")
			("dmax,d", po::value<unsigned>()->default_value(1), "maximum excitatory delay,  where delays are uniform in range [1, dmax]")
		;

		po::variables_map vm = processOptions(argc, argv, desc);

		unsigned ncount = vm["neurons"].as<unsigned>();
		unsigned scount = vm["synapses"].as<unsigned>();
		unsigned dmax = vm["dmax"].as<unsigned>();
		unsigned duration = vm["duration"].as<unsigned>();
		unsigned stdp = vm["stdp-period"].as<unsigned>();
		unsigned verbose = vm["verbose"].as<unsigned>();
		bool runBenchmark = vm.count("benchmark") != 0;

		std::ofstream file;
		std::string filename;

		if(vm.count("output-file")) {
			filename = vm["output-file"].as<std::string>();
			file.open(filename.c_str()); // closes on destructor
		}

		std::ostream& out = filename.empty() ? std::cout : file;

		LOG(verbose, "Constructing network");
		boost::scoped_ptr<nemo::Network> net(nemo::random::construct(ncount, scount, dmax, stdp != 0));
		LOG(verbose, "Creating configuration");
		nemo::Configuration conf = configuration(vm);
		LOG(verbose, "Simulation will run on %s", conf.backendDescription());
		LOG(verbose, "Creating simulation");
		boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf));
		LOG(verbose, "Running simulation");
		if(runBenchmark) {
			benchmark(sim.get(), ncount, scount, vm);
		} else {
			simulate(sim.get(), duration, stdp, out);
		}
		LOG(verbose, "Simulation complete");
		return 0;
	} catch(std::exception& e) {
		std::cerr << e.what() << std::endl;
		return -1;
	} catch(...) {
		std::cerr << "random: An unknown error occurred\n";
		return -1;
	}

}
Пример #9
0
//Gets a request packet, figures out what to do, and does it
void TFTPserv::dispatchRequest(sockaddr_in &from, string buf){
	unsigned short op = ntohs(*((unsigned short*)buf.c_str()));
	unsigned int currentSpot = 2;
	switch (op){
	case OpRead:{
		currentSpot = buf.find('\x00',2);
		if(currentSpot == -1)
			return;
		string fn(buf.substr(2,currentSpot - 2)); //get filename
		if(fileIndexes.count(fn) == 0) //nonexistant file
			return;
		unsigned int newSpot = buf.find('\x00',currentSpot + 1);
		if(newSpot == -1) //invalid packet format
			return;
		//string mode(buf.substr(currentSpot + 1, newSpot - currentSpot - 1)); //don't really need this

		//New transfer!
		map<string,unsigned int> *transfer = new map<string,unsigned int>();
		(*transfer)["type"] = OpRead;
		(*transfer)["fromIp"] = *((unsigned int *)&from.sin_addr);
		(*transfer)["fromPort"] = from.sin_port;
		(*transfer)["file"] = fileIndexes[fn];
		(*transfer)["block"] = 1;
		(*transfer)["blksize"] = 512;
		(*transfer)["offset"] = 0;
		(*transfer)["timeout"] = 3;
		(*transfer)["lastSent"] = 0;
		(*transfer)["retries"] = 0;
		
		//process_options
		processOptions((struct sockaddr *)&from, sizeof(sockaddr_in), buf, *transfer, newSpot + 1);

		transfers.insert(transfer);
		break;
	}
	case OpAck:{
		//Got an ack
		unsigned short block = ntohs(*((unsigned short*)(buf.c_str() + 2)));
		map<string,unsigned int> *transfer = NULL;
		//Find transfer
		for (set<map<string,unsigned int> *>::iterator it = transfers.begin(); it != transfers.end(); ++it)
			if ((*(*it))["fromIp"] == *((unsigned int *)&from.sin_addr) 
					&& (*(*it))["fromPort"] == from.sin_port
					&& (*(*it))["block"] == block)
				transfer = *it;
		if(transfer == NULL)
			return;
		(*transfer)["offset"] = (*transfer)["offset"] + (*transfer)["blksize"];
		(*transfer)["block"] = (*transfer)["block"] + 1;
		(*transfer)["lastSent"] = 0;
		(*transfer)["retries"] = 0;
		if ((*transfer)["offset"] <= files[(*transfer)["file"]].length())
			return; //not complete
		transfers.erase(transfer); // we're done!
		delete transfer;
	}
	}
}
Пример #10
0
  /**
   * \brief Function to list sessions information
   * \return The pointer to the UMS_Data::ListSessions containing sessions information
   * \return raises an exception on error
   */
  UMS_Data::ListSessions*
  list(UMS_Data::ListSessionOptions_ptr option)
  {
    std::string query = (boost::format("SELECT DISTINCT vsessionid, userid, sessionkey, state, closepolicy, "
                                       "                timeout, lastconnect, creation, closure, authid "
                                       " FROM vsession, users, clmachine"
                                       " WHERE vsession.state            = %1%"
                                       "    AND users.status             = %1%"
                                       "    AND vsession.users_numuserid = users.numuserid"
                                       "    AND vsession.clmachine_numclmachineid=clmachine.numclmachineid")
                         % vishnu::STATUS_ACTIVE).str();

    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListSessions();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();

    if (! userServer.exist()) {
      throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
    }

    processOptions(userServer, option, query);
    query.append(" order by creation");
    //To get the list of sessions from the database
    boost::scoped_ptr<DatabaseResult> ListOfSessions (mdatabase->getResult(query));

    if (ListOfSessions->getNbTuples() != 0){
      for (size_t i = 0; i < ListOfSessions->getNbTuples(); ++i) {
        dbResults.clear();
        dbResults = ListOfSessions->get(i);
        dbResultIter = dbResults.begin();

        UMS_Data::Session_ptr session = ecoreFactory->createSession();
        session->setSessionId(*(dbResultIter));
        session->setUserId(*(++dbResultIter));
        session->setSessionKey(*(++dbResultIter));
        session->setStatus(vishnu::convertToInt(*(++dbResultIter)));
        session->setClosePolicy(vishnu::convertToInt(*(++dbResultIter)));
        session->setTimeout(vishnu::convertToInt(*(++dbResultIter)));
        session->setDateLastConnect(convertToTimeType(*(++dbResultIter)));
        session->setDateCreation(convertToTimeType(*(++dbResultIter)));
        session->setDateClosure(convertToTimeType(*(++dbResultIter)));
        session->setAuthenId(*(++dbResultIter));
        mlistObject->getSessions().push_back(session);
      }
    }

    return mlistObject;
  }
Пример #11
0
  /**
   * \brief Function to list commands information
   * \return The pointer to the UMS_Data::ListCommands containing commands information
   * \return raises an exception on error
   */
  UMS_Data::ListCommands* list(UMS_Data::ListCmdOptions_ptr option)
  {
    std::string query;
    std::vector<std::string>::iterator ii;
    std::vector<std::string> results;
    std::string description;

    query = "SELECT DISTINCT ctype, vsessionid, name, description, starttime, endtime, command.status"
            " FROM vsession, clmachine, command, users"
            " WHERE vsession.numsessionid=command.vsession_numsessionid"
            "  AND vsession.clmachine_numclmachineid=clmachine.numclmachineid"
            "  AND vsession.users_numuserid=users.numuserid";


    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListCommands();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (!userServer.exist()) {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }

    processOptions(userServer, option, query);
    query.append(" order by starttime");
    //To get the list of commands from the database
    boost::scoped_ptr<DatabaseResult> ListOfCommands (mdatabase->getResult(query.c_str()));
    for (size_t i = 0; i < ListOfCommands->getNbTuples(); ++i) {

      results.clear();
      results = ListOfCommands->get(i);
      ii = results.begin();

      UMS_Data::Command_ptr command = ecoreFactory->createCommand();
      vishnu::CmdType currentCmdType = static_cast<vishnu::CmdType>(vishnu::convertToInt(*ii));
      command->setCommandId(convertCmdType(static_cast<vishnu::CmdType>(currentCmdType)));
      command->setSessionId(*(++ii));
      command->setMachineId(*(++ii));
      //MAPPER CREATION
      Mapper* mapper = MapperRegistry::getInstance()->getMapper(convertypetoMapperName(currentCmdType));
      description = mapper->decode(*(++ii));
      command->setCmdDescription(description);
      command->setCmdStartTime(convertToTimeType(*(++ii)));
      command->setCmdEndTime(convertToTimeType(*(++ii)));
      command->setStatus(vishnu::convertToInt(*(++ii)));

      mlistObject->getCommands().push_back(command);
    }
    return mlistObject;
  }
Пример #12
0
int main(int argc, char* argv[]) {
    if (argc < 2) {
        printHelp();
        return 0;
    }
    char *filename;
    unsigned options = processOptions(argc, argv, &filename);

    struct timeval timebegin, timeend;
    gettimeofday(&timebegin, NULL);


    gbaHandle *gba = initGbaHandle("/dev/tty.usbmodem12341", MODE_NORMAL);

    int ret = 0;
    if (options & SEND_2ND_LOADER) {
        ret = secondStageSend(gba);
    }
    if (filename) {
        FILE *rom = fopen(filename,"rb");
        if (!gba || !rom) return -1;
        unsigned size;
        struct stat stats;
        fstat(fileno(rom), &stats);
        size = stats.st_size;
        if (size < 0x60 * 2) return -1;
        size = (size+0xf)&(~0xf); //Align to 16bytes

        unsigned char* romdata = malloc(size);
        fread(romdata, 1, size, rom);

        if ((options & SEND_VIA_2ND_LOADER) && ret == 0) {
            secondStageLoad(romdata, size, -1, gba);
        }
        if ((options & (SEND_2ND_LOADER | SEND_VIA_2ND_LOADER)) == 0) {
            gbaMultibootSend(romdata, size, gba);
        }

        free(romdata);
        fclose(rom);
    }

    freeGbaHandle(gba);

    gettimeofday(&timeend, NULL);
    double executiontime = timeend.tv_sec + (timeend.tv_usec / 1000000.0);
    executiontime -= timebegin.tv_sec + (timebegin.tv_usec / 1000000.0);
    fprintf(stderr,"\nTotal transfer time: %.2f seconds\n", executiontime);
    return 0;

}
Пример #13
0
  /**
   * \brief Function to list sessions information
   * \return The pointer to the UMS_Data::ListSessions containing sessions information
   * \return raises an exception on error
   */
  UMS_Data::ListSessions*
  list(UMS_Data::ListSessionOptions_ptr option)
  {
    std::string sqlListOfSessions = "SELECT vsessionid, userid, sessionkey, state, closepolicy, timeout, lastconnect, "
                                    "creation, closure, authid from vsession, users where vsession.users_numuserid=users.numuserid";

    std::vector<std::string>::iterator ii;
    std::vector<std::string> results;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListSessions();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (userServer.exist()) {

      processOptions(userServer, option, sqlListOfSessions);
      sqlListOfSessions.append(" order by creation");
      //To get the list of sessions from the database
      boost::scoped_ptr<DatabaseResult> ListOfSessions (mdatabaseInstance->getResult(sqlListOfSessions.c_str()));

      if (ListOfSessions->getNbTuples() != 0){
        for (size_t i = 0; i < ListOfSessions->getNbTuples(); ++i) {
          results.clear();
          results = ListOfSessions->get(i);
          ii = results.begin();

          UMS_Data::Session_ptr session = ecoreFactory->createSession();
          session->setSessionId(*(ii));
          session->setUserId(*(++ii));
          session->setSessionKey(*(++ii));
          session->setStatus(vishnu::convertToInt(*(++ii)));
          session->setClosePolicy(vishnu::convertToInt(*(++ii)));
          session->setTimeout(vishnu::convertToInt(*(++ii)));
          session->setDateLastConnect(convertToTimeType(*(++ii)));
          session->setDateCreation(convertToTimeType(*(++ii)));
          session->setDateClosure(convertToTimeType(*(++ii)));
          session->setAuthenId(*(++ii));

          mlistObject->getSessions().push_back(session);
        }
      }
    }
    else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;
  }
Пример #14
0
void Stage::prepare(PointTableRef table)
{
    for (size_t i = 0; i < m_inputs.size(); ++i)
    {
        Stage *prev = m_inputs[i];
        prev->prepare(table);
    }
    l_processOptions(m_options);
    processOptions(m_options);
    l_initialize(table);
    initialize(table);
    addDimensions(table.layout());
    prepared(table);
}
int main(int argc, char **argv) {
    command_data_t cmd_data;

    function_t *command = processOptions(argc, argv, &cmd_data);
    if (!command) {
        usage();
        return -1;
    }

    if (!raisePriorityAndLock(cmd_data.cpu_to_lock)) {
        return -1;
    }

    printf("%s\n", command->name);
    return (*command->ptr)(cmd_data);
}
Пример #16
0
  /**
   * \brief Function to list locoal accounts information
   * \return The pointer to the UMS_Data::ListLocalAccounts containing local accounts information
   * \return raises an exception on error
   */
  UMS_Data::ListLocalAccounts* list(UMS_Data::ListLocalAccOptions_ptr option)
  {
    std::string query = boost::str(boost::format("SELECT DISTINCT machineid, userid, aclogin, home"
                                                 " FROM account, machine, users"
                                                 " WHERE account.status               = %1%"
                                                 "   AND machine.status               = %1%"
                                                 "   AND users.status                 = %1%"
                                                 "   AND account.machine_nummachineid = machine.nummachineid"
                                                 "   AND account.users_numuserid      = users.numuserid"
                                                 ) % vishnu::STATUS_ACTIVE);


    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListLocalAccounts();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    if (! userServer.exist()) {
      throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
    }

    //To process options
    processOptions(userServer, option, query);

    boost::scoped_ptr<DatabaseResult> resultAccount(mdatabase->getResult(query));
    if (resultAccount->getNbTuples() != 0){
      for (size_t i = 0; i < resultAccount->getNbTuples(); ++i) {
        dbResults.clear();
        dbResults = resultAccount->get(i);
        dbResultIter = dbResults.begin();

        UMS_Data::LocalAccount_ptr localAccount = ecoreFactory->createLocalAccount();
        localAccount->setMachineId(*dbResultIter);
        localAccount->setUserId(*(++dbResultIter));
        localAccount->setAcLogin(*(++dbResultIter));
        localAccount->setHomeDirectory(*(++dbResultIter));

        mlistObject->getAccounts().push_back(localAccount);
      }
    }

    return mlistObject;
  }
Пример #17
0
// Cancel  file transfers
int
FileTransferServer::stopThread(const FMS_Data::StopTransferOptions& options) {


  if (! options.getTransferId().empty()
      || ! options.getUserId().empty()
      || ! options.getFromMachineId().empty()) {

    std::string sqlListOfPid = "SELECT transferId,processId "
                               " FROM filetransfer, vsession "
                               " WHERE vsession.numsessionid=filetransfer.vsession_numsessionid "
                               " AND filetransfer.status=0";

    std::string transferid;
    std::vector<std::string>::iterator iter;
    std::vector<std::string> results;

    msessionServer.check();

    processOptions(options, sqlListOfPid);

    boost::scoped_ptr<DatabaseResult> ListOfPid (FileTransferServer::getDatabaseInstance()->getResult(sqlListOfPid.c_str()));

    if (ListOfPid->getNbTuples() != 0){
      for (size_t i = 0; i < ListOfPid->getNbTuples(); ++i) {
        int pid;
        results.clear();
        results = ListOfPid->get(i);
        iter = results.begin();
        transferid = *iter;
        ++iter;
        pid = vishnu::convertToInt(*iter);
        stopThread(transferid,pid);
        ++iter;
      }

    } else {
      throw FMSVishnuException (ERRCODE_RUNTIME_ERROR, "There is no file transfer in progress ");
    }
  }

  return 0;
}
Пример #18
0
 /**
  * \brief Function to list machines information
  * \fn UMS_Data::ListMachines* list()
  * \return The pointer to the UMS_Data::ListMachines containing machines information
  * \return raises an exception on error
  */
 UMS_Data::ListMachines* list() {
    std::string sqlListofMachines = "SELECT machineid, name, site, status, lang, description from machine, description "
    "where machine.nummachineid = description.machine_nummachineid";

    std::vector<std::string>::iterator ii;
    std::vector<std::string> results;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListMachines();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (userServer.exist()) {

      //To process options
      processOptions(userServer, mparameters, sqlListofMachines);

      boost::scoped_ptr<DatabaseResult> ListofMachines (mdatabaseVishnu->getResult(sqlListofMachines.c_str()));
      if (ListofMachines->getNbTuples() != 0){
        for (size_t i = 0; i < ListofMachines->getNbTuples(); ++i) {
          results.clear();
          results = ListofMachines->get(i);
          ii = results.begin();
          UMS_Data::Machine_ptr machine = ecoreFactory->createMachine();
          machine->setMachineId(*ii);
          machine->setName(*(++ii));
          machine->setSite(*(++ii));
          machine->setStatus(convertToInt(*(++ii)));
          machine->setLanguage(*(++ii));
          machine->setMachineDescription(*(++ii));

          mlistObject->getMachines().push_back(machine);
        }
      }

    } else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;
  }
int main(int argc, char * argv[]) {

    MetronamicaOF2Parameters params;
    int err = processOptions(argc, argv, params);
    if (err != 0)
    {
        return EXIT_SUCCESS;
    }

    std::vector<double> real_lowerbounds  = {100,-1000,0.05,100,-1000,0.05,100,-1000,0.05,100,-1000,0.05,100,-1000,0.05,100,-1000,0.05,100,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,-50,-1000,0.05,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //lower bounds
    std::vector<double> real_upperbounds = {5000,1000,5,5000,1000,5,5000,1000,5,5000,1000,5,5000,1000,5,5000,1000,5,5000,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,100,1000,5,15,15,15,15,15,15,15,15,15,15,15,15,15,15,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; // upper bound of x
    int num_classes = 9;
    params.evaluator_id = 0;
    MetronamicaCalibrationObjectiveFunction metro_eval(params, FKS_CLUMP_KAPPA, SMALL_RANDSTAD, real_lowerbounds, real_upperbounds, num_classes);


    typedef std::mt19937 RNG;
    if (params.search_rand_seed == -1) params.search_rand_seed = std::chrono::system_clock::now().time_since_epoch().count();
    RNG rng(params.search_rand_seed);



    // Initialise population
    PopulationSPtr pop(new Population);
    if (params.pop_file_xml.first != "none")
    {
        pop = restore_population(params.pop_file_xml.second);
    }
    else if (params.pop_file_txt.first != "none")
    {
        pop.reset(new Population(params.pop_file_txt.second, metro_eval.getProblemDefinitions()));
    }
    else
    {
        std::cerr << "Warning: a file of solutions was not give. evaluating a random population\n";
        pop = intialisePopulationRandomDVAssignment(params.pop_size, metro_eval.getProblemDefinitions(), rng);
    }

    postProcessResults(metro_eval, pop, params);
    return EXIT_SUCCESS;

}
Пример #20
0
int main(int argc, char **argv) {

    printf("\n\t[*note*] Don't forget to run from same directory containing binaries [DetectAndLandmark] and [alignFace]...\n");

    if (argc < 2 ) {
        PrintUsage();
        exit(0);
    }

    serverPort = 0;
    serverHost = "localhost";
    processOptions(argc, argv);

    if (serverPort > 0) {
        printf("\tserver port: %d, base path: [%s], host: [%s]\n", serverPort, imageBasePath, serverHost);
        connectToServerAsWorker();
    }

    return 0;
}
Пример #21
0
	/*!
	 * Core of the tool. Calls processOptions() to handle command line options
	 * before performing the real work the tool does.
	 */
	int run()
	{
		try
		{
			// read command line options
			int result;
			if ((result = processOptions()) != -1)
			{
				return result;
			}
			
			// set verbose logging
			setVerboseLogging();
			
			// make sure a file was provided
			if (m_positionalArgs.size() < 1)
			{
				throw std::runtime_error("no output file path was provided");
			}
			
			// generate key files
			string_vector_t::const_iterator it = m_positionalArgs.begin();
			for (; it != m_positionalArgs.end(); ++it)
			{
				generateKeyFile(*it);
			}
		}
		catch (std::exception & e)
		{
			Log::log(Logger::ERROR, "error: %s\n", e.what());
			return 1;
		}
		catch (...)
		{
			Log::log(Logger::ERROR, "error: unexpected exception\n");
			return 1;
		}
		
		return 0;
	}
Пример #22
0
  /**
  * \brief Function to list machines information
  * \return The pointer to the UMS_Data::ListMachines containing machines information
  * \return raises an exception on error
  */
  UMS_Data::ListMachines* list(UMS_Data::ListMachineOptions_ptr option) {
    std::string sqlListofMachines = boost::str(boost::format("SELECT machineid, address, status, description"
                                                             " FROM machine"
                                                             " WHERE machine.status != %1%") % vishnu::STATUS_DELETED);
    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListMachines();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (userServer.exist()) {

      //To process options
      processOptions(userServer, option, sqlListofMachines);

      boost::scoped_ptr<DatabaseResult> ListofMachines (mdatabase->getResult(sqlListofMachines.c_str()));
      if (ListofMachines->getNbTuples() != 0){
        for (size_t i = 0; i < ListofMachines->getNbTuples(); ++i) {
          dbResults.clear();
          dbResults = ListofMachines->get(i);
          dbResultIter = dbResults.begin();
          UMS_Data::Machine_ptr machine = ecoreFactory->createMachine();
          machine->setMachineId(*dbResultIter);
          machine->setAddress(*(++dbResultIter));
          machine->setStatus(vishnu::convertToInt(*(++dbResultIter)));
          machine->setDescription(*(++dbResultIter));

          mlistObject->getMachines().push_back(machine);
        }
      }

    } else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;
  }
Пример #23
0
int
main(int argc,char **argv)
    {
    int argIndex = 1;

    int old;
    FILE *in,*out;
    RRA *r;

    level = 20000;
    sign = 0;
    direction = 0;
    delaySize = 1;
    argIndex = processOptions(argc,argv);

    if (argc-argIndex == 0)
        {
        in = stdin;
        out = stdout;
        }
    else if (argc-argIndex == 1)
        {
        in = OpenFile(argv[argIndex],"r");
        out = stdout;
        }
    else if (argc-argIndex == 2)
        {
        in = OpenFile(argv[argIndex],"r");
        out = OpenFile(argv[argIndex+1],"w");
        }
    else
        {
        printf("usage: filter [<input rra file> [<output wave file>]]\n");
        exit(-1);
        }

    r = newRRAHeader();
    readRRAHeader(in, r, 0);
    
    if (r->channels != 1)
        Fatal("distorter only works on mono audio files\n");

    factor = ((int)pow(2,r->bitsPerSample - 1)/level) / 3;
    if (level >= 20000) {
        factor = 1;
    }

    /* compute new number of samples, saving the old number */
    old = r->samples;
    r->samples = (int) (r->samples / step);

    writeRRAHeader(out,r,"modifiedBy: rraDistorter",0);

    /* restore the old number */
    r->samples = old;

    processData(in,out,r);

    fclose(in);
    fclose(out);

    return 0;
    }
Пример #24
0
int getOptions(int argc, char **argv) {
  splitFirstArg(argc, argv, &argc, &argv);
  return processOptions(copyright, argc, argv, options, NumberOf(options));
}
Пример #25
0
  /**
  * \brief Function to list users information
  * \return The pointer to the UMS_Data::ListUsers containing users information
  * \return raises an exception on error
  */
  UMS_Data::ListUsers* list(UMS_Data::ListUsersOptions_ptr option) {

    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> results;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListUsers();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (userServer.exist()) {

      std::string sqlQuery = "";
      if ( userServer.isAdmin()) {
        // query all users
        sqlQuery = boost::str(boost::format(
                                "SELECT userid, pwd, firstname, lastname, privilege, email, status"
                                " FROM users"
                                " WHERE users.status<>%1%") % vishnu::STATUS_DELETED);
      } else {
        // dont query admin users
        sqlQuery = boost::str(boost::format(
                                "SELECT userid, pwd, firstname, lastname, privilege, email, status"
                                " FROM users"
                                " WHERE userid<>'%1%'"
                                " AND users.status<>%2%") % vishnu::ROOTUSERNAME % vishnu::STATUS_DELETED);
      }

      processOptions(userServer, option, sqlQuery);

      sqlQuery.append(" ORDER BY userid");

      //To get the list of users from the database
      boost::scoped_ptr<DatabaseResult> ListofUsers (mdatabaseInstance->getResult(sqlQuery));

      if (ListofUsers->getNbTuples() != 0){
        for (size_t resultIndex = 0; resultIndex < ListofUsers->getNbTuples(); ++resultIndex) {
          results.clear();
          results = ListofUsers->get(resultIndex);
          dbResultIter = results.begin();
          UMS_Data::User_ptr user = ecoreFactory->createUser();
          user->setUserId(*dbResultIter);
          user->setPassword(*(++dbResultIter));
          user->setFirstname(*(++dbResultIter));
          user->setLastname(*(++dbResultIter));
          user->setPrivilege(vishnu::convertToInt(*(++dbResultIter)));
          user->setEmail(*(++dbResultIter));
          user->setStatus(vishnu::convertToInt(*(++dbResultIter)));

          mlistObject->getUsers().push_back(user);
        }
      }
    }
    else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;


  }
int main(int argc, char * argv[]) {
    boost::mpi::environment env(argc, argv);
    boost::mpi::communicator world;

    MetronamicaOF2Parameters params;
    int err = processOptions(argc, argv, params);
    if (err != 0)
    {
        return EXIT_SUCCESS;
    }

//    std::vector<double> real_lowerbounds  = {500,   -1000,   0.05,   500,   -1000,   0.05,   500,   -1000,   0.05,   500,   -1000,   0.05,   500,   -1000,   0.05,   500,   -1000,   0.05,   500,   -1000,   0.05,   500,   -1000,   0.05,   500,   -1000,   0.05,   500,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   -100,   -1000,   0.05,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0 };
//    std::vector<double> real_upperbounds =  {5000,   1000,   5,   5000,   1000,   5,   5000,   1000,   5,   5000,   1000,   5,   5000,   1000,   5,   5000,   1000,   5,   5000,   1000,   5,   5000,   1000,   5,   5000,   1000,   5,   5000,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   100,   1000,   5,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   15,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1   };
//    int num_classes = 16;
    params.evaluator_id = world.rank();
    MetronamicaCalibrationObjectiveFunction metro_eval(params);

    
    
    if (world.rank() == 0)
    {
//        std::ofstream ofs(time_fname.c_str());
//        if (ofs.is_open())
//        {
//            t.reset(new boost::timer::auto_cpu_timer(timer_info, 3));
//        }
//        else
//        {
//            std::cerr << "Error: Could not open file for writing time elapsed for search, using std::cout";
//            t.reset(new boost::timer::auto_cpu_timer(3));
//        }


        //create evaluator server
        boost::filesystem::path eval_log = params.save_dir.second / "evaluation_timing.log";
        std::ofstream eval_strm(eval_log.c_str());
        ParallelEvaluatePopServerNonBlocking eval_server(env, world, metro_eval.getProblemDefinitions());
        if (eval_strm.is_open())
        {
            eval_server.log(ParallelEvaluatorBase::LVL1, eval_strm);
        }

        // The random number generator
        typedef std::mt19937 RNG;
        if (params.search_rand_seed == -1) params.search_rand_seed = std::chrono::system_clock::now().time_since_epoch().count();
        RNG rng(params.search_rand_seed);


        // The optimiser
        NSGAII<RNG> optimiser(rng, eval_server);
        if (eval_strm.is_open())
        {
            optimiser.log(eval_strm, eval_log, NSGAII<RNG>::LVL1 );
        }
        std::vector<double> ref_point =  {-0.1, 1, -0.1};
        std::vector<double> unitise_point = {1,0, 1};
        createCheckpoints(optimiser, params, ref_point, unitise_point);

        // Initialise population

        PopulationSPtr pop(new Population);
        if (params.pop_file_xml.first != "none")
        {
            pop = restore_population(params.pop_file_xml.second);
        }
        else if (params.pop_file_txt.first != "none")
        {
            pop.reset(new Population(params.pop_file_txt.second, metro_eval.getProblemDefinitions()));
        }
        else
        {
            pop = intialisePopulationRandomDVAssignment(params.pop_size, metro_eval.getProblemDefinitions(), rng);
        }
        optimiser.getRealMutationOperator().setMutationInverseDVSize(pop->at(0));


//        hvol(pop);
//        std::cout << "Hypervolume: " << hvol.getVal() << std::endl;

        // Run the optimisation
        optimiser(pop);

        postProcessResults(metro_eval, pop, params);

    }
    else
    {
        std::string log_file_name = "worker_" + std::to_string(world.rank()) + "_timing.log";
        boost::filesystem::path eval_log = params.save_dir.second / log_file_name;
        std::ofstream eval_strm(eval_log.c_str());
        ParallelEvaluatePopClientNonBlocking eval_client(env, world, metro_eval.getProblemDefinitions(), metro_eval);
        if (eval_strm.is_open())
        {
            eval_client.log(ParallelEvaluatorBase::LVL1, eval_strm);
        }

        //logging eval_client
//        std::string log_filename = "evaluation_timing_worker" + std::to_string(world.rank()) + ".log";
//        boost::filesystem::path eval_log = working_dir.second / log_filename;
//        std::ofstream eval_strm(eval_log.c_str());
//        if (eval_strm.is_open())
//        {
//            eval_client.log(ParallelEvaluatorBase::LVL1, eval_strm);
//        }
        eval_client();
    }
}
Пример #27
0
int main(int argc, char *argv[]) {
	if (argc < 2) {
		std::cerr << "USAGE: ./aixi agent.conf [--option1=value1 --option2=value2 ...] " << std::endl;
		std::cerr << "The first argument should indicate the location of the configuration file. Further arguments can either be specified in the config file or passed as command line option. Command line options are used over options specified in the file." << std::endl;
		return -1;
	}
    // Initialize random seed
    srand(time(NULL));

	// Load configuration options
	options_t options;

	// Default configuration values
	options["ct-depth"] = "16";
	options["agent-horizon"] = "3";
	options["exploration"] = "0";     // do not explore
	options["explore-decay"] = "1.0"; // exploration rate does not decay
    options["mc-timelimit"] = "500"; //number of mc simulations per search
    options["terminate-age"] = "10000";
    options["log"]  = "log";
    options["load-ct"] = "";
    options["write-ct"] = "";
    options["intermediate-ct"] = "1";

	// Read configuration options
	std::ifstream conf(argv[1]);
	if (!conf.is_open()) {
		std::cerr << "ERROR: Could not open file '" << argv[1] << "' now exiting" << std::endl;
		return -1;
	}
	processOptions(conf, options);
	conf.close();

    //parse command line options (overwrites values of config files)
    parseCmdOptions(argc, argv, options);

	// Set up logging
	std::string log_file = options["log"];
	verboseLog.open((log_file + ".log").c_str());
	compactLog.open((log_file + ".csv").c_str());

	// Print header to compactLog
	compactLog << "cycle, observation, reward, action, explored, explore_rate, total reward, average reward" << std::endl;

	// Set up the environment
	Environment *env;
	std::string environment_name = options["environment"];
	if (environment_name == "coin-flip") {
		env = new CoinFlip(options);
		options["agent-actions"] = "2";
		options["observation-bits"] = "1";
		options["reward-bits"] = "1";
	}
	else if (environment_name == "tiger") {
		env = new Tiger(options);
		options["agent-actions"] = "3";
		options["observation-bits"] = "2";
		options["reward-bits"] = "7";
	}
	else if (environment_name == "biased-rock-paper-scissor") {
		env = new BiasedRockPaperScissor(options);
		options["agent-actions"] = "3";
		options["observation-bits"] = "2";
		options["reward-bits"] = "2";
	}
	else if (environment_name == "kuhn-poker") {
		env = new KuhnPoker(options);
		options["agent-actions"] = "2";
		options["observation-bits"] = "4";
		options["reward-bits"] = "3";
	}
	else if (environment_name == "pacman") {
        env = new Pacman(options);
		options["agent-actions"] = "4";
		options["observation-bits"] = "16";
		options["reward-bits"] = "8";
	}
	else {
		std::cerr << "ERROR: unknown environment '" << environment_name << "'" << std::endl;
		return -1;
	}

    printOptions(options);

	// Set up the agent
	Agent ai(options);

	// If specified, load a pretrained context tree.
    if(options["load-ct"] != ""){
        std::ifstream ct(options["load-ct"].c_str());

        if(ct.is_open()){
            ai.loadCT(ct);
        }
        else{
            std::cerr << "WARNING: specified context tree file could not be loaded.\n";
        }
        ct.close();
    }  

	// Run the main agent/environment interaction loop
	mainLoop(ai, *env, options);

	verboseLog.close();
	compactLog.close();

	return 0;
}
Пример #28
0
//------------------------------------------------------------------------------------------
//
//   main          for ugrep
//
//           Structurally, all use of the ICU Regular Expression API is in main(),
//           and all of the supporting stuff necessary to make a running program, but
//           not directly related to regular expressions, is factored out into these other
//           functions.
//
//------------------------------------------------------------------------------------------
int main(int argc, const char** argv) {
    UBool     matchFound = FALSE;

    //
    //  Process the commmand line options.
    //
    processOptions(argc, argv);

    //
    // Create a RegexPattern object from the user supplied pattern string.
    //
    UErrorCode status = U_ZERO_ERROR;   // All ICU operations report success or failure
                                        //   in a status variable.

    UParseError    parseErr;            // In the event of a syntax error in the regex pattern,
                                        //   this struct will contain the position of the
                                        //   error.

    RegexPattern  *rePat = RegexPattern::compile(pattern, parseErr, status);
                                        // Note that C++ is doing an automatic conversion
                                        //  of the (char *) pattern to a temporary
                                        //  UnicodeString object.
    if (U_FAILURE(status)) {
        fprintf(stderr, "ugrep:  error in pattern: \"%s\" at position %d\n",
            u_errorName(status), parseErr.offset);
        exit(-1);
    }

    //
    // Create a RegexMatcher from the newly created pattern.
    //
    UnicodeString empty;
    RegexMatcher *matcher = rePat->matcher(empty, status);
    if (U_FAILURE(status)) {
        fprintf(stderr, "ugrep:  error in creating RegexMatcher: \"%s\"\n",
            u_errorName(status));
        exit(-1);
    }

    //
    // Loop, processing each of the input files.
    //
    for (int fileNum=firstFileNum; fileNum < argc; fileNum++) {
        readFile(argv[fileNum]);

        //
        //  Loop through the lines of a file, trying to match the regex pattern on each.
        //
        for (nextLine(0); lineStart<fileLen; nextLine(lineEnd)) {
            UnicodeString s(FALSE, ucharBuf+lineStart, lineEnd-lineStart);
            matcher->reset(s);
            if (matcher->find()) {
                matchFound = TRUE;
                printMatch();
            }
        }
    }

    //
    //  Clean up
    //
    delete matcher;
    delete rePat;
    free(ucharBuf);
    free(charBuf);
    ucnv_close(outConverter);
    
    u_cleanup();       // shut down ICU, release any cached data it owns.

    return matchFound? 0: 1;
}
Пример #29
0
bool
bootpc_init(bool update_files, bool forever)
{
  struct bootp_packet call;
  struct bootp_packet reply;
  static u_int32_t xid = ~0xFF;
  
  struct ifreq ireq;
  struct ifnet *ifp;
  struct socket *so;
  int j;
  int error;
  struct sockaddr_in myaddr;
  struct ifaddr *ifa;
  struct sockaddr_dl *sdl = NULL;
  char *delim;
  struct proc *procp = NULL;

  /*
   * If already filled in, don't touch it here 
   */
  if (nfs_diskless_valid)
    return true;

  /*
   * If we are to update the files create the root
   * file structure.
   */
  if (update_files)
    if (rtems_create_root_fs () < 0) {
      printf("Error creating the root filesystem.\nFile not created.\n");
      update_files = 0;
    }

  if (dhcp_hostname != NULL) {
	/* free it */
    dhcp_hostname=bootp_strdup_realloc(dhcp_hostname,0);
  }

  /*
   * Find a network interface.
   */
  for (ifp = ifnet; ifp != 0; ifp = ifp->if_next)
    if ((ifp->if_flags &
      (IFF_LOOPBACK|IFF_POINTOPOINT)) == 0)
	break;
  if (ifp == NULL) {
    printf("bootpc_init: no suitable interface\n");
    return false;
  }
  bzero(&ireq,sizeof(ireq));
  sprintf(ireq.ifr_name, "%s%d", ifp->if_name,ifp->if_unit);
  printf("bootpc_init: using network interface '%s'\n",
	 ireq.ifr_name);

  if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0,procp)) != 0) {
    printf("bootpc_init: socreate, error=%d", error);
    return false;
  }
  if (bootpc_fakeup_interface(&ireq,so,procp) != 0) {
    soclose(so);
    return false;
  }

  /* Get HW address */

  for (ifa = ifp->if_addrlist;ifa; ifa = ifa->ifa_next)
    if (ifa->ifa_addr->sa_family == AF_LINK &&
        (sdl = ((struct sockaddr_dl *) ifa->ifa_addr)) &&
        sdl->sdl_type == IFT_ETHER)
      break;
  
  if (!sdl) {
    printf("bootpc: Unable to find HW address\n");
    soclose(so);
    return false;
  }
  if (sdl->sdl_alen != EALEN ) {
    printf("bootpc: HW address len is %d, expected value is %d\n",
	   sdl->sdl_alen,EALEN);
    soclose(so);
    return false;
  }

  printf("bootpc hw address is ");
  delim="";
  for (j=0;j<sdl->sdl_alen;j++) {
    printf("%s%x",delim,((unsigned char *)LLADDR(sdl))[j]);
    delim=":";
  }
  printf("\n");

#if 0
  bootpboot_p_iflist();
  bootpboot_p_rtlist();
#endif

  while (true) {
    bzero((caddr_t) &call, sizeof(call));

    /* bootpc part */
    call.op = 1; 			/* BOOTREQUEST */
    call.htype= 1;		/* 10mb ethernet */
    call.hlen=sdl->sdl_alen;	/* Hardware address length */
    call.hops=0;	
    xid++;
    call.xid = txdr_unsigned(xid);
    bcopy(LLADDR(sdl),&call.chaddr,sdl->sdl_alen);
  
    call.vend[0]=99;
    call.vend[1]=130;
    call.vend[2]=83;
    call.vend[3]=99;
    call.vend[4]=255;
  
    call.secs = 0;
    call.flags = htons(0x8000); /* We need an broadcast answer */
  
    error = bootpc_call(&call,&reply,procp);
  
    if (!error)
      break;
    
    printf("BOOTP call failed -- error %d", error);

    if (!forever) {
      soclose(so);
      return false;
    }
  }
  
  /*
   * Initialize network address structures
   */
  bzero(&myaddr,sizeof(myaddr));
  bzero(&dhcp_netmask,sizeof(dhcp_netmask));
  bzero(&dhcp_gw,sizeof(dhcp_gw));
  myaddr.sin_len = sizeof(myaddr);
  myaddr.sin_family = AF_INET;
  dhcp_netmask.sin_len = sizeof(dhcp_netmask);
  dhcp_netmask.sin_family = AF_INET;
  dhcp_gw.sin_len = sizeof(dhcp_gw);
  dhcp_gw.sin_family= AF_INET;

  /*
   * Set our address
   */
  myaddr.sin_addr = reply.yiaddr;
  printip("My ip address",myaddr.sin_addr);

  /*
   * Process BOOTP/DHCP options
   */
  if (reply.vend[0]==99 && reply.vend[1]==130 &&
      reply.vend[2]==83 && reply.vend[3]==99) {
    processOptions (&reply.vend[4], sizeof(reply.vend) - 4);
  }
  if (dhcpOptionOverload & 1) {
    processOptions ((unsigned char *)reply.file, sizeof reply.file);
  }
  else {
    if (reply.file[0])
      rtems_bsdnet_bootp_boot_file_name = 
	bootp_strdup_realloc(rtems_bsdnet_bootp_boot_file_name,reply.file);
  }
  if (dhcpOptionOverload & 2) {
    processOptions ((unsigned char *)reply.sname, sizeof reply.sname);
  }
  else {
    if (reply.sname[0])
      rtems_bsdnet_bootp_server_name = 
	bootp_strdup_realloc(rtems_bsdnet_bootp_server_name,reply.sname);
  }
  if (rtems_bsdnet_bootp_server_name)
    printf ("Server name is %s\n", rtems_bsdnet_bootp_server_name);
  if (rtems_bsdnet_bootp_boot_file_name)
    printf ("Boot file is %s\n", rtems_bsdnet_bootp_boot_file_name);
  if (rtems_bsdnet_bootp_cmdline)
    printf ("Command line is %s\n", rtems_bsdnet_bootp_cmdline);

  /*
   * Use defaults if values were not supplied by BOOTP/DHCP options
   */
  if (!dhcp_gotnetmask) {
    if (IN_CLASSA(ntohl(myaddr.sin_addr.s_addr)))
      dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET);
    else if (IN_CLASSB(ntohl(myaddr.sin_addr.s_addr)))
      dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET);
    else 
      dhcp_netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET);
  }
  printip ("Subnet mask", dhcp_netmask.sin_addr);
  if (!dhcp_gotserver)
   rtems_bsdnet_bootp_server_address = reply.siaddr;
  printip ("Server ip address" ,rtems_bsdnet_bootp_server_address);
  if (!dhcp_gotgw)
    dhcp_gw.sin_addr = reply.giaddr;
  printip ("Gateway ip address", dhcp_gw.sin_addr);
  if (!dhcp_gotlogserver)
    rtems_bsdnet_log_host_address = rtems_bsdnet_bootp_server_address;
  printip ("Log server ip address", rtems_bsdnet_log_host_address);

  /*
   * Update the files if we are asked too.
   */
  if (update_files) {
    char *dn = rtems_bsdnet_domain_name;
    char *hn = dhcp_hostname;
    if (!dn)
      dn = "mydomain";
    if (!hn)
      hn = "me";
    rtems_rootfs_append_host_rec(myaddr.sin_addr.s_addr, hn, dn);

    /*
     * Should the given domainname be used here ?
     */
    if (dhcp_gotserver) {
      if (rtems_bsdnet_bootp_server_name)
        hn = rtems_bsdnet_bootp_server_name;
      else
        hn = "bootps";
      rtems_rootfs_append_host_rec(rtems_bsdnet_bootp_server_address.s_addr,
                                   hn, dn);
    }

    if (dhcp_gotlogserver) {
      rtems_rootfs_append_host_rec(rtems_bsdnet_log_host_address.s_addr,
                                   "logs", dn);
    }

    /*
     * Setup the DNS configuration file /etc/resolv.conf.
     */
    if (rtems_bsdnet_nameserver_count) {
      int        i;
      char       buf[64];
      const char *bufl[1];

      bufl[0] = buf;
      
#define MKFILE_MODE (S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH)
      
      if (rtems_bsdnet_domain_name &&
          (strlen(rtems_bsdnet_domain_name) < (sizeof(buf) - 1))) {
        strcpy(buf, "search ");
        strcat(buf, rtems_bsdnet_domain_name);
        strcat(buf, "\n");
        rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl);
      }

      for (i = 0; i < rtems_bsdnet_nameserver_count; i++) {
        strcpy(buf, "nameserver ");
        strcat(buf, inet_ntoa(rtems_bsdnet_nameserver[i]));
        strcat(buf, "\n");
        if (rtems_rootfs_file_append ("/etc/resolv.conf", MKFILE_MODE, 1, bufl))
          break;
      }
    }
  }

  /*
   * Configure the interface with the new settings
   */
  error = bootpc_adjust_interface(&ireq,so,
				  &myaddr,&dhcp_netmask,&dhcp_gw,procp);
  soclose(so);

  return true;
}
Пример #30
0
void 
decodeCML (int argc, char *argv[])
{
  initializeOptions();
  processOptions(argc, argv);
}