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

Add specialized components and port old components to new architecture #81

Merged
merged 36 commits into from
Jun 18, 2022

Conversation

Saethox
Copy link
Collaborator

@Saethox Saethox commented May 11, 2022

Closes #80, closes #85.

Ported modules:

  • archive
  • custom_state
  • generation
  • initialization
  • postprocess
  • replacement
  • selection
  • termination

@Saethox
Copy link
Collaborator Author

Saethox commented May 15, 2022

The RandomSpread and RandomPermutation initializer and generation components were merged into a single component that implements Initialization and Generation and exposes these two different types with the new_init(population_size) and new_gen() methods, wrapping itself in an Initializer or Generator, respectively. The generator component replaces a population, while the initialization component generates a new one that is pushed on the stack.

I think this pattern is a reasonable compromise between code reuse and usability.

src/operators/initialization.rs Outdated Show resolved Hide resolved
src/operators/mod.rs Show resolved Hide resolved
src/operators/selection.rs Outdated Show resolved Hide resolved
src/operators/selection.rs Outdated Show resolved Hide resolved
@Saethox
Copy link
Collaborator Author

Saethox commented May 23, 2022

Should the specialized component traits and helper structs rather be kept inside their respective modules? For example, Initialization and Initializor in operators::initialization?

Also, should we maybe split operators::generation into mutation and crossover/recombination submodules?

What do you think, @luleyleo?

@luleyleo
Copy link
Collaborator

Should the specialized component traits and helper structs rather be kept inside their respective modules? For example, Initialization and Initializor in operators::initialization?

I think that would be nice.

Also, should we maybe split operators::generation into mutation and crossover/recombination submodules?

Having submodules like operators::generation::mutation and the same for crossover seems reasonable, given how many there are. But the less classifiable should probably be kept in the operators::generation module.

@Saethox
Copy link
Collaborator Author

Saethox commented May 24, 2022

But the less classifiable should probably be kept in the operators::generation module.

Regarding this: PsoGeneration is currently located in this module, and I'm torn about this. On one hand, it kind of is a generation method, but on the other hand it is very heuristic-specific, with using a custom state and all. So I think it might be better to move it to heuristics::pso, similar to the ACO components. Or maybe add an operators::pso module? I think this is something we should discuss, as more and more heuristics with very specific components will be added in the future, which naturally don't fit into our previous categories.

@HeleNoir
Copy link
Collaborator

Regarding this: PsoGeneration...

I would like to keep it either as a kind of mutation or as some kind of operator::swarm. mutation would be suitable as the two operator types do essentially the same thing and should be interchangable in all algorithms. operator::swarm could be an alternative, as there are more PSO-like metaheuristics on our list and they do have very similar operators (this is also the reason why heuristics::pso would make the operator far too specific and I would say it isn't).

@Saethox Saethox mentioned this pull request May 31, 2022
7 tasks
@Saethox Saethox force-pushed the abstract-model-specializations branch from 82282cd to 3796b7f Compare May 31, 2022 14:59
@Saethox Saethox changed the title WIP: Add specialized components and port old components to new architecture Add specialized components and port old components to new architecture Jun 5, 2022
@Saethox Saethox mentioned this pull request Jun 5, 2022
@Saethox Saethox requested a review from luleyleo June 5, 2022 12:55
@Saethox
Copy link
Collaborator Author

Saethox commented Jun 5, 2022

This has become a very large PR, with more than 4000 lines changed, but I think this is appropriate.

@HeleNoir Please have a look especially at generation::swarm::PsoGeneration and the components in selection, and verify their correctness.
The selection::Tournament was sorting its tournaments the wrong way, and selection::LinearRank and selection::ExponentialRank did some weird thing with indirect rankings, which was very hard to understand, and I think incorrect. The ranking is now obtained by using argsort two times (which I'm still amazed that this works) and the layer of indirection was removed. I looked at a paper describing the exponential ranking, and it should now be correct. Applying the components in the GA also yields good solutions now, which was not the case before.

@luleyleo, I briefly looked at #88 and I think we have some overlapping functionality. I think a rebase of your branch would be good after we have sorted out this PR.

src/heuristics/pso.rs Show resolved Hide resolved
src/operators/generation/mod.rs Show resolved Hide resolved
src/operators/generation/mod.rs Show resolved Hide resolved
src/operators/selection.rs Show resolved Hide resolved
@HeleNoir HeleNoir mentioned this pull request Jun 9, 2022
3 tasks
Copy link
Collaborator

@HeleNoir HeleNoir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find any other issues (but I'm not that well-versed in Rust), so we should wait for @luleyleo to approve as well.

Copy link
Collaborator

@luleyleo luleyleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall. A few nits to pick and then we can merge this.

src/framework/individual.rs Outdated Show resolved Hide resolved
src/framework/state.rs Show resolved Hide resolved
src/framework/state/map.rs Outdated Show resolved Hide resolved
src/framework/components.rs Outdated Show resolved Hide resolved
src/framework/components.rs Outdated Show resolved Hide resolved
src/framework/components.rs Show resolved Hide resolved
src/framework/individual.rs Show resolved Hide resolved
src/framework/mod.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@luleyleo luleyleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good now 👍🏻

@Saethox Saethox merged commit 5083c20 into master Jun 18, 2022
@Saethox Saethox deleted the abstract-model-specializations branch June 18, 2022 10:21
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

Successfully merging this pull request may close these issues.

Is this implementation correct? Port components to new architecture
3 participants