12 #ifndef GENETIC_ALGORITHM_H_
13 #define GENETIC_ALGORITHM_H_
27 #define GENE_POOL "!@#$^&*()_-=+,.;:'/\\\"{}[]<>? 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
136 void mutate_genome(
char *genome, uint16_t length, uint16_t max_mutation, uint16_t min_mutation);
int genome_calculate_fitness(const char *target, const char *genome, uint16_t length)
Calculates fitness of the genome based on how close it is to the target.
Definition: genetic_algorithm_utils.c:154
char get_mutated_gene(void)
Function for extracting a mutated / random gene from the available gene pool specified in the GENE_PO...
Definition: genetic_algorithm_utils.c:140
struct genome_t genome_t
The genome structure. It contains genes, the length of those genes and a fitness score....
genome_t genome_target_init(char *string)
Initialization of the target genome is slightly different as it already has allocated memory and does...
Definition: genetic_algorithm_utils.c:22
void genome_print(const genome_t genome)
Function for printing genomes in a readable format.
Definition: genetic_algorithm_utils.c:93
genome_t genome_init(uint16_t length)
Creates a new genome object with allocated memory of the given size. The genome must be manually free...
Definition: genetic_algorithm_utils.c:41
void genome_copy(genome_t *destination, const genome_t *source)
Performs a deep copy of source to destination while maintaining their original references.
Definition: genetic_algorithm_utils.c:80
void genomes_mate(const genome_t *p_target, const genome_t *p_parent_1, const genome_t *p_parent_2, genome_t *p_offspring)
Mating combines the genomes of two parents over a random crossover point, while the sequence of paren...
Definition: genetic_algorithm_utils.c:222
void genomes_sort_by_fitness(genome_t genomes[], uint16_t genome_count)
Sorts the given genome array by ascending fitness.
Definition: genetic_algorithm_utils.c:176
void mutate_genome(char *genome, uint16_t length, uint16_t max_mutation, uint16_t min_mutation)
Provides a mutated genome based on the maximum and minimum possible mutations.
Definition: genetic_algorithm_utils.c:201
void genome_destroy(genome_t *p_genome)
Frees the gene memory allocated to the genome and resets its fitness and length.
Definition: genetic_algorithm_utils.c:65
char gene_t
A singular gene is just a character.
Definition: genetic_algorithm_utils.h:32
int random_in_pos_range(const int upper_limit, const int lower_limit)
Provides a pseudo random number between a positive range.
Definition: genetic_algorithm_utils.c:111
The genome structure. It contains genes, the length of those genes and a fitness score....
Definition: genetic_algorithm_utils.h:39
int fitness
Fitness of the genes.
Definition: genetic_algorithm_utils.h:42
gene_t * genes
Pointer to an array of genes.
Definition: genetic_algorithm_utils.h:40
uint16_t length
length of the genes.
Definition: genetic_algorithm_utils.h:41