Writing a simulation program in Python

809 views Asked by At

I'm currently busy writing a simulation in Python. I'm simulating the effect of changing the logic by which forklifts store pallets in a warehouse has on travel distance. I'm looking at 5 forklifts, each being assigned jobs to a job list and using mathematical models to assign locations to store the pallets. The area where the pallets are stored is divided into smaller sub-sections. All 5 the forklifts use the same storing area but only one forklift is allowed in a sub-section at a time.

The problem i'm currently facing is whats the best way to write a code so these 5 forklifts do their jobs simultaneously while keeping track of each forklift's position in the storage area and what pallet locations are available.

So far I've written code that does the mathematical models and the movement of a single forklift. I'm currently experimenting with multiprocessing to allow all 5 forklifts moving in parallel. So i create 5 processes, one for each forklift, then in each process I run my mathematical model to find the best pallet placement location. To do the move then however I need to have a global list consisting of the information of where all the other forklifts are and what storing locations are available.

So how do you guys think would be the easiest way to keep track of the information regarding forklift locations and storing locations? Also is multiprocessing the direction I should go to solve this problem?

Thank you in advance.

1

There are 1 answers

4
Mike McKerns On

Your question is very general, so I can at best give you a general answer.

There are codes like klepto and joblib that provide dynamic caching of function calls, so you can declare a function as "cached", and it will store the result (so you don't have to recalculate given the same inputs). I mention this because klepto provides an abstraction for storage to memory, disk, or database… so you can cache/archive results to files on disk, or to a database backend -- both of which can be accessed by parallel processes (and in the case of the database, processes on distributed computing resources). joblib only works with a file backend, and is a little more limited in options, but is a more mature code.

Both klepto and joblib are very commonly used for storage and communication between processes in some form of optimization or predictive science type problem -- which seems like what you are doing.

There are lower-level "roll-your-own" solutions, like picking a database module and using it, or writing to files, or dumping objects to disk with pickle… but joblib and klepto are meant to make the process easy.

https://github.com/uqfoundation/klepto

https://github.com/joblib/joblib