ProgramEvolutionTask
Models & Types · AiDotNet.Evolution.Programs
Binds program genomes, a fitness evaluator, and program descriptors into one evolution task.
Implements: IEvolutionTask<ProgramGenome>
For Beginners
This is the adapter that lets the generic evolution engine evolve source code. You give it your scoring rule and, optionally, the pigeonhole axes you want the archive to use; it handles recognizing duplicate programs, refusing candidates that broke the rules, and combining your score with the descriptor coordinates. Everything about running the code stays in your evaluator, so nothing here executes generated program text.
How It Works
The task supplies the three things EvolutionEngine<ProgramGenome> cannot know by itself: what a
valid candidate looks like, which candidates count as the same, and how good one is.
CanonicalizeAsync uses Id, the SHA-256 of the normalized source, so a
child that differs from its parent only in line endings or trailing white space is recognized as a duplicate
before any evaluation is paid for. EvaluateAsync enforces the configured program bounds, delegates
scoring to the IProgramFitnessEvaluator, and then merges the descriptor set’s coordinates into the
result.
Descriptor merging follows the reference implementation’s precedence: a coordinate the evaluator computed
itself always wins over a built-in descriptor of the same name, so an evaluator that measures real runtime can
override the static token-count proxy without any reconfiguration. A candidate longer than
MaxProgramChars, or one whose evolve-block markers are damaged while
EnforceEvolveBlocks is set, is returned as
Rejected without being executed at all.
Constructors
| Constructor | Summary |
|---|---|
ProgramEvolutionTask(IProgramFitnessEvaluator evaluator, ProgramDescriptorSet descriptors, ProgramEvolutionOptions options, string id) |
Initializes a program-evolution task. |
Properties
| Property | Summary |
|---|---|
ProgramDescriptorSet Descriptors { get; } |
Gets the descriptors merged into every completed evaluation. |
string EvaluatorVersionHash { get; } |
|
string Id { get; } |
|
string VersionHash { get; } |
Methods
| Method | Summary |
|---|---|
ProgramEvolutionOptions GetOptions() |
Gets a copy of the program bounds and evolve-block settings this task enforces. |
ValueTask<EvolutionCanonicalGenome<ProgramGenome>> CanonicalizeAsync(ProgramGenome genome, CancellationToken cancellationToken) |
|
ValueTask<EvolutionTaskResult> EvaluateAsync(EvolutionCandidate<ProgramGenome> candidate, EvolutionEvaluationContext context, CancellationToken cancellationToken) |