Тёмный

Coding Challenge #35.4: Traveling Salesperson with Genetic Algorithm 

The Coding Train
Подписаться 1,7 млн
Просмотров 131 тыс.
50% 1

Опубликовано:

 

9 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 126   
@abdirahmanmohamud1353
@abdirahmanmohamud1353 Год назад
This man is an alien, the way he teaches is incredible, as soon as video starts the video ends without know that you spent 20 mints, thanks man
@ethanchua2335
@ethanchua2335 4 года назад
This dude gives an authentic coding experience.
@justinlangley8972
@justinlangley8972 2 года назад
So glad I found this channel. Even if you're using another language, these videos are incredibly helpful to learn from. I'm doing a project for a class involving the traveling salesperson problem and was thinking of using ACS or ACO, and it's interesting how similar it is to the genetic algorithm.
@husseintammam4691
@husseintammam4691 7 лет назад
Hi I read The Nature of Code a couple of years ago, and I loved it! It was a super fun read and the code was really easy to follow. It was my intro to artificial intelligence and the beginning of my addiction. Now I'm studying computer science and AI in uni and your book is part of the reason why :) I randomly started watching some of your videos a few days ago and when you mentioned your book I really felt the nostalgia. Your RU-vid channel looks awesome btw and I'm probably gonna binge-watch a bunch of your videos when I have the time! I love you work man. THANK YOU FOR YOUR CONTRIBUTION TO HUMANITY!
@TheCodingTrain
@TheCodingTrain 7 лет назад
Love hearing this, thank you!!!
@user-or2gl9sq5d
@user-or2gl9sq5d 5 лет назад
I like how this guy can't even offend an index of an array
@LeahLundqvist
@LeahLundqvist 7 лет назад
man. i love how well you explain things, i tried siraj's (don't know how to spell it) videos but it feels like you have to have a phd in math to understand, really looking forward to neural nets 🙌
@sethlivingston1310
@sethlivingston1310 6 лет назад
i really love his videos. It makes progamming more fun than studying
@spicytuna08
@spicytuna08 6 лет назад
this factorial number, we don't have a sense how long it takes. this video really shows the importance of algorithm.
@Spaceizcool
@Spaceizcool 7 лет назад
27:54 IT UPDATED TO OPTIMAL SOLUTION
@DavidWMiller
@DavidWMiller 7 лет назад
I wanted to yell at the screen when he didn't notice that.
@Alex-Eldridge
@Alex-Eldridge 7 лет назад
Just a note on the shuffle algorithm you made, it will not produce every possible order. By swapping an even number of times, you only get half of the total permutations. All the orders created will be even permutations, and there is no way for the shuffle to produce an order that is only one, three, or five swaps away. This is the parity theorem of permutations. Helpful information when making a shuffle algorithm! Here's a link to more info on even and odd permutations. www.efgh.com/math/algebra/permutations.htm
@shaytal100
@shaytal100 7 лет назад
I think you need to implement the possibility of switching more than 1 pair of cities per mutation. Otherwise the algorithm can be stuck in a local minimum. In other words: It can be, that switching any possible single pair of cities leads to a longer distance while switching 2 or more cities would further lower it. Really like your videos! They are educational and entertaining!
@TheHpsh
@TheHpsh 7 лет назад
yes, but that will probably be a problem anyway, the traveling salesman problem are well known to be a pretty hard to do with genetic algorithm.
@shaytal100
@shaytal100 7 лет назад
Yeah I would think so too. The number of possible solutions grows with n!. And there will be lots of local optimals. But intelligent combinations of former generation sequences might make it an efficient algorithm. But this is not an easy problem. Looking forward to the next part.
@TheHpsh
@TheHpsh 7 лет назад
i have one idea, about using epigenetic, and using a complete route as a gene. it will need to have many alternative routes to randomly select between, but cross breading might help removing bad ones. but think it will be slower then brute force, since it will often remove good routes to.
@TGCByJesus
@TGCByJesus 5 лет назад
Thank you. Your lecture has helped me a lot.
@MrAashish24
@MrAashish24 7 лет назад
Hello Sir I am your big fan
@EDToasty
@EDToasty 6 лет назад
Hello Sir I am your big fan
@sagarkapasi099
@sagarkapasi099 6 лет назад
Hello Sir I am your big fan
@Johncena-bk1lg
@Johncena-bk1lg 6 лет назад
Hello Sir I am your big fan
@Marcus-jf4hu
@Marcus-jf4hu 6 лет назад
Hello Sir I am your big fan
@alecday3552
@alecday3552 5 лет назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-mif77aOd9ns.html
@tomek3633
@tomek3633 2 года назад
Great stuff! Looking forward to see part II of it!
@theWorldOfIss
@theWorldOfIss Год назад
Sir how to implement multiple traveling salesman problem using NSGA-2 in python.
@xzesstence8862
@xzesstence8862 5 лет назад
thank you for this great tutorial, i really enjoyed this series
@SergioPolimante
@SergioPolimante 5 лет назад
Your videos are really helpful and very fun to watch, you are very fun! Thanks for the content
@MrCmon113
@MrCmon113 6 лет назад
Omg it found the best solution while he wasn't looking! XD
@Victor_Marius
@Victor_Marius 5 лет назад
Hello! I found a quick way to shuffle with order.sort((a, b) => Math.random() > 0.5). But this is not be the best way to do it.
@TheCodingTrain
@TheCodingTrain 5 лет назад
oh, that's clever!
@mohamedmhmood2940
@mohamedmhmood2940 7 лет назад
you are awesome.. you are best programmer I've ever see
@TheCodingTrain
@TheCodingTrain 7 лет назад
Thank you!
@mrbubbly4536
@mrbubbly4536 7 лет назад
Wow... everything you did seems so complicated! Nice Work!
@TheCodingTrain
@TheCodingTrain 7 лет назад
Thank you!
@davidalejandromurocampa1005
How a genetic algorithm could be applied to the set covering problem (SCP)?
@Tracks777
@Tracks777 7 лет назад
Great! Keep it up!
@SetTheCurve
@SetTheCurve 5 лет назад
It seemed like the solutions were not only changing order, but changing the location of the dots. What am I missing?
@SourabhBhat
@SourabhBhat 7 лет назад
Is it calculating at the frame rate? I mean, is the new distance calculated once per frame and rendered to screen? or is it only rendering the current possibility that is there in the array at the time of rendering? I guess it would be too slow to calculate only once per frame. I suppose it would be better to do the calculation in a separate thread which can continuously crunch the numbers.
@Wuzzysbrand06
@Wuzzysbrand06 7 лет назад
Yes, the draw function is called once per frame, so everything inside of it is executed once per frame. That's just how the p5.js library works. You can add custom flags to skip things when something happens (e.g. don't draw the path again if the "bestEver" hasn't changed). That might speed things up a bit. You're right about it being better to do in a seperate thread, however, JavaScript is single thread only. There are things called "Web Workers" that allow for multithreading in JS but that's a whole different tutorial and there are limitations with that as well, as Web Workers don't have access to things like the document object, the window object etc. I'm not sure how suitable it is in conjunction with p5.js, however, I have to admit that I don't have experience with it either. Doing this multithreaded would be better in a language that supports parallelization properly.
@Garfield100
@Garfield100 7 лет назад
Just loop the whole thing so it does it multiple times each frame :D No need for complicated threading and stuff
@SourabhBhat
@SourabhBhat 7 лет назад
@GarfieldGaming I think, if we do that on the the same UI thread, it will freeze the canvas.
@Wuzzysbrand06
@Wuzzysbrand06 7 лет назад
@GarfieldGaming that would make it choppy and wouldn't really be any faster than doing it once each frame, because you're still calculating everything sequentially.
@Garfield100
@Garfield100 7 лет назад
+Wuzzybrand06 It's capped at 60, that's why it remains at 60 even if it could go faster :D basically it calculates one frame and when it's done it does nothing for the rest of the 1/60th of a second period. I've done this multiple times and it's a neat trick because you can't seem to change the framerate cap :/ (It really does work!)
@yuvalyehezkel5558
@yuvalyehezkel5558 7 лет назад
lol you didnt notice it optimized it behind your back :D 27:49 i LOVE your videos btw, keep doing what you do!
@ritikkhatri
@ritikkhatri 6 лет назад
27:56 to be precise
@DeathRuNNerVST
@DeathRuNNerVST 7 лет назад
Daniel i love you so much .. your recent videos are soo good
@TheCodingTrain
@TheCodingTrain 7 лет назад
I'm so glad to hear!
@virenlakum
@virenlakum 6 лет назад
Travelling salesman Problem states that it should start and end at same city...
@charbelsarkis3567
@charbelsarkis3567 6 лет назад
could you possibly make this with google maps? what if i want to deliver packages to houses as fast as possible.
@TheCodingTrain
@TheCodingTrain 6 лет назад
Great idea! Check out: github.com/cvalenzuela/Mappa
@charbelsarkis3567
@charbelsarkis3567 6 лет назад
The Coding Train thank you
@Tracks777
@Tracks777 7 лет назад
When is your next video? :D Keep it up!
@frodeflem9353
@frodeflem9353 7 лет назад
What I would give, to be able to do the things you are doing, for a living!
@tips-today463
@tips-today463 3 года назад
Sir , how can i perform a scheduling with genetic algorithm
@niklasfrank7847
@niklasfrank7847 7 лет назад
A LSTM or NEAT coding challenge/tutorial/example would be interresting and nice. Also nice videos ;-)
@TheCodingTrain
@TheCodingTrain 7 лет назад
It's coming!
@niklasfrank7847
@niklasfrank7847 7 лет назад
The Coding Train Nice! Always wanted to know more about those two!
@Johnnyboycurtis
@Johnnyboycurtis 6 лет назад
I get this guy is trying to be fun and silly, but I wouldn't mind if he could take it down a notch. Aside from that, it's quality content. He doesn't dive deep into the theory of GAs, but enough to get novice programmers started.
@afqradeon4757
@afqradeon4757 6 лет назад
Hi, when picking one why not pick the one with the BEST fitness (like hightest fitness) ?? instead of taking it via random number
@hadidihosney
@hadidihosney 5 лет назад
How can I modify this code to add my own points please can anyone help
@peterhayman
@peterhayman 7 лет назад
haha those horns sound like the intro to jump around
@elderbinks22
@elderbinks22 7 лет назад
I've got a challenge that I would love to see. I want to see genetic algorithm implemented in a rc car with some sort of distance tracker. so that it can make its way through the obstacle course. i understand it would take a long time. But id still love to see it
@SimonTiger
@SimonTiger 4 года назад
/20:42 "2-Dimensional space" Why does it have to be 2-dimensional!? The mathematically appropriate way to discribe it is in a 1-dimensional space!
@flaviaawan6297
@flaviaawan6297 4 года назад
How to calculate fitness function without path cost?
@kennethstewart4SPToRead4FREE
Hasn't the traveling salesman been solved through path of least resistance?
@i.i
@i.i 7 лет назад
I like your way of doing things the best programming channel on RU-vid can you please use some ES6 functions and stuff we want to learn some modern JS
@earthbender731
@earthbender731 3 месяца назад
Isn't the original name The traveling salesMAN?
@fayezbayzidify
@fayezbayzidify 7 лет назад
you are amazing !
@wyxas
@wyxas 7 лет назад
im your bigger fan
@ivansivak93
@ivansivak93 7 лет назад
Vytautas I am a bigger fan,
@wyxas
@wyxas 7 лет назад
dont lie
@juandavidnavarro
@juandavidnavarro 4 года назад
Can you try this problem with Tabu Search?
@wassilchoujaa3478
@wassilchoujaa3478 4 года назад
TSP is best solved with sat (constraint based) solver AFAIK
@arifhussain-qx1ef
@arifhussain-qx1ef 4 года назад
I'm anxiously looking for implementation of genetic algorithm in timetable scheduling problem
@aimenmansouri7648
@aimenmansouri7648 7 лет назад
did university is so important in learning computer sience can i learn alone and how ?
@Lanr1s
@Lanr1s 7 лет назад
في 90 ثانية - in 90 sec interested too
@aimenmansouri7648
@aimenmansouri7648 7 лет назад
حسب علمي مستوى الجامعات العربية متدني جدا معظم الخرجين يزعمون انهم تعلموا علوم الحاسب مستقلين عن الجامعة
@aimenmansouri7648
@aimenmansouri7648 7 лет назад
حسب علمي مستوى الجامعات العربية متدني جدا و معظم الخريجين يزعمون انهم تعلمو علوم الحاسب مستقلين عن الجامعة
@adud6764
@adud6764 7 лет назад
Depends on what you want to do with it. Do you just want to create some personal applications and delve into stuff that is shown here on the channel? No, you probably dont need a university degree. Some things might fly over your head but if you invest enough time and look into the background mathematics or whatever you will be able to do it. But if you want a solid job in software development you will probably be required to have a degree. Even if you can show a lot of working experience employers will consider people with a degree over you, even if they lack the experience. I think they want this mathematic/algorythmic background in employees. At least that is the way where I am from.
@i.i
@i.i 7 лет назад
انا احب شرح هذا الكائن لكن المشكلة انه يستخدم مكتبة مو مشهورة وتنفع في الرسم بس
@Farpezio
@Farpezio 6 лет назад
*deletes order, "next I need to create order..."
@owclassy308
@owclassy308 7 лет назад
Next: Traveling Salesperson with Dynamic Programming
@armanshirzad4409
@armanshirzad4409 3 года назад
awesome, good energy, easy to learn only one question where can i find the source code?? fast reply would be appreciated due to my project deadline, All The Bests
@matiasforti6088
@matiasforti6088 3 года назад
In the description
@brianbouf8303
@brianbouf8303 7 лет назад
i am your biggest fan.
@ThisIsntBrandon
@ThisIsntBrandon 7 лет назад
I'm the most big fan
@peterbonnema8913
@peterbonnema8913 6 лет назад
at 8:52 I assume that you haven't read the text: directly above that piece of code it says: "Here's what the implemententation looks like in Javascript, not that you should use it:". And direct below the code it says: "This is bad, and we can do better." hahaha
@kocakOFarc
@kocakOFarc 4 года назад
java code for flying sidekick traveling salesman problem please
@shuvamshah5970
@shuvamshah5970 7 лет назад
can't we do this using Prim's or Kruskal's algorithm of Minimum spanning tree?
@mebamme
@mebamme 7 лет назад
this video is about the shortest route that visits all nodes. A tree on the other hand might have branches, which isn't exactly a route you can follow (unless you backtrack, but that wouldn't be short anymore.)
@officialniknak
@officialniknak 7 лет назад
Prim's and Kruskal's would indeed give an minimum spanning TREE, but the Traveling Salesman is looking for the shortest PATH among the vertices. A tree is not necessarily a path
@shuvamshah5970
@shuvamshah5970 7 лет назад
mebamme yeah exactly... I got it
@simpletongeek
@simpletongeek 7 лет назад
you're talking about Christofide approximate algorithm. once you have the tree, you can traverse it, skipping the backtracks. it provides a pretty good solution relatively quickly.
@akruijff
@akruijff 5 лет назад
How about fitness = -d?
@raderadovic7886
@raderadovic7886 7 лет назад
where I can find the whole code? It's much easier for me to follow
@kaz372
@kaz372 4 года назад
Would in effect never work with a mute mutate function ;)
@krystianzawadzki975
@krystianzawadzki975 7 лет назад
Oh, didn't even notice I was this quick :D
@patuitar1117
@patuitar1117 4 года назад
Why not just use dijkstra's algorithm
@sabecraftgamingandmore1364
@sabecraftgamingandmore1364 7 лет назад
13 factorial is 6,227,020,800 (6 billion, 227 million, 20 thousand, 8 hundred)!
@bechirjamousi6696
@bechirjamousi6696 4 года назад
But the TSP needs to return back to the city he starts with! Am i right?
@SimonTiger
@SimonTiger 4 года назад
Traveling Salesman problem
@DasAntiNaziBroetchen
@DasAntiNaziBroetchen 4 года назад
Aha?
@adonis1168
@adonis1168 6 лет назад
22:23 mutation
@wouter11234
@wouter11234 7 лет назад
Watching this in a car, on a laptop with linux. I'm happy with myself xD
@OrangeC7
@OrangeC7 6 лет назад
4D travelling salesperson problem, you say? 🤔
@Drone256
@Drone256 4 года назад
For decades there was something similar called the traveling salesman problem. You are being very PC about your computer science. Lol.
@DasAntiNaziBroetchen
@DasAntiNaziBroetchen 4 года назад
You make it out to be a problem.
@vasugupta9824
@vasugupta9824 6 лет назад
swaaaap
@Tymon0000
@Tymon0000 7 лет назад
Woah your coding is messy as hell xD
@adonis1168
@adonis1168 6 лет назад
17:50 next gen
@Jkauppa
@Jkauppa 3 года назад
or you just send multiple salesmen, to every city, one straight line
@Jkauppa
@Jkauppa 3 года назад
merge partial best paths
@Jkauppa
@Jkauppa 3 года назад
you could display the achieved path length
@Jkauppa
@Jkauppa 3 года назад
permutate partial populations
@Jkauppa
@Jkauppa 3 года назад
minimize path length
@zakcodes3507
@zakcodes3507 7 лет назад
I watched the stream and I remembered that your algorithm to associate a fitness with a probability really annoyed me so here's mine which I use in my NEAT algorithm and is way more efficient and looks like yours a little: var fitnesses = []; function pick() { // Get the fitness sum var fitnessSum = 0; for (var i = 0; i < fitnesses.length; i++) fitnessSum += fitness[i]; // Pick a random one var prob = fitnessSum * random(); fitnessSum = 0; for (var i = 0; i < fitnesses.length; i++) { fitnessSum += fitness[i]; if (fitnessSum > prob) return i; // or fitness[i] depending on what you want } } I'm probably going to do a pull request about it soon but it really annoyed me because I had to fight with a guy who didn't understand what I was doing because he was sure that the only way to pick a member depending on the fitness was to use percentages
@alexchase1856
@alexchase1856 6 лет назад
GENERIC not genetic ffs
@DasAntiNaziBroetchen
@DasAntiNaziBroetchen 4 года назад
Are you stupid?
6 лет назад
Please sub this video in English
Далее
Introducing iPhone 16 | Apple
02:00
Просмотров 3,6 млн
Пришёл к другу на ночёвку 😂
01:00
Coding Challenge 180: Falling Sand
23:00
Просмотров 904 тыс.
What was Coding like 40 years ago?
29:05
Просмотров 1,7 млн
Coding Challenge #35.1: Traveling Salesperson
22:55
Просмотров 288 тыс.
Coding Challenge 182: Apollonian Gasket Fractal
56:48
Ant colony optimization algorithm
19:21
Просмотров 60 тыс.
Genetic Algorithms - Jeremy Fisher
50:07
Просмотров 53 тыс.