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

[Update] Change some review

More detail on https://gitlab.inria.fr/aevol/sswm_prototype/-/merge_requests
parent 1eed4ceb
......@@ -23,7 +23,7 @@
MutationFactorySswm::MutationFactorySswm(std::shared_ptr<aevol::JumpingMT> prng,
MutationParametersSswm mut_parameters) {
prng_nb = std::move(prng); // permet d'eviter d'incrimenter 2 fois
prng_nb = prng; // permet d'eviter d'incrimenter 2 fois
mp_sswm = mut_parameters;
}
......@@ -36,8 +36,7 @@ bool MutationFactorySswm::is_inversion() {
return nb == 0; // par defition on 0 = inversion
}
aevol::MutationEvent MutationFactorySswm::do_mutation(aevol::Individual_7& indiv) {
int dna_lenght = indiv.dna_->length();
aevol::MutationEvent MutationFactorySswm::do_mutation(int dna_lenght) {
bool is_inversion_bool = is_inversion();
// _____ If inversion
if (is_inversion_bool) {
......
......@@ -19,15 +19,14 @@ struct MutationParametersSswm {
class MutationFactorySswm {
bool is_inversion();
public:
MutationFactorySswm(std::shared_ptr<aevol::JumpingMT> prng,
MutationParametersSswm mut_parameters);
aevol::MutationEvent do_mutation(aevol::Individual_7& indiv);
MutationParametersSswm mp_sswm{};
std::shared_ptr<aevol::JumpingMT> prng_nb;
public:
MutationFactorySswm(std::shared_ptr<aevol::JumpingMT> prng,
MutationParametersSswm mut_parameters);
aevol::MutationEvent do_mutation(int dna_lenght);
};
......
......@@ -88,11 +88,13 @@ class MutationEvent {
char base() const { return base_; }
#endif
int32_t type_;
private:
int32_t type_;
int32_t pos_1_,pos_2_,pos_3_,pos_4_;
int32_t number_; // insertion or deletion
......
......@@ -153,7 +153,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();
long good_mut = 0;
long neutral_mut = 0;
......@@ -172,15 +172,20 @@ int main(int argc, char* argv[]) {
if_eq +
underscore +
extension;
remove(result_evol_file.c_str());
std::ofstream output_evol_file(result_evol_file);
output_evol_file << " nb_gen,non_mutant,mutant,mutation" << std::endl;
if (output_evol_file) {
for (int i = 0; i < nb_gen; i++) {
MutationFactorySswm mutationFactorySswm =
MutationFactorySswm(prng_shared_ptr, mp);
auto mutationEvent = mutationFactorySswm.do_mutation(*individual);
MutationFactorySswm mutationFactorySswm(prng_shared_ptr, mp);
if (not output_evol_file.is_open()) {
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,
......@@ -191,7 +196,7 @@ int main(int argc, char* argv[]) {
delete individual;
individual = new_indiv;
output_evol_file << i << "," << individual->fitness << ","
<< new_indiv->fitness << "," << mutationEvent.type_
<< new_indiv->fitness << "," << mutationEvent.type()
<< std::endl;
good_mut++;
}
......@@ -207,6 +212,11 @@ int main(int argc, char* argv[]) {
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;
......@@ -219,9 +229,7 @@ int main(int argc, char* argv[]) {
output_file << std::setw(2) << inputs << std::endl;
}
}
else {
printf("ERROR ! File can not be open !");
}
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