### How do we route Santa?

Some things seem very simple, supposing I ask you to visit 10 friends in the shortest possible distance.

This is quite an easy problem for us to solve simply by looking at a map. But in how many different orders can you arrange the 10 visits?

The number of possible ways in which we can visit our 10 friends is calculated as ...
= (10x9x8x7x5x4x3x2x1)/2*10.

So there are 181,440 different orders we can visit our friends in!

For a simple problem such as visiting 10 friends we can easily solve the problem by looking at a map and using some common sense.

Q: What if Santa has to visit 50 houses?...

A: There would be 3041409320171337804361260816606476884437764156896051200000000000
possible routes that he can take....! If we have to visit more than a few houses it becomes impossible to check all of the possible routes, even using a computer would take a very long time.

Q: How can we solve a complex problem like this quickly?...

A: We can solve this problem using a simple computer program known as an
*Evolutionary Algorithm*.

It works like this..

OurEvolutionary Algorithm is written in a programming language called Java, it's running on a computer at Edinburgh Napier University. If you refresh this page it will show the latest state of the algorithm.

### Step 1.

The Evolutionary Algorithm has a group of posible sleigh trips, this group is known as the population. When the algorithm starts, each member of the population has the deliveries in a random order, but we can still calculate the length of each tour.

# Click here to see the lengths of the tours in the latest population

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.35

52665.85

52664.31

52664.35

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.87

52664.31

52664.31

52664.31

52664.31

52664.59

52664.31

52664.31

52665.09

257327.76

52664.31

52674.72

52669.78

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52815.86

52664.31

52664.31

52664.31

52664.31

52664.31

255266.53

53172.77

52664.31

52664.31

52664.73

52664.31

52664.31

52664.31

52664.31

52676.94

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

53000.53

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.32

52664.31

52664.31

52664.31

52664.31

52664.31

52664.74

52664.31

52664.74

52664.31

52664.31

Sometimes all of the tours will have the same length, this happens when a short tour has been found, but will change when new houses are added.

Step 2.

