Day 9 – Perl 6 and the wolf pack

This year I rejoin with Perl6 once again and found out that this Christmas is THE Christmas.

With the announcement of Larry Wall and the imminent liberation of a 1.0 version of Rakudo I got really excited and right away started a couple of side projects using it.

And just when I was thinking that Perl6 couldn’t get any cooler I found the Jonathan Worthington, YAPC::Asia conference: «Parallelism, Concurrency, and Asynchrony in Perl 6».

Perl6 parallelism realy impressed me so implemented an  adaptation of the Grey wolf optimizer created by Mirjalili et all in 2014.

This algorithm (by wikipedia’s definition) is a meta heuristic that mimics the social and hunting behavior of the wolf packs to search for “good enough” solutions in a wide range of problems.

The pseudo-code here:


And from my implementation the interesting parallel bits:


Initially I used a loop block here (I like them more), but that caused that all the wolves end up with a random value instead of keeping the passed $wolf_number value.

After a couple hours and a lot of questions on the #Perl6 IRC channel (wonderful, patient people by the way) I found the problem: the $wolf_number variable disappear with the end of the loop block leaving the fitness_libsvm with nothing.

After that is just await and vòila! process the results.


Never ever have I seen a simpler more elegant code for parallelism than the one produced by Perl6… I just love it!

Postdata: The full implementation is available at

3 thoughts on “Day 9 – Perl 6 and the wolf pack

  1. Updating the top three wolves is buggy. If the old alpha fitness was 3 and the new omega wolves have fitnessses [4, 5, 6, …] in ascending order then beta and delta will never be updated.

    1. Hi Michael,

      Nice catch!, the original mathlab implementation (made by the author of the paper) suffer from the same problem.

      I’ll make some tests to see how this changes the behavior of the algorithm.

      Many Thanks,
      Aurelio (Sufrostico)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.