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

Use traits instead of structs #5

Open
garro95 opened this issue May 28, 2019 · 8 comments
Open

Use traits instead of structs #5

garro95 opened this issue May 28, 2019 · 8 comments

Comments

@garro95
Copy link

garro95 commented May 28, 2019

The Genotype iter and into_iter methods should return a Type that implements the Iterator and IntoIterator traits and not the specific implementation of these traits for slices.
This would improve usability of the framework

@Martin1887
Copy link
Owner

I have been thinking about changing this in a 2.x branch.

However, it has implications in the performance if Boxes are used to encapsulate the traits or makes more unconfortable the interface if generics are used (adding two more types to Genotype and GeneticExecution).

In the first version of the library I used this structs to simplify the interface and because all genotypes are arrays of things. What structs are you thinking about and what are their cases of use?

A possible use that I though was using bitflags, but I'm also thinking in implementing utilities to transform integers into Gray and vice versa.

Thanks.

@garro95
Copy link
Author

garro95 commented May 29, 2019

Maybe what I want to do is out of the scope of this framework. I will clone it and try to adapt it. Then we'll see

@Martin1887
Copy link
Owner

Feel free to fork and create pull requests. If they are interesting can be merged into this project.

Anyway, a 2.x branch will be created in the following months, with more flexibility and other improvements.

Regards.

@garro95
Copy link
Author

garro95 commented May 29, 2019

Do you mean there is already some work going on for this 2.x version? How can I know what are the improvements of this?

Regards.

@Martin1887
Copy link
Owner

Martin1887 commented May 29, 2019

Yes, I have been working in some ideas and implementations, but nothing has been pushed yet because I am experimenting and trying to get better results and performance.

The improvements are:

  • Different replacement strategies, like more similar individuals or children replace parents.
  • from_iter function instead of FromIteratorrequirement in Genotype to allow the modification of individuals changing their genes without modifying other relevant information. I am experimenting with the knapsack problem, where individuals have references to available items and knapsack' capacity for evaluation function but only the current items change.
  • distance function in Genotype with default implementation to support that strategies.
  • parents_children as argument of SurvivalPressure to support that strategies.
  • PopulationRefitness trait, that allows to refitness the population in function of the other individuals. This is useful for things like niches, that are also provided.
  • Multipoint and uniform cross functions.

These improvements are focused in find multiple solutions and exploring different search space areas.

Other improvements in which I have thinking (but not started) are:

  • Gray encoding utilities to use binary genotypes.
  • Using traits instead of structs as commented in into_iter and iter inside Genotype.
  • Macros to create simpler encodings (vectors of basic types) without boilerplate.
  • Python bindings (the loss of performance is critical for this).
  • Hall of fame (the historical best individuals are randomly introduced for cross).

I have not worked on this for some weeks, but I expect releasing a new branch during summer.

@garro95
Copy link
Author

garro95 commented May 30, 2019

Half of this is done by simply adding one trait bound IntoIterator<Item=T>

@Martin1887
Copy link
Owner

I had tried using IntoIterator<Item = T> as trait bound before, but that only provides into_iter function, and a function that does not take the ownership is also needed. I will continue thinking in the best interface.

@Martin1887
Copy link
Owner

2.0 version is more flexible than 1.x, but I have not made Genotype iterator types generic because it makes the interface much more cumbersome and a vector of genes is flexible enough. It would be overcome using trait alias VecGenotype like the current Genotype and a more generic Genotype trait with generic iterators, but they are not in Rust stable.

Maybe a future major version of Oxigen will apply this changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants