
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

This test is broken right out of the box…
— FAIL: TestAgent (7.82s)
agent_test.go:77:
Error Trace: agent_test.go:77
agent_test.go:...
New

As per the title, thanks.
New

Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks”
While running the smoke tests in Chapter 2, I get these...
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

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

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 running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New

I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1:
programming_ML/code/03_...
New

root_layout: {PentoWeb.LayoutView, :root},
This results in the following following error:
no “root” html template defined for PentoWeb...
New

Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New
Other popular topics

You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
New

This looks like a stunning keycap set :orange_heart:
A LEGENDARY KEYBOARD LIVES ON
When you bought an Apple Macintosh computer in the e...
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

“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco
Ever wonder how authoring books compares to writing articles?...
New

A Hero’s Journey
with Chris Pine
@chrispine
Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New

Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New

Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

Author Spotlight
Jamis Buck
@jamis
This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New

If you want a quick and easy way to block any website on your Mac using Little Snitch simply…
File > New Rule:
And select Deny, O...
New
Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /haskell
- /java
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /slackware
- /julia
- /c
- /neovim