<commit_before>#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "defines.h"
#include "enums.h"
#include "ea_mono.h"
#include "protein.h"
#include "topology.h"
#include "pdbio.h"
#include "pdbatom.h"
#include "messages.h"
#include "algorithms.h"
#include "string_owner.h"
#include "futil.h"
#include "random_number_gsl.h"
#include "aminoacids.h"
#include "aminoacids_io.h"
#include "populationio.h"
#include "topology.h"
#include "topologyio.h"
#include "rotation.h"
#include "math_owner.h"
#include "solution.h"
#include "gromacs_objectives.h"
#include "algorithms.h"
#include "randomlib.h"

 /** Implementation of tournament for chosing individual to reproduce 
 * solutions represents the population of solutions
 * in_para represents the parameters
 * output is the reference of solution has earned the tournament
 */
static int tournament(const solution_t *solutions, const int *popsize){
    int ind_1, ind_2;
    int max_random;
    max_random = *popsize -1;
    ind_1 = _get_int_random_number(&max_random);
    ind_2 = _get_int_random_number(&max_random);
    if (solutions[ind_1].obj_values[0] < solutions[ind_2].obj_values[0]){
        return ind_1;
    }else{
        return ind_2;
    }
}

/** Selects the individuals which will be reproduced 
* index_solutions_to_reproduce index of individuals were selected to reproduce
* num_ind_reproduce number the individuals for reprodution
* solutions population of solutions
* popsize size of population
*/
static void select_individual_mono(int *index_solutions_to_reproduce, 
        const int *num_ind_reproduce, const solution_t *solutions, const int *popsize){    
    for (int i = 0; i < *num_ind_reproduce;i++){
       index_solutions_to_reproduce[i] = tournament(solutions,popsize);
    }

}

/** Applies the crossover parents.
* p_new is based on one of its parents
* When choose = 0 is considered father 1. Otherwise, father 2
*/
void crossover_parents(protein_t *p_new, const protein_t *p1,
        const protein_t *p2){
    int choose;
    int aux = 2;
    choose = _get_int_random_number(&aux);
    if (choose == 0){        
        copy_protein_atoms(p_new,p1);
    }else{
        copy_protein_atoms(p_new,p2);
    }
}

/** Applies the crossover operator
* ind_new is an individual of new population
* prot_1 is first indiviual
* prot_2 is second indiviual
*/
void apply_crossover(protein_t *ind_new, const protein_t *prot_1, 
    const protein_t * prot_2){

    crossover_parents(ind_new, prot_1, prot_2);
}

