Logistic Simulation
The concept of deterministic discrete event simulations could be extended to model more interesting scenarios.
Take a look at this imaginary map of locations (cities) and roads connecting them:
Aside from demonstrating my slight fascination with steampunk and games, we could use this map to describe a domain:
- there is a world with locations that are connected by the roads;
- we have trucks that travel on these roads, travel takes time.
How can we find the fastest (not shortest!) path between any two locations: A and B?
One way to approach that is to run a simulation. We will launching truck instances from the location A in all directions at once. At every intersection we will fork and create more instances in all unvisited directions.
Time will move forward. As soon as the first truck instance arrives to location B, we can abort the simulation. The route that this winning truck took would be our fastest route.
Another term for this algorithm is "A* Search". It is described well on wikipedia.
Here is how we could implement the algorithm in Python:
You can read more about this venue in the following articles:
And in following Transport Tycoon Software Katas (I'm linking only the relevant catas):
- S01E01: Write a program to print time it would take to deliver cargo
- S02E01: Find shortest path for travel on a map
- S02E02: Compute ETA with fixed speed
- S02E03: Mine historical data for travel speed
- S02E04: Connect speed model to simulation
🤗 Check out my newsletter! It is about building products with ChatGPT and LLMs: latest news, technical insights and my journey. Check out it out