Esempio n. 1
0
std::string filename_to_type(const std::string& filename)
{
  for (mapping* m = mappings; m->extension; ++m)
  {
    if (iends_with(filename, m->extension))
    {
      return m->mime_type;
    }
  }

  return "application/octet-stream";
}
  void ExperimentRun::setupExperimentInProgressUseDat(string _datFile, string populationFileName,string _outputFileName)
  {
    outputFileName = _outputFileName;
    //datFile = _datFile;
    PRINT(populationFileName);
    {
      TiXmlDocument doc(populationFileName);
			
      bool loadStatus;
			
      if (iends_with(populationFileName,".gz"))
        {
          loadStatus = doc.LoadFileGZ();
        }
      else
        {
          loadStatus = doc.LoadFile();
        }
			
      if (!loadStatus)
        {
          cerr << "Error trying to load the XML file!" << endl;
          throw CREATE_LOCATEDEXCEPTION_INFO("Error trying to load the XML file!");
        }
			
      TiXmlElement *element = doc.FirstChildElement();
			
      NEAT::Globals* globals = NEAT::Globals::init(element);
      (void) globals; //to get rid of unused variable warning
			
      NEAT::Globals::getSingleton()->overrideParametersFromFile(_datFile);
      NEAT::Globals::getSingleton()->setOutputFilePrefix(outputFileName); //set the name of the outputPrefixFile                                                                                                                                                                                               
			
      //Destroy the document
    }
		
    int experimentType = int(NEAT::Globals::getSingleton()->getParameterValue("ExperimentType")+0.001);
		
    cout << "Loading Experiment: " << experimentType << endl;
		
    setupExperiment(experimentType,_outputFileName);
		
    cout << "Experiment set up.  Creating population...\n";
		
    createPopulation(populationFileName);
		
    cout << "Population Created\n";
  }
    GeneticPopulation::GeneticPopulation(string fileName)
            : onGeneration(-1)
    {
        TiXmlDocument doc(fileName);

        bool loadStatus;

        if (iends_with(fileName,".gz"))
        {
            loadStatus = doc.LoadFileGZ();
        }
        else
        {
            loadStatus = doc.LoadFile();
        }

        if (!loadStatus)
        {
            throw CREATE_LOCATEDEXCEPTION_INFO("Error trying to load the XML file!");
        }

        TiXmlElement *root;

        root = doc.FirstChildElement();

        {
            TiXmlElement *generationElement = root->FirstChildElement("GeneticGeneration");

            while (generationElement)
            {
                generations.push_back(shared_ptr<GeneticGeneration>(new GeneticGeneration(generationElement)));

                generationElement = generationElement->NextSiblingElement("GeneticGeneration");
                onGeneration++;
            }
        }

        if (onGeneration<0)
        {
            throw CREATE_LOCATEDEXCEPTION_INFO("Tried to load a population with no generations!");
        }

        adjustFitness();
    }
Esempio n. 4
0
void Archive::readOverrides() {
  // Iterate over all files in the directory and override the table of contents
  // if there is a free SEENXXXX.TXT file.
  fs::path seen_dir = fs::path(name).branch_path();
  fs::directory_iterator end;
  for (fs::directory_iterator it(seen_dir); it != end; ++it) {
    string filename = it->leaf();
    if (filename.size() == 12 &&
        istarts_with(filename, "seen") &&
        iends_with(filename, ".txt") &&
        isdigit(filename[4]) &&
        isdigit(filename[5]) &&
        isdigit(filename[6]) &&
        isdigit(filename[7])) {
      Mapping* mapping = new Mapping((seen_dir / filename).string(), Read);
      maps_to_delete_.push_back(mapping);

      int index = lexical_cast<int>(filename.substr(4, 4));
      scenarios[index] = FilePos(mapping->get(), mapping->size());
    }
  }

}
    void ExperimentRun::setupExperimentInProgress(
        string populationFileName,
        string _outputFileName
    )
    {
        outputFileName = _outputFileName;

        {
            TiXmlDocument *doc = new TiXmlDocument(populationFileName);
            
            cout << "Loading population\n";

            bool loadStatus;

            if (iends_with(populationFileName,".gz"))
            {
                loadStatus = doc->LoadFileGZ();
            }
            else
            {
                loadStatus = doc->LoadFile();
            }

            if (!loadStatus)
            {
                throw CREATE_LOCATEDEXCEPTION_INFO("Error trying to load the XML file!");
            }

            TiXmlElement *element = doc->FirstChildElement();

            NEAT::Globals* globals = NEAT::Globals::init(element);
            
            //Destroy the document
            delete doc;
            
            cout << "Population loaded\n";


        }


        int experimentType = int(NEAT::Globals::getSingleton()->getParameterValue("ExperimentType")+0.001);

        NEAT::Globals::getSingleton()->seedRandom((unsigned int)(NEAT::Globals::getSingleton()->getParameterValue("ActualRandomSeed")+0.001));

        cout << "Loading Experiment: " << experimentType << endl;

        setupExperiment(experimentType,_outputFileName);

        cout << "Experiment set up.  Creating population...\n";

        createPopulation(populationFileName);

        cout << "Population Created\n";
        
        /*cout << "Cleaning up old generations\n";
        
		population->cleanupOld(population->getGenerationCount()-1);
		
		cout << "Done cleaning\n";*/
		
    }