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

Implement a genetic algorithm that can handle an arbitrary number of images #4

Open
6 of 9 tasks
ravicious opened this issue Aug 6, 2021 · 1 comment
Open
6 of 9 tasks

Comments

@ravicious
Copy link
Owner

ravicious commented Aug 6, 2021

Photo Layout with a Fast Evaluation Method and Genetic Algorithm by Jian Fan describes a genetic algorithm for making collage layouts which perfectly fits our needs.

However, in order to actually implement the algorithm, we need to take care of some other stuff first.

  • Write a Wasm prototype that uses a genetic programming crate.
    • The crate will be probably either genevo or rsgenetic, probably best to evaluate them both.
    • Check if either of them works without any rayon-enabled features.
      • If it does then we can skip the next main point and go straight to writing the algorithm, adding parallelization later to make the algorithm faster.
    • We might need to use wasm-bindgen-rayon, because both of those crates depend on rayon, which doesn't work in Wasm OOTB.
  • Implement randomized generation of layout tree (III.A).
  • Implement the fast layout solver (III.B).
  • Translate the random layout into an actual image.
    • I didn't think too much about it yet, but going from the tree to an actual bitmap will certainly require some thinking.
    • The first idea that came to my head was to treat each internal node as a separate canvas. We can calculate the size of each internal node. Going deeper in the tree is just going to shift the coordinates on the root canvas on which a particular internal node operates. So first we go to a bottom node and then make our way up.
  • Implement the cost function (III.C).
    • We don't need to care about desired image size for now, all images will have the same weight.
  • Implement the genetic operators (III.D)
    • This will probably be the most time consuming step, as far as the genetic algorithm is concerned, because it involves tree operations and I need to read more about that, never done that in Rust.
  • Use the previous steps with a genetic programming crate to let the algorithm create a better layout.
  • (Not needed for now) Rewrite the current code to use --target web rather than --target no-modules.
  • (Not needed for now) Add wasm-bindgen-rayon and increase population size.

III.B and III.C might need to be slightly changed. The original algorithm treats the resulting canvas size as the input, whereas we don't know the size upfront and just want to optimize for the biggest one. Perhaps the cost function will need to control the trade-off between canvas size and coverage of canvas area by images.

@ravicious
Copy link
Owner Author

@ravicious ravicious changed the title Implement a genetic algorithm that can handle arbitrary number of images Implement a genetic algorithm that can handle an arbitrary number of images Aug 6, 2021
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

1 participant