📄 ---segregation(1).nlogo
字号:
globals [ percent-similar ;; on the average, what percent of a turtle's neighbors ;; are the same color as that turtle? percent-unhappy ;; what percent of the turtles are unhappy?]turtles-own [ happy? ;; for each turtle, indicates whether at least %-similar-wanted percent of ;; that turtles' neighbors are the same color as the turtle similar-nearby ;; how many neighboring patches have a turtle with my color? other-nearby ;; how many have a turtle of another color? total-nearby ;; sum of previous two variables]to setup ca if number > count patches [ user-message "This pond only has room for " + count patches + " turtles." stop ] ;; create turtles on random patches. ask random-n-of number patches [ sprout 1 [ set color red ] ] ;; turn half the turtles green ask random-n-of (number / 2) turtles [ set color green ] update-variables do-plotsendto go if not any? turtles with [not happy?] [ stop ] move-unhappy-turtles update-variables do-plotsendto move-unhappy-turtles ask turtles with [ not happy? ] [ find-new-spot ]endto find-new-spot rt random-float 360 fd random-float 10 if any? other-turtles-here [ find-new-spot ] ;; keep going until we find an unoccupied patch setxy pxcor pycor ;; move to center of patchendto update-variables update-turtles update-globalsendto update-turtles ask turtles [ ;; in next two lines, we use "neighbors" to test the eight patches ;; surrounding the current patch set similar-nearby count (turtles-on neighbors) with [color = color-of myself] set other-nearby count (turtles-on neighbors) with [color != color-of myself] set total-nearby similar-nearby + other-nearby set happy? similar-nearby >= ( %-similar-wanted * total-nearby / 100 ) ]endto update-globals let similar-neighbors sum values-from turtles [similar-nearby] let total-neighbors sum values-from turtles [total-nearby] set percent-similar (similar-neighbors / total-neighbors) * 100 set percent-unhappy (count turtles with [not happy?]) / (count turtles) * 100endto do-plots set-current-plot "Percent Similar" plot percent-similar set-current-plot "Percent Unhappy" plot percent-unhappyend; *** 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 1998 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. (1998). NetLogo Segregation model.; http://ccl.northwestern.edu/netlogo/models/Segregation.; 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/Segregation; for terms of use.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW2731064039825257.01101110111CC-WINDOW5462649557Command Center0MONITOR439399552448Percent Unhappypercent-unhappy11MONITOR315399423448Percent Similarpercent-similar11PLOT12121261264Percent Similartime%0.025.00.0100.0truefalsePENS"percent" 1.0 0 -2674135 truePLOT12265261429Percent Unhappytime%0.025.00.0100.0truefalsePENS"percent" 1.0 0 -10899396 trueSLIDER194823181numbernumber50025002000101NILSLIDER1985231118%-similar-wanted%-similar-wanted0.0100.030.01.01%BUTTON341411447setupsetupNIL1TOBSERVERTNILBUTTON1241420447gogoT1TOBSERVERTNIL@#$#@#$#@WHAT IS IT?------------This project models the behavior of two types of turtles in a mythical pond. The red turtles and green turtles get along with one another. But each turtle wants to make sure that it lives near some of "its own." That is, each red turtle wants to live near at least some red turtles, and each green turtle wants to live near at least some green turtles. The simulation shows how these individual preferences ripple through the pond, leading to large-scale patterns.This project was inspired by Thomas Schelling's writings about social systems (such as housing patterns in cities).HOW TO USE IT--------------Click the SETUP button to set up the turtles. There are equal numbers of red and green turtles. The turtles move around until there is at most one turtle on a patch. Click GO to start the simulation. If turtles don't have enough same-color neighbors, they jump to a nearby patch.The NUMBER slider controls the total number of turtles. (It takes effect the next time you click SETUP.) The %-SIMILAR-WANTED slider controls the percentage of same-color turtles that each turtle wants among its neighbors. For example, if the slider is set at 30, each green turtle wants at least 30% of its neighbors to be green turtles.The "Percent Similar" monitor shows the average percentage of same-color neighbors for each turtle. It starts at about 0.5, since each turtle starts (on average) with an equal number of red and green turtles as neighbors. The "Percent Unhappy" monitor shows the percent of turtles that have fewer same-color neighbors than they want (and thus want to move). Both monitors are also plotted.THINGS TO NOTICE----------------When you execute SETUP, the red and green turtles are randomly distributed throughout the pond. But many turtles are "unhappy" since they don't have enough same-color neighbors. The unhappy turtles jump to new locations in the vicinity. But in the new locations, they might tip the balance of the local population, prompting other turtles to leave. If a few red turtles move into an area, the local green turtles might leave. But when the green turtles move to a new area, they might prompt red turtles to leave that area.Over time, the number of unhappy turtles decreases. But the pond becomes more segregated, with clusters of red turtles and clusters of green turtles.In the case where each turtle wants at least 30% same-color neighbors, the turtles end up with (on average) 70% same-color neighbors. So relatively small individual preferences can lead to significant overall segregation.THINGS TO TRY------------Try different values for %-SIMILAR-WANTED. How does the overall degree of segregation change?If each turtle wants at least 40% same-color neighbors, what percentage (on average) do they end up with?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -