A project for simulating daily flows and customers' behaviour in a supermarket through a Monte Carlo Markov Chain
This project runs a Monte Carlo Simulation for predicting customers' behaviour in a fictional supermarket over a working day. Customers enter the supermarket, freely move through its ailes and then leave the facility.
Fig. 1: The simple architecture of the simulated supermarket |
The data set records the entrance time of each customer into the supermarket; minute by minute, it then follows their path through the ailes of the supermarket and finally to the checkout.
- The CSV files containing the raw daily data are available under
data/daily_attendance/raw
; - The clean and reshaped data set used to run the MCMC Simulation may be found under
data/daily_attendance/cleaned_up
.
The user can follow the various steps of the undertaken data preparation in the Jupyter Notebook Exploratory_Data_Analysis.ipynb
. The Notebook also features a few graphics that provide an insight into the daily flows of customers in the supermarket.
Fig. 2: Rush hours are clearly visible around 9:00, 14:00 and 19:30 |
-
Transition Matrix: Put in a nutshell, the Markov Chain algorithm predicts each customer's next movement based on their last position. This means that each location in the supermarket has to be associated with probabilities for a customer to move from there to any other location (or to remain there). Such a Transition Matrix is elaborated in the module
MCMC_Simulation/transition_matrix.py
based on the information extracted fromdata/daily_attendance/cleaned_up/clean_final.csv
. -
Simulator: The simulation is run by
supermarket.py
. Single customers are simulated as instances of the Python classCustomer
; their location inside the supermarket is updated based on transition matrix. The classSupermarket
allows customers into the simulation in accordance with the described daily flows (fig. 2). When they reach the checkout, customers are removed from the simulation.
Fig. 3: Example simulation |
-
Clone this repository and
cd
into it. -
Install the required Python libraries with
pip install -r requirements.txt
. -
cd
into the folderMCMC_Simulation
. -
To launch the simulation, just run
python supermarket.py
!N.B. One simulated minute equals half a second of real life time, which means that one minute in real life time equals two hours in the simulated supermarket. Therefore, once started, the simulation will run for about seven minutes.
-
You may retrieve the record of each simulation cycle in the folder
MCMC_Simulation/output
.
The code in this repository is an extended and reworked version of the original project developed in collaboration with Behzad Azarhoushang, Laura Bartolini and Vlasis Tritakis.
- Provide customers with a budget to spend into the supermarket.
- Add a tool for the user to visualise the movements of each customer on the supermarket map.
- Tests.