Showing posts with label Glowworm Swarm Optimization. Show all posts
Showing posts with label Glowworm Swarm Optimization. Show all posts

Friday, September 11, 2015

Last Pet Project: Glowworm Swarm Optimization in Clojure

Lately I've been working bit by bit in an implementation of the Glowworm Swarm Optimization algorithm (GSO) in Clojure.

Some time ago I implemented the GSO algorithm in C++ to practice TDD.

I decided to implement it it again in Clojure to practice with something larger that Exercism exercises or katas an yet small and familiar enough to finish it in spare bits of time.

This is the code of the resulting Clojure GSO on GitHub.

This GSO Clojure version is much shorter than its C++ version.

Aside from practicing Clojure, I've learned many other things while doing it.

I'll try to enumerate them here:
  • Mixing Java and Clojure code in order to use a Sean Luke's Mersenne Twister Java implementation.
  • I learned more about Midje's checkers.
  • dire library.
  • Decomposing a bigger Clojure application in several name spaces according to roles and responsibilities.
  • Using maps to model the data.
  • Struggling to make the code more readable and keeping functions at the same level of abstraction.
  • Using only higher-order functions to compose the algorithm (I set myself the constraint to use no global configuration maps).
  • Taking advantage of those higher-order functions to test the different parts of the algorithm in isolation.
  • Separating the code that builds the graph of functions that compose the algorithm from the algorithm itself.
  • Where would I apply a library like component instead of relying only n higher-order functions.
  • Many other little Clojure things.
But overall it's been great fun.

I'd like to thank Álvaro García, Natxo Cabré and Francesc Guillén from the Clojure Developers Barcelona meetup for their feedback and Brian Jiménez for rubbing elbows with me in the first C++ version.

Monday, March 26, 2012

Last Pet Project: Glowworm Swarm Optimization in C++

Lately @irrati0nal and I have been working on a C++ pet project: glowworm++
It is a C++ implementation of the Glowworm Swarm Optimization algorithm as described in the original paper from Krishnanand, K.N. and Ghose, D., Glowworm swarm optimization for simultaneous capture of multiple local optima of multimodal functions, published in Swarm Intelligence, 3, 2, June 2009, 87-124.

I wanted to practice TDD in C++ and was looking for an interesting pet project. So when I knew about @irrati0nal wanting to use GSO optimization for his research on protein docking, I asked him if he wanted to implement it in C++ with me and he gladly accepted. I had worked with genetic algorithms before and I thought that Bio-inspired algorithms were just beautiful.

We worked in short sessions once a week after work and in longer sessions during the weekend once a month, we called the long ones "hackathons". It wasn't difficult to follow the description of the algorithm in the paper, but we had to implement the coordinates and objective function code several times until we were happy enough with the result.

From the very beginning we wanted to release glowworm++ so other people could use it if they wanted. Now it's finally done. If you want to use it you can find the code here.

We applied TDD using the CppUTest framework and pair programming throughout the whole development. We are newbies in these two thecniques. We tried to do our best but, in the end, I think we did a nice job at TDD but not that good at pair programming. We had a lot of fun though. We need to read more about how pair programming works and how to do it well.
We also learn a lot of C++ and realize that we still have so much more to learn.

I'll try to improve my TDD and pair programming skills with my next pet project: I'm working with @remosu on a single page application using Backbone.js

In the near future, I'll have to devote most of my time after work to the UOC, so I won't have more time for glowworm++. However @irrati0nal is starting to use it in his research and will go on improving it to adapt it to his needs. Next summer, once the semester in the UOC is over, I'd like to use glowworm++ as well. I'll try to apply it to search special genetic networks.

@irrati0nal, thanks a million for all the good times we spent rubbing elbows together.

-----------------------------

Update:
I've continued evolving the code in this fork.
I mainly fixed a bug, simplified the code a bit and used some C++11 new features.