Archive for December, 2007

Porting the Particle Swarm

I had an idea that I might do something with particle swarm optimization .. another of the “nature inspired” pantheon of randomized algorithms which explore the possible solution space in a semi-greedy manner .. always the trade-off that : greed versus patience and investment (even if we are only talking computer cycles). And I thought differential evolution might do something for me too .. possibly it still will. The application has something to do with optimum positioning of labels in a 2D/3D visualization.

I won’t bore you with the algorithmic details. If you know the area (scatter search, squeaky wheel optimization, tabu search, simulated annealing and the dreaded genetic algorithms) then you will know what I am talking about - otherwise do a bit of googling on particle swarms and why swarms are not flocks and you will have a good time.

Now my point is porting. And OOP. And whether there really is a way forward, and whether legacy code should have a silver stake driven through its heart

These algorithms PSO (Particle Swarm Optimization) and DE (Differential Evolution) are usually touted as “simple - just a few lines of code”.

Yes, well we have all been there and done that, haven’t we?. It’s such a simple algorithm that we/you can do it in your sleep, right? Yeah, right. Reminds me of the first time I implemented a multidimensional scaling algorithm (”just a few lines of code”)

But being ever optimistic, I found me some code - a more or less standard PSO (Particle Swarm Optimization) implementation in C. Why C one might ask?.. or Fortran for that matter?

And why are modern algorithms being implemented in Dead Languages?

And it is 12 TWELVE pages of code. Of which 90% is either housekeeping or workarounds for the language deficiencies.

So, I thought I would port it from C to maybe Delphi or C#. With the aid of a language translation tool. Like C2Pas or somesuch.

yeah, in your/my dreams

I guess you know it didn’t work?

Well, you’d be right.. a half a dozen tools just made a mess of it. Nothing compilable, nothing remotely approaching compilable. Nothing sensible, nothing that if I could have got a working exe out of it would I have had any confidence in at all.

So, What am I Gunna Do?

Simple. An Informed and Literate Complete Rewrite. In a Living Language

The algorithm is good. The Quick Fix isn’t. A bit of thought and an elegant rewrite that puts all the housekeeping and service classes out of sight and out of mind, and we will be back to where we started.

Comments (5)

Frabjous Day

Comments

« Previous entries ·