Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 4a4d39ac authored by David Parsons's avatar David Parsons
Browse files

pass chromosome to ParamLoader::load in a list of strings

Allows for chromosome to be optional (list is empty by default)
as well as multiple chromosomes (coming soon)
parent b6dfac80
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@ const char* DEFAULT_PARAM_FILE_NAME = "param.in";
#include <getopt.h>
#include <fstream>
#include <list>
#include <sstream>
#include <string>
......@@ -73,7 +74,7 @@ int main(int argc, char* argv[]) {
exp_manager = new ExpManager();
// Initialize the simulation from the parameter file
std::string chromosome;
std::list<std::string> chromosomes;
if (chromosome_file_name != nullptr) {
std::ifstream chromosome_file(chromosome_file_name);
......@@ -81,19 +82,21 @@ int main(int argc, char* argv[]) {
Utils::ExitWithUsrMsg(std::string("failed to open source chromosome file ") + chromosome_file_name);
}
std::string chromosome;
std::getline(chromosome_file, chromosome);
if (not chromosome_file or chromosome.length() == 0) {
Utils::ExitWithUsrMsg(std::string("failed to read from chromosome file ") + chromosome_file_name);
}
chromosomes.push_back(std::move(chromosome));
std::cout << "Loading chromosome from text file " << chromosome_file_name << " (" << chromosome.length()
std::cout << "Loading chromosome from text file " << chromosome_file_name << " (" << chromosomes.front().length()
<< " base pairs)" << std::endl;
delete [] chromosome_file_name;
}
if(param_file_name != nullptr) {
if (chromosome.length() != 0) {
ParamLoader::load(param_values, exp_manager, true, chromosome.c_str(), chromosome.length());
if (chromosomes.size() != 0) {
ParamLoader::load(param_values, exp_manager, chromosomes, true);
} else {
ParamLoader::load(param_values, exp_manager, true);
}
......
......@@ -45,9 +45,14 @@ namespace aevol {
void ParamLoader::load(const ParamValues& param_values,
ExpManager* exp_m,
bool verbose,
const char* chromosome,
int32_t lchromosome) {
bool verbose) {
load(param_values, exp_m, std::list<std::string>(), verbose);
}
void ParamLoader::load(const ParamValues& param_values,
ExpManager* exp_m,
const std::list<std::string>& chromosomes,
bool verbose) {
// Initialize master prng
// Will be used to create the initial genome(s) and to generate seeds for the other prngs
auto prng = std::make_shared<JumpingMT>(param_values.seed_);
......@@ -247,8 +252,7 @@ void ParamLoader::load(const ParamValues& param_values,
Individual * indiv = NULL;
int32_t id_new_indiv = 0;
if (chromosome != NULL)
{
if (not chromosomes.empty()) {
printf("Option -c is used: chromosome will be loaded from a text file\n");
#ifndef __REGUL
Individual * indiv = new Individual(exp_m,
......@@ -276,9 +280,11 @@ void ParamLoader::load(const ParamValues& param_values,
#endif
// Make a copy of the provided chromosome and transfer ownership to the genetic unit we create with it
char* chromosome_copy = new char[lchromosome + 1];
strncpy(chromosome_copy, chromosome, lchromosome + 1);
indiv->add_GU(chromosome_copy, lchromosome);
assert(chromosomes.size() == 1);
auto& chromosome = chromosomes.front();
char* chromosome_copy = new char[chromosome.length() + 1];
strncpy(chromosome_copy, chromosome.c_str(), chromosome.length() + 1);
indiv->add_GU(chromosome_copy, chromosome.length());
chromosome_copy = nullptr;
indiv->genetic_unit_nonconst(0).set_min_gu_length(param_values.chromosome_minimal_length_);
......
......@@ -31,6 +31,8 @@
// Includes
// =================================================================
#include <cinttypes>
#include <list>
#include <string>
#include "legacy/ExpManager.h"
#include "ParamValues.h"
......@@ -58,9 +60,11 @@ class ParamLoader {
// =========================================================================
static void load(const ParamValues& param_values,
ExpManager* exp_m,
bool verbose = false,
const char* chromosome = nullptr,
int32_t lchromosome = 0);
bool verbose = false);
static void load(const ParamValues& param_values,
ExpManager* exp_m,
const std::list<std::string>& chromosomes,
bool verbose = false);
protected:
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment