---party_ pt.nlogo
来自「NETLOGO」· NLOGO 代码 · 共 536 行
NLOGO
536 行
;The 'turtles-own' keyword, like the globals, breed, <BREED>-own, and patches-own keywords, ;can only be used at the beginning of a program, before any function definitions. ;It defines the variables belonging to each turtleturtles-own [man? woman? happy?]patches-own [men women people]globals [boring-groups moves number-happy group-sites]to setup ca ; 'with' takes two inputs: on the left, an agentset (usually "turtles" or "patches"). ; On the right, a boolean reporter. set group-sites patches with [group-site?] set-default-shape turtles "person"; 'cct' create-custom-turtles cct number [ ;;blue represents male, pink represents female. No stereotypes are meant ;;to be promoted. Simply change the colors right here if you'd like.;ifelse reporter [ commands1 ] [ commands2 ] ifelse (random 2 = 0) [set man? true set woman? false set color blue] [set man? false set woman? true set color pink] ifelse (random 2 = 0) [set heading 90] [set heading 270] ;; randomly face right or left set ycor 0 set xcor random screen-size-x ] ; These reporters give the total width and height of the NetLogo world. ; Screen-size is the same as ((2 * screen-edge) + 1) ask turtles [move-into-groups] setup-patches setup-plots set moves 0 update-labels spread-people update-plotsendto setup-patches ask patches [ set men 0 set women 0 set people 0] ask turtles [ if man? [set men (men + 1)] if woman? [set women (women + 1)]] ask patches [ set people (men + women)] update-happiness update-boring-groupsendto go if (number-happy = number) [ stop ;; stop the simulation if everyone is happy ] group-people ;; put all people on the x-axis update-happiness move-if-unhappy update-boring-groups update-labels spread-people ;; move the people into vertical columns set moves (moves + 1) update-plots if limit-speed? [ wait 0.75 ] ;; keep the spread groups on the screen for a bitendto update-labels ask group-sites [ set plabel count turtles-here ] ; plabel is a pattch label ; turtles-here reports an agentset containing all ; the turtles on the caller's patch (including the caller ; itself if it's a turtle). ; count agentset reports the number of agents in the given agentsetendto update-happiness ask patches [ set people (men + women)] ask turtles [ ;;; you are happy if the proportion of people of the opposite sex does not exceed your tolerance if man? [ifelse (women / people) > (tolerance / 100) [set happy? false] [set happy? true]] if woman? [ifelse (men / people) > (tolerance / 100) [set happy? false] [set happy? true]] ;; if (happy? = true) [set num-happy (num-happy + 1)] ] set number-happy count turtles with [happy?] ;; update number-happy variableendto move-if-unhappy ask turtles [ if (not happy?) [ifelse man? [set men men - 1] ;;decrease the count in your old group [set women women - 1] ifelse (random 2 = 0) [set heading 90] [set heading 270] ;; randomly face right or left fd 1 ;; move out of your group move-into-groups ifelse man? [set men men + 1] [set women women + 1]]] ;;increase the count in your new in groupendto move-into-groups ;;turtle procedure ; move forward until you hit the closest group if not group-site? [ fd 1 if limit-speed? [ wait 0.1 ] ;; slow it down so user can see it happening move-into-groups]endto-report group-site? ;; turtle or patch procedure ;; if your pycor is 0 and your pxcor is where a group should be located, ;; then you're a group site (patch) or on a group site (turtle) locals [group-interval] ;; first figure out how many patches apart the groups will be set group-interval floor (screen-size-x / num-groups) report ;; first check pycor (pycor = 0) and ;; then check if the distance between groups divides evenly into ;; our distance from the right hand edge of the screen (((screen-edge-x - pxcor) mod group-interval) = 0) and ;; finally, make sure we don't wind up with more groups than ;; the user asked for (floor ((screen-edge-x - pxcor) / group-interval) < num-groups)endto update-boring-groups ask group-sites [ set plabel-color white if people > 0 [if ((men = 0) or (women = 0)) [set plabel-color gray]]] set boring-groups (count group-sites with [plabel-color = gray])endto setup-plots set-current-plot "Happy Partygoers" set-plot-y-range 0 numberendto update-plots set-current-plot "Happy Partygoers" set-current-plot-pen "Happy" plot (count turtles with [happy?]) set-current-plot "Single Sex Groups" plot boring-groupsend;; spread people out vertically to spread-people ask turtles [ifelse man? [set heading 0 fd 2] [set heading 180 fd 2] jump count other-turtles-here] ;; this trick works because of the serial ordering of turtle execution ; 'jump': turtles move forward by number units all at once, without the ; amount of time passing depending on the distance.end ;; pile people up on the x-axis to group-people ask turtles [set ycor 0]end; *** NetLogo Model Copyright Notice ***;; This model was created as part of the project: CONNECTED MATHEMATICS:; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL; MODELS (OBPML). The project gratefully acknowledges the support of the; National Science Foundation (Applications of Advanced Technologies; Program) -- grant numbers RED #9552950 and REC #9632612.;; Copyright 1997 by Uri Wilensky. All rights reserved.;; Permission to use, modify or redistribute this model is hereby granted,; provided that both of the following requirements are followed:; a) this copyright notice is included.; b) this model will not be redistributed for profit without permission; from Uri Wilensky.; Contact Uri Wilensky for appropriate licenses for redistribution for; profit.;; This model was converted to NetLogo as part of the project:; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN; CLASSROOMS. The project gratefully acknowledges the support of the; National Science Foundation (REPP program) -- grant number REC #9814682.; Converted from StarLogoT to NetLogo, 2001. Updated 2002.;; To refer to this model in academic publications, please use:; Wilensky, U. (1997). NetLogo Party model.; http://ccl.northwestern.edu/netlogo/models/Party.; Center for Connected Learning and Computer-Based Modeling,; Northwestern University, Evanston, IL.;; In other publications, please use:; Copyright 1998 by Uri Wilensky. All rights reserved. See; http://ccl.northwestern.edu/netlogo/models/Party; for terms of use.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW2041070070740556.0116111CC-WINDOW3320198454Command CenterBUTTON7107543setupsetupNIL1TOBSERVERTBUTTON7477580gogoT1TOBSERVERTBUTTON78475117step-oncegoNIL1TOBSERVERTMONITOR721563264movesmoves01SLIDER771020043tolerancetolerance0.099.025.01.01%SLIDER774720080numbernumber03007511NILMONITOR69215173264number-happynumber-happy01MONITOR24266142315single-sex-groupsboring-groups01PLOT71843961283Happy Partygoersmovesnumber0.010.00.0150.0truefalsePENS"Happy" 1.0 0 -11352576 truePLOT717297960499Single Sex Groupsmovesseg-groups0.010.00.012.0truefalsePENS"Single Sex" 1.0 0 -65536 trueSLIDER7784200117num-groupsnum-groups5201011NILSWITCH35150168183limit-speed?limit-speed?01-1000@#$#@#$#@WHAT IS IT?-----------This program models a cocktail party. The party is made up of groups of both men and women. The partygoers have a TOLERANCE that defines their comfort level with a group that has members of the opposite sex. If they are in a group that has a higher percentage of people of the opposite sex than their TOLERANCE allows, then they are considered "uncomfortable", and they leave that group to find another group. This action continues until everyone at the party is "comfortable" within their group.This model is based on the work of the pioneering economist Thomas Schelling. It is also described in: Resnick, M. & Wilensky, U. (1998). Diving into Complexity: Developing Probabilistic Decentralized Thinking through Role-Playing Activities. Journal of Learning Sciences, Vol. 7, No. 2. http://ccl.northwestern.edu/cm/papers/starpeople/HOW TO USE IT-------------To set the number of people at the party, use the NUMBER slider. To set the number of initial groups, use the NUM-GROUPS slider.To set the tolerance of the people for the opposite sex, use the TOLERANCE slider. If the TOLERANCE slider is set to 75, then each person will tolerate being in a group with less than or equal to 75% people of the opposite sex. If there are more than this, the person is uncomfortable, and he/she leaves the group and tries out an adjacent group.The SETUP button sets up all the people into random groups. The GO button sets the party in motion. You can use the STEP-ONCE button to make all uncomfortable partygoers move once. The MOVES monitor shows the number of times people move from their groups. The NUMBER-HAPPY monitor shows how many people are content and this value is dynamically graphed in the "happy partygoers" plot. The counts are shown in gray for "single-sex" groups, white for mixed groups. The simulation ends when everyone is happy. The SINGLE-SEX-GROUPS monitor shows the number of single-sex groups and this value is dynamically plotted in the "single sex groups" plot.RUNNING the MODEL-----------------THINGS TO NOTICE----------------At the end of the simulation (when everyone is happy), notice the number of single-sex groups. Is there an increase from their initial compositions?Is there a critical tolerance at which each group ends up being a single-sex group?Notice the difference in time it takes for all groups to be comfortable depending upon the tolerance.THINGS TO TRY-------------See how many mixed groups (not a single-sex group) you can get. Use the STEP-ONCE button, and experiment with different tolerances. Watch how one unhappy person can disrupt the stability of other groups.Is it possible to have an initial grouping such that the party is never completely content? (i.e. the model never terminates)Observe real parties. Is this model descriptive of real social settings? What tolerances would model the people in the real party?EXTENDING THE MODEL-------------------Add another dimension to the model. Instead of male/female, try a trait that has more than two types, like race or religion. You can use BREEDS to implement that.Allow each BREED of person to have their own tolerance.Complicate the tolerance rules: For example, the tolerance could go up as long as there are at least 2 of one BREED.Allow groups to subdivide, instead of finding new groups.Set a maximum group size, so that if there are too many people in the group, they become unhappy.NETLOGO FEATURES-----------------Notice the use of the "mod" function with a portion of the "screen-size" to space out the groups evenly. Setting up the groups in this manner allows for easy movement from group to group.Note also the use of the seriality of turtle execution for spreading out the turtles. Knowing that lower numbered turtles execute first enables this code to align the labels in the SHOW-COUNTS option.RELATED MODELS---------------SegregationCREDITS AND REFERENCES----------------------Schelling, T. (1978). Micro-motives and Macro-Behavior. New York: Norton. Resnick, M. & Wilensky, U. (1998). Diving into Complexity: Developing Probabilistic Decentralized Thinking through Role-Playing Activities. Journal of Learning Sciences, Vol. 7, No. 2.To refer to this model in academic publications, please use: Wilensky, U. (1997). NetLogo Party model. http://ccl.northwestern.edu/netlogo/models/Party. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.In other publications, please use: Copyright 1997 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/Party for terms of use.@#$#@#$#@defaulttrue0Polygon -7566196 true true 150 5 40 250 150 205 260 250arrowtrue0Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150boxtrue0Polygon -7566196 true true 45 255 255 255 255 45 45 45circletrue0Circle -7566196 true true 35 35 230personfalse0Circle -7566196 true true 155 20 63Rectangle -7566196 true true 158 79 217 164Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110Polygon -7566196 true true 216 83 267 123 248 143 215 107Polygon -7566196 true true 167 163 145 234 183 234 183 163Polygon -7566196 true true 195 163 195 233 227 233 206 159spacecrafttrue0Polygon -7566196 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135thin-arrowtrue0Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150truck-downfalse0Polygon -7566196 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30Polygon -8716033 true false 195 75 195 120 240 120 240 75Polygon -8716033 true false 195 225 195 180 240 180 240 225truck-leftfalse0Polygon -7566196 true true 120 135 225 135 225 210 75 210 75 165 105 165Polygon -8716033 true false 90 210 105 225 120 210Polygon -8716033 true false 180 210 195 225 210 210truck-rightfalse0Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165Polygon -8716033 true false 210 210 195 225 180 210Polygon -8716033 true false 120 210 105 225 90 210turtletrue0Polygon -7566196 true true 138 75 162 75 165 105 225 105 225 142 195 135 195 187 225 195 225 225 195 217 195 202 105 202 105 217 75 225 75 195 105 187 105 135 75 142 75 105 135 105@#$#@#$#@NetLogo 2.0.0@#$#@#$#@@#$#@#$#@@#$#@#$#@
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?