Coding Challenge #35.3: Traveling Salesperson with Lexicographic Order

Subscribers:
1,750,000
Published on ● Video Link: https://www.youtube.com/watch?v=9Xy-LMAfglE



Duration: 20:07
64,312 views
896


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 4: TSP with Genetic Algorithm: https://youtu.be/M3KTWnTrU_c
πŸ“Ί 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 3
01:26 Code! Bringing code from the lexical order challenge
03:19 Drawing the numeric order below the path
04:30 Generating the next order each time through draw()
05:07 Using the generated lexical order
08:24 Copying the best order ever
10:48 Drawing the best order ever
13:04 Drawing the current and best permutation separately
15:22 Displaying the progress
18:15 Trying different numbers of cities

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







Tags:
shiffman
p5js
p5.js tutorial
processing tutorial
creative coding
traveling salesman
traveling salesperson
permutation
lexical ordering
lexicographic ordering
nature of code
coding challenge
genetic
genetic algorithms
genetic algorithm
algorithm
evolution
challenge
patreon
brute force
factorial
swap
javascript swap
lexicographical ordering
coding
salesperson
daniel shiffman
lexical
brute-force algorithm
permutations