diff options
| author | sanine <sanine.not@pm.me> | 2025-10-25 11:09:32 -0500 | 
|---|---|---|
| committer | sanine <sanine.not@pm.me> | 2025-10-25 11:09:32 -0500 | 
| commit | cc69389d79e4bed927e9aa29b8769c2ad4f90d8c (patch) | |
| tree | 50034136ed2db13d3256b2b24f5271970f138433 /genalg.h | |
create simple genetic algorithm in c
Diffstat (limited to 'genalg.h')
| -rw-r--r-- | genalg.h | 34 | 
1 files changed, 34 insertions, 0 deletions
| 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 | 
