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 ๋ผ์์ ์ข ๋ง์ ์๋ค์๋ค. ํ์ง๋ง ๋์ ํ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์๊ฐํ๊ธฐ์๋ ๋ฆ์ด์ ๊ณ์ ํ๋ ๊ฒ ๊ฐ๋ค. ํ๋ฒํ ๊ณผ์ ๋๋์ด ์๋๋ผ ๋๋ง์ ์๊ณ ๋ฆฌ์ฆ์ ๋ง๋ค๊ณ ์ด๋ฏธ ์กด์ฌํ๋ ์๊ณ ๋ฆฌ์ฆ๊ณผ ์ฑ๋ฅ๋น๊ต๋ฅผ ํด๋ณด๋๊ฒ ์๋ฌ๋ผ์ ์ฌ๋ฐ์๋ค.