📄 ---final-evo-moths.nlogo
字号:
breeds [ lights moths ]globals [ scale-factor ;; to control the form of the light field time like-count ]lights-own [ intensity ]moths-own [ ;; +1 means the moths turn to the right to try to evade a bright light ;; (and thus circle the light source clockwise). -1 means the moths ;; turn to the left (and circle the light counter-clockwise) ;; The direction tendancy is assigned to each moth when it is created and does not ;; change during the moth's lifetime. direction turn-angle age like-light available ]patches-own [ light-level ;; represents the light energy from all light sources ]to setup ca set-default-shape lights "circle 2" set-default-shape moths "butterfly" set scale-factor 50 set time 0 if number-lights > 0 [ make-lights number-lights ask patches [ generate-field ] ] make-moths number-mothsendto go ask moths [ move-thru-field ] update-pop set time time + 1endto update-pop let avg-like-light 0 set like-count 0 ask moths [ without-interruption [ if count moths < 100 [ let closest min-one-of moths with [self != myself] [distance myself] if closest != nobody [ if distance closest < 2 [ if random 100 < fertility-rate [ ifelse random 2 = 0 [make-offspring self][make-offspring closest] ] set available-of closest false set available false ] ] ] if any? lights [ if distance min-one-of lights [distance myself] < 1 [die] ] set age age + 1 if age > life-expectancy [ if random 100 < 10 [die] ] ] ] ask moths [set avg-like-light avg-like-light + like-light] set-current-plot "Average like light" plot avg-like-light / (count moths + 1) ask moths [if like-light > 0 [set like-count like-count + 1]] set-current-plot "Moths who like light" ;print like-count ;print like-count / (count moths + 1) plot 100 * like-count / (count moths + 1) end;;;;;;;;;;;;;;;;;;;;;;;; Setup Procedures ;;;;;;;;;;;;;;;;;;;;;;;;to make-lights [ number ] create-custom-lights number [ set color white set heading random-float 360 jump 10 + random-float (screen-edge-x - 30) set intensity random luminance + 20 set size sqrt intensity ]endto make-offspring [parent] hatch-moths 1 [ ifelse (random 2 = 0) [ set direction 1 ] [ set direction -1 ] set color white jump random-float screen-edge-x set size 5 set age 0 set turn-angle random (10) - 5 + turn-angle-of parent set like-light random (10) - 5 + like-light-of parent ]endto make-moths [ number ] create-custom-moths number [ ifelse (random 2 = 0) [ set direction 1 ] [ set direction -1 ] set color white jump random-float screen-edge-x set size 5 set turn-angle random 180 set like-light random (100) - 50 set age 0 ]endto generate-field ;; patch procedure set light-level 0 ;; every patch needs to check in with every light ask lights [ set-field myself ] set pcolor scale-color blue (sqrt light-level) 0.1 ( sqrt ( 20 * max values-from lights [intensity] ) )end;; do the calculations for the light on one patch due to one light;; which is proportional to the distance from the light squared.to set-field [p] ;; turtle procedure; input p is a patch let xd xcor - pxcor-of p let yd ycor - pycor-of p let rsquared ( (xd * xd) + (yd * yd) ) ifelse (rsquared != 0) [ set light-level-of p (light-level-of p + ( (intensity * scale-factor) / rsquared ) ) ] [ set light-level-of p (light-level-of p + (intensity * scale-factor * 1000)) ]end;;;;;;;;;;;;;;;;;;;;;;;;;; Runtime Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;to move-thru-field ;; turtle procedure set available true ifelse (light-level <= ( 1 / (10 * sensitivity) )) [ ;; if there is no detectable light move randomly rt flutter-amount 45 fd 1 ;if like-light > 0 [print "i like light!" + age] ] [ ifelse (random 25 = 0) ;; add some additional randomness to the moth's movement, this allows some small ;; probability that the moth might "escape" from the light. [ rt flutter-amount 45 fd 1 ] [ ;; turn toward the brightest light ifelse like-light > like-light-bias [set heading uphill light-level] [set heading downhill light-level] ;; if the light ahead is not above the sensitivity threshold head towards the light ;; otherwise move randomly ifelse ( light-level-of patch-ahead 1 / light-level-of patch-here > ( 1 + 1 / (10 * sensitivity) ) ) [ lt ( direction * turn-angle ) fd 1 ] [ rt flutter-amount 45 fd 1 ] ] ] endto-report flutter-amount [limit] ;; This routine takes a number as an input and returns a random value between ;; (+1 * input value) and (-1 * input value). ;; It is used to add a random flutter to the moth's movements report random-float (2 * limit) - limitend; *** NetLogo Model Copyright Notice ***;; This model was created as part of the projects:; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN; CLASSROOMS and 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.;; Copyright 2005 by Uri Wilensky. Updated 2005. 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.;; To refer to this model in academic publications, please use:; Wilensky, U. (2005). NetLogo Moths model.; http://ccl.northwestern.edu/netlogo/models/Moths.; Center for Connected Learning and Computer-Based Modeling,; Northwestern University, Evanston, IL.;; In other publications, please use:; Copyright 2005 Uri Wilensky. All rights reserved.; See http://ccl.northwestern.edu/netlogo/models/Moths; for terms of use.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW540119524441001002.01101110111CC-WINDOW5480961575Command Center0BUTTON140118206151NILsetupNIL1TOBSERVERNILNILSLIDER14879270112luminanceluminance110211NILBUTTON208118271151NILgoT1TOBSERVERTNILSLIDER2479146112number-lightsnumber-lights05111NILSLIDER972326956number-mothsnumber-moths1201011NILSLIDER50159235192sensitivitysensitivity031.00.251NILMONITOR11198668Pop countcount moths01SLIDER49199236232fertility-ratefertility-rate01007511NILSLIDER49238236271like-light-biaslike-light-bias-5050011NILSLIDER56277228310life-expectancylife-expectancy02000500251NILPLOT48313248463Average like lighttimelike-light0.010.0-50.050.0truefalseMONITOR1912276171timetime01PLOT300316500466Moths who like lighttimemoths-that-like-light0.010.00.0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -