But I’m a computer science student, I have a problem: I can’t stop trying to optimize things that (probably) don’t need optimization.
So instead of just doing my job and, well… cleaning up… I did what any “reasonable” person would do: I converted the supermarket floor plan into a grid graph, created a visual editor, and wrote a C++ path optimizer using simulated annealing.
But before we get into how this went horribly wrong, and how it made me realize how miserable it makes everyone, I want you to answer a quick question:
If you had to take over my job for a day (I wouldn’t recommend this but hypothetically speaking) and you needed to clean the entire Albert Heijn floor, would you take path A or B?

seriously. Check them out. Which one seems more efficient for cleaning supermarket floors?
If you chose Path A: Congratulations, you think like an algorithm and are probably a robot. (Good luck with the captcha questions.)
But you are technically correct. Path A is shorter in terms of distance. However this is absolutely useless.
Look at those turns. Actually imagine for a second that you would be taking those turns. You’ll look crazy, like a Roomba having a seizure.
Path A is when you adapt to the wrong thing.
Which, spoiler alert, is the entire point of this story. But we will get there, first let me explain how we got here:
First, I took the Albert Heijn floor plan and turned it into a grid. Each tile is either empty (must be swept) or has an obstacle (a wall, a checkout counter, a yogurt package that someone has thrown on the ground).
I made a visual editor processing (a Java tool for those who like to make things fancy), so I can easily map the store and export the resulting graph.
So converting the floorplan to a grid structure was quite easy.

Tiling the actual floor helped break up the area into smaller pieces.

This can then be easily converted into a network structure (also called a graph) by interpreting each tile as a node and then connecting them to neighboring tiles.


As you can see, I’ve allowed horizontal and vertical movement as well as diagonal movement (as long as you don’t fly through walls).

The only thing to do next was to find a cycle through this network, making sure to visit all the nodes (tiles). Then this will be the solution to my broader problem.
(This problem is also called Traveling salesman problemSee the article for more details and why it’s so hard to “solve”.)
Since finding the best path in a graph of this size is computationally impossible, we have to resort to heuristics. Estimates basically try to find Very good Instead of trying to find a solution in less time Excellent Solution (which is more or less impossible).
So I implemented the path optimizer in C++.
Underlying Heuristic Algorithm: simulated annealing,
If you’re not familiar, simulated annealing is essentially trying a bunch of small changes (also called local moves).
At first, you simply accept every small change (even if it makes the path worse), but throughout the algorithm you gradually become more selective and finally allow only those changes that strictly improve the path.
This is inspired by how metals cool. Explore a lot by starting at a higher temperature (just trying different tricks), and then gradually cooling down to a lower energy state (closer to optimal).

Check out this GIF. See how it starts out chaotic and slowly settles down to a stable state? This annealing is exemplary in doing its job.
For the local move, I used the 2-opt move. You take two edges in your path, remove them, and reassemble them in a different way. If this small change improves the path, keep it. If not, either keep it (if the temperature is still high) or discard it.

So just do that 1 billion times. Or well… let your computer do this 1 billion times.
After letting it run for a while, I got my first “optimized” path. Here’s what it came up with:

Look at this. That route has more sharp turns than Christopher Nolan’s film. There’s no way anyone could be crazy enough to actually do a sweep like that. You will probably vomit afterwards.
Technically, it covers the entire floor. Technically, this is (almost) the shortest path. Technically, it is perfect.
It has some good parts, but in practice, it’s absolutely useless.
The algorithm did what I asked. (Thankfully, imagine if it did something else entirely, that would be scary.)
I just asked the wrong question.
I immediately realized that I was optimizing for the wrong thing. Distance isn’t everything.
The matter changes. Speed matters. Looking like a bad robot doesn’t matter.
So I added a “turn penalty” to the cost function and asked it to be reduced as well. Basically the algorithm is saying: “Turning 90 degrees gets you extra points. Turning 180 degrees? You’re out of your mind.”
This resulted in easier routes, even if it made the distances slightly longer.

look at that. It’s actually…walkable. You can give this path to a real human being and they won’t leave it there.
We are no longer optimizing for distance. We are adapting to reality.
This is where the fun is found.
You can adjust the penalty for sharp turns. It acts as a slider between “pure efficiency” and “actually useful”.

You can literally see the trade-offs. As you increase the fine, the path becomes easier but a little longer. As soon as you reduce it, you get efficiency but chaos.
Which path you choose is entirely up to you. It depends on how easy it is for you to turn, whether total distance is a priority or not, and how much detours you can tolerate.
However, it’s not just about cleaning the floors.
It’s about everything.
Social media algorithms optimize for engagement. They are really good at it. Problem?
Engagement ≠ happiness. Engagement ≠ truth. Engagement = clicks, screen time, anger and reaction.
consequences? Outrage, misinformation, condemnation, concern.
The algorithms are working perfectly. It’s doing exactly what it was designed for. The cost function is just wrong. (Instagram will probably think otherwise.)
Recommendation algorithms optimize for viewing time and click-through rates. Your grandma has been watching conspiracy theories on YouTube for 6 hours.
The algorithm crushed it. She feels like crap.
No surprise there.
Even LLMs (large language models) like ChatGPT optimize for the wrong thing. They adapt to appear confident. Looks like he knows the answer.
Not to be perfect. Not to be honest.
They are trained to complete the pattern, not to say “I don’t know”. So they just guess. Without any shame and with perfect grammar.
This also applies to things outside of technology.
Think about businesses. Most of them optimize for profit. Earth, environment, morality or ethics? They are not integrated into the cost function, so they will not be optimized.
Did I use this optimized path in my actual work?
No, obviously not. I cleaned the floor like a normal person.
But its creation taught me something I think about constantly: Technical correctness is useless if you’re solving the wrong problem.
You can write perfect code. You can create flawless systems. You can optimize the sh*t out of your cost function. And you may still end up with something that sucks.
The important part is not the optimization algorithm. The important part is to figure out what you should optimize for first.
Most of the time, we don’t even ask that question. We just adapt whatever is easy to measure and hope it works.
Spoiler: Probably not.
If you learned something from it, great. If you enjoyed watching me do overly complicated cleaning tasks, that’s cool too.
Anyhow, thanks for reading about my attempt to optimize a function that didn’t need to be optimized at all.
Do you want more experiments like this? More algorithms, interesting technology, and the occasional rant about productivity and the attention economy? Subscribe for free below! (No spam, only 1/2x per month)
GitHub Repository (code): Here
<a href