
kristjan.rovsek
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 Prag Prog topics

Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New

Hi Brian,
Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New

Hello Brian,
I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New

your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New

In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions:
In Gemfile, change
gem 'rails'
t...
New

When trying to run tox in parallel as explained on page 151, I got the following error:
tox: error: argument -p/–parallel: expected one...
New

When running tox for the first time, I got the following error:
ERROR: InterpreterNotFound: python3.10
I realised that I was running ...
New

I am using Android Studio Chipmunk | 2021.2.1 Patch 2
Build #AI-212.5712.43.2112.8815526, built on July 10, 2022
Runtime version: 11.0....
New

Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
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

Hello Devtalk World!
Please let us know a little about who you are and where you’re from :nerd_face:
New

Why, if your answer is yes?
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

I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl:
The Ser...
New

Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New

Think Again 50% Off Sale »
The theme of this sale is new perspectives on familiar topics.
Enter coupon code ThinkAgain2021 at checkout t...
New

Hi folks,
I don’t know if I saw this here but, here’s a new programming language, called Roc
Reminds me a bit of Elm and thus Haskell. ...
New

We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New

Author Spotlight
Rebecca Skinner
@RebeccaSkinner
Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
New
Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /zig
- /html
- /scala
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /textmate
- /sublime-text
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /julia
- /c
- /slackware
- /neovim