欢迎来到天天文库
浏览记录
ID:37861129
大小:33.50 KB
页数:4页
时间:2019-06-01
《netlogo的virus程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、turtles-own[sick?;;iftrue,theturtleisinfectiousimmune?;;iftrue,theturtlecan'tbeinfectedsick-count;;howlongtheturtlehasbeeninfectiousage];;howmanyweeksoldtheturtleisglobals[%infected;;what%ofthepopulationisinfectious%immune;;what%ofthepopulationisimmunelifespan;;theaveragelif
2、espanofaturtleaverage-offspring;;theaveragenumberofoffspringaturtlecouldhavecarrying-capacity;;thenumberofturtlesthatcanbeintheworldatonetime];;Thesetupisdividedintothreesubroutinestosetupclear-allsetup-constantssetup-turtlesupdate-global-variablesreset-ticksend;;Wecreateava
3、riablenumberofturtlesofwhich10areinfectious,;;anddistributethemrandomlytosetup-turtlesset-default-shapeturtles"person"crtpeople[setxyrandom-xcorrandom-ycorsetagerandomlifespansetsick-count0setimmune?falsesetsize1.5;;easiertoseeget-healthy]askn-of10turtles[get-sick]endtoget-s
4、ick;;turtleproceduresetsick?truesetimmune?falsesetcolorredendtoget-healthy;;turtleproceduresetsick?falsesetimmune?falsesetsick-count0setcolorgreenendtobecome-immune;;turtleproceduresetsick?falsesetsick-count0setimmune?truesetcolorgrayendtosetup-constantssetlifespan100setcarr
5、ying-capacity750setaverage-offspring4endtogoget-oldermoveinfectrecoverreproduceupdate-global-variablestickendtoupdate-global-variablesifcountturtles>0[set%infected(countturtleswith[sick?])/(countturtles)*100set%immune(countturtleswith[immune?])/(countturtles)*100]end;;Turtle
6、countingvariablesareadvanced.toget-olderaskturtles[setageage+1ifsick?[setsick-count(sick-count+1)];;Turtlesdieofoldageoncetheirageequalsthe;;lifespan(setat100inthismodel).ifage>lifespan[die]]end;;Turtlesmoveaboutatrandom.tomoveaskturtles[rtrandom100ltrandom100fd1]end;;Ifatur
7、tleissick,itinfectsotherturtlesonthesamepatch.;;Immuneturtlesdon'tgetsick.toinfectaskturtleswith[sick?][askotherturtles-herewith[notimmune?][if(random-float100)8、ecoveraskturtleswith[sick?][if(randomsick-count)>(lifespan*(duration/100));
8、ecoveraskturtleswith[sick?][if(randomsick-count)>(lifespan*(duration/100));
此文档下载收益归作者所有