In our previous installments, we laid the groundwork of our Bee Colony Algorithm implementation. Today, it’s time to put the bees to work, searching for an acceptable solution to the Traveling Salesman problem.

We will approach the search as a Sequence: starting from an initial hive and solution, we will unfold it, updating the state of the hive and the current best solution at each step. Let’s start with the hive initialization. Starting from an initial route, we need to create a pre-defined number of each Bee type, and provide them with an initial destination:

let Initialize nScouts nActives nInactives cities (rng : Random) = [ for i in 1 .. nScouts do let solution = Evaluate(Shuffle rng cities) yield Scout(solution) for i in 1 .. nActives do let solution = Evaluate(Shuffle rng cities) yield Active(solution, 0) for i in 1 .. nActives do let solution = Evaluate(Shuffle rng cities) yield Inactive(solution) ]

There is probably a more elegant way to do this, but this is good enough: we use a simple List comprehension to generate a list on the fly, yielding the appropriate number of each type of bees, and assigning them a shuffled version of the starting route.

## Comments

- Create an Excel chart in C# without worksheet data (3)
- Read Excel VBA macros and functions through C# (30)
- Using FSI to execute F# code from a .NET app (8)
- Excel ScatterPlot with labels, colors and markers (29)

Comment RSSgopro hero 4 release date 2014 wrote: All the different styles of Chaco adventure sandal... [More]

identity theft protection tips wrote: Hello! I could have sworn I've been to this site b... [More]

Dave Thomas wrote: If anyones interested I wrote a couple of article ... [More]

Ron wrote: Mathias, That was just what I was looking for. T... [More]