📄 xxx-altruism.nlogo
字号:
patches-own [ benefit-out ;; 1 for altruists, 0 for selfish altruism-benefit fitness self-weight self-fitness alt-weight alt-fitness harsh-weight harsh-fitness]to setup ca ask patches [ initialize ] do-plotsendto initialize ;; patch procedure locals [ptype] set ptype random-float 1.0 ifelse (ptype < altruistic-probability) [ set benefit-out 1 set pcolor pink ] [ set benefit-out 0 ifelse (ptype < altruistic-probability + selfish-probability) [ set pcolor green ] [ set pcolor black ] ]endto go ;; if all altruistic and selfish patches are gone, stop if not any? patches with [(pcolor = pink) or (pcolor = green)] [ stop ] ask patches [ set altruism-benefit benefit-from-altruism * (benefit-out + sum values-from neighbors4 [benefit-out]) / 5 ] ask patches [ perform-fitness-check ] lottery do-plotsendto perform-fitness-check ;; patch procedure if (pcolor = green) [ set fitness (1 + altruism-benefit) ] if(pcolor = pink) [ set fitness ((1 - cost-of-altruism) + altruism-benefit) ] if (pcolor = black) [ set fitness harshness ]endto lottery ask patches [ record-neighbor-fitness ] ask patches [ find-lottery-weights ] ask patches [ next-generation ]endto record-neighbor-fitness ;; patch procedure set alt-fitness 0 set self-fitness 0 set harsh-fitness 0 if (pcolor = pink) [ set alt-fitness fitness ] if (pcolor = green) [ set self-fitness fitness ] if (pcolor = black) [ set harsh-fitness fitness ] update-fitness-from-neighbor 1 0 update-fitness-from-neighbor -1 0 update-fitness-from-neighbor 0 1 update-fitness-from-neighbor 0 -1endto update-fitness-from-neighbor [x y] ;; patch procedure locals [neighbor-fitness neighbor-color] set neighbor-color pcolor-of patch-at x y set neighbor-fitness fitness-of patch-at x y if (neighbor-color = pink) [set alt-fitness (alt-fitness + neighbor-fitness)] if (neighbor-color = green) [set self-fitness (self-fitness + neighbor-fitness)] if(neighbor-color = black) [set harsh-fitness (harsh-fitness + neighbor-fitness)]endto find-lottery-weights ;; patch procedure locals [fitness-sum] set fitness-sum alt-fitness + self-fitness + harsh-fitness + disease ifelse (fitness-sum > 0) [ set alt-weight (alt-fitness / fitness-sum) set self-weight (self-fitness / fitness-sum) set harsh-weight ((harsh-fitness + disease) / fitness-sum) ] [ set alt-weight 0 set self-weight 0 set harsh-weight 0 ]endto next-generation ;; patch procedure locals [breed-chance] set breed-chance random-float 1.0 ifelse (breed-chance < alt-weight) [ set pcolor pink set benefit-out 1 ] [ ifelse (breed-chance < (alt-weight + self-weight))[ set pcolor green set benefit-out 0 ] [ clear-patch ] ]endto clear-patch ;; patch procedure set pcolor black set altruism-benefit 0 set fitness 0 set alt-weight 0 set self-weight 0 set harsh-weight 0 set alt-fitness 0 set self-fitness 0 set harsh-fitness 0 set benefit-out 0endto do-plots set-current-plot "Populations" set-current-plot-pen "altruists" plot count patches with [pcolor = pink] set-current-plot-pen "selfish" plot count patches with [pcolor = green]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 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 2003.;; To refer to this model in academic publications, please use:; Wilensky, U. (1998). NetLogo Altruism model.; http://ccl.northwestern.edu/netlogo/models/Altruism.; 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/Altruism; for terms of use.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW3301066836920208.0010111CC-WINDOW330374659527Command CenterBUTTON754214475setupsetupNIL1TOBSERVERTSLIDER5382270115altruistic-probabilityaltruistic-probability0.00.50.260.011NILSLIDER53115270148selfish-probabilityselfish-probability0.00.50.260.011NILSLIDER53214270247diseasedisease01.00.00.011NILSLIDER53181270214benefit-from-altruismbenefit-from-altruism0.00.90.480.011NILSLIDER53148270181cost-of-altruismcost-of-altruism0.00.90.130.011NILBUTTON1814225075gogoT1TOBSERVERTSLIDER53246270279harshnessharshness01.00.00.011NIL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -