Households, located in the city of Berkeley, CA, periodically have needs for delivery (demand based on a recent census). The stores in the city can answer these needs - and hire a fleet of car drivers to perform the deliveries.
Using a modified supply chain model, we can evaluate the time (and distance) it takes a user to ride between two given places in the city of Berkeley, while being (theoretically) able to add new agents and behaviors (jaywalking, accidents…) that will more realistically mimic traffic simulation, thus giving a more precise estimation.
Here is how this simulation works:
- First, we create the model, i.e. households, stores, via the file
create_supply_chain.js. - Then, we model the demand of a household, using a Poisson distribution (
demand.js) - that will be assigned to the nearest store (choose_order_from.js). More details on how orders are handled are in the fileorders.js. - This demand will lead to the creation, in the simulation, of an agent (a truck), that will carry out the delivery (
deliver.js). It will initialize some variables, such as the distance the truck has to ride, its initial position, color… Note: the behavior of the truck is dictated bytruck.js, and everytime a truck is created / deleted (--> seeremove_self.js), a message is sent to an agent named 'accountant', whose role is to gather data on the simulation. - Trucks navigate along real roads by using the Mapbox message handler (enabled in
globals.json) and making Navigation API calls (seetruck.js). - Once the order is received by the household (
receive.js), the truck agent will be deleted.
Note: the files 'truck_return.js', 'restock.js', and 'experiments.js' are not currently used.
Data and plots:
- Coordinate data for the model is contained in the
globals.jsonfile. - The graphs in the 'Plots' tab are made by sending messages to an agent called accountant (see
accounting.jsfor more details), that will then extract the data contained in the messages for plotting. - The graphs are generated thanks to the
analysis.jsfile.
To extend this to a different city, we need to go into the globals.json file to edit the values in globals.json, as all the values that are refrenced that can change are all listed there. This to more easily scale our work to fit other models of citites.
- "mean_orders_per_day" -- corresponds to the average household size of a city
- "distributors" -- homes modelled as distributors as this is where people leave from
- "manufacturers" -- stores that manufacture the goods that are in demand by the people
- "messageHandlers" -- external APIs that we refrence for the routing -- for us mapbox
- "port_stock_1_capacity" -- capacity of the ports (not touched in our case)
- "port_1_rent" -- cost of rent of ports
- "storage_cost_per_ton" -- cost to store tons of materials inside of ports
- "interest_rate" -- interest rates of the total capital used to maintain chain
- "port_stock_1_alarm_level" -- restock proportion
- "port_stock_replenishment_time" -- how much frames it takes to get new shipments
- "long_trip_truck_capacity" -- how much each truck can carry in capacity
- "long_trip_cost" -- cost of trucks being sent out (flat rate)
- "min_orders_per_day" -- minimum orders per day
- "max_orders_per_day" -- max orders that can be made per day
- "min_quantity" -- minimum quantity of an order
- "max_quantity" -- maximum quantity of an order
- "mean_quantity" -- mean order value
NEEDS for plots:
- Plot the demand as it occurs, so we can compare it to the number of cars
- Plot the time it takes to each car to go from A to B
How to run simulation:
- Create a Hash.Ai account
- Go to this link: https://core.hash.ai/@jacksonle/demandtest_end/main
- Click file
- Click Fork Project
- Name new forked simulation
- Click Start Simulation (right side running man icon)
- Go to the "Geospatial" tab on the top right to view the simulation on a map.
- Go to the "Plots" tab on the top right to view the real time simulated demand and delivery as well as delivery metrics.
Note: Edit parameters listed above in globals.json to manipulate the simulation and test / visualize your new ideas!
Note: To move to a new city, run Yelp web scraping script and replace coordinates in globals.json
How to interpret results:
Geospatial view show us the acutal traffic conditions made by the deliveries that are occuring inside of the city. The blue colored dots are the cars that are interacting with the yellow homes and the red stores.
Plots show the number of active cars at a frame, along with the average number of fixed sized distance steps a car needs to take to complete its delievery. We also have included the total number of simulated steps along with the demand and ordering of each item in the plots.
To modify the graphs, you can go to the analysis.json file to create a new plot section to visualize any other variable that is being tracked by the accountants via message intercepts.
This simulation utilizes HASH's in-built geospatial viewer and ability to retrieve directions from Mapbox. You can read more about these features in the docs: