School of Simulation Logo - Navigate to Homepage

Trustpilot Reviews

What's the relationship between simulation and optimisation?

Ah, simulation and optimisation. Two words often found loitering in the same sentences, sometimes even mistaken for one another, like a pair of technically-minded twins who insist on dressing alike. But while they're undeniably chums, working together splendidly, they are distinct characters with their own unique talents. Think of it like this: simulation is your keen-eyed explorer, charting out the vast, often bewildering, landscape of 'what ifs'. Optimisation, on the other hand, is your pragmatic guide, trying to find the most efficient or profitable path through that landscape.

Let's be clear. Simulation, as I drone on about rather extensively in my book, Simulation in Python with SimPy (which, by a happy coincidence, you can snag for free here), is all about creating a model of a real-world system. It's your digital sandpit. Want to know what happens if a crucial machine in your factory throws a wobbler? Or how your A&E department will cope with a sudden influx of scooter-related injuries? Simulation lets you play out these scenarios, complete with all the glorious randomness and variability the real world loves to throw at us – think Monte Carlo methods here, as discussed in Chapter 10 of said book. It provides data, shedloads of it, on wait times, queue lengths, resource utilisation, and throughput. It lets you identify bottlenecks (Chapter 9 is your friend here) and understand the intricate dance of system dynamics. It's about understanding how a system behaves.

Diagram illustrating a complex system like a factory or logistics network, suitable for simulation.
Figure 1: Simulation helps explore complex system behavior.

Optimisation, conversely, is less about the "how" and more about the "how best". It's a mathematical pursuit, usually involving clever algorithms, to find the peak of a particular hill or the deepest part of a valley, metaphorically speaking. Given a set of objectives (e.g., "minimise cost," "maximise patient throughput," "reduce waiting times to a level that doesn't inspire rioting") and a bunch of constraints (e.g., "we only have three widget-making machines," "there are only 24 hours in a day, surprisingly"), optimisation aims to pinpoint the best set of inputs or decisions.

So, where's the connection? It's beautifully symbiotic.

Imagine you're trying to work out the ideal number of tills to open in a supermarket. Optimisation on its own might struggle. The 'best' number of tills isn't a simple mathematical equation; it depends on customer arrival patterns, how long each transaction takes (which itself can be wildly variable – think of the person paying for a week's shopping in 5p pieces), and the cost of staffing each till.

This is where simulation struts onto the stage. An optimisation algorithm might suggest, "Right, let's try five tills." Your simulation model, packed with realistic customer arrival rates and service time distributions, then runs the scenario. It churns out data: average queue length, maximum wait time, till utilisation, staff costs for those five tills.

The optimisation algorithm looks at this output and says, "Hmm, not bad, but those queues were a bit Lord of the Flies. What if we try six tills?" Back to the simulation. It runs again, provides new metrics. This continues, iteratively. The simulation acts as the evaluation function for the optimisation algorithm. It's the proving ground where the optimiser's bright ideas are put to the test in a close-to-reality environment.

You can't just "optimise" a complex, dynamic system directly in many cases. You need to simulate its behaviour under different conditions to feed the optimisation engine. The outputs from the simulation – average wait times, throughput, resource utilisation – become the very objective functions that the optimisation algorithms aim to minimise or maximise.

Why not just simulate lots of random options? Well, you could, and sometimes a bit of good old full factorial analysis (see Chapter 10 of the book https://www.schoolofsimulation.com/free_book for that gem) helps you explore. But the solution space can be vast. Optimisation provides a more directed, intelligent search for those high-performing configurations, guided by the results of each simulation run.

Essentially, simulation provides the rich, messy, data-driven context. Optimisation provides the disciplined, mathematical approach to navigate that context effectively. Together, they're a powerhouse. Simulation tells you what could happen. Optimisation, informed by simulation, helps you decide what should happen to achieve your goals.

It's this powerful duo that can transform a system from just functioning to genuinely excelling. So, next time you're looking to not just understand your system but to actively improve it, remember that simulation and optimisation are your go-to experts, working best when they work together.

If you're keen to get a firmer grip on how to build these simulations in the first place, my free masterclass "How to Become a Go-To Expert in Simulation with Python" is a good starting point. And if you're really serious, the School of Simulation flagship course dives deep into all of this, equipping you to tackle real-world challenges. For those just starting their Python journey, consider "The 10-Day Python Bootcamp for Engineers and Scientists".