void SelectionSetting::attemptToChangeParam(string new_param)
{
  new_param[0] = toupper(new_param[0]);
  std::transform(new_param.begin() + 1, new_param.end(), new_param.begin() + 1,
                 ::tolower);
    
  changeParam(new_param);
}
Пример #2
0
void ListSetting::attemptToChangeParam(string new_param)
{
  new_param[0] = toupper(new_param[0]);

  if (!new_param.empty())
  {
    std::transform(new_param.begin() + 1, new_param.end(), new_param.begin() + 1,
                   ::tolower);
  }

  changeParam(new_param);
}
Пример #3
0
int main(int argc, const char *argv[])
{
	// 'true' satisfaccion restricciones duras
	bool type = true;
	// 'true' selecciona mejores
	bool cloneSelType = true;
	// 'true' remplaza los mas malos
	bool replaceType = true;
	// 'true' Se clonan mediante formula
	bool cloneType = true;

	timespec ts, te;

	clock_gettime(CLOCK_REALTIME, &ts);
	population[POP].fitness = 10000;	
	if(!checkFile(argc,argv))
		return 0;

	changeParam(argv);
//	cout << "ClonationFactor: "<<clonationFactor << endl;
//	cout << "ClonationRate: " << clonationRate << endl;
//	cout << "ReplaceRate: " << replaceRate << endl;
	
	inputReading(argv[1]);
	generation = 0;

	initPopulation(type);
	evaluation(population, type);

	while(generation<GENS){
		cleanPops();
		selection(clonationRate, population);
		clonation(tmpPop, cloneType);
		hypermutation();
		evaluation(clonePop, type);
		cloneSelection(clonePop, cloneSelType);
		cloneInsertion();
		newGeneration(replaceRate, replaceType);
		evaluation(population, type);
		generation++;
	}
	
	clock_gettime(CLOCK_REALTIME, &te);

//	printFile(argv[1],population[0].gene,population[0].fitness,(te.tv_sec-ts.tv_sec), (te.tv_nsec-ts.tv_nsec));
//	printFile(population[0].fitness);
	cout << replaceRate << " " << population[0].fitness << " " <<  (te.tv_sec-ts.tv_sec)<<"."<<(te.tv_nsec-ts.tv_nsec) << endl;

	return 0;
}
Пример #4
0
int numcheck(void)
{
   if(getDynamicVP()) return 1;
   cleanDecayTable();
   ForceUG=forceUG;
   {
     char  mmenu[]="\026" 
                   " Parameters           "
                   " All Constraints      "
                   " Masses,Widths,Branch.";
     int m0=1,err;
     void (*F10)(int);
     void (*F6)(int);
     F10=f3_key[7];    F6=f3_key[3];
     f3_key[3]=localF6;
chdir("results");
outputDir="./"; 
     err=calcMainFunc();
     if(Warnings) messanykey(5,10,Warnings);
     for(;m0;)
     {  menu1(56,7,"",mmenu,"s_num_*",NULL,&m0);
       if(err && (m0==2||m0==3)) 
       { char txt[100];
         sprintf(txt," Can not calculate %s ",varNames[err]);
         messanykey(12,15,txt);
       }   
       switch(m0)
       {                
         case 1: if(changeParam(56,8))
                 {
                   cleanDecayTable();
                   err=calcMainFunc();  
                   if(Warnings) messanykey(5,10,Warnings);        
                 }
                 break;
         case 2: if(nModelFunc) {if(!err ) show_dependence(56,8);} 
                 else messanykey(5,10,"There are no public constraints in this model.");  
                 break;           
         case 3: if(!err) show_spectrum(56,8); break;
       }
     }
chdir("..");
outputDir="results/";
       f3_key[7]=F10;   
       f3_key[3]=F6;       
   }
   return 0;
}
Пример #5
0
string const ListSetting::setParam()
{
  string user_selection;
  string new_setting;
  bool new_setting_set = false;

  ui_.writeString("What do you want to do?", true, "green");
  ui_.writeString("add     - add " + ONE_WORD_DESCRIPTION_ + " to the list", true);
  ui_.writeString("remove  - remove " + ONE_WORD_DESCRIPTION_ + " from the list", true);
  ui_.writeString("rewrite - rewrite the whole list", true);
  ui_.writeString("exit    - go back to all settings", true);

  do
  {
    user_selection = ui_.readStringNoCapitalize();

    if (user_selection == "exit")
    {
      return getParam();
    }
    else if (user_selection == "add")
    {
      ui_.writeString("Please enter a " + ONE_WORD_DESCRIPTION_ + " to add (if you want to add multiple " + ONE_WORD_DESCRIPTION_ + "s, separate them with \",\")", true);
      do
      {
        string value_to_add = ui_.readStringNoCapitalize();

        if (value_to_add == "exit")
        {
          return getParam();
        }
        else
        {
          if (getParam().empty())
          {
            new_setting = value_to_add;
          }
          else
          {
            new_setting = getParam() + "," + value_to_add;
          }
          while (*new_setting.rbegin() == ',')
          {
            new_setting = new_setting.substr(0, new_setting.size() - 1);
          }

          new_setting_set = true;
        }
      }
      while (!new_setting_set);
    }
    else if (user_selection == "remove")
    {
      ui_.writeString("Please enter the " + ONE_WORD_DESCRIPTION_ + " to remove", true);
      do
      {
        string value_to_remove = ui_.readStringNoCapitalize();

        if (value_to_remove.find(",") != std::string::npos)
        {
          ui_.writeString("Please enter a string without \",\"", true);
        }
        else if (value_to_remove == "exit")
        {
          return getParam();
        }
        else
        {
          if (stringIsIncluded(value_to_remove))
          {
            new_setting = removeFromSettingsString(value_to_remove);
            new_setting_set = true;
          }
          else
          {
            ui_.writeString(ONE_WORD_DESCRIPTION_ + " is not included in list.", true);
            ui_.readString(false);
            return getParam();
          }
        }
      }
      while (!new_setting_set);
    }
    else if (user_selection == "rewrite")
    {
      ui_.writeString("Please a new list of " + ONE_WORD_DESCRIPTION_ + "s (separate it with \",\")", true);
      string new_list = ui_.readStringNoCapitalize();

      if (new_list == "exit")
      {
        return getParam();
      }
      else
      {
        while (*new_list.rbegin() == ',')
        {
          new_list = new_list.substr(0, new_list.size() - 1);
        }
        new_setting = new_list;
        new_setting_set = true;
      }
    }
  } while (!new_setting_set);

  changeParam(new_setting);

  ui_.writeString("Saved.", true, "green");
  ui_.readString(false);

  return new_setting;
}
Пример #6
0
float dynamixObjective(GAGenome &c) {
  GA1DArrayGenome<double> &genome = (GA1DArrayGenome<double> &)c;
  // get MPI rank and size
  int rank, size;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);

  // variables and output
  double g1 = genome.gene(0);
  double g2 = genome.gene(1);
  double g1_c = genome.gene(2);
  float output = 1.0;

  pid_t pid;
  int status;

  // array of strings for commands + arguments
  char * args [10];
  for (int ii = 0; ii < 10; ii++) {
    args[ii] = new char [1000];
  }

  std::string arg = "/extra/scratch/foo";

  // names for original directory and job directory
  // TODO pass as cmd line params
  pid = getpid();
  std::string tmpDir ("/extra/scratch/dynamix");
  // job directory name
  char jobFmt [] = "%s%.12e_%.12e_%.12e_%d_%d";
  char jobDir [1000];
  sprintf(jobDir, jobFmt, tmpDir.c_str(), g1, g2, g1_c, rank, size);
  std::cout << jobDir << std::endl;
  std::string dynDir ("/home/andyras/git/dynamix/dm/");
  std::string dynInsDir (dynDir + "ins/");
  std::string dynamix (dynDir + "bin/dynamix");
  std::string changeParam (dynDir + "tools/changeParam.py");
  char sciFmt [] = "%.12e";
  char g1Str [100];
  char g2Str [100];
  char g1_cStr [100];
  sprintf(g1Str, sciFmt, g1);
  sprintf(g2Str, sciFmt, g2);
  sprintf(g1_cStr, sciFmt, g1_c);

  std::string jobInsDir (jobDir + std::string("/ins/"));
  std::string jobOutsDir (jobDir + std::string("/outs/"));

  // ---- set up job directory ---- //

  // -- create job directory -- //
  // making the output directory so that the top directory gets made too

  strncpy(args[0], "mkdir", 6);
  strncpy(args[1], "-p", 3);
  strncpy(args[2], jobOutsDir.c_str(), jobOutsDir.length()+1);
  args[3] = NULL;

  fprintf(stdout, "COMMAND:");
  for (int ii = 0; ii < 4; ii++) {
    fprintf(stdout, " %s", args[ii]);
  }
  fprintf(stdout, "\n");

  if ((pid = fork()) < 0) { // fork fails
    fprintf(stdout, "Fork bork\n");
    _exit(EXIT_FAILURE);
  }
  else if (pid == 0) { // child process
    // make directory
    execv("/bin/mkdir", args);
    // just in case
    _exit(EXIT_FAILURE);
  }
  else { // parent process
    waitpid(pid, &status, 0);
  }

  // -- copy inputs to job dir -- //
  std::string dynInsDirNoSlash = dynInsDir;

  while (dynInsDirNoSlash.at(dynInsDirNoSlash.size()-1) == '/') {
    std::cerr << "About to erase slash from " << dynInsDirNoSlash << std::endl;
    dynInsDirNoSlash.erase(dynInsDirNoSlash.end()-1);
    std::cerr << "Erased slash from " << dynInsDirNoSlash << std::endl;
  }

  // construct arguments
  for (int ii = 0; ii < 10; ii++) {
    delete [] args[ii];
    args[ii] = new char [1000];
  }
  strncpy(args[0], "cp", strlen("cp") + 1);
  strncpy(args[1], "-r", strlen("-r") + 1);
  strncpy(args[2], dynInsDirNoSlash.c_str(), dynInsDirNoSlash.length() + 1);
  strncpy(args[3], jobDir, strlen(jobDir) + 1);
  args[4] = NULL;


  fprintf(stdout, "COMMAND:");
  for (int ii = 0; ii < 10; ii++) fprintf(stdout, " %s", args[ii]);
  fprintf(stdout, "\n");

  if ((pid = fork()) < 0) { // fork fails
    fprintf(stdout, "Fork bork\n");
    _exit(EXIT_FAILURE);
  }
  else if (pid == 0) { // child
    execv("/bin/cp", args);
    _exit(EXIT_FAILURE);
  }
  else { // parent
    waitpid(pid, &status, 0);
  }



  std::string jobDirParamFile (jobDir + std::string("/ins/parameters.in"));
  // construct arguments
  for (int ii = 0; ii < 10; ii++) {
    delete [] args[ii];
    args[ii] = new char [1000];
  }
  // change parameter
  strncpy(args[0], changeParam.c_str(), changeParam.length() + 1);
  strncpy(args[1], "-f", strlen("-f") + 1);
  strncpy(args[2], jobDirParamFile.c_str(), jobDirParamFile.length() + 1);
  strncpy(args[3], "gamma1", strlen(jobDir) + 1);
  strncpy(args[4], g1Str, strlen(g1Str) + 1);
  args[5] = NULL;

  fprintf(stdout, "COMMAND:");
  for (int ii = 0; ii < 10; ii++) fprintf(stdout, " %s", args[ii]);
  fprintf(stdout, "\n");

  if ((pid = fork()) < 0) { // fork fails
    fprintf(stdout, "Fork bork\n");
    _exit(EXIT_FAILURE);
  }
  else if (pid == 0) { // child
    execv("changeParam.py", args);
    _exit(EXIT_FAILURE);
  }
  else { // parent
    waitpid(pid, &status, 0);
  }



  // construct arguments
  for (int ii = 0; ii < 10; ii++) {
    delete [] args[ii];
    args[ii] = new char [1000];
  }
  // change parameter
  strncpy(args[0], changeParam.c_str(), changeParam.length() + 1);
  strncpy(args[1], "-f", strlen("-f") + 1);
  strncpy(args[2], jobDirParamFile.c_str(), jobDirParamFile.length() + 1);
  strncpy(args[3], "gamma2", strlen(jobDir) + 1);
  strncpy(args[4], g2Str, strlen(g2Str) + 1);
  args[5] = NULL;

  fprintf(stdout, "COMMAND:");
  for (int ii = 0; ii < 10; ii++) fprintf(stdout, " %s", args[ii]);
  fprintf(stdout, "\n");

  if ((pid = fork()) < 0) { // fork fails
    fprintf(stdout, "Fork bork\n");
    _exit(EXIT_FAILURE);
  }
  else if (pid == 0) { // child
    execv("changeParam.py", args);
    _exit(EXIT_FAILURE);
  }
  else { // parent
    waitpid(pid, &status, 0);
  }



  // construct arguments
  for (int ii = 0; ii < 10; ii++) {
    delete [] args[ii];
    args[ii] = new char [1000];
  }
  // change parameter
  strncpy(args[0], changeParam.c_str(), changeParam.length() + 1);
  strncpy(args[1], "-f", strlen("-f") + 1);
  strncpy(args[2], jobDirParamFile.c_str(), jobDirParamFile.length() + 1);
  strncpy(args[3], "gamma1_c", strlen(jobDir) + 1);
  strncpy(args[4], g1_cStr, strlen(g1_cStr) + 1);
  args[5] = NULL;

  fprintf(stdout, "COMMAND:");
  for (int ii = 0; ii < 10; ii++) fprintf(stdout, " %s", args[ii]);
  fprintf(stdout, "\n");

  if ((pid = fork()) < 0) { // fork fails
    fprintf(stdout, "Fork bork\n");
    _exit(EXIT_FAILURE);
  }
  else if (pid == 0) { // child
    execv("changeParam.py", args);
    _exit(EXIT_FAILURE);
  }
  else { // parent
    waitpid(pid, &status, 0);
  }



  // ---- run code ---- //
  //

  // construct arguments
  for (int ii = 0; ii < 10; ii++) {
    delete [] args[ii];
    args[ii] = new char [1000];
  }
  strncpy(args[0], dynamix.c_str(), dynamix.length() + 1);
  strncpy(args[1], "-i", strlen("-i") + 1);
  strncpy(args[2], jobInsDir.c_str(), jobInsDir.length() + 1);
  strncpy(args[3], "-o", strlen("-o") + 1);
  strncpy(args[4], jobOutsDir.c_str(), jobOutsDir.length() + 1);
  args[5] = NULL;

  fprintf(stdout, "COMMAND:");
  for (int ii = 0; ii < 10; ii++) fprintf(stdout, " %s", args[ii]);
  fprintf(stdout, "\n");

  int flag;
  flag = dynamixMain(5, args);

  /*
  if ((pid = fork()) < 0) { // fork fails
    fprintf(stdout, "Fork bork\n");
    _exit(EXIT_FAILURE);
  }
  else if (pid == 0) { // child
    execv("dynamix", args);
    _exit(EXIT_FAILURE);
  }
  else { // parent
    waitpid(pid, &status, 0);
  }
  */

  // ---- check for success ---- //
  //
  // ---- read in outputs ---- //
  //
  // ---- calculate objective ---- //
  //
  // ---- remove job directory ---- //

  // clean up
  for (int ii = 0; ii < 10; ii++) {
    delete [] args[ii];
  }

  return output;
}