Coding Challenge #35.4: Traveling Salesperson with Genetic Algorithm

Subscribers:
1,740,000
Published on ● Video Link: https://www.youtube.com/watch?v=M3KTWnTrU_c



Duration: 30:09
122,455 views
1,837


In Part 1 of this multi-part coding challenge, I introduce the classic computer science problem of the Traveling Salesperson (TSP) and discuss the pitfalls with a brute force solution. In Part 2, I discuss Lexicographic Ordering and demonstrate one algorithm to iterate over all the permutations of an array. In Part 3, I apply this algorithm to a brute-force solution of the TSP problem. Every single route permutation is checked one by one. In Part 4, I attempt to create a solution to the TSP problem with a genetic algorithm, and then I add a “crossover” algorithm in Part 5. Code: https://thecodingtrain.com/challenges/35-traveling-salesperson

p5.js Web Editor Sketches:
🕹️ Part 1: Traveling Salesperson (TSP): https://editor.p5js.org/codingtrain/sketches/FCNAHaCqf
🕹️ Part 2: Lexicographic Order: https://editor.p5js.org/codingtrain/sketches/iYxi30gbl
🕹️ Part 3: TSP with Lexicographic Order: https://editor.p5js.org/codingtrain/sketches/bWPIkEv9s
🕹️ Part 4: TSP with Genetic Algorithm: https://editor.p5js.org/codingtrain/sketches/EGjTrkkf9
🕹️ Part 5: TSP with Genetic Algorithm and Crossover: https://editor.p5js.org/codingtrain/sketches/EGjTrkkf9

Other Parts of this Challenge:
📺 Part 1: Traveling Salesperson (TSP): https://youtu.be/BAejnwN4Ccw
📺 Part 2: Lexicographic Order: https://youtu.be/goUlyp4rwiU
📺 Part 3: TSP with Lexicographic Order: https://youtu.be/9Xy-LMAfglE
📺 Part 5: TSP with Genetic Algorithm and Crossover: https://youtu.be/hnxn6DtLYcY

🎥 Previous video: https://youtu.be/Cl_Gjj80gPE?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
🎥 Next video: https://youtu.be/rX5p-QRP6R4?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
🎥 All videos: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH

References:
🌐 Traveling Salesman on Wikipedia: https://en.wikipedia.org/wiki/Travelling_salesman_problem
🗨️ Permutation Algorithm Using Lexicographic Ordering: https://www.quora.com/How-would-you-explain-an-algorithm-that-generates-permutations-using-lexicographic-ordering
📝 Array on MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array
📝 Array.includes() on MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
📝 Array.reverse() on MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse
📝 ES6 Sets on MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set
💾 The Nature of Code Part 2: https://github.com/shiffman/NOC-S17-2-Intelligence-Learning
📕 The Nature of Code: http://natureofcode.com/

Videos:
🎥 Improved Pool Selection: https://www.youtube.com/watch?v=ETphJASzYes&list=PLRqwX-V7Uu6YJ3XfHhT2Mm4Y5I99nrIKX&index=23
🎥 Genetic Algorithm Playlist: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6bJM3VgzjNV5YxVxUwzALHV
🔴 Live Stream Archive #57: https://youtu.be/r_SpBy9fQuo

Related Coding Challenges:
🚂 #29 Smart Rockets in p5.js: https://youtu.be/bGz7mv2vD6g
🚂 #51 A* Pathfinding Algorithm: https://youtu.be/aKYlikFAV4k
🚂 #69 Evolutionary Steering Behaviors: https://youtu.be/flxOkx0yLrY
🚂 #70 Nearest Neighbors Recommendation Engine: https://youtu.be/N8Fabn1om2k

Timestamps:
00:00 Introducing Part 4
01:56 Code! Creating a population of orders
05:25 Shuffling the arrays of orders
09:45 Giving each order in the population a fitness score
11:17 Storing the order with the best fitness
13:17 Creating a new file for the Genetic Algorithm
14:08 Generating the next generation based on the best orders
18:59 Picking an order using pool selection based on their fitness
22:02 Mutating the picked orders
26:02 Debugging the code
27:12 Yay! This is working!
27:26 How to make the algorithm better?

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

🚂 Website: http://thecodingtrain.com/
👾 Share Your Creation! https://thecodingtrain.com/guides/passenger-showcase-guide
🚩 Suggest Topics: https://github.com/CodingTrain/Suggestion-Box
💡 GitHub: https://github.com/CodingTrain
💬 Discord: https://discord.gg/hPuGy2g
💖 Membership: http://youtube.com/thecodingtrain/join
🛒 Store: https://standard.tv/codingtrain
🖋️ Twitter: https://twitter.com/thecodingtrain
📸 Instagram: https://www.instagram.com/the.coding.train/

🎥 Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
🎥 Intro to Programming: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA

🔗 p5.js: https://p5js.org
🔗 p5.js Web Editor: https://editor.p5js.org/
🔗 Processing: https://processing.org

📄 Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct

This description was auto-generated. If you see a problem, please open an issue: https://github.com/CodingTrain/thecodingtrain.com/issues/new

#travelingsalesperson #permutation #lexicographicordering #natureofcode #geneticalgorithm #evolution #bruteforce #factorial #arrays #p5js




Other Videos By The Coding Train


2017-05-11Coding Challenge #70: Nearest Neighbors Recommendation Engine - Part 3
2017-05-10Coding Challenge #70: Nearest Neighbors Recommendation Engine - Part 2
2017-05-09Coding Challenge #70: Nearest Neighbors Recommendation Engine - Part 1
2017-05-083.1: Introduction to Session 3 - What is Machine Learning?
2017-05-062.2: Exercise Ideas: Session 2 - Intelligence and Learning
2017-05-05Live Stream #91: Session 3 of “Intelligence and Learning”
2017-05-051.2: Exercise Ideas: Session 1 - Intelligence and Learning
2017-05-042.1: Introduction to Session 2 - Intelligence and Learning
2017-05-039.8: Genetic Algorithm: Improved Pool Selection - The Nature of Code
2017-05-02Coding Challenge #35.5: TSP with Genetic Algorithm and Crossover
2017-05-01Coding Challenge #35.4: Traveling Salesperson with Genetic Algorithm
2017-04-29Coding Train Live 90: Session 2 of “Intelligence and Learning” Continued
2017-04-28Coding Challenge #69: Evolutionary Steering Behaviors - Part 5 (Bonus)
2017-04-27Coding Challenge #69: Evolutionary Steering Behaviors - Part 4
2017-04-24Coding Challenge #69: Evolutionary Steering Behaviors - Part 3
2017-04-20Coding Challenge #69: Evolutionary Steering Behaviors - Part 2
2017-04-18Coding Challenge #69: Evolutionary Steering Behaviors - Part 1
2017-04-15Live Stream #89: Session 2 of “Intelligence and Learning”
2017-03-30Coding Challenge #68: Breadth-First Search Part 2
2017-03-30Coding Challenge #68: Breadth-First Search Part 1
2017-03-291.1: Introduction to Session 1 - Intelligence and Learning



Tags:
JavaScript (Programming Language)
live
programming
creative coding
coding challenge
tutorial
coding
challenges
coding train
nature of code
intelligence creative coding
evolution code
genetic algorithm
traveling salesman genetic algorithm
evolution computer
evolution programming
computing evolution
pool selection
traveling salesperson genetic
traveling
genetic
salesperson
algorithm
genetic algorithms
travelling salesman problem
challenge
traveling salesperson
tsp