From cc69389d79e4bed927e9aa29b8769c2ad4f90d8c Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 25 Oct 2025 11:09:32 -0500 Subject: create simple genetic algorithm in c --- genalg.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 genalg.h (limited to 'genalg.h') diff --git a/genalg.h b/genalg.h new file mode 100644 index 0000000..33066bb --- /dev/null +++ b/genalg.h @@ -0,0 +1,34 @@ +#ifndef GENALG_H +#define GENALG_H + + +typedef struct genalg_t { + void ** population; + size_t pop_count; + + double (*fitness)(void*); + void * (*create_child)(void*); + void (*org_free)(void*); +} genalg_t; + + +struct genalg_stats_t { + double mean, variance; + double min, max; + void * best; +}; + + +genalg_t * ga_create( + size_t pop_count, + double (*fitness)(void*), + void * (*create_child)(void*), + void (*org_free)(void*) +); +void ga_free(genalg_t *ga); +void * ga_tournament_select(genalg_t *ga, int tournament_sz); +struct genalg_stats_t ga_population_statistics(genalg_t *ga); +int ga_replace_population(genalg_t *ga, int tournament_sz, int keep); + + +#endif -- cgit v1.2.1