vending
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
VERSION
$Id: vending.nlogo 38634 2008-03-11 13:35:54Z everreau $
Each student stands in line to get something from the vending machine. For each vending machine, there is a certain probability that it will give out a prize. After each student gets something from the vending machine, he picks a random line to stand at the end of. If the line he picks is too long, he just moves to the back of his own line, which is known not to be too long.
NOTE: "wealth" in the UI refers to prizes won, not prizes won vs. money spent
WHAT IS IT?
The students stand in lines to get an item from a vending machine. Each vending machine has a certain probability of giving away a prize with the item. After they receive the item, they move to the back of their line. Students can change the line they are in at any time, taking place at the end of the line.
For further documentation, see the Participatory Simulations Guide found at http://ccl.northwestern.edu/ps/
HOW TO USE IT
QUICKSTART INSTRUCTIONS:
------------------------
Teacher: Follow these directions to run the HubNet activity.
Optional: Zoom In (see Tools in the Menu Bar)
Optional: Change any of the settings. Press the GO button to start the model.
Everyone: Open up a HubNet Client on your machine and input the IP Address of this computer, type your user name in the user name box and press ENTER.
Teacher: Have the students move their turtles around to acquaint themselves with the interface. Then press the INFECT NetLogo button to start the simulation. Watch the plot of the number infected.
Teacher: To rerun the activity with the same group, stop the model by pressing the NetLogo GO button, if it is on. Change any of the settings that you would like. To overlay the new run's plot data change the value of the slider DATA-SET. If you set DATA-SET to a value that already had data in it, the new data will over-write the old data. Press the NetLogo RE-RUN button. Restart the simulation by pressing the NetLogo GO button again. Infect some turtles and continue.
Teacher: To start the simulation over with a new group, stop the model by pressing the NetLogo GO button, if it is on and follow these instructions again from the beginning.
BUTTONS:
--------
SETUP - clears all turtles and patches and the plot. This should only be pressed when starting out with a new group of users since all data is lost.
GO - runs the simulation
RE-RUN - cures all turtles, and clears the current plot pen selected with DATA-SET. This should be used to setup the model again for collecting more data or running the model again with the same users connected.
CREATE ANDROIDS - adds randomly moving turtles to the simulation
INFECT - infects some of the turtles in the simulation
NEXT >>> - shows the next quick start instruction
<<< PREVIOUS - shows the previous quick start instruction
RESET INSTRUCTIONS - shows the first quick start instruction
SLIDERS:
--------
NUMBER - determines how many androids are created by the CREATE ANDROIDS button
ANDROID-DELAY - the delay time, in seconds, for android movement - the higher the number, the slower the androids move
INITIAL-NUMBER-SICK - the number of turtles that become infected spontaneously when the INFECT button is pressed
PERCENTAGE-INFECTION - sets the percentage chance that every tenth of a second a healthy turtle will become sick if it is on the same patch as an infected turtle
DATA-SET - sets which plot pen the data from this run will be plotted with. This is useful for comparing several runs of the model to one another. All pens are cleared by SETUP.
SWITCHES:
---------
WANDER? - when on, the androids wander randomly. When off, they sit still
SHOW-ILL? - when on, sick turtles add to their original shape a red circle. When off, they can move through the populace unnoticed
SHOW-ILL-ON-CLIENTS? - when on, the clients will be told if their turtle is sick or not.
MONITORS:
---------
TURTLES - the number of turtles in the simulation
NUM-INFECTED - the number of turtles that are infected
PLOTS:
------
NUMBER SICK - shows the number of sick turtles versus time
CLIENT INFORMATION
After logging in, the client interface will appear for the students, and if GO is pressed in NetLogo they will be assigned a turtle which will be described in the YOU ARE A: monitor. And their current location will be shown in the LOCATED AT: monitor. If the student doesn't like their assigned shape and/or color they can hit the CHANGE APPEARANCE button at any time to change to another random appearance.
The SICK? monitor will show one of three values: "true" "false" or "N/A". "N/A" will be shown if the NetLogo SHOW-ILL-ON-CLIENTS? switch is off, otherwise "true" will be shown if your turtle is infected, or "false" will be shown if your turtle is not infected.
The student controls the movement of their turtle with the UP, DOWN, LEFT, and RIGHT buttons and the STEP-SIZE slider. Clicking any of the directional buttons will cause their turtle to move in the respective direction a distance of STEP-SIZE.
The students can watch the progress of the disease in the NUMBER SICK plot which is identical to the plot of the same name in NetLogo.
THINGS TO NOTICE
No matter how you change the various parameters, the same basic plot shape emerges. After using the model once with the students, ask them how they think the plot will change if you alter a parameter. Altering the initial percentage sick and the percentage infection will have different effects on the plot.
THINGS TO TRY
Use the model with the entire class to serve as an introduction to the topic. Then have students use the NetLogo model individually, in a computer lab, to explore the effects of the various parameters. Discuss what they find, observe, and can conclude from this model.
Comments and Questions
globals [ vend-lines ;; list of vending machines containing a list students for each vending machine vend-positions ;; list of xcors of each vending machine prize-streaks ;; list of prize streaks for each line wealth-distribution-list ;; list of (num-prizes / (money-spent) vending-machine-colors ;; list of colors for each line max-line-length ;; the longest a line can be (determined to be 14 for the current screen size) ;; lists used to create the various turtles shape-names ;; list that holds the names of the non-sick shapes a student's turtle can have colors ;; list that holds the colors used for students' turtles color-names ;; list that holds the names of the colors used for students' turtles used-shape-colors ;; list that holds the shape-color pairs that are already being used ;; misc clock ;; keeps track of the number of times through the go procedure (if there is at least one turtle infected) max-possible-codes ;; total number of possible unique shape/color combinations ;; 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 ] breed [ students student ] breed [ vending-machines vending-machine ] students-own [ line-number ;; the vending machine number you are standing in line for money-spent ;; the number of times student has 'vended' line-position ;; the place they are in the line, 1 being the front num-prizes ;; the number of prizes won user-id ;; unique id, input by the client when they log in, to identify each student turtle ] vending-machines-own [goods-dispensed prizes-dispensed last-vended-prize] to startup setup hubnet-set-client-interface "COMPUTER" [] hubnet-reset end to setup ca setup-vars create-vending-machines 4 [ set shape "vending machine" set size 2 set color (item who vending-machine-colors) set goods-dispensed 0 set prizes-dispensed 0 set last-vended-prize 0 setxy ((floor (max-pxcor / 2) * (who - 2) + 3 )) (max-pycor - 1) set vend-positions (lput xcor vend-positions) ] setup-quick-start end to setup-vars set clock 0 set max-line-length 14 set vend-lines [[] [] [] []] set vend-positions [] set prize-streaks [[] [] [] []] set wealth-distribution-list [] set vending-machine-colors [red green blue] set vending-machine-colors lput (orange + 1) vending-machine-colors set shape-names ["wide wedge" "thin wedge" "big boat" "pickup truck" "nu" "uu" "butterfly" "wolf" "sheep" "lobster" "monster" "moose" "bear" "teddy bear"] set colors [ white gray brown yellow green lime turquoise cyan sky blue violet ] ;; adjust a few colors so they don't blend in with the red infection dot too much set colors lput (orange + 1) colors set colors lput (magenta + 0.5) colors set colors lput (pink + 2.5) colors set color-names ["white" "gray" "brown" "yellow" "green" "lime" "turquoise" "cyan" "sky" "blue" "violet" "orange" "magenta" "pink"] set max-possible-codes (length colors * length shape-names) set used-shape-colors [] end to re-run set vend-lines [[] [] [] []] set vend-positions [] set prize-streaks [[] [] [] []] set wealth-distribution-list [] ask vending-machines [ set label "" set goods-dispensed 0 set prizes-dispensed 0 set last-vended-prize 0 ] ask students [ set num-prizes 0 set money-spent 0 send-info-to-clients ] clear-all-plots end ;; 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 to go every 0.1 [ ;; get commands and data from the clients listen-clients ask students with [line-position = 1] [ hubnet-send user-id "Instructions:" "Click Vend!" ] ask students [ send-info-to-clients ] do-plot set clock (clock + 1) ] end ;; observer procedure to add-student-to-line [student num] set vend-lines (replace-item num vend-lines (lput student (item num vend-lines))) ask student [ set line-position num set line-number num setxy ((item line-number vend-positions)) ( max-pycor - 2.5 - 2 * line-length line-number) ] end to leave-line hide-turtle foreach (item line-number vend-lines) [ ask ? [ if (line-position > [line-position] of myself) [fd 2 set line-position (line-position - 1)] ] ] set vend-lines (replace-item line-number vend-lines (remove self (item line-number vend-lines))) end ;; student procedure ;; moves student to the back of the chosen line ;; if the line chosen is too long, the student will remain in the line he is currently in to move-to-line [num] if line-length num >= max-line-length ;; if the line is too long, go to the back of the current line [set num line-number] foreach (item line-number vend-lines) [ ask ? [ if (line-position > [line-position] of myself) [fd 2 set line-position (line-position - 1)] ] ] set vend-lines (replace-item line-number vend-lines (remove self (item line-number vend-lines))) add-student-to-line self num end ;; observer procedure ;; returns the number of students at a particular vending machine to-report line-length [num] report length (item num vend-lines) end ;;vending-machine procedure to vend [student] if ((who = 0 and random 10 < vend-1) or (who = 1 and random 10 < vend-2) or (who = 2 and random 10 < vend-3) or (who = 3 and random 10 < vend-4)) [ ask student [ set num-prizes num-prizes + 1 ] set prizes-dispensed (prizes-dispensed + 1) set prize-streaks (replace-item who prize-streaks (lput last-vended-prize (item who prize-streaks))) set last-vended-prize 0 ] ask student [ set money-spent money-spent + 1 ] set goods-dispensed (goods-dispensed + 1) set last-vended-prize (last-vended-prize + 1) set label last-vended-prize end to-report average-prizes-in-line [num] let num-prizes-list 0 set num-prizes-list [num-prizes] of students with [line-number = num] ifelse (sum num-prizes-list = 0) [report 0] [report mean num-prizes-list] end to do-plot set-current-plot "Prizes Won vs. Money Spent" histogram ([num-prizes / money-spent] of students with [money-spent != 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." "Optional: Zoom In (see Tools in the Menu Bar)" "Press the GO button." "Everyone: Open up a HubNet Client on your machine and..." "type your user name, select this activity and press ENTER." "Teacher: Have the students change their move-to slider to..." "acquaint themselves with the interface." "When the students receive the 'Vend Now' instruction ..." "they should click VEND" "Teacher: To start the simulation over ..." "stop the model by pressing the NetLogo GO button, if it is on..." "click RE-RUN to reset the data and the plots, and press GO" "Teacher: To start the simulation over with a new group,..." "stop the model by pressing the NetLogo GO button, if it is on..." "click SETUP, and follow these instructions again from the beginning." ] 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-clients while [ hubnet-message-waiting? ] [ hubnet-fetch-message ifelse hubnet-enter-message? [ create-new-student ] [ ifelse hubnet-exit-message? [ remove-student ] [ execute-command hubnet-message-tag ] ] ] end to execute-command [command] if member? "Move to" command [ ask students with [user-id = hubnet-message-source] [ move-to-line ((read-from-string last command) - 1) hubnet-send user-id "Instructions:" "Wait in Line" ] stop ] if command = "vend" [ ask students with [user-id = hubnet-message-source] [ ifelse line-position = 1 [ ;; since vending machines are the first four turtles, their who is the line-number ask turtle line-number [vend myself] move-to-line line-number hubnet-send user-id "Instructions:" "Wait in Line" ] [ hubnet-send user-id "Instructions:" "Wait for your turn" ] ] ] end ;; Create a student, set its shape and color, put it in a line ;; and tell the node about itself to create-new-student create-students 1 [ setup-student-vars add-student-to-line self (who mod 4) hubnet-send user-id "Instructions:" "Wait in Line" send-info-to-clients ] end ;; Remove the student from her line and kill her to remove-student ask students with [user-id = hubnet-message-source] [ leave-line set used-shape-colors remove my-code used-shape-colors die ] end ;; sets the turtle variables to appropriate initial values to setup-student-vars ;; turtle procedure set user-id hubnet-message-source set-unique-shape-and-color set heading 0 set money-spent 0 set num-prizes 0 set size 1.75 set line-number (who mod 4) setxy (item line-number vend-positions) ( max-pycor - 2.5 - 2.2 * line-length line-number) set line-position line-length line-number end ;; sends the appropriate monitor information back to the client to send-info-to-clients hubnet-send user-id "You are a:" (word (color-string color) " " shape) hubnet-send user-id "Money Spent:" money-spent hubnet-send user-id "Position In Line:" line-position hubnet-send user-id "Line Number:" line-number + 1 hubnet-send user-id "Prizes Won:" num-prizes if money-spent != 0 [hubnet-send user-id "Prizes Won vs. Money Spent:" (num-prizes / money-spent)] end to set-unique-shape-and-color let code 0 set code random max-possible-codes while [member? code used-shape-colors and count students < max-possible-codes] [ set code random max-possible-codes ] set used-shape-colors (lput code used-shape-colors) set shape item (code mod length shape-names) shape-names set color item (code / length shape-names) colors end ;; translates a student turtle's shape and color into a code to-report my-code report (position shape shape-names) + (length shape-names) * (position color colors) end ;; report the string version of the turtle's color to-report color-string [color-value] report item (position color-value colors) color-names end
There are 2 versions of this model.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.