Customer Stores Choice Model
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Overview
Purpose and Patterns
The model is designed to explore questions about how customers choose which stores to visit given a setting of the location of the stores and customers in a grid. A customer is assumed to favor the store which is near to home location and the waiting time at the store should also be low. Using this, we assume that the "unhappiness" of a customer depends on a linear combination of the travelling time from home to the store and average waiting time at the store over the past visits. At first the customer prefer the store nearest, but as the waiting time grows due to crowd, he/she looks for alternatives and then makes the best decision based on it. We can think of the store selection as a form of "Minority Game", but the with a location factor involved for the agents.
In patterns, we hope to see the trend of the average "unhappiness" of the population over the time, as the customers regurarly make decisions to choose the best store based on the past experiences and distance to store's location. The distribution of the customers at each store and "unhappiness" distribution of the population is also to be observed to draw conclusions about how biased the distribution is on the location of stores. Finally, we observer the pattern of unhappiness over the grid terrain, to conclude the effect of proximity of competing stores to uneven unhappiness distribution around the stores location.
Entities, State variables and scales
The model has mainly the two entities Stores and Customers; the other minor being House entities.
Customers
- ID and location of the home on grid (Each customer is associated with a unique home on the grid))
- Store visit count list (A list which maintains that how many times the customer have visited each store in the past)
- Store total waiting time list (A list which maintains that how much total time customer have spent waiting at each store)
- Rest time (A random value in range(1, MaxRestTime) to decide for how much time, a customer should rest at home before next visit)
- Wait time (Based on the current crowd and quantity, the time for which the customer must wait at store to get the request fulfilled)
- Demand (A random value in range(1, MaxDemanTime) to decide what is the required quantity by the customer while visit to a store)
- Target store ID (On starting a visit to store, the customer decides the best available store)
A state variable or set of state variable to store the current state of person whose value can be one of ["at home", "travelling to store", "at store", "travelling to home"]
Stores
Quantity (The current quantity available at the store, can be negative if the crowd at the store is already waiting at the store for a placed order)
Houses
Marks the home location of the unique customer associated with it.
Scales and Limits
- The landscape is 21 X 21 patches in size with no wrapping at its edges.
There is no time limit to the simulation. The user has to manually stop the go forever button.
Global Variables
Supply rate (same for each store)
- Max quantity of store (same for each store)
- Max Demand of customers for a visit
- Max Rest time of customers after a visit
How to Use (Model Interface)
Model Parameters
Agent Population
- num-consumers: The number of customers in the grid
- num-stores: The number of stores in the grid
Store Parameters
- store-capacity: The maximum quantity any store can hold
- supply-rate: The rate at which the quantity is replenished
Customer Parameters
- person-max-demand (The maximum required quantity by the customer on a visit)
- person-max-rest-time (The maximum time a customer rests at home before next visit)
Procedure Buttons
- Setup: Setup and initialise the whole with the new location of stores and customers
- setup-consumers: Vary the location of customers keeping the location of stores same and reset the time and all entities variables
- setup-stores: Vary the location of stores keeping the location of customers same and reset the customer variables
- go-once: Run the model for a single time step
- go: Run the model forever
- reset-consumers: Reset the customer variables with the time and plots. The location of stores and customers do not change
Visual Tools
- inner-influence-circles? : Whether to display the inner influence circles for each store
- outer-influence-circles? : Whether to diplay the outer influence circles for each store
- show-links? : Whether to display the links between stores and its current customer home locations
- show-unhappiness-terrain? : Whether to color the patches as per the unhappiness distribution over the grid
Plots
- num-customers(Histogram): It shows the current number of customers for each store at the current time
- num-customers-waiting(Histogram): It shows the number of customers at each store which are currently waiting at the store for their demand to be fulfilled
- average-unhappiness(Line plot): Shows the average unhappiness of the customers value over the time
- unhappiness-distribution(Histogram): Show the distribution of the unhappiness over the customers population
Monitors
- average-unhappiness: Shows the current average unhappiness of the customer population
- unhappiness-start-time: The first time when each customer has visited its target store at least once
- std-dev unhappiness: The standard deviation of the unhappiness values of the customer population
- mean inner-influence-radius: The mean of the inner influence radius of the stores
- std-dev inner-influence-radius: Standard deviation of the inner influence radius of the stores
- mean outer-influence-radius: The mean of the outer influence radius of the stores
- std-dev outer-influence-radius: Standard deviation of the outer influence radius of the stores
Store Location Optimization
- move-shops-towards-customers: Moves the stores to the mean coordinate of their current customers home location and reset the customers and plots
- move-shops-towards-unhappiness-customers: Moves the stores the unhappiness weighted mean of their current customers home location and reset the customers and plots
Process Overview and Scheduling
Processes
Logic for Customer
In a single discrete time unit, the execution in the flow chart of customer reaches a "flowchart state" (can be same as previous) from the previous "flowchart state".
The figure below explains the cycle of actions for the customer.
- The customer performs actions as per the current state in the flowchart. Accordingly, it moves or sets some state variables such as restTime, waitTime or completes an order transaction at a store in a single time unit.
- A customer is initially at the home location with a random RestTime between 1 and Max Rest time.
- With every tick, the rest time of the customer decreases by 1, if the customer is at home.
- When the rest time becomes zero, the customer makes a decision to which store to visit based on the store with least unhappiness value. (Unhappiness of a customer with respect to a store = Travelling distance from store + Average waiting time at the store)
- The state of the customer changes from "at home" to "travelling to store" and starts moving towards target-store.
- On reaching the target store, the state of customer is changed to "at store". On visit, the customer updates the quantity at store, the demand value. In case the quantity at the store is less the customer's demand, then the customer has to wait for the given time. WaitTime = (Customer's demand - Quantity at Store) / Supply Rate
- Once the waiting time is over, the customer starts to move towards home location.
- Once reaching the home, the restTime is set in Random(1 , max-restTime).
- When the restTime becomes zero, the customer repeats the above steps starting from making a decision to which store to visit based on unhappiness value for each store for the given customer.
Logic for Store
- At each time unit, the quantity of each store increases by the supply rate.
- If the quantity is more than the capacity of the store, quantity is set to the capacity.
Schedules
- The order in which the customers and stores respectively perform actions is unimportant because there are no direct interactions.
- In our model implementation, first the customer agentset perform the action described in Customer Flowchart. The order of customers execution is random.
- After the customers have performed their respective actions, the stores update the quantity as per the supply rate. The order of stores execution is random and is unimportant.
- In each time unit, customers and stores execute one step in the flowchart moving to a new state (which may be the same as previous state).
- The visual outputs use synchronous updating such as the influence circles are updated at the end of the time step.
- There is no time limit for a run, so the user has to manually stop the go procedure if required.
Design Concepts
Basic Principles
How Customers decide the Stores
There are multiple factors by which a customer decide which store to visit such as travelling distance to the store, waiting time at the store, price, customer service, personal preferences and many more. Here in our models we have taken into consideration the first two factors that are the travelling distance to the store and waiting time at the store.
'Unhappiness' value for a store of a customer Here we define the unhappiness value, as the unsatisfaction of the customer for the specific store. We take it as a linear combination of the travelling distance and average waiting time at the store. The customer keeps track of the average waiting at the store of his/her past visits to it. So we define unhappiness value of a store for a customer as: unhappiness value = Travelling Distance + Average Waiting Time for the customer in past visits In case the customer has not visited a store once, the average waiting time for that store is taken to be 0. THe unhappiness value of the customer for calculating the average unhappiness and unhappiness distribution is taken to be the unappiness associated with its current target-store.
Deciding target store for a customer The store that the customer will be visiting, will be the store which gives the minimum unhappiness value for the customer.
Emergence
The key outcome of the model are the distribution of customers over the stores and the avaerage unhappiness value over the time period. Over the simulation, the customers would try to avoid the crowded stores with a preference of the location. The choices of the customers made over the time is based on the prediction from past experiences. The run of the model can be generally classified into three time phases - the initial phase, decision phase and the stable phase. In the initial phase, the customers are expected to prefer just the nearby store. But as certain store gets crowded, the customers of the specific store look for better alternatives stores. In the decision phase, the customer distribution keeps on changing as per the decision and crowd at the store and the average unhappiness values goes over a period of ups and downs. Finally after a long run, in stable phase, the average unhappiness value is expected to stabilise as the customers have made choice preferences based on the past visits to each store.
Adaptation
Deciding the target store When the customer wants to visit a store, it has to make the decision that which store it must visit. The choices available to each customer are all the stores on the grid. The decision is modeled as direct objective seeking, explained below.
Objectives
Direct Objective Seeking When deciding which store to visit, the customer chooses the store which gives the minimum unhappiness value to the customer. The unhappiness value as mentioned before is the sum of travelling time (taken as travelling distance here) and average waiting time at the store in past visits. In case the person has not visited the store before, then the waiting time for that store is taken to be zero. Each customer maintains the visit counts for each store, hence gets the average waiting time as (Total waiting time for the customer in past visits to the store) / Number of visits.
To minimize the unhappiness value Each customer is making choices seeking to reduce its unhappiness value over the time. Due to each customer continuosly looking for better store alternatives, some stores over time get crowded forcing its existing customers to prefer other store alternatives.
Learning
The average waiting time and thus the decision to choose the store based on minimum unhappiness value depends on the past experience of the customer at the store. As part of past experience, a customer maintains visit count to each store and the total waiting for the customer at the store in past visits, using this memory the customer calculates the average waiting time factor in unhappiness. In case the customer has not visited the store at least once, the initial waiting time is assumed to be 0 for the customer.
Prediction
Implicit Prediction The adaptive behaviour of the customers is based on implicit prediction that choosing the store with minimum unhappiness value is likely to minimize the unhappiness value of the customer.
Sensing
Customers
- Customers store the location and ID of the unique house agent associated with it.
- When a customer reaches it target store, it will know the current quantity (inventory) available at the store. It updates its waiting time at the store based on the available quantity at the store and its demand.
- Customer knows the location of each store and its distance from its home location.
- Customers sense the crowding at a store indirectly via the calculated waiting time at the store.
- Customer update the quantity of the target store upon reaching as per the its current demand.
- Customer all keeps track of its past experiences for each store.
Stores
- Stores can sense the number of customers associated with the store using the links between the stores and houses of current customers.
- Using the links connecting store and house locations of its current customers, the store can detect the distances of the current customers to its location.
Houses
- Each House is associated with a unique customer.
Interaction
Mediated Interaction between customers The customers interaction is mediated by the resource that they compete for, each customer is seeking to minimize its unhappiness value. A customer thus prefer less crowded stores over the more crowded ones, as it has to wait longer due to crowding at a store. As the number of stores and supply-rate is limited, the customers compete over the choices of the stores to get better experience.
Direct Interaction between stores and customers When a customer reaches its target store, it updates the quantity available at the store as per its current demand. When the quantity available at the store is less than the demand, then the customer has to wait at the store for time = (demand - quantity at store) / supply-rate.
Stochasticity
- Uniform Random location of the customers and stores: In the beginning the customers at their associated home and the stores are located randomly over the grid.
- RestTime: The time for which a customer must rest at home before going for next visit to store is random uniform in range 1 to person-max-rest-time.
- Demand: The quantity required by a customer during a store visit is random uniform in range 1 to person-max-demand.
- The order in which customers execute is random, to avoid bias on different customers arriving at same time at a store.
Collectives
There are no major collectives in the model. A minor case of collective in the model is the group of customers that belong to the same store. Their behaviour such as the demand value, rest time and distance from the store affects the other individual customers of the same store. Based on the arrival time and waiting at the store of the customer group, the individual customers may choose alternative stores.
Observation
The models purpose is study the customer distribution and average unhappiness over the time. Also, the unhappiness distribution over the terrain and customer population. We also observe the influence of different stores based on the current setting of their location and proximity to other competing stores.
Graphical Output
- The color of the customer agent and its associated house shows where does its current unhappiness value lie in the unhappiness distribution of the population.
- Blue (Happiest ones) -- if the unhappiness value is below the mean - standard deviation of the distribution
- Green (Happy) -- else if the unhappiness value is below the mean of the distribution
- Orange (Unhappy) -- else if the unhappiness value is above the mean of the distribution
- Red (Unhappiest ones) -- if the unhappiness value is above the mean + standard deviation of the distribution
- The color of the patch shows a lighter tone of the color of the nearest house to the patch.
- Links between the stores and houses, shows the location of the house of the current customers of the store.
- The inner influence circles (every house inside the circle is the customer of the specified store only) and outer influence cirlces (show the distance from which the farthest customer is coming to the store)
Plots
- The distribution of customers over the stores (Histogram): Shows how many customers each store has at the current time
- The distribution of waiting customers over the stores (Histogram): Shows how many customers are currently waiting at each store
- Average Unhappiness (Line): The line plot shows how the average unhappiness varies over the complete simulation
- Unhappiness distribution over population (Histogram): Shows the count distribution of the unhappiness values over the population Output Monitors
- Average Unhappiness value: The mean value of unhappiness value over the population (The unhappiness value for a customer is its unhappiness associated with its current target store)
- Standard Deviation of Unhappiness in Population: The standard deviation of the unhappiness values over the population
- Mean of inner influence radius: The mean of the inner influence radius of the stores
- Unhappiness Start Time: The first time at which each customers has visited at least one of the stores since the beginning of the simulation
- Standard Deviation of inner influence radius: The standard deviation of the radius of inner influence of the stores
- Mean of outer influence radius
- Standard Deviation of outer influence radius
Details
Initialization
- The location of the stores and customers is random over the grid.
- The intital quantity at each store is the store-capacity. The inventory at stores are assumed to be full in the beginning.
- The customers are located at the same location as the associated unique house.
- The visit count for each customer to each store is initialised to zero and the total waiting time for each store is zero as well.
- All the customers at the start are in "at home" state with a uniform random rest time in range 1 to max-person-rest-time.
- The color of the patches is initialized to some same color.
- The house id and house coordinates of the customer is set according to the house uniquely associated with the customer.
Input data
The model does not use input data to represent the time-varying processes.
Submodels
Parameters to the Model
- Supply rate (same for each store)
- Max quantity of store (same for each store)
- Max Demand of customers for a visit
- Max Rest time of customers after a visit
Generating the house and customer pairs
- For generating the house and customer pairs, first the customers are generated uniform random in the grid.
- Then each customer sprouts a house and the customer then stores its ID and location.
Average Unhappiness Reporter
- For calculating the average unhappiness, only those customers were considered which have at least visited the target store once.
- This was done to avoid unexpected trends in average unhappiness, due to many customers which are visiting the store for first time and the average waiting for that visit was thus taken as zero.
- Thus the mean is taken for the unhappiness values of the customers who have visited the current target store at least once.
Calculating the Inner and Outer Influence circles
- For the inner influence radius, the distance of the closest customer to the given store who is currently customer of any other store is taken.
- The outer influence raius, is the distance of the farthest current customers of the given store.
Moving stores to Mean Location of current customers with and without unhappiness weights
- We used these procedures to see if the store location can be optmized in the given distribution of customers over the grid.
- In attempt 1, after running the model for a long time, we can change the location of each stores as the mean coordinate of its current customers.
- In attempt 2, we move the stores to the unhappiness weighted mean coordinate of its current customers. That is x-coordinate = ( Sum(Unhappines of customer * x-coordinate of the customer) )/ (Number of customers of the given store). Similarly y-coordinate = (Sum(Unhappines of customer * y-coordinate of the customer)) / (Number of customers of the given store).
Extending the Model
- In our model, we have only assumed a single type of commodity being sold by the stores. We can extend the model by having more than one commodities with different supply-rates for each commodity.
- Further the stores are assumed to have same suppy-rate, we can have different supply-rate for different stores. Different supply rates would signify the different production or procurement rate at the stores. Such as restaurent with larger cooking staff will have higher supply-rate of the quantities.
- The customer in our model, keeps track of all the past visits to each stores. We can implement a limit to the memory of the customer, such that the customer only remembers about the past 'n' visits.
- There can be customers influencing the customers that reside near their home location about the preference for the stores.
Related Models
Minority Game
- At each step the minority agent group wins and their strategies are rewarded.
- We can think of our model as minority game on different stores, each person tries to avoid crowded stores but there is a cost factor of distance involved.
El Farol
- The problem also deals with reduced customer satisfaction when the customer finds the bar crowded during a visit.
- The agents here work on strategies seeking to visit the bar when it is uncrowded.
Kolkata Paise Restaurant Problem
- It is a variant of El Farol problem where customers have to choose between many restaurants.
- Each restaurant serves a limited number of customers and rest are not serviced.
- In our model as well, each customer has to decide which store to visit, but crowded stores result in long waiting times rather than denial of service.
Comments and Questions
breed [persons person] breed [stores store] breed [houses house] ;; the start-time (unhappiness start-time) is the first time when each customer have visited the target store at least once ;; the unhappiness-values-list keeps track of the unhappiness values of the population of the customers for calculation of standard-deviation globals [start-time unhappiness-values-list] persons-own [house-id home-xcor home-ycor ;; who-number of the home belonging to person, the x-coordinate and y-coordinate of the home store-travel-time-list store-visit-count-list store-total-waiting-time-list ;; store-travel-time-list contains the list of travel-distance from home to each store, store-visit-count-list contains the total number of visits by the person to each store ;; store-waiting-time-list contains the total waiting time for each store in the past visits of the person rest-time wait-time demand target-store-id ;; how much time the person will rest at home after returning from store ;; what is the quantity of the item that person requires in current visit to store ;; in the beginning of journey, the person decides which store to visit, the who of target store is saved in target-store-id at-home? at-store? travelling-to-store? travelling-to-home?] ;; the state variables, at-home is true if the person is at home, travelling-to-store if on way to store, travelling-to-home if on way to home, at-store if at store currently stores-own [quantity] ;; every store keeps track of its current quantity ;; Reports the current average-unhappiness of the population ;; A person's unhappiness for a given store = Avg. Waiting Time at the store + Travel Time for the store (proportional to distance of store from home) ;; A person's unhappiness is counted towards average unhappiness, only when the person has visited the current targeted store at least once. ;; ^ This is to avoid bad unhappiness values when the person is yet to experience the target store atleast once to-report average-unhappiness ;; Initialize the list for the unhappiness values of the customers set unhappiness-values-list [] ;; The number of customers which have actually experienced the target-store at least once let actual-num-consumers 0 ask persons [ ;; If the person has visited the target store at least once if (item target-store-id store-visit-count-list) > 0 [ ;; insert its unhappiness value in the unhappiness list for the population set unhappiness-values-list lput store-unhappiness target-store-id unhappiness-values-list set actual-num-consumers actual-num-consumers + 1 ] ] ;; If all of the customers have atleast experienced their current target store at least once, then set the current time as the start-time if actual-num-consumers = num-consumers and start-time = 0 [set start-time ticks] ;; color the customers and houses as per the unhappiness distribution ;; report the standard-deviation and mean of the unhappiness if the actual numbers of customers are greater than 2 if (actual-num-consumers >= 2) [ let std-dev-unhappiness standard-deviation unhappiness-values-list let mean-unhappiness mean unhappiness-values-list ;;set the colors of the customer and house agents set-customer-unhappiness-colors std-dev-unhappiness mean-unhappiness ;; If the user has turned ON the visual tool to show the unhappiness distribution over the patches, then color the patches accordingly ;; otherwise set all the patches to turquoise color ifelse (show-unhappiness-terrain?) [show-unhappiness-terrain] [ ask patches [set pcolor turquoise] ] ] ;; report the average unhappiness value ifelse actual-num-consumers > 0 [report mean unhappiness-values-list] [report 0] end ;; sets the color of the customers and houses as per the current unhappiness value in the population distribution to set-customer-unhappiness-colors [std-dev mean-val] ask persons [ ;; get the unhappiness value of the customer let person-unhappiness store-unhappiness target-store-id ;; red color for person with unhappiness more than mean value + standard-deviation (ifelse (person-unhappiness >= mean-val + std-dev) [set color red] ;; orange color for person with unhappiness above mean (person-unhappiness >= mean-val) [set color orange] ;; sky color for unhappiness below the mean-value - standard deviation, the happiest of the customers (person-unhappiness < mean-val - std-dev) [set color sky] ;; rest green color for below mean [ set color green]) ;; set the same color for the house as of the associated customer ask house house-id [set color [color] of myself] ] end ;; set the color of the patches as per the color of the nearest house (denoting the unhappiness value of customer residing in the region) to show-unhappiness-terrain ask patches [ ;; local variable to store the new color value of the patch let my-new-color 0 ;; get the color of the nearest house to the patch ask houses with-min [distance myself] [ set my-new-color [color] of self ] ;; set a lighter tone for the patch color set pcolor my-new-color + 2 ] end ;; reports the first time, when all of the customers have experienced their target store atleast once to-report unhappiness-start-time report start-time end to setup clear-all ask patches [set pcolor turquoise] ;; initialize the unhappiness start-time to 0 set start-time 0 ;; setup the stores in the grid setup-stores-initial ;; setup the persons in the grid setup-homes-and-consumers ;; initialize the lists and initial state variables for the persons ask persons [ initialize-person-lists-and-state ] reset-ticks end ;; if we want keep the location of stores same, but want to try a new location of consumers to setup-consumers clear-all-plots ask patches [set pcolor turquoise] ;; initialize the unhappiness start-time to 0 set start-time 0 ;; kill all the persons and houses and generate a new set of customers and houses with different location ask persons [die] ask houses [die] ;; reset the quantity in the stores ask stores [set quantity store-capacity] ;; generate the customer and house pairs in the grid setup-homes-and-consumers ;; intialize the lists for each consumer ask persons [initialize-person-lists-and-state] reset-ticks end ;; if we want to keep the same location of consumers, but want to try a new location for shops to setup-stores clear-all-plots ;; initialize the unhappiness start-time to 0 set start-time 0 ;; set a unifrom random location of the stores ;; intially the inventory (quantity) at each store is full ask stores [ setxy random-xcor random-ycor set quantity store-capacity ] ;; initialize the list and state variables of the customers ask persons [initialize-person-lists-and-state] reset-ticks end ;; create the stores in the grid to setup-stores-initial create-stores num-stores [ setxy random-xcor random-ycor set shape "building store" set color yellow set size 1.5 ;; intially the inventory (quantity) at each store is full set quantity store-capacity ] end ;; move each of the store to the average coordinate of its current customers to move-shops-to-customers ask stores [ let num-customers count link-neighbors let mean-x-customer mean [xcor] of link-neighbors let mean-y-customer mean [ycor] of link-neighbors ;; move the store to the mean coordian setxy mean-x-customer mean-y-customer ] reset-consumers end ;; move the store to the unhappiness weighted mean coordinate of its current customers to move-shops-to-unhappiness-customers ask stores [ let current-store-id [who] of self ;; the total unhappiness of current store customers let total-customer-unhappiness 0 let mean-unhappiness-x-customer 0 let mean-unhappiness-y-customer 0 ;; ask the houses of its customers ask link-neighbors[ let current-house-id [who] of self ;; get the customer who is associated with this house let person-here persons with [house-id = current-house-id] ;; ask the customer associated with this house ask person-here [ let unhappiness-value store-unhappiness current-store-id ;; take the weigted x and y coordinate of the customer set mean-unhappiness-x-customer mean-unhappiness-x-customer + (xcor * unhappiness-value) set mean-unhappiness-y-customer mean-unhappiness-y-customer + (ycor * unhappiness-value) set total-customer-unhappiness total-customer-unhappiness + unhappiness-value ] ] ;; finally get the unhappiness weighted customer coordinates set mean-unhappiness-x-customer mean-unhappiness-x-customer / total-customer-unhappiness set mean-unhappiness-y-customer mean-unhappiness-y-customer / total-customer-unhappiness setxy mean-unhappiness-x-customer mean-unhappiness-y-customer ] reset-consumers end ;; reset the customer variables and set the location to its home location ;; reset the quantity of the store as well to reset-consumers clear-all-plots set start-time 0 ;; reset the quantity in the stores ask stores [set quantity store-capacity] ;; intialize the lists for each consumer ask persons [initialize-person-lists-and-state] reset-ticks end ;; create the customer and the associated house pairs on the grid to setup-homes-and-consumers ;; create persons/consumers create-persons num-consumers [ setxy random-xcor random-ycor ;; the initial location will be the location of person's home as well set home-xcor xcor set home-ycor ycor set shape "person" set color blue ;; store the current person in local variable parent let parent self ;; ask the patch on the where the person is standing to create an agent of breed house ask patch-here[ sprout-houses 1 [ set shape "house" set color blue ;; store the who number of house in local variable of the associated customer let current-house-id who ;; ask the customer stored as parent, to set its house-id to the who number of this house ask parent [ set house-id current-house-id ] ] ] ] ;; reset the unhappiness values of the population list set unhappiness-values-list [] end ;; initializes the calling customer's lists and initial-state to initialize-person-lists-and-state ;; calculate the travelling distance to each store set store-travel-time-list n-values num-stores distance-from-store ;; initialize visit count for each store to zero set store-visit-count-list n-values num-stores [i -> 0] ;; initialize the total waiting time for each store to zero set store-total-waiting-time-list n-values num-stores [i -> 0] ;; set the initial state of person as at home set at-home? true ;; initialize the rest-time of the person set rest-time random person-max-rest-time ;; place the person at associated house setxy home-xcor home-ycor end ;; reports the euclidean distance from calling customer's house to the store with given who number as store-id to-report distance-from-store [store-id] let distance-to-store 0 ;; store the distance from home to store in distance-to-store variable ask house house-id [ set distance-to-store distance store store-id] ;; resport the distance report distance-to-store end ;; reports the best store option for the calling customer depending on the unhappiness values ;; unhappiness for a store = distance-from-home + (average waiting time at the store) to-report best-store-option ;; prepare the unhappiness value for each store and store in a local variable - list let store-unhappiness-list n-values num-stores store-unhappiness ;; find the minimum unhappiness value let min-unhappiness min store-unhappiness-list ;; report the index (who of the store in this case) with the given minimum unhappiness-value report position min-unhappiness store-unhappiness-list end ;; reports the unhappiness for a particular store for the calling customer ;; unhappiness for a store = distance-from-home + (average waiting time at the store) to-report store-unhappiness [store-id] ;; initally unhappiness = distance-from-home let unhappiness item store-id store-travel-time-list ;; add average waiting time for the store to the unhappiness value, if the number of visits to the store > 0 if (item store-id store-visit-count-list) > 0 [ set unhappiness unhappiness + (item store-id store-total-waiting-time-list) / (item store-id store-visit-count-list) ] ;; report the unhappiness value report unhappiness end ;; display the inner influence circles for each store ;; every house strictly inside this radius is a customer to calling store only, not to any other store to-report inner-influence-radius let current-store self ;; the list of the houses of the current customers of the store let current-store-link-neighbors link-neighbors ;; report the distance of the nearest home which is a customer of another store report min [distance current-store] of houses with [not member? self current-store-link-neighbors] end ;; the distance of the home of the farthest customer for the store ;; this is the radius of the star network of this to-report outer-influence-radius let current-store self ;; report the distance of the home of the farthest customer report max [distance current-store] of link-neighbors end to go ;; perform the following actions for each customer ask persons[run-consumer-finite-state-logic] ;; increase the quantity in each store by the supply-rate ask stores [ set quantity quantity + supply-rate ;; if the quantity of the store goes above its capacity, set quantity to exactly its capacity if quantity > store-capacity [set quantity store-capacity] ] ;; clear all the previous drawings clear-drawing ;; display inner-circles if inner-influence-circles? switch is ON if inner-influence-circles? [display-inner-influence-circles] ;; display outer-circles if outer-influence-circles? switch is ON if outer-influence-circles? [display-outer-influence-circles] ;; hide links if show-links? switch if OFF ask links [set hidden? not show-links?] tick end ;; contains the logic of customer for the go procedure to run-consumer-finite-state-logic ;; fetch the target store via the target-store-id let target-store store target-store-id (ifelse ;; if the person is currently inside home at-home? = true [ ;; if the person at home doesn't need rest ifelse rest-time = 0 [ ;; set demand to a random value over the range set demand random person-max-demand let person-home house house-id ;; kill the link with previous target-store ask target-store[ let link-with-person-home link-with person-home if link-with-person-home != nobody [ ask link-with-person-home [die] ] ] ;; calculate the best store, as per the unhappiness values set target-store-id best-store-option ;; update the target-store local variable as well set target-store store target-store-id ;; create a link between updated target-store and home of the person ask target-store[create-link-with person-home ask link-with person-home [set color red]] ;; set at-home to false, set travelling-to-store to true set at-home? false set travelling-to-store? true] ;; otherwise if the person requires rest, then person stays at home and rest-time is decreased by 1 [set rest-time rest-time - 1] ] ;; if the person is on its way to store travelling-to-store? = true[ ;; if reached the store (that is when distance from store is less or equal to one) ifelse distance target-store <= 1[ ;; move inside the shop setxy [xcor] of target-store [ycor] of target-store ;; travelling-to-store is set to false and at-store set to true set travelling-to-store? false set at-store? true ] ;; if still far from store, then face towards the store and move 1 step forward [ face target-store fd 1] ] ;; if the person is inside store at-store? = true [ ;; try to get the demand fulfilled ifelse demand > 0 [ ;; initialize the wait-time if the quantity at store is less than the demand of person if [quantity] of target-store < demand [ set wait-time floor (( demand - [quantity] of target-store ) / supply-rate) ] ;; increase the store visit count and total waiting time for the store accordingly set store-visit-count-list replace-item target-store-id store-visit-count-list (item target-store-id store-visit-count-list + 1) set store-total-waiting-time-list replace-item target-store-id store-total-waiting-time-list (item target-store-id store-total-waiting-time-list + wait-time) let person-demand demand ;; update the quantity at the store and the demand is fulfilled, set it to zero ask target-store[set quantity quantity - person-demand] set demand 0] [ ;; if waiting is over ifelse wait-time = 0 [ ;; move outside the store and get on way back to home set at-store? false set travelling-to-home? true] ;; if still needs to wait, decrease wait-time by 1 [set wait-time wait-time - 1]] ] ;; if is travelling to home travelling-to-home? = true [ ;; if reached near home ifelse (distancexy home-xcor home-ycor) <= 1 [ ;; move inside home and set travelling to home as false setxy home-xcor home-ycor set travelling-to-home? false ;; set a rest-time uniform random in range 1 to person-max-rest-time set rest-time random person-max-rest-time set at-home? true ] ;; if far from home, face towards home and move forward one step [ facexy home-xcor home-ycor fd 1]] ) end ;; display the inner influence circle for the calling store-agent to display-inner-influence-circles ask stores [ let distance-influence inner-influence-radius stamp-circle "circle" distance-influence ] end ;; display the outer influence circles for the calling store-agent to display-outer-influence-circles ask stores [ let distance-influence outer-influence-radius stamp-circle "circle 3" distance-influence ] end ;; to draw the influence circles on the grid ;; it stamps a shape of given size as "distance-influence * 2" ;; parameters are drawing-shape, the shape of the stamp, distance-influence, the radius in case of circles to stamp-circle [drawing-shape distance-influence] ;; store-xcor and store-ycor stores the coordinates of the current store let store-xcor xcor let store-ycor ycor ;; ask the patch-here to create a circle turle, then stamp and then die ask patch-here[ sprout 1[ ;; set the center of the turtle at the store setxy store-xcor store-ycor set shape drawing-shape ;; lighten the shade of the color set color color + 1 ;; make the turtle half transparent set color lput 125 extract-rgb color ;; set appropriate turtle-size for the set size 2 * ( distance-influence ) ;; mark the color impression of the turtle and make it die stamp die ] ] end
There are 3 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Customer Stores Choice Model.pdf | Research Paper | over 4 years ago, by Sachin Yadav | Download | |
Customer Stores Choice Model.png | preview | Preview for 'Customer Stores Choice Model' | over 4 years ago, by Sachin Yadav | Download |
customer_logic.png | png | Customer Logic Flowchart | over 4 years ago, by Sachin Yadav | Download |
store_logic.png | png | Store Logic Flowchart | over 4 years ago, by Sachin Yadav | Download |
This model does not have any ancestors.
This model does not have any descendants.