Restaurants

Restaurants preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0beta1 • Viewed 572 times • Downloaded 35 times • Run 0 times
Download the 'Restaurants' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This simulates the competition in a a single industry, in this case the restaurant industry. Each restaurant is controlled by an owner trying to maximize profit. Depending on the owners' decisions, the outcome may demonstrate the Efficient Market Theorem ("Pareto efficiency"): if all the agents within a market look out for their own best interest, it will lead to the most efficient outcome. In this case it means that if the restaurant owners try to maximize their own wealth it will also maximize the customer satisfaction.

HOW IT WORKS

Students act as restaurant owners. Each student is given one restaurant to control and starts with 2000 dollars in his/her account. There are computer-controlled consumers that move around and may choose to become customers in restaurants of their choice. Their color shows which food they like. For instance, a red client likes food that can be found in the red restaurants ('American' cuisine).

Each day the customers decide to eat at a restaurant. In order to try and persuade the customers to come and eat at their restaurants, the owners (the students) have several options they can control: PRICE, QUALITY, SERVICE, and CUISINE. The PRICE slider sets the price of a meal at the restaurant. The QUALITY slider sets the quality of the meal at the restaurant. The SERVICE slider affects the quality of service and appeal of the restaurant (staff and decor quality). Finally the CUISINE determines the type of food the restaurant serves. The owners may change these variables freely during the day.

The quality and service that restaurant offer as well as renting the space all come at a price to the restaurant owners. These prices per quality and per service are set on the server interface. At the end of the day the profit of each owner is calculated and added to his/her account balance and the process repeats.

Initially, each participant will be feeling their way around the market place with different settings. Then as competition continues with each owner trying to maximize profits, the various restaurants proceed to establish themselves in the market place. While the owners continue to aggressively look to attract the most customers and maximize profits, the customers actually begin to benefit. This can be seen in the three plots: average profit (of restaurants), disgruntled customers, and customer satisfaction. The average profit of the restaurants will decrease as the competition heats up and, due to the competition, the number of disgruntled customers will drop and customer satisfaction will rise.

HOW TO USE IT

Quickstart Instructions: (these instructions also appear at the top of the Interface) Teacher: Follow these directions to run the HubNet activity. Press the SETUP button, then Press the INITIAL LOGIN button.

Everyone: Open up a HubNet Client on your machine, input the IP Address of this computer, press ENTER, type your name, and press ENTER.

Teacher: Once everyone has logged in, turn off the INITIAL LOGIN button by pressing it again. Have the students acquaint themselves with their interface. Teacher: Press GO to start the simulation. Each student is a restaurateur. The customers are independent computer agents. Following are some additional features you might want to adjust for later runs: NUM-CUSTOMERS determines the number of customers: set this before you run the game. The following conditions can be changed either before or while the game is running: If SHOW-RANK? is on, the students are able to see their ranking amongst all restaurateurs. If BANKRUPCY? is on, then students might go bankrupt. Use the cost sliders, QUALITY-COST, SERVICE-COST and RENT-COST to adjust costs. CUSTOMER-ENERGY determines the beginning energy of the customer. CUSTOMER-THRESHOLD determines the threshold at which a customer gets hungry. To create some automated restaurants set the AUTO-RESTAURANTS slider and press CREATE-AUTOMATED-RESTAURANTS. Teacher: To rerun the activity with the same group, un-press GO, adjust settings, press RE-RUN then GO. Teacher: To start the simulation over with a new group, follow our instruction set again.

Buttons: SETUP - clears all turtles, patches and plots. The setup button should only be pressed when beginning a new simulation with a new group of users, otherwise all the data from the old simulation will be lost. INITIAL LOGIN - allows users to log into the activity without having to start the simulation. GO - runs the simulation. RE-RUN - sets up the model to be ready for another run of the simulation with the same users. CREATE AUTOMATED RESTAURANTS - creates as many automated restaurants as the '#AUTO-RESTAURANTS' slider is set to. RESET INSTRUCTIONS - resets the Quickstart instruction menu to the beginning of the instructions. PREV - displays the previous line of the Quickstart instructions in the monitor. NEXT - displays the next line of the Quickstart instructions in the monitor.

Sliders: NUMBER-CONSUMERS - the total number of consumers in the market place. QUALITY-COST - the cost of increasing the quality of the restaurant. RENT-COST - the amount of money rent costs each day. SERVICE-COST - the cost increase per each point spent on service. CUSTOMER-THRESHOLD - the energy level at which customers become hungry. CUSTOMER-ENERGY - the energy level at which customers start at and are restored to after eating. #AUTO-RESTAURANTS - the number of automated owners to create. (To create the owners press the CREATE AUTOMATED RESTAURANTS button after adjusting the slider).

Switches: SHOW-RANK? - when on, ranks the restaurant owners by their account balance (the rank appears in the clients' monitors only). When off, the ranks of the owners are not displayed in the clients' monitors. BANKRUPTCY? - when on, allows owners to go bankrupt when their account balance goes below zero.

Monitors: AMERICAN CUISINES - the number of American cuisines in the market place. ASIAN CUISINES - the number of Asian cuisines in the market place. EUROPEAN CUISINES - the number of European cuisines in the market place. DAY - what day the simulation is in.

Plots: CUSTOMER SATISFACTION - plots the maximum, minimum and average restaurant satisfaction of the customers. DISGRUNTLED CUSTOMERS - plots the number of consumers who cannot find a restaurant to their liking each day. PROFITS - plots the profits over a period of a day of all the user-controlled restaurants as well as an average (in black). # CUSTOMERS - plots the number of customers who attended each user-controlled restaurant over the period of a day as well as an average (in black).

Client Information: After login is completed the Restaurants client interface will appear for each of the participants, including a restaurant color which will be displayed in the RESTAURANT COLOR monitor. Participant are each credited with 2000 in their individuals accounts balance and the starting settings PRICE, QUALITY, SERVICE and RESTAURANT TYPE are set to random variables.

The client interface contains a number of monitors which contain personal information regarding the participant. ACCOUNT BALANCE states the amount of money that the participant currently has, and RANK shows the participants ranking out of all the owners based on account balance when the SHOW-RANK? switch is in the 'On' position. When the BANKRUPTCY? switch is on, the BANKRUPT monitor shows whether the restaurant is bankrupt. The PROFIT / CUSTOMER monitor shows the amount of money that is made from each additional customer that the restaurant receives for the current day. DAYS REVENUE and DAYS COST show the amount of revenue and costs accumulated during the current day. The RESTAURANT PROFITS and RESTAURANT CUSTOMERS plots show graphs of all the user controlled restaurants (these two plots mirror two of the four plots on the server interface). Finally, DAY shows the day that the simulation is currently on.

The participant is able to control the restaurant by using the SERVICE, PRICE, and QUALITY sliders as well as the CUISINE choice. The participant is able to change all these settings at any time during the simulation. The SERVICE slider controls the quality of the service (waiting staff) at the restaurant. By increasing the SERVICE slider customers will perceive a better meal and a lower price for the meal, all in all increasing the restaurant's appeal. The choice of CUISINE is crucial as it determines which niche the participant enters in the market. The PRICE and QUALITY sliders set the price and the quality of the meal in the restaurant.

The participants can track their own progress in the RANK monitors and aim for the greatest possible account balance.

THINGS TO NOTICE

The two things to notice in this simulation are in the two plots. As the simulation goes on there should be a downward trend of the avg. profit due to the increased competition between the restaurants, and more importantly there should be a constant increase in the average customer satisfaction value throughout the simulation. The maximum customer satisfaction should also increase along with the average value, the minimum is dependent however on how many automated owners are used. If the amount of actual participants is fairly low, below 7, and the rest are automated, then the minimum value will never rise, as some customers will be eating at the automated restaurants which don't change their variable. The increase of the average customer satisfaction is the important aspect as it is the emergent phenomena of the free market theorem.

THINGS TO TRY

Initial Settings: Number-Customers: 350 Show-Rank?: on Bankruptcy?: off

Quality-Cost: 0.20 Rent-Cost: 100 Service-Cost: 0.20

Customer-Threshold 30 Customer-Energy 50

Initial Run: The first time the simulation is run with the participants, do not allow any collusion between the participants. In other words, make sure that they at least try not to reveal their variable values to their neighbors. This will make the environment more like a free market system.

However you can choose to run the simulation a second time and tell the participants that they are allowed to share their personal variables with all the other participants if they would like.

What differences appear between the plots in the two different simulations? How did the ability to collude with others change the results of the second simulation?

EXTENDING THE MODEL

Currently, the automated restaurants do not change their product the way that real users of this simulation so. If they did, it would allow the simulation to run smoother with a lower number of actual participants. Add code so that the automated owners will change their variables when they notice their profit decrease by a significant amount.

NETLOGO FEATURES

This model uses the create-temporary-plot-pen function to plot the the day's profit for all of the user-controlled restaurants.

RELATED MODELS

See the Social Science models in the NetLogo models library. 'Wealth Distribution,' for example, deals with similar content as this model -- the human economical behavior in a free market. Also see the HubNet activity 'Tragedy of the Commons' for a simulation of economical aggression under the conditions of limited resources.

CREDITS AND REFERENCES

This model simulates an Economics concept associated with Vilfredo Pareto. See V. Pareto, Manuale d'economia politico (Milan,1906).

Thanks to Ben Neidhart for his work on this model.

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

COPYRIGHT AND LICENSE

Copyright 2004 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This activity and associated models and materials were created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

Comments and Questions

how about a auto restaurant ? (Question)

hello, i'm new with netlogo and want to create a auto restaurant ,that have to person working in there and people come randomly and i want to simulat how many hours they will work can you please help me ? thanks alot

Posted over 8 years ago

Click to Run Model

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variable and Breed declarations ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

globals [
 day                  ;; number of days so far

 ;; Color globals
 colors               ;; list that holds the colors for the student's restaurant
 color-names          ;; list that holds the names of the colors used for the student's restaurants
 num-colors           ;; number of different colors in the color list
 used-colors          ;; list that holds the colors that are already being used

 ;; quick start instructions variables
 quick-start          ;; current quickstart instruction displayed in the quickstart monitor
 qs-item              ;; index of the current quickstart instruction
 qs-items             ;; list of quickstart instructions

 n/a                  ;; unset variable indicator
]

patches-own [ ]

breed [ restaurants restaurant ]         ;; controlled by the clients
breed [ customers customer ]             ;; created by the server

customers-own [
 ;; Customer Preferences
 customer-cuisine        ;; the preferred cuisine type
 customer-taste          ;; the preferred quality of the cuisine
 customer-money          ;; the maximum amount of money the customer can spend on a meal

 ;; Restaurant Appeal
 appeal               ;; how appealing the restaurant is to the customer
 persuaded?           ;; has the customer been persuaded to go to a restaurant
 my-restaurant           ;; by which restaurant has the customer been persuaded

 ;; Eating Patterns
 energy               ;; amount of energy the customer has
]

restaurants-own [
 ;; Owner Information
 user-id              ;; unique user-id, input by the client when they log in, to identify each student's restaurant
 auto?                ;; is the owner automated
 bankrupt?            ;; is the owner bankrupt
 account-balance      ;; total amount of money the owner has

 ;; Ranking Statistics
 received-rank?       ;; if given a rank, ranked? is true, otherwise false
 rank                 ;; rank number according to account balance

 ;; Restaurant Information
 restaurant-color        ;; color of the restaurant

 ;; Restaurant Taste Profile
 restaurant-cuisine      ;; the type of cuisine the restaurant serves
 restaurant-service      ;; the quality of the service
 restaurant-quality      ;; the quality of the food
 restaurant-price        ;; the price of a meal at the restaurant

 ;; Restaurant Statistics
 days-revenue         ;; amount of revenue generated so far today
 days-cost            ;; amount of costs accumulated so far today
 days-profit          ;; profit made so far today
 num-customers        ;; number of customers today
 profit-customer  ;; avg profit made per customer
]

;;;;;;;;;;;;;;;;;;;;;
;; Setup Functions ;;
;;;;;;;;;;;;;;;;;;;;;

to startup
  hubnet-reset
  setup
end 

;; initializes the display and
;; set parameters for the system

to setup
  cp ct
  clear-output
  setup-quick-start
  reset
end 

;; initializes the display (but does not clear already created restaurants)

to reset
  setup-globals
  setup-consumers
  clear-all-plots
  ask restaurants
  [ reset-owner-variables ]
  broadcast-system-info
end 

;; initializes the global variables

to setup-globals
  reset-ticks
  set day 0

  set-default-shape customers "person"

  ;; Set the available colors  and their names
  set colors      [ lime   orange   brown   yellow  turquoise  cyan   sky   blue
                   violet   magenta   pink  red  green  gray  12 62 102 38 ]
  set color-names ["lime" "orange" "brown" "yellow" "turquoise" "cyan" "sky" "blue"
                   "violet" "magenta" "pink" "red" "green" "gray" "maroon" "hunter green" "navy" "sand"]
  set used-colors []
  set num-colors length colors
  set n/a "n/a"
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customer Setup Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; initializes and creates the customers

to setup-consumers

  ask customers
  [ die ]

  create-customers Num-Consumer
    [ set energy Consumer-Energy
    set persuaded? false
    set my-restaurant -1

    setxy random-xcor random-ycor

    set appeal 0
    let chance random 3

    ;; initialize the customer's preferences
    set customer-money (20 + random 81)
    set customer-taste (customer-money - 20)
    ifelse (chance = 0)
    [ set color red
      set customer-cuisine "American" ]
    [ ifelse (chance = 1)
      [ set color yellow
        set customer-cuisine "Asian" ]
      [ set color cyan
        set customer-cuisine "European" ] ] ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Automated Restaurants Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; creates automated owners

to create-automated-restaurants [ number ]
  create-restaurants number
  [ set user-id who
    reset-owner-variables
    set auto? true
    set color 32
    set size 2
    setup-automated-restaurant
    setup-location ]
end 

;; initializes the automated owner's variables

to setup-automated-restaurant

  let chance (random 3)

  ;; initializes the automated owner's settings
  set restaurant-service 5
  set restaurant-quality (25 + random 50)
  set restaurant-price (restaurant-quality + 10)
  ifelse (chance = 0)
  [ set restaurant-cuisine "American"
    set shape "restaurant american" ]
  [ ifelse (chance = 1)
    [ set restaurant-cuisine "Asian"
      set shape "restaurant asian" ]
    [ set restaurant-cuisine "European"
      set shape "restaurant european" ] ]
end 

;;;;;;;;;;;;;;;;;;
;; Setup Prompt ;;
;;;;;;;;;;;;;;;;;;

;; give the user some information about what the setup button does so they can
;; know whether they want to proceed before actually doing the setup

to setup-prompt
 if user-yes-or-no? (word "The SETUP button should only be used when starting "
             "over with a new group (such as a new set of students) since "
             "all data is lost.  Use the RE-RUN button for continuing with "
             "an existing group."
             "\n\nDo you really want to setup the model?")
 [ user-message (word "Before closing this dialog, please do the following:"
                "\n  -Have everyone that is currently logged in, log off and "
                "then kick all remaining clients with the HubNet Console.")
   setup ]
end 

;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;

to go
  listen-to-clients
  every .5
  [ broadcast-system-info
    ask restaurants with [ auto? = false ]
    [ send-personal-info ] ]

  if not any? restaurants
  [ user-message "There are no restaurant owners. Log people in or create restaurants."
    stop ]

  ask restaurants with [ bankrupt? = false ] ;; Let the Restaurants work
  [ serve-customers
    attract-customers ]

  ask customers ;; Move the customers
  [ move-customers ]

  if (ticks mod day-length) = 0 ;; Is it time to end the day?
  [ set day day + 1
   plot-disgruntled-customers
   plot-restaurant-statistics
   ask restaurants with [ bankrupt? = false ]
   [ end-day ]
   if show-rank? and any? restaurants with [auto? = false]
    [ rank-restaurants ] ]
  tick
end 

to serve-customers ;; turtle procedure
 let restaurant# user-id
 let new-customers 0

 ;; customers update the information of the restaurant where they have decided to dine
 ask customers with [ (persuaded? = true) and (my-restaurant = restaurant#) ] in-radius 1
 [ set new-customers new-customers + 1
   set persuaded? false
   set my-restaurant -1
   set appeal 0
   set energy Consumer-Energy ]

  set num-customers (num-customers + new-customers)
  set days-revenue (days-revenue + (new-customers * restaurant-price))
  set days-cost round (days-cost + (new-customers * Service-Cost * restaurant-service) + (new-customers * Quality-Cost * restaurant-quality))
  set days-profit round (days-revenue - days-cost)
end 

to attract-customers ;; turtle procedure
  let restaurant# user-id
  let r-x xcor
  let r-y ycor
  let r-cuisine restaurant-cuisine
  let adj-price (restaurant-price - 0.15 * restaurant-service)
  let adj-quality (restaurant-quality + 0.15 * restaurant-service)
  let util-price false
  let util-quality false
  let restaurant-appeal false

  ;; Try and persuade customers that are within range
  ask customers with [ (energy < Consumer-Threshold) and (customer-cuisine = r-cuisine) ] in-radius 7
  [
    set util-price (customer-money - adj-price)
    set util-quality (adj-quality - customer-taste)
    if (util-price >= 0) and (util-quality >= 0)
    [
       set restaurant-appeal (util-price + util-quality) * 5
       if (restaurant-appeal > appeal)
       [ set appeal restaurant-appeal
         set persuaded? true
         set my-restaurant restaurant#
         facexy r-x r-y ] ] ]
end 

;; makes the customers move

to move-customers ;; customer procedure
 if persuaded? = false
 [ rt random-float 45 - random-float 45 ]
 set energy energy - 1
 fd 1
end 

;; makes the owner calculate end-of-day figures and initializes
;; the personal variables for the next day

to end-day ;; turtle procedure

  if (auto? = false)
  [ hubnet-send user-id "Number of Customers" num-customers
    hubnet-send user-id "Day's Profit" days-profit
    hubnet-send user-id "Day's Revenue" days-revenue
    hubnet-send user-id "Day's Cost" days-cost ]

  set account-balance round (account-balance + days-profit)
  set days-cost Rent-Cost
  set days-revenue 0
  set days-profit (days-revenue - days-cost)
  set num-customers 0

  if (Bankruptcy?) ;; If the owner is bankrupt shut his restaurant down
  [ if (account-balance < 0)
  [ set bankrupt? true ] ]
end 

;;;;;;;;;;;;;;;;;;;;;;;
;; Ranking Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;

;; ranks owners by their account balance. if there are three players and two of them are tied with the
;; lower account balance, then they will both be ranked as 3rd place.

to rank-restaurants
  let num-ranks (length (remove-duplicates ([account-balance] of restaurants)))
  let rank# count restaurants

  repeat num-ranks
  [ let min-rev min [account-balance] of restaurants with [not received-rank?]
    let rankee restaurants with [account-balance = min-rev]
    let num-tied count rankee
    ask rankee
    [ set rank rank#
      set received-rank? true ]
    set rank# rank# - num-tied ]

  ask restaurants
  [ set received-rank? false ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;
;; Plotting Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;

;; plot the number of disgruntled customers

to plot-disgruntled-customers
  set-current-plot "Disgruntled Customers"
  plot disgruntled-consumers
end 

;; plot the restaurant statistics for the user controlled restaurants

to plot-restaurant-statistics
    ask restaurants with [ auto? = false ]
    [ set-current-plot "Profits"
      set-current-plot-pen user-id
      plot days-profit

      set-current-plot "# Customers"
      set-current-plot-pen user-id
      plot num-customers
    ]

    set-current-plot "Profits"
    set-current-plot-pen "avg-profit"
    plot mean [days-profit] of restaurants

    set-current-plot "# Customers"
    set-current-plot-pen "avg-custs"
    plot mean [num-customers] of restaurants

    set-current-plot "Customer Satisfaction"
    set-current-plot-pen "min."
    plot min [appeal] of customers
    set-current-plot-pen "avg."
    plot mean [appeal] of customers
    set-current-plot-pen "max."
    plot max [appeal] of customers
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Calculation Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; reports the number of tavern restaurants in the marketplace

to-report american-cuisines
  report count restaurants with [ restaurant-cuisine = "American" ]
end 

;; reports the number of fine dining restaurants in the marketplace

to-report asian-cuisines
  report count restaurants with [ restaurant-cuisine = "Asian" ]
end 

;; reports the number of fast food restaurants in the marketplace

to-report european-cuisines
  report count restaurants with [ restaurant-cuisine = "European" ]
end 

;; reports the avg profit from all the owners on the current day

to-report avg-profit/owner
  report mean [ days-profit ] of restaurants
end 

to-report avg-customers/owner
  report mean [ num-customers ] of restaurants
end 

;; reports the avg energy of the customers

to-report avg-energy/customer
  report mean [ energy ] of customers
end 

;; reports the number of customers that can't find a restaurant that they want to eat at

to-report disgruntled-consumers
  report count customers with [ energy < 0 ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Quick Start functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; instructions to quickly setup the model, and clients to run this activity

to setup-quick-start
  set qs-item 0
  set qs-items
  [ "Teacher: Follow these directions to run the HubNet activity."
    "Press the SETUP button, then Press the INITIAL LOGIN button."
    "Everyone: Open up a HubNet Client on your machine, input the IP Address of this computer, press ENTER, type your name, and press ENTER."
    "Teacher: Once everyone has logged in, turn off the INITIAL LOGIN button by pressing it again."
    "Have the students acquaint themselves with their interface."
    "Teacher: Press GO to start the simulation."
    "Each student is a restaurateur. The customers are independent computer agents."
    "Following are some additional features you might want to adjust for later runs:"
    "NUM-CUSTOMERS determines the number of customers: set this before you run the game."
    "The following conditions can be changed either before or while the game is running:"
    "If SHOW-RANK? is on, the students are able to see their ranking amongst all restaurateurs."
    "If BANKRUPCY? is on, then students might go bankrupt."
    "Use the cost sliders, QUALITY-COST, SERVICE-COST and RENT-COST to adjust costs."
    "CUSTOMER-ENERGY determines the beginning energy of the customer."
    "CUSTOMER-THRESHOLD determines the threshold at which a customer gets hungry."
    "To create some automated restaurants set the AUTO-RESTAURANTS slider and press CREATE-AUTOMATED-RESTAURANTS."
    "Teacher: To rerun the activity with the same group, un-press GO, adjust settings, press RE-RUN then GO."
    "Teacher: To start the simulation over with a new group, follow our instruction set again."]
  set quick-start (item qs-item qs-items)
end 

;; view the next item in the quickstart monitor

to view-next
  set qs-item qs-item + 1
  if qs-item >= length qs-items
  [ set qs-item length qs-items - 1 ]
  set quick-start (item qs-item qs-items)
end 

;; view the previous item in the quickstart monitor

to view-prev
  set qs-item qs-item - 1
  if qs-item < 0
  [ set qs-item 0 ]
  set quick-start (item qs-item qs-items)
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Code for interacting with the clients ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; determines which client sent a command, and what the command was

to listen-to-clients
  while [ hubnet-message-waiting? ]
  [ hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ create-new-restaurant hubnet-message-source ]
    [ ifelse hubnet-exit-message?
      [ remove-restaurant hubnet-message-source ]
      [ execute-command hubnet-message-tag ] ] ]
end 

;; NetLogo knows what each student's restaurant patch is supposed to be
;; doing based on the tag sent by the name Cuisine, Service, Price and Quality

to execute-command [command]
  if command = "Cuisine"
  [ ask restaurants with [ user-id = hubnet-message-source ]
    [ set restaurant-cuisine hubnet-message
      ifelse (restaurant-cuisine = "American")
      [ set shape "restaurant american" ]
      [ ifelse (restaurant-cuisine = "Asian")
        [ set shape "restaurant asian" ]
        [ set shape "restaurant european" ] ] ]
    stop ]
  if command = "Service"
  [ ask restaurants with [ user-id = hubnet-message-source ]
    [ set restaurant-service hubnet-message
      set profit-customer round (restaurant-price - ((Service-Cost * restaurant-service) + (Quality-Cost * restaurant-quality))) ]
    stop ]
  if command = "Quality"
  [ ask restaurants with [ user-id = hubnet-message-source ]
    [ set restaurant-quality hubnet-message
      set profit-customer round (restaurant-price - ((Service-Cost * restaurant-service) + (Quality-Cost * restaurant-quality))) ]
    stop ]
  if command = "Price"
  [ ask restaurants with [ user-id = hubnet-message-source ]
    [ set restaurant-price hubnet-message
      set profit-customer round (restaurant-price - ((Service-Cost * restaurant-service) + (Quality-Cost * restaurant-quality))) ]
    stop ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Owner Setup Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; creates a new owner

to create-new-restaurant [ id ]
  create-restaurants 1
  [ set user-id id
    set auto? false
    reset-owner-variables
    setup-restaurant
    setup-location
    send-personal-info
  ]
end 

;; sets up the owners personal variables and location

to setup-restaurant ;; Restaurant procedure
  let helplist remove used-colors colors

  ifelse empty? helplist
  [set restaurant-color one-of colors ]
  [
   set restaurant-color one-of helplist
   set used-colors lput restaurant-color used-colors
  ]
  set color restaurant-color
  set size 2
  set shape one-of ["restaurant american" "restaurant asian" "restaurant european" ]
  ifelse shape = "restaurant american"
  [set restaurant-cuisine "American"]
  [
   ifelse shape = "restaurant asian"
   [set restaurant-cuisine "Asian"]
   [set restaurant-cuisine "European"]
  ]
  reset-owner-variables
end 

;; sets up the restaurant's location and premises

to setup-location   ;; owner procedure
  setxy ((random (world-width - 2)) + 1)
        ((random (world-height - 2)) + 1)
  if any? other restaurants in-radius 3
  [ setup-location ]
end 

;; reset owners variables to initial values

to reset-owner-variables  ;; owner procedure
  set rank n/a
  set received-rank? false
  set bankrupt? false
  set account-balance 2000
  set days-revenue 0
  set days-cost Rent-Cost
  set days-profit 0
  set profit-customer 100
  set num-customers 0
  set restaurant-price random 50
  set restaurant-service 50 + random 50
  set restaurant-quality 50 + random 50
  if (auto? = false) ;; send the personal info only to clients
  [ send-personal-info ]
  ask restaurants with [auto? = false]
  [
    ;; Setup the plot pens for the restaurant
    set-current-plot "Profits"
    create-temporary-plot-pen user-id
    set-plot-pen-color restaurant-color

    set-current-plot "# Customers"
    create-temporary-plot-pen user-id
    set-plot-pen-color restaurant-color
  ]
end 

;; delete restaurant once client has exited

to remove-restaurant [ id ] ;; owner procedure
  let old-color false
  ask restaurants with [user-id = id] ;; remove the owner's turtle
  [ set old-color restaurant-color
    die ]

  if not any? restaurants with [ color = old-color ] ;; make the unused color available again
  [ set used-colors remove (position old-color colors) used-colors ]
end 

;; sends the appropriate monitor information back to the client

to send-personal-info ;; restaurant procedure
  hubnet-send user-id "Restaurant Color" (color->string color)
  hubnet-send user-id "Account Balance" account-balance
  hubnet-send user-id "Profit / Customer" profit-customer
  hubnet-send user-id "Rank" rank
  hubnet-send user-id "Bankrupt?" bankrupt?
  hubnet-send user-id "Cuisine" restaurant-cuisine
  hubnet-send user-id "Service" restaurant-service
  hubnet-send user-id "Quality" restaurant-quality
  hubnet-send user-id "Price" restaurant-price
end 

;; returns string version of color name

to-report color->string [ color-value ]
  report item (position color-value colors) color-names
end 

;; sends the appropriate monitor information back to one client

to send-system-info ;; owner procedure
  hubnet-send user-id "Day" day
end 

;; broadcasts the appropriate monitor information back to all clients

to broadcast-system-info
  hubnet-broadcast "Day" day
end 


; Copyright 2004 Uri Wilensky.
; See Info tab for full copyright and license.

There are 7 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 9 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky almost 10 years ago Updated version tag Download this version
Uri Wilensky almost 10 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 10 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Restaurants Download this version
Uri Wilensky over 12 years ago Restaurants Download this version

Attached files

File Type Description Last updated
Restaurants.png preview Preview for 'Restaurants' over 9 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.