working through compile bugs

This commit is contained in:
2025-08-21 00:41:51 -05:00
parent 3265f045d1
commit 3a901a0a40
3 changed files with 215 additions and 167 deletions

View File

@@ -2,8 +2,7 @@
namespace genetic {
template <class T> struct ReadonlySpan;
template <class T> struct Span;
template <class T> struct Array;
template <class T> struct Stats;
template <class T> struct Strategy;
@@ -16,7 +15,8 @@ template <class T> struct Strategy {
// before accessing/locking the work queue again.
int num_cells; // Size of the population pool
int num_generations; // Number of times (epochs) to run the algorithm
bool test_all; // Sets whether or not every cell is tested every generation
bool test_all; // Sets whether or not every cell's fitness is evaluated every
// generation
float test_chance; // Chance to test any given cell's fitness. Relevant only
// if test_all is false.
bool enable_crossover; // Cells that score well in the evaluation stage
@@ -25,11 +25,17 @@ template <class T> struct Strategy {
float crossover_mutation_chance; // Chance to mutate a child cell
int crossover_parent_num; // Number of unique high-scoring parents in a
// crossover call.
int crossover_children_num; // Number of children to expect the user to
// produce in the crossover function.
bool enable_mutation; // Cells may be mutated
// before fitness evaluation
float mutation_chance; // Chance to mutate cells before fitness evaluation
int crossover_parent_stride; // Number of parents to skip over when moving to
// the next set of parents. A stride of 1 would
// produce maximum overlap because the set of
// parents would only change by one every
// crossover.
int crossover_children_num; // Number of children to expect the user to
// produce in the crossover function.
bool enable_mutation; // Cells may be mutated
// before fitness evaluation
float mutation_chance; // Chance for any given cell to be mutated cells during
// the mutation
uint64_t rand_seed;
bool higher_fitness_is_better; // Sets whether or not to consider higher
// fitness values better or worse. Set this to
@@ -38,16 +44,16 @@ template <class T> struct Strategy {
// User defined functions
T (*make_default_cell)();
void (*mutate)(T &cell_to_modify);
void (*crossover)(const Span<T *> parents, const Span<T *> out_children);
void (*crossover)(const Array<T *> parents, const Array<T *> out_children);
float (*fitness)(const T &cell);
};
template <class T> struct Stats {
std::vector<T> best_cell;
std::vector<float> average_fitness;
std::vector<float> best_cell_fitness;
};
template <class T> struct Span {
template <class T> struct Array {
T *_data;
int len;