Commit 4e19e5b6 authored by SINDT--BARET Yanis's avatar SINDT--BARET Yanis
Browse files

[New] Add functional loop for number of generation.

Creation of the loop depending on the number of generation. At each generation, individual with the best fitness is chosen. Add of a new parameter for the user (number of generation). Feature already functional.
parent b51aba38
......@@ -99,16 +99,20 @@ void from_json(const json& j, Parameters& p) {
int main(int argc, char* argv[]) {
if (argc != 3) {
printf("!!!\nPlease don't forget to write the json file and the inversion rate\n!!!\n");
if (argc != 4) {
printf("!!!\nPlease don't forget to write the json file then the inversion rate and the number of generation\n!!!\n");
exit(EXIT_FAILURE);
}
else if (std::stof(argv[2]) > 1 or std::stof(argv[2]) < 0) {
printf("!!!\nPlease select a inversion rate between 0 and 1\n!!!\n");
exit(EXIT_FAILURE); } // Todo : verif que ça soit bien convertissable
else if (std::stol(argv[3]) <= 0) {
printf("!!!\nPlease select positive number of generation\n!!!\n");
exit(EXIT_FAILURE); }
char* input_file_name = argv[1];
std::ifstream input_file(input_file_name);
float inversion_rate = std::stof(argv[2]);
float const inversion_rate = std::stof(argv[2]);
long const nb_gen = std::stol(argv[3]);
json inputs;
input_file >> inputs;
......@@ -123,64 +127,62 @@ int main(int argc, char* argv[]) {
Dna_7::polya_length = inputs.at("polya_length").get<int8_t>();
#endif
// Env : Liste de gaussienne : [hauteur, position (moyenne), ecartype]
// Env : Liste de gaussienne : [hauteur, position (moyenne), ecartype]
const auto& env = inputs.at("env");
assert(env.is_array());
const auto& env = inputs.at("env");
assert(env.is_array());
std::vector<Gaussian> gaussians;
for (const auto& g: env) {
assert(g.is_array() && g.size() == 3);
gaussians.emplace_back(g[0].get<double>(),
g[1].get<double>(),
g[2].get<double>());
std::vector<Gaussian> gaussians;
for (const auto& g: env) {
assert(g.is_array() && g.size() == 3);
gaussians.emplace_back(g[0].get<double>(),
g[1].get<double>(),
g[2].get<double>());
}
FuzzyFactory_7 fuzzyFactory(VECTOR, p.sampling);
auto* target = define_target(gaussians, p.sampling, fuzzyFactory);
JumpingMT prng(p.seed); // générateur de nombre aléatoire à partir d'une seed.
const auto& seq = inputs.at("individual").get<std::string>();
int src_seq_length = seq.length();
const auto* src_seq = seq.data();
Individual_7* individual = nullptr;
individual = new Individual_7(0.0);
individual->dna_ = new Dna_7(src_seq_length);
individual->dna_->set_indiv(src_seq, src_seq_length, individual);
individual->evaluation_from_scratch(target, p.w_max, p.selection_pressure,
&fuzzyFactory);
Individual_7* new_indiv = nullptr;
auto* fuzzyFac = &fuzzyFactory;
auto prng_shared_ptr = std::make_shared<aevol::JumpingMT>(prng); // ici on crééer un shared pointeur (le truc a droite permet de faire un shared pointeur)
long good_mut = 0;
for (int i = 0; i<nb_gen;i++) {
MutationFactorySswm mutationFactorySswm = MutationFactorySswm(prng_shared_ptr, mp);
auto mutationEvent = mutationFactorySswm.do_mutation(*individual);
new_indiv = new aevol::Individual_7(individual);
new_indiv->dna_->apply_mutation(mutationEvent);
new_indiv->evaluate_after_mutation(target, p.w_max, p.selection_pressure, fuzzyFac);
print_step(i,individual, new_indiv);
if (individual->fitness <= new_indiv->fitness) {
delete individual;
individual = new_indiv;
good_mut ++;
}
FuzzyFactory_7 fuzzyFactory(VECTOR, p.sampling);
auto* target = define_target(gaussians, p.sampling, fuzzyFactory);
JumpingMT prng(p.seed); // générateur de nombre aléatoire à partir d'une seed.
const auto& seq = inputs.at("individual").get<std::string>();
int src_seq_length = seq.length();
const auto* src_seq = seq.data();
Individual_7* individual = nullptr;
individual = new Individual_7(0.0);
individual->dna_ = new Dna_7(src_seq_length);
individual->dna_->set_indiv(src_seq, src_seq_length, individual);
individual->evaluation_from_scratch(target, p.w_max, p.selection_pressure,
&fuzzyFactory);
auto* fuzzyFac = &fuzzyFactory;
auto prng_shared_ptr = std::make_shared<aevol::JumpingMT>(prng); // ici on crééer un shared pointeur (le truc a droite permet de faire un shared pointeur)
int const nb_gen = 1;
aevol::Individual_7 indiv_table[nb_gen][2];
std::vector<std::vector< aevol::Individual_7> > indiv_list;
for (int i = 0; i<1;i++) {
MutationFactorySswm mutationFactorySswm = MutationFactorySswm(prng_shared_ptr, mp);
auto mutationEvent = mutationFactorySswm.do_mutation(*individual);
auto newIndiv = new aevol::Individual_7(individual);
newIndiv->dna_->apply_mutation(mutationEvent);
newIndiv->evaluate_after_mutation(target, p.w_max, p.selection_pressure, fuzzyFac);
indiv_list[0].push_back(*individual);
indiv_list[0].push_back(*newIndiv);
else {
new_indiv = nullptr;
}
if (i%5000==0) {
printf("--- Generation %d done ---\n",i);
}
}
print_step(0,individual, newIndiv);
// TODO: Obtenir l'individu d'apres
// On veut faire une mutation
// A faire cette aprem : print les mutations voir comment ça marche avec les paramèetre que je viens de mettre.
// Mais aussi commencer a bien voir si on peu faire do mutation et apply mutation a partir du module_run
delete individual;
delete newIndiv;
printf("There are %ld positive(s) mutation(s) and %ld negative(s) mutation(s)",good_mut,nb_gen - good_mut);
return 0;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment