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

[Update] Delete "backup"

Genome saved outside the for loop.
parent 0c670358
......@@ -4,10 +4,8 @@
#include "Individual_7.h"
#include "json.hpp"
#include "JumpingMT.h"
#include "ExpManager_7.h"
#include "MutationSswm.h"
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
......@@ -16,21 +14,6 @@
using namespace aevol;
using json = nlohmann::json;
// _________
// Todo: Objectif
// 1. Creer 1 individu initial & stocker ses datas ------------ DONE
// 2. Mutation de cet individu --> comparaison des deux fitness
// if f(A) > f(B) :
// On garde f(A)
// sinon :
// On prends f(B) ------------------ DONE
// 3. Jusqu'a X génération
// 4. Traitement des données etc à voir plus tard
// Sépare les deux bases
#ifdef BASE_4
#define NB_BASE 4
constexpr double ERROR_MARGIN = 1E4;
......@@ -91,9 +74,11 @@ void from_json(const json& j, Parameters& p) {
j.at("selection_pressure").get_to(p.selection_pressure);
}
int main(int argc, char* argv[]) {
int main(int argc, char* argv[]) { // USAGE: program GENE_JSON_FILE MUTATION_RATE NB_GENERATION NEUTRAL_MUTATION_BOOL
if (argc != 5) {
printf("!!!\nPlease don't forget to write the json file then the inversion rate and the number of generation\n!!!\n");
printf("!!!\nPlease don't forget to write the json file then the"
" inversion rate, the number of generation"
" and to chose if neutral mutation are selected\n!!!\n");
exit(EXIT_FAILURE);
}
else if (std::stof(argv[2]) > 1 or std::stof(argv[2]) < 0) {
......@@ -104,16 +89,16 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE); }
char* input_file_name = argv[1];
std::ifstream input_file(input_file_name);
float const inversion_rate = std::stof(argv[2]);
long const nb_gen = std::stol(argv[3]);
std::string const if_eq = argv[4];
const float inversion_rate = std::stof(argv[2]);
const long nb_gen = std::stol(argv[3]);
const std::string if_eq = argv[4];
json inputs;
input_file >> inputs;
input_file.close();
auto p = inputs.get<Parameters>();
MutationParametersSswm mp;
MutationParametersSswm mp{};
mp.inversion_rate_ = inversion_rate;
// auto mp =
// inputs.at("mutation_parameters").get<MutationParametersSswm>();
......@@ -153,7 +138,7 @@ int main(int argc, char* argv[]) {
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 dna_length = individual->dna_->length();
const int dna_length = individual->dna_->length();
long good_mut = 0;
long neutral_mut = 0;
......@@ -183,52 +168,49 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "Error, cannot open file %s\n", result_evol_file.c_str()); // utilisation de `fprintf` parmet d'écrire spécifiquement dans le stderr. C'est explicitement une erreur
exit(EXIT_FAILURE);
}
else {
for (int i = 0; i <= nb_gen; i++) {
auto mutationEvent = mutationFactorySswm.do_mutation(dna_length);
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); Si on veut print les infos
if (individual->fitness < new_indiv->fitness) {
delete individual;
individual = new_indiv;
output_evol_file << i << "," << individual->fitness << ","
<< new_indiv->fitness << "," << mutationEvent.type()
<< std::endl;
good_mut++;
}
else if (individual->fitness == new_indiv->fitness and if_eq == "y") {
delete individual;
individual = new_indiv;
neutral_mut++;
}
else {
delete new_indiv;
new_indiv = nullptr;
}
if (i % 5000 == 0) {
printf("--- Generation %d done ---\n", i);
}
else if (i == nb_gen-1) {
output_evol_file << nb_gen << "," << individual->fitness << ","
<< individual->fitness << "," << mutationEvent.type()
<< std::endl;
}
std::string result(individual->dna_->data());
inputs["individual"] = result;
std::string base_result_file = "sswm_result_";
std::string result_file = base_result_file + nbgen_result_file +
underscore + prob_result_file + underscore + if_eq + underscore +
who_result_file;
std::ofstream output_file(result_file);
output_file << std::setw(2) << inputs << std::endl;
for (int i = 0; i <= nb_gen; i++) {
auto mutationEvent = mutationFactorySswm.do_mutation(dna_length);
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); Si on veut print les infos
if (individual->fitness < new_indiv->fitness) {
delete individual;
individual = new_indiv;
output_evol_file << i << "," << individual->fitness << ","
<< new_indiv->fitness << "," << mutationEvent.type()
<< std::endl;
good_mut++;
}
else if (individual->fitness == new_indiv->fitness and if_eq == "y") {
delete individual;
individual = new_indiv;
neutral_mut++;
}
else {
delete new_indiv;
new_indiv = nullptr;
}
if (i % 5000 == 0) {
printf("--- Generation %d done ---\n", i);
}
else if (i == nb_gen-1) {
output_evol_file << nb_gen << "," << individual->fitness << ","
<< individual->fitness << "," << mutationEvent.type()
<< std::endl;
}
}
std::string result(individual->dna_->data());
inputs["individual"] = result;
std::string base_result_file = "sswm_result_";
std::string result_file = base_result_file + nbgen_result_file +
underscore + prob_result_file + underscore + if_eq + underscore +
who_result_file;
std::ofstream output_file(result_file);
output_file << std::setw(2) << inputs << std::endl;
delete individual;
printf("There are %ld positive(s) mutations(s), %ld neutral(s) mutation(s) and %ld negative(s) mutation(s)",good_mut, neutral_mut,nb_gen - good_mut - neutral_mut);
......
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