The long and winding road

The long and winding road

Last week, I received an email telling me a recent online purchase was out for delivery. There was a real-time tracking option - I clicked the link to check on progress. I was encouraged to see my driver was only a few streets away, which impressed me since I'd only bought the item the night before.?

Four hours passed before the doorbell finally rang. I'd updated delivery tracking many times, watching the dot on my screen move in what seemed like a random pattern from one drop-off point to another.?

It's life Jim, but not as we know it

I was reminded of the travelling salesperson problem and inspired by similar work by others (thanks, to Peter den Haan , Micha? Jankowski , Michael Baczyk and Peter Brookes-Smith ). We have also created a Quantum Computing solution for this challenge for anyone that's interested. This may be handy since the number of possible routes gets large very quickly as the number of locations increase.

My version uses Python to create a genetic algorithm to optimise delivery journeys. The application works in real-time, providing a view of the best current route. A simple chart also shows how the total journey distance (mostly) decreases over time.?

The screenshots above show a route at specific generations. Note how the journey chart flattens out over time. Mutation continues but has less effect in later generations as diversity in the route population decreases. Showing diversity in some way may be something to think about for a future version. The diagram below illustrates what happens for each generation of routes.

The steps involved in the genetic algorithm. Create an initial population of routes, calculate the fitness of each route, choose routes for seeding the next generation, create children from the parent routes, mutate children periodically and repeat

1: The process starts by generating a specified number of random routes.

2: For fitness, I've just used the reciprocal of the total route distance which means shorter routes are fitter.

3: A specified number of parents are chosen based on their relative fitness.

4: The next generation is created using the parents that were chosen in the previous step. In genetics, crossover means that children take a mixture of genes from their parents - for this adventure, elements of parent routes are combined.

5: Now and again, a route mutates, the amount is configurable by specifying the probability that mutation will occur. Mutation provides an element of exploration in the exploration-exploitation trade off.

For this example, the application runs until it is stopped.

Interesting measurements

The application sidebar updates progress as each frame is drawn. Here you can see the number of locations, the initial (random) journey distance and the current distance (amongst other things). The application has a configuration file that allows the hyperparameters to be set.

The mutation rate can be changed as the application is running to show how this affects the algorithm.

A picture of the application interface showing how route planning is improved over time.
The application sidebar provides some interesting measurements

The buttons allow you to run the application again using the same locations or to generate new locations. The number of locations is defined in the configuration file along with other application settings. A selected subset is shown here.

    # Environment details
    TICKS_PER_SECOND = 40
    LOCATION_RADIUS = 12
    
    # The bars representing total route distance over time
    DRAW_BAR_INTERVAL = 4
    BAR_WIDTH = 12
    BAR_COLOR = (130, 205, 207)
    
    LOCATION_COUNT = 48
    
    # Hyperparameters       
    FITTEST_ROUTES_COUNT =22
    POPULATION_SIZE = 110
    MUTATION_RATE = 0.003        

Final thoughts

These kinds of algorithms can help with a number of real-world challenges especially in the areas of optimisation and search/sort. There are other ways to address this problem, I chose this after working on a similar strategy for an evolution simulation I recently created.

If anyone would like to discuss this more, see it running (it's strangely soothing) or get access to the code then please let me know. If you're interested in Quantum Computing - some of my colleagues are mentioned above.

Micha? Jankowski

Innovator | Tech Evangelist | Emerging Tech Strategist | Solution Architect | Microsoft Azure MVP | Global Explorer

2 年

Great article Matthew! If you would like to check what inspired Matt visit the page: https://ideaapp.objectivity.co.uk/project/robssantaqlause There is also a link where you can run simulations on a real quantum computer.

Andrew P. Smith

Director of Healthcare, Life Sciences & Public Sector (EMEA) - Platform Engineering at Accenture

2 年

Great stuff Matt, as always!

David Perks

Board Commercial Director @ Container Solutions | Emea lead for Retail, Consumer goods | Rethink top retail expert

2 年

Love this Matt!!

Nice work Matt! An elegant solution to a classic problem.

要查看或添加评论,请登录

Matthew Weaver的更多文章

  • Why do your friends have more friends than you?

    Why do your friends have more friends than you?

    It’s more of a statistical trait than a personal one. Have you ever thought that your friends on social media seem to…

  • Ask the Right Questions, Get the Right?Answers

    Ask the Right Questions, Get the Right?Answers

    The ability to ask great questions is one of the biggest differentiators between a great leader and a mediocre one -…

  • Why do LLMs Hallucinate?

    Why do LLMs Hallucinate?

    Because response diversity cannot exist without it Large language models (LLMs) generate text by predicting the most…

  • The Devil’s in the Detail: Why Coastlines Defy Measurement

    The Devil’s in the Detail: Why Coastlines Defy Measurement

    We’ll use a simple fractal to make sense of it all Many of us have dreamt about owning a private island to retire to…

    4 条评论
  • Don’t Be Fooled: Sneaky Stats Can Sabotage Your Sales Analysis

    Don’t Be Fooled: Sneaky Stats Can Sabotage Your Sales Analysis

    Uncover a hidden statistical trap that may be misleading you into making poor business decisions. Imagine you are the…

    2 条评论
  • Not all choices are equal

    Not all choices are equal

    We are all familiar with the classic dilemma - you have two (or more) choices and must decide on the best option…

  • Simple is not always easy

    Simple is not always easy

    Last week I wrote about a simple process that can generate complex patterns. Today's topic is the equally 'simple' but…

    7 条评论
  • Can random choices lead to predictable outcomes?

    Can random choices lead to predictable outcomes?

    The simplest algorithms can sometimes generate unexpected outcomes. This post looks at a simple, three-step process and…

  • Digital (image) transformation

    Digital (image) transformation

    Digital transformation can mean many things to many people. In this post, I avoid the bigger question and demonstrate…

    4 条评论
  • My thoughts on Future Decoded 2019

    My thoughts on Future Decoded 2019

    A couple of weeks ago, a familiar journey ended as I arrived at London ExCeL for Microsoft Future Decoded (FD) 2019. My…

    3 条评论

社区洞察

其他会员也浏览了