TSP Algorithm

Designed and implemented classical TSP algorithms (Heldโ€“Karp, MST, Greedy) and a novel MCMF-based heuristic.



๐Ÿ’ฌ Thoughts

The most fun part of this project was coming up with my own algorithm instead of just using an existing one. I used MCMF to get a global structure and layered 2-opt on top to improve the tour quality โ€” it didnโ€™t feel like I was just solving a homework problem, it actually felt like I was solving a problem.

I always knew TSP was NP-hard, but running an exact algorithm like Held-Karp myself really hit it home. Now I get why people obsess over polynomial time โ€” with exponential time, just increasing the number of cities a bit makes the whole thing blow up. It made me realize why algorithm research actually matters.

At first, I naรฏvely thought Held-Karp would run fine for something like 200 cities. I let it run, waitedโ€ฆ and it never finished. Then I realized 2^200 is an insane number. I even asked GPT if my code had a bug, and it politely roasted me saying thereโ€™s no bug โ€” itโ€™s just that even if you had all the computers in the universe, it still wouldnโ€™t finish. That was humbling.

The most surprising part? Problems like Mona Lisa 100K are still being worked on. I thought these had all been solved ages ago, but people are still out there breaking records and trying new ideas. Itโ€™s wild and kind of inspiring that thereโ€™s still progress being made on such a classic problem.

That said, I wasnโ€™t really happy with my final results. I ran into unexpected issues and had to force 2-opt in just to get something that worked. I didnโ€™t love that, but it was already too late to start over, so I just rolled with it. Still, the project felt different from typical assignments โ€” I got to design something of my own and compare it head-to-head with existing algorithms. That part was really cool.


๐Ÿ’ฌ ๋А๋‚€ ์ 

์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์—์„œ ์ œ์ผ ์žฌ๋ฐŒ์—ˆ๋˜ ๊ฑด, ๊ทธ๋ƒฅ ์žˆ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์“ฐ๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ์ง์ ‘ ์•„์ด๋””์–ด ์งœ์„œ ๊ตฌํ˜„ํ•ด๋ดค๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. MCMF๋กœ ์ „์ฒด ํ๋ฆ„ ์žก๊ณ , ๊ทธ ์œ„์— 2-opt ๋ถ™์—ฌ์„œ ํˆฌ์–ด ํ’ˆ์งˆ ๋†’์ด๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•ด๋ดค๋Š”๋ฐ, ๋‹จ์ˆœํžˆ ๊ณผ์ œ ํ‘ธ๋Š” ๋А๋‚Œ์ด ์•„๋‹ˆ๋ผ์„œ ์žฌ๋ฐŒ์—ˆ๋‹ค.

TSP๊ฐ€ NP-hardํ•˜๋‹ค๋Š” ๊ฑด ์•Œ๊ณ ๋Š” ์žˆ์—ˆ๋Š”๋ฐ, Held-Karp ๊ฐ™์€ ์ •ํ™•ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ง์ ‘ ๋Œ๋ ค๋ณด๋‹ˆ๊นŒ ๊นœ์ง ๋†€๋ž๋‹ค. ์™œ๊ทธ๋ ‡๊ฒŒ Polynomial Time์— ํ™˜์žฅํ•˜๋Š”์ง€ ์•Œ ๊ฒƒ ๊ฐ™๋‹ค. ์ง€์ˆ˜์‹œ๊ฐ„์ด ๋˜๋‹ˆ๊นŒ ๋„์‹œ ์ˆ˜ ์กฐ๊ธˆ๋งŒ ๋Š˜์–ด๋‚˜๋„ ๊ฐ๋‹น ์•ˆ ๋˜๋Š” ๊ฑธ ๋ณด๋ฉด์„œ ์‹ค์ œ๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์™œ ์—ฐ๊ตฌํ•˜๋Š”์ง€ ๋А๋ผ๊ฒŒ ๋˜์—ˆ๋‹ค.

์‚ฌ์‹ค ์ฒ˜์Œ์— Held-Karp๋„ 200์งœ๋ฆฌ๋Š” ๋Œ์•„๊ฐˆ์ค„์•Œ๊ณ  ๋Œ๋ ธ๋Š”๋ฐ ์•ˆ๋๋‚˜๊ธธ๋ž˜ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ๊นŒ, 2^200์€ ์—„์ฒญ๋‚œ ์ˆซ์ž์˜€๋‹ค. ์ƒ๊ฐ์—†์ด ๋Œ๋ฆฌ๊ณ  GPTํ•œํ…Œ ์ฝ”๋“œ ์˜ค๋ฅ˜์žˆ๋ƒ๊ณ  ๋ฌผ์–ด๋ดค๋Š”๋ฐ, ์˜ค๋ฅ˜ ์—†๊ณ , 2^200์€ ์šฐ์ฃผ์— ์žˆ๋Š” ๋ชจ๋“  ์ปดํ“จํ„ฐ ๊ฐ€์ ธ์™€์„œ ๋Œ๋ ค๋„ ์•ˆ๋๋‚œ๋‹ค๊ณ  ๋‚˜ํ•œํ…Œ ๊ผฝ์„ ์ค˜์„œ ์ชฝํŒ”๋ ธ๋‹ค.

์ œ์ผ ์ธ์ƒ ๊นŠ์—ˆ๋˜ ๊ฑด, ๋ชจ๋‚˜๋ฆฌ์ž 100K์ฒ˜๋Ÿผ ์—„์ฒญ ์˜ค๋ž˜๋œ TSP ๋ฌธ์ œ๋“ค๋„ ์•„์ง๋„ ์‚ฌ๋žŒ๋“ค์ด ๋” ์ข‹์€ ํ•ด๋‹ต ์ฐพ์œผ๋ ค๊ณ  ๋…ธ๋ ฅํ•˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋ฏธ ๋‹ค ์—ฐ๊ตฌ๋์„ ์ค„ ์•Œ์•˜๋Š”๋ฐ, ์—ฌ์ „ํžˆ ๊ธฐ๋ก์ด ๊นจ์ง€๊ณ  ์žˆ๋‹ค๋Š” ๊ฒŒ ๋†€๋ผ์› ๊ณ , ๊ณ„์† ๋ˆ„๊ตฐ๊ฐ€๋Š” ๋…ธ๋ ฅํ•˜๋Š”๊ฒŒ ๋ฉ‹์กŒ๋‹ค.

๊ทผ๋ฐ ๊ฒฐ๊ณผ๊ฐ€ ๋„ˆ๋ฌด ๋ณ„๋กœ์˜€๊ณ , ์ƒ๊ฐ ์™ธ์˜ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ด์„œ ์–ต์ง€๋กœ 2-opt ๋ผ์›Œ์„œ ์ข€ ๋ง˜์— ์•ˆ๋“ค์—ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋„์ €ํžˆ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ƒ๊ฐํ•˜๊ธฐ์—๋Š” ๋Šฆ์–ด์„œ ๊ณ„์† ํ–ˆ๋˜ ๊ฒƒ ๊ฐ™๋‹ค. ํ‰๋ฒ”ํ•œ ๊ณผ์ œ ๋А๋‚Œ์ด ์•„๋‹ˆ๋ผ ๋‚˜๋งŒ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋งŒ๋“ค๊ณ  ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜๊ณผ ์„ฑ๋Šฅ๋น„๊ต๋ฅผ ํ•ด๋ณด๋Š”๊ฒŒ ์ƒ‰๋‹ฌ๋ผ์„œ ์žฌ๋ฐŒ์—ˆ๋‹ค.