Genetic Algorithms in Elixir: Using reinsertions (source code)
Provided source code has some problems when dealing with the reinsertions.
- scripts/schedule.exs example has a default reinsertion strategy set to “elitist”. The problem is, it actually doesn’t and is always running the default “pure” strategy because the naming of the optional parameter has a typo. Changing “reinserton_strategy” to “reinsertion_strategy” does the trick.
- If we run the script again, correct strategy is used, but now we get an “ArgumentError” in “Toolbox.Reinsertion.elitist” function when trying to sort data based on fitness.
The problem actually lies in the “Genetic.evolve” function. In it, “select” function is called which returns “parents” ( composed of pairs of chromosomes, ie: [{p1, p2}, {p3, p4}, …] ) and “leftovers” ( represented as a normal list of chromosomes, ie: [l1, l2, l3, …] ). These two get recombined in the
“Toolbox.Reinsertion.elitist” function producing a list like [{p1, p2}, {p3, p4}, l5, l6] which is of wrong format.
A solution then is to de-chunk the “parents” list before sending it to reinsertion function. Something like the following should do the trick:
parents = parents
|> Enum.reduce([],
fn {p1, p2}, acc ->
[p1, p2 | acc]
end)
- While testing this I also found that the “population_size” parameter is not working. This is because “Genetic.run” does not pass optional parameters to function “Genetic.initialize”. Changing the call to:
population = initialize(&problem.genotype/0, opts)
solves it.
Popular Pragprog topics

page 37
ANTLRInputStream input = new ANTLRInputStream(is);
as of ANTLR 4 .8 should be:
CharStream stream = CharStreams.fromStream(i...
New

The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New

When I try the command to create a pair of migration files I get an error.
user=> (create-migration "guestbook")
Execution ...
New

First, the code resources:
Page 237: rumbl_umbrella/apps/rumbl/mix.exs
Note: That this file is missing.
Page 238: rumbl_umbrella/app...
New

Hello! Thanks for the great book.
I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New

In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New

Hi,
I completed chapter 6 but am getting the following error when running:
thread 'main' panicked at 'Failed to load textur...
New

Modern Front-End Development for Rails - application does not start after run bin/setup (page xviii)
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New

Modern front-end development for Rails, second edition - Struggling to get the first chapter to work
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install ...
New

I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New
Other popular topics

Reading something? Working on something? Planning something? Changing jobs even!?
If you’re up for sharing, please let us know what you’...
New

I’ve been really enjoying obsidian.md:
It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New

I’m thinking of buying a monitor that I can rotate to use as a vertical monitor?
Also, I want to know if someone is using it for program...
New

We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New

There’s a whole world of custom keycaps out there that I didn’t know existed!
Check out all of our Keycaps threads here:
https://forum....
New

Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face:
...
New

I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New

Was just curious to see if any were around, found this one:
I got 51/100:
Not sure if it was meant to buy I am sure at times the b...
New

Author Spotlight: Mike Riley (@mriley)
This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s bo...
New

Author Spotlight: Peter Ullrich (@PJUllrich)
Data is at the core of every business, but it is useless if nobody can access and analyz...
New
Latest in Pragprog
Latest (all)
Categories:
My Saved Portals
-
None saved yet
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /v
- /react-native
- /wasm
- /security
- /django
- /nodejs
- /centos
- /haskell
- /rails
- /fable
- /gleam
- /swift
- /js
- /deno
- /assemblyscript
- /tailwind
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /preact
- /flutter
- /c-plus-plus
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /vuejs
- /nim
- /emacs
- /nerves
- /elm