Traveling Salesman Problem Visualization

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024
  • Visually compares Greedy, Local Search, and Simulated Annealing strategies for addressing the Traveling Salesman problem.
    Thanks to the Discrete Optimization course on Coursera by Pascal Van Hentenryck for teaching me about this! www.coursera.o...
    Read more in this blog post: popcyclical.com...
    Update:
    PBS's NOVA features this animation in Einstein's Quantum Riddle. Watch at 34:35 www.pbs.org/wg...
    Sources:
    City coordinates: www.geonames.or...
    US Map: commons.wikimed...
    Music: / clearly-opaque

Комментарии • 186

  • @Chris_t0
    @Chris_t0 9 лет назад +431

    Love how the music speeds up when the code is in action, it actually makes it enjoyable and not a bunch of boring moving lines.

  • @patanypang
    @patanypang 9 лет назад +310

    the background music make it looks extra cool

  • @Cscuile
    @Cscuile 4 года назад +46

    I always come back to this video due to the sheer amount of beauty it contains.

  • @Kurchack
    @Kurchack 10 лет назад +160

    I first watched it to understand methods of solving TSP. Then I watched it 4 more times because it's so optically pleasing.

  • @sindorei
    @sindorei 5 лет назад +6

    I watched this 2 or 3 years ago. Now, I am here again.
    Great video! Visualization and your choice of music make me watch this over and over again.

  • @astarothgr
    @astarothgr 6 лет назад +3

    This is the absolute best TL;DW (too long, didn't watch) video for anybody looking for a quick intro into what is local search. Great work!

  • @noxiouspro
    @noxiouspro 10 лет назад +19

    This isn't just a good visualization but also a good production video.
    Thus it's might invite more audience into the field.

    • @bodenseeboys
      @bodenseeboys 5 лет назад

      'Thus it's might invite' - that gave me cancer

    • @ziq1450
      @ziq1450 4 года назад

      I like science, so you are correct in saying it might invite more people into the field, because it worked for me.

    • @ghaith81981
      @ghaith81981 3 года назад

      ruclips.net/video/gm0Nc4wPJZI/видео.html

  • @Cscuile
    @Cscuile 6 лет назад +4

    This is the most beautiful algorithm video I have seen on youtube.

  • @insaneviruss
    @insaneviruss 9 лет назад +10

    Finally a video that explains the core logic so easily, thanks a tonn!

  • @Playncooler
    @Playncooler 7 лет назад +91

    Man, travelling salesmen are smarter nowadays...

  • @philipwells7149
    @philipwells7149 10 лет назад +15

    Oh this is so beautiful. Thanks for making this video!

  • @decepticon1SB
    @decepticon1SB 5 месяцев назад +1

    best visualization I've seen on TSP

  • @littlelilly7480
    @littlelilly7480 Месяц назад

    These kind of video are actual motivation to get into the stuff

  • @ChairmanMo
    @ChairmanMo Год назад +1

    If you ever played Galactic Civilizations 3, you have to deal with this problem too when you start to set up your Hypergate networks. Thanks for the suggestions about moving the edges. That will help!

  • @billpetrak
    @billpetrak 3 года назад +1

    I can't believe my ears! Is this post rock music in an algorithm video I hear? Had to watch multiple times. It made my day! Now if only every piece of information was accessible through a video like this. :/

    • @ghaith81981
      @ghaith81981 3 года назад

      Have a look if you like this video
      ruclips.net/video/uUOd5dJTR7E/видео.html

  • @WhiteDragon103
    @WhiteDragon103 2 года назад +1

    An idea I had for the travelling salesman problem (when the points are in some euclidean space):
    1) Enclose the smallest possible convex hull around all of the points.
    2) For each point not on the edge of the current hull, pick the one that is closest to the hull (or, that would increase the length of the path the least if inserted into the closest hull edge).
    3) Bend the hull to include that point. The point would be inserted between the two points already in the hull forming the edge that it is closest to.
    4) Go to step 2 until there are no points left not part of the hull.
    For added precision, you could enumerate through all of the first N possible vertex insertions and use the combination of insertions that results in the shortest path. The above algorithm assumes N == 1.
    I just tried doing this manually in MS Paint and it seems to work pretty well. I got almost the same result you did at 1:17 (though I did eyeball it).

    • @poprhythm
      @poprhythm  2 года назад +2

      This seems like a good optimization for these kind of special cases - perhaps very similar to this: www.sciencedirect.com/science/article/abs/pii/0020019096001251?via%3Dihub

    • @WhiteDragon103
      @WhiteDragon103 2 года назад

      @@poprhythm Thanks, I'll have to read it ::}

  • @arctan-k
    @arctan-k Год назад +1

    One of the sub problems that i had in my dimploma project duting my bacholer's involed this problem. I solved it using two methods: integer programming and genetic algorithms. It was so fun and exciting. I'm so eager to learn more math during my master's.

    • @arctan-k
      @arctan-k Год назад +1

      Also, I researched local neighborhood search and big neighborhood search. I was also thinking about applying neural networks, but it was too difficult for me

  • @_motho_
    @_motho_ 5 лет назад

    the drums are like routes connecting and colliding with eachother. i like it

  • @yogi799
    @yogi799 9 лет назад +5

    What a magnificent way of explaining these concepts, thank you!

  • @DaRKtWiSTeR1000
    @DaRKtWiSTeR1000 10 лет назад +1

    This video is very fascinating. I appreciate it because on a real simple way, i.e. visualization, it provides the core of the TSP.
    But it contains a little mistake though.
    If the quantity of possible routes is calculated with (n-1)!
    with n:= number of cities then for 304 the solution should be about 8,43*10^(621)
    ____________________________________________________________
    "Wenn Null besonders groß ist, ist es beinahe so groß wie ein bisschen Eins. Tadeln ist leicht, deshalb tun es so viele; mit Verstand loben ist schwer, darum versuchen es so wenige." (Anselm Feuerbach)

  • @JonDotExe
    @JonDotExe 3 года назад

    Love it! These are the types of visualizations we need to get people into mathematics. So much easier to understand than a dude at a white board

  • @emperorlelouch5696
    @emperorlelouch5696 4 года назад +1

    Wow, it's so intense and difficult that there had to be epic music to accompany it

  • @nabilaabrak5738
    @nabilaabrak5738 8 лет назад

    What an impressive approach of the problem. It's clear, and the video is so cool.

  • @freshdesignbe-to-ce3070
    @freshdesignbe-to-ce3070 10 месяцев назад

    Good visualization of the salesman problem. Thanks!

  • @PaulBorn-m2h
    @PaulBorn-m2h Год назад

    I agree with the others...I'm a techie and route planning solver...this helps me when explaining to customers

  • @Randomperson-by1eg
    @Randomperson-by1eg 8 лет назад +31

    2.3*10^624 possibility? That is 10^544 times more than atoms in observable universe

    • @thomaselder4076
      @thomaselder4076 8 лет назад +14

      +Oktay So, like....a lot?

    • @dorukayhanwastaken
      @dorukayhanwastaken 7 лет назад +12

      Random Person That there is why combinatorics is hard - not because the algorithms and formulas are complex but because the resulting numbers are so large you can't store them in any naïve format.

    • @connorskudlarek8598
      @connorskudlarek8598 6 лет назад +7

      Thomas,
      Well, if you took every particle in the universe (about 10^80), made a quadrillion duplicates, then duplicated all of your new particles and old particles a quadrillion times, and did it again, and again, and again, and again, and again, and again, you still wouldn't have even close to that number (you'd have 10^200). You wouldn't even be in the ballpark.
      But this doesn't even remotely compare to all the possible arrangements of every particle in the universe, which is absolutely monstrously large. If you duplicated every particle in the universe a quadrillion times every second until the universe died, you would not have reached a number of particles that was even close to the number of possible arrangements of every particle in our universe.
      Every arrangement is something like 10^(10^80), that is 10 to the power of 1 followed by 10^80 zeroes. The number you'd get duplicating particles a quadrillion times per second to the end of the universe is a mere 10^(10^20) if you assume the universe will live for 100 trillion years.

    • @MrAntiKnowledge
      @MrAntiKnowledge 6 лет назад +8

      Can't explain/calculate something with 100% accuracy? Goddidit

    • @apostolismoschopoulos1876
      @apostolismoschopoulos1876 6 лет назад

      Thta's why we have to find a new algorthim that shortens the avaible routes

  • @LEARNWITHPANDA
    @LEARNWITHPANDA 4 года назад

    very cool video on travelling salesman problem. Interesting visualization.

  • @therkoth
    @therkoth 10 лет назад +1

    Cool! Now do one on vertex cover focused on internet infrastructure! ;)
    I remember having a blast coding heuristics to find suboptimal solutions in the uni.
    Really enjoyed the video.

  • @SirCutRy
    @SirCutRy 9 лет назад +3

    Awesome visualization!

  • @yesamd3169
    @yesamd3169 8 лет назад +5

    love the music

  • @wahyuagungsugimartanto3340
    @wahyuagungsugimartanto3340 6 лет назад

    I loved the music, it just plain awesome

  • @sanyamjain7229
    @sanyamjain7229 9 лет назад +4

    Hey. What softwares did it take to build such kind of beautiful simulation ?

    • @poprhythm
      @poprhythm  8 лет назад +4

      +Sanyam Jain Hey thanks! Here's a blog article on how I made it popcyclical.com/2013/08/19/TravelingSalesmanProblemVisualization.aspx

  • @alan2here
    @alan2here 5 лет назад +7

    More visualising algorithms videos please :)
    How about 2D sorts, these are on a 2D grid and the numbers must decrease downwards as well as rightwards.

    • @ghaith81981
      @ghaith81981 3 года назад

      ruclips.net/video/gm0Nc4wPJZI/видео.html

  • @Chaoswarrior3489
    @Chaoswarrior3489 8 лет назад +5

    As a CS nerd, I love the visualisation. Any way I can purchase a copy of the song?

    • @poprhythm
      @poprhythm  8 лет назад +4

      +Chaoswarrior3489 Thank you very much! I've enabled downloads for the song here soundcloud.com/poprhythm/clearly-opaque

  • @notabailabe97
    @notabailabe97 10 лет назад

    Excelent video on an famous algorithm.

  • @zhanglg921
    @zhanglg921 9 лет назад +1

    Awesome. Thanks for sharing the video.

  • @rajenderkumar5351
    @rajenderkumar5351 8 лет назад +17

    its awesome

  • @gredangeo
    @gredangeo 6 лет назад

    The general consensus I'm getting is, travel in a circle that makes your last point nearest to your starting point, and don't cross lines.

  • @fanz4088
    @fanz4088 4 года назад +2

    Thanks! Really appreciate your work! May I cite your work in my presentation? Please let me know how can I properly cite it!

  • @ringyring
    @ringyring 3 года назад +1

    It's beautiful, but please don't change the number of vertices from one demonstration to the next. This confuses the viewer as to whether the final result is truly optimal.
    I thought the last result is sub-optimal, because it didn't look like the one you showed previously, which was actually for a smaller number of cities.

    • @studmath
      @studmath 2 года назад

      Maybe it's shorter, I could run it according to my algorithm

  • @Blacksoul444
    @Blacksoul444 7 лет назад +6

    0:16, greedy-algo is taking the next closest point? but as he connects the first 8 points, the 7th is more far away from the 6th than the 8th from the 6th, isn't it? :D Aynway, really cool video!

    • @poprhythm
      @poprhythm  7 лет назад +5

      I think you're right! I had chosen the top 8 locations from the population data I had found. The distances were calculated naively based on their lat/long coordinates. Either the calculations for Chicago->New York and Chicago->Philadelphia somehow put them opposite closeness, or I fudged it somehow . Not sure now, but Philadelphia is definitely a little closer!

    • @Centauri902
      @Centauri902 7 лет назад +8

      Curvature of the earth plays with flat maps a bit.

    • @Twas-RightHere
      @Twas-RightHere 7 лет назад +3

      I would guess the points are closer in reality, but the flat projection of the US makes it appear different.

    • @No3xx
      @No3xx 6 лет назад +1

      It would be easier if the edges show their weights/distances.

  • @taFBackwards
    @taFBackwards 8 лет назад +2

    Hey there, this is a very interesting algorythm; I just would like to ask what background music are you using for this video?

    • @poprhythm
      @poprhythm  8 лет назад +7

      +Fatbackwards I agree, it's really interesting to think about optimizations for large problem sizes such as this! I wrote the music using software synthesizers and lots of arpeggiators :) Here is a link to the soundcloud of the song soundcloud.com/poprhythm/clearly-opaque

  • @synony6
    @synony6 7 лет назад +1

    So good. Very impressed

  • @chasyen5945
    @chasyen5945 7 лет назад +1

    so beautiful. thank you

  • @Chaosfury50
    @Chaosfury50 5 лет назад +3

    I thought this would be another foreign indian common chintzy explanation but the visualization actually really hit home for me and I immediately left my life, my marriage, even my chemo treatments and now reside in a corner of the Atlantic ocean in a perfectly cubed and sealed floating room, bobbing with the waves. People are free to continue visiting me with well wishes and to see all the progress I've made and get a copy of the book I have written until now (I do enjoy the challenge of having to completely rewrite it back to get to my spot and continue).

  • @MiguelBacaoco
    @MiguelBacaoco 9 лет назад +1

    great music!

  • @hartake6667
    @hartake6667 8 лет назад +2

    This woke me up - literally :D

  • @likeyou3317
    @likeyou3317 5 лет назад

    Love the visualization

  • @yilmazaliyy
    @yilmazaliyy 7 лет назад +1

    great job, thanks for sharing

  • @BubbaYoga
    @BubbaYoga 9 лет назад +1

    Very well done!

  • @SURYATEJA96
    @SURYATEJA96 4 года назад

    how were you able to make the simulation? can you tell us what software/application you have used for the same?

  • @toussaint_bank
    @toussaint_bank 7 лет назад

    This was very nice. Thanks

  • @shivakumarcd
    @shivakumarcd 9 лет назад

    this music while solving Rubik's cube would be more thrilling ... ;-)

  • @vector8934
    @vector8934 5 лет назад

    In what computer science course do we learn about the Traveling Salesman Problem, the Post Correspondence Problem, etc..?

  • @markjoe664
    @markjoe664 3 года назад +1

    Ill use it to visit US thank you

  • @linowmik
    @linowmik 5 лет назад

    very nice video

  • @MRlinkinpark12
    @MRlinkinpark12 7 лет назад +1

    I love it man!

  • @hyperrealhank
    @hyperrealhank 9 лет назад +1

    fantastic!

  • @mrkinetic
    @mrkinetic 6 лет назад +1

    Would it be more accurate to use a brute force algorithm? Iterate over each possible route, and throw away the previous route if the the current one is shorter?

    • @poprhythm
      @poprhythm  6 лет назад +3

      Certainly! This will work fine for a small number of cities to test. However, as the number of cities grows, the number of possible solutions increases with a factorial amount - the time needed to check all of these grows from hours to days to years. There are optimizations (for instance, branch and bound - don't even consider a set of solutions unlikely to yield better result), but even then, the possible considered solutions can be quite large. Read more here: en.wikipedia.org/wiki/Travelling_salesman_problem#Exact_algorithms

  • @maxniebs2174
    @maxniebs2174 7 лет назад +1

    I love the little 7!

  • @thetruereality2
    @thetruereality2 5 лет назад +1

    Why do you choose different vertices in different algorithms?

    • @poprhythm
      @poprhythm  5 лет назад

      Good question. Each set of vertices is a subset of the next - they're US cities sorted by population in descending order. I used the different numbers of these cities to illustrate the strengths (and weaknesses) of the techniques. For instance, it'd be harder to visually see the local minimum demonstrated in the local search section with the 300 vertices used in the simulated annealing section. Likewise, the apparent chaos resolving to a solution in simulated annealing wouldn't be quite as captivating with the 30 vertices used in local search.

  • @deeplearningpartnership
    @deeplearningpartnership 4 года назад

    Fantastic.

    • @ghaith81981
      @ghaith81981 3 года назад

      Have a look if you like this video
      ruclips.net/video/uUOd5dJTR7E/видео.html

  • @dsc5085
    @dsc5085 6 лет назад

    Simulated annealing seems like it would make a good approximation algorithm

  • @willjadsonevania9787
    @willjadsonevania9787 11 месяцев назад

    teacher I developed a heuristic and would like to share it. My heuristic uses topology and concentric circles. What do you think?.

  • @weichenghe
    @weichenghe 8 лет назад

    It helps a lot, thanks

  • @MrDavePed
    @MrDavePed 8 лет назад

    I have an idea for finding the optimal route consistently, a new approach, a new algorithm. How would I get it to work like your video? I'm not a programmer. Is there software to do this? If not would you be willing to consider writing it if I describe it to you?
    Thank you.
    ..

    • @poprhythm
      @poprhythm  8 лет назад

      +Dave Ped There exist some toolkits for tinkering with optimization algorithms such as this. I'm not very familiar with them - this one came up in a google search, and it contains a TSP function optalgtoolkit.sourceforge.net/

    • @MrDavePed
      @MrDavePed 8 лет назад

      +poprhythm Thank you. I need a nerd to check out my idea. I'm not nerd enough to do this. I just come up with ideas. I understand most people's ideas are not worth pursuing so if you want me to describe it in detail first, no obligations, fine I can do that. Thanks.

  • @alexanderstrada2933
    @alexanderstrada2933 8 лет назад

    Doesn't the order of the swapping affect the outcome? You say to select edges at random for the swap, but I'm assuming you're actually comparing every edge to every other edge once, right? (Otherwise, how do you know when to stop?) So, if you go through the whole thing once, wouldn't going through it again produce further changes? As other parts of the route switch around, the changed distance between each edge also varies, no?

    • @poprhythm
      @poprhythm  8 лет назад

      Hi! You might be interested in reading this more detailed look into the 2-opt swap mechanism : en.wikipedia.org/wiki/2-opt . You've hinted at the underlying problem - how do you know when to stop? For non-trivial optimization problems, you're often faced with accepting a "very good" solution as opposed to the optimal - simply because the search space for larger problems becomes astronomically large. Like hundreds of years on modern hardware large. So using a heuristic-based search to find good solutions in a reasonable amount of time is currently our best bet.

    • @grossteilfahrer
      @grossteilfahrer 6 лет назад

      ...which is why sometimes your car navigator will take a different route between the same adresses.

  • @dillonl6324
    @dillonl6324 7 лет назад

    What if you split the area into quadrants and then connected them? You could also use a rotating axis that finds the 4 most optimal quadrants and then it syncs them. This 2-opt swap just ends up making a giant trace around the outside of the area; no more clever than connect the dots.

    • @poprhythm
      @poprhythm  7 лет назад

      Yes! If you have prior knowledge about likely patterns in your data then you can potentially reduce the problem size by many factors. This visualization only demonstrates for the generic case. If this problem were being addressed for real, a likely optimization would be to cluster all the metropolitan areas together and solve those discretely, then add them back into the complete solution by removing the "interior" nodes. These problems are fun to think about - especially how additional/alternate optimizations might make make it faster!

  • @adnanbehrem9651
    @adnanbehrem9651 3 года назад +1

    More videos pls

  • @SantiagoGonzalez-wy4vx
    @SantiagoGonzalez-wy4vx 7 лет назад

    So cool!

  • @Nidhichirania02
    @Nidhichirania02 5 лет назад

    How did you get the visual representation?

  • @ahmidahmid9303
    @ahmidahmid9303 5 лет назад

    this video is motivating

  • @vibe_wit_y
    @vibe_wit_y 7 лет назад +1

    amazing

  • @weeva6390
    @weeva6390 4 года назад

    I Luv the channel name

  • @quaxk
    @quaxk 9 лет назад

    please, next time, make the background music louder, I feel I could still discern some notes through the distortion, also choose it more randomly, I feel it wasn't a 100% inappropriate

  • @climbercarmich
    @climbercarmich 7 лет назад

    What software did you make this in? Looks like R?

    • @poprhythm
      @poprhythm  7 лет назад +3

      R is a great tool, but no, this was made in C#. Here's an article about creating it: popcyclical.com/2013/08/19/TravelingSalesmanProblemVisualization.aspx

  • @samuelwallace-dr.universal
    @samuelwallace-dr.universal 8 лет назад

    I'm thinking a sequence of pi should be rendered around the travel area. Then the program extrapolates the rout to the perimeter of the travel area. Once the outline is created, the remaining locations could run greedy sequence. The key is starting with a circle and working from there, wish I could write code or I'd try it haha.

  • @zaidalmahmoud4272
    @zaidalmahmoud4272 4 года назад

    Awesome work! Thank you.

  • @TSPxEclipse
    @TSPxEclipse 6 лет назад

    This is fine and all, but what if the name of the salesman is Crowley?

  • @alperkalamanoglu4660
    @alperkalamanoglu4660 Год назад

    lol I can literally just watch this for the music. Mmy favourite part starts at 1:43, watched for 4 times.

  • @reymicroc
    @reymicroc 6 лет назад

    It always end up choosing the outline made by the points, why search then?

  • @changlife7581
    @changlife7581 7 лет назад

    Thats really cool!!!!

  • @manoelcamposdev
    @manoelcamposdev 7 лет назад +4

    Hey, could you enable the video to receive contributions from the community? I'd like to include a Portuguese subtitle. And thanks for providing this awesome video.

    • @poprhythm
      @poprhythm  7 лет назад +1

      Thank you! I've enabled the Community Contributions for closed captioning, I think. Let me know if you have any problem with it.

    • @manoelcamposdev
      @manoelcamposdev 7 лет назад +1

      I've just submitted the subtitles. Thanks for enabling Community Contributions. It's a great video.

  • @georgeraafat1329
    @georgeraafat1329 3 года назад

    Guys, I think I found the solution to reduce the time as much as possible. But what can I do with the solution?

  • @StephenCurry-ff4zc
    @StephenCurry-ff4zc 7 лет назад

    Practically speaking, what is this information used for in practical life

    • @grossteilfahrer
      @grossteilfahrer 6 лет назад

      Your car GPS does a small bit of this every time you put in an address to go to. It will not find the BEST solution but one that is as good at is can find in the time before you lose patience and reboot it thinking it's crashed.

  • @rajenderkumar5351
    @rajenderkumar5351 8 лет назад +1

    thanx

  • @devdeve-l1g
    @devdeve-l1g 8 месяцев назад

    How difficult is it to draw a circle?

  • @subratapaul061325
    @subratapaul061325 8 лет назад

    awesome

  • @ThiNguyen-gd9ny
    @ThiNguyen-gd9ny 8 лет назад

    hello...
    how to write programs using HEAPSORT to
    solve Travelling Salesman Problem - TSP on programming language ...
    and I need code :(
    im form Viet Nam...thanks

  • @OliverJoshuaJacob
    @OliverJoshuaJacob 8 лет назад +7

    this was flabbergasting.

  • @چوچالحربي
    @چوچالحربي 7 лет назад

    Which programme used??

  • @osamarizwan1635
    @osamarizwan1635 2 года назад

    How did you make this video

  • @lenlen8099
    @lenlen8099 6 лет назад

    I have a feeling you need to make a shape with the smallest area

  • @doomiesa2830
    @doomiesa2830 7 лет назад

    Could genetic algorithms be implemented? I would like to see that.

    • @ghaith81981
      @ghaith81981 3 года назад

      ruclips.net/video/gm0Nc4wPJZI/видео.html

  • @SGuy157
    @SGuy157 6 лет назад

    Why is this so lit

  • @pickinnick100
    @pickinnick100 4 года назад

    Your "greedy algorithm" doesn't choose the nearest city as claimed 00:16

  • @yongamer
    @yongamer 7 лет назад

    What if there is several salesmen?

  • @lenlen8099
    @lenlen8099 6 лет назад

    Is this a minimum spanning tree problem?

    • @poprhythm
      @poprhythm  6 лет назад

      They're both distance-on-a-graph problems, but not quite the same! - here's a short discussion: stackoverflow.com/a/3838791/99492

  • @florianreichelt
    @florianreichelt 7 лет назад

    cool!:)

  • @SeleniumThoride
    @SeleniumThoride 6 лет назад

    Wonder what would actually happen if a real travelling salesman used this.
    [A travelling salesman walks up to a door and knocks]
    _Man:_ Hello?
    _Salesman:_ Hello! Would yo be interested in buying math algorithms that solves the problems of least distance between major cities?
    _Man:_ What?
    _Salesman:_ I wasted my entire life looking for the perfect route rather than just actually traveling.