avatarThe Pragmatic Programmers

Summary

This context introduces the concept of optimization and genetic algorithms as a solution to complex problems such as the traveling salesman problem.

Abstract

The text discusses the challenge of making informed decisions in a complex world, using the example of designing the shortest shipping route for a company. It highlights the difficulty of calculating every possible path and the need for a more informed approach. The solution proposed is optimization, specifically through the use of genetic algorithms, which are a set of instructions for finding the best solution to a problem.

Opinions

  • The author emphasizes the importance of optimization in making informed decisions.
  • The author suggests that humans are naturally good at optimization, while computers need help.
  • The author presents genetic algorithms as a common and effective optimization algorithm.
  • The author implies that genetic algorithms can be a more efficient solution than experimenting with different strategies.
  • The author suggests that genetic algorithms can help computers make the best decisions.

Chapter 1 Writing Your First Genetic Algorithm

Genetic Algorithms in Elixir — by Sean Moriarity (9 / 101)

👈 How Does Elixir Fit In? | TOC | Understanding Genetic Algorithms 👉

In a world of competition, people are always searching for the best. The best job, the best diet, the best financial plan, and so on. Unfortunately, with so many options, it’s impossible to make the best decisions all the time. Fortunately, humans have evolved to navigate the complexity of everyday life and make informed decisions that ultimately lead to success.

While your brain is naturally wired to make informed decisions, computers are not. Computers are naive — they can only do what you program them to do. So how do you program a computer to make informed decisions, and why is this even necessary?

Consider this example: you’re tasked with designing the shipping route for a large shipping company. You’re given a list of fifteen cities and your job is to pick the shortest route between them to save the company money on gas and travel expenses. At first, you might think it’s best to calculate every possible path between the cities — there’re only fifteen. Unfortunately, the number of possible paths is 130,766,744,000,000 — that’s 130 trillion. This problem is an example of the traveling salesman problem. The goal of the traveling salesman problem is to find the shortest route between a designated number of cities.

The number of possible paths grows at a factorial rate. A factorial is the product of every integer up to a certain integer. In the shipping example with fifteen cities, you can calculate the number of paths by multiplying every integer from 1 to 15.

Nobody has enough time to calculate the distance of 130 trillion paths. You have to take a better, more informed approach. You could choose a random start point and choose to travel to the next closest city after every stop. This strategy might produce the shortest path — you could even calculate the distance of the paths produced from starting at every city and choose the shortest one from that. You’d then only have to calculate the distance of fifteen paths. Unfortunately, experimenting with different strategies is still time consuming, and without a calculated approach you might miss the best strategy.

So how can you make the best decisions and teach a computer to do the same?

The answer is optimization. Optimization is the practice of making the best possible decisions in a situation. You can think of optimization as the search for the best. Humans are great at optimizing — it’s natural for us to find and make the best decisions for ourselves. Computers can be great at optimizing too; they just need a little help.

Optimization algorithms are techniques for solving optimization problems — problems where your goal is to find the best of something. An algorithm is a series of instructions. An optimization algorithm is a set of instructions for finding the best solution to a problem. While there are countless optimization algorithms, one of the oldest and most common is the genetic algorithm.

👈 How Does Elixir Fit In? | TOC | Understanding Genetic Algorithms 👉

Genetic Algorithms in Elixir by Sean Moriarity can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

Smgaelixir
Recommended from ReadMedium