Author: Won Oh (wonsoh@live.com) Paul Won Oh (wonsoh1234@gmail.com)
This environment assumes you are using latest version of Go at the time of writing (version 1.18+).
Please visit Go installation page.
Please make sure your environment variables are properly set for your shell profile (.bashrc, .bash_profile, .zshrc, .profile, etc.)
GOPATH=$HOME/goThe directory for this project needs to be set up under the source directory (src) of your $GOPATH. The project directory for this project is $GOPATH/src/wonsoh.private/cloudkitchens.
mkdir -p $GOPATH/src/wonsoh.private/cloudkitchensThen, please copy all the contents in this directory into the project directory.
cp -r ./ $GOPATH/src/wonsoh.private/cloudkitchensInstall all dependencies by running the following command:
go mod downloadThe project directory setup can be automated by running the following script
./install.shAll the projects are set up.
There are two strategies you can use to run the simulation.
This will run a simulation where a courier is dispatched for a specific order and may only pick up that order.
To run this strategy, run the following command:
./run_matched.shWe used a thread-safe map (concurrent hash map, or sync.Map) for fast lookup (O(1)) (dictionaries, or maps, are good data structures for looking up). We also used channels for notifying between entities (order-to-courier and courier-to-order) and utilized sync.Mutex to prevent deadlocks and for thread-safety.
Alternatively, we could use an infinite-loop (polling) with a sentinel value that breaks upon discovering a courier or order to be picked up from the map (by constantly checking if the value corresponding to the key exists in the map).
This will run a simulation where a courier picks up the next available order upon arrival. If there are multiple orders available, pick up an arbitrary order. If there are no available orders, couriers wait for the next available one. When there are multiple couriers waiting, the next available order is assigned to the earliest arrived courier.
To run this strategy, run the following command:
./run_fifo.shWe used a doubly-linked list (container/list package) for fast-eviction (O(1)) and the nature of ordering (queues are good for FIFO ordering, and a linked-list is an optimal data structure to represent a queue). We also used channels for notifying between entities (order-to-courier and courier-to-order) and utilized sync.Mutex to prevent deadlocks and for thread-safety.
Alternatively, we could use an infinite-loop (polling) with a sentinel value that breaks upon discovering a courier or order to be picked up from the queue (by constantly checking if an element exists in the queue).
You can run comprehensive unit-tests that will run all unit tests and report the coverage for this project.
To run all the unit-tests and view the coverage, run the following command:
./test_with_coverage.sh