The Eureka Moment

Hollywood is full of tropes, significant and recurring themes that are used for everything from character development to plot advancement. For example, in almost every film where the protagonist is trying to solve a problem there is some seemingly unconnected event that triggers their working out the answer. The “Eureka!” moment is so prevalent it’s getting hackneyed. And yet it’s not as far fetched as it sometimes seems.

Software developers are well aware of how solutions to problems will often come to them at bizarre times. Sometime you just wake up with the answer. Sometimes it pops into your head while taking a walk, or having a shower. In fact, this is so common that at Rainbird we actively encourage people to go for a walk when they’re stuck.

But this isn’t the seemingly unconnected event. This is just giving your brain the space to work on the issue almost subconsciously. Sometimes, however, the mind does need something to prod it in the right direction.

This weekend I was at Wroxham Barns with my family. The children’s menu there has activities on the back to keep small people occupied while they wait for their food. It’s a fairly standard practice at child friendly venues and often gives parents a chance to hone their colouring skills under the close supervision of their children – at least that’s what happens in our family.

In this particular case I was helping Willow, my eldest, to do the maze. I was also using it as an opportunity to start teaching her fairly basic pathing algorithms. We would draw a line to a junction, then check each possible route for dead ends. Since it was a fairly basic maze I could easily check ahead and guide Willow so that we only started drawing again when each incorrect direction has been investigated and discounted.

At one point the maze got a little more complex, with me having to hold a number of junctions in my head and effectively build a tree of routes which we could then go and explore. Not only that, but there were actually multiple routes through the maze. Jokingly I started talking about Dijkstra’s algorithm and A*, knowing full well that we were already well beyond the attention span of a three year old.

Far from being a pointless and throwaway conversation with a small child, the event actually linked two disparate bits of information that had been floating around my head for weeks now. You see, I’ve been trying to move more of Rainbird into the graph to simplify our inference algorithm. I believe I now have the core structure of the graph correct, and have been thinking through how inference would work within this structure.

My working hypothesis was that the answer starts as a linear goal and expands to be a tree as the solution is sought. But there’s a problem with this. For complex Knowledge Maps the tree can get very large very quickly. There is a performance concern here.

Sitting there, messing about with this maze and trying to explain pathing algorithms to a toddler I suddenly realised that the solution isn’t a tree, it’s a directed acyclic graph with multiple paths through some parts. I could collapse large parts of very complex trees, seek multiple routes through the graph at once, and handle complexities such as salience that I hadn’t even considered yet.

Sadly this isn’t Hollywood, and I didn’t get to just run off an implement the solution. I had to continue entertaining the child until lunch came and wait until we were back in the car home before I could jot down some notes. I also won’t be able to code up the solution in a single sitting with beautiful, bug free code that works first time. Instead I get to test my new hypothesis on paper, see if it works, and then slowly integrate it into the existing codebase over the coming months.

So yes, the eureka moment isn’t that far fetched. It’s just everything that happens around it that is.