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 https://github.com/Sufrostico/perl6-gwo