feat: better defaults for GA builder #149
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Add better defaults for builder.
Right now this PR is stuck, due to problems with implementation.
Rust lacks few important language mechanisms:
It is an issue, because:
T: Chromosome
forBuilder
struct. It would be ridiculous to force user to implement customBuilder
.Chromosome
, thus defaults for different chromosome types must be different (there is really no common ground).Due to aforementioned language restrictions it seems impossible to implement defaults depending on incoming chromosome type.
Edit:
There is hope however: Rust's macros - as they are quite powerfull - you can operate directly on AST -- so it seems doable, but some research has to be done first.
Edit 2:
Defaults rarely make any sense as operators are problem specific. There are really no operators that fit the needs of all problems (or are at least valid).
It seems to me, that we must force end-user to specify operators alongside fitness function.
Can we se macros somehow to manage this?
Selected solution
So far we focus mostly on two types of chromosome:
Therefore I went with following approach: for each chromosome type I created a dedicated builder for which all parameters except operators (outside the fixed type) can be modified.
There is also a single "dispatcher" -
ecrs::ga::Builder
which has factory methods for other builders.Following API is now available:
We should consider separating our API into two categories:
Because most of API shape issues arise from the fact that we went for fully static API. We could also expose
dynamic
API, which is configurable in much easier way.Linked issues
Resolves #128
Resolves #179
Resolves #180