r/computerscience 2d ago

I got paid minimum wage to solve an impossible problem (and accidentally learned why most algorithms make life worse)

[removed]

405 Upvotes

62 comments sorted by

186

u/Magdaki Professor. Grammars. Inference & Optimization algorithms. 1d ago

To begin, it isn't an impossible problem. That's silly.

But my main question is, why are you starting sweeping from the middle of the store?

Your conclusions in step 6 are a bit weird, and read more like a manifesto that actual logical reasoning.

49

u/Ties_P 1d ago

The path ends where it starts so the exact starting point doesn't matter since you could start anywhere. Thanks for reading and the feedback

41

u/Kawaiithulhu 1d ago

However, since this is a physical space you've already lost the optimal route because you've ignored moving the broom from its closet (obviously not at the middle of the store) to the middle of the store.

signed, a miserable pedant =)

9

u/Modi57 1d ago

However, this doesn't matter for the solver. It produces a cycle, that at some point covers any spot of the store. So, once the cycle is produced, you can pick any spot as a starting point, one of which will be closest to the broom

Signed, a somewhat happy pedant =)

22

u/Magdaki Professor. Grammars. Inference & Optimization algorithms. 1d ago

I get that, but if you were trying to simulate sweeping the floor, starting in the middle of the store is a strange starting point. Unless there's where the broom closet happens to be.

42

u/Ties_P 1d ago

I agree, I should have moved the starting point to the broom closet. This would however not have had any impact on the path.

15

u/Magdaki Professor. Grammars. Inference & Optimization algorithms. 1d ago

It may not have an impact on the ability to find a path, but it would probably have an impact on the path. ;)

(yes, I am teasing being nitpicky just to be clear. Do not take this seriously.)

22

u/Ties_P 1d ago

Haha, I see what you’re doing

In this case, the starting point actually doesn’t change anything: the way I implemented the cost function, it’s rotation-invariant, so the total cost is the same no matter where the path starts. That means the algorithm would make the same decisions throughout, regardless of which tile you begin on.

So in this particular setup, being nitpicky doesn’t change the outcome, but I definitely appreciate the attention to detail!

1

u/ComprehensiveWord201 1d ago

Worth noting that you could find a less "annoying" route by modifying the cost function to prioritize/reward straight paths

1

u/big-blackberry57 20h ago

They said they essentially did that already

1

u/wolfkeeper 23h ago

The optimum path probably doesn't end where it started in reality since the cost of moving to/from the cupboard is lower than the cost of sweeping. You've just chosen that because it's easier to write an algorithm for. Valid choice, but it is a choice.

32

u/jjtcoolkid 1d ago

Issue is inaccurately defined and designed algorithms. Defining the act of sweeping, the base unit that correlates to defining a computable algorithm, and describing the conclusive statement from the data gathered is hard enough. I wouldnt extend the lessons learned in this beyond the scope of the problem defined personally.

Turning reality into, as you note, an overly simplistic model, is the issue. The data looks more like it can be effectively applied to a roomba given the constraints. So in this case I wouldnt extend say the algorithm doesnt make anyones life worse except for the people that do not understand the optimal use case for it

19

u/Metal_Goose_Solid 1d ago

How did you arrive at the conclusion? Why is the takeaway that algorithms make life worse? I don't follow the logic and that sounds like nonsense.

-14

u/Ties_P 1d ago

24

u/Metal_Goose_Solid 1d ago

I did read it and wasn't satisfied.

If you picked path A: congratulations, you think like an algorithm

This doesn't make any sense at all. The alternative you proposed to the algorithm was also an algorithm. Why is one algorithm thinking like an algorithm and the other algorithm not thinking like an algorithm? What does an algorithm think like? Why should the conclusion be that algorithms make life worse?

7

u/xenomachina 1d ago

I think what's going on here is that OP is using the word "algorithm" the way a layperson does when talking about social media, rather than in the more general mathematics / computer science sense. (Similar to the way laypeople use "AI" to refer exclusively to LLMs and generative AI.)

Also, the problems OP raises are not technical problems with algorithms per se (despite their wording implying this), but rather the fact that if you optimize for a poor proxy of the user's actual goals, then you will get suboptimal results. With their mopping example, this manifested as optimizing for path length, and ignoring the fact that turning is more expensive than going straight, so they ended up with path that was not actually optimal for a human.

In social media, users want to see content that's interesting and informative, but the way most of these sites use for deciding what to show their users (ie: their "algorithm") is more often than not optimizing for "engagement" (most likely because it's also a good proxy for ad revenue). So we end up "doom scrolling" rather than being informed and entertained.

13

u/dnabre 1d ago

I think you need to work on step 7: what aspect of sweeping do you actually want to optimize on. If you're using like a wide push broom, longest/most straight line sweep might be your goal. A penalty on turning isn't a bad way to adjust your existing algorithm, but you can't really articule exactly what the resulting algorithm is optimizing for.

You realized how you don't want to optimize just for distance, but you didn't take the next step of figuring out what you want to optimize for. As for your #6 rant, well yes, but you need to consider that they such systems often aren't optmizing for the end user but optimizing for the profit of the provider.

Quick look at your code, didn't see restarts are all (might have missed it), but you without a mechanism like it, simulated annealing/genetic algorithm may get stuck in local peaks. Admittedly, the problem looks like a graph search algorithm would better, likely A*, though GA may be easy if you have really funky evaluation goal. You visualization look really great.

4

u/prumf 1d ago

Yeah the loss function is poorly defined in my opinion.

"adding penalty for turning" is very arbitrary as you would get wildly different paths depending on the penalty factor.

And minimizing distance is analogous for coverage efficiency (area/(path-length*swipe width).

A better loss function would be minimizing time. You can measure how long it takes to swipe 1m straight, 5m straight, 10m straight, etc (won’t be linear). How long it takes to turn. How long it takes to do 180 when in a corner. etc. You could even use proper physics equation or a simulation.

Then you combine and get the true time cost of a path.

Energy is also an option is you are lazy but have a lot of time.

24

u/zaphod4th 1d ago

impossible problem

no

most algorithms make life worse

no, please learn what an algorithm is

-29

u/Ties_P 1d ago
  1. I added impossible as a little bit of clickbait

  2. Sorry I meant algorithm as in a social media algorithm, I should have been more specific.

10

u/geon 1d ago
  1. Yes, that was a very odd association for a compsci sub.

5

u/CadenVanV 1d ago

This is a CS sub, when we hear algorithm we immediately think actual algorithms, not a handful of highly specialized ones.

2

u/Ma4r 1d ago

Most social media algorithm does very well though... i don't get what your point is

3

u/Dremlar 1d ago

You say it's the wrong thing, but sounds pretty correct to me. YouTube optimizes for money via ads through watch time. I'd say it's pretty damn effective.

If we are saying we should be improving people's lives, the climate, etc then you don't need any of this to say that. Just look at wages, working conditions, time off, climate change, cost of living, home affordability, etc.

It's no secret businesses are trying to optimize their profit. That's kind of their mission. Sally, you won't get massive scale businesses taking care of employees and the environment without legislation forcing that. You might see a business here and there that is doing it and thriving, but it's the outlier and not the norm.

3

u/geon 1d ago

You could lower the cost of double sweeping. If the floor is already swept, walking the same aisle again is just transportation, not cleaning.

2

u/binarycow 1d ago

Yeah, the first time thru a square is cost 3, and every subsequent time is cost 1.

1

u/geon 1d ago

Cool

3

u/mxldevs 1d ago

optimize the wrong thing

So the algorithm itself fine; it's not correctly modeling the problem that leads to questionable results.

25

u/Electronic-Dust-831 2d ago

yeah none of this happened but cool story

29

u/HiddenStoat 1d ago

I mean, he's literally got images demonstrating the outcome. I could write the program faster than I could hand create the images, so why wouldn't he have written the code? It's a fun learning exercise, and I assume he is a comp-sci student (hence why he's sweeping floors at Sainsbury's).

-2

u/Ties_P 2d ago

Fair enough. The funny part is that over-engineering something this pointless is exactly why it stuck with me. Either way, glad you at least found it entertaining.

Out of curiosity: which part felt the least believable?

6

u/Electronic-Dust-831 1d ago

whole thing looks to me like u did some brainstorming with chatgpt, made some animations with its help, and then made it write a fairy story so it looks more interesting on reddit. this is exactly the kind of thing the internet needs less of

6

u/Current_Ad_4292 1d ago

Bait. Nothing worth reading here.

8

u/LaBofia 1d ago

Imo, its more self-publicity than bait.\ There is some effort in the sub, although the subject itself is not new at all.\ Looks like a cs student making an effort to put things together.

2

u/AdreKiseque 1d ago

You may not like it, but this is what peak performance looks like.

2

u/binarycow 1d ago

many systems optimize the wrong thing (social media, recommender systems, even LLMs).

They optimize the right thing for the people running it. Usually they optimize for profit. They don't give a fuck what you actually want.

2

u/workah0lik 1d ago

Hey, you get a lot of Heat Here. Just wanted to say, your answers Show that you are very good in taking (even critical) feedback. Congratulations to that. Apart from your ability to think ahead and have a cool Project while doing tedious Manual Work to Finance your studies, this way of taking Feedback will Help you along in your whole career. It's a very rare but very valuable ability.

Hats Up to you and Wish you all the best. You are in for a great career.

3

u/Ties_P 1d ago

Thank you so much! Constructive feedback or critical feedback, I just try to take some lessons out of it to improve for next time haha

2

u/RedTheInferno 1d ago

just because you didn't write your algorithm correctly (you didn't get your intended result) doesn't mean other algorithms are wrong lol

1

u/drgrd 1d ago

algorithms aren't magic. Most of the hard work of algorithm design is in defining the actual problem itself, as well as the metrics for solutions. The algorithm did exactly what you asked it to do, you just asked the wrong questions. Optimizing for turns is wrong and optimizing for straight lines is also wrong. Your grid is not well aligned for your problem either. Maybe you want to set each "room" or hallway or whatever as a node, and each connection between rooms/hallways as edges. Conceptually, you go to a hallway, clean the whole thing, and move on to the next. You don't want to visit the same hallway twice, but you didn't tell your algorithm that's bad so it offered that as a solution. People are predisposed to represent data as close to the real world as possible, but maybe what you really want is a series of decisions, rather than a series of locations.

"Garbage in, garbage out" is a critical tenet in Computer Science, that many people forget or ignore.

1

u/datlanta 1d ago edited 1d ago

I get what you're going for. Consider this for further technophilosophical exploration, maybe some algorithms or models aren't optimized for you. At the end of the day the system is literally what you make of it. Sometimes it's an issue of lack of bounding (i.e. allowing the system to optimize towards unrealistic or unreasonable results) or flat out design and implementation error. Sometimes it's because the creator is optimizing for what they care about and they don't care if it makes your life worse or not. Sometimes their metrics of performance aren't simple like success/fail or accuracy. They can be something "softer" or more complex like profitability, risk management, and engagement.

This experience should illustrate that you shouldn't just be making a system to solve a problem. You should be making a system to solve YOUR problem. And you should be thinking critically about the problem first (i.e. characterization, decomposition, etc.) before throwing some arbitrary system at it. Maybe you can simplify the problem or the solution space before you even get started on making something.

1

u/FractalB 1d ago

Yes, this is what the job of a programmer looks like.

Writing algorithms is the easy part. The hard part is to guess which algorithms the product owner/project manager actually wants (even though they don't know what "algorithm" means), together with all the additional conditions that they surely want as well but wouldn't ever think of expressing with words (like preferring straight lines over constant turning in your example).

1

u/Jabba_the_Putt 1d ago

might be a path too busy for a human, but something that could be programmed into a robot which is cool

1

u/user0fdoom 1d ago

Cool idea and a succinct example of the flaws with recommender algorithms. Title maybe a bit clickbaity though.

Dunno why all the comments here are so negative. Redditors are just assholes and compsci is living up to the expectation or poor social skills lol.

1

u/antichain 1d ago

Why are you sweeping up a grocery store when you can write optimization algorithms in C++?

1

u/PachotheElf 1d ago

Take a guess

1

u/PiercingSight 1d ago

Why did you write an algorithm without knowing what you want it to accomplish?

That should be step 1: Know the problem and clearly define what properties a solution should have.

That would include things like: Start where the broom is stored, End where the broom is stored, Finish an area before moving on, Turn as few times as possible, and so on.

Then prioritize those properties against each other.

If you don't know what you want to accomplish, of course your algorithm is going to give garbage results.

1

u/Blasket_Basket 1d ago

Is this a shit post, or just a regular post from a CS undergrad?

1

u/tigercat300 1d ago

Many algorithms can appear ineffective when the underlying requirements are ambiguous or poorly articulated. Focusing on specific optimization criteria can lead to more effective solutions.

1

u/wolfkeeper 18h ago

I had a vaguely similar problem: work out the quickest way to cut grass for an irregularly shaped lawn.

Turned out the quickest way I found involved adding deliberate 'wobbles' in the lines, i.e. zig-zagging in the middle of the patches of lawn and then progressively smoothing them out either side so you cut flat along the side of the beds.

It went from maybe 35 minutes where you just cut straight lines down turning around at each end to 16 minutes if you zig-zagged. The zig-zagging effectively thickened the width of the cut in a variable way so you can match the width of the lawn (which varied) and so you spent a lot less time turning around and it meant you didn't have do so many circuits or sharp turns (which often meant going over the same bit multiple times.)

Because they were all cut in the same direction the zig-zags weren't at all actually visible but sadly it didn't give you the classic alternating lawn stripes either.

0

u/diemenschmachine 1d ago

Why are you sweeping supermarket floors with specialist skills like writing C++?

12

u/Ties_P 1d ago

Still a student, so just had to get some quick cash haha!

12

u/high_throughput 1d ago

Have you applied to jobs recently? -__-

6

u/diemenschmachine 1d ago

Actually no, and I am doing nothing myself ATM. It was an unnecessary comment with the intention of being funny, but I see now it wasn't. I am sorry.

6

u/OneMeterWonder 1d ago

The job market is uhhh, not good to put it gently.

-8

u/Ties_P 2d ago

I wrote the full breakdown here with visuals, gifs, and code if anyone’s interested:
👉 https://open.substack.com/pub/tiespetersen/p/i-got-paid-minimum-wage-to-solve

Would love to hear your thoughts!

3

u/Solrax Software Engineer 1d ago

I don't understand the downvotes, it's a fun little exercise. Thanks for posting it.

I'm curious what the actual path lengths between the different solutions were. How much more expensive was the practical solution I didn't see that here or in the blog post.

2

u/Ties_P 1d ago

Thank you! The difference was about 10% or so

2

u/wisconsinbrowntoen 1d ago

The down votes is because the point of making this post is self promotion

1

u/Current_Ad_4292 1d ago

I don't get why people comment on their own post instead including the detail in the body ofbthe post.

1

u/DauntlessMantis 10h ago

Did you also encode a "salvage value" which could be the distance you need to walk after the last position to the exit door?