/** Applies the mutation operator
* ind_new is an individual of new population
* in_para is the input parameter
*/
void apply_mutation(protein_t *ind_new, const input_parameters_t *in_para){
    float angle_radians, angle_degree, rate;
    int num_residue_choose;
    int what_rotation;
    int max_kind_of_rotation = 4;  

    rate = _get_float();
    num_residue_choose = 0;
    if (rate < in_para->individual_mutation_rate){
        //Choose a residue. It must be started 1 untill number of residue
        while (num_residue_choose == 0){
            num_residue_choose = _get_int_random_number(&ind_new->p_topol->numres);
        }
        //Obtaing kind of rotation
        what_rotation = _get_int_random_number(&max_kind_of_rotation);        
        //Appling the rotation 
        if (what_rotation == 0){<commit_msg>Added 1-point crossover<commit_after>#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "defines.h"
#include "enums.h"
#include "ea_mono.h"
#include "protein.h"
#include "topology.h"
#include "pdbio.h"
#include "pdbatom.h"
#include "messages.h"
#include "algorithms.h"
#include "string_owner.h"
#include "futil.h"
#include "random_number_gsl.h"
#include "aminoacids.h"
#include "aminoacids_io.h"
#include "populationio.h"
#include "topology.h"
#include "topologyio.h"
#include "rotation.h"
#include "math_owner.h"
#include "solution.h"
#include "gromacs_objectives.h"
#include "algorithms.h"
#include "randomlib.h"


/** Implementation of 1 point crossover
* p_new represents the new solution
* p1 means the solution 1 that will build s_new
* p2 means the solution 2 that will build s_new
*/
static void crossover_1_part(protein_t *p_new, const protein_t *p1, 
    const protein_t *p2){
    int res_aux, res_ini;
    res_aux = 0;
    res_ini = 1;
    //getting a random residue
    while (res_aux == 0){
        res_aux = _get_int_random_number(&p1->p_topol->numres);
    }
    //coping from solution s1
    copy_protein_atoms_by_residues(p_new, &res_ini, &res_aux, p1);
    //coping from solution s2
    res_ini = res_aux + 1;
    if (res_ini <= p2->p_topol->numres){
        res_aux = p2->p_topol->numres;
        copy_protein_atoms_by_residues(p_new, &res_ini, &res_aux, p2);
    }
    build_topology_individual(p_new);
}

 /** Implementation of tournament for chosing individual to reproduce 
 * solutions represents the population of solutions
 * in_para represents the parameters
 * output is the reference of solution has earned the tournament
 */
static int tournament(const solution_t *solutions, const int *popsize){
    int ind_1, ind_2;
    int max_random;
    max_random = *popsize -1;
    ind_1 = _get_int_random_number(&max_random);
    ind_2 = _get_int_random_number(&max_random);
    if (solutions[ind_1].obj_values[0] < solutions[ind_2].obj_values[0]){
        return ind_1;
    }else{
        return ind_2;
    }
}

/** Selects the individuals which will be reproduced 
* index_solutions_to_reproduce index of individuals were selected to reproduce
* num_ind_reproduce number the individuals for reprodution
* solutions population of solutions
* popsize size of population
*/
static void select_individual_mono(int *index_solutions_to_reproduce, 
        const int *num_ind_reproduce, const solution_t *solutions, const int *popsize){    
    for (int i = 0; i < *num_ind_reproduce;i++){
       index_solutions_to_reproduce[i] = tournament(solutions,popsize);
    }

}

/** Applies the crossover parents.
* p_new is based on one of its parents
* When choose = 0 is considered father 1. Otherwise, father 2
*/
void crossover_parents(protein_t *p_new, const protein_t *p1,
        const protein_t *p2){
    int choose;
    int aux = 2;
    choose = _get_int_random_number(&aux);
    if (choose == 0){        
        copy_protein_atoms(p_new,p1);
    }else{
        copy_protein_atoms(p_new,p2);
    }
}

/** Applies the crossover operator
* ind_new is an individual of new population
* prot_1 is first indiviual
* prot_2 is second indiviual
*/
void apply_crossover(protein_t *ind_new, const protein_t *prot_1, 
    const protein_t * prot_2){
    int choose;
    int aux = 2;
    choose = _get_int_random_number(&aux);
    if (choose == 0){
        crossover_parents(ind_new, prot_1, prot_2);
    }else{
        crossover_1_part(ind_new, prot_1, prot_2);
    }
}

/** Applies the mutation operator
* ind_new is an individual of new population
* in_para is the input parameter
*/
void apply_mutation(protein_t *ind_new, const input_parameters_t *in_para){
    float angle_radians, angle_degree, rate;
    int num_residue_choose;
    int what_rotation;
    int max_kind_of_rotation = 4;  

    rate = _get_float();
    num_residue_choose = 0;
    if (rate < in_para->individual_mutation_rate){
        //Choose a residue. It must be started 1 untill number of residue
        while (num_residue_choose == 0){
            num_residue_choose = _get_int_random_number(&ind_new->p_topol->numres);
        }
        //Obtaing kind of rotation
        what_rotation = _get_int_random_number(&max_kind_of_rotation);        
        //Appling the rotation 
        if (what_rotation == 0){
{'fraction_non_alphanumeric': 0.09896583322424402, 'fraction_numerical': 0.011650739625605446, 'mean_word_length': 3.8201892744479493, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '710025', 'n_tokens_mistral': 2723, 'n_tokens_neox': 2578, 'n_words': 698}