We need to create some new shorter sleigh rides. We select some of the shortest sleigh rides in our population andthey become the parents of our next generation of sleigh rides. To create a child sleigh ride we copy either a whole tour from one parent, or make a new tour by adding togther the tour from two parents. We then make a random change (swap around some of the deliveries in the child (this is known as a mutation)

# Click here to see the new children and their parents

Child, 52664.59Parents ,p1,52664.31,p2,52664.31 Mutation 2 opt Mutate

Child, 54744.20Parents ,p1,52664.31,p2,52664.31 Mutation 2 opt Mutate

Child, 56233.67 Parent p1,52664.31 Mutation adj Swap Mutate

Child, 53720.78 Parent p1,52664.31 Mutation Swap Mutate

Child, 52664.63 Parent p1,52664.59 Mutation adj Swap Mutate

Child, 52863.80 Parent p1,52664.31 Mutation Simple Mutate

Child, 63478.92 Parent p1,52664.31 Mutation Swap Mutate

Child, 69507.44 Parent p1,52664.31 Mutation Swap Mutate

Child, 65695.11 Parent p1,52664.31 Mutation Swap Mutate

Child, 52664.31 Parent p1,52664.31 Mutation NN Simple Mutate

Child, 53290.19Parents ,p1,52664.31,p2,52664.31 Mutation Simple Mutate

Child, 52665.32 Parent p1,52664.31 Mutation NN Simple Mutate

Child, 53088.65 Parent p1,52664.31 Mutation adj Swap Mutate

Child, 64192.15 Parent p1,52664.31 Mutation 2 opt Mutate

Child, 57205.38 Parent p1,52664.31 Mutation 2 opt Mutate

Child, 53237.56 Parent p1,52664.31 Mutation NN Simple Mutate

Child, 52742.00 Parent p1,52664.31 Mutation 2 opt Mutate

Child, 63989.26Parents ,p1,52664.31,p2,52664.31 Mutation Swap Mutate

Child, 52667.17 Parent p1,52665.09 Mutation 2 opt Mutate

Child, 52664.31Parents ,p1,52664.31,p2,52664.31 Mutation NN Simple Mutate

Child, 52699.60 Parent p1,52664.31 Mutation 2 opt Mutate

Child, 52673.29 Parent p1,52664.31 Mutation adj Swap Mutate

Child, 53262.86 Parent p1,52664.31 Mutation Swap Mutate

Child, 52679.42 Parent p1,52664.31 Mutation Simple Mutate

Child, 60526.42 Parent p1,52664.31 Mutation 2 opt Mutate

Child, 52677.47 Parent p1,52664.87 Mutation adj Swap Mutate

Child, 57046.44 Parent p1,52664.31 Mutation Simple Mutate

Child, 53853.57Parents ,p1,52664.31,p2,52664.31 Mutation 2 opt Mutate

Child, 58487.19 Parent p1,52664.31 Mutation 2 opt Mutate

Child, 53671.74 Parent p1,52664.31 Mutation NN Simple Mutate

Child, 55239.42 Parent p1,52664.31 Mutation Simple Mutate

Child, 66433.83 Parent p1,52664.31 Mutation 2 opt Mutate

Child, 52674.60 Parent p1,52664.31 Mutation NN Simple Mutate

Child, 52676.16 Parent p1,52664.31 Mutation Swap Mutate

Child, 52759.43 Parent p1,52665.09 Mutation adj Swap Mutate

Child, 52664.87 Parent p1,52664.31 Mutation adj Swap Mutate

Child, 52664.31 Parent p1,52664.31 Mutation NN Simple Mutate

Child, 53751.55 Parent p1,52664.31 Mutation Swap Mutate

Child, 53053.19 Parent p1,52664.31 Mutation Swap Mutate

Child, 52664.31Parents ,p1,52664.31,p2,52664.31 Mutation NN Simple Mutate

Child, 66184.44 Parent p1,52664.31 Mutation Simple Mutate

Child, 52754.81 Parent p1,52664.31 Mutation 2 opt Mutate

Child, 52664.32 Parent p1,52664.31 Mutation adj Swap Mutate

Child, 52864.85 Parent p1,52664.31 Mutation Simple Mutate

Child, 52826.95Parents ,p1,52664.31,p2,52664.31 Mutation 2 opt Mutate

Child, 52664.31Parents ,p1,52664.31,p2,52664.31 Mutation NN Simple Mutate

Child, 54558.05 Parent p1,52664.31 Mutation Swap Mutate

Child, 52859.32 Parent p1,52664.31 Mutation Simple Mutate

Child, 53028.92 Parent p1,52664.31 Mutation Simple Mutate

Child, 53322.44 Parent p1,52664.31 Mutation 2 opt Mutate

### Step 3.

We would like to add some our new children into our population, to replace the longer tours. For each child we select a random member of the population, if the ride length of the population is longer, then the child replaces that member.

# Click here to see the replacement

Child 52664.59 Replaces 53172.77

Child 52664.31 Replaces 52669.78

Child 52664.31 Replaces 52664.35

Child 52673.29 Replaces 52676.94

Child 52674.60 Replaces 52815.86

Child 52759.43 Replaces 257327.76

### Step 4.

We have now added the children into the population

# Click here to see the improved population

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52665.85

52664.31

52664.35

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.87

52664.31

52664.31

52664.31

52664.31

52664.59

52664.31

52664.31

52665.09

52759.43

52664.31

52674.72

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52674.60

52664.31

52664.31

52664.31

52664.31

52664.31

255266.53

52664.59

52664.31

52664.31

52664.73

52664.31

52664.31

52664.31

52664.31

52673.29

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

53000.53

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.31

52664.32

52664.31

52664.31

52664.31

52664.31

52664.31

52664.74

52664.31

52664.74

52664.31

52664.31

### Check to see if any new deliveries have been added and then go back to step 2