Truck haulage simulation animation in Python

In this article I will share a discrete-event simulation animation example in Python. More specifically a truck haul transport simulation animation for a mine, using SimPy and DesViz in Python. This example, and the DesViz module, was developed by Prof. Paul Corry and his team and I am resharing his example in this post. Using DesViz SimPy model developers can animate their simulation model.

Below is an animation of a SimPy truck haul simulation model for mining operations.

The example is documented and available in Paul Corry’s GitHub repository: https://github.com/corryp/DesViz

How can DesViz be used for simulation animation in Python?

Citing directly from the DesViz documentation:

DesViz is a collection of Python classes and functions facilitating asynchronous animation for discrete event simulation (DES) models. It is built on top of the Pyglet package which provides the underlying graphics functionality. DesViz allows a DES model to write a csv file which is later interpreted by DesViz to configure and move sprites representing background and foreground objects in the simulation. Each line of the csv file gives the simulation time, an animation instruction and set of arguments relating to that instruction. These instructions provide a compact method to specify sprite appearance and movements in ways that are useful in a DES context.

DesViz documentation, by Paul Corry

SimPy developers can use DesViz to animate their simulation model, in a two-step approach. First, they must use the DesViz library to generate and store animation data. Next, the animation is used for rendering an animation.

Here are some examples of what you can animate with DesViz:

  • movements from pixel point to pixel point or along predefined paths, with automatic object orientations
  • adjusting object orientations, i.e. animate object rotations
  • define master-slave relationships between objects for animation purposes, e.g. truck (master) and trailer (slave)
  • progress bars, either static or attached to another object (i.e. moving together with the associated object)
  • labeling, annotation, and background images
  • defined animation speed (frame interval, i.e. fps – frames per second)

Under the hood, DesViz populates a database (csv-file) with defined animation instructions. These instructions must be implemented into the simulation application itself. The underlying database is populated during simulation execution and is then used for rendering the animation itself. For this, DesViz provides are range of classes, methods, and functions.

Related content

If you are interested in learning more about discrete-event simulation and related model implementation in Python you might be interested in the following blog posts:

If you are interested in learning more about simulation and its use cases in mining industry you may be interested in the following articles:

You May Also Like

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.