Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: better defaults for GA builder #149

Merged
merged 13 commits into from
Nov 25, 2022
Merged

Conversation

kkafar
Copy link
Collaborator

@kkafar kkafar commented Nov 17, 2022

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:

  1. We want to provide a blanket implementation over T: Chromosome for Builder struct. It would be ridiculous to force user to implement custom Builder.
  2. Different operators require different trait bounds on 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:

  1. real valued (RVC)
  2. bit string (BSC)

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:

  ecrs::ga::Builder::with_rvc()
    .fitness_fn(rastrigin::rastrigin_fitness)
    .dim(5)
    .build()
    .run()

We should consider separating our API into two categories:

  • static
  • dynamic

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

@kkafar kkafar self-assigned this Nov 17, 2022
@kkafar kkafar closed this Nov 21, 2022
@kkafar kkafar force-pushed the @kkafar/defaults-for-builder branch from e97f7b0 to 066c170 Compare November 21, 2022 23:06
@kkafar kkafar reopened this Nov 21, 2022
Make ga::Builder::default() to return builder with fixed operators?
@kkafar kkafar force-pushed the @kkafar/defaults-for-builder branch from d593de5 to d9eb9aa Compare November 24, 2022 20:50
@kkafar kkafar marked this pull request as ready for review November 25, 2022 17:46
@kkafar kkafar merged commit 2de39bc into main Nov 25, 2022
@kkafar kkafar deleted the @kkafar/defaults-for-builder branch November 25, 2022 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant