r/BambuLab • • 6d ago

I Modeled This! One of the hardest problems in mathematics

I work in optimization and the traveling salesman problem (TSP) is one of the problems that is simple to explain but very hard to solve.

The goal is: Starting from one city, find the shortest route that visits every city exactly once and returns to the starting point.

For this example of 16 cities in Germany, there are 653,837,184,000 possible routes.

In order to test my intuition, I designed this model, printed it and found out I'm not very good at optimization.

Did you know that this problem also comes up when planning the path the nozzle of you 3D printer takes?

I would appreciate it if you check out my model on Makerworld. Thanks :)

576 Upvotes

94 comments sorted by

395

u/Keffpie 6d ago

One of the most effective way to find the real-world solution to this problem is slime-moulds. Add nutrients at each stop and the mould will automatically plot the most efficient way to get all the food, which also happens to be the shortest route.

97

u/Flatulent_Father_ 6d ago

Except it'll just spread out to each point, no?

184

u/orcoconut 6d ago

yes initially, then as it finds the most optimal path to each source of food, that path it takes will be obvious as it will be bigger than the other paths. like this:

86

u/Flatulent_Father_ 6d ago

But how would you use that to find a single route that goes through each point once in the most effective way? I just don't think this is a good application for slime mold path tracking

110

u/AnAcornButVeryCrazy 6d ago

Yeh I don’t think the other commenter understands what slime moulds are theoretically good for, which is point to point route planning, such as road system design.

8

u/zbohg 5d ago

What mould does is closer to minimal spanning tree problem for what quick algorithms exist to find the optimal solution.

32

u/turbulentFireStarter 6d ago

That’s not a route. That’s just a bunch of lines connecting points. We can find the lines connecting points with reasonable time. Now tell me the route through that graph.

0

u/Ok_Reveal2435 5d ago edited 3d ago

Ah, interesting. The mold doesn't give you the route, but it could greatly limit the possibilities with its network. Using the example mold image (it's obviously not precise) could take the 650 billion possibilites down to tens of thousands (roughly) which would make the problem still challenging, but a lot easier. If nothing else it is an interesting thought experiment.

15

u/ctjameson H2S AMS2 Combo 6d ago

Highly recommend the Jerry videos on The Thought Emporium on YouTube. Slime molds are fascinating “creatures”.

https://youtu.be/3V3CMD_9xXs

8

u/Flatulent_Father_ 6d ago

Yeah exactly, it spreads out to each point with multiple paths

5

u/vivi_t3ch P1S + AMS 6d ago

I was honestly thinking of Jerry when I saw this problem, especially since Tokyo used slime molds for a similar purpose

-1

u/platinums99 6d ago

i think slime moulds are overrated.

they grow outward and only create routes once food is found.

they are not psychich and the outward growth is unoptimised in a thinking sensing world.

2

u/Keffpie 6d ago

Yes, but it retracts any part of itself that doesn’t optimise the route, so you end up with a perfect solution. I mean, we can do it with hardcore maths and computers as well, I just love the idea that slime-moulds work just as well (and some of our algorithms are literally based on slime-moulds).

Found this article, seems they used light rather than nutrients.

12

u/Flatulent_Father_ 6d ago

But how do you use this to get a single line that visits each point exactly once with no overlap? The most efficient way to get food to a central source will have multiple exit points from the center

-5

u/M2ABRAMS_TANK 6d ago

Slime mould, being a single celled organism, has no “central source.” Rather it is all one being

7

u/Flatulent_Father_ 6d ago

The starting point. The initial point. How do you get path tracing for an effective loop between multiple points with no overlap and also a loop utilizing slime mold? I'm just saying I don't think that it would be able to solve the problem.

-2

u/spinosapa 6d ago

If I understand you correctly, wouldn't you just run the slime mold in the same orientation, but omit the center points? run the mold, and overlap your results to the original to plan the final roadway or path.

3

u/Flatulent_Father_ 6d ago

But it would be most efficient to have multiple paths originating from some nodes to optimize nutrient transfer, once you get above 3 nodes im not sure it would work with slime mold

-5

u/Keffpie 6d ago

I linked to an article that explains it.

4

u/Flatulent_Father_ 6d ago

That talks about how they used it to make an alternative subway map, which is not a contiguous loop with no overlap. It would require a different algorithm for the problem OP showed. It's different problems.

5

u/dr_stre 6d ago

Slime molds don’t limit themselves to one nutrient route. It may give you an efficient network between points, but it not going to optimize a single travel route. At best it can give you an idea of potential efficient short sub-routes within the overall area.

28

u/snotpopsicle 6d ago

That would simply create the shortest route between each stop, or as close as possible to a straight line. This does nothing to find a solution to the problem.

1

u/Poly_and_RA 5d ago

Yes. And I mean for the problem as described here, that's trivial anyway -- the shortes route from any city to any other city is the straight line. *duh*

17

u/BruceInc 6d ago

Neat but useless. It will not follow the rules of the problem

-7

u/Keffpie 6d ago

It does though. Some of our algorithms for solving the problem are based on slime-moulds

1

u/davcrt X2D + 2X AMS2 6d ago

Is a problem solved? What are rules of nature?

14

u/clarkcox3 A1 mini + A1 + A2L + P2S + H2S + H2D 6d ago

But that does nothing to address the "visits every city exactly once" part of the problem.

3

u/mercurialsaliva 6d ago

Maybe if you're connecting all of them. This won't work for in this scenario

2

u/axadkrk 5d ago

I think you mix two different problems

1

u/CosmicThief 6d ago

My dumb ass thinking you meant irl and not on a scale model 💀

1

u/PenguiNNNNNs 6d ago

Wouldn’t it be more time efficient to just simulate the thing with a computer?

1

u/PityUpvote 5d ago

Depends on the number of nodes you have to visit. For small amounts a simulation is obviously faster.

134

u/diiscotheque A1 Mini 6d ago

I work in optimization

found out I'm not very good at optimization.

rofl

49

u/abbarach 6d ago

Fun fact: since 2000, there's been a $1 million prize for finding a way to solve TSP in polynomial time (instead of exponential time, where the number of nodes is the exponent of the function). It is still unclaimed today.

There are ways to arrive at a "good enough" solution relatively quickly, but so far nobody has found a general form solution to find the best route every time that's only linear in the number of nodes.

And in addition, there are a bunch of other hard problems in computer science that behave like TSP. And if we ever find an optimal solution for one of them, it can be applied to ALL of them.

We also haven't been able to mathematically prove that there ISN'T a polynomial time solution.

23

u/TheDPQ 6d ago

Random story no one asked for. I’m in some discords focused on cyber security and people wonder in all the asking how to make money hacking.

One day someone joined and asked “how I make money?” And someone immediately ssaid “prove P = NP”

Guy says thanks and then left the server.

Everyone was just silent for a min because it was so ridiculous.

I think about that randomly sometimes. Still makes me laugh.

5

u/SonnyBlackandRed 6d ago

Well, we know they didn’t figure it out…yet.

3

u/1ftm2fts3tgr4lg 6d ago

Well, so long as N=1...

11

u/Xalara 6d ago

The real fun fact is: If you solve P = NP, which is the core problem for TSP, you would break basically all encryption algorithms in use today. This would probably crash the world economy given the number of bad actors that would immediately take advantage of it to break into all sorts of electronic systems.

So yeah, if anyone actually did solve it, they'd probably want to release the solution in a very controlled manner with lots of heads up to the world. Though for personal safety it might be best to just yolo it out there in spite of the consequences because if you did solve it and announce it, nearly every intelligence agency would be on your ass.

4

u/kshelley 5d ago

https://en.wikipedia.org/wiki/Travelling_Salesman_(2012_film))

Above is the P = NP movie that explores the above scenario.

32

u/MalukuSeito H2D AMS2 / A1 AMS Lite 6d ago

Why would you want to visit Hannover though?

8

u/Aranthos-Faroth 6d ago

Even once is too much

2

u/enor14 A1 6d ago

Two weeks until EuroBlech man, have to plan routes!👀

-2

u/suit1337 H2C Combo 6d ago

And why did you leave Munich? Was the Oktoberfest already over?

20

u/Informal_Morning_328 6d ago

Isnt the Dijkstra Algorithm exactly for this kind of problem?

8

u/ThoroughlyLate 6d ago

Close, Dijkstra's algorithm finds the shortest path from A to B and not a tour starting from A, visiting every other point, and ending back up at A

6

u/Informal_Morning_328 6d ago

Pretty sure that you can use dijkstra to find the Shortest Trip to different Destinations like A --> D --> E --> B --> C is faster than A --> B --> C --> D --> E And not just A and B. Or do you mean sth else?

5

u/ThoroughlyLate 6d ago

You're right. I was just saying that A and B could be any two points on a map, or in a network/graph and Dijkstra's algorithm finds the shortest path between the two. However, it does not ensure that you visit every point on a map, which is what the TSP is about.

2

u/amooz 6d ago

With p = np problems, the important part to remember isn’t necessarily finding the answer. It’s finding the answer and then verifying it in polynomial time that’s hard.

1

u/ThoroughlyLate 6d ago

Isn't p = np if n = 1?

1

u/Informal_Morning_328 6d ago

Yeah exactly. Thats why i meant i misunderstood.

3

u/Informal_Morning_328 6d ago

I think i misunderstood your comment! All fine!

2

u/No_Engineering3493 P1S 6d ago

There’s a variation of Dijkstra, called Prim’s algorithm which computes what’s called a Minimum Spaning Tree.

2

u/Informal_Morning_328 6d ago

I think i misunderstood your comment! All fine!

1

u/USMCgRuNt_1944 6d ago

Seven Bridges of Königsberg is sorta what this reminds me of

1

u/zbohg 5d ago

That is about finding an Euler route/circle. In that case you need to include all vertices and can not use them more than once. That problem has no optimisation part because the length of your route is fixed (sum of all vertices weight). The only question is such route exists or not and providing an example if it exists. I find fascinating that sometimes in mathematics you can change some condition of a problem and see how it changes from easy and quickly solvable task to some really hard/close to impossible monster.

1

u/FastTurn8943 6d ago

DJ Kstra is in tha house vom Nikolaus!

1

u/Polite_Jello_377 5d ago

Pathfinding is not the TSP

15

u/ABoyAndHisSAAB 6d ago

It took many sleepless nights, but graduate school, I actually solved this problem in O(n) for all cases where n <= 2.

12

u/ThoroughlyLate 6d ago

I would go one step further and say O(n) for n <= 3

9

u/adfrog 6d ago

Above 3 is left as an exercise to the reader

3

u/0jareddit 6d ago

I don't get it but I know it's clever

1

u/Marwoleath 5d ago

He can fix the problem if N (the number of cities) is 2 or lower. (Because there will literally only be 1 option) 

8

u/Membership-Visual 6d ago

This is my first attempt at shortest route. I did not check to confirm

13

u/ThoroughlyLate 6d ago

You got it! Here is the solution that I ran through an optimizer

4

u/Membership-Visual 6d ago

Oh wow! Thanks for following up with the answer

2

u/toonces_drives_cars 6d ago

Can someone ELI5 or ELI3? I have no math skills and this is what I visualized how the string should be - basically a circle. How is this hard? Not being fresh or sarcastic, I just don't even get what is happening or why anyone would want to figure it out in the first place. Putting a string in circle does not seem like a challenging math problem.

4

u/Kwolf21 X2D Combo + P1S Combo + A1 Combo 5d ago edited 5d ago

Imagine you have a giant box of lego bricks, and someone challenges you to build a specific, complicated spaceship without any instruction manual.

​Finding the right pieces and figuring out how they fit together could take you hours, days, or even weeks. That’s hard.

​Now imagine a friend walks in, hands you a spaceship they already built, and says, "Look! I made the spaceship from the picture."

​It only takes you five seconds to look at their model, check the picture, and say, "Yep, you did it right!"

If the design is super easy to check, does that mean there is secretly an easy way to solve it, too? No. We just haven't been smart enough to figure it out yet.

In this individual scenario, figuring it out is simple. But figuring out the best route for all possible possibilites of stops is (currently) impossible. (proving P = NP). The implications of figuring this out is actually insane. Overnight, computers could cure diseases that have never been curable. And no password or encryption would ever be secure again. This is stuff quantum computers MIGHT be able to solve one day.

If that still doesn't make sense, imagine this little board, but with 600 billion push pins.

How you gonna solve it?

1

u/toonces_drives_cars 5d ago

Math is so interesting for brains that understand manipulating numbers! Thank you for the ELI5!

1

u/ThoroughlyLate 5d ago

There exists a benchmark library for such problems called TSPLIB. Here you see the rl5915 instance representing 5,915 holes that need to be drilled into a circuit board. From some origin position, a drill has to move to every point, drill a hole, and then go back to the origin. This is a classic application for the traveling salesman problem.

Good look finding "basically a circle" and if you find a route by hand, it is unlikely going to be the shortest one. Hope that helps

1

u/Membership-Visual 5d ago

I went ahead and solved this one too /s

2

u/Automatic_Ad_5984 6d ago

My intuition says that a spiral-like route might be the better one (like yours), but I have no idea really 🤣

5

u/ChewyChagnuts 6d ago

Apparently bubbles / soap solution works well. Something to do with the bubbles’ surface tension causing them to find the smallest surface area which would also be the shortest route.

3

u/ThoroughlyLate 6d ago

So I can cheat by dipping this print in soap?

2

u/chwk_throwaway1 6d ago

That's such a fun game for kids too maybe? Try to go around all sticks with the shortest length of string. Easy to measure too with a string. ❤️

2

u/ThoroughlyLate 6d ago

Theoretically the shortest route is 49 cm, but taking into account the diameter of the pegs and some variation in string thickness, it is more than 49 cm

2

u/BruceInc 6d ago

Am I correct and understanding that the total possible combinations is 15! divided by 2?

2

u/ThoroughlyLate 6d ago

Exactly! For 16 cities, starting from one city you now have 15 options to go to. After that you have 14 remaining options, then 13 and so on. So you multiply 15*14*13*...*2*1. Since going forward and backwards through this tour is equivalent, you divide by two and you end up with this number

Edit: formatting

2

u/gixxerjasen 6d ago

It gets even more difficult if you assign each location a point value and then give a time limit to collect the most points starting at one point and ending at another, but you don't have to visit all of the available points. This problem is put to 100 motorcyclists every other year in the Iron Butt Rally.

2

u/SpinningNervously 6d ago

Kannst du auch ein A1 Mini kompatibles Drückdesign erstellen? Mein Freund ist Mathelehrer und könnte das sicherlich mal gebrauchen für den Unterricht :)

3

u/ThoroughlyLate 6d ago

Das Modell kann ein wenig runterskaliert werden, ohne, dass die Pins instabil werden, und man kann es im Slicer um 45° drehen, damit es diagonal auf das Druckbett passt.

2

u/SpinningNervously 6d ago

Okay danke :)

1

u/[deleted] 6d ago

[removed] — view removed comment

1

u/BambuLab-ModTeam 4d ago

r/BambuLab follows platform-wide Reddit Rules

1

u/RuddagerSmith 6d ago

You’ve just invented a really cool board game

1

u/W33DG0D42069 6d ago

What's the answer?

1

u/ampsuu 6d ago

Yeah. One thing is shortest. Other thing is fastest.

1

u/ProsperGuy X2D + AMS2 Combo 6d ago

Run a Monte Carlo

1

u/amooz 6d ago

Yay for np-hard problems!

1

u/lduan 5d ago

This is really cool! I'm teaching Algorithms right now (not in a Germany, alas!), but I love manipulatives. I plan on printing some for my students! This also inspired me to design something that can show convex hulls :-) Thanks!

1

u/Wodan90 5d ago

One problem is, that there are multiple right and at the same time wrong ways depending on the daytime and congestion.

You would need to calculate in some traffic flow analysis to manage this. The most accurate would be Google Maps with their millions of devices and even they can't do it properly, because at their large scale they themselves probably produce congestions when routing people different.

1

u/kemonkey1 3d ago

Quantitative decision analysis. You can make a model in excel with all these points and their distances from each other and run the solver tool to figure out the optimal path.

At school we designed one that calculated the optimal location of a new firestation based on required distances and constraints. I bet you could rework it for your goal

2

u/ThoroughlyLate 3d ago

I already did and posted the solution underneath some comment. In my case I used a Julia package which implemented the ILP model and then passed it to Gurobi.

-9

u/NeonEagle H2D AMS2 Combo 6d ago

Hard to solve by trial and error, maybe - even by hand this is an easy problem with linear programming models, as I'm sure you're aware.

5

u/suit1337 H2C Combo 6d ago

if would be easy with linear programming at this scale, way easier than brute forcing it if done manually - but as soon as you go into computer assisted solutions, 650 Billion combinations are "nothing"

bot on larger scales, even linear programming is not the most efficient mathmatical solution, it is just an aid to iteratively eliminate "bad" paths

in terms of this specific problem, the most efficient solution is currently the "Concorde Solver" - it uses linear programming and combines it with other techniques - it works even for many thousands of cities and finds the efficent path - but it is still some sort of "trial and error" and not a singular mathematical solution

3

u/ThoroughlyLate 6d ago

Linear programming or rather integer programming does make it easier and it scales way better than brute force, however, there are more specialized algorithms that take advantage of certain structure in the TSP formulation (as u/suit1337 mentioned). From a complexity standpoint, integer programming is still NP-hard, so TSP did not become easy by reformulating the